Skip to content

Commit 6b201a1

Browse files
committed
stop overwriting fullTrace arrays in convert_column_xyz
1 parent 95911da commit 6b201a1

File tree

13 files changed

+142
-96
lines changed

13 files changed

+142
-96
lines changed

src/plots/plots.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2364,14 +2364,15 @@ plots.doCalcdata = function(gd, traces) {
23642364
// clear stuff that should recomputed in 'regular' loop
23652365
if(hasCalcTransform) clearAxesCalc(axList);
23662366

2367-
// 'regular' loop
2368-
for(i = 0; i < fullData.length; i++) {
2369-
var cd = [];
2370-
2367+
function calci(i, isContainer) {
23712368
trace = fullData[i];
2369+
_module = trace._module;
2370+
2371+
if(!!_module.isContainer !== isContainer) return;
2372+
2373+
var cd = [];
23722374

23732375
if(trace.visible === true) {
2374-
_module = trace._module;
23752376

23762377
// keep ref of index-to-points map object of the *last* enabled transform,
23772378
// this index-to-points map object is required to determine the calcdata indices
@@ -2406,6 +2407,11 @@ plots.doCalcdata = function(gd, traces) {
24062407
calcdata[i] = cd;
24072408
}
24082409

2410+
// 'regular' loop - make sure container traces (eg carpet) calc before
2411+
// contained traces (eg contourcarpet)
2412+
for(i = 0; i < fullData.length; i++) calci(i, true);
2413+
for(i = 0; i < fullData.length; i++) calci(i, false);
2414+
24092415
Registry.getComponentMethod('fx', 'calc')(gd);
24102416
};
24112417

src/traces/carpet/axis_defaults.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, options)
103103
handleCalendarDefaults(containerIn, containerOut, 'calendar', options.calendar);
104104
}
105105

106+
// we need some of the other functions setConvert attaches, but for
107+
// path finding, override pixel scaling to simple passthrough (identity)
106108
setConvert(containerOut, options.fullLayout);
109+
containerOut.c2p = Lib.identity;
107110

108111
var dfltColor = coerce('color', options.dfltColor);
109112
// if axis.color was provided, use it for fonts too; otherwise,

src/traces/carpet/calc.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,37 @@ var calcLabels = require('./calc_labels');
1717
var calcClipPath = require('./calc_clippath');
1818
var clean2dArray = require('../heatmap/clean_2d_array');
1919
var smoothFill2dArray = require('./smooth_fill_2d_array');
20+
var hasColumns = require('./has_columns');
21+
var convertColumnData = require('../heatmap/convert_column_xyz');
22+
var setConvert = require('./set_convert');
2023

2124
module.exports = function calc(gd, trace) {
22-
var xa = Axes.getFromId(gd, trace.xaxis || 'x');
23-
var ya = Axes.getFromId(gd, trace.yaxis || 'y');
25+
var xa = Axes.getFromId(gd, trace.xaxis);
26+
var ya = Axes.getFromId(gd, trace.yaxis);
2427
var aax = trace.aaxis;
2528
var bax = trace.baxis;
26-
var a = trace._a = trace.a;
27-
var b = trace._b = trace.b;
2829

29-
var t = {};
30-
var x;
30+
var x = trace.x;
3131
var y = trace.y;
32+
var cols = [];
33+
if(x && !hasColumns(x)) cols.push('x');
34+
if(y && !hasColumns(y)) cols.push('y');
35+
36+
if(cols.length) {
37+
convertColumnData(trace, aax, bax, 'a', 'b', cols);
38+
}
39+
40+
var a = trace._a = trace._a || trace.a;
41+
var b = trace._b = trace._b || trace.b;
42+
x = trace._x || trace.x;
43+
y = trace._y || trace.y;
44+
45+
var t = {};
3246

3347
if(trace._cheater) {
3448
var avals = aax.cheatertype === 'index' ? a.length : a;
3549
var bvals = bax.cheatertype === 'index' ? b.length : b;
3650
x = cheaterBasis(avals, bvals, trace.cheaterslope);
37-
} else {
38-
x = trace.x;
3951
}
4052

4153
trace._x = x = clean2dArray(x);
@@ -48,6 +60,8 @@ module.exports = function calc(gd, trace) {
4860
smoothFill2dArray(x, a, b);
4961
smoothFill2dArray(y, a, b);
5062

63+
setConvert(trace);
64+
5165
// create conversion functions that depend on the data
5266
trace.setScale();
5367

src/traces/carpet/calc_gridlines.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ module.exports = function calcGridlines(trace, cd, axisLetter, crossAxisLetter)
1616
var eps, bounds, n1, n2, n, value, v;
1717
var j1, v0, v1, d;
1818

19-
var data = trace[axisLetter];
19+
var data = trace['_' + axisLetter];
2020
var axis = trace[axisLetter + 'axis'];
2121

2222
var gridlines = axis._gridlines = [];
2323
var minorgridlines = axis._minorgridlines = [];
2424
var boundarylines = axis._boundarylines = [];
2525

26-
var crossData = trace[crossAxisLetter];
26+
var crossData = trace['_' + crossAxisLetter];
2727
var crossAxis = trace[crossAxisLetter + 'axis'];
2828

2929
if(axis.tickmode === 'array') {
@@ -34,8 +34,8 @@ module.exports = function calcGridlines(trace, cd, axisLetter, crossAxisLetter)
3434
var ycp = trace._yctrl;
3535
var nea = xcp[0].length;
3636
var neb = xcp.length;
37-
var na = trace.a.length;
38-
var nb = trace.b.length;
37+
var na = trace._a.length;
38+
var nb = trace._b.length;
3939

4040
Axes.prepTicks(axis);
4141

src/traces/carpet/defaults.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
var Lib = require('../../lib');
1313
var handleXYDefaults = require('./xy_defaults');
1414
var handleABDefaults = require('./ab_defaults');
15-
var setConvert = require('./set_convert');
1615
var attributes = require('./attributes');
1716
var colorAttrs = require('../../components/color/attributes');
1817

@@ -49,8 +48,6 @@ module.exports = function supplyDefaults(traceIn, traceOut, dfltColor, fullLayou
4948
// and i goes from 0 to a.length - 1.
5049
var len = handleXYDefaults(traceIn, traceOut, coerce);
5150

52-
setConvert(traceOut);
53-
5451
if(traceOut._cheater) {
5552
coerce('cheaterslope');
5653
}

src/traces/carpet/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Carpet.supplyDefaults = require('./defaults');
1616
Carpet.plot = require('./plot');
1717
Carpet.calc = require('./calc');
1818
Carpet.animatable = true;
19+
Carpet.isContainer = true; // so carpet traces get `calc` before other traces
1920

2021
Carpet.moduleType = 'trace';
2122
Carpet.name = 'carpet';

src/traces/carpet/set_convert.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ var createJDerivativeEvaluator = require('./create_j_derivative_evaluator');
2525
* p: screen-space pixel coordinates
2626
*/
2727
module.exports = function setConvert(trace) {
28-
var a = trace.a;
29-
var b = trace.b;
30-
var na = trace.a.length;
31-
var nb = trace.b.length;
28+
var a = trace._a;
29+
var b = trace._b;
30+
var na = a.length;
31+
var nb = b.length;
3232
var aax = trace.aaxis;
3333
var bax = trace.baxis;
3434

@@ -60,10 +60,6 @@ module.exports = function setConvert(trace) {
6060
return a < amin || a > amax || b < bmin || b > bmax;
6161
};
6262

63-
// XXX: ONLY PASSTHRU. ONLY. No, ONLY.
64-
aax.c2p = function(v) { return v; };
65-
bax.c2p = function(v) { return v; };
66-
6763
trace.setScale = function() {
6864
var x = trace._x;
6965
var y = trace._y;

src/traces/carpet/xy_defaults.js

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,11 @@
99

1010
'use strict';
1111

12-
var hasColumns = require('./has_columns');
13-
var convertColumnData = require('../heatmap/convert_column_xyz');
14-
1512
module.exports = function handleXYDefaults(traceIn, traceOut, coerce) {
16-
var cols = [];
1713
var x = coerce('x');
18-
19-
var needsXTransform = x && !hasColumns(x);
20-
if(needsXTransform) cols.push('x');
21-
22-
traceOut._cheater = !x;
23-
2414
var y = coerce('y');
2515

26-
var needsYTransform = y && !hasColumns(y);
27-
if(needsYTransform) cols.push('y');
28-
29-
if(!x && !y) return;
30-
31-
if(cols.length) {
32-
convertColumnData(traceOut, traceOut.aaxis, traceOut.baxis, 'a', 'b', cols);
33-
}
16+
traceOut._cheater = !x;
3417

35-
return true;
18+
return !!x || !!y;
3619
};

src/traces/contourcarpet/calc.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,17 @@ function heatmappishCalc(gd, trace) {
7070
bax._minDtick = 0;
7171

7272
if(hasColumns(trace)) convertColumnData(trace, aax, bax, 'a', 'b', ['z']);
73+
a = trace._a = trace._a || trace.a;
74+
b = trace._b = trace._b || trace.b;
7375

74-
a = trace.a ? aax.makeCalcdata(trace, 'a') : [];
75-
b = trace.b ? bax.makeCalcdata(trace, 'b') : [];
76+
a = a ? aax.makeCalcdata(trace, '_a') : [];
77+
b = b ? bax.makeCalcdata(trace, '_b') : [];
7678
a0 = trace.a0 || 0;
7779
da = trace.da || 1;
7880
b0 = trace.b0 || 0;
7981
db = trace.db || 1;
8082

81-
z = clean2dArray(trace.z, trace.transpose);
83+
z = trace._z = clean2dArray(trace._z || trace.z, trace.transpose);
8284

8385
trace._emptypoints = findEmpties(z);
8486
trace._interpz = interp2d(z, trace._emptypoints, trace._interpz);

src/traces/heatmap/calc.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@ module.exports = function calc(gd, trace) {
5858
z = binned.z;
5959
}
6060
else {
61+
var zIn = trace.z;
6162
if(hasColumns(trace)) {
6263
convertColumnData(trace, xa, ya, 'x', 'y', ['z']);
63-
x = trace.x;
64-
y = trace.y;
64+
x = trace._x;
65+
y = trace._y;
66+
zIn = trace._z;
6567
} else {
6668
x = trace.x ? xa.makeCalcdata(trace, 'x') : [];
6769
y = trace.y ? ya.makeCalcdata(trace, 'y') : [];
@@ -72,7 +74,7 @@ module.exports = function calc(gd, trace) {
7274
y0 = trace.y0 || 0;
7375
dy = trace.dy || 1;
7476

75-
z = clean2dArray(trace.z, trace.transpose);
77+
z = clean2dArray(zIn, trace.transpose);
7678

7779
if(isContour || trace.connectgaps) {
7880
trace._emptypoints = findEmpties(z);
@@ -131,7 +133,7 @@ module.exports = function calc(gd, trace) {
131133
x: xArray,
132134
y: yArray,
133135
z: z,
134-
text: trace.text
136+
text: trace._text || trace.text
135137
};
136138

137139
if(xIn && xIn.length === xArray.length - 1) cd0.xCenter = xIn;

src/traces/heatmap/convert_column_xyz.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,10 @@ module.exports = function convertColumnData(trace, ax1, ax2, var1Name, var2Name,
6666
}
6767
}
6868

69-
// hack for Plotly.react - save the input arrays for diffing purposes
70-
trace['_input_' + var1Name] = trace[var1Name];
71-
trace['_input_' + var2Name] = trace[var2Name];
72-
trace[var1Name] = col1vals;
73-
trace[var2Name] = col2vals;
69+
trace['_' + var1Name] = col1vals;
70+
trace['_' + var2Name] = col2vals;
7471
for(j = 0; j < arrayVarNames.length; j++) {
75-
trace['_input_' + arrayVarNames[j]] = trace[arrayVarNames[j]];
76-
trace[arrayVarNames[j]] = newArrays[j];
72+
trace['_' + arrayVarNames[j]] = newArrays[j];
7773
}
78-
if(hasColumnText) trace.text = text;
74+
if(hasColumnText) trace._text = text;
7975
};

test/jasmine/tests/heatmap_test.js

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -174,17 +174,21 @@ describe('heatmap convertColumnXYZ', function() {
174174
var xa = makeMockAxis();
175175
var ya = makeMockAxis();
176176

177+
function checkConverted(trace, x, y, z) {
178+
convertColumnXYZ(trace, xa, ya, 'x', 'y', ['z']);
179+
expect(trace._x).toEqual(x);
180+
expect(trace._y).toEqual(y);
181+
expect(trace._z).toEqual(z);
182+
}
183+
177184
it('should convert x/y/z columns to z(x,y)', function() {
178185
trace = {
179186
x: [1, 1, 1, 2, 2, 2],
180187
y: [1, 2, 3, 1, 2, 3],
181188
z: [1, 2, 3, 4, 5, 6]
182189
};
183190

184-
convertColumnXYZ(trace, xa, ya, 'x', 'y', ['z']);
185-
expect(trace.x).toEqual([1, 2]);
186-
expect(trace.y).toEqual([1, 2, 3]);
187-
expect(trace.z).toEqual([[1, 4], [2, 5], [3, 6]]);
191+
checkConverted(trace, [1, 2], [1, 2, 3], [[1, 4], [2, 5], [3, 6]]);
188192
});
189193

190194
it('should convert x/y/z columns to z(x,y) with uneven dimensions', function() {
@@ -194,10 +198,7 @@ describe('heatmap convertColumnXYZ', function() {
194198
z: [1, 2, 4, 5, 6]
195199
};
196200

197-
convertColumnXYZ(trace, xa, ya, 'x', 'y', ['z']);
198-
expect(trace.x).toEqual([1, 2]);
199-
expect(trace.y).toEqual([1, 2, 3]);
200-
expect(trace.z).toEqual([[1, 4], [2, 5], [, 6]]);
201+
checkConverted(trace, [1, 2], [1, 2, 3], [[1, 4], [2, 5], [, 6]]);
201202
});
202203

203204
it('should convert x/y/z columns to z(x,y) with missing values', function() {
@@ -207,10 +208,7 @@ describe('heatmap convertColumnXYZ', function() {
207208
z: [1, null, 4, 5, 6]
208209
};
209210

210-
convertColumnXYZ(trace, xa, ya, 'x', 'y', ['z']);
211-
expect(trace.x).toEqual([1, 2]);
212-
expect(trace.y).toEqual([1, 2, 3]);
213-
expect(trace.z).toEqual([[1, 4], [null, 5], [, 6]]);
211+
checkConverted(trace, [1, 2], [1, 2, 3], [[1, 4], [null, 5], [, 6]]);
214212
});
215213

216214
it('should convert x/y/z/text columns to z(x,y) and text(x,y)', function() {
@@ -222,7 +220,7 @@ describe('heatmap convertColumnXYZ', function() {
222220
};
223221

224222
convertColumnXYZ(trace, xa, ya, 'x', 'y', ['z']);
225-
expect(trace.text).toEqual([['a', 'd'], ['b', 'e'], ['c', 'f']]);
223+
expect(trace._text).toEqual([['a', 'd'], ['b', 'e'], ['c', 'f']]);
226224
});
227225

228226
it('should convert x/y/z columns to z(x,y) with out-of-order data', function() {
@@ -253,20 +251,19 @@ describe('heatmap convertColumnXYZ', function() {
253251
]
254252
};
255253

256-
convertColumnXYZ(trace, xa, ya, 'x', 'y', ['z']);
257-
expect(trace.x).toEqual(
258-
[-88596, -65484, -42372, -19260, 3852, 26964, 50076, 73188]);
259-
expect(trace.y).toEqual(
260-
[-78096.2, -52106.6, -26117, -127.4, 25862.2, 51851.8, 77841.4]);
261-
expect(trace.z).toEqual([
262-
[,, 4.154291, 4.404264, 4.33847, 4.270931,,, ],
263-
[, 4.339848, 4.39907, 4.345006, 4.315032, 4.295618, 4.262052,, ],
264-
[3.908434, 4.433257, 4.364234, 4.308714, 4.275516, 4.126979, 4.296483, 4.320471],
265-
[4.032226, 4.381492, 4.328922, 4.24046, 4.349151, 4.202861, 4.256402, 4.28972],
266-
[3.956225, 4.337909, 4.31226, 4.259435, 4.146854, 4.235799, 4.238752, 4.299876],
267-
[, 4.210373, 4.32009, 4.246728, 4.293992, 4.316364, 4.361856,, ],
268-
[,, 4.234497, 4.321701, 4.450315, 4.416136,,, ]
269-
]);
254+
checkConverted(trace,
255+
[-88596, -65484, -42372, -19260, 3852, 26964, 50076, 73188],
256+
[-78096.2, -52106.6, -26117, -127.4, 25862.2, 51851.8, 77841.4],
257+
[
258+
[,, 4.154291, 4.404264, 4.33847, 4.270931,,, ],
259+
[, 4.339848, 4.39907, 4.345006, 4.315032, 4.295618, 4.262052,, ],
260+
[3.908434, 4.433257, 4.364234, 4.308714, 4.275516, 4.126979, 4.296483, 4.320471],
261+
[4.032226, 4.381492, 4.328922, 4.24046, 4.349151, 4.202861, 4.256402, 4.28972],
262+
[3.956225, 4.337909, 4.31226, 4.259435, 4.146854, 4.235799, 4.238752, 4.299876],
263+
[, 4.210373, 4.32009, 4.246728, 4.293992, 4.316364, 4.361856,, ],
264+
[,, 4.234497, 4.321701, 4.450315, 4.416136,,, ]
265+
]
266+
);
270267
});
271268

272269
it('should convert x/y/z columns with nulls to z(x,y)', function() {
@@ -282,11 +279,7 @@ describe('heatmap convertColumnXYZ', function() {
282279
z: [0, 50, 100, 50, null, 255, 100, 510, 1010]
283280
};
284281

285-
convertColumnXYZ(trace, xa, ya, 'x', 'y', ['z']);
286-
287-
expect(trace.x).toEqual([0, 5, 10]);
288-
expect(trace.y).toEqual([0, 5, 10]);
289-
expect(trace.z).toEqual([
282+
checkConverted(trace, [0, 5, 10], [0, 5, 10], [
290283
[0, 50, 100],
291284
[50, undefined, 510],
292285
[100, 255, 1010]

0 commit comments

Comments
 (0)