dreampuf / GraphvizOnline

Let's Graphviz it online
https://dreampuf.github.io/GraphvizOnline/
BSD 3-Clause "New" or "Revised" License
799 stars 213 forks source link

Import from Github gist #12

Closed lemmy closed 4 years ago

lemmy commented 5 years ago

It would be convenient if it were possible to dump the .dot/.gv file into a Github gist and then share a dreampuf link that is significantly shorten than: https://dreampuf.github.io/GraphvizOnline/#strict%20digraph%20DiskGraph%20%7B%0A%09graph%20%5Bbb%3D%220%2C0%2C1235%2C443.84%22%2C%0A%09%09nodesep%3D0.35%0A%09%5D%3B%0A%09node%20%5Blabel%3D%22%5CN%22%5D%3B%0A%09edge%20%5Bcolorscheme%3Dpaired12%5D%3B%0A%09subgraph%20cluster_graph%20%7B%0A%09%09graph%20%5Bbb%3D%228%2C8%2C879%2C431.81%22%2C%0A%09%09%09color%3Dwhite%0A%09%09%5D%3B%0A%09%09%7B%0A%09%09%09graph%20%5Brank%3Dsame%5D%3B%0A%09%09%09-4678409207515090095%09%09%09%20%5Bheight%3D1.041%2C%0A%09%09%09%09label%3D%22%2F%5C%5C%20victim%20%3D%20Null%5Cn%2F%5C%5C%20owner%20%3D%20(t1%20%3A%3E%20FALSE%20%40%40%20t2%20%3A%3E%20FALSE)%5Cn%2F%5C%5C%20wasVictim%20%3D%20(t1%20%3A%3E%20FALSE%20%40%40%20t2%20%3A%3E%20FALSE)%22%2C%0A%09%09%09%09pos%3D%22428%2C386.34%22%2C%0A%09%09%09%09style%3Dfilled%2C%0A%09%09%09%09width%3D5.6372%5D%3B%0A%09%09%7D%0A%09%09%7B%0A%09%09%09graph%20%5Brank%3Dsame%5D%3B%0A%09%09%093675886290632349128%09%09%09%20%5Bheight%3D1.041%2C%0A%09%09%09%09label%3D%22%2F%5C%5C%20victim%20%3D%20t1%5Cn%2F%5C%5C%20owner%20%3D%20(t1%20%3A%3E%20FALSE%20%40%40%20t2%20%3A%3E%20FALSE)%5Cn%2F%5C%5C%20wasVictim%20%3D%20(t1%20%3A%3E%20TRUE%20%40%40%20t2%20%3A%3E%20FALSE)%22%2C%0A%09%09%09%09pos%3D%22232%2C275.38%22%2C%0A%09%09%09%09width%3D5.5194%5D%3B%0A%09%09%09-4891499473505380123%09%09%09%20%5Bheight%3D1.041%2C%0A%09%09%09%09label%3D%22%2F%5C%5C%20victim%20%3D%20t2%5Cn%2F%5C%5C%20owner%20%3D%20(t1%20%3A%3E%20FALSE%20%40%40%20t2%20%3A%3E%20FALSE)%5Cn%2F%5C%5C%20wasVictim%20%3D%20(t1%20%3A%3E%20FALSE%20%40%40%20t2%20%3A%3E%20TRUE)%22%2C%0A%09%09%09%09pos%3D%22654%2C275.38%22%2C%0A%09%09%09%09width%3D5.5194%5D%3B%0A%09%09%7D%0A%09%09%7B%0A%09%09%09graph%20%5Brank%3Dsame%5D%3B%0A%09%09%09-1891075296837866694%09%09%09%20%5Bheight%3D1.041%2C%0A%09%09%09%09label%3D%22%2F%5C%5C%20victim%20%3D%20t2%5Cn%2F%5C%5C%20owner%20%3D%20(t1%20%3A%3E%20FALSE%20%40%40%20t2%20%3A%3E%20FALSE)%5Cn%2F%5C%5C%20wasVictim%20%3D%20(t1%20%3A%3E%20TRUE%20%40%40%20t2%20%3A%3E%20TRUE)%22%2C%0A%09%09%09%09pos%3D%22210%2C164.43%22%2C%0A%09%09%09%09width%3D5.4015%5D%3B%0A%09%09%096551234386972865759%09%09%09%20%5Bheight%3D1.041%2C%0A%09%09%09%09label%3D%22%2F%5C%5C%20victim%20%3D%20t1%5Cn%2F%5C%5C%20owner%20%3D%20(t1%20%3A%3E%20FALSE%20%40%40%20t2%20%3A%3E%20FALSE)%5Cn%2F%5C%5C%20wasVictim%20%3D%20(t1%20%3A%3E%20TRUE%20%40%40%20t2%20%3A%3E%20TRUE)%22%2C%0A%09%09%09%09pos%3D%22677%2C164.43%22%2C%0A%09%09%09%09width%3D5.4015%5D%3B%0A%09%09%7D%0A%09%09%7B%0A%09%09%09graph%20%5Brank%3Dsame%5D%3B%0A%09%09%098999254966766664384%09%09%09%20%5Bheight%3D1.041%2C%0A%09%09%09%09label%3D%22%2F%5C%5C%20victim%20%3D%20t2%5Cn%2F%5C%5C%20owner%20%3D%20(t1%20%3A%3E%20TRUE%20%40%40%20t2%20%3A%3E%20FALSE)%5Cn%2F%5C%5C%20wasVictim%20%3D%20(t1%20%3A%3E%20FALSE%20%40%40%20t2%20%3A%3E%20TRUE)%22%2C%0A%09%09%09%09pos%3D%22232%2C53.477%22%2C%0A%09%09%09%09width%3D5.5194%5D%3B%0A%09%09%094362618074356267131%09%09%09%20%5Bheight%3D1.041%2C%0A%09%09%09%09label%3D%22%2F%5C%5C%20victim%20%3D%20t1%5Cn%2F%5C%5C%20owner%20%3D%20(t1%20%3A%3E%20FALSE%20%40%40%20t2%20%3A%3E%20TRUE)%5Cn%2F%5C%5C%20wasVictim%20%3D%20(t1%20%3A%3E%20TRUE%20%40%40%20t2%20%3A%3E%20FALSE)%22%2C%0A%09%09%09%09pos%3D%22663%2C53.477%22%2C%0A%09%09%09%09width%3D5.5194%5D%3B%0A%09%09%7D%0A%09%09-4678409207515090095%20-%3E%203675886290632349128%09%09%20%5Bcolor%3D2%2C%0A%09%09%09fontcolor%3D2%2C%0A%09%09%09pos%3D%22e%2C294.98%2C311.03%20364.91%2C350.62%20345.41%2C339.58%20323.79%2C327.35%20303.76%2C316%22%5D%3B%0A%09%09-4678409207515090095%20-%3E%20-4891499473505380123%09%09%20%5Bcolor%3D2%2C%0A%09%09%09fontcolor%3D2%2C%0A%09%09%09pos%3D%22e%2C582.57%2C310.45%20499.51%2C351.23%20523.01%2C339.69%20549.3%2C326.78%20573.44%2C314.94%22%5D%3B%0A%09%093675886290632349128%20-%3E%20-1891075296837866694%09%09%20%5Bcolor%3D2%2C%0A%09%09%09fontcolor%3D2%2C%0A%09%09%09pos%3D%22e%2C217.44%2C201.96%20224.55%2C237.82%20222.9%2C229.51%20221.14%2C220.59%20219.42%2C211.94%22%5D%3B%0A%09%09-4891499473505380123%20-%3E%206551234386972865759%09%09%20%5Bcolor%3D2%2C%0A%09%09%09fontcolor%3D2%2C%0A%09%09%09pos%3D%22e%2C669.22%2C201.96%20661.79%2C237.82%20663.51%2C229.51%20665.36%2C220.59%20667.15%2C211.94%22%5D%3B%0A%09%09-1891075296837866694%20-%3E%208999254966766664384%09%09%20%5Bcolor%3D3%2C%0A%09%09%09fontcolor%3D3%2C%0A%09%09%09pos%3D%22e%2C224.56%2C91.002%20217.45%2C126.87%20219.1%2C118.55%20220.86%2C109.64%20222.58%2C100.98%22%5D%3B%0A%09%096551234386972865759%20-%3E%204362618074356267131%09%09%20%5Bcolor%3D3%2C%0A%09%09%09fontcolor%3D3%2C%0A%09%09%09pos%3D%22e%2C667.73%2C91.002%20672.26%2C126.87%20671.21%2C118.55%20670.09%2C109.64%20668.99%2C100.98%22%5D%3B%0A%09%098999254966766664384%20-%3E%20-4891499473505380123%09%09%20%5Bcolor%3D4%2C%0A%09%09%09fontcolor%3D4%2C%0A%09%09%09pos%3D%22e%2C545.24%2C243.9%20341.35%2C84.88%20367.75%2C95.593%20394.73%2C109.43%20417%2C126.95%20449.06%2C152.18%20437.96%2C176.65%20470%2C201.91%20489.55%2C217.32%20512.76%2C229.9%20%5C%0A535.99%2C240%22%5D%3B%0A%09%094362618074356267131%20-%3E%203675886290632349128%09%09%20%5Bcolor%3D4%2C%0A%09%09%09fontcolor%3D4%2C%0A%09%09%09pos%3D%22e%2C341.35%2C243.98%20548.92%2C84.2%20521.39%2C94.926%20493.23%2C108.94%20470%2C126.95%20437.76%2C151.95%20449.06%2C176.68%20417%2C201.91%20397.34%2C217.38%20374.01%2C229.97%20%5C%0A350.65%2C240.08%22%5D%3B%0A%09%7D%0A%09subgraph%20cluster_legend%20%7B%0A%09%09graph%20%5Bbb%3D%22887%2C359.84%2C1227%2C435.84%22%2C%0A%09%09%09label%3D%22Next%20State%20Actions%22%2C%0A%09%09%09lheight%3D0.21%2C%0A%09%09%09lp%3D%221057%2C424.34%22%2C%0A%09%09%09lwidth%3D1.43%2C%0A%09%09%09style%3Dsolid%0A%09%09%5D%3B%0A%09%09node%20%5Bcolorscheme%3Dpaired12%2C%0A%09%09%09labeljust%3Dl%2C%0A%09%09%09shape%3Drecord%2C%0A%09%09%09style%3Dfilled%0A%09%09%5D%3B%0A%09%09AcquireLock%09%09%20%5Bcolorscheme%3Dpaired12%2C%0A%09%09%09fillcolor%3D3%2C%0A%09%09%09height%3D0.51389%2C%0A%09%09%09label%3DAcquireLock%2C%0A%09%09%09labeljust%3Dl%2C%0A%09%09%09pos%3D%221175%2C386.34%22%2C%0A%09%09%09rects%3D%221131%2C368.34%2C1219%2C404.34%22%2C%0A%09%09%09shape%3Drecord%2C%0A%09%09%09style%3Dfilled%2C%0A%09%09%09width%3D1.2222%5D%3B%0A%09%09BecomeVictim%09%09%20%5Bcolorscheme%3Dpaired12%2C%0A%09%09%09fillcolor%3D2%2C%0A%09%09%09height%3D0.51389%2C%0A%09%09%09label%3DBecomeVictim%2C%0A%09%09%09labeljust%3Dl%2C%0A%09%09%09pos%3D%221056%2C386.34%22%2C%0A%09%09%09rects%3D%221006%2C368.34%2C1106%2C404.34%22%2C%0A%09%09%09shape%3Drecord%2C%0A%09%09%09style%3Dfilled%2C%0A%09%09%09width%3D1.3889%5D%3B%0A%09%09ReleaseLock%09%09%20%5Bcolorscheme%3Dpaired12%2C%0A%09%09%09fillcolor%3D4%2C%0A%09%09%09height%3D0.51389%2C%0A%09%09%09label%3DReleaseLock%2C%0A%09%09%09labeljust%3Dl%2C%0A%09%09%09pos%3D%22938%2C386.34%22%2C%0A%09%09%09rects%3D%22895%2C368.34%2C981%2C404.34%22%2C%0A%09%09%09shape%3Drecord%2C%0A%09%09%09style%3Dfilled%2C%0A%09%09%09width%3D1.1944%5D%3B%0A%09%7D%0A%7D%0A

