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

On-par autorange for scattergl #2404

Merged
merged 9 commits into from
Feb 28, 2018
Merged
Show file tree
Hide file tree
Changes from 6 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
4 changes: 2 additions & 2 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2008,12 +2008,12 @@ function _relayout(gd, aobj) {
else flags.plot = true;
}
else {
if((fullLayout._has('gl2d') || fullLayout._has('regl')) &&
if((fullLayout._has('scatter-like') && fullLayout._has('regl')) &&
(ai === 'dragmode' &&
(vi === 'lasso' || vi === 'select') &&
!(vOld === 'lasso' || vOld === 'select'))
) {
flags.calc = true;
flags.plot = true;
}
else if(valObject) editTypes.update(flags, valObject);
else flags.calc = true;
Expand Down
14 changes: 8 additions & 6 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,13 @@ axes.saveShowSpikeInitial = function(gd, overwrite) {
return hasOneAxisChanged;
};

axes.doesAxisNeedAutoRange = function(ax) {
return (
ax.autorange ||
!!Lib.nestedProperty(ax, 'rangeslider.autorange').get()
);
};

// axes.expand: if autoranging, include new data in the outer limits
// for this axis
// data is an array of numbers (ie already run through ax.d2c)
Expand All @@ -436,12 +443,7 @@ axes.saveShowSpikeInitial = function(gd, overwrite) {
// tozero: (boolean) make sure to include zero if axis is linear,
// and make it a tight bound if possible
axes.expand = function(ax, data, options) {
var needsAutorange = (
ax.autorange ||
!!Lib.nestedProperty(ax, 'rangeslider.autorange').get()
);

if(!needsAutorange || !data) return;
if(!axes.doesAxisNeedAutoRange(ax) || !data) return;

if(!ax._min) ax._min = [];
if(!ax._max) ax._max = [];
Expand Down
51 changes: 30 additions & 21 deletions src/traces/scatter/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,31 @@ function calc(gd, trace) {
var x = xa.makeCalcdata(trace, 'x');
var y = ya.makeCalcdata(trace, 'y');
var serieslen = trace._length;
var cd = new Array(serieslen);

var ppad = calcMarkerSize(trace, serieslen);
calcAxisExpansion(gd, trace, xa, ya, x, y, ppad);

for(var i = 0; i < serieslen; i++) {
cd[i] = (isNumeric(x[i]) && isNumeric(y[i])) ?
{x: x[i], y: y[i]} :
{x: BADNUM, y: BADNUM};

if(trace.ids) {
cd[i].id = String(trace.ids[i]);
}
}

arraysToCalcdata(cd, trace);
calcColorscale(trace);
calcSelection(cd, trace);

gd.firstscatter = false;
return cd;
}

function calcAxisExpansion(gd, trace, xa, ya, x, y, ppad) {
var serieslen = trace._length;

// cancel minimum tick spacings (only applies to bars and boxes)
xa._minDtick = 0;
Expand All @@ -35,8 +60,9 @@ function calc(gd, trace) {
var xOptions = {padded: true};
var yOptions = {padded: true};

var ppad = calcMarkerSize(trace, serieslen);
if(ppad) xOptions.ppad = yOptions.ppad = ppad;
if(ppad) {
xOptions.ppad = yOptions.ppad = ppad;
}

// TODO: text size

Expand Down Expand Up @@ -72,24 +98,6 @@ function calc(gd, trace) {

Axes.expand(xa, x, xOptions);
Axes.expand(ya, y, yOptions);

// create the "calculated data" to plot
var cd = new Array(serieslen);
for(var i = 0; i < serieslen; i++) {
cd[i] = (isNumeric(x[i]) && isNumeric(y[i])) ?
{x: x[i], y: y[i]} : {x: BADNUM, y: BADNUM};

if(trace.ids) {
cd[i].id = String(trace.ids[i]);
}
}

arraysToCalcdata(cd, trace);
calcColorscale(trace);
calcSelection(cd, trace);

gd.firstscatter = false;
return cd;
}

function calcMarkerSize(trace, serieslen) {
Expand Down Expand Up @@ -131,5 +139,6 @@ function calcMarkerSize(trace, serieslen) {

module.exports = {
calc: calc,
calcMarkerSize: calcMarkerSize
calcMarkerSize: calcMarkerSize,
calcAxisExpansion: calcAxisExpansion
};
Loading