Skip to content

Convert arrayOk attribute to calcdata in calc step #1257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/plot_api/subroutines.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ exports.doTraceStyle = function(gd) {
_module = ((cdi[0] || {}).trace || {})._module || {},
arraysToCalcdata = _module.arraysToCalcdata;

if(arraysToCalcdata) arraysToCalcdata(cdi);
if(arraysToCalcdata) arraysToCalcdata(cdi, cdi[0].trace);
}

Plots.style(gd);
Expand Down
18 changes: 9 additions & 9 deletions src/traces/bar/arrays_to_calcdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ var mergeArray = require('../../lib').mergeArray;


// arrayOk attributes, merge them into calcdata array
module.exports = function arraysToCalcdata(cd) {
var trace = cd[0].trace,
marker = trace.marker;

module.exports = function arraysToCalcdata(cd, trace) {
mergeArray(trace.text, cd, 'tx');

if(marker && marker.line) {
var markerLine = marker.line;

var marker = trace.marker;
if(marker) {
mergeArray(marker.opacity, cd, 'mo');
mergeArray(marker.color, cd, 'mc');
mergeArray(markerLine.color, cd, 'mlc');
mergeArray(markerLine.width, cd, 'mlw');

var markerLine = marker.line;
if(markerLine) {
mergeArray(markerLine.color, cd, 'mlc');
mergeArray(markerLine.width, cd, 'mlw');
}
}
};
4 changes: 4 additions & 0 deletions src/traces/bar/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ var Axes = require('../../plots/cartesian/axes');
var hasColorscale = require('../../components/colorscale/has_colorscale');
var colorscaleCalc = require('../../components/colorscale/calc');

var arraysToCalcdata = require('./arrays_to_calcdata');


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

arraysToCalcdata(cd, trace);

return cd;
};
4 changes: 0 additions & 4 deletions src/traces/bar/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ var Color = require('../../components/color');
var Drawing = require('../../components/drawing');
var ErrorBars = require('../../components/errorbars');

var arraysToCalcdata = require('./arrays_to_calcdata');

var attributes = require('./attributes'),
attributeText = attributes.text,
attributeTextPosition = attributes.textposition,
Expand Down Expand Up @@ -53,8 +51,6 @@ module.exports = function plot(gd, plotinfo, cdbar) {
barwidth = t.barwidth,
barwidthIsArray = Array.isArray(barwidth);

arraysToCalcdata(d);

d3.select(this).selectAll('g.point')
.data(Lib.identity)
.enter().append('g').classed('point', true)
Expand Down
17 changes: 10 additions & 7 deletions src/traces/scatter/arrays_to_calcdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ var Lib = require('../../lib');


// arrayOk attributes, merge them into calcdata array
module.exports = function arraysToCalcdata(cd) {
var trace = cd[0].trace,
marker = trace.marker;
module.exports = function arraysToCalcdata(cd, trace) {

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

if(marker && marker.line) {
var markerLine = marker.line;
var marker = trace.marker;
if(marker) {
Lib.mergeArray(marker.size, cd, 'ms');
Lib.mergeArray(marker.opacity, cd, 'mo');
Lib.mergeArray(marker.symbol, cd, 'mx');
Lib.mergeArray(marker.color, cd, 'mc');
Lib.mergeArray(markerLine.color, cd, 'mlc');
Lib.mergeArray(markerLine.width, cd, 'mlw');

var markerLine = marker.line;
if(marker.line) {
Lib.mergeArray(markerLine.color, cd, 'mlc');
Lib.mergeArray(markerLine.width, cd, 'mlw');
}
}
};
5 changes: 2 additions & 3 deletions src/traces/scatter/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
var isNumeric = require('fast-isnumeric');

var Axes = require('../../plots/cartesian/axes');
var Lib = require('../../lib');

var subTypes = require('./subtypes');
var calcColorscale = require('./colorscale_calc');
var arraysToCalcdata = require('./arrays_to_calcdata');


module.exports = function calc(gd, trace) {
Expand Down Expand Up @@ -121,8 +121,7 @@ module.exports = function calc(gd, trace) {
}
}

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

gd.firstscatter = false;
return cd;
Expand Down
3 changes: 0 additions & 3 deletions src/traces/scatter/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ var Drawing = require('../../components/drawing');
var ErrorBars = require('../../components/errorbars');

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

arraysToCalcdata(cdscatter);

var prevRevpath = '';
var prevPolygons = [];
var prevtrace = trace._prevtrace;
Expand Down
2 changes: 1 addition & 1 deletion src/traces/scatter3d/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var calcColorscales = require('../scatter/colorscale_calc');
module.exports = function calc(gd, trace) {
var cd = [{x: false, y: false, trace: trace, t: {}}];

arraysToCalcdata(cd);
arraysToCalcdata(cd, trace);
calcColorscales(trace);

return cd;
Expand Down
6 changes: 2 additions & 4 deletions src/traces/scatterternary/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
var isNumeric = require('fast-isnumeric');

var Axes = require('../../plots/cartesian/axes');
var Lib = require('../../lib');

var subTypes = require('../scatter/subtypes');
var calcColorscale = require('../scatter/colorscale_calc');
var arraysToCalcdata = require('../scatter/arrays_to_calcdata');

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

calcColorscale(trace);

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

return cd;
};
28 changes: 28 additions & 0 deletions test/jasmine/tests/transform_filter_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,7 @@ describe('filter transforms interactions', function() {
var mockData0 = [{
x: [-2, -1, -2, 0, 1, 2, 3],
y: [1, 2, 3, 1, 2, 3, 1],
text: ['a', 'b', 'c', 'd', 'e', 'f', 'g'],
transforms: [{
type: 'filter',
operation: '>'
Expand All @@ -856,6 +857,7 @@ describe('filter transforms interactions', function() {
var mockData1 = [Lib.extendDeep({}, mockData0[0]), {
x: [20, 11, 12, 0, 1, 2, 3],
y: [1, 2, 3, 2, 5, 2, 0],
text: ['A', 'B', 'C', 'D', 'E', 'F', 'G'],
transforms: [{
type: 'filter',
operation: '<',
Expand Down Expand Up @@ -988,4 +990,30 @@ describe('filter transforms interactions', function() {
done();
});
});

it('zooming in/out should not change filtered data', function(done) {
var data = Lib.extendDeep([], mockData1);

var gd = createGraphDiv();

function getTx(p) { return p.tx; }

Plotly.plot(gd, data).then(function() {
expect(gd.calcdata[0].map(getTx)).toEqual(['e', 'f', 'g']);
expect(gd.calcdata[1].map(getTx)).toEqual(['D', 'E', 'F', 'G']);

return Plotly.relayout(gd, 'xaxis.range', [-1, 1]);
})
.then(function() {
expect(gd.calcdata[0].map(getTx)).toEqual(['e', 'f', 'g']);
expect(gd.calcdata[1].map(getTx)).toEqual(['D', 'E', 'F', 'G']);

return Plotly.relayout(gd, 'xaxis.autorange', true);
})
.then(function() {
expect(gd.calcdata[0].map(getTx)).toEqual(['e', 'f', 'g']);
expect(gd.calcdata[1].map(getTx)).toEqual(['D', 'E', 'F', 'G']);
})
.then(done);
});
});