From 7ccc9bf48e52fe525bd0c58439ed967d280dfaac Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Sat, 22 Mar 2014 01:47:03 +0100 Subject: [PATCH] feat(BpmnTreeWalker): handle loose processes / only selected DI --- lib/BpmnTreeWalker.js | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/lib/BpmnTreeWalker.js b/lib/BpmnTreeWalker.js index 759b5d53..3e666152 100644 --- a/lib/BpmnTreeWalker.js +++ b/lib/BpmnTreeWalker.js @@ -5,6 +5,9 @@ function BpmnTraverser(handler) { var elementDiMap = {}; var elementGfxMap = {}; + // list of containers already walked + var handledProcesses = []; + ///// Helpers ///////////////////////////////// function contextual(fn, ctx) { @@ -19,8 +22,15 @@ function BpmnTraverser(handler) { function visit(element, di, ctx) { + var gfx = elementGfxMap[element.id]; + + // avoid multiple rendering of elements + if (gfx) { + return gfx; + } + // call handler - var gfx = handler.element(element, di, ctx); + gfx = handler.element(element, di, ctx); // and log returned result elementGfxMap[element.id] = gfx; @@ -78,8 +88,6 @@ function BpmnTraverser(handler) { ////// Semantic handling ////////////////////// function handleDefinitions(definitions, diagram) { - buildDiMap(definitions); - // make sure we walk the correct bpmnElement var diagrams = definitions.diagrams; @@ -99,6 +107,9 @@ function BpmnTraverser(handler) { return; } + // load DI from selected diagram only + handleDiagram(diagram); + var rootElement = diagram.plane.bpmnElement; if (is(rootElement, 'bpmn:Process')) { @@ -106,11 +117,25 @@ function BpmnTraverser(handler) { } else if (is(rootElement, 'bpmn:Collaboration')) { handleCollaboration(rootElement); + + // force drawing of everything not yet drawn that is part of the target DI + handleUnhandledProcesses(definitions.rootElements); } else { throw new Error('unsupported root element for bpmndi:Diagram: ' + type.name); } } + function handleUnhandledProcesses(rootElements) { + + // walk through all processes that have not yet been drawn and draw them + // (in case they contain lanes with DI information) + var processes = _.forEach(rootElements, function(e) { + return e.$type === 'bpmn:Process' && e.laneSets && handledProcesses.indexOf(e) !== -1; + }); + + processes.forEach(contextual(handleProcess)); + } + function handleDataAssociation(association, context) { visitIfDi(association, context); } @@ -265,6 +290,9 @@ function BpmnTraverser(handler) { handleIoSpecification(process.ioSpecification, context); handleArtifacts(process.artifacts, context); + + // log process handled + handledProcesses.push(process); } function handleMessageFlow(messageFlow, context) {