Skip to content

Commit 05b0ec9

Browse files
authoredApr 26, 2018
Merge pull request #2577 from plotly/transform-react
Transform react
2 parents 4ed586a + 0414147 commit 05b0ec9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+1264
-489
lines changed
 

Diff for: ‎src/components/colorscale/calc.js

+49-24
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,47 @@ var flipScale = require('./flip_scale');
1616

1717

1818
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+
}
2046

2147
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() || {};
2851
}
2952

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;
3760

3861
if(auto !== false || min === undefined) {
3962
min = Lib.aggNums(Math.min, null, vals);
@@ -48,11 +71,8 @@ module.exports = function calc(trace, vals, containerStr, cLetter) {
4871
max += 0.5;
4972
}
5073

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);
5676

5777
/*
5878
* If auto was explicitly false but min or max was missing,
@@ -61,17 +81,22 @@ module.exports = function calc(trace, vals, containerStr, cLetter) {
6181
* Otherwise make sure the trace still looks auto as far as later
6282
* changes are concerned.
6383
*/
64-
inputContainer[autoAttr] = (auto !== false ||
65-
(min === undefined && max === undefined));
84+
doUpdate(autoAttr, (auto !== false || (min === undefined && max === undefined)));
6685

6786
if(container.autocolorscale) {
6887
if(min * max < 0) scl = scales.RdBu;
6988
else if(min >= 0) scl = scales.Reds;
7089
else scl = scales.Blues;
7190

7291
// 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+
}
76101
}
77102
};

Diff for: ‎src/lib/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ lib.ensureArray = require('./ensure_array');
3030
var isArrayModule = require('./is_array');
3131
lib.isTypedArray = isArrayModule.isTypedArray;
3232
lib.isArrayOrTypedArray = isArrayModule.isArrayOrTypedArray;
33+
lib.isArray1D = isArrayModule.isArray1D;
3334

3435
var coerceModule = require('./coerce');
3536
lib.valObjectMeta = coerceModule.valObjectMeta;

0 commit comments

Comments
 (0)