@buggyorg/dupjoin
Advanced tools
Comparing version
@@ -18,2 +18,8 @@ 'use strict'; | ||
var defaultOptions = { | ||
createDuplicatesAndJoins: true, | ||
createIdNodes: true, | ||
addConsumeNodes: true | ||
}; | ||
function multipleOuts(graph) { | ||
@@ -104,2 +110,3 @@ return (0, _lodash2.default)(graph.nodes()).map(function (n) { | ||
w: to.node, | ||
name: from.node + '@' + from.port + '→' + to.node + '@' + to.node, | ||
value: { | ||
@@ -204,3 +211,3 @@ outPort: from.port, | ||
outputPorts: { | ||
output: compound.outputPorts[_edge.outPort] | ||
output: compound.inputPorts[_edge.outPort] | ||
}, | ||
@@ -276,8 +283,3 @@ settings: { | ||
function normalize(graph) { | ||
if (!_graphtools.utils.isNPG(graph)) { | ||
throw new Error('Cannot normalize non NPG.'); | ||
} | ||
var editGraph = _graphtools.graph.toJSON(graph); | ||
function createDupJoins(editGraph, graph) { | ||
var multiOuts = multipleOuts(graph); | ||
@@ -308,7 +310,24 @@ var multiIns = multipleIns(graph); | ||
editGraph.edges = _lodash2.default.compact(_lodash2.default.concat(oldEdges, dupsIn.edges, dupsOut.edges)); | ||
return editGraph; | ||
} | ||
editGraph = rewriteEdgesThroughCompoundNodes(editGraph); | ||
editGraph = addConsumeForUnusedPorts(editGraph); | ||
function normalize(graph, options) { | ||
options = options || {}; | ||
options = _lodash2.default.merge({}, defaultOptions, options); | ||
if (!_graphtools.utils.isNPG(graph)) { | ||
throw new Error('Cannot normalize non NPG.'); | ||
} | ||
var editGraph = _graphtools.graph.toJSON(graph); | ||
if (options.createDuplicatesAndJoins) { | ||
editGraph = createDupJoins(editGraph, graph); | ||
} | ||
if (options.createIdNodes) { | ||
editGraph = rewriteEdgesThroughCompoundNodes(editGraph); | ||
} | ||
if (options.addConsumeNodes) { | ||
editGraph = addConsumeForUnusedPorts(editGraph); | ||
} | ||
return _graphtools.graph.importJSON(editGraph); | ||
} |
{ | ||
"name": "@buggyorg/dupjoin", | ||
"version": "0.1.16", | ||
"version": "0.1.17", | ||
"description": "Program that removes multiple out and in edges in a NG.", | ||
@@ -25,3 +25,3 @@ "main": "lib/api.js", | ||
"dependencies": { | ||
"@buggyorg/graphtools": "^0.2.22", | ||
"@buggyorg/graphtools": "^0.3.1", | ||
"graphlib": "^2.1.0", | ||
@@ -28,0 +28,0 @@ "lodash": "^4.8.2" |
@@ -5,2 +5,8 @@ | ||
const defaultOptions = { | ||
createDuplicatesAndJoins: true, | ||
createIdNodes: true, | ||
addConsumeNodes: true | ||
} | ||
export function multipleOuts (graph) { | ||
@@ -93,2 +99,3 @@ return _(graph.nodes()) | ||
w: to.node, | ||
name: from.node + '@' + from.port + '→' + to.node + '@' + to.node, | ||
value: { | ||
@@ -197,3 +204,3 @@ outPort: from.port, | ||
outputPorts: { | ||
output: compound.outputPorts[edge.outPort] | ||
output: compound.inputPorts[edge.outPort] | ||
}, | ||
@@ -269,8 +276,3 @@ settings: { | ||
export function normalize (graph) { | ||
if (!utils.isNPG(graph)) { | ||
throw new Error('Cannot normalize non NPG.') | ||
} | ||
var editGraph = graphAPI.toJSON(graph) | ||
function createDupJoins (editGraph, graph) { | ||
var multiOuts = multipleOuts(graph) | ||
@@ -299,7 +301,24 @@ var multiIns = multipleIns(graph) | ||
editGraph.edges = _.compact(_.concat(oldEdges, dupsIn.edges, dupsOut.edges)) | ||
return editGraph | ||
} | ||
editGraph = rewriteEdgesThroughCompoundNodes(editGraph) | ||
editGraph = addConsumeForUnusedPorts(editGraph) | ||
export function normalize (graph, options) { | ||
options = options || {} | ||
options = _.merge({}, defaultOptions, options) | ||
if (!utils.isNPG(graph)) { | ||
throw new Error('Cannot normalize non NPG.') | ||
} | ||
var editGraph = graphAPI.toJSON(graph) | ||
if (options.createDuplicatesAndJoins) { | ||
editGraph = createDupJoins(editGraph, graph) | ||
} | ||
if (options.createIdNodes) { | ||
editGraph = rewriteEdgesThroughCompoundNodes(editGraph) | ||
} | ||
if (options.addConsumeNodes) { | ||
editGraph = addConsumeForUnusedPorts(editGraph) | ||
} | ||
return graphAPI.importJSON(editGraph) | ||
} |
@@ -124,2 +124,4 @@ /* global describe, it */ | ||
expect(newGraph.parent(idNode)).to.equal('nop_1') | ||
expect(newGraph.node(idNode).inputPorts.input).to.equal('generic') | ||
expect(newGraph.node(idNode).outputPorts.output).to.equal('generic') | ||
@@ -126,0 +128,0 @@ const edge1 = newGraph.edge(newGraph.edges().filter((e) => e.v === 'nop_1' && e.w === idNode)[0]) |
178017
0.66%6741
0.57%+ Added
- Removed
Updated