all files / lib/features/label-editing/ LabelUtil.js

100% Statements 13/13
93.33% Branches 14/15
100% Functions 3/3
100% Lines 13/13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37      440×           417×     23× 15×         337× 337×   337× 329×           103× 103×   103× 103×     103×  
import { is } from '../../util/ModelUtil';
 
function getLabelAttr(semantic) {
  if (is(semantic, 'bpmn:FlowElement') ||
      is(semantic, 'bpmn:Participant') ||
      is(semantic, 'bpmn:Lane') ||
      is(semantic, 'bpmn:SequenceFlow') ||
      is(semantic, 'bpmn:MessageFlow')) {
 
    return 'name';
  }
 
  if (is(semantic, 'bpmn:TextAnnotation')) {
    return 'text';
  }
}
 
export function getLabel(element) {
  var semantic = element.businessObject,
      attr = getLabelAttr(semantic);
 
  if (attr) {
    return semantic[attr] || '';
  }
}
 
 
export function setLabel(element, text, isExternal) {
  var semantic = element.businessObject,
      attr = getLabelAttr(semantic);
 
  Eif (attr) {
    semantic[attr] = text;
  }
 
  return element;
}