From 404c35c97ff4af0781b61d2e0015a3d316621269 Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Thu, 1 Dec 2016 13:17:44 +0100 Subject: [PATCH] fix(BpmnRenderer): revert text annotations automatic content fitting This reverts commit a53562e1d5ff37b91ad1e70d1069c15308802389. Closes #635 --- lib/draw/BpmnRenderer.js | 32 +++---------------- .../label-editing/LabelEditingProvider.js | 6 ++-- lib/features/rules/BpmnRules.js | 4 +++ test/spec/draw/BpmnRendererSpec.js | 2 +- .../label-editing/LabelEditingProviderSpec.js | 16 +++++----- .../modeling/append/TextAnnotationSpec.js | 2 +- .../modeling/layout/LayoutAssociationSpec.js | 6 ++-- .../features/snapping/BpmnSnappingSpec.js | 31 +++++++++++++++++- 8 files changed, 54 insertions(+), 45 deletions(-) diff --git a/lib/draw/BpmnRenderer.js b/lib/draw/BpmnRenderer.js index 3784af22..8b8b2e6d 100644 --- a/lib/draw/BpmnRenderer.js +++ b/lib/draw/BpmnRenderer.js @@ -1402,27 +1402,13 @@ function BpmnRenderer(eventBus, styles, pathMap, priority) { 'stroke': 'none' }; - var minHeight = 32, - minWidth = 100; - - var text = getSemantic(element).text || ''; - - // provide pseudo infinite max width, which is necessary to - // avoid automatic line breaks in createText - var box = { width: 9000, height: element.height, x: element.x, y: element.y }; - - var label = renderLabel(parentGfx, text, { box: box, align: 'left', padding: 5 }); - - var bbox = label.getBBox(); - - var height = Math.max(bbox.height + 18, minHeight), - width = Math.max(bbox.width, minWidth); + var textElement = drawRect(parentGfx, element.width, element.height, 0, 0, style); var textPathData = pathMap.getScaledPath('TEXT_ANNOTATION', { xScaleFactor: 1, yScaleFactor: 1, - containerWidth: width, - containerHeight: height, + containerWidth: element.width, + containerHeight: element.height, position: { mx: 0.0, my: 0.0 @@ -1430,16 +1416,8 @@ function BpmnRenderer(eventBus, styles, pathMap, priority) { }); drawPath(parentGfx, textPathData); - var dy = -((height - element.height) / 2); - - // adjust dimension and vertical position - assign(element, { - width: width, - height: height, - y: element.y + dy - }); - - var textElement = drawRect(parentGfx, element.width, element.height, 0, 0, style); + var text = getSemantic(element).text || ''; + renderLabel(parentGfx, text, { box: element, align: 'left-middle', padding: 5 }); return textElement; }, diff --git a/lib/features/label-editing/LabelEditingProvider.js b/lib/features/label-editing/LabelEditingProvider.js index c10c4eaf..3663e8f3 100644 --- a/lib/features/label-editing/LabelEditingProvider.js +++ b/lib/features/label-editing/LabelEditingProvider.js @@ -175,12 +175,10 @@ LabelEditingProvider.prototype.getEditingBBox = function(element) { // text annotations if (is(element, 'bpmn:TextAnnotation')) { - bounds.minWidth = element.width + PADDING; - bounds.minHeight = element.height; + bounds.minWidth = 100; + bounds.height = element.height; style.textAlign = 'left'; - style.paddingLeft = '4px'; - style.paddingTop = '7px'; } return { bounds: bounds, style: style }; diff --git a/lib/features/rules/BpmnRules.js b/lib/features/rules/BpmnRules.js index 0e2ef8b7..2498eedc 100644 --- a/lib/features/rules/BpmnRules.js +++ b/lib/features/rules/BpmnRules.js @@ -679,6 +679,10 @@ function canResize(shape, newBounds) { return !newBounds || (newBounds.width >= 250 && newBounds.height >= 50); } + if (isTextAnnotation(shape)) { + return true; + } + return false; } diff --git a/test/spec/draw/BpmnRendererSpec.js b/test/spec/draw/BpmnRendererSpec.js index 92fb136e..aec9ec83 100644 --- a/test/spec/draw/BpmnRendererSpec.js +++ b/test/spec/draw/BpmnRendererSpec.js @@ -274,7 +274,7 @@ describe('draw - bpmn renderer', function() { var TextAnnotationPath = graphicsFactory.getShapePath(TextAnnotationElement); // then - expect(TextAnnotationPath).to.equal('M368,180l100,0l0,32l-100,0z'); + expect(TextAnnotationPath).to.equal('M368,156l100,0l0,80l-100,0z'); })); }); diff --git a/test/spec/features/label-editing/LabelEditingProviderSpec.js b/test/spec/features/label-editing/LabelEditingProviderSpec.js index fe4d4405..fcac08e0 100644 --- a/test/spec/features/label-editing/LabelEditingProviderSpec.js +++ b/test/spec/features/label-editing/LabelEditingProviderSpec.js @@ -441,13 +441,13 @@ describe('features - label-editing', function() { describe('text annotation', function() { - it('[no text] should have element height', testTextboxSizing('text-annotation', 1, 106, 'auto')); + it('[no text] should have element height', testTextboxSizing('text-annotation', 1, 100, 98)); - it('[1 line text] should have element height', testTextboxSizing('text-annotation', 1, 106, 'auto', oneLineText)); + it('[1 line text] should have element height', testTextboxSizing('text-annotation', 1, 100, 98, oneLineText)); - it('[2 line text] should have extended height', testTextboxSizing('text-annotation', 1, 106, { min: 38 }, twoLineText)); + it('[2 line text] should have element height', testTextboxSizing('text-annotation', 1, 100, 98, twoLineText)); - it('[10 line text] should have extended height', testTextboxSizing('text-annotation', 1, 106, { min: 140 }, tenLineText)); + it('[10 line text] should have element height', testTextboxSizing('text-annotation', 1, { min: 100 }, 98, tenLineText)); }); @@ -556,13 +556,13 @@ describe('features - label-editing', function() { describe('text annotation', function() { - it('[no text] should have min width', testTextboxSizing('text-annotation', 1, 106, { min: 32 })); + it('[no text] should have min width', testTextboxSizing('text-annotation', 1, 100, 98)); - it('[one word] should have min width', testTextboxSizing('text-annotation', 1, 106, { min: 32 }, oneWord)); + it('[one word] should have min width', testTextboxSizing('text-annotation', 1, 100, 98, oneWord)); - it('[five words] should expand width', testTextboxSizing('text-annotation', 1, { min: 176 }, { min: 32 }, fiveWords)); + it('[five words] should expand width', testTextboxSizing('text-annotation', 1, { min: 176 }, 98, fiveWords)); - it('[long word] should expand width', testTextboxSizing('text-annotation', 1, { min: 129 }, { min: 32 }, longWord)); + it('[long word] should expand width', testTextboxSizing('text-annotation', 1, { min: 129 }, 98, longWord)); }); diff --git a/test/spec/features/modeling/append/TextAnnotationSpec.js b/test/spec/features/modeling/append/TextAnnotationSpec.js index b4a13743..7fc1e5f6 100644 --- a/test/spec/features/modeling/append/TextAnnotationSpec.js +++ b/test/spec/features/modeling/append/TextAnnotationSpec.js @@ -95,7 +95,7 @@ describe('features/modeling - append text-annotation', function() { //then expect(annotationShape.width).to.eql(100); - expect(annotationShape.height).to.eql(32); + expect(annotationShape.height).to.eql(30); })); }); diff --git a/test/spec/features/modeling/layout/LayoutAssociationSpec.js b/test/spec/features/modeling/layout/LayoutAssociationSpec.js index db8f7edd..9bf9019f 100644 --- a/test/spec/features/modeling/layout/LayoutAssociationSpec.js +++ b/test/spec/features/modeling/layout/LayoutAssociationSpec.js @@ -41,7 +41,7 @@ describe('features/modeling - layout association', function() { // then expect(waypoints).to.eql([ - { original: { x: 400, y: 400 }, x: 388, y: 384 }, + { original: { x: 400, y: 400 }, x: 389, y: 385 }, { original: { x: 191, y: 120 }, x: 202, y: 134 } ]); @@ -63,7 +63,7 @@ describe('features/modeling - layout association', function() { // then expect(waypoints).to.eql([ - { original: { x: 420, y: 400 }, x: 407, y: 384 }, + { original: { x: 420, y: 400 }, x: 408, y: 385 }, { original: { x: 191, y: 120 }, x: 202, y: 134 } ]); @@ -91,7 +91,7 @@ describe('features/modeling - layout association', function() { // then expect(waypoints).to.eql([ - { original: { x: 420, y: 400 }, x: 417, y: 384 }, + { original: { x: 420, y: 400 }, x: 417, y: 385 }, { x: 400, y: 300 }, { original: { x: 191, y: 120 }, x: 204, y: 131 } ]); diff --git a/test/spec/features/snapping/BpmnSnappingSpec.js b/test/spec/features/snapping/BpmnSnappingSpec.js index f9689f0a..eebd34fb 100644 --- a/test/spec/features/snapping/BpmnSnappingSpec.js +++ b/test/spec/features/snapping/BpmnSnappingSpec.js @@ -302,7 +302,7 @@ describe('features/snapping - BpmnSnapping', function() { dragging.end(); expect(participant.width).to.equal(467); - expect(participant.height).to.equal(263); + expect(participant.height).to.equal(287); })); @@ -437,6 +437,35 @@ describe('features/snapping - BpmnSnapping', function() { }); + describe('on TextAnnotation resize', function() { + + var diagramXML = require('./BpmnSnapping.textAnnotation-resize.bpmn'); + + var testResizeModules = [ + coreModule, + modelingModule, + resizeModule, + rulesModule, + snappingModule + ]; + + beforeEach(bootstrapModeler(diagramXML, { modules: testResizeModules })); + + + it('should snap to minimum bounds', inject(function(elementRegistry, resize, dragging) { + + var textAnnotation = elementRegistry.get('TextAnnotation'); + + resize.activate(canvasEvent({ x: 0, y: 0 }), textAnnotation, 'se'); + dragging.move(canvasEvent({ x: -400, y: -400 })); + dragging.end(); + + expect(textAnnotation.width).to.equal(50); + expect(textAnnotation.height).to.equal(30); + })); + + }); + describe('labels', function() { var diagramXML = require('./BpmnSnapping.labels.bpmn');