@@ -20,6 +20,10 @@ module.exports = function plot(gd, plotinfo, cdViolins, violinLayer) {
20
20
var fullLayout = gd . _fullLayout ;
21
21
var xa = plotinfo . xaxis ;
22
22
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 ;
23
27
24
28
function makePath ( pts ) {
25
29
var segments = linePoints ( pts , {
@@ -39,16 +43,30 @@ module.exports = function plot(gd, plotinfo, cdViolins, violinLayer) {
39
43
var t = cd0 . t ;
40
44
var trace = cd0 . trace ;
41
45
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 ;
45
49
// violin max half width
46
- var bdPos = t . bdPos = t . dPos * groupFraction * ( 1 - fullLayout . violingroupgap ) / ( group ? numViolins : 1 ) ;
50
+ var bdPos ;
47
51
// violin center offset
48
- var bPos = t . bPos = group ? 2 * t . dPos * ( - 0.5 + ( t . num + 0.5 ) / numViolins ) * groupFraction : 0 ;
52
+ var bPos ;
49
53
// half-width within which to accept hover for this violin
50
54
// 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 ;
52
70
53
71
if ( trace . visible !== true || t . empty ) {
54
72
plotGroup . remove ( ) ;
@@ -60,7 +78,6 @@ module.exports = function plot(gd, plotinfo, cdViolins, violinLayer) {
60
78
var hasBothSides = trace . side === 'both' ;
61
79
var hasPositiveSide = hasBothSides || trace . side === 'positive' ;
62
80
var hasNegativeSide = hasBothSides || trace . side === 'negative' ;
63
- var groupStats = fullLayout . _violinScaleGroupStats [ trace . scalegroup ] ;
64
81
65
82
var violins = plotGroup . selectAll ( 'path.violin' ) . data ( Lib . identity ) ;
66
83
@@ -76,15 +93,15 @@ module.exports = function plot(gd, plotinfo, cdViolins, violinLayer) {
76
93
var len = density . length ;
77
94
var posCenter = d . pos + bPos ;
78
95
var posCenterPx = posAxis . c2p ( posCenter ) ;
79
- var scale ;
80
96
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 ;
88
105
}
89
106
90
107
var pathPos , pathNeg , path ;
0 commit comments