Skip to content

Commit 391f602

Browse files
authored
Merge pull request #1257 from plotly/array-to-calcdata-in-calc
Convert arrayOk attribute to calcdata in calc step
2 parents b823573 + aca5487 commit 391f602

File tree

10 files changed

+57
-32
lines changed

10 files changed

+57
-32
lines changed

src/plot_api/subroutines.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ exports.doTraceStyle = function(gd) {
236236
_module = ((cdi[0] || {}).trace || {})._module || {},
237237
arraysToCalcdata = _module.arraysToCalcdata;
238238

239-
if(arraysToCalcdata) arraysToCalcdata(cdi);
239+
if(arraysToCalcdata) arraysToCalcdata(cdi, cdi[0].trace);
240240
}
241241

242242
Plots.style(gd);

src/traces/bar/arrays_to_calcdata.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ var mergeArray = require('../../lib').mergeArray;
1313

1414

1515
// arrayOk attributes, merge them into calcdata array
16-
module.exports = function arraysToCalcdata(cd) {
17-
var trace = cd[0].trace,
18-
marker = trace.marker;
19-
16+
module.exports = function arraysToCalcdata(cd, trace) {
2017
mergeArray(trace.text, cd, 'tx');
2118

22-
if(marker && marker.line) {
23-
var markerLine = marker.line;
24-
19+
var marker = trace.marker;
20+
if(marker) {
2521
mergeArray(marker.opacity, cd, 'mo');
2622
mergeArray(marker.color, cd, 'mc');
27-
mergeArray(markerLine.color, cd, 'mlc');
28-
mergeArray(markerLine.width, cd, 'mlw');
23+
24+
var markerLine = marker.line;
25+
if(markerLine) {
26+
mergeArray(markerLine.color, cd, 'mlc');
27+
mergeArray(markerLine.width, cd, 'mlw');
28+
}
2929
}
3030
};

src/traces/bar/calc.js

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ var Axes = require('../../plots/cartesian/axes');
1515
var hasColorscale = require('../../components/colorscale/has_colorscale');
1616
var colorscaleCalc = require('../../components/colorscale/calc');
1717

18+
var arraysToCalcdata = require('./arrays_to_calcdata');
19+
1820

1921
module.exports = function calc(gd, trace) {
2022
// depending on bar direction, set position and size axes
@@ -97,5 +99,7 @@ module.exports = function calc(gd, trace) {
9799
colorscaleCalc(trace, trace.marker.line.color, 'marker.line', 'c');
98100
}
99101

102+
arraysToCalcdata(cd, trace);
103+
100104
return cd;
101105
};

src/traces/bar/plot.js

-4
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ var Color = require('../../components/color');
2020
var Drawing = require('../../components/drawing');
2121
var ErrorBars = require('../../components/errorbars');
2222

23-
var arraysToCalcdata = require('./arrays_to_calcdata');
24-
2523
var attributes = require('./attributes'),
2624
attributeText = attributes.text,
2725
attributeTextPosition = attributes.textposition,
@@ -53,8 +51,6 @@ module.exports = function plot(gd, plotinfo, cdbar) {
5351
barwidth = t.barwidth,
5452
barwidthIsArray = Array.isArray(barwidth);
5553

56-
arraysToCalcdata(d);
57-
5854
d3.select(this).selectAll('g.point')
5955
.data(Lib.identity)
6056
.enter().append('g').classed('point', true)

src/traces/scatter/arrays_to_calcdata.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ var Lib = require('../../lib');
1313

1414

1515
// arrayOk attributes, merge them into calcdata array
16-
module.exports = function arraysToCalcdata(cd) {
17-
var trace = cd[0].trace,
18-
marker = trace.marker;
16+
module.exports = function arraysToCalcdata(cd, trace) {
1917

2018
Lib.mergeArray(trace.text, cd, 'tx');
2119
Lib.mergeArray(trace.textposition, cd, 'tp');
@@ -25,12 +23,17 @@ module.exports = function arraysToCalcdata(cd) {
2523
Lib.mergeArray(trace.textfont.family, cd, 'tf');
2624
}
2725

28-
if(marker && marker.line) {
29-
var markerLine = marker.line;
26+
var marker = trace.marker;
27+
if(marker) {
28+
Lib.mergeArray(marker.size, cd, 'ms');
3029
Lib.mergeArray(marker.opacity, cd, 'mo');
3130
Lib.mergeArray(marker.symbol, cd, 'mx');
3231
Lib.mergeArray(marker.color, cd, 'mc');
33-
Lib.mergeArray(markerLine.color, cd, 'mlc');
34-
Lib.mergeArray(markerLine.width, cd, 'mlw');
32+
33+
var markerLine = marker.line;
34+
if(marker.line) {
35+
Lib.mergeArray(markerLine.color, cd, 'mlc');
36+
Lib.mergeArray(markerLine.width, cd, 'mlw');
37+
}
3538
}
3639
};

src/traces/scatter/calc.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
var isNumeric = require('fast-isnumeric');
1313

1414
var Axes = require('../../plots/cartesian/axes');
15-
var Lib = require('../../lib');
1615

1716
var subTypes = require('./subtypes');
1817
var calcColorscale = require('./colorscale_calc');
18+
var arraysToCalcdata = require('./arrays_to_calcdata');
1919

2020

2121
module.exports = function calc(gd, trace) {
@@ -121,8 +121,7 @@ module.exports = function calc(gd, trace) {
121121
}
122122
}
123123

124-
// this has migrated up from arraysToCalcdata as we have a reference to 's' here
125-
if(typeof s !== 'undefined') Lib.mergeArray(s, cd, 'ms');
124+
arraysToCalcdata(cd, trace);
126125

127126
gd.firstscatter = false;
128127
return cd;

src/traces/scatter/plot.js

-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ var Drawing = require('../../components/drawing');
1616
var ErrorBars = require('../../components/errorbars');
1717

1818
var subTypes = require('./subtypes');
19-
var arraysToCalcdata = require('./arrays_to_calcdata');
2019
var linePoints = require('./line_points');
2120
var linkTraces = require('./link_traces');
2221
var polygonTester = require('../../lib/polygon').tester;
@@ -179,8 +178,6 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition
179178
// store node for tweaking by selectPoints
180179
cdscatter[0].node3 = tr;
181180

182-
arraysToCalcdata(cdscatter);
183-
184181
var prevRevpath = '';
185182
var prevPolygons = [];
186183
var prevtrace = trace._prevtrace;

src/traces/scatter3d/calc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var calcColorscales = require('../scatter/colorscale_calc');
2020
module.exports = function calc(gd, trace) {
2121
var cd = [{x: false, y: false, trace: trace, t: {}}];
2222

23-
arraysToCalcdata(cd);
23+
arraysToCalcdata(cd, trace);
2424
calcColorscales(trace);
2525

2626
return cd;

src/traces/scatterternary/calc.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
var isNumeric = require('fast-isnumeric');
1313

1414
var Axes = require('../../plots/cartesian/axes');
15-
var Lib = require('../../lib');
1615

1716
var subTypes = require('../scatter/subtypes');
1817
var calcColorscale = require('../scatter/colorscale_calc');
18+
var arraysToCalcdata = require('../scatter/arrays_to_calcdata');
1919

2020
var dataArrays = ['a', 'b', 'c'];
2121
var arraysToFill = {a: ['b', 'c'], b: ['a', 'c'], c: ['a', 'b']};
@@ -89,9 +89,7 @@ module.exports = function calc(gd, trace) {
8989
}
9090

9191
calcColorscale(trace);
92-
93-
// this has migrated up from arraysToCalcdata as we have a reference to 's' here
94-
if(typeof s !== 'undefined') Lib.mergeArray(s, cd, 'ms');
92+
arraysToCalcdata(cd, trace);
9593

9694
return cd;
9795
};

test/jasmine/tests/transform_filter_test.js

+28
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,7 @@ describe('filter transforms interactions', function() {
847847
var mockData0 = [{
848848
x: [-2, -1, -2, 0, 1, 2, 3],
849849
y: [1, 2, 3, 1, 2, 3, 1],
850+
text: ['a', 'b', 'c', 'd', 'e', 'f', 'g'],
850851
transforms: [{
851852
type: 'filter',
852853
operation: '>'
@@ -856,6 +857,7 @@ describe('filter transforms interactions', function() {
856857
var mockData1 = [Lib.extendDeep({}, mockData0[0]), {
857858
x: [20, 11, 12, 0, 1, 2, 3],
858859
y: [1, 2, 3, 2, 5, 2, 0],
860+
text: ['A', 'B', 'C', 'D', 'E', 'F', 'G'],
859861
transforms: [{
860862
type: 'filter',
861863
operation: '<',
@@ -988,4 +990,30 @@ describe('filter transforms interactions', function() {
988990
done();
989991
});
990992
});
993+
994+
it('zooming in/out should not change filtered data', function(done) {
995+
var data = Lib.extendDeep([], mockData1);
996+
997+
var gd = createGraphDiv();
998+
999+
function getTx(p) { return p.tx; }
1000+
1001+
Plotly.plot(gd, data).then(function() {
1002+
expect(gd.calcdata[0].map(getTx)).toEqual(['e', 'f', 'g']);
1003+
expect(gd.calcdata[1].map(getTx)).toEqual(['D', 'E', 'F', 'G']);
1004+
1005+
return Plotly.relayout(gd, 'xaxis.range', [-1, 1]);
1006+
})
1007+
.then(function() {
1008+
expect(gd.calcdata[0].map(getTx)).toEqual(['e', 'f', 'g']);
1009+
expect(gd.calcdata[1].map(getTx)).toEqual(['D', 'E', 'F', 'G']);
1010+
1011+
return Plotly.relayout(gd, 'xaxis.autorange', true);
1012+
})
1013+
.then(function() {
1014+
expect(gd.calcdata[0].map(getTx)).toEqual(['e', 'f', 'g']);
1015+
expect(gd.calcdata[1].map(getTx)).toEqual(['D', 'E', 'F', 'G']);
1016+
})
1017+
.then(done);
1018+
});
9911019
});

0 commit comments

Comments
 (0)