2014-03-20 15:18:23 +00:00
|
|
|
var bpmnModule = require('../di').defaultModule;
|
|
|
|
|
2014-03-20 16:51:05 +00:00
|
|
|
require('diagram-js/src/core/Events');
|
2014-03-25 13:08:11 +00:00
|
|
|
require('diagram-js/src/draw/Styles');
|
2014-03-20 16:51:05 +00:00
|
|
|
|
2014-03-20 15:18:23 +00:00
|
|
|
var DefaultRenderer = require('diagram-js/src/draw/Renderer');
|
|
|
|
|
2014-03-20 16:51:05 +00:00
|
|
|
|
|
|
|
var flattenPoints = DefaultRenderer.flattenPoints;
|
|
|
|
|
2014-03-25 13:08:11 +00:00
|
|
|
function BpmnRenderer(events, styles) {
|
|
|
|
|
|
|
|
DefaultRenderer.apply(this, [ events, styles ]);
|
2014-03-20 15:18:23 +00:00
|
|
|
|
|
|
|
var TASK_BORDER_RADIUS = 8;
|
|
|
|
var INNER_OUTER_DIST = 3;
|
|
|
|
|
2014-03-20 16:51:05 +00:00
|
|
|
var markers = {};
|
|
|
|
|
|
|
|
function addMarker(id, element) {
|
|
|
|
markers[id] = element;
|
|
|
|
}
|
|
|
|
|
|
|
|
function marker(id) {
|
|
|
|
return markers[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
function initMarkers(paper) {
|
|
|
|
|
|
|
|
addMarker('sequenceflow-end',
|
|
|
|
paper
|
|
|
|
.path('M 0 0 L 10 5 L 0 10 Z')
|
|
|
|
.attr({
|
|
|
|
'fill': 'black',
|
|
|
|
'stroke': 'none'
|
|
|
|
})
|
|
|
|
.marker(0, 0, 10, 10, 10, 5)
|
|
|
|
.attr({
|
|
|
|
markerUnits: 'strokeWidth',
|
|
|
|
markerWidth: 10,
|
|
|
|
markerHeight: 6,
|
|
|
|
orient: 'auto',
|
|
|
|
overflow: 'visible'
|
|
|
|
}));
|
|
|
|
|
|
|
|
addMarker('messageflow-start',
|
|
|
|
paper
|
|
|
|
.circle(4, 4, 4)
|
|
|
|
.attr({
|
|
|
|
fill: 'white',
|
|
|
|
stroke: 'black',
|
2014-03-21 15:54:34 +00:00
|
|
|
'stroke-width': 1,
|
2014-03-20 16:51:05 +00:00
|
|
|
'stroke-dasharray': '1,0'
|
|
|
|
})
|
|
|
|
.marker(0, 0, 10, 10, 4, 4)
|
|
|
|
.attr({
|
|
|
|
markerUnits: 'strokeWidth',
|
2014-03-21 15:54:34 +00:00
|
|
|
markerWidth: 7,
|
|
|
|
markerHeight: 7,
|
2014-03-20 16:51:05 +00:00
|
|
|
orient: 'auto',
|
|
|
|
overflow: 'visible'
|
|
|
|
}));
|
|
|
|
|
|
|
|
addMarker('messageflow-end',
|
|
|
|
paper
|
2014-03-22 00:45:38 +00:00
|
|
|
.path('M 0 0 L 10 5 L 0 10 Z')
|
2014-03-20 16:51:05 +00:00
|
|
|
.attr({
|
|
|
|
stroke: 'black',
|
2014-03-21 15:54:34 +00:00
|
|
|
fill: 'white',
|
|
|
|
'stroke-width': 1,
|
2014-03-20 16:51:05 +00:00
|
|
|
'stroke-linecap': 'round',
|
|
|
|
'stroke-dasharray': '1,0'
|
|
|
|
})
|
2014-03-25 13:08:11 +00:00
|
|
|
.marker(0, 0, 10, 10, 11, 5)
|
2014-03-20 16:51:05 +00:00
|
|
|
.attr({
|
|
|
|
markerUnits: 'strokeWidth',
|
2014-03-25 13:08:11 +00:00
|
|
|
markerWidth: 6,
|
|
|
|
markerHeight: 6,
|
2014-03-20 16:51:05 +00:00
|
|
|
orient: 'auto',
|
|
|
|
overflow: 'visible'
|
|
|
|
}));
|
|
|
|
|
|
|
|
addMarker('directed-association-end',
|
|
|
|
paper
|
|
|
|
.path('M 0 0 L 10 5 L 0 10 Z')
|
|
|
|
.attr('class', 'djs-connection-marker')
|
|
|
|
.marker(0, 0, 10, 10, 10, 5)
|
|
|
|
.attr({
|
|
|
|
stroke: 'black',
|
|
|
|
fill: 'none',
|
|
|
|
'stroke-width': 1.5,
|
|
|
|
'stroke-linecap': 'round',
|
|
|
|
'stroke-dasharray': '1,0'
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2014-03-20 15:18:23 +00:00
|
|
|
function drawCircle(p, width, height, offset) {
|
|
|
|
|
|
|
|
offset = offset || 0;
|
|
|
|
|
|
|
|
var cx = width / 2,
|
|
|
|
cy = height / 2;
|
|
|
|
|
|
|
|
return p.circle(cx, cy, Math.round((width + height) / 4 - offset)).attr({
|
|
|
|
'stroke': 'Black',
|
|
|
|
'stroke-width': 2,
|
|
|
|
'fill': 'White'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function drawRect(p, width, height, r, offset) {
|
|
|
|
offset = offset || 0;
|
|
|
|
|
|
|
|
var x, y;
|
|
|
|
|
|
|
|
x = y = offset;
|
|
|
|
|
|
|
|
return p.rect(offset, offset, width - offset * 2, height - offset * 2, r).attr({
|
|
|
|
'stroke': 'Black',
|
|
|
|
'stroke-width': 2,
|
|
|
|
'fill': 'White'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-03-20 16:51:05 +00:00
|
|
|
function drawDiamond(p, width, height) {
|
|
|
|
|
|
|
|
var x_2 = width / 2;
|
|
|
|
var y_2 = height / 2;
|
|
|
|
|
|
|
|
var points = [x_2, 0, width, y_2, x_2, height, 0, y_2 ];
|
|
|
|
|
|
|
|
return p.polygon(points).attr({
|
|
|
|
'stroke': 'Black',
|
|
|
|
'stroke-width': 2,
|
|
|
|
'fill': 'White'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function drawLine(p, waypoints) {
|
|
|
|
var points = flattenPoints(waypoints);
|
|
|
|
|
2014-03-25 13:08:11 +00:00
|
|
|
return p.polyline(points).attr(styles.style([ 'no-fill' ], {
|
2014-03-20 16:51:05 +00:00
|
|
|
'stroke-width': 2,
|
|
|
|
'stroke': 'Black'
|
2014-03-25 13:08:11 +00:00
|
|
|
}));
|
2014-03-20 16:51:05 +00:00
|
|
|
}
|
|
|
|
|
2014-03-20 15:18:23 +00:00
|
|
|
function as(type) {
|
|
|
|
return function(p, data) {
|
|
|
|
return handlers[type](p, data);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function renderer(type) {
|
|
|
|
return handlers[type];
|
|
|
|
}
|
|
|
|
|
|
|
|
var handlers = {
|
|
|
|
'bpmn:Event': function(p, data) {
|
|
|
|
var circle = drawCircle(p, data.width, data.height);
|
|
|
|
return circle;
|
|
|
|
},
|
|
|
|
'bpmn:StartEvent': as('bpmn:Event'),
|
|
|
|
'bpmn:EndEvent': function(p, data) {
|
|
|
|
var circle = renderer('bpmn:Event')(p, data);
|
|
|
|
|
|
|
|
circle.attr({
|
|
|
|
'stroke-width': 4
|
|
|
|
});
|
|
|
|
|
|
|
|
return circle;
|
|
|
|
},
|
|
|
|
'bpmn:IntermediateEvent': function(p, data) {
|
|
|
|
var outer = renderer('bpmn:Event')(p, data);
|
|
|
|
var inner = drawCircle(p, data.width, data.height, INNER_OUTER_DIST);
|
|
|
|
|
|
|
|
outer.attr('stroke-width', 1);
|
|
|
|
inner.attr('stroke-width', 1);
|
|
|
|
|
|
|
|
return outer;
|
|
|
|
},
|
|
|
|
'bpmn:IntermediateThrowEvent': as('bpmn:IntermediateEvent'),
|
|
|
|
'bpmn:IntermediateCatchEvent': as('bpmn:IntermediateEvent'),
|
|
|
|
|
|
|
|
'bpmn:Activity': function(p, data) {
|
|
|
|
var rect = drawRect(p, data.width, data.height, TASK_BORDER_RADIUS);
|
|
|
|
return rect;
|
|
|
|
},
|
|
|
|
|
|
|
|
'bpmn:Task': as('bpmn:Activity'),
|
|
|
|
'bpmn:ServiceTask': as('bpmn:Activity'),
|
|
|
|
'bpmn:UserTask': as('bpmn:Activity'),
|
|
|
|
'bpmn:ManualTask': as('bpmn:Activity'),
|
|
|
|
'bpmn:SendTask': as('bpmn:Activity'),
|
|
|
|
'bpmn:ReceiveTask': as('bpmn:Activity'),
|
|
|
|
'bpmn:ScriptTask': as('bpmn:Activity'),
|
|
|
|
'bpmn:BusinessRuleTask': as('bpmn:Activity'),
|
|
|
|
'bpmn:SubProcess': as('bpmn:Activity'),
|
|
|
|
'bpmn:AdHocSubProcess': as('bpmn:Activity'),
|
|
|
|
'bpmn:Transaction': function(p, data) {
|
|
|
|
var outer = renderer('bpmn:Activity')(p, data);
|
|
|
|
var inner = drawRect(p, data.width, data.height, TASK_BORDER_RADIUS - 2, INNER_OUTER_DIST);
|
|
|
|
|
|
|
|
outer.attr('stroke-width', 1.5);
|
|
|
|
inner.attr('stroke-width', 1.5);
|
|
|
|
|
|
|
|
return outer;
|
|
|
|
},
|
|
|
|
'bpmn:CallActivity': function(p, data) {
|
|
|
|
var rect = renderer('bpmn:Activity')(p, data);
|
|
|
|
rect.attr('stroke-width', 4);
|
|
|
|
return rect;
|
|
|
|
},
|
|
|
|
|
|
|
|
'bpmn:Participant': as('bpmn:Lane'),
|
|
|
|
'bpmn:Lane': function(p, data) {
|
|
|
|
var rect = drawRect(p, data.width, data.height, 0);
|
|
|
|
return rect;
|
2014-03-20 16:51:05 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
'bpmn:InclusiveGateway': as('bpmn:Gateway'),
|
|
|
|
'bpmn:ExclusiveGateway': as('bpmn:Gateway'),
|
|
|
|
'bpmn:ComplexGateway': as('bpmn:Gateway'),
|
|
|
|
'bpmn:ParallelGateway': as('bpmn:Gateway'),
|
|
|
|
'bpmn:EventBasedGateway': as('bpmn:Gateway'),
|
|
|
|
'bpmn:Gateway': function(p, data) {
|
|
|
|
|
|
|
|
var diamond = drawDiamond(p, data.width, data.height);
|
|
|
|
|
|
|
|
return diamond;
|
|
|
|
},
|
|
|
|
'bpmn:SequenceFlow': function(p, data) {
|
|
|
|
var polyline = drawLine(p, data.waypoints);
|
|
|
|
|
|
|
|
return polyline.attr({
|
|
|
|
'marker-end': marker('sequenceflow-end')
|
|
|
|
});
|
|
|
|
},
|
|
|
|
'bpmn:Association': function(p, data) {
|
|
|
|
var polyline = drawLine(p, data.waypoints);
|
|
|
|
|
|
|
|
// TODO(nre): style according to directed state
|
|
|
|
return polyline.attr({
|
|
|
|
'stroke-dasharray': '3,3'
|
|
|
|
});
|
|
|
|
},
|
|
|
|
'bpmn:MessageFlow': function(p, data) {
|
|
|
|
var polyline = drawLine(p, data.waypoints);
|
|
|
|
|
|
|
|
return polyline.attr({
|
|
|
|
'marker-end': marker('messageflow-end'),
|
|
|
|
'marker-start': marker('messageflow-start'),
|
|
|
|
'stroke-dasharray': '3,4'
|
|
|
|
});
|
2014-03-20 15:18:23 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function drawShape(parent, data) {
|
|
|
|
|
|
|
|
var type = data.type;
|
|
|
|
var h = handlers[type];
|
|
|
|
|
|
|
|
if (!h) {
|
2014-03-25 13:08:11 +00:00
|
|
|
return DefaultRenderer.prototype.drawShape.apply(this, [ parent, data ]);
|
2014-03-20 15:18:23 +00:00
|
|
|
} else {
|
|
|
|
return h(parent, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-20 16:51:05 +00:00
|
|
|
function drawConnection(parent, data) {
|
|
|
|
|
|
|
|
var type = data.type;
|
|
|
|
var h = handlers[type];
|
|
|
|
|
|
|
|
if (!h) {
|
2014-03-25 13:08:11 +00:00
|
|
|
return DefaultRenderer.prototype.drawConnection.apply(this, [ parent, data ]);
|
2014-03-20 16:51:05 +00:00
|
|
|
} else {
|
|
|
|
return h(parent, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// hook onto canvas init event to initialize
|
|
|
|
// connection start/end markers on paper
|
|
|
|
events.on('canvas.init', function(event) {
|
|
|
|
var paper = event.paper;
|
|
|
|
|
|
|
|
initMarkers(paper);
|
|
|
|
});
|
|
|
|
|
2014-03-20 15:18:23 +00:00
|
|
|
this.drawShape = drawShape;
|
2014-03-20 16:51:05 +00:00
|
|
|
this.drawConnection = drawConnection;
|
2014-03-20 15:18:23 +00:00
|
|
|
}
|
|
|
|
|
2014-03-25 13:08:11 +00:00
|
|
|
BpmnRenderer.prototype = Object.create(DefaultRenderer.prototype);
|
2014-03-20 15:18:23 +00:00
|
|
|
|
|
|
|
|
2014-03-25 13:08:11 +00:00
|
|
|
bpmnModule.type('renderer', [ 'events', 'styles', BpmnRenderer ]);
|
2014-03-20 15:18:23 +00:00
|
|
|
|
|
|
|
module.exports = BpmnRenderer;
|