You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.1 KiB
54 lines
1.1 KiB
var _ = require("./lodash"); |
|
|
|
// Public utility functions |
|
module.exports = { |
|
isSubgraph: isSubgraph, |
|
edgeToId: edgeToId, |
|
applyStyle: applyStyle, |
|
applyClass: applyClass, |
|
applyTransition: applyTransition |
|
}; |
|
|
|
/* |
|
* Returns true if the specified node in the graph is a subgraph node. A |
|
* subgraph node is one that contains other nodes. |
|
*/ |
|
function isSubgraph(g, v) { |
|
return !!g.children(v).length; |
|
} |
|
|
|
function edgeToId(e) { |
|
return escapeId(e.v) + ":" + escapeId(e.w) + ":" + escapeId(e.name); |
|
} |
|
|
|
var ID_DELIM = /:/g; |
|
function escapeId(str) { |
|
return str ? String(str).replace(ID_DELIM, "\\:") : ""; |
|
} |
|
|
|
function applyStyle(dom, styleFn) { |
|
if (styleFn) { |
|
dom.attr("style", styleFn); |
|
} |
|
} |
|
|
|
function applyClass(dom, classFn, otherClasses) { |
|
if (classFn) { |
|
dom |
|
.attr("class", classFn) |
|
.attr("class", otherClasses + " " + dom.attr("class")); |
|
} |
|
} |
|
|
|
function applyTransition(selection, g) { |
|
var graph = g.graph(); |
|
|
|
if (_.isPlainObject(graph)) { |
|
var transition = graph.transition; |
|
if (_.isFunction(transition)) { |
|
return transition(selection); |
|
} |
|
} |
|
|
|
return selection; |
|
}
|
|
|