@@ -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