From d95155acd302471efad13ae81b968d902c4506d6 Mon Sep 17 00:00:00 2001 From: Yasufumi Ogawa Date: Fri, 18 Aug 2017 23:44:47 +0900 Subject: [PATCH] Add edge styles support for DOT lib (#3348) * Add support for edge style * Update for TODO: support of solid/dotted/dashed edges (attr = 'style') * Edge styles are defined as var edgeStyles in parseAttributeList(). * Add example for edge styles Add an editable example for playing DOT edge styles * Correct typo and remove TODO description * Correct typo of filename from 'dotEdgeSytles.html' to 'dotEdgeStyles.html'. * Remove TODO description of the issue for edge style --- .../data/dotLanguage/dotEdgeStyles.html | 197 ++++++++++++++++++ lib/network/dotparser.js | 15 +- 2 files changed, 211 insertions(+), 1 deletion(-) create mode 100644 examples/network/data/dotLanguage/dotEdgeStyles.html diff --git a/examples/network/data/dotLanguage/dotEdgeStyles.html b/examples/network/data/dotLanguage/dotEdgeStyles.html new file mode 100644 index 000000000..9d5644b08 --- /dev/null +++ b/examples/network/data/dotLanguage/dotEdgeStyles.html @@ -0,0 +1,197 @@ + + + + Network | DOT edge styles + + + + + + + + + + + + +
+
+ +
+ +
+ + + + diff --git a/lib/network/dotparser.js b/lib/network/dotparser.js index 9bb7e3c1f..577f5ed90 100644 --- a/lib/network/dotparser.js +++ b/lib/network/dotparser.js @@ -52,6 +52,7 @@ var NODE_ATTR_MAPPING = { }; var EDGE_ATTR_MAPPING = Object.create(NODE_ATTR_MAPPING); EDGE_ATTR_MAPPING.color = 'color.color'; +EDGE_ATTR_MAPPING.style = 'dashes'; // token types enumeration var TOKENTYPE = { @@ -682,6 +683,13 @@ function parseEdge(graph, from) { function parseAttributeList() { var attr = null; + // edge styles of dot and vis + var edgeStyles = { + 'dashed': true, + 'solid': false, + 'dotted': [1, 5] + }; + while (token === '[') { getToken(); attr = {}; @@ -701,6 +709,12 @@ function parseAttributeList() { throw newSyntaxError('Attribute value expected'); } var value = token; + + // convert from dot style to vis + if (name === 'style') { + value = edgeStyles[value]; + } + setValue(attr, name, value); // name can be a path getToken(); @@ -885,7 +899,6 @@ function DOTToGraph (data) { } } - // TODO: support of solid/dotted/dashed edges (attr = 'style') // TODO: support for attributes 'dir' and 'arrowhead' (edge arrows) if (dotEdge.to instanceof Object) {