bpmn-js/lib/Importer.js

32 lines
791 B
JavaScript

var _ = require('lodash');
var BpmnTreeWalker = require('./BpmnTreeWalker');
function importBpmnDiagram(diagram, definitions, done) {
var canvas = diagram.resolve('canvas');
var visitor = function(element, di, parent) {
if (di.$type === 'bpmndi:BPMNShape') {
var bounds = di.bounds;
canvas.addShape({ id: element.id, type: element.$type, x: bounds.x, y: bounds.y, width: bounds.width, height: bounds.height });
} else {
var waypoints = _.collect(di.waypoint, function(p) {
return { x: p.x, y: p.y };
});
canvas.addConnection({ id: element.id, waypoints: waypoints });
}
};
var walker = new BpmnTreeWalker(visitor);
walker.handleDefinitions(definitions);
done();
}
module.exports.importBpmnDiagram = importBpmnDiagram;