Skip to content

Commit a2fb88b

Browse files
authored
Merge pull request #2404 from plotly/scattergl-autorange
On-par autorange for scattergl
2 parents 53ea0ec + c15722f commit a2fb88b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+362
-246
lines changed

src/plot_api/plot_api.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2053,12 +2053,12 @@ function _relayout(gd, aobj) {
20532053
else flags.plot = true;
20542054
}
20552055
else {
2056-
if((fullLayout._has('gl2d') || fullLayout._has('regl')) &&
2056+
if((fullLayout._has('scatter-like') && fullLayout._has('regl')) &&
20572057
(ai === 'dragmode' &&
20582058
(vi === 'lasso' || vi === 'select') &&
20592059
!(vOld === 'lasso' || vOld === 'select'))
20602060
) {
2061-
flags.calc = true;
2061+
flags.plot = true;
20622062
}
20632063
else if(valObject) editTypes.update(flags, valObject);
20642064
else flags.calc = true;

src/plots/cartesian/axes.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,13 @@ axes.saveShowSpikeInitial = function(gd, overwrite) {
423423
return hasOneAxisChanged;
424424
};
425425

426+
axes.doesAxisNeedAutoRange = function(ax) {
427+
return (
428+
ax.autorange ||
429+
!!Lib.nestedProperty(ax, 'rangeslider.autorange').get()
430+
);
431+
};
432+
426433
// axes.expand: if autoranging, include new data in the outer limits
427434
// for this axis
428435
// data is an array of numbers (ie already run through ax.d2c)
@@ -436,12 +443,7 @@ axes.saveShowSpikeInitial = function(gd, overwrite) {
436443
// tozero: (boolean) make sure to include zero if axis is linear,
437444
// and make it a tight bound if possible
438445
axes.expand = function(ax, data, options) {
439-
var needsAutorange = (
440-
ax.autorange ||
441-
!!Lib.nestedProperty(ax, 'rangeslider.autorange').get()
442-
);
443-
444-
if(!needsAutorange || !data) return;
446+
if(!axes.doesAxisNeedAutoRange(ax) || !data) return;
445447

446448
if(!ax._min) ax._min = [];
447449
if(!ax._max) ax._max = [];

src/traces/scatter/calc.js

+30-21
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,31 @@ function calc(gd, trace) {
2525
var x = xa.makeCalcdata(trace, 'x');
2626
var y = ya.makeCalcdata(trace, 'y');
2727
var serieslen = trace._length;
28+
var cd = new Array(serieslen);
29+
30+
var ppad = calcMarkerSize(trace, serieslen);
31+
calcAxisExpansion(gd, trace, xa, ya, x, y, ppad);
32+
33+
for(var i = 0; i < serieslen; i++) {
34+
cd[i] = (isNumeric(x[i]) && isNumeric(y[i])) ?
35+
{x: x[i], y: y[i]} :
36+
{x: BADNUM, y: BADNUM};
37+
38+
if(trace.ids) {
39+
cd[i].id = String(trace.ids[i]);
40+
}
41+
}
42+
43+
arraysToCalcdata(cd, trace);
44+
calcColorscale(trace);
45+
calcSelection(cd, trace);
46+
47+
gd.firstscatter = false;
48+
return cd;
49+
}
50+
51+
function calcAxisExpansion(gd, trace, xa, ya, x, y, ppad) {
52+
var serieslen = trace._length;
2853

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

38-
var ppad = calcMarkerSize(trace, serieslen);
39-
if(ppad) xOptions.ppad = yOptions.ppad = ppad;
63+
if(ppad) {
64+
xOptions.ppad = yOptions.ppad = ppad;
65+
}
4066

4167
// TODO: text size
4268

@@ -72,24 +98,6 @@ function calc(gd, trace) {
7298

7399
Axes.expand(xa, x, xOptions);
74100
Axes.expand(ya, y, yOptions);
75-
76-
// create the "calculated data" to plot
77-
var cd = new Array(serieslen);
78-
for(var i = 0; i < serieslen; i++) {
79-
cd[i] = (isNumeric(x[i]) && isNumeric(y[i])) ?
80-
{x: x[i], y: y[i]} : {x: BADNUM, y: BADNUM};
81-
82-
if(trace.ids) {
83-
cd[i].id = String(trace.ids[i]);
84-
}
85-
}
86-
87-
arraysToCalcdata(cd, trace);
88-
calcColorscale(trace);
89-
calcSelection(cd, trace);
90-
91-
gd.firstscatter = false;
92-
return cd;
93101
}
94102

95103
function calcMarkerSize(trace, serieslen) {
@@ -131,5 +139,6 @@ function calcMarkerSize(trace, serieslen) {
131139

132140
module.exports = {
133141
calc: calc,
134-
calcMarkerSize: calcMarkerSize
142+
calcMarkerSize: calcMarkerSize,
143+
calcAxisExpansion: calcAxisExpansion
135144
};

0 commit comments

Comments
 (0)