From dc1f18a4972cee2d9e1bf46a6412dbb93b28506a Mon Sep 17 00:00:00 2001 From: Philipp Fromme Date: Wed, 23 May 2018 14:27:32 +0200 Subject: [PATCH] feat(bpmn-renderer): accept default fill and stroke color Related to #797 --- lib/draw/BpmnRenderer.js | 261 ++++++++++--------- test/fixtures/bpmn/draw/colors.bpmn | 375 ++++++++++++++-------------- test/spec/NavigatedViewerSpec.js | 10 +- test/spec/draw/BpmnRendererSpec.js | 124 ++++++++- 4 files changed, 459 insertions(+), 311 deletions(-) diff --git a/lib/draw/BpmnRenderer.js b/lib/draw/BpmnRenderer.js index 74713f2c..cfa974f5 100644 --- a/lib/draw/BpmnRenderer.js +++ b/lib/draw/BpmnRenderer.js @@ -68,11 +68,14 @@ var DEFAULT_FILL_OPACITY = .95, export default function BpmnRenderer( - eventBus, styles, pathMap, + config, eventBus, styles, pathMap, canvas, priority) { BaseRenderer.call(this, eventBus, priority); + var defaultFillColor = config.renderer && config.renderer.defaultFillColor, + defaultStrokeColor = config.renderer && config.renderer.defaultStrokeColor; + var rendererId = RENDERER_IDS.next(); var textUtil = new TextUtil({ @@ -448,7 +451,9 @@ export default function BpmnRenderer( function renderLabel(parentGfx, label, options) { var text = textUtil.createText(label || '', options); + svgClasses(text).add('djs-label'); + svgAppend(parentGfx, text); return text; @@ -462,7 +467,7 @@ export default function BpmnRenderer( align: align, padding: 5, style: { - fill: getStrokeColor(element) + fill: getStrokeColor(element, defaultStrokeColor) } }); } @@ -479,7 +484,10 @@ export default function BpmnRenderer( return renderLabel(parentGfx, semantic.name, { box: box, fitBox: true, - style: { fontSize: '11px' } + style: { + fontSize: '11px', + fill: getStrokeColor(element, defaultStrokeColor) + } }); } @@ -488,7 +496,7 @@ export default function BpmnRenderer( box: { height: 30, width: element.height }, align: 'center-middle', style: { - fill: getStrokeColor(element) + fill: getStrokeColor(element, defaultStrokeColor) } }); @@ -518,8 +526,8 @@ export default function BpmnRenderer( }, 'bpmn:StartEvent': function(parentGfx, element) { var attrs = { - fill: getFillColor(element), - stroke: getStrokeColor(element) + fill: getFillColor(element, defaultFillColor), + stroke: getStrokeColor(element, defaultStrokeColor) }; var semantic = getSemantic(element); @@ -527,7 +535,9 @@ export default function BpmnRenderer( if (!semantic.isInterrupting) { attrs = { strokeDasharray: '6', - strokeLinecap: 'round' + strokeLinecap: 'round', + fill: getFillColor(element, defaultFillColor), + stroke: getStrokeColor(element, defaultStrokeColor) }; } @@ -549,8 +559,8 @@ export default function BpmnRenderer( } }); - var fill = isThrowing ? getStrokeColor(element) : getFillColor(element); - var stroke = isThrowing ? getFillColor(element) : getStrokeColor(element); + var fill = isThrowing ? getStrokeColor(element, defaultStrokeColor) : getFillColor(element, defaultFillColor); + var stroke = isThrowing ? getFillColor(element, defaultFillColor) : getStrokeColor(element, defaultStrokeColor); var messagePath = drawPath(parentGfx, pathData, { strokeWidth: 1, @@ -563,8 +573,8 @@ export default function BpmnRenderer( 'bpmn:TimerEventDefinition': function(parentGfx, element) { var circle = drawCircle(parentGfx, element.width, element.height, 0.2 * element.height, { strokeWidth: 2, - fill: getFillColor(element), - stroke: getStrokeColor(element) + fill: getFillColor(element, defaultFillColor), + stroke: getStrokeColor(element, defaultStrokeColor) }); var pathData = pathMap.getScaledPath('EVENT_TIMER_WH', { @@ -581,7 +591,7 @@ export default function BpmnRenderer( drawPath(parentGfx, pathData, { strokeWidth: 2, strokeLinecap: 'square', - stroke: getStrokeColor(element) + stroke: getStrokeColor(element, defaultStrokeColor) }); for (var i = 0;i < 12;i++) { @@ -604,7 +614,7 @@ export default function BpmnRenderer( strokeWidth: 1, strokeLinecap: 'square', transform: 'rotate(' + (i * 30) + ',' + height + ',' + width + ')', - stroke: getStrokeColor(element) + stroke: getStrokeColor(element, defaultStrokeColor) }); } @@ -622,12 +632,12 @@ export default function BpmnRenderer( } }); - var fill = isThrowing ? getStrokeColor(event) : 'none'; + var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none'; return drawPath(parentGfx, pathData, { strokeWidth: 1, fill: fill, - stroke: getStrokeColor(event) + stroke: getStrokeColor(event, defaultStrokeColor) }); }, 'bpmn:ConditionalEventDefinition': function(parentGfx, event) { @@ -644,7 +654,7 @@ export default function BpmnRenderer( return drawPath(parentGfx, pathData, { strokeWidth: 1, - stroke: getStrokeColor(event) + stroke: getStrokeColor(event, defaultStrokeColor) }); }, 'bpmn:LinkEventDefinition': function(parentGfx, event, isThrowing) { @@ -659,12 +669,12 @@ export default function BpmnRenderer( } }); - var fill = isThrowing ? getStrokeColor(event) : 'none'; + var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none'; return drawPath(parentGfx, pathData, { strokeWidth: 1, fill: fill, - stroke: getStrokeColor(event) + stroke: getStrokeColor(event, defaultStrokeColor) }); }, 'bpmn:ErrorEventDefinition': function(parentGfx, event, isThrowing) { @@ -679,12 +689,12 @@ export default function BpmnRenderer( } }); - var fill = isThrowing ? getStrokeColor(event) : 'none'; + var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none'; return drawPath(parentGfx, pathData, { strokeWidth: 1, fill: fill, - stroke: getStrokeColor(event) + stroke: getStrokeColor(event, defaultStrokeColor) }); }, 'bpmn:CancelEventDefinition': function(parentGfx, event, isThrowing) { @@ -699,11 +709,12 @@ export default function BpmnRenderer( } }); - var fill = isThrowing ? 'black' : 'none'; + var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none'; var path = drawPath(parentGfx, pathData, { strokeWidth: 1, - fill: fill + fill: fill, + stroke: getStrokeColor(event, defaultStrokeColor) }); rotate(path, 45); @@ -722,12 +733,12 @@ export default function BpmnRenderer( } }); - var fill = isThrowing ? getStrokeColor(event) : 'none'; + var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none'; return drawPath(parentGfx, pathData, { strokeWidth: 1, fill: fill, - stroke: getStrokeColor(event) + stroke: getStrokeColor(event, defaultStrokeColor) }); }, 'bpmn:SignalEventDefinition': function(parentGfx, event, isThrowing) { @@ -742,12 +753,12 @@ export default function BpmnRenderer( } }); - var fill = isThrowing ? getStrokeColor(event) : 'none'; + var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none'; return drawPath(parentGfx, pathData, { strokeWidth: 1, fill: fill, - stroke: getStrokeColor(event) + stroke: getStrokeColor(event, defaultStrokeColor) }); }, 'bpmn:MultipleEventDefinition': function(parentGfx, event, isThrowing) { @@ -762,7 +773,7 @@ export default function BpmnRenderer( } }); - var fill = isThrowing ? 'black' : 'none'; + var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none'; return drawPath(parentGfx, pathData, { strokeWidth: 1, @@ -783,15 +794,15 @@ export default function BpmnRenderer( return drawPath(parentGfx, pathData, { strokeWidth: 1, - fill: getStrokeColor(event), - stroke: getStrokeColor(event) + fill: getStrokeColor(event, defaultStrokeColor), + stroke: getStrokeColor(event, defaultStrokeColor) }); }, 'bpmn:EndEvent': function(parentGfx, element) { var circle = renderer('bpmn:Event')(parentGfx, element, { strokeWidth: 4, - fill: getFillColor(element), - stroke: getStrokeColor(element) + fill: getFillColor(element, defaultFillColor), + stroke: getStrokeColor(element, defaultStrokeColor) }); renderEventContent(element, parentGfx, true); @@ -801,8 +812,8 @@ export default function BpmnRenderer( 'bpmn:TerminateEventDefinition': function(parentGfx, element) { var circle = drawCircle(parentGfx, element.width, element.height, 8, { strokeWidth: 4, - fill: getStrokeColor(element), - stroke: getStrokeColor(element) + fill: getStrokeColor(element, defaultStrokeColor), + stroke: getStrokeColor(element, defaultStrokeColor) }); return circle; @@ -810,14 +821,15 @@ export default function BpmnRenderer( 'bpmn:IntermediateEvent': function(parentGfx, element) { var outer = renderer('bpmn:Event')(parentGfx, element, { strokeWidth: 1, - fill: getFillColor(element), - stroke: getStrokeColor(element) + fill: getFillColor(element, defaultFillColor), + stroke: getStrokeColor(element, defaultStrokeColor) }); - /* inner */ drawCircle(parentGfx, element.width, element.height, INNER_OUTER_DIST, { + /* inner */ + drawCircle(parentGfx, element.width, element.height, INNER_OUTER_DIST, { strokeWidth: 1, fill: getFillColor(element, 'none'), - stroke: getStrokeColor(element) + stroke: getStrokeColor(element, defaultStrokeColor) }); renderEventContent(element, parentGfx); @@ -840,8 +852,8 @@ export default function BpmnRenderer( 'bpmn:Task': function(parentGfx, element) { var attrs = { - fill: getFillColor(element), - stroke: getStrokeColor(element) + fill: getFillColor(element, defaultFillColor), + stroke: getStrokeColor(element, defaultStrokeColor) }; var rect = renderer('bpmn:Activity')(parentGfx, element, attrs); @@ -863,8 +875,8 @@ export default function BpmnRenderer( /* service bg */ drawPath(parentGfx, pathDataBG, { strokeWidth: 1, - fill: getFillColor(element), - stroke: getStrokeColor(element) + fill: getFillColor(element, defaultFillColor), + stroke: getStrokeColor(element, defaultStrokeColor) }); var fillPathData = pathMap.getScaledPath('TASK_TYPE_SERVICE_FILL', { @@ -876,7 +888,7 @@ export default function BpmnRenderer( /* service fill */ drawPath(parentGfx, fillPathData, { strokeWidth: 0, - fill: getFillColor(element) + fill: getFillColor(element, defaultFillColor) }); var pathData = pathMap.getScaledPath('TASK_TYPE_SERVICE', { @@ -888,8 +900,8 @@ export default function BpmnRenderer( /* service */ drawPath(parentGfx, pathData, { strokeWidth: 1, - fill: getFillColor(element), - stroke: getStrokeColor(element) + fill: getFillColor(element, defaultFillColor), + stroke: getStrokeColor(element, defaultStrokeColor) }); return task; @@ -909,8 +921,8 @@ export default function BpmnRenderer( /* user path */ drawPath(parentGfx, pathData, { strokeWidth: 0.5, - fill: getFillColor(element), - stroke: getStrokeColor(element) + fill: getFillColor(element, defaultFillColor), + stroke: getStrokeColor(element, defaultStrokeColor) }); var pathData2 = pathMap.getScaledPath('TASK_TYPE_USER_2', { @@ -922,8 +934,8 @@ export default function BpmnRenderer( /* user2 path */ drawPath(parentGfx, pathData2, { strokeWidth: 0.5, - fill: getFillColor(element), - stroke: getStrokeColor(element) + fill: getFillColor(element, defaultFillColor), + stroke: getStrokeColor(element, defaultStrokeColor) }); var pathData3 = pathMap.getScaledPath('TASK_TYPE_USER_3', { @@ -935,8 +947,8 @@ export default function BpmnRenderer( /* user3 path */ drawPath(parentGfx, pathData3, { strokeWidth: 0.5, - fill: getStrokeColor(element), - stroke: getStrokeColor(element) + fill: getStrokeColor(element, defaultStrokeColor), + stroke: getStrokeColor(element, defaultStrokeColor) }); return task; @@ -953,8 +965,8 @@ export default function BpmnRenderer( /* manual path */ drawPath(parentGfx, pathData, { strokeWidth: 0.5, // 0.25, - fill: getFillColor(element), - stroke: getStrokeColor(element) + fill: getFillColor(element, defaultFillColor), + stroke: getStrokeColor(element, defaultStrokeColor) }); return task; @@ -975,8 +987,8 @@ export default function BpmnRenderer( /* send path */ drawPath(parentGfx, pathData, { strokeWidth: 1, - fill: getStrokeColor(element), - stroke: getFillColor(element) + fill: getStrokeColor(element, defaultStrokeColor), + stroke: getFillColor(element, defaultFillColor) }); return task; @@ -1012,8 +1024,8 @@ export default function BpmnRenderer( /* receive path */ drawPath(parentGfx, pathData, { strokeWidth: 1, - fill: getFillColor(element), - stroke: getStrokeColor(element) + fill: getFillColor(element, defaultFillColor), + stroke: getStrokeColor(element, defaultStrokeColor) }); return task; @@ -1030,7 +1042,7 @@ export default function BpmnRenderer( /* script path */ drawPath(parentGfx, pathData, { strokeWidth: 1, - stroke: getStrokeColor(element) + stroke: getStrokeColor(element, defaultStrokeColor) }); return task; @@ -1049,7 +1061,7 @@ export default function BpmnRenderer( svgAttr(businessHeaderPath, { strokeWidth: 1, fill: getFillColor(element, '#aaaaaa'), - stroke: getStrokeColor(element) + stroke: getStrokeColor(element, defaultStrokeColor) }); var headerData = pathMap.getScaledPath('TASK_TYPE_BUSINESS_RULE_MAIN', { @@ -1062,15 +1074,15 @@ export default function BpmnRenderer( var businessPath = drawPath(parentGfx, headerData); svgAttr(businessPath, { strokeWidth: 1, - stroke: getStrokeColor(element) + stroke: getStrokeColor(element, defaultStrokeColor) }); return task; }, 'bpmn:SubProcess': function(parentGfx, element, attrs) { attrs = assign({ - fill: getFillColor(element), - stroke: getStrokeColor(element) + fill: getFillColor(element, defaultFillColor), + stroke: getStrokeColor(element, defaultStrokeColor) }, attrs); var rect = renderer('bpmn:Activity')(parentGfx, element, attrs); @@ -1100,7 +1112,7 @@ export default function BpmnRenderer( var outer = renderer('bpmn:SubProcess')(parentGfx, element); var innerAttrs = styles.style([ 'no-fill', 'no-events' ], { - stroke: getStrokeColor(element) + stroke: getStrokeColor(element, defaultStrokeColor) }); /* inner path */ drawRect(parentGfx, element.width, element.height, TASK_BORDER_RADIUS - 2, INNER_OUTER_DIST, innerAttrs); @@ -1116,8 +1128,8 @@ export default function BpmnRenderer( var attrs = { fillOpacity: DEFAULT_FILL_OPACITY, - fill: getFillColor(element), - stroke: getStrokeColor(element) + fill: getFillColor(element, defaultFillColor), + stroke: getStrokeColor(element, defaultStrokeColor) }; var lane = renderer('bpmn:Lane')(parentGfx, element, attrs); @@ -1129,7 +1141,7 @@ export default function BpmnRenderer( { x: 30, y: 0 }, { x: 30, y: element.height } ], { - stroke: getStrokeColor(element) + stroke: getStrokeColor(element, defaultStrokeColor) }); var text = getSemantic(element).name; renderLaneLabel(parentGfx, text, element); @@ -1139,7 +1151,7 @@ export default function BpmnRenderer( renderLabel(parentGfx, text2, { box: element, align: 'center-middle', style: { - fill: getStrokeColor(element) + fill: getStrokeColor(element, defaultStrokeColor) } }); } @@ -1154,9 +1166,9 @@ export default function BpmnRenderer( }, 'bpmn:Lane': function(parentGfx, element, attrs) { var rect = drawRect(parentGfx, element.width, element.height, 0, assign({ - fill: getFillColor(element), + fill: getFillColor(element, defaultFillColor), fillOpacity: HIGH_FILL_OPACITY, - stroke: getStrokeColor(element) + stroke: getStrokeColor(element, defaultStrokeColor) }, attrs)); var semantic = getSemantic(element); @@ -1174,8 +1186,8 @@ export default function BpmnRenderer( /* circle path */ drawCircle(parentGfx, element.width, element.height, element.height * 0.24, { strokeWidth: 2.5, - fill: getFillColor(element), - stroke: getStrokeColor(element) + fill: getFillColor(element, defaultFillColor), + stroke: getStrokeColor(element, defaultStrokeColor) }); return diamond; @@ -1197,8 +1209,8 @@ export default function BpmnRenderer( if ((getDi(element).isMarkerVisible)) { drawPath(parentGfx, pathData, { strokeWidth: 1, - fill: getStrokeColor(element), - stroke: getStrokeColor(element) + fill: getStrokeColor(element, defaultStrokeColor), + stroke: getStrokeColor(element, defaultStrokeColor) }); } @@ -1220,8 +1232,8 @@ export default function BpmnRenderer( /* complex path */ drawPath(parentGfx, pathData, { strokeWidth: 1, - fill: getStrokeColor(element), - stroke: getStrokeColor(element) + fill: getStrokeColor(element, defaultStrokeColor), + stroke: getStrokeColor(element, defaultStrokeColor) }); return diamond; @@ -1242,8 +1254,8 @@ export default function BpmnRenderer( /* parallel path */ drawPath(parentGfx, pathData, { strokeWidth: 1, - fill: getStrokeColor(element), - stroke: getStrokeColor(element) + fill: getStrokeColor(element, defaultStrokeColor), + stroke: getStrokeColor(element, defaultStrokeColor) }); return diamond; @@ -1257,7 +1269,7 @@ export default function BpmnRenderer( /* outer circle path */ drawCircle(parentGfx, element.width, element.height, element.height * 0.20, { strokeWidth: 1, fill: 'none', - stroke: getStrokeColor(element) + stroke: getStrokeColor(element, defaultStrokeColor) }); var type = semantic.eventGatewayType; @@ -1279,7 +1291,7 @@ export default function BpmnRenderer( var attrs = { strokeWidth: 2, fill: getFillColor(element, 'none'), - stroke: getStrokeColor(element) + stroke: getStrokeColor(element, defaultStrokeColor) }; /* event path */ drawPath(parentGfx, pathData, attrs); @@ -1310,7 +1322,7 @@ export default function BpmnRenderer( svgAttr(innerCircle, { strokeWidth: 1, fill: 'none', - stroke: getStrokeColor(element) + stroke: getStrokeColor(element, defaultStrokeColor) }); } @@ -1322,9 +1334,9 @@ export default function BpmnRenderer( }, 'bpmn:Gateway': function(parentGfx, element) { var attrs = { - fill: getFillColor(element), + fill: getFillColor(element, defaultFillColor), fillOpacity: DEFAULT_FILL_OPACITY, - stroke: getStrokeColor(element) + stroke: getStrokeColor(element, defaultStrokeColor) }; return drawDiamond(parentGfx, element.width, element.height, attrs); @@ -1332,13 +1344,13 @@ export default function BpmnRenderer( 'bpmn:SequenceFlow': function(parentGfx, element) { var pathData = createPathFromConnection(element); - var fill = getFillColor(element), - stroke = getStrokeColor(element); + var fill = getFillColor(element, defaultFillColor), + stroke = getStrokeColor(element, defaultStrokeColor); var attrs = { strokeLinejoin: 'round', markerEnd: marker('sequenceflow-end', fill, stroke), - stroke: getStrokeColor(element) + stroke: getStrokeColor(element, defaultStrokeColor) }; var path = drawPath(parentGfx, pathData, attrs); @@ -1372,14 +1384,14 @@ export default function BpmnRenderer( var semantic = getSemantic(element); - var fill = getFillColor(element), - stroke = getStrokeColor(element); + var fill = getFillColor(element, defaultFillColor), + stroke = getStrokeColor(element, defaultStrokeColor); attrs = assign({ strokeDasharray: '0.5, 5', strokeLinecap: 'round', strokeLinejoin: 'round', - stroke: getStrokeColor(element) + stroke: getStrokeColor(element, defaultStrokeColor) }, attrs || {}); if (semantic.associationDirection === 'One' || @@ -1394,16 +1406,16 @@ export default function BpmnRenderer( return drawLine(parentGfx, element.waypoints, attrs); }, 'bpmn:DataInputAssociation': function(parentGfx, element) { - var fill = getFillColor(element), - stroke = getStrokeColor(element); + var fill = getFillColor(element, defaultFillColor), + stroke = getStrokeColor(element, defaultStrokeColor); return renderer('bpmn:Association')(parentGfx, element, { markerEnd: marker('association-end', fill, stroke) }); }, 'bpmn:DataOutputAssociation': function(parentGfx, element) { - var fill = getFillColor(element), - stroke = getStrokeColor(element); + var fill = getFillColor(element, defaultFillColor), + stroke = getStrokeColor(element, defaultStrokeColor); return renderer('bpmn:Association')(parentGfx, element, { markerEnd: marker('association-end', fill, stroke) @@ -1414,8 +1426,8 @@ export default function BpmnRenderer( var semantic = getSemantic(element), di = getDi(element); - var fill = getFillColor(element), - stroke = getStrokeColor(element); + var fill = getFillColor(element, defaultFillColor), + stroke = getStrokeColor(element, defaultStrokeColor); var pathData = createPathFromConnection(element); @@ -1426,7 +1438,7 @@ export default function BpmnRenderer( strokeLinecap: 'round', strokeLinejoin: 'round', strokeWidth: '1.5px', - stroke: getStrokeColor(element) + stroke: getStrokeColor(element, defaultStrokeColor) }; var path = drawPath(parentGfx, pathData, attrs); @@ -1469,9 +1481,9 @@ export default function BpmnRenderer( }); var elementObject = drawPath(parentGfx, pathData, { - fill: getFillColor(element), + fill: getFillColor(element, defaultFillColor), fillOpacity: DEFAULT_FILL_OPACITY, - stroke: getStrokeColor(element) + stroke: getStrokeColor(element, defaultStrokeColor) }); var semantic = getSemantic(element); @@ -1521,9 +1533,9 @@ export default function BpmnRenderer( var elementStore = drawPath(parentGfx, DATA_STORE_PATH, { strokeWidth: 2, - fill: getFillColor(element), + fill: getFillColor(element, defaultFillColor), fillOpacity: DEFAULT_FILL_OPACITY, - stroke: getStrokeColor(element) + stroke: getStrokeColor(element, defaultStrokeColor) }); return elementStore; @@ -1535,8 +1547,8 @@ export default function BpmnRenderer( var attrs = { strokeWidth: 1, - fill: getFillColor(element), - stroke: getStrokeColor(element) + fill: getFillColor(element, defaultFillColor), + stroke: getStrokeColor(element, defaultStrokeColor) }; if (!cancel) { @@ -1591,12 +1603,20 @@ export default function BpmnRenderer( my: 0.0 } }); + drawPath(parentGfx, textPathData, { - stroke: getStrokeColor(element) + stroke: getStrokeColor(element, defaultStrokeColor) }); var text = getSemantic(element).text || ''; - renderLabel(parentGfx, text, { box: element, align: 'left-top', padding: 5 }); + renderLabel(parentGfx, text, { + box: element, + align: 'left-top', + padding: 5, + style: { + fill: getStrokeColor(element, defaultStrokeColor) + } + }); return textElement; }, @@ -1612,13 +1632,17 @@ export default function BpmnRenderer( } }); - drawMarker('participant-multiplicity', parentGfx, markerPath); + drawMarker('participant-multiplicity', parentGfx, markerPath, { + strokeWidth: 1, + fill: getFillColor(element, defaultFillColor), + stroke: getStrokeColor(element, defaultStrokeColor) + }); }, 'SubProcessMarker': function(parentGfx, element) { var markerRect = drawRect(parentGfx, 14, 14, 0, { strokeWidth: 1, - fill: getFillColor(element), - stroke: getStrokeColor(element) + fill: getFillColor(element, defaultFillColor), + stroke: getStrokeColor(element, defaultStrokeColor) }); // Process marker is placed in the middle of the box @@ -1637,8 +1661,8 @@ export default function BpmnRenderer( }); drawMarker('sub-process', parentGfx, markerPath, { - fill: getFillColor(element), - stroke: getStrokeColor(element) + fill: getFillColor(element, defaultFillColor), + stroke: getStrokeColor(element, defaultStrokeColor) }); }, 'ParallelMarker': function(parentGfx, element, position) { @@ -1653,7 +1677,10 @@ export default function BpmnRenderer( } }); - drawMarker('parallel', parentGfx, markerPath); + drawMarker('parallel', parentGfx, markerPath, { + fill: getFillColor(element, defaultFillColor), + stroke: getStrokeColor(element, defaultStrokeColor) + }); }, 'SequentialMarker': function(parentGfx, element, position) { var markerPath = pathMap.getScaledPath('MARKER_SEQUENTIAL', { @@ -1667,7 +1694,10 @@ export default function BpmnRenderer( } }); - drawMarker('sequential', parentGfx, markerPath); + drawMarker('sequential', parentGfx, markerPath, { + fill: getFillColor(element, defaultFillColor), + stroke: getStrokeColor(element, defaultStrokeColor) + }); }, 'CompensationMarker': function(parentGfx, element, position) { var markerMath = pathMap.getScaledPath('MARKER_COMPENSATION', { @@ -1681,7 +1711,11 @@ export default function BpmnRenderer( } }); - drawMarker('compensation', parentGfx, markerMath, { strokeWidth: 1 }); + drawMarker('compensation', parentGfx, markerMath, { + strokeWidth: 1, + fill: getFillColor(element, defaultFillColor), + stroke: getStrokeColor(element, defaultStrokeColor) + }); }, 'LoopMarker': function(parentGfx, element, position) { var markerPath = pathMap.getScaledPath('MARKER_LOOP', { @@ -1697,7 +1731,8 @@ export default function BpmnRenderer( drawMarker('loop', parentGfx, markerPath, { strokeWidth: 1, - fill: 'none', + fill: getFillColor(element, defaultFillColor), + stroke: getStrokeColor(element, defaultStrokeColor), strokeLinecap: 'round', strokeMiterlimit: 0.5 }); @@ -1716,7 +1751,8 @@ export default function BpmnRenderer( drawMarker('adhoc', parentGfx, markerPath, { strokeWidth: 1, - fill: 'black' + fill: getStrokeColor(element, defaultStrokeColor), + stroke: getStrokeColor(element, defaultStrokeColor) }); } }; @@ -1806,6 +1842,7 @@ export default function BpmnRenderer( inherits(BpmnRenderer, BaseRenderer); BpmnRenderer.$inject = [ + 'config', 'eventBus', 'styles', 'pathMap', diff --git a/test/fixtures/bpmn/draw/colors.bpmn b/test/fixtures/bpmn/draw/colors.bpmn index 6a10217f..0d1b795e 100644 --- a/test/fixtures/bpmn/draw/colors.bpmn +++ b/test/fixtures/bpmn/draw/colors.bpmn @@ -1,5 +1,5 @@ - + @@ -26,6 +26,88 @@ + + SequenceFlow_1jrsqqc + + + + SequenceFlow_1jrsqqc + SequenceFlow_0h9s0mp + + + DataStoreReference_1clvrcw + Property_1vr5ovt + + + + SequenceFlow_0h9s0mp + SequenceFlow_0pqo7zt + SequenceFlow_1qt82pt + + + SequenceFlow_0pqo7zt + SequenceFlow_152w54z + + + SequenceFlow_1qt82pt + SequenceFlow_17ohrlh + + + SequenceFlow_17ohrlh + + + SequenceFlow_152w54z + SequenceFlow_1xvnonz + + + SequenceFlow_1xvnonz + SequenceFlow_0mbw4et + SequenceFlow_024djlt + SequenceFlow_02klp91 + + + SequenceFlow_0mbw4et + SequenceFlow_01w8xpk + + + + SequenceFlow_01w8xpk + SequenceFlow_17fk7n7 + + + SequenceFlow_17fk7n7 + SequenceFlow_1hytpfi + SequenceFlow_17yh2em + + + SequenceFlow_1hytpfi + SequenceFlow_1u8uz5a + + + SequenceFlow_024djlt + SequenceFlow_096z65r + + + + SequenceFlow_096z65r + SequenceFlow_17yh2em + SequenceFlow_0ld619c + + + + SequenceFlow_02klp91 + SequenceFlow_1xbxd38 + + + + SequenceFlow_1ooycy6 + + + SequenceFlow_0ld619c + + + SequenceFlow_1u8uz5a + SequenceFlow_1xbxd38 SequenceFlow_1ooycy6 @@ -38,144 +120,63 @@ - - SequenceFlow_1u8uz5a - - - SequenceFlow_0ld619c - - - SequenceFlow_1ooycy6 - - - SequenceFlow_02klp91 - SequenceFlow_1xbxd38 - - - - - SequenceFlow_096z65r - SequenceFlow_17yh2em - SequenceFlow_0ld619c - - - SequenceFlow_024djlt - SequenceFlow_096z65r - - - - SequenceFlow_1hytpfi - SequenceFlow_1u8uz5a - - - SequenceFlow_17fk7n7 - SequenceFlow_1hytpfi - SequenceFlow_17yh2em - - - SequenceFlow_01w8xpk - SequenceFlow_17fk7n7 - - - SequenceFlow_0mbw4et - SequenceFlow_01w8xpk - - - - SequenceFlow_1xvnonz - SequenceFlow_0mbw4et - SequenceFlow_024djlt - SequenceFlow_02klp91 - - - SequenceFlow_152w54z - SequenceFlow_1xvnonz - - - SequenceFlow_17ohrlh - - - SequenceFlow_1qt82pt - SequenceFlow_17ohrlh - - - SequenceFlow_0pqo7zt - SequenceFlow_152w54z - - - SequenceFlow_0h9s0mp - SequenceFlow_0pqo7zt - SequenceFlow_1qt82pt - - - SequenceFlow_1jrsqqc - SequenceFlow_0h9s0mp - - - DataStoreReference_1clvrcw - Property_1vr5ovt - - - - SequenceFlow_1jrsqqc - - - - + + Some random comment +can be added, too + - + - + - + - + - - - + + + - + - + - - + + - + - - + + - + - - - + + + @@ -183,126 +184,126 @@ can be added, too]]> - + - - + + - + - - + + - + - - + + - + - + - + - + - + - - - - + + + + - + - + - - - + + + - + - + - - + + - + - - + + - + - + - - + + - + - + - - + + - + - - + + - + - - - + + + @@ -310,20 +311,20 @@ can be added, too]]> - + - - + + - + - + @@ -333,78 +334,78 @@ can be added, too]]> - - + + - + - + - - - + + + - + - - - + + + - + - + - - + + - - - + + + - + - - + + - + - - - - + + + + - + - + - + - + - - - + + + diff --git a/test/spec/NavigatedViewerSpec.js b/test/spec/NavigatedViewerSpec.js index 825b8adb..e36fffd9 100644 --- a/test/spec/NavigatedViewerSpec.js +++ b/test/spec/NavigatedViewerSpec.js @@ -1,19 +1,19 @@ import NavigatedViewer from 'lib/NavigatedViewer'; +import TestContainer from 'mocha-test-container-support'; describe('NavigatedViewer', function() { var container; beforeEach(function() { - container = document.createElement('div'); - document.body.appendChild(container); + container = TestContainer.get(this); }); - - function createViewer(xml, done) { - var viewer = new NavigatedViewer({ container: container }); + var viewer = new NavigatedViewer({ + container: container + }); viewer.importXML(xml, function(err, warnings) { done(err, warnings, viewer); diff --git a/test/spec/draw/BpmnRendererSpec.js b/test/spec/draw/BpmnRendererSpec.js index 16badb6f..50d364fd 100644 --- a/test/spec/draw/BpmnRendererSpec.js +++ b/test/spec/draw/BpmnRendererSpec.js @@ -16,6 +16,12 @@ import { query as domQuery } from 'min-dom'; +import { isAny } from 'lib/features/modeling/util/ModelingUtil'; + +import { + getDi +} from 'lib/draw/BpmnRenderUtil'; + function checkErrors(done) { return function(err, warnings) { expect(warnings).to.be.empty; @@ -177,12 +183,6 @@ describe('draw - bpmn renderer', function() { }); - it('should render colors', function(done) { - var xml = require('../../fixtures/bpmn/draw/colors.bpmn'); - bootstrapViewer(xml)(checkErrors(done)); - }); - - it('should render call activity', function(done) { var xml = require('../../fixtures/bpmn/draw/call-activity.bpmn'); @@ -249,7 +249,10 @@ describe('draw - bpmn renderer', function() { expect(markers).to.have.length(5); expect(markers[0].id).to.match(/^sequenceflow-end-white-black-[A-Za-z0-9]{25}$/); - expect(markers[4].id).to.match(/^messageflow-start-white-fuchsia-[A-Za-z0-9]{25}$/); + expect(markers[1].id).to.match(/^sequenceflow-end-blue-blue-[A-Za-z0-9]{25}$/); + expect(markers[2].id).to.match(/^association-end-white-black-[A-Za-z0-9]{25}$/); + expect(markers[3].id).to.match(/^messageflow-end-white-black-[A-Za-z0-9]{25}$/); + expect(markers[4].id).to.match(/^messageflow-start-white-black-[A-Za-z0-9]{25}$/); })(); done(err); @@ -292,6 +295,113 @@ describe('draw - bpmn renderer', function() { }); + describe('colors', function() { + + var xml = require('../../fixtures/bpmn/draw/colors.bpmn'); + + + it('should render colors without warnings and errors', function(done) { + bootstrapViewer(xml)(checkErrors(done)); + }); + + + describe('default colors', function() { + + var defaultFillColor = 'red', + defaultStrokeColor = 'lime'; + + // TODO(philippfromme): remove once PhantomJS is not used anymore + var hexValues = { + blue: '#0000ff', + lime: '#00ff00', + red: '#ff0000', + yellow: '#ffff00' + }; + + beforeEach(bootstrapViewer(xml,{ + renderer: { + defaultFillColor: defaultFillColor, + defaultStrokeColor: defaultStrokeColor + } + })); + + function expectFillColor(element, color) { + expect([ color, hexValues[ color ]]).to.include(element.style.fill); + } + + function expectStrokeColor(element, color) { + expect([ color, hexValues[ color ]]).to.include(element.style.stroke); + } + + /** + * Expect colors depending on element type. + * + * @param {djs.model.base} element - Element. + * @param {SVG} gfx - Graphics of element. + * @param {String} fillColor - Fill color to expect. + * @param {String} strokeColor - Stroke color to expect. + */ + function expectColors(element, gfx, fillColor, strokeColor) { + var djsVisual = domQuery('.djs-visual', gfx); + + var circle, path, polygon, polyline, rect, text; + + if (element.labelTarget) { + text = domQuery('text', djsVisual); + + expectFillColor(text, strokeColor); + } else if (element.waypoints) { + path = domQuery('path', djsVisual); + polyline = domQuery('polyline', djsVisual); + + expectStrokeColor(path || polyline, strokeColor); + } else if (isAny(element, [ 'bpmn:StartEvent', 'bpmn:EndEvent' ])) { + circle = domQuery('circle', djsVisual); + + expectFillColor(circle, fillColor); + expectStrokeColor(circle, strokeColor); + } else if (isAny(element, [ 'bpmn:Task', 'bpmn:SubProcess', 'bpmn:Particpant' ])) { + rect = domQuery('rect', djsVisual); + text = domQuery('text', djsVisual); + + expectFillColor(rect, fillColor); + expectStrokeColor(rect, strokeColor); + expectFillColor(text, strokeColor); + } else if (isAny(element, [ 'bpmn:Gateway' ])) { + polygon = domQuery('polygon', djsVisual); + + expectFillColor(polygon, fillColor); + expectStrokeColor(polygon, strokeColor); + } + } + + + it('should render default colors without overriding', inject(function(canvas, elementRegistry) { + var rootElement = canvas.getRootElement(); + + elementRegistry.forEach(function(e) { + if (e === rootElement) { + return; + } + + var gfx = elementRegistry.getGraphics(e), + di = getDi(e), + fillColor = di.get('bioc:fill'), + strokeColor = di.get('bioc:stroke'); + + if (fillColor || strokeColor) { + expectColors(e, gfx, fillColor, strokeColor); + } else { + expectColors(e, gfx, defaultFillColor, defaultStrokeColor); + } + }); + })); + + }); + + }); + + describe('path', function() { var diagramXML = require('./BpmnRenderer.simple-cropping.bpmn');