Skip to content

Commit

Permalink
Merge pull request #1076 from ecomfe/fix/svg-color-compatibility
Browse files Browse the repository at this point in the history
fix(svg): set `pointer-events` as `visible` when fill/stroke color `none` in SSR mode & fix invalid `transparent` color issue
  • Loading branch information
Ovilia authored Jun 28, 2024
2 parents 71bde87 + 5f0427c commit 52e45b6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/svg/Painter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class SVGPainter implements PainterBase {
scope.willUpdate = opts.willUpdate;
scope.compress = opts.compress;
scope.emphasis = opts.emphasis;
scope.ssr = this._opts.ssr;

const children: SVGVNode[] = [];

Expand Down
2 changes: 2 additions & 0 deletions src/svg/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ export interface BrushScope {
* If compress the output string.
*/
compress?: boolean

ssr?: boolean
}

export function createBrushScope(zrId: string): BrushScope {
Expand Down
10 changes: 6 additions & 4 deletions src/svg/graphic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,15 @@ function setStyleAttrs(attrs: SVGVNodeAttrs, style: AllStyleOption, el: Path | T
else if (isFillStroke && isPattern(val)) {
setPattern(el, attrs, key, scope);
}
else if (isFillStroke && val === 'none') {
// When is none, it cannot be interacted when ssr
attrs[key] = 'transparent';
}
else {
attrs[key] = val;
}
if (isFillStroke && scope.ssr && val === 'none') {
// When is none, it cannot be interacted when ssr
// Setting `pointer-events` as `visible` to make it responding
// See also https://www.w3.org/TR/SVG/interact.html#PointerEventsProperty
attrs['pointer-events'] = 'visible';
}
}, style, el, false);

setShadow(el, attrs, scope);
Expand Down

0 comments on commit 52e45b6

Please sign in to comment.