Skip to content

Commit 7f423d6

Browse files
committed
fix(svg): not convert 'transparent' color to 'none' to fix gradient color rendering bug
1 parent 247e119 commit 7f423d6

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/svg/helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const mathRound = Math.round;
1616

1717
export function normalizeColor(color: string): { color: string; opacity: number; } {
1818
let opacity;
19-
if (!color || color === 'transparent') {
19+
if (!color) {
2020
color = 'none';
2121
}
2222
else if (typeof color === 'string' && color.indexOf('rgba') > -1) {

test/svg-gradient.html

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>SVG Gradient</title>
6+
<script src="./lib/config.js"></script>
7+
<script src="../dist/zrender.js"></script>
8+
<meta name="viewport" content="width=device-width, initial-scale=1" />
9+
</head>
10+
<body>
11+
<div id="main"></div>
12+
<script type="text/javascript">
13+
var zr = zrender.init(document.getElementById('main'), {
14+
renderer: 'svg',
15+
width: 200,
16+
height: 200
17+
});
18+
zr.setBackgroundColor('navajowhite');
19+
20+
var linearGradient = new zrender.LinearGradient(0, 0, 0, 1);
21+
linearGradient.addColorStop(0, 'transparent');
22+
linearGradient.addColorStop(1, 'orange');
23+
24+
zr.add(
25+
new zrender.Rect({
26+
shape: {
27+
x: 100,
28+
y: 100,
29+
width: 20,
30+
height: 100,
31+
},
32+
style: {
33+
fill: linearGradient
34+
}
35+
})
36+
);
37+
</script>
38+
</body>
39+
</html>

0 commit comments

Comments
 (0)