fix(label-editing): correctly compute direct-editing bbox

Closes #115
This commit is contained in:
Nico Rehwaldt 2014-09-09 15:21:21 +02:00
parent 0044a51bc5
commit a1044e2784
1 changed files with 16 additions and 10 deletions

View File

@ -8,9 +8,11 @@ var LabelUtil = require('./LabelUtil'),
DiUtil = require('../../util/Di'); DiUtil = require('../../util/Di');
var minBounds = { var PADDING = 4;
var MIN_BOUNDS = {
width: 150, width: 150,
height: 100 height: 50
}; };
@ -60,8 +62,8 @@ LabelEditingProvider.prototype.activate = function(element) {
if ((semantic.$instanceOf('bpmn:Participant') && DiUtil.isExpandedPool(semantic)) || if ((semantic.$instanceOf('bpmn:Participant') && DiUtil.isExpandedPool(semantic)) ||
semantic.$instanceOf('bpmn:Lane')) { semantic.$instanceOf('bpmn:Lane')) {
bbox.width = minBounds.width; bbox.width = MIN_BOUNDS.width;
bbox.height = minBounds.height; bbox.height = MIN_BOUNDS.height;
bbox.x = bbox.x + 10 - bbox.width / 2; bbox.x = bbox.x + 10 - bbox.width / 2;
bbox.y = bbox.mid.y - bbox.height / 2; bbox.y = bbox.mid.y - bbox.height / 2;
@ -70,7 +72,7 @@ LabelEditingProvider.prototype.activate = function(element) {
// adjust for sub processes // adjust for sub processes
if (semantic.$instanceOf('bpmn:SubProcess') && DiUtil.isExpanded(semantic, di)) { if (semantic.$instanceOf('bpmn:SubProcess') && DiUtil.isExpanded(semantic, di)) {
bbox.height = minBounds.height; bbox.height = MIN_BOUNDS.height;
bbox.x = bbox.mid.x - bbox.width / 2; bbox.x = bbox.mid.x - bbox.width / 2;
bbox.y = bbox.y + 10 - bbox.height / 2; bbox.y = bbox.y + 10 - bbox.height / 2;
@ -82,18 +84,22 @@ LabelEditingProvider.prototype.activate = function(element) {
LabelEditingProvider.prototype.getEditingBBox = function(element, maxBounds) { LabelEditingProvider.prototype.getEditingBBox = function(element, maxBounds) {
var bbox = this._canvas.getAbsoluteBBox(element.label || element); var target = element.label || element;
var bbox = this._canvas.getAbsoluteBBox(target);
var mid = { var mid = {
x: bbox.x + bbox.width / 2, x: bbox.x + bbox.width / 2,
y: bbox.y + bbox.height / 2 y: bbox.y + bbox.height / 2
}; };
bbox.width = Math.max(bbox.width, minBounds.width); // external label
bbox.height = Math.max(bbox.height, minBounds.height); if (target.labelTarget) {
bbox.width = Math.max(bbox.width, MIN_BOUNDS.width);
bbox.height = Math.max(bbox.height, MIN_BOUNDS.height);
bbox.x = mid.x - bbox.width / 2; bbox.x = mid.x - bbox.width / 2;
bbox.y = mid.y - bbox.height / 2; }
bbox.mid = mid; bbox.mid = mid;