Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 12 commits into from
Aug 15, 2024

Conversation

kumilingus
Copy link
Contributor

@kumilingus kumilingus commented Aug 10, 2024

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.

  • If there is no unset callback defined, an attribute with the same name as attribute definition is removed.
  • Otherwise, it can be a string (an attribute to be removed from the DOM element), an array of strings, or a function that returns the aforementioned string or array.
  • The callback accepts (node, attrs, cellView).
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'
  }
}

@kumilingus kumilingus marked this pull request as ready for review August 14, 2024 14:39
@zbynekstara zbynekstara merged commit 58df31d into clientIO:master Aug 15, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants