Skip to content

Commit

Permalink
chore: draw lines using dedicated utility
Browse files Browse the repository at this point in the history
  • Loading branch information
nikku committed Feb 1, 2023
1 parent 6ee0d9b commit 7be67b5
Showing 1 changed file with 16 additions and 23 deletions.
39 changes: 16 additions & 23 deletions lib/draw/BpmnRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,17 @@ export default function BpmnRenderer(
return line;
}

/**
* @param {SVGElement} parentGfx
* @param {Point[]} waypoints
* @param {any} attrs
*
* @return {SVGElement}
*/
function drawConnectionSegments(parentGfx, waypoints, attrs) {
return drawLine(parentGfx, waypoints, attrs);
}

function drawPath(parentGfx, d, attrs) {

attrs = lineStyle(attrs);
Expand Down Expand Up @@ -525,16 +536,6 @@ export default function BpmnRenderer(
transform(textBox, 0, -top, 270);
}

function createPathFromConnection(connection) {
var waypoints = connection.waypoints;

var pathData = 'm ' + waypoints[0].x + ',' + waypoints[0].y;
for (var i = 1; i < waypoints.length; i++) {
pathData += 'L' + waypoints[i].x + ',' + waypoints[i].y + ' ';
}
return pathData;
}

var handlers = this.handlers = {
'bpmn:Event': function(parentGfx, element, attrs) {

Expand Down Expand Up @@ -1356,17 +1357,13 @@ export default function BpmnRenderer(
});
},
'bpmn:SequenceFlow': function(parentGfx, element) {
var pathData = createPathFromConnection(element);

var fill = getFillColor(element, defaultFillColor),
stroke = getStrokeColor(element, defaultStrokeColor);

var attrs = {
var path = drawConnectionSegments(parentGfx, element.waypoints, {
markerEnd: marker('sequenceflow-end', fill, stroke),
stroke: getStrokeColor(element, defaultStrokeColor)
};

var path = drawPath(parentGfx, pathData, attrs);
});

var sequenceFlow = getSemantic(element);

Expand Down Expand Up @@ -1415,7 +1412,7 @@ export default function BpmnRenderer(
attrs.markerStart = marker('association-start', fill, stroke);
}

return drawLine(parentGfx, element.waypoints, attrs);
return drawConnectionSegments(parentGfx, element.waypoints, attrs);
},
'bpmn:DataInputAssociation': function(parentGfx, element) {
var fill = getFillColor(element, defaultFillColor),
Expand All @@ -1441,17 +1438,13 @@ export default function BpmnRenderer(
var fill = getFillColor(element, defaultFillColor),
stroke = getStrokeColor(element, defaultStrokeColor);

var pathData = createPathFromConnection(element);

var attrs = {
var path = drawConnectionSegments(parentGfx, element.waypoints, {
markerEnd: marker('messageflow-end', fill, stroke),
markerStart: marker('messageflow-start', fill, stroke),
strokeDasharray: '10, 11',
strokeWidth: '1.5px',
stroke: getStrokeColor(element, defaultStrokeColor)
};

var path = drawPath(parentGfx, pathData, attrs);
});

if (semantic.messageRef) {
var midPoint = path.getPointAtLength(path.getTotalLength() / 2);
Expand Down

0 comments on commit 7be67b5

Please sign in to comment.