Skip to content

Commit 0aff315

Browse files
committed
Fix zero length arc draw in VML
1 parent f391930 commit 0aff315

File tree

2 files changed

+109
-5
lines changed

2 files changed

+109
-5
lines changed

src/vml/graphic.js

+27-5
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,32 @@ if (!require('../core/env').canvasSupported) {
356356
var y1 = cy + sin(endAngle) * ry;
357357

358358
var type = clockwise ? ' wa ' : ' at ';
359-
// IE won't render arches drawn counter clockwise if x0 == x1.
360-
if (Math.abs(x0 - x1) < 1e-10 && Math.abs(endAngle - startAngle) > 1e-2 && clockwise) {
361-
// Offset x0 by 1/80 of a pixel. Use something
362-
// that can be represented in binary
363-
x0 += 270 / Z;
359+
if (Math.abs(x0 - x1) < 1e-10) {
360+
// IE won't render arches drawn counter clockwise if x0 == x1.
361+
if (Math.abs(endAngle - startAngle) > 1e-2) {
362+
// Offset x0 by 1/80 of a pixel. Use something
363+
// that can be represented in binary
364+
if (clockwise) {
365+
x0 += 270 / Z;
366+
}
367+
}
368+
else {
369+
// Avoid case draw full circle
370+
if (Math.abs(y0 - cy) < 1e-10) {
371+
if ((clockwise && x0 < cx) || (!clockwise && x0 > cx)) {
372+
y1 -= 270 / Z;
373+
}
374+
else {
375+
y1 += 270 / Z;
376+
}
377+
}
378+
else if ((clockwise && y0 < cy) || (!clockwise && y0 > cy)) {
379+
x1 += 270 / Z;
380+
}
381+
else {
382+
x1 -= 270 / Z;
383+
}
384+
}
364385
}
365386
str.push(
366387
type,
@@ -426,6 +447,7 @@ if (!require('../core/env').canvasSupported) {
426447
}
427448
}
428449
}
450+
429451
return str.join('');
430452
};
431453

test/sector.html

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<script type="text/javascript" src="esl.js"></script>
6+
</head>
7+
<body>
8+
<script type="text/javascript">
9+
require.config({
10+
packages: [
11+
{
12+
name: 'zrender',
13+
location: '../src',
14+
main: 'zrender'
15+
}
16+
]
17+
});
18+
19+
require(['zrender', 'zrender/graphic/shape/Sector', 'zrender/vml/vml'], function(zrender, SectorShape){
20+
// 初始化zrender
21+
var zr = zrender.init(document.getElementById('main'));
22+
23+
zr.add(new SectorShape({
24+
position: [100, 100],
25+
scale: [1, 1],
26+
style: {
27+
stroke: 'black'
28+
},
29+
shape: {
30+
startAngle: -Math.PI / 2,
31+
endAngle: -Math.PI / 2,
32+
r0: 50,
33+
r: 100
34+
}
35+
}));
36+
37+
zr.add(new SectorShape({
38+
position: [100, 100],
39+
scale: [1, 1],
40+
style: {
41+
stroke: 'black'
42+
},
43+
shape: {
44+
startAngle: 0,
45+
endAngle: 0,
46+
r0: 50,
47+
r: 100
48+
}
49+
}));
50+
51+
zr.add(new SectorShape({
52+
position: [100, 100],
53+
scale: [1, 1],
54+
style: {
55+
stroke: 'black'
56+
},
57+
shape: {
58+
startAngle: Math.PI / 2,
59+
endAngle: Math.PI / 2,
60+
r0: 50,
61+
r: 100
62+
}
63+
}));
64+
65+
zr.add(new SectorShape({
66+
position: [100, 100],
67+
scale: [1, 1],
68+
style: {
69+
stroke: 'black'
70+
},
71+
shape: {
72+
startAngle: Math.PI,
73+
endAngle: Math.PI,
74+
r0: 50,
75+
r: 100
76+
}
77+
}));
78+
});
79+
</script>
80+
<div id="main" style="width:1000px;height:600px;"></div>
81+
</body>
82+
</html>

0 commit comments

Comments
 (0)