Skip to content

Commit 27be5c6

Browse files
authored
Merge pull request #147 from zqwitt/improvements/_drawCoords
Updated _drawCoords()
2 parents 159747f + 94450a7 commit 27be5c6

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed
-1.27 KB
Loading

src/elements/Violin.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,32 +70,36 @@ export class Violin extends StatsBase<IViolinElementProps, IViolinElementOptions
7070
} else {
7171
maxEstimate = props.maxEstimate;
7272
}
73+
74+
ctx.beginPath();
7375
if (this.isVertical()) {
7476
const { x, width } = props;
7577
const factor = width / 2 / maxEstimate;
76-
ctx.moveTo(x, props.min);
78+
7779
props.coords.forEach((c) => {
7880
ctx.lineTo(x - c.estimate * factor, c.v);
7981
});
80-
ctx.lineTo(x, props.max);
81-
ctx.moveTo(x, props.min);
82-
props.coords.forEach((c) => {
83-
ctx.lineTo(x + c.estimate * factor, c.v);
84-
});
85-
ctx.lineTo(x, props.max);
82+
83+
props.coords
84+
.slice()
85+
.reverse()
86+
.forEach((c) => {
87+
ctx.lineTo(x + c.estimate * factor, c.v);
88+
});
8689
} else {
8790
const { y, height } = props;
8891
const factor = height / 2 / maxEstimate;
89-
ctx.moveTo(props.min, y);
92+
9093
props.coords.forEach((c) => {
9194
ctx.lineTo(c.v, y - c.estimate * factor);
9295
});
93-
ctx.lineTo(props.max, y);
94-
ctx.moveTo(props.min, y);
95-
props.coords.forEach((c) => {
96-
ctx.lineTo(c.v, y + c.estimate * factor);
97-
});
98-
ctx.lineTo(props.max, y);
96+
97+
props.coords
98+
.slice()
99+
.reverse()
100+
.forEach((c) => {
101+
ctx.lineTo(c.v, y + c.estimate * factor);
102+
});
99103
}
100104
ctx.closePath();
101105
ctx.stroke();

0 commit comments

Comments
 (0)