From 0044a51bc5f6c1e5fb04d8c496b7c8ac11867fa8 Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Tue, 9 Sep 2014 15:20:30 +0200 Subject: [PATCH] feat(label-editing): auto hide empty labels Related to #105 --- lib/core/BpmnImporter.js | 2 +- lib/draw/BpmnRenderer.js | 11 ++++++++--- lib/features/label-editing/LabelUtil.js | 4 ++-- lib/features/modeling/ElementFactory.js | 4 +--- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/core/BpmnImporter.js b/lib/core/BpmnImporter.js index a28551c6..68637e69 100644 --- a/lib/core/BpmnImporter.js +++ b/lib/core/BpmnImporter.js @@ -125,7 +125,7 @@ BpmnImporter.prototype.addLabel = function (semantic, element) { id: semantic.id + '_label', labelTarget: element, type: 'label', - hidden: element.hidden || !semantic.name, + hidden: element.hidden, x: bounds.x, y: bounds.y, width: bounds.width, diff --git a/lib/draw/BpmnRenderer.js b/lib/draw/BpmnRenderer.js index 7daf98e3..0adb77a4 100644 --- a/lib/draw/BpmnRenderer.js +++ b/lib/draw/BpmnRenderer.js @@ -3,7 +3,7 @@ var _ = require('lodash'); var DefaultRenderer = require('diagram-js/lib/draw/Renderer'); -var TextUtil = require('diagram-js/lib/util/TextUtil'); +var TextUtil = require('diagram-js/lib/util/Text'); var DiUtil = require('../util/Di'); @@ -22,7 +22,7 @@ function BpmnRenderer(events, styles, pathMap) { fontSize: '12px' }; - var labelUtil = new TextUtil({ + var textUtil = new TextUtil({ style: LABEL_STYLE, size: { width: 100 } }); @@ -276,7 +276,7 @@ function BpmnRenderer(events, styles, pathMap) { } function renderLabel(p, label, options) { - return labelUtil.createLabel(p, label || '', options).addClass('djs-label'); + return textUtil.createText(p, label || '', options).addClass('djs-label'); } function renderEmbeddedLabel(p, element, align) { @@ -286,6 +286,11 @@ function BpmnRenderer(events, styles, pathMap) { function renderExternalLabel(p, element, align) { var semantic = getSemantic(element); + + if (!semantic.name) { + element.hidden = true; + } + return renderLabel(p, semantic.name, { box: element, align: align, style: { fontSize: '11px' } }); } diff --git a/lib/features/label-editing/LabelUtil.js b/lib/features/label-editing/LabelUtil.js index e2b18fe8..8ba39932 100644 --- a/lib/features/label-editing/LabelUtil.js +++ b/lib/features/label-editing/LabelUtil.js @@ -33,8 +33,8 @@ module.exports.setLabel = function(element, text) { var label = element.label || element; - // hide label if not set - label.hidden = !text; + // show label + label.hidden = false; return label; }; \ No newline at end of file diff --git a/lib/features/modeling/ElementFactory.js b/lib/features/modeling/ElementFactory.js index df367a21..58dbd9d5 100644 --- a/lib/features/modeling/ElementFactory.js +++ b/lib/features/modeling/ElementFactory.js @@ -65,9 +65,7 @@ ElementFactory.prototype.createRoot = function(attrs) { }; ElementFactory.prototype.createLabel = function(attrs) { - return this.create('label', _.extend({ - type: 'label' - }, LabelUtil.DEFAULT_LABEL_SIZE, attrs)); + return this.create('label', _.extend({ type: 'label' }, LabelUtil.DEFAULT_LABEL_SIZE, attrs)); }; ElementFactory.prototype.createShape = function(attrs) {