@@ -16,24 +16,47 @@ var flipScale = require('./flip_scale');
16
16
17
17
18
18
module . exports = function calc ( trace , vals , containerStr , cLetter ) {
19
- var container , inputContainer ;
19
+ var container = trace ;
20
+ var inputContainer = trace . _input ;
21
+ var fullInputContainer = trace . _fullInput ;
22
+
23
+ // set by traces with groupby transforms
24
+ var updateStyle = trace . updateStyle ;
25
+
26
+ function doUpdate ( attr , inputVal , fullVal ) {
27
+ if ( fullVal === undefined ) fullVal = inputVal ;
28
+
29
+ if ( updateStyle ) {
30
+ updateStyle ( trace . _input , containerStr ? ( containerStr + '.' + attr ) : attr , inputVal ) ;
31
+ }
32
+ else {
33
+ inputContainer [ attr ] = inputVal ;
34
+ }
35
+
36
+ container [ attr ] = fullVal ;
37
+ if ( fullInputContainer && ( trace !== trace . _fullInput ) ) {
38
+ if ( updateStyle ) {
39
+ updateStyle ( trace . _fullInput , containerStr ? ( containerStr + '.' + attr ) : attr , fullVal ) ;
40
+ }
41
+ else {
42
+ fullInputContainer [ attr ] = fullVal ;
43
+ }
44
+ }
45
+ }
20
46
21
47
if ( containerStr ) {
22
- container = Lib . nestedProperty ( trace , containerStr ) . get ( ) ;
23
- inputContainer = Lib . nestedProperty ( trace . _input , containerStr ) . get ( ) ;
24
- }
25
- else {
26
- container = trace ;
27
- inputContainer = trace . _input ;
48
+ container = Lib . nestedProperty ( container , containerStr ) . get ( ) ;
49
+ inputContainer = Lib . nestedProperty ( inputContainer , containerStr ) . get ( ) ;
50
+ fullInputContainer = Lib . nestedProperty ( fullInputContainer , containerStr ) . get ( ) || { } ;
28
51
}
29
52
30
- var autoAttr = cLetter + 'auto' ,
31
- minAttr = cLetter + 'min' ,
32
- maxAttr = cLetter + 'max' ,
33
- auto = container [ autoAttr ] ,
34
- min = container [ minAttr ] ,
35
- max = container [ maxAttr ] ,
36
- scl = container . colorscale ;
53
+ var autoAttr = cLetter + 'auto' ;
54
+ var minAttr = cLetter + 'min' ;
55
+ var maxAttr = cLetter + 'max' ;
56
+ var auto = container [ autoAttr ] ;
57
+ var min = container [ minAttr ] ;
58
+ var max = container [ maxAttr ] ;
59
+ var scl = container . colorscale ;
37
60
38
61
if ( auto !== false || min === undefined ) {
39
62
min = Lib . aggNums ( Math . min , null , vals ) ;
@@ -48,11 +71,8 @@ module.exports = function calc(trace, vals, containerStr, cLetter) {
48
71
max += 0.5 ;
49
72
}
50
73
51
- container [ minAttr ] = min ;
52
- container [ maxAttr ] = max ;
53
-
54
- inputContainer [ minAttr ] = min ;
55
- inputContainer [ maxAttr ] = max ;
74
+ doUpdate ( minAttr , min ) ;
75
+ doUpdate ( maxAttr , max ) ;
56
76
57
77
/*
58
78
* If auto was explicitly false but min or max was missing,
@@ -61,17 +81,22 @@ module.exports = function calc(trace, vals, containerStr, cLetter) {
61
81
* Otherwise make sure the trace still looks auto as far as later
62
82
* changes are concerned.
63
83
*/
64
- inputContainer [ autoAttr ] = ( auto !== false ||
65
- ( min === undefined && max === undefined ) ) ;
84
+ doUpdate ( autoAttr , ( auto !== false || ( min === undefined && max === undefined ) ) ) ;
66
85
67
86
if ( container . autocolorscale ) {
68
87
if ( min * max < 0 ) scl = scales . RdBu ;
69
88
else if ( min >= 0 ) scl = scales . Reds ;
70
89
else scl = scales . Blues ;
71
90
72
91
// reversescale is handled at the containerOut level
73
- inputContainer . colorscale = scl ;
74
- if ( container . reversescale ) scl = flipScale ( scl ) ;
75
- container . colorscale = scl ;
92
+ doUpdate ( 'colorscale' , scl , container . reversescale ? flipScale ( scl ) : scl ) ;
93
+
94
+ // We pushed a colorscale back to input, which will change the default autocolorscale next time
95
+ // to avoid spurious redraws from Plotly.react, update resulting autocolorscale now
96
+ // This is a conscious decision so that changing the data later does not unexpectedly
97
+ // give you a new colorscale
98
+ if ( ! inputContainer . autocolorscale ) {
99
+ doUpdate ( 'autocolorscale' , false ) ;
100
+ }
76
101
}
77
102
} ;
0 commit comments