drawio-desktop icon indicating copy to clipboard operation
drawio-desktop copied to clipboard

Global option to save all new files as uncompressed

Open JesseAldridge opened this issue 5 years ago • 3 comments

I found out about the compressed="false" attribute here: https://github.com/jgraph/drawio-desktop/issues/79

Cool. So my understanding is that in order to convert an existing diagram to uncompressed text, I need to do the following:

  1. Open foo.drawio in a text editor
  2. Add compressed="false" to the mxfile node and save
  3. Open foo.drawio in Draw.io.
  4. Hit cmd+s to save

I have about 600 existing .drawio files that I would like to convert to plain text. This is a bit annoying, but doable in a pseudo automatic way.

In addition to that, I will have to perform this procedure every time I create a new diagram, right? Because there's no way to set compressed="false" by default?

It would be great if there was a checkbox somewhere to save all files as uncompressed.

In case you're interested, the use case I have in mind is annotating my diagrams with additional info via a rewrite script that runs in the background periodically. For example coloring nodes based on how recently they were modified. It's a lot easier to perform this sort of operation on uncompressed files.

JesseAldridge avatar Jan 15 '20 00:01 JesseAldridge

I guess I might as well leave this here:

const fs = require('fs')
const path = require('path')

const expand_home_dir = require('expand-home-dir');
const glob = require("glob")


function convert_all_files_to_uncompressed(root_dir_path) {
  glob.glob(path.join(root_dir_path, '**/*.drawio'), function (er, paths) {
    for(let i = 0; i < paths.length; i++) {
      console.log('path:', paths[i]);

      fs.readFile(paths[i], 'utf8', function(err, text) {
        text = text.replace('<mxfile', '<mxfile compressed="false"')
        fs.writeFile(paths[i], text, function() {
          console.log('wrote:', paths[i]);
        });
      });

    }
  });
}

convert_all_files_to_uncompressed(expand_home_dir('~/Dropbox/diagrams'));

Then you can do: find . | grep drawio > out.sh then you add open before each line and run the script in batches of fifty. Then you just have to hit cmd+s and close the window 50 times per batch haha. It took me about 15 minutes to convert all my diagrams. I still don't have a good solution for new diagrams though.

JesseAldridge avatar Jan 15 '20 00:01 JesseAldridge

I tried writing a looping background script that runs periodically, setting compressed=false for all diagrams in order to solve the problem of new diagrams saving as compressed. But if the drawio file is currently open the synchronization operation discards the new compressed attribute. If synchronization preserved the compressed attribute that would solve my problem.

JesseAldridge avatar Feb 01 '20 01:02 JesseAldridge

To set the default to not compress files. From Extras -> draw.io Configuration... Add the following JSON config:

{
  "compressXml": false
}

In next version, there will be also an option in Extras menu to compress/decompress the currently open file.

m-mohamedin avatar Feb 19 '20 12:02 m-mohamedin

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. See the FAQ for more information.

stale[bot] avatar Jan 09 '23 08:01 stale[bot]

Literally nobody seems to want compression, so we'll default to uncompressed in the next release.

davidjgraph avatar Mar 22 '23 10:03 davidjgraph