@@ -20,6 +20,10 @@ module.exports = function plot(gd, plotinfo, cdViolins, violinLayer) {
2020 var fullLayout = gd . _fullLayout ;
2121 var xa = plotinfo . xaxis ;
2222 var ya = plotinfo . yaxis ;
23+ var numViolins = fullLayout . _numViolins ;
24+ var group = ( fullLayout . violinmode === 'group' && numViolins > 1 ) ;
25+ var groupFraction = 1 - fullLayout . violingap ;
26+ var groupGapFraction = 1 - fullLayout . violingroupgap ;
2327
2428 function makePath ( pts ) {
2529 var segments = linePoints ( pts , {
@@ -39,16 +43,30 @@ module.exports = function plot(gd, plotinfo, cdViolins, violinLayer) {
3943 var t = cd0 . t ;
4044 var trace = cd0 . trace ;
4145 if ( ! plotinfo . isRangePlot ) cd0 . node3 = plotGroup ;
42- var numViolins = fullLayout . _numViolins ;
43- var group = ( fullLayout . violinmode === 'group' && numViolins > 1 ) ;
44- var groupFraction = 1 - fullLayout . violingap ;
46+
47+ // position coordinate delta
48+ var dPos = t . dPos ;
4549 // violin max half width
46- var bdPos = t . bdPos = t . dPos * groupFraction * ( 1 - fullLayout . violingroupgap ) / ( group ? numViolins : 1 ) ;
50+ var bdPos ;
4751 // violin center offset
48- var bPos = t . bPos = group ? 2 * t . dPos * ( - 0.5 + ( t . num + 0.5 ) / numViolins ) * groupFraction : 0 ;
52+ var bPos ;
4953 // half-width within which to accept hover for this violin
5054 // always split the distance to the closest violin
51- t . wHover = t . dPos * ( group ? groupFraction / numViolins : 1 ) ;
55+ var wHover ;
56+
57+ if ( trace . width ) {
58+ bdPos = dPos ;
59+ bPos = 0 ;
60+ wHover = dPos ;
61+ } else {
62+ bdPos = dPos * groupFraction * groupGapFraction / ( group ? numViolins : 1 ) ;
63+ bPos = group ? 2 * dPos * ( - 0.5 + ( t . num + 0.5 ) / numViolins ) * groupFraction : 0 ;
64+ wHover = dPos * ( group ? groupFraction / numViolins : 1 ) ;
65+ }
66+
67+ t . bdPos = bdPos ;
68+ t . bPos = bPos ;
69+ t . wHover = wHover ;
5270
5371 if ( trace . visible !== true || t . empty ) {
5472 plotGroup . remove ( ) ;
@@ -60,7 +78,6 @@ module.exports = function plot(gd, plotinfo, cdViolins, violinLayer) {
6078 var hasBothSides = trace . side === 'both' ;
6179 var hasPositiveSide = hasBothSides || trace . side === 'positive' ;
6280 var hasNegativeSide = hasBothSides || trace . side === 'negative' ;
63- var groupStats = fullLayout . _violinScaleGroupStats [ trace . scalegroup ] ;
6481
6582 var violins = plotGroup . selectAll ( 'path.violin' ) . data ( Lib . identity ) ;
6683
@@ -76,15 +93,15 @@ module.exports = function plot(gd, plotinfo, cdViolins, violinLayer) {
7693 var len = density . length ;
7794 var posCenter = d . pos + bPos ;
7895 var posCenterPx = posAxis . c2p ( posCenter ) ;
79- var scale ;
8096
81- switch ( trace . scalemode ) {
82- case 'width' :
83- scale = groupStats . maxWidth / bdPos ;
84- break ;
85- case 'count' :
86- scale = ( groupStats . maxWidth / bdPos ) * ( groupStats . maxCount / d . pts . length ) ;
87- break ;
97+ var scale ;
98+ if ( trace . width ) {
99+ scale = t . maxKDE / bdPos ;
100+ } else {
101+ var groupStats = fullLayout . _violinScaleGroupStats [ trace . scalegroup ] ;
102+ scale = trace . scalemode === 'count' ?
103+ ( groupStats . maxKDE / bdPos ) * ( groupStats . maxCount / d . pts . length ) :
104+ groupStats . maxKDE / bdPos ;
88105 }
89106
90107 var pathPos , pathNeg , path ;
0 commit comments