Last active
August 29, 2015 14:04
-
-
Save iamnoah/f6742bb1ef1a5532e71b to your computer and use it in GitHub Desktop.
console.viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Usage: | |
console.viz("digraph foo { a -> b; }"); | |
*/ | |
(function(global) { | |
"use strict"; | |
if (!global.console) { | |
return; | |
} | |
function load(src, onload) { | |
var s = document.createElement("script"); | |
s.onload = onload; | |
s.src = src; | |
document.body.appendChild(s); | |
} | |
load("https://github.com/mdaines/viz.js/releases/download/0.0.3/viz.js", function() { | |
load("https://cdn.rawgit.com/adriancooney/console.snapshot/master/console.snapshot.js", function() { | |
global.console.viz = function(graph) { | |
var canvas = document.createElement("canvas"); | |
var ctx = canvas.getContext("2d"); | |
var img = new Image(); | |
img.onload = draw; | |
img.src = "data:image/svg+xml;utf8," + encodeURI(global.Viz(graph, "svg")); | |
function draw() { | |
ctx.drawImage(img, 0, 0, 250, 150); | |
console.screenshot(canvas); | |
global.console.log(img.src); | |
} | |
}; | |
}); | |
}); | |
})(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment