Skip to content

Commit 5717ca9

Browse files
authored
feat(highlighters.stroke)!: add nonScalingStroke option (#2442)
1 parent 8558a53 commit 5717ca9

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

packages/joint-core/docs/src/joint/api/highlighters/stroke.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<li><b>ry</b> - the stroke's border radius on the y-axis</li>
99
<li><b>attrs</b> - an object with SVG attributes to be set on the highlighter element</li>
1010
<li><b>useFirstSubpath</b> - draw the stroke by using the first subpath of the target <code>el</code> compound path.</li>
11+
<li><b>nonScalingStroke</b> - when enabled the stroke width of the highlighter is not dependent on the transformations of the paper (e.g. zoom level). It defaults to <code>false</code>.</li>
1112
</ul>
1213

1314
<p>Example usage:</p>

packages/joint-core/src/highlighters/stroke.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export const stroke = HighlighterView.extend({
88
className: 'highlight-stroke',
99
attributes: {
1010
'pointer-events': 'none',
11-
'vector-effect': 'non-scaling-stroke',
1211
'fill': 'none'
1312
},
1413

@@ -88,6 +87,9 @@ export const stroke = HighlighterView.extend({
8887
highlight(cellView, node) {
8988
const { vel, options } = this;
9089
vel.attr(options.attrs);
90+
if (options.nonScalingStroke) {
91+
vel.attr('vector-effect', 'non-scaling-stroke');
92+
}
9193
if (cellView.isNodeConnection(node)) {
9294
this.highlightConnection(cellView);
9395
} else {

packages/joint-core/test/jointjs/dia/HighlighterView.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,28 @@ QUnit.module('HighlighterView', function(hooks) {
897897
assert.notEqual(elementView.el, highlighter.el.parentNode);
898898
});
899899

900+
QUnit.module('options', function() {
901+
902+
QUnit.test('nonScalingStroke', function(assert) {
903+
904+
const HighlighterView = joint.highlighters.stroke;
905+
const id = 'highlighter-id';
906+
907+
let highlighter;
908+
909+
// use default nonScalingStroke
910+
highlighter = HighlighterView.add(elementView, 'body', id);
911+
assert.equal(getComputedStyle(highlighter.el).vectorEffect, 'none');
912+
913+
// explicit nonScalingStroke = false
914+
highlighter = HighlighterView.add(elementView, 'body', id, { nonScalingStroke: false });
915+
assert.equal(getComputedStyle(highlighter.el).vectorEffect, 'none');
916+
917+
// explicit nonScalingStroke = true
918+
highlighter = HighlighterView.add(elementView, 'body', id, { nonScalingStroke: true });
919+
assert.equal(getComputedStyle(highlighter.el).vectorEffect, 'non-scaling-stroke');
920+
});
921+
});
900922

901923
QUnit.module('Rendering', function() {
902924

packages/joint-core/types/joint.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,6 +1966,7 @@ export namespace highlighters {
19661966
rx?: number;
19671967
ry?: number;
19681968
useFirstSubpath?: boolean;
1969+
nonScalingStroke?: boolean;
19691970
attrs?: attributes.NativeSVGAttributes;
19701971
}
19711972

0 commit comments

Comments
 (0)