dreampuf commented 5 years ago

That's an interesting feature.

Originally thought was try to not use any external services. So It is a simple URL encoding as the query string.

Gist definitely would be a cleaner solution and associated with versioning and multi-files support. But I'd like to consider it be the right solution rather than a simple Gist reader. How to put your current work into Gist should also need to think of it.

lemmy commented 5 years ago

At first, why not just have a url parameter that takes the given resource as input. Could be a (raw) gist or a .dot file hosted on a webserver.

dreampuf commented 5 years ago

Because of the Same-origin policy, it restricts very few sites that could be as an input in Javascript, unless the target site enabled the cross-origin script access. AFAIK Gist v3 API provides the JSONP that could be a choice.

leonelgalan commented 4 years ago

Another option Im considering to shorten the URLs is compressing with zlib (pako) and base64 encode. The entire chart shared by @lemmy comes down to:

eJzFl8tu4zYUhtf2UxBetYDCkof3FhpMil42gyxmpt0kReHYnNiNYruW0rQo\n8u7zk7IydqLYSRC08MakpMP/OzeSdbOeTxo2nV+sx6sZ+2FeX/6c//07HLRT\np+fn5UgUopCkTKG14l6PiuFgsFhOYx1XpeDKDAe/fTfMM+y0Gp/HqhydnYzS\nXJxeYG6yrJbrejKLV7FcjefrOJWUntbX5+0qk+q6buL694tu8e3VfYGfC4VW\nknuZFx9ki+XNbN5EDJOtQfqq+2w9XlyW9fgq5ieDI22d1yKQcEYaEYQIBtPs\ndBbnF7OmlFxome0ONvK/OTtjf8E18ytWspPrqjpbpKnlzSKuMfNVI9m3b9hP\nx+8+/MjevmUN3Q2/bt+8Gde/dt/ve7vFGayWdTnS5AvlLVd6M1s3/1Sx/DSv\nqjhtZ27m02ZWGm6Vyx4c3O4nV9YZ7y0FYRUpHST5Z4A38hWwP77/ZS81KSrI\nGa78aJfRyKC7+PkgdQjaKSOM8gLJ+BwMev3oJaodDGv0AYwDoTqSgESCUrBe\nOW+tDfq/htyN1QNGkugDVnOt7jFqIU1LYY1BcDTSODjy1jgT/t+Eexgo5w5A\nHAiUDyGQ0cFahyBZsL5CnPqq5MW5mErKKK6de7SktLJkpRdOK4N/Tir56nHK\nul7cF6xVByBSnPpaOzt6w3ob32YnKikb/LRcNNvjvGosKGge0IglfKBgByNZ\noO9wS0xppAlGKnDjGQxz7EuKHPZApgRGFt/ZvPM9qqy/mT1JmvHEjcMSgmvD\nYAO+gDTJSTEDMaKVZgNDenIFZZY7z4yDGzU+A4puxfW4J2vr7UFPc5t0aRES\nkgfLiDQ3piDluCeMiIeCKOnFQHKJF0lwExjJwDU2AHi709bnoCSut7U8SRsw\nOFGnzVqZwrbRhjRLXtyIsxYd3HbiUOFcml1xPR5K4nqbQidO3ROndhyXXGWL\ngHQTcFVyo8Fpy3LvsndkIaWHM1kS5W0hBSKss0+Nx0ggW1ttPQ5K0npL/UnS\nEr9TnTTriJPtpMEOpztt1gkuQqfNWs9D2NHW45/DxaDvidM7xYBaJOQRjqQB\nhSlRg4XX3PtU+9yZIqBVBFQw6hkQSZpWTEuXCVCLGjUiwGOISw8vOSRHIZ3l\nFs+caNNFMijMqYzAKGLwcKrylC6BnQ2NMomUtGgxe3x9sBvtpdyAZUpUsoZj\nKWFCCepIhSJ1K7JoBgpdAJR4QWf5HSW4XKKU28yJ0mdnbChVAJ5uKeFBp1Mz\nyZQOmLn9JRWIchvQ257TexUv4mL64Pju0bFMwL0BksjhGG+6O0S3t5zEvxv2\noRk3kR1jk1gu6s3jzW4kUqbliVU5kgItUKNoumNy1W4MEuHN4/bUXC+r+bS7\nG7RXk75ryBcZfwCirFoLs/Eqlus4Wa6nWybbg3hn83jy5zVsvFtOLu9i2Wc8\nfbVdW3dMRiofttywZbBXVc4IKZHZ25cEqGzyvELzR92p5GaJ25L44qG9PHmi\ncyG6Snuv+B4vX8V2z34iHu3H27a4h0+gF/bxCaRtxyfx/2V8yvuQ+d7HKo7r\n50RP78fbMvg4XVC+D84H07EFL1+IhlORbivzdvgZT6vUjQ==\n

