Skip to content
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

Faster axis autorange + remove calcIfAutorange edit type #2823

Merged
merged 15 commits into from
Aug 2, 2018
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 0 additions & 6 deletions src/plots/cartesian/autorange.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,6 @@ function doAutoRange(ax) {
}
}

function needsAutorange(ax) {
return ax.autorange || ax._rangesliderAutorange;
}

/*
* expand: if autoranging, include new data in the outer limits for this axis.
* Note that `expand` is called during `calc`, when we don't yet know the axis
Expand All @@ -236,8 +232,6 @@ function needsAutorange(ax) {
* and make it a tight bound if possible
*/
function expand(ax, data, options) {
if(!needsAutorange(ax) || !data) return;

if(!ax._min) ax._min = [];
if(!ax._max) ax._max = [];
if(!options) options = {};
Expand Down
6 changes: 3 additions & 3 deletions src/plots/cartesian/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ module.exports = {
valType: 'enumerated',
values: [true, false, 'reversed'],
dflt: true,
role: 'style',
editType: 'calc',
role: 'info',
editType: 'plot',
impliedEdits: {'range[0]': undefined, 'range[1]': undefined},
description: [
'Determines whether or not the range of this axis is',
Expand All @@ -91,7 +91,7 @@ module.exports = {
valType: 'enumerated',
values: ['normal', 'tozero', 'nonnegative'],
dflt: 'normal',
role: 'style',
role: 'info',
editType: 'plot',
description: [
'If *normal*, the range is computed in relation to the extrema',
Expand Down
13 changes: 5 additions & 8 deletions test/jasmine/tests/axes_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1858,24 +1858,21 @@ describe('Test axes', function() {
expect(ax._max).toEqual([{val: 6, pad: 10, extrapad: true}]);
});

it('should return early if no data is given', function() {
it('should fail if no data is given', function() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're confident we always send an array to expand? I guess in principle if we don't have a required array the trace will be set visible: false...

Copy link
Contributor Author

@etpinard etpinard Jul 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, expand is only called from trace module calc or setPosition or component calcAutorange which are skipped for visible: false traces / component items.

I thought removing that if(!data) return; was a nice way to make sure expand is only called when needed.

ax = getDefaultAx();

expand(ax);
expect(ax._min).toBeUndefined();
expect(ax._max).toBeUndefined();
expect(function() { expand(ax); }).toThrow();
});

it('should return early if `autorange` is falsy', function() {
it('should return even if `autorange` is false', function() {
ax = getDefaultAx();
data = [2, 5];

ax.autorange = false;
ax.rangeslider = { autorange: false };

expand(ax, data, {});
expect(ax._min).toBeUndefined();
expect(ax._max).toBeUndefined();
expect(ax._min).toEqual([{val: 2, pad: 0, extrapad: false}]);
expect(ax._max).toEqual([{val: 5, pad: 0, extrapad: false}]);
});

it('should consider range slider `autorange`', function() {
Expand Down
10 changes: 6 additions & 4 deletions test/jasmine/tests/gl2d_click_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,17 +593,19 @@ describe('@noCI @gl Test gl2d lasso/select:', function() {

function drag(path) {
var len = path.length;
var el = d3.select(gd).select('rect.nsewdrag').node();
var opts = {element: el};

Lib.clearThrottle();
mouseEvent('mousemove', path[0][0], path[0][1]);
mouseEvent('mousedown', path[0][0], path[0][1]);
mouseEvent('mousemove', path[0][0], path[0][1], opts);
mouseEvent('mousedown', path[0][0], path[0][1], opts);

path.slice(1, len).forEach(function(pt) {
Lib.clearThrottle();
mouseEvent('mousemove', pt[0], pt[1]);
mouseEvent('mousemove', pt[0], pt[1], opts);
});

mouseEvent('mouseup', path[len - 1][0], path[len - 1][1]);
mouseEvent('mouseup', path[len - 1][0], path[len - 1][1], opts);
}

function select(path) {
Expand Down
11 changes: 4 additions & 7 deletions test/jasmine/tests/gl2d_pointcloud_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,21 +181,18 @@ describe('@gl pointcloud traces', function() {

return Plotly.relayout(gd, 'xaxis.range', [3, 6]);
}).then(function() {

expect(scene2d.xaxis._min).toEqual([]);
expect(scene2d.xaxis._max).toEqual([]);
expect(scene2d.xaxis._min).toEqual(xBaselineMins);
expect(scene2d.xaxis._max).toEqual(xBaselineMaxes);

return Plotly.relayout(gd, 'xaxis.autorange', true);
}).then(function() {

expect(scene2d.xaxis._min).toEqual(xBaselineMins);
expect(scene2d.xaxis._max).toEqual(xBaselineMaxes);

return Plotly.relayout(gd, 'yaxis.range', [8, 20]);
}).then(function() {

expect(scene2d.yaxis._min).toEqual([]);
expect(scene2d.yaxis._max).toEqual([]);
expect(scene2d.yaxis._min).toEqual(yBaselineMins);
expect(scene2d.yaxis._max).toEqual(yBaselineMaxes);

return Plotly.relayout(gd, 'yaxis.autorange', true);
}).then(function() {
Expand Down
32 changes: 16 additions & 16 deletions test/jasmine/tests/scatter_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var Plotly = require('@lib/index');
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
var customAssertions = require('../assets/custom_assertions');
var fail = require('../assets/fail_test');
var failTest = require('../assets/fail_test');

var assertClip = customAssertions.assertClip;
var assertNodeDisplay = customAssertions.assertNodeDisplay;
Expand Down Expand Up @@ -561,7 +561,7 @@ describe('end-to-end scatter tests', function() {
expect(d3.select(this).classed('plotly-customdata')).toBe(false);
});

}).catch(fail).then(done);
}).catch(failTest).then(done);
});

it('adds "textpoint" class to scatter text points', function(done) {
Expand All @@ -572,7 +572,7 @@ describe('end-to-end scatter tests', function() {
text: ['a', 'b', 'c']
}]).then(function() {
expect(Plotly.d3.selectAll('.textpoint').size()).toBe(3);
}).catch(fail).then(done);
}).catch(failTest).then(done);
});

it('should remove all point and text nodes on blank data', function(done) {
Expand Down Expand Up @@ -625,7 +625,7 @@ describe('end-to-end scatter tests', function() {
assertNodeCnt(3, 3);
assertText(['A', 'B', 'C']);
})
.catch(fail)
.catch(failTest)
.then(done);
});

Expand Down Expand Up @@ -683,7 +683,7 @@ describe('end-to-end scatter tests', function() {
['apple', 'banana', 'clementine']
);
})
.catch(fail)
.catch(failTest)
.then(done);
});

Expand Down Expand Up @@ -727,7 +727,7 @@ describe('end-to-end scatter tests', function() {
['apple', 'banana', 'clementine']
);
})
.catch(fail)
.catch(failTest)
.then(done);
});

