From 9456ca9098c7c0a36519fcb37dd5d82b94f609c2 Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Sat, 26 Jul 2014 14:21:54 +0200 Subject: [PATCH] feat(features/modeling): assign default size for elements --- lib/features/modeling/ElementFactory.js | 30 ++++++++++++++++++++----- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/lib/features/modeling/ElementFactory.js b/lib/features/modeling/ElementFactory.js index f4015de6..e8536540 100644 --- a/lib/features/modeling/ElementFactory.js +++ b/lib/features/modeling/ElementFactory.js @@ -23,7 +23,8 @@ ElementFactory.prototype.createWithBpmn = function(elementType, attrs) { attrs = attrs || {}; - var businessObject = attrs.businessObject; + var businessObject = attrs.businessObject, + size; if (!businessObject) { if (!attrs.type) { @@ -31,13 +32,15 @@ ElementFactory.prototype.createWithBpmn = function(elementType, attrs) { } businessObject = this._bpmnFactory.create(attrs.type); - - _.extend(attrs, { - businessObject: businessObject, - id: businessObject.id - }); } + size = this._getDefaultSize(businessObject); + + attrs = _.extend({ + businessObject: businessObject, + id: businessObject.id + }, size, attrs); + return this.create(elementType, attrs); }; @@ -55,4 +58,19 @@ ElementFactory.prototype.createShape = function(attrs) { ElementFactory.prototype.createConnection = function(attrs) { return this.createWithBpmn('connection', attrs); +}; + +ElementFactory.prototype._getDefaultSize = function(semantic) { + + if (semantic.$instanceOf('bpmn:Task')) { + return { width: 100, height: 80 }; + } + + if (semantic.$instanceOf('bpmn:Gateway')) { + return { width: 36, height: 36 }; + } + + if (semantic.$instanceOf('bpmn:Event')) { + return { width: 36, height: 36 }; + } }; \ No newline at end of file