Which is 1635 long as opposed to 4056.

const pako = require('pako')
const atob = require('atob')

// Based on https://stackoverflow.com/a/30240791/637094
function uncompress(base64data){
    compressData = atob(base64data);
    compressData = compressData.split('').map(function(e) {
        return e.charCodeAt(0);
    });
    binData = new Uint8Array(compressData);
    data = pako.inflate(binData);
    return String.fromCharCode.apply(null, new Uint16Array(data));
}

const chart = 'eJzFl8tu4zYUhtf2UxBetYDCkof3FhpMil42gyxmpt0kReHYn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U+9yZIqBVBFQw6hkQSZpWTEuXCVCLGjUiwGOISw8vOSRHIZ3l\nFs+caNNFMijMqYzAKGLwcKrylC6BnQ2NMomUtGgxe3x9sBvtpdyAZUpUsoZj\nKWFCCepIhSJ1K7JoBgpdAJR4QWf5HSW4XKKU28yJ0mdnbChVAJ5uKeFBp1Mz\nyZQOmLn9JRWIchvQ257TexUv4mL64Pju0bFMwL0BksjhGG+6O0S3t5zEvxv2\noRk3kR1jk1gu6s3jzW4kUqbliVU5kgItUKNoumNy1W4MEuHN4/bUXC+r+bS7\nG7RXk75ryBcZfwCirFoLs/Eqlus4Wa6nWybbg3hn83jy5zVsvFtOLu9i2Wc8\nfbVdW3dMRiofttywZbBXVc4IKZHZ25cEqGzyvELzR92p5GaJ25L44qG9PHmi\ncyG6Snuv+B4vX8V2z34iHu3H27a4h0+gF/bxCaRtxyfx/2V8yvuQ+d7HKo7r\n50RP78fbMvg4XVC+D84H07EFL1+IhlORbivzdvgZT6vUjQ==\n'

