From 738a8a64f60bf71280e45c980d0713eae70bf5fd Mon Sep 17 00:00:00 2001 From: jdotzki Date: Mon, 19 May 2014 16:22:55 +0200 Subject: [PATCH] feat(bpmnrenderer): add default flow markers close #29 --- lib/draw/BpmnRenderer.js | 48 ++++++++- .../bpmn/render/conditional-default-flow.bpmn | 100 ++++++++++++++++++ test/spec/browser/draw/BpmnRendererSpec.js | 11 ++ 3 files changed, 156 insertions(+), 3 deletions(-) create mode 100644 test/fixtures/bpmn/render/conditional-default-flow.bpmn diff --git a/lib/draw/BpmnRenderer.js b/lib/draw/BpmnRenderer.js index 8af0d2d0..c0948aca 100644 --- a/lib/draw/BpmnRenderer.js +++ b/lib/draw/BpmnRenderer.js @@ -130,7 +130,7 @@ function BpmnRenderer(events, styles, bpmnRegistry, pathMap) { paper .path('M 0,0 7.089123,3.1832974 0.00383366,6.1129516 -7.0814464,3.1832966 z') .attr({ - 'fill': 'white', + 'fill': 'White', 'stroke': 'Black' }) .marker(0, 0, 15, 15, 0, 0) @@ -143,7 +143,27 @@ function BpmnRenderer(events, styles, bpmnRegistry, pathMap) { 'stroke-width': 1, 'stroke-dasharray': '1,0', 'refX': -8, - 'refY': 3.15 + 'refY': 3.15 + })); + + addMarker('conditional-default-flow-marker', + paper + .path('M 3,0 10,11') + .attr({ + 'fill': 'Black', + 'stroke': 'Black' + }) + .marker(0, 0, 15, 15, 0, 0) + .attr({ + markerUnits: 'strokeWidth', + markerWidth: 14.296, + markerHeight: 7.238, + orient: 'auto', + overflow: 'visible', + 'stroke-width': 1, + 'stroke-dasharray': '1,0', + 'refX': -4, + 'refY': 5.5 })); } @@ -1072,12 +1092,34 @@ function BpmnRenderer(events, styles, bpmnRegistry, pathMap) { 'bpmn:SequenceFlow': function(p, data) { var polyline = drawLine(p, data.waypoints); - if(!!bpmnRegistry.getSemantic(data.id).conditionExpression) { + var sequence = bpmnRegistry.getSemantic(data.id); + + // Conditional Flow Marker + if(!!sequence.conditionExpression) { polyline.attr({ 'marker-start': marker('conditional-flow-marker') }); } + // Default Marker + var srcRef = sequence.sourceRef; + if(!!srcRef) { + var source = bpmnRegistry.getSemantic(srcRef); + if(!!source && + (source.$type === 'bpmn:InclusiveGateway' || + source.$type === 'bpmn:ExclusiveGateway')) { + + if(!!source.default + && source.default.$type === 'bpmn:SequenceFlow' + && source.default.id === data.id) { + polyline.attr({ + 'marker-start': marker('conditional-default-flow-marker') + }); + } + console.log(source); + } + } + return polyline.attr({ 'marker-end': marker('sequenceflow-end') }); diff --git a/test/fixtures/bpmn/render/conditional-default-flow.bpmn b/test/fixtures/bpmn/render/conditional-default-flow.bpmn new file mode 100644 index 00000000..3ad66ded --- /dev/null +++ b/test/fixtures/bpmn/render/conditional-default-flow.bpmn @@ -0,0 +1,100 @@ + + + + + sid-F71776EB-FC77-47EC-A608-4D90422C9C9D + + + sid-F71776EB-FC77-47EC-A608-4D90422C9C9D + sid-8372F73C-BF60-4F06-A520-F3D010C17849 + sid-586C231A-A870-475A-9CC7-6E5EB7D96EA0 + + + sid-8372F73C-BF60-4F06-A520-F3D010C17849 + sid-2AD76A90-5C48-48D5-A1A4-B965E9A176F1 + + + sid-2AD76A90-5C48-48D5-A1A4-B965E9A176F1 + sid-3D50F08F-F5CA-41F5-8B2D-8AC1E3EE12C1 + sid-F24B422A-FC22-444F-9B47-B6220BC8BC79 + + + sid-3D50F08F-F5CA-41F5-8B2D-8AC1E3EE12C1 + sid-F861C2E1-3A74-4EE0-850B-ED7251335F00 + + + + + + + sid-F861C2E1-3A74-4EE0-850B-ED7251335F00 + + + sid-586C231A-A870-475A-9CC7-6E5EB7D96EA0 + sid-F24B422A-FC22-444F-9B47-B6220BC8BC79 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/spec/browser/draw/BpmnRendererSpec.js b/test/spec/browser/draw/BpmnRendererSpec.js index 4dce83c7..44fedaf2 100644 --- a/test/spec/browser/draw/BpmnRendererSpec.js +++ b/test/spec/browser/draw/BpmnRendererSpec.js @@ -28,6 +28,17 @@ describe('draw/BpmnRenderer', function() { }); }); + it('should render conditional default flows', function(done) { + + var xml = fs.readFileSync(__dirname + '/../../../fixtures/bpmn/render/conditional-default-flow.bpmn', 'utf8'); + + var renderer = new Viewer(container); + + renderer.importXML(xml, function(err) { + done(err); + }); + }); + it('should render conditional flows', function(done) { var xml = fs.readFileSync(__dirname + '/../../../fixtures/bpmn/render/conditional-flow.bpmn', 'utf8');