Last active
April 2, 2017 10:30
-
-
Save jakkaj/14c0986fce77c6905f446f7bafec3561 to your computer and use it in GitHub Desktop.
Function to render Graphviz graphs from dot files that are posted in
This file contains hidden or 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
{ | |
"bindings": [ | |
{ | |
"authLevel": "function", | |
"type": "httpTrigger", | |
"direction": "in", | |
"name": "req" | |
}, | |
{ | |
"type": "http", | |
"direction": "out", | |
"name": "res" | |
} | |
], | |
"disabled": false | |
} |
This file contains hidden or 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
//post{ "dot": "digraph { x -> y -> z; }"} | |
var viz = require('viz.js'); | |
var fs = require('fs'); | |
var svg2png = require("svg2png"); | |
module.exports = function (context, req) { | |
context.log('JavaScript HTTP trigger function processed a request.'); | |
if (req.body && req.body.dot) { | |
var dot = req.body.dot; | |
var svg = viz(dot, { format: "svg" }); | |
svg = svg.replace(/Times,serif/gi, "sans-serif"); | |
svg2png(svg, { width: 2560, height: 2048 }) | |
.then(buffer => { | |
context.res = { | |
// status: 200, /* Defaults to 200 */ | |
body: buffer, | |
headers: { | |
'Content-Type': 'image/png' | |
} | |
}; | |
context.done(); | |
}); | |
} | |
else { | |
context.res = { | |
status: 400, | |
body: "Please pass a dot field in the request body that contains " | |
}; | |
context.done(); | |
} | |
}; |
This file contains hidden or 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
//thanks http://brandewinder.com/2017/04/01/azure-function-app-diagram/ | |
{ | |
"dot": "digraph app {\r\nnode [shape=doublecircle,style=filled,color=orange]\r\n \"check-mentions\"\r\n \"follow-users\"\r\n \"process-mention\"\r\n \"send-tweet\"\r\nnode [shape=box,style=filled,color=yellow]\r\n \"Timer\"\r\n \"Blob incontainer\/lastid\"\r\n \"Queue mentions\"\r\n \"Queue friends\"\r\n \"Queue tweets\"\r\nnode [shape=box,style=filled,color=lightblue]\r\n \"linqtotwitter (4.1.0)\"\r\n \"Newtonsoft.Json (9.0.1)\"\r\n \"FSharp.Compiler.Service (9.0.1)\" \r\nedge [ style=bold ]\r\n \"Timer\" -> \"check-mentions\" [ label = \"timer\" ]\r\n \"Queue friends\" -> \"follow-users\" [ label = \"userName\" ]\r\n \"Queue mentions\" -> \"process-mention\" [ label = \"input\" ]\r\n \"Queue tweets\" -> \"send-tweet\" [ label = \"input\" ]\r\nedge [ style=solid ]\r\n \"Blob incontainer\/lastid\" -> \"check-mentions\" [ label = \"previousID\" ]\r\nedge [ style=solid ]\r\n \"check-mentions\" -> \"Blob incontainer\/lastid\" [ label = \"updatedID\" ]\r\n \"check-mentions\" -> \"Queue mentions\" [ label = \"mentionsQueue\" ]\r\n \"check-mentions\" -> \"Queue friends\" [ label = \"friendsQueue\" ]\r\n \"process-mention\" -> \"Queue tweets\" [ label = \"responseQueue\" ] \r\nedge [ arrowhead=none,style=dotted,dir=none ]\r\n \"linqtotwitter (4.1.0)\" -> \"check-mentions\"\r\n \"Newtonsoft.Json (9.0.1)\" -> \"check-mentions\"\r\n \"linqtotwitter (4.1.0)\" -> \"follow-users\"\r\n \"FSharp.Compiler.Service (9.0.1)\" -> \"process-mention\"\r\n \"Newtonsoft.Json (9.0.1)\" -> \"process-mention\"\r\n \"linqtotwitter (4.1.0)\" -> \"send-tweet\"\r\n \"Newtonsoft.Json (9.0.1)\" -> \"send-tweet\" \r\n}" | |
} |
This file contains hidden or 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
{ | |
"dependencies": { | |
"viz.js": "~1.7.1", | |
"svg2png": "~4.1.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment