Skip to content

Commit

Permalink
feat(dia.CellView): add unset() attribute callback (#2735)
Browse files Browse the repository at this point in the history
  • Loading branch information
kumilingus authored Aug 15, 2024
1 parent 9e22400 commit 58df31d
Show file tree
Hide file tree
Showing 16 changed files with 538 additions and 142 deletions.
13 changes: 7 additions & 6 deletions examples/tree-of-life/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,16 @@ class Branch extends dia.Link {
static attributes = {
// The `organicStroke` attribute is used to set the `d` attribute of the `<path>` element.
// It works similarly to the `connection` attribute of JointJS.
organicStroke: {
qualify: function () {
return this.model.isLink();
},
'organic-stroke': {
set: function (
_value: any,
_refBBox: g.Rect,
_node: SVGElement,
attrs: attributes.NativeSVGAttributes
) {
if (!this.model.isLink()) {
throw new Error('The `organicStroke` attribute can only be used with links.');
}
// The path of the link as returned by the `connector`.
const path = this.getConnection();
const segmentSubdivisions = this.getConnectionSubdivisions();
Expand All @@ -231,7 +231,7 @@ class Branch extends dia.Link {
// Using the `getStroke` function from the `perfect-freehand` library,
// we get the points that represent the outline of the stroke.
const outlinePoints = getStroke(points, {
size: attrs.organicStrokeSize || 20,
size: attrs['organic-stroke-size'] || 20,
thinning: 0.5,
simulatePressure: false,
last: true,
Expand All @@ -241,10 +241,11 @@ class Branch extends dia.Link {
// The `d` attribute is set on the `node` element.
return { d };
},
unset: 'd'
},
// Empty attributes definition to prevent the attribute from being set on the element.
// They are only meant to be used in the `organicStroke` function.
organicStrokeSize: {},
'organic-stroke-size': {},
};
}

Expand Down
Loading

0 comments on commit 58df31d

Please sign in to comment.