33# import " sample.typ"
44
55# let kernel-normal (x , stdev : 1.5 ) = {
6- (1 / calc . sqrt (2 * calc . pi * calc . pow (stdev ,2 ))) * calc . exp ( - (x * x )/ ( 2 * calc . pow (stdev ,2 )))
6+ (1 / calc . sqrt (2 * calc . pi * calc . pow (stdev , 2 ))) * calc . exp (- (x * x ) / ( 2 * calc . pow (stdev , 2 )))
77}
88
99# let _violin-render (self , ctx , violin , filling : true ) = {
1010 let path = range (self . samples )
11- . map ((t )=> violin . min + (violin . max - violin . min ) * (t / self . samples ))
12- . map ((u )=> (u , (violin . convolve )(u )))
13- . map (((u ,v )) => {
14- (violin . x-position + v , u )
15- })
11+ . map ((t )=> violin . min + (violin . max - violin . min ) * (t / self . samples ))
12+ . map ((u )=> (u , (violin . convolve )(u )))
13+ . map (((u ,v )) => {
14+ (violin . x-position + v , u )
15+ })
1616
1717 if self . side == " both" {
1818 path += path . rev (). map (((x ,y ))=> {(2 * violin . x-position - x ,y )})
1919 } else if self . side == " left" {
20- path = path . map ( ((x ,y ))=> { (2 * violin . x-position - x ,y )} )
20+ path = path . map (((x ,y )) => (2 * violin . x-position - x ,y ))
2121 }
2222
23- let (x , y ) = (ctx . x , ctx . y )
24- let stroke-paths = util . compute-stroke-paths (path , (x . min , y . min ), (x . max , y . max ))
23+ let stroke-paths = util . compute-stroke-paths (path , ctx . x , ctx . y )
2524
2625 for p in stroke-paths {
2726 let args = arguments (.. p , closed : self . side == " both" )
4645 min : min - (self . extents * range ),
4746 max : max + (self . extents * range ),
4847 convolve : (t ) => {
49- points . map (( y ) => (self . kernel )((y - t )/ self . bandwidth )). sum () / (points . len () * self . bandwidth )
48+ points . map (y => (self . kernel )((y - t ) / self . bandwidth )). sum () / (points . len () * self . bandwidth )
5049 }
5150 )
5251 })
7776// /
7877// / - data (array): Array of data items. An item is an array containing an `x` and one
7978// / or more `y` values.
80- // / - x-key (int, string): Key to use for retreiving the `x` position of the violin.
81- // / - y-key (int, string): Key to use for retreiving values of points within the category.
79+ // / - x-key (int, string): Key to use for retrieving the `x` position of the violin.
80+ // / - y-key (int, string): Key to use for retrieving values of points within the category.
8281// / - side (string): The sides of the violin to be rendered:
8382// / / left: Plot only the left side of the violin.
8483// / / right: Plot only the right side of the violin.
132131 plot-legend-preview : _plot-legend-preview ,
133132 ),)
134133
135- }
134+ }
0 commit comments