From a1d93100907a37874ffdb258be78684e97652edc Mon Sep 17 00:00:00 2001 From: jos Date: Thu, 21 May 2015 16:15:56 +0200 Subject: [PATCH] Some minor fixed in dotparser --- lib/network/dotparser.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/network/dotparser.js b/lib/network/dotparser.js index 2e4c461a..6e38c9e8 100644 --- a/lib/network/dotparser.js +++ b/lib/network/dotparser.js @@ -17,7 +17,7 @@ function parseDOT (data) { } // mapping of attributes from DOT (the keys) to vis.js (the values) -var ATTR_MAPPING = { +var NODE_ATTR_MAPPING = { 'fontsize': 'font.size', 'fontcolor': 'font.color', 'labelfontcolor': 'font.color', @@ -27,6 +27,8 @@ var ATTR_MAPPING = { 'tooltip': 'title', 'labeltooltip': 'title' }; +var EDGE_ATTR_MAPPING = Object.create(NODE_ATTR_MAPPING); +EDGE_ATTR_MAPPING.color = 'color.color'; // token types enumeration var TOKENTYPE = { @@ -769,22 +771,23 @@ function setProp(object, path, value) { /** * Convert an object with DOT attributes to their vis.js equivalents. - * @param {Object} attr Object with DOT attributes - * @return {Object} Returns an object with vis.js attributes + * @param {Object} attr Object with DOT attributes + * @param {Object} mapping + * @return {Object} Returns an object with vis.js attributes */ -function convertAttr (attr) { +function convertAttr (attr, mapping) { var converted = {}; for (var prop in attr) { if (attr.hasOwnProperty(prop)) { - var mapping = ATTR_MAPPING[prop]; - if (Array.isArray(mapping)) { - mapping.forEach(function (mapping_i) { - setProp(converted, mapping_i, attr[prop]); + var visProp = mapping[prop]; + if (Array.isArray(visProp)) { + visProp.forEach(function (visPropI) { + setProp(converted, visPropI, attr[prop]); }) } - else if (typeof mapping === 'string') { - setProp(converted, mapping, attr[prop]); + else if (typeof visProp === 'string') { + setProp(converted, visProp, attr[prop]); } else { setProp(converted, prop, attr[prop]); @@ -817,7 +820,7 @@ function DOTToGraph (data) { id: dotNode.id, label: String(dotNode.label || dotNode.id) }; - merge(graphNode, convertAttr(dotNode.attr)); + merge(graphNode, convertAttr(dotNode.attr, NODE_ATTR_MAPPING)); if (graphNode.image) { graphNode.shape = 'image'; } @@ -837,7 +840,7 @@ function DOTToGraph (data) { from: dotEdge.from, to: dotEdge.to }; - merge(graphEdge, convertAttr(dotEdge.attr)); + merge(graphEdge, convertAttr(dotEdge.attr, EDGE_ATTR_MAPPING)); graphEdge.arrows = (dotEdge.type === '->') ? 'to' : undefined; return graphEdge;