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

fix(svg): duplicate id for background rect with multiple charts #1002

Merged
merged 3 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/svg/Painter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class SVGPainter implements PainterBase {

const children: SVGVNode[] = [];

const bgVNode = this._bgVNode = createBackgroundVNode(width, height, this._backgroundColor, scope);
const bgVNode = this._bgVNode = createBackgroundVNode(this._id, width, height, this._backgroundColor, scope);
plainheart marked this conversation as resolved.
Show resolved Hide resolved
bgVNode && children.push(bgVNode);

// Ignore the root g if wan't the output to be more tight.
Expand Down Expand Up @@ -360,6 +360,7 @@ function createMethodNotSupport(method: string): any {
}

function createBackgroundVNode(
zrId: string,
width: number,
height: number,
backgroundColor: SVGPainterBackgroundColor,
Expand All @@ -375,7 +376,7 @@ function createBackgroundVNode(
height,
x: '0',
y: '0',
id: '0'
id: zrId + '-bg'
}
);
if (isGradient(backgroundColor)) {
Expand Down
12 changes: 10 additions & 2 deletions test/svg-backgroundColor.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
</head>
<body>
<div id="main" style="width:100vw;height:100vh;"></div>

<h2>This should not have a rect with the same id as the above instance.</h2>
<div id="main2" style="width:100vw;height:100vh;"></div>
<div class="opt-bar">
<button onclick="updateBg()">Change Background</button>
<select id="repeat">
Expand All @@ -42,7 +45,12 @@
}
});
zr.add(txt);


var zr2 = zrender.init(document.getElementById('main2'), {
renderer: 'svg'
});
zr2.add(txt);

var linearGradient = new zrender.LinearGradient();
linearGradient.addColorStop(0, '#a598e1');
linearGradient.addColorStop(1, '#14c4ba');
Expand Down Expand Up @@ -95,8 +103,8 @@
else {
bg = text = 'none';
}
console.log(text);
zr.setBackgroundColor(bg);
zr2.setBackgroundColor(bg);
txt.setStyle({ text: 'SVG BackgroundColor: ' + text });
i++;
}
Expand Down