feat(label-editing): auto hide empty labels

Related to #105
This commit is contained in:
Nico Rehwaldt 2014-09-09 15:20:30 +02:00
parent b5483b2565
commit 0044a51bc5
4 changed files with 12 additions and 9 deletions

View File

@ -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,

View File

@ -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' } });
}

View File

@ -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;
};

View File

@ -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) {