clientIO / joint

A proven SVG-based JavaScript diagramming library powering exceptional UIs
https://jointjs.com
Mozilla Public License 2.0
4.72k stars 853 forks source link

feat(dia.CellView): add unset() attribute callback #2735

Closed kumilingus closed 3 months ago

kumilingus commented 3 months ago

Description

If you currently set sourceMarker and later try to remove it by setting it to null, marker-start SVG attribute will not be removed from the DOM. This is a mechanism to ensure that the actual presentation attributes can be removed if necessary.

This PR also defines TypeScript for defining custom special attributes and fixes various examples where special attributes were used.

Documentation

The unset callback for presentation attributes is called when an attribute is set to null.

attributes: {
  'line-style': {
      set: function(lineStyle, refBBox, node, attrs) {
          const n = parseFloat(attrs['stroke-width']) || 1;
          const dasharray = {
              'dashed': `${4*n},${2*n}`,
              'dotted': `${n},${n}`,
          }[lineStyle] || 'none';
          return { 'stroke-dasharray': dasharray };
      },
      unset: 'stroke-dasharray'
  }
}