uncompress(chart);
timabell commented 4 years ago

Some references

Thanks for a great project!

timabell commented 4 years ago

Seeing if I can pay someone to build this because I want it and don't have time: https://www.upwork.com/jobs/~01a9f81b8a394c74fa

lemmy commented 4 years ago

@timabell Is there a way for me to chime in and raise to $100?

timabell commented 4 years ago

@lemmy that's a good idea, I haven't had any takers so far so it might help.

I've set up a payment page so you can send money to my business which is funding the upwork posting; I've set the amount to $60 to cover all the processing fees so that I can still make it $100 total if that's okay.

Head over to https://timwise.co.uk/pay/ and put in a credit card number and I will add the money to the upwork posting. I'm pretty sure I can do a refund from stripe if it doesn't work out. Any problems drop me an email.

lemmy commented 4 years ago

@timabell Tried to chime in and my browser crashed mid-flight. Did you get the $60?

timabell commented 4 years ago

Yep, got it, thanks. Yay computers. ... upwork posting updated, let's see if this works! https://www.upwork.com/jobs/~01a9f81b8a394c74fa

bcardiff commented 4 years ago

@dreampuf AFAIK you can use urls with gist.githubusercontent.com prefix to allow CORS.

ObservableHQ uses those url in many examples https://stackoverflow.com/a/57255140/30948

Another route to make .dot files from gist render in graphviz is to package the js in an easy way to consume it and use https://bl.ocks.org/ to load those gist. People will need to add a bolerplate index.html to bl.ocks.org render it directly but is another way to share graphs with no maintenance cost.

timabell commented 4 years ago

Neat, thanks @bcardiff Here's a trivial graph example in that form: https://gist.githubusercontent.com/timabell/da08616ecb8693d524b8eab3b7b51018/raw/9575a3c887526eb5858587514f6bfb5c173b6449/graph.gv

(from https://gist.github.com/timabell/da08616ecb8693d524b8eab3b7b51018 )

Which comes with these headers:

Selection_20200723-01-d

Which includes Access-Control-Allow-Origin: *, which I think means we are okay for xss protection - reference https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

In this case, the server responds with Access-Control-Allow-Origin: *, which means that the resource can be accessed by any domain.

dreampuf commented 4 years ago

Thank you, everyone, for using this tool. I'm working on a rework version(relatively slow). It combines monaco-editor(DOT language highlight support and even a fully functional LSP) and an updated javascript portion of graphviz https://github.com/hpcc-systems/hpcc-js-wasm. It gives you ability to link picture files in your graph.

For the shorter share URL, @leonelgalan shared a valuable library pako. I will check it out. Thank you @leonelgalan. Regarding gist, thank you for sharing the knowledge. The client-side import is possible. It's on my list.

timabell commented 4 years ago

@lemmy I've closed that upwork post as it had zero response and upwork removed the link to this issue which was less than helpful. I'll post with bountysource instead which is perhaps more appropriate. If you're not happy with this change in approach let me know and I'll refund your contribution. Sorry to others for clogging up the discussion with trying to get this paid for, I hope you all don't mind. ... and here's the bounty https://www.bountysource.com/issues/83842220-import-from-github-gist :crossed_fingers:

timabell commented 4 years ago

It works! https://dreampuf.github.io/GraphvizOnline/?url=https://gist.githubusercontent.com/timabell/da08616ecb8693d524b8eab3b7b51018/raw/0e205c341b40641206a55c9f96b5db9b8fa581bc/graph.gv Thanks everyone who helped on this, I've very happy this has been done and merged. :champagne: