@@ -70,32 +70,36 @@ export class Violin extends StatsBase<IViolinElementProps, IViolinElementOptions
70
70
} else {
71
71
maxEstimate = props . maxEstimate ;
72
72
}
73
+
74
+ ctx . beginPath ( ) ;
73
75
if ( this . isVertical ( ) ) {
74
76
const { x, width } = props ;
75
77
const factor = width / 2 / maxEstimate ;
76
- ctx . moveTo ( x , props . min ) ;
78
+
77
79
props . coords . forEach ( ( c ) => {
78
80
ctx . lineTo ( x - c . estimate * factor , c . v ) ;
79
81
} ) ;
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
+ } ) ;
86
89
} else {
87
90
const { y, height } = props ;
88
91
const factor = height / 2 / maxEstimate ;
89
- ctx . moveTo ( props . min , y ) ;
92
+
90
93
props . coords . forEach ( ( c ) => {
91
94
ctx . lineTo ( c . v , y - c . estimate * factor ) ;
92
95
} ) ;
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
+ } ) ;
99
103
}
100
104
ctx . closePath ( ) ;
101
105
ctx . stroke ( ) ;
0 commit comments