Skip to content

Commit 94450a7

Browse files
committed
Update Violin.ts
-Removed firstCoord and lastCoord. Redundant variables that were already being draw within the forEach loops and reverse forEach loop
1 parent e06fc92 commit 94450a7

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

src/elements/Violin.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,44 +70,36 @@ export class Violin extends StatsBase<IViolinElementProps, IViolinElementOptions
7070
} else {
7171
maxEstimate = props.maxEstimate;
7272
}
73-
const firstCoord = props.coords[0];
74-
const lastCoord = props.coords[props.coords.length - 1];
7573

7674
ctx.beginPath();
7775
if (this.isVertical()) {
7876
const { x, width } = props;
7977
const factor = width / 2 / maxEstimate;
80-
ctx.moveTo(x - firstCoord.estimate * factor, firstCoord.v);
78+
8179
props.coords.forEach((c) => {
8280
ctx.lineTo(x - c.estimate * factor, c.v);
8381
});
8482

85-
ctx.lineTo(x - lastCoord.estimate * factor, props.max);
86-
ctx.lineTo(x + lastCoord.estimate * factor, props.max);
8783
props.coords
8884
.slice()
8985
.reverse()
9086
.forEach((c) => {
9187
ctx.lineTo(x + c.estimate * factor, c.v);
9288
});
93-
ctx.lineTo(x - firstCoord.estimate * factor, firstCoord.v);
9489
} else {
9590
const { y, height } = props;
9691
const factor = height / 2 / maxEstimate;
97-
ctx.moveTo(firstCoord.v, y - firstCoord.estimate * factor);
92+
9893
props.coords.forEach((c) => {
9994
ctx.lineTo(c.v, y - c.estimate * factor);
10095
});
10196

102-
ctx.lineTo(props.max, y - props.coords[props.coords.length - 1].estimate * factor);
103-
ctx.lineTo(props.max, y + props.coords[props.coords.length - 1].estimate * factor);
10497
props.coords
10598
.slice()
10699
.reverse()
107100
.forEach((c) => {
108101
ctx.lineTo(c.v, y + c.estimate * factor);
109102
});
110-
ctx.lineTo(props.min, y - props.coords[0].estimate * factor);
111103
}
112104
ctx.closePath();
113105
ctx.stroke();

0 commit comments

Comments
 (0)