Expand Down Expand Up @@ -763,7 +763,7 @@ describe('end-to-end scatter tests', function() {
['apple', 'banana', 'dragon fruit']
);
})
.catch(fail)
.catch(failTest)
.then(done);
});

Expand All @@ -785,7 +785,7 @@ describe('end-to-end scatter tests', function() {
);
}).then(function() {
expect(fill()).toEqual('rgb(0, 0, 255)');
}).catch(fail).then(done);
}).catch(failTest).then(done);
});

it('clears fills tonext when either trace is emptied out', function(done) {
Expand Down Expand Up @@ -828,7 +828,7 @@ describe('end-to-end scatter tests', function() {
.then(function() {
checkFill(false, 'null out both traces');
})
.catch(fail)
.catch(failTest)
.then(done);
});

Expand Down Expand Up @@ -875,7 +875,7 @@ describe('end-to-end scatter tests', function() {
[40, 30, 20]
);
})
.catch(fail)
.catch(failTest)
.then(done);
});
});
Expand Down Expand Up @@ -944,7 +944,7 @@ describe('scatter hoverPoints', function() {
expect(pts[1].text).toEqual('banana', 'hover text');
expect(pts[2].text).toEqual('orange', 'hover text');
})
.catch(fail)
.catch(failTest)
.then(done);
});
});
Expand Down Expand Up @@ -1073,7 +1073,7 @@ describe('Test Scatter.style', function() {
'selected pt 1 w/ set unselected.marker.opacity'
);
})
.catch(fail)
.catch(failTest)
.then(done);
});

Expand Down Expand Up @@ -1160,7 +1160,7 @@ describe('Test Scatter.style', function() {
'selected pts 0-2 w/ set selected.marker.color'
);
})
.catch(fail)
.catch(failTest)
.then(done);
});

Expand Down Expand Up @@ -1204,7 +1204,7 @@ describe('Test Scatter.style', function() {
'selected pt 0 w/ set unselected.marker.size'
);
})
.catch(fail)
.catch(failTest)
.then(done);
});

Expand Down Expand Up @@ -1287,7 +1287,7 @@ describe('Test Scatter.style', function() {
'selected pts 0-2 w/ set selected.textfont.color'
);
})
.catch(fail)
.catch(failTest)
.then(done);
});
});
Expand Down Expand Up @@ -1433,7 +1433,7 @@ describe('Test scatter *clipnaxis*:', function() {
[true, 1]
);
})
.catch(fail)
.catch(failTest)
.then(done);
});
});