Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c9d92d7

Browse filesBrowse files
committed
fixes #3273 - add Colorscale.crossTraceDefaults
- to 'relink' zmin/zmax, cmin/cmax and auto colorscale, these values are computed in 'calc' in need to be relinked in 'supply-defaults' in order to work properly after edits that don't go through 'calc'.
1 parent 0a686dd commit c9d92d7
Copy full SHA for c9d92d7

File tree

Expand file treeCollapse file tree

9 files changed

+112
-98
lines changed
Filter options
Expand file treeCollapse file tree

9 files changed

+112
-98
lines changed

‎src/components/colorscale/calc.js

Copy file name to clipboardExpand all lines: src/components/colorscale/calc.js
+9-46Lines changed: 9 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,10 @@ module.exports = function calc(gd, trace, opts) {
1515
var vals = opts.vals;
1616
var containerStr = opts.containerStr;
1717
var cLetter = opts.cLetter;
18-
var container = trace;
19-
var inputContainer = trace._input;
20-
var fullInputContainer = trace._fullInput;
2118

22-
// set by traces with groupby transforms
23-
var updateStyle = trace.updateStyle;
24-
25-
function doUpdate(attr, inputVal, fullVal) {
26-
if(fullVal === undefined) fullVal = inputVal;
27-
28-
if(updateStyle) {
29-
updateStyle(trace._input, containerStr ? (containerStr + '.' + attr) : attr, inputVal);
30-
}
31-
else {
32-
inputContainer[attr] = inputVal;
33-
}
34-
35-
container[attr] = fullVal;
36-
if(fullInputContainer && (trace !== trace._fullInput)) {
37-
if(updateStyle) {
38-
updateStyle(trace._fullInput, containerStr ? (containerStr + '.' + attr) : attr, fullVal);
39-
}
40-
else {
41-
fullInputContainer[attr] = fullVal;
42-
}
43-
}
44-
}
45-
46-
if(containerStr) {
47-
container = Lib.nestedProperty(container, containerStr).get();
48-
inputContainer = Lib.nestedProperty(inputContainer, containerStr).get();
49-
fullInputContainer = Lib.nestedProperty(fullInputContainer, containerStr).get() || {};
50-
}
19+
var container = containerStr ?
20+
Lib.nestedProperty(trace, containerStr).get() :
21+
trace;
5122

5223
var autoAttr = cLetter + 'auto';
5324
var minAttr = cLetter + 'min';
@@ -70,32 +41,24 @@ module.exports = function calc(gd, trace, opts) {
7041
max += 0.5;
7142
}
7243

73-
doUpdate(minAttr, min);
74-
doUpdate(maxAttr, max);
44+
container['_' + minAttr] = container[minAttr] = min;
45+
container['_' + maxAttr] = container[maxAttr] = max;
7546

47+
// TODO ?!?
7648
/*
7749
* If auto was explicitly false but min or max was missing,
7850
* we filled in the missing piece here but later the trace does
7951
* not look auto.
8052
* Otherwise make sure the trace still looks auto as far as later
8153
* changes are concerned.
8254
*/
83-
doUpdate(autoAttr, (auto !== false || (min === undefined && max === undefined)));
55+
// doUpdate(autoAttr, (auto !== false || (min === undefined && max === undefined)));
8456

8557
if(container.autocolorscale) {
8658
if(min * max < 0) scl = fullLayout.colorscale.diverging;
8759
else if(min >= 0) scl = fullLayout.colorscale.sequential;
88-
else scl = gd._fullLayout.colorscale.sequentialminus;
89-
90-
// reversescale is handled at the containerOut level
91-
doUpdate('colorscale', scl);
60+
else scl = fullLayout.colorscale.sequentialminus;
9261

93-
// We pushed a colorscale back to input, which will change the default autocolorscale next time
94-
// to avoid spurious redraws from Plotly.react, update resulting autocolorscale now
95-
// This is a conscious decision so that changing the data later does not unexpectedly
96-
// give you a new colorscale
97-
if(!inputContainer.autocolorscale) {
98-
doUpdate('autocolorscale', false);
99-
}
62+
container._colorscale = container.colorscale = scl;
10063
}
10164
};
+70Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* Copyright 2012-2018, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var Lib = require('../../lib');
12+
var hasColorscale = require('./helpers').hasColorscale;
13+
14+
module.exports = function crossTraceDefaults(fullData) {
15+
function replace(cont, k) {
16+
var val = cont['_' + k];
17+
if(val !== undefined) {
18+
cont[k] = val;
19+
}
20+
}
21+
22+
function relinkColorAtts(trace, cAttrs) {
23+
var cont = cAttrs.container ?
24+
Lib.nestedProperty(trace, cAttrs.container).get() :
25+
trace;
26+
27+
if(cont) {
28+
var isAuto = cont.zauto || cont.cauto;
29+
var minAttr = cAttrs.min;
30+
var maxAttr = cAttrs.max;
31+
32+
if(isAuto || cont[minAttr] === undefined) {
33+
replace(cont, minAttr);
34+
}
35+
if(isAuto || cont[maxAttr] === undefined) {
36+
replace(cont, maxAttr);
37+
}
38+
if(cont.autocolorscale) {
39+
replace(cont, 'colorscale');
40+
}
41+
}
42+
}
43+
44+
for(var i = 0; i < fullData.length; i++) {
45+
var trace = fullData[i];
46+
var _module = trace._module;
47+
48+
if(_module.colorbar) {
49+
relinkColorAtts(trace, _module.colorbar);
50+
}
51+
52+
// TODO could generalize _module.colorscale and use it here?
53+
54+
if(hasColorscale(trace, 'marker.line')) {
55+
relinkColorAtts(trace, {
56+
container: 'marker.line',
57+
min: 'cmin',
58+
max: 'cmax'
59+
});
60+
}
61+
62+
if(hasColorscale(trace, 'line')) {
63+
relinkColorAtts(trace, {
64+
container: 'line',
65+
min: 'cmin',
66+
max: 'cmax'
67+
});
68+
}
69+
}
70+
};

‎src/components/colorscale/index.js

Copy file name to clipboardExpand all lines: src/components/colorscale/index.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module.exports = {
2020

2121
supplyLayoutDefaults: require('./layout_defaults'),
2222
handleDefaults: require('./defaults'),
23+
crossTraceDefaults: require('./cross_trace_defaults'),
2324

2425
calc: require('./calc'),
2526

‎src/plots/plots.js

Copy file name to clipboardExpand all lines: src/plots/plots.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ plots.supplyDefaults = function(gd, opts) {
449449
for(i = 0; i < crossTraceDefaultsFuncs.length; i++) {
450450
crossTraceDefaultsFuncs[i](newFullData, newFullLayout);
451451
}
452+
Registry.getComponentMethod('colorscale', 'crossTraceDefaults')(newFullData, newFullLayout);
452453

453454
// turn on flag to optimize large splom-only graphs
454455
// mostly by omitting SVG layers during Cartesian.drawFramework

‎test/jasmine/tests/colorscale_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/colorscale_test.js
-15Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -406,21 +406,6 @@ describe('Test colorscale:', function() {
406406
expect(trace.colorscale).toEqual(colorscale);
407407
});
408408

409-
it('should set autocolorscale to false if it wasn\'t explicitly set true in input', function() {
410-
trace = {
411-
type: 'heatmap',
412-
z: [[0, -1.5], [-2, -10]],
413-
zmin: -10,
414-
zmax: 0,
415-
autocolorscale: true,
416-
_input: {}
417-
};
418-
gd = _supply(trace);
419-
calcColorscale(gd, trace, {vals: trace.z, containerStr: '', cLetter: 'z'});
420-
expect(trace.autocolorscale).toBe(false);
421-
expect(trace.colorscale[5]).toEqual([1, 'rgb(220,220,220)']);
422-
});
423-
424409
it('should be Blues when the only numerical z <= -0.5', function() {
425410
trace = {
426411
type: 'heatmap',

‎test/jasmine/tests/contour_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/contour_test.js
-7Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -309,14 +309,7 @@ describe('contour calc', function() {
309309

310310
['start', 'end', 'size'].forEach(function(attr) {
311311
expect(out.contours[attr]).toBe(spec[attr], [contoursIn, spec.inputNcontours, attr]);
312-
// all these get copied back to the input trace
313-
expect(out._input.contours[attr]).toBe(spec[attr], [contoursIn, spec.inputNcontours, attr]);
314312
});
315-
316-
expect(out._input.autocontour).toBe(true);
317-
expect(out._input.zauto).toBe(true);
318-
expect(out._input.zmin).toBe(0);
319-
expect(out._input.zmax).toBe(5);
320313
});
321314
});
322315
});

‎test/jasmine/tests/mesh3d_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/mesh3d_test.js
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ describe('Test mesh3d restyle', function() {
1414
var fullTrace = gd._fullData[0];
1515

1616
expect(trace.cauto).toBe(user[0], 'user cauto');
17-
expect(trace.cmin).toEqual(user[1], 'user cmin');
18-
expect(trace.cmax).toEqual(user[2], 'user cmax');
17+
expect(trace.cmin).toBe(user[1], 'user cmin');
18+
expect(trace.cmax).toBe(user[2], 'user cmax');
1919
expect(fullTrace.cauto).toBe(full[0], 'full cauto');
20-
expect(fullTrace.cmin).toEqual(full[1], 'full cmin');
21-
expect(fullTrace.cmax).toEqual(full[2], 'full cmax');
20+
expect(fullTrace.cmin).toBe(full[1], 'full cmin');
21+
expect(fullTrace.cmax).toBe(full[2], 'full cmax');
2222
}
2323

2424
Plotly.plot(gd, [{
@@ -32,12 +32,12 @@ describe('Test mesh3d restyle', function() {
3232
intensity: [0, 0.33, 0.66, 3]
3333
}])
3434
.then(function() {
35-
_assert([true, 0, 3], [true, 0, 3]);
35+
_assert([undefined, undefined, undefined], [true, 0, 3]);
3636

3737
return Plotly.restyle(gd, 'cmin', 0);
3838
})
3939
.then(function() {
40-
_assert([false, 0, 3], [false, 0, 3]);
40+
_assert([false, 0, undefined], [false, 0, 3]);
4141

4242
return Plotly.restyle(gd, 'cmax', 10);
4343
})
@@ -47,7 +47,7 @@ describe('Test mesh3d restyle', function() {
4747
return Plotly.restyle(gd, 'cauto', true);
4848
})
4949
.then(function() {
50-
_assert([true, 0, 3], [true, 0, 3]);
50+
_assert([true, 0, 10], [true, 0, 3]);
5151

5252
return Plotly.purge(gd);
5353
})

‎test/jasmine/tests/parcoords_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/parcoords_test.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ describe('parcoords initialization tests', function() {
284284
cauto: true,
285285
cmin: 21,
286286
cmax: 63,
287+
_cmin: 21,
288+
_cmax: 63,
287289
autocolorscale: false,
288290
reversescale: false,
289291
showscale: false

‎test/jasmine/tests/plot_api_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/plot_api_test.js
+22-23Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,18 +1052,17 @@ describe('Test plot api', function() {
10521052

10531053
it('should redo auto z/contour when editing z array', function(done) {
10541054
Plotly.plot(gd, [{type: 'contour', z: [[1, 2], [3, 4]]}]).then(function() {
1055-
expect(gd.data[0].zauto).toBe(true, gd.data[0]);
1056-
expect(gd.data[0].zmin).toBe(1);
1057-
expect(gd.data[0].zmax).toBe(4);
1058-
1055+
expect(gd._fullData[0].zauto).toBe(true);
1056+
expect(gd._fullData[0].zmin).toBe(1);
1057+
expect(gd._fullData[0].zmax).toBe(4);
10591058
expect(gd.data[0].autocontour).toBe(true);
10601059
expect(gd.data[0].contours).toEqual({start: 1.5, end: 3.5, size: 0.5});
10611060

10621061
return Plotly.restyle(gd, {'z[0][0]': 10});
10631062
}).then(function() {
1064-
expect(gd.data[0].zmin).toBe(2);
1065-
expect(gd.data[0].zmax).toBe(10);
1066-
1063+
expect(gd._fullData[0].zauto).toBe(true);
1064+
expect(gd._fullData[0].zmin).toBe(2);
1065+
expect(gd._fullData[0].zmax).toBe(10);
10671066
expect(gd.data[0].contours).toEqual({start: 3, end: 9, size: 1});
10681067
})
10691068
.catch(failTest)
@@ -1111,10 +1110,10 @@ describe('Test plot api', function() {
11111110
var zmax1 = 10;
11121111

11131112
function check(auto, msg) {
1114-
expect(gd.data[0].zmin).negateIf(auto).toBe(zmin0, msg);
1115-
expect(gd.data[0].zauto).toBe(auto, msg);
1116-
expect(gd.data[1].zmax).negateIf(auto).toBe(zmax1, msg);
1117-
expect(gd.data[1].zauto).toBe(auto, msg);
1113+
expect(gd._fullData[0].zmin).negateIf(auto).toBe(zmin0, msg);
1114+
expect(gd._fullData[0].zauto).toBe(auto, msg);
1115+
expect(gd._fullData[1].zmax).negateIf(auto).toBe(zmax1, msg);
1116+
expect(gd._fullData[1].zauto).toBe(auto, msg);
11181117
}
11191118

11201119
Plotly.plot(gd, [
@@ -1144,32 +1143,32 @@ describe('Test plot api', function() {
11441143
});
11451144

11461145
it('turns off cauto (autocolorscale) when you edit cmin or cmax (colorscale)', function(done) {
1147-
var autocscale = require('@src/components/colorscale/scales').scales.Reds;
1146+
var scales = require('@src/components/colorscale/scales').scales;
11481147

1148+
var autocscale = scales.Reds;
1149+
var mcscl0 = 'Rainbow';
1150+
var mlcscl1 = 'Greens';
11491151
var mcmin0 = 3;
1150-
var mcscl0 = 'rainbow';
11511152
var mlcmax1 = 6;
1152-
var mlcscl1 = 'greens';
11531153

11541154
function check(auto, autocolorscale, msg) {
1155-
expect(gd.data[0].marker.cauto).toBe(auto, msg);
1156-
expect(gd.data[0].marker.cmin).negateIf(auto).toBe(mcmin0);
1155+
expect(gd._fullData[0].marker.cauto).toBe(auto, msg);
1156+
expect(gd._fullData[0].marker.cmin).negateIf(auto).toBe(mcmin0);
11571157
expect(gd._fullData[0].marker.autocolorscale).toBe(autocolorscale, msg);
1158-
expect(gd.data[0].marker.colorscale).toEqual(auto ? autocscale : mcscl0);
1159-
expect(gd.data[1].marker.line.cauto).toBe(auto, msg);
1160-
expect(gd.data[1].marker.line.cmax).negateIf(auto).toBe(mlcmax1);
1158+
expect(gd._fullData[0].marker.colorscale).toEqual(auto ? autocscale : scales[mcscl0]);
1159+
1160+
expect(gd._fullData[1].marker.line.cauto).toBe(auto, msg);
1161+
expect(gd._fullData[1].marker.line.cmax).negateIf(auto).toBe(mlcmax1);
11611162
expect(gd._fullData[1].marker.line.autocolorscale).toBe(autocolorscale, msg);
1162-
expect(gd.data[1].marker.line.colorscale).toEqual(auto ? autocscale : mlcscl1);
1163+
expect(gd._fullData[1].marker.line.colorscale).toEqual(auto ? autocscale : scales[mlcscl1]);
11631164
}
11641165

11651166
Plotly.plot(gd, [
11661167
{y: [1, 2], mode: 'markers', marker: {color: [1, 10]}},
11671168
{y: [2, 1], mode: 'markers', marker: {line: {width: 2, color: [3, 4]}}}
11681169
])
11691170
.then(function() {
1170-
// autocolorscale is actually true after supplyDefaults, but during calc it's set
1171-
// to false when we push the resulting colorscale back to the input container
1172-
check(true, false, 'initial');
1171+
check(true, true, 'initial');
11731172
return Plotly.restyle(gd, {'marker.cmin': mcmin0, 'marker.colorscale': mcscl0}, null, [0]);
11741173
})
11751174
.then(function() {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.