From: Emden R. Gansner Date: Sun, 29 Jan 2017 23:50:34 +0000 (-0500) Subject: Update documentation to handle included json X-Git-Tag: 2.42.0~214 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bbd38b76890d6332564f65ed294ce12634269ff4;p=graphviz Update documentation to handle included json --- diff --git a/doc/info/graphviz_json_schema.json b/doc/info/graphviz_json_schema.json new file mode 100644 index 000000000..a28b72e11 --- /dev/null +++ b/doc/info/graphviz_json_schema.json @@ -0,0 +1,422 @@ +{ + "title": "Graphviz JSON", + "description": "JSON representation of a graph encoding xdot attributes", + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "The graph name" + }, + "directed": { + "type": "boolean", + "description": "True if the graph is directed" + }, + "strict": { + "type": "boolean", + "description": "True if the graph is strict" + }, + "_subgraph_cnt": { + "type": "integer", + "description": "Number of subgraphs in the graph" + }, + "objects": { + "type": "array", + "items": { "$ref": "#/definitions/metanode" }, + "description": "The graph's subgraphs followed by the graph's nodes" + }, + "edges": { + "type": "array", + "items": { + "$ref": "#/definitions/edge" + } + }, + "_draw_": { + "$ref": "#/definitions/drawops" + }, + "_ldraw_": { + "$ref": "#/definitions/drawops" + }, + "additionalProperties": { + "type": "string" + } + }, + "required": [ + "name", + "directed", + "strict", + "_subgraph_cnt" + ], + "definitions": { + "edge": { + "title": "edge", + "type": "object", + "properties": { + "_gvid": { + "type": "integer" + }, + "tail": { + "type": "integer", + "description": "_gvid of tail node" + }, + "head": { + "type": "integer", + "description": "_gvid of tail head" + }, + "_draw_": { + "$ref": "#/definitions/drawops" + }, + "_ldraw_": { + "$ref": "#/definitions/drawops" + }, + "_hdraw_": { + "$ref": "#/definitions/drawops" + }, + "_tdraw_": { + "$ref": "#/definitions/drawops" + }, + "_hldraw_": { + "$ref": "#/definitions/drawops" + }, + "_tldraw_": { + "$ref": "#/definitions/drawops" + }, + "additionalProperties": { + "type": "string" + } + }, + "required": [ + "_gvid", + "tail", + "head" + ] + }, + "metanode": { + "title": "node or subgraph", + "type": "object", + "properties": { + "_gvid": { + "type": "integer" + }, + "name": { + "type": "string", + "description": "The node or subgraph name" + }, + "subgraphs": { + "type": "array", + "items": { + "type": "integer" + }, + "description": "index of a child subgraph" + }, + "nodes": { + "type": "array", + "items": { + "type": "integer" + }, + "description": "index of a node in this subgraph" + }, + "edges": { + "type": "array", + "items": { + "type": "integer" + }, + "description": "index of an edge in this subgraph" + }, + "_draw_": { + "$ref": "#/definitions/drawops" + }, + "_ldraw_": { + "$ref": "#/definitions/drawops" + }, + "additionalProperties": { + "type": "string" + } + }, + "required": [ + "_gvid", + "name" + ] + }, + "drawops": { + "type": "array", + "items": { + "oneOf": [ + { + "$ref": "#/definitions/ellipse" + }, + { + "$ref": "#/definitions/polygon" + }, + { + "$ref": "#/definitions/polyline" + }, + { + "$ref": "#/definitions/bspline" + }, + { + "$ref": "#/definitions/text" + }, + { + "$ref": "#/definitions/font_style" + }, + { + "$ref": "#/definitions/drawcolor" + }, + { + "$ref": "#/definitions/font" + }, + { + "$ref": "#/definitions/style" + } + ] + } + }, + "ellipse": { + "type": "object", + "properties": { + "op": { + "type": "string", + "pattern": "[eE]" + }, + "rect": { + "$ref": "#/definitions/rectangle" + } + }, + "required": [ + "op", + "rect" + ] + }, + "polygon": { + "type": "object", + "properties": { + "op": { + "type": "string", + "pattern": "[pP]" + }, + "points": { + "$ref": "#/definitions/pointlist" + } + }, + "required": [ + "op", + "points" + ] + }, + "polyline": { + "type": "object", + "properties": { + "op": { + "type": "string", + "pattern": "L" + }, + "points": { + "$ref": "#/definitions/pointlist" + } + }, + "required": [ + "op", + "points" + ] + }, + "bspline": { + "type": "object", + "properties": { + "op": { + "type": "string", + "pattern": "[bB]" + }, + "points": { + "$ref": "#/definitions/pointlist" + } + }, + "required": [ + "op", + "points" + ] + }, + "text": { + "type": "object", + "properties": { + "op": { + "type": "string", + "pattern": "T" + }, + "pt": { + "$ref": "#/definitions/point" + }, + "align": { + "type": "string", + "pattern": "[lcr]" + }, + "text": { + "type": "string" + }, + "width": { + "type": "number" + } + }, + "required": [ + "op", + "pt", + "align", + "text", + "width" + ] + }, + "font_style": { + "type": "object", + "properties": { + "op": { + "type": "string", + "pattern": "t" + }, + "fontchar": { + "type": "integer", + "minimum": 0, + "maximum": 127 + } + }, + "required": [ + "op", + "fontchar" + ] + }, + "drawcolor": { + "type": "object", + "properties": { + "op": { + "type": "string", + "pattern": "[cC]" + }, + "p0": { + "oneOf": [ + { + "$ref": "#/definitions/point" + }, + { + "$ref": "#/definitions/point3" + } + ] + }, + "p1": { + "oneOf": [ + { + "$ref": "#/definitions/point" + }, + { + "$ref": "#/definitions/point3" + } + ] + }, + "grad": { + "type": "string", + "enum": [ + "none", + "linear", + "radial" + ] + }, + "color": { + "$ref": "#/definitions/color" + }, + "stops": { + "type": "array", + "items": { + "$ref": "#/definitions/stop" + } + } + }, + "required": [ + "op", + "grad" + ] + }, + "font": { + "type": "object", + "properties": { + "op": { + "type": "string", + "pattern": "F" + }, + "size": { + "type": "number", + "minimum": 0 + }, + "face": { + "type": "string" + } + }, + "required": [ + "op", + "size", + "face" + ] + }, + "style": { + "type": "object", + "properties": { + "op": { + "type": "string", + "pattern": "S" + }, + "style": { + "type": "string" + } + }, + "required": [ + "op", + "style" + ] + }, + "pointlist": { + "type": "array", + "items": { + "$ref": "#/definitions/point" + } + }, + "point": { + "type": "array", + "items": { + "type": "number" + }, + "maxItems": 2, + "minItems": 2 + }, + "point3": { + "type": "array", + "items": { + "type": "number" + }, + "maxItems": 3, + "minItems": 3 + }, + "rectangle": { + "type": "array", + "items": { + "type": "number" + }, + "maxItems": 4, + "minItems": 4 + }, + "color": { + "type": "string", + "pattern": "(#[0-9a-f]*)|(#[0-9a-f]{8})" + }, + "stop": { + "type": "object", + "properties": { + "frac": { + "type": "number" + }, + "color": { + "$ref": "#/definitions/color" + } + }, + "required": [ + "frac", + "color" + ] + } + } +} diff --git a/doc/info/output.html b/doc/info/output.html index c9f49c1d8..5e2c8bfb8 100644 --- a/doc/info/output.html +++ b/doc/info/output.html @@ -11,7 +11,7 @@ background-color: beige; } - + diff --git a/doc/info/w3data.js b/doc/info/w3data.js new file mode 100644 index 000000000..24fc4687d --- /dev/null +++ b/doc/info/w3data.js @@ -0,0 +1,148 @@ +/* W3Data ver 1.31 by W3Schools.com */ +var w3DataObject = {}; +function w3DisplayData(id, data) { + var htmlObj, htmlTemplate, html, arr = [], a, l, rowClone, x, j, i, ii, cc, repeat, repeatObj, repeatX = ""; + htmlObj = document.getElementById(id); + htmlTemplate = w3InitTemplate(id, htmlObj); + html = htmlTemplate.cloneNode(true); + arr = w3GetElementsByAttribute(html, "w3-repeat"); + l = arr.length; + for (j = (l - 1); j >= 0; j -= 1) { + cc = arr[j].getAttribute("w3-repeat").split(" "); + if (cc.length == 1) { + repeat = cc[0]; + } else { + repeatX = cc[0]; + repeat = cc[2]; + } + arr[j].removeAttribute("w3-repeat"); + repeatObj = data[repeat]; + if (repeatObj && typeof repeatObj == "object" && repeatObj.length != "undefined") { + i = 0; + for (x in repeatObj) { + i += 1; + rowClone = arr[j]; + rowClone = w3NeedleInHaystack(rowClone, "element", repeatX, repeatObj[x]); + a = rowClone.attributes; + for (ii = 0; ii < a.length; ii += 1) { + a[ii].value = w3NeedleInHaystack(a[ii], "attribute", repeatX, repeatObj[x]).value; + } + (i === repeatObj.length) ? arr[j].parentNode.replaceChild(rowClone, arr[j]) : arr[j].parentNode.insertBefore(rowClone, arr[j]); + } + } else { + console.log("w3-repeat must be an array. " + repeat + " is not an array."); + continue; + } + } + html = w3NeedleInHaystack(html, "element"); + htmlObj.parentNode.replaceChild(html, htmlObj); + function w3InitTemplate(id, obj) { + var template; + template = obj.cloneNode(true); + if (w3DataObject.hasOwnProperty(id)) {return w3DataObject[id];} + w3DataObject[id] = template; + return template; + } + function w3GetElementsByAttribute(x, att) { + var arr = [], arrCount = -1, i, l, y = x.getElementsByTagName("*"), z = att.toUpperCase(); + l = y.length; + for (i = -1; i < l; i += 1) { + if (i == -1) {y[i] = x;} + if (y[i].getAttribute(z) !== null) {arrCount += 1; arr[arrCount] = y[i];} + } + return arr; + } + function w3NeedleInHaystack(elmnt, typ, repeatX, x) { + var value, rowClone, pos1, haystack, pos2, needle = [], needleToReplace, i, cc, r; + rowClone = elmnt.cloneNode(true); + pos1 = 0; + while (pos1 > -1) { + haystack = (typ == "attribute") ? rowClone.value : rowClone.innerHTML; + pos1 = haystack.indexOf("{{", pos1); + if (pos1 === -1) {break;} + pos2 = haystack.indexOf("}}", pos1 + 1); + needleToReplace = haystack.substring(pos1 + 2, pos2); + needle = needleToReplace.split("||"); + value = undefined; + for (i = 0; i < needle.length; i += 1) { + needle[i] = needle[i].replace(/^\s+|\s+$/gm, ''); //trim + //value = ((x && x[needle[i]]) || (data && data[needle[i]])); + if (x) {value = x[needle[i]];} + if (value == undefined && data) {value = data[needle[i]];} + if (value == undefined) { + cc = needle[i].split("."); + if (cc[0] == repeatX) {value = x[cc[1]]; } + } + if (value == undefined) { + if (needle[i] == repeatX) {value = x;} + } + if (value == undefined) { + if (needle[i].substr(0, 1) == '"') { + value = needle[i].replace(/"/g, ""); + } else if (needle[i].substr(0,1) == "'") { + value = needle[i].replace(/'/g, ""); + } + } + if (value != undefined) {break;} + } + if (value != undefined) { + r = "{{" + needleToReplace + "}}"; + if (typ == "attribute") { + rowClone.value = rowClone.value.replace(r, value); + } else { + w3ReplaceHTML(rowClone, r, value); + } + } + pos1 = pos1 + 1; + } + return rowClone; + } + function w3ReplaceHTML(a, r, result) { + var b, l, i, a, x, j; + if (a.hasAttributes()) { + b = a.attributes; + l = b.length; + for (i = 0; i < l; i += 1) { + if (b[i].value.indexOf(r) > -1) {b[i].value = b[i].value.replace(r, result);} + } + } + x = a.getElementsByTagName("*"); + l = x.length; + a.innerHTML = a.innerHTML.replace(r, result); + } +} +function w3IncludeHTML() { + var z, i, elmnt, file, xhttp; + z = document.getElementsByTagName("*"); + for (i = 0; i < z.length; i++) { + elmnt = z[i]; + file = elmnt.getAttribute("w3-include-html"); + if (file) { + xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function() { + if (this.readyState == 4 && this.status == 200) { + elmnt.innerHTML = this.responseText; + elmnt.removeAttribute("w3-include-html"); + w3IncludeHTML(); + } + } + xhttp.open("GET", file, true); + xhttp.send(); + return; + } + } +} +function w3Http(target, readyfunc, xml, method) { + var httpObj; + if (!method) {method = "GET"; } + if (window.XMLHttpRequest) { + httpObj = new XMLHttpRequest(); + } else if (window.ActiveXObject) { + httpObj = new ActiveXObject("Microsoft.XMLHTTP"); + } + if (httpObj) { + if (readyfunc) {httpObj.onreadystatechange = readyfunc;} + httpObj.open(method, target, true); + httpObj.send(xml); + } +} \ No newline at end of file diff --git a/doc/infosrc/Makefile b/doc/infosrc/Makefile index d25cd09d6..bd5a87159 100644 --- a/doc/infosrc/Makefile +++ b/doc/infosrc/Makefile @@ -88,7 +88,8 @@ GIF = $(SGIF) $(AGIF) $(MGIF) $(A2GIF) $(XGIF) DOTS = html2.gv html3.gv html4.gv tee.gv HTML = attrs.html colors.html command.html lang.html output.html shapes.html \ arrows.html schema.html -INSTALL_FILES = $(HTML) $(DOTS) $(SGIF) $(AGIF) $(A2GIF) $(MGIF) $(XGIF) $(MJPG) $(MPNG) +MISC = graphviz_json_schema.json w3data.js +INSTALL_FILES = $(HTML) $(DOTS) $(SGIF) $(AGIF) $(A2GIF) $(MGIF) $(XGIF) $(MJPG) $(MPNG) $(MISC) .SUFFIXES: .gv .gif .dot .png diff --git a/doc/infosrc/jconvert.py b/doc/infosrc/jconvert.py new file mode 100755 index 000000000..157f3d9ca --- /dev/null +++ b/doc/infosrc/jconvert.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python + +import json +from json2html import * + +def main(): + with open(sys.argv[1]) as inf: + inputs = inf.read() + input = json.loads(inputs) + output = json2html.convert(json = input, table_attributes="class=\"jsontable\"") + with open(sys.argv[2], 'w') as outf: + outf.write(output) + +main() diff --git a/doc/infosrc/output.1 b/doc/infosrc/output.1 index 7eb74c843..d125ee002 100644 --- a/doc/infosrc/output.1 +++ b/doc/infosrc/output.1 @@ -11,7 +11,7 @@ background-color: beige; } - + diff --git a/doc/infosrc/w3data.js b/doc/infosrc/w3data.js new file mode 100644 index 000000000..24fc4687d --- /dev/null +++ b/doc/infosrc/w3data.js @@ -0,0 +1,148 @@ +/* W3Data ver 1.31 by W3Schools.com */ +var w3DataObject = {}; +function w3DisplayData(id, data) { + var htmlObj, htmlTemplate, html, arr = [], a, l, rowClone, x, j, i, ii, cc, repeat, repeatObj, repeatX = ""; + htmlObj = document.getElementById(id); + htmlTemplate = w3InitTemplate(id, htmlObj); + html = htmlTemplate.cloneNode(true); + arr = w3GetElementsByAttribute(html, "w3-repeat"); + l = arr.length; + for (j = (l - 1); j >= 0; j -= 1) { + cc = arr[j].getAttribute("w3-repeat").split(" "); + if (cc.length == 1) { + repeat = cc[0]; + } else { + repeatX = cc[0]; + repeat = cc[2]; + } + arr[j].removeAttribute("w3-repeat"); + repeatObj = data[repeat]; + if (repeatObj && typeof repeatObj == "object" && repeatObj.length != "undefined") { + i = 0; + for (x in repeatObj) { + i += 1; + rowClone = arr[j]; + rowClone = w3NeedleInHaystack(rowClone, "element", repeatX, repeatObj[x]); + a = rowClone.attributes; + for (ii = 0; ii < a.length; ii += 1) { + a[ii].value = w3NeedleInHaystack(a[ii], "attribute", repeatX, repeatObj[x]).value; + } + (i === repeatObj.length) ? arr[j].parentNode.replaceChild(rowClone, arr[j]) : arr[j].parentNode.insertBefore(rowClone, arr[j]); + } + } else { + console.log("w3-repeat must be an array. " + repeat + " is not an array."); + continue; + } + } + html = w3NeedleInHaystack(html, "element"); + htmlObj.parentNode.replaceChild(html, htmlObj); + function w3InitTemplate(id, obj) { + var template; + template = obj.cloneNode(true); + if (w3DataObject.hasOwnProperty(id)) {return w3DataObject[id];} + w3DataObject[id] = template; + return template; + } + function w3GetElementsByAttribute(x, att) { + var arr = [], arrCount = -1, i, l, y = x.getElementsByTagName("*"), z = att.toUpperCase(); + l = y.length; + for (i = -1; i < l; i += 1) { + if (i == -1) {y[i] = x;} + if (y[i].getAttribute(z) !== null) {arrCount += 1; arr[arrCount] = y[i];} + } + return arr; + } + function w3NeedleInHaystack(elmnt, typ, repeatX, x) { + var value, rowClone, pos1, haystack, pos2, needle = [], needleToReplace, i, cc, r; + rowClone = elmnt.cloneNode(true); + pos1 = 0; + while (pos1 > -1) { + haystack = (typ == "attribute") ? rowClone.value : rowClone.innerHTML; + pos1 = haystack.indexOf("{{", pos1); + if (pos1 === -1) {break;} + pos2 = haystack.indexOf("}}", pos1 + 1); + needleToReplace = haystack.substring(pos1 + 2, pos2); + needle = needleToReplace.split("||"); + value = undefined; + for (i = 0; i < needle.length; i += 1) { + needle[i] = needle[i].replace(/^\s+|\s+$/gm, ''); //trim + //value = ((x && x[needle[i]]) || (data && data[needle[i]])); + if (x) {value = x[needle[i]];} + if (value == undefined && data) {value = data[needle[i]];} + if (value == undefined) { + cc = needle[i].split("."); + if (cc[0] == repeatX) {value = x[cc[1]]; } + } + if (value == undefined) { + if (needle[i] == repeatX) {value = x;} + } + if (value == undefined) { + if (needle[i].substr(0, 1) == '"') { + value = needle[i].replace(/"/g, ""); + } else if (needle[i].substr(0,1) == "'") { + value = needle[i].replace(/'/g, ""); + } + } + if (value != undefined) {break;} + } + if (value != undefined) { + r = "{{" + needleToReplace + "}}"; + if (typ == "attribute") { + rowClone.value = rowClone.value.replace(r, value); + } else { + w3ReplaceHTML(rowClone, r, value); + } + } + pos1 = pos1 + 1; + } + return rowClone; + } + function w3ReplaceHTML(a, r, result) { + var b, l, i, a, x, j; + if (a.hasAttributes()) { + b = a.attributes; + l = b.length; + for (i = 0; i < l; i += 1) { + if (b[i].value.indexOf(r) > -1) {b[i].value = b[i].value.replace(r, result);} + } + } + x = a.getElementsByTagName("*"); + l = x.length; + a.innerHTML = a.innerHTML.replace(r, result); + } +} +function w3IncludeHTML() { + var z, i, elmnt, file, xhttp; + z = document.getElementsByTagName("*"); + for (i = 0; i < z.length; i++) { + elmnt = z[i]; + file = elmnt.getAttribute("w3-include-html"); + if (file) { + xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function() { + if (this.readyState == 4 && this.status == 200) { + elmnt.innerHTML = this.responseText; + elmnt.removeAttribute("w3-include-html"); + w3IncludeHTML(); + } + } + xhttp.open("GET", file, true); + xhttp.send(); + return; + } + } +} +function w3Http(target, readyfunc, xml, method) { + var httpObj; + if (!method) {method = "GET"; } + if (window.XMLHttpRequest) { + httpObj = new XMLHttpRequest(); + } else if (window.ActiveXObject) { + httpObj = new ActiveXObject("Microsoft.XMLHTTP"); + } + if (httpObj) { + if (readyfunc) {httpObj.onreadystatechange = readyfunc;} + httpObj.open(method, target, true); + httpObj.send(xml); + } +} \ No newline at end of file