Skip to content

Commit 138a84f

Browse files
committed
🔪 calcIfAutorange logic in Plotly methods
... including the refAutorange block which is no longer necessary.
1 parent a326778 commit 138a84f

File tree

2 files changed

+12
-77
lines changed

2 files changed

+12
-77
lines changed

src/plot_api/edit_types.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@ var isPlainObject = Lib.isPlainObject;
1515
var traceOpts = {
1616
valType: 'flaglist',
1717
extras: ['none'],
18-
flags: ['calc', 'calcIfAutorange', 'clearAxisTypes', 'plot', 'style', 'colorbars'],
18+
flags: ['calc', 'clearAxisTypes', 'plot', 'style', 'colorbars'],
1919
description: [
2020
'trace attributes should include an `editType` string matching this flaglist.',
2121
'*calc* is the most extensive: a full `Plotly.plot` starting by clearing `gd.calcdata`',
2222
'to force it to be regenerated',
23-
'*calcIfAutorange* does a full `Plotly.plot`, but only clears and redoes `gd.calcdata`',
24-
'if there is at least one autoranged axis.',
2523
'*clearAxisTypes* resets the types of the axes this trace is on, because new data could',
2624
'cause the automatic axis type detection to change. Log type will not be cleared, as that',
2725
'is never automatically chosen so must have been user-specified.',
@@ -35,15 +33,13 @@ var layoutOpts = {
3533
valType: 'flaglist',
3634
extras: ['none'],
3735
flags: [
38-
'calc', 'calcIfAutorange', 'plot', 'legend', 'ticks', 'axrange',
36+
'calc', 'plot', 'legend', 'ticks', 'axrange',
3937
'layoutstyle', 'modebar', 'camera', 'arraydraw'
4038
],
4139
description: [
4240
'layout attributes should include an `editType` string matching this flaglist.',
4341
'*calc* is the most extensive: a full `Plotly.plot` starting by clearing `gd.calcdata`',
4442
'to force it to be regenerated',
45-
'*calcIfAutorange* does a full `Plotly.plot`, but only clears and redoes `gd.calcdata`',
46-
'if there is at least one autoranged axis.',
4743
'*plot* calls `Plotly.plot` but without first clearing `gd.calcdata`.',
4844
'*legend* only redraws the legend.',
4945
'*ticks* only redraws axis ticks, labels, and gridlines.',
@@ -60,7 +56,7 @@ var layoutOpts = {
6056
// that shouldn't be used in attributes, to deal with certain
6157
// combinations and conditionals efficiently
6258
var traceEditTypeFlags = traceOpts.flags.slice()
63-
.concat(['clearCalc', 'fullReplot']);
59+
.concat(['fullReplot']);
6460

6561
var layoutEditTypeFlags = layoutOpts.flags.slice()
6662
.concat('layoutReplot');

src/plot_api/plot_api.js

+9-70
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ exports.restyle = function restyle(gd, astr, val, _traces) {
12991299
var flags = specs.flags;
13001300

13011301
// clear calcdata and/or axis types if required so they get regenerated
1302-
if(flags.clearCalc) gd.calcdata = undefined;
1302+
if(flags.calc) gd.calcdata = undefined;
13031303
if(flags.clearAxisTypes) helpers.clearAxisTypes(gd, traces, {});
13041304

13051305
// fill in redraw sequence
@@ -1597,21 +1597,7 @@ function _restyle(gd, aobj, traces) {
15971597
}
15981598
}
15991599

1600-
// do we need to force a recalc?
1601-
var autorangeOn = false;
1602-
var axList = Axes.list(gd);
1603-
for(i = 0; i < axList.length; i++) {
1604-
if(axList[i].autorange) {
1605-
autorangeOn = true;
1606-
break;
1607-
}
1608-
}
1609-
1610-
// combine a few flags together;
1611-
if(flags.calc || (flags.calcIfAutorange && autorangeOn)) {
1612-
flags.clearCalc = true;
1613-
}
1614-
if(flags.calc || flags.plot || flags.calcIfAutorange) {
1600+
if(flags.calc || flags.plot) {
16151601
flags.fullReplot = true;
16161602
}
16171603

@@ -1956,37 +1942,21 @@ function _relayout(gd, aobj) {
19561942
var propStr = containerArrayMatch.property;
19571943
var componentArray = Lib.nestedProperty(layout, arrayStr);
19581944
var obji = (componentArray || [])[i] || {};
1959-
var objToAutorange = obji;
1960-
19611945
var updateValObject = valObject || {editType: 'calc'};
1962-
var checkForAutorange = updateValObject.editType.indexOf('calcIfAutorange') !== -1;
19631946

1964-
if(i === '') {
1965-
// replacing the entire array - too many possibilities, just recalc
1966-
if(checkForAutorange) flags.calc = true;
1967-
else editTypes.update(flags, updateValObject);
1968-
checkForAutorange = false; // clear this, we're already doing a recalc
1969-
}
1970-
else if(propStr === '') {
1947+
if(propStr === '') {
19711948
// special handling of undoit if we're adding or removing an element
19721949
// ie 'annotations[2]' which can be {...} (add) or null (remove)
1973-
objToAutorange = vi;
19741950
if(manageArrays.isAddVal(vi)) {
19751951
undoit[ai] = null;
1976-
}
1977-
else if(manageArrays.isRemoveVal(vi)) {
1952+
} else if(manageArrays.isRemoveVal(vi)) {
19781953
undoit[ai] = obji;
1979-
objToAutorange = obji;
1954+
} else {
1955+
Lib.warn('unrecognized full object value', aobj);
19801956
}
1981-
else Lib.warn('unrecognized full object value', aobj);
19821957
}
19831958

1984-
if(checkForAutorange && (refAutorange(gd, objToAutorange, 'x') || refAutorange(gd, objToAutorange, 'y'))) {
1985-
flags.calc = true;
1986-
}
1987-
else {
1988-
editTypes.update(flags, updateValObject);
1989-
}
1959+
editTypes.update(flags, updateValObject);
19901960

19911961
// prepare the edits object we'll send to applyContainerArrayChanges
19921962
if(!arrayEdits[arrayStr]) arrayEdits[arrayStr] = {};
@@ -2088,25 +2058,6 @@ function updateAutosize(gd) {
20882058
return (fullLayout.width !== oldWidth) || (fullLayout.height !== oldHeight);
20892059
}
20902060

2091-
// for editing annotations or shapes - is it on autoscaled axes?
2092-
function refAutorange(gd, obj, axLetter) {
2093-
if(!Lib.isPlainObject(obj)) return false;
2094-
var axRef = obj[axLetter + 'ref'] || axLetter,
2095-
ax = Axes.getFromId(gd, axRef);
2096-
2097-
if(!ax && axRef.charAt(0) === axLetter) {
2098-
// fall back on the primary axis in case we've referenced a
2099-
// nonexistent axis (as we do above if axRef is missing).
2100-
// This assumes the object defaults to data referenced, which
2101-
// is the case for shapes and annotations but not for images.
2102-
// The only thing this is used for is to determine whether to
2103-
// do a full `recalc`, so the only ill effect of this error is
2104-
// to waste some time.
2105-
ax = Axes.getFromId(gd, axLetter);
2106-
}
2107-
return (ax || {}).autorange;
2108-
}
2109-
21102061
/**
21112062
* update: update trace and layout attributes of an existing plot
21122063
*
@@ -2145,7 +2096,7 @@ exports.update = function update(gd, traceUpdate, layoutUpdate, _traces) {
21452096
var relayoutFlags = relayoutSpecs.flags;
21462097

21472098
// clear calcdata and/or axis types if required
2148-
if(restyleFlags.clearCalc || relayoutFlags.calc) gd.calcdata = undefined;
2099+
if(restyleFlags.calc || relayoutFlags.calc) gd.calcdata = undefined;
21492100
if(restyleFlags.clearAxisTypes) helpers.clearAxisTypes(gd, traces, layoutUpdate);
21502101

21512102
// fill in redraw sequence
@@ -2392,14 +2343,10 @@ function diffData(gd, oldFullData, newFullData, immutable) {
23922343
if(seenUIDs[trace.uid]) continue;
23932344
seenUIDs[trace.uid] = 1;
23942345

2395-
diffOpts.autoranged = trace.xaxis ? (
2396-
Axes.getFromId(gd, trace.xaxis).autorange ||
2397-
Axes.getFromId(gd, trace.yaxis).autorange
2398-
) : false;
23992346
getDiffFlags(oldFullData[i]._fullInput, trace, [], diffOpts);
24002347
}
24012348

2402-
if(flags.calc || flags.plot || flags.calcIfAutorange) {
2349+
if(flags.calc || flags.plot) {
24032350
flags.fullReplot = true;
24042351
}
24052352

@@ -2438,17 +2385,9 @@ function getDiffFlags(oldContainer, newContainer, outerparts, opts) {
24382385
var immutable = opts.immutable;
24392386
var inArray = opts.inArray;
24402387
var arrayIndex = opts.arrayIndex;
2441-
var gd = opts.gd;
2442-
var autoranged = opts.autoranged;
24432388

24442389
function changed() {
24452390
var editType = valObject.editType;
2446-
if(editType.indexOf('calcIfAutorange') !== -1 && (autoranged || (autoranged === undefined && (
2447-
refAutorange(gd, newContainer, 'x') || refAutorange(gd, newContainer, 'y')
2448-
)))) {
2449-
flags.calc = true;
2450-
return;
2451-
}
24522391
if(inArray && editType.indexOf('arraydraw') !== -1) {
24532392
Lib.pushUnique(flags.arrays[inArray], arrayIndex);
24542393
return;

0 commit comments

Comments
 (0)