Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Oct 6, 2022. It is now read-only.

Commit 4f8fc66

Browse files
committed
move clearAxisTypes into helpers
1 parent 6e8a68c commit 4f8fc66

File tree

2 files changed

+35
-29
lines changed

2 files changed

+35
-29
lines changed

src/plot_api/helpers.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,3 +536,36 @@ exports.hasParent = function(aobj, attr) {
536536
}
537537
return false;
538538
};
539+
540+
/**
541+
* Empty out types for all axes containing these traces so we auto-set them again
542+
*
543+
* @param {object} gd
544+
* @param {[integer]} traces: trace indices to search for axes to clear the types of
545+
* @param {object} layoutUpdate: any update being done concurrently to the layout,
546+
* which may supercede clearing the axis types
547+
*/
548+
var axLetters = ['x', 'y', 'z'];
549+
exports.clearAxisTypes = function(gd, traces, layoutUpdate) {
550+
for(var i = 0; i < traces.length; i++) {
551+
var trace = gd._fullData[i];
552+
for(var j = 0; j < 3; j++) {
553+
var ax = Axes.getFromTrace(gd, trace, axLetters[j]);
554+
555+
// do not clear log type - that's never an auto result so must have been intentional
556+
if(ax && ax.type !== 'log') {
557+
var axAttr = ax._name;
558+
var sceneName = ax._id.substr(1);
559+
if(sceneName.substr(0, 5) === 'scene') {
560+
if(layoutUpdate[sceneName] !== undefined) continue;
561+
axAttr = sceneName + '.' + axAttr;
562+
}
563+
var typeAttr = axAttr + '.type';
564+
565+
if(layoutUpdate[axAttr] === undefined && layoutUpdate[typeAttr] === undefined) {
566+
Lib.nestedProperty(gd.layout, typeAttr).set(null);
567+
}
568+
}
569+
}
570+
}
571+
};

src/plot_api/plot_api.js

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ Plotly.restyle = function restyle(gd, astr, val, _traces) {
12861286

12871287
// clear calcdata and/or axis types if required so they get regenerated
12881288
if(flags.clearCalc) gd.calcdata = undefined;
1289-
if(flags.clearAxisTypes) clearAxisTypes(gd, traces, {});
1289+
if(flags.clearAxisTypes) helpers.clearAxisTypes(gd, traces, {});
12901290

12911291
// fill in redraw sequence
12921292
var seq = [];
@@ -2095,7 +2095,7 @@ Plotly.update = function update(gd, traceUpdate, layoutUpdate, _traces) {
20952095

20962096
// clear calcdata and/or axis types if required
20972097
if(restyleFlags.clearCalc || relayoutFlags.calc) gd.calcdata = undefined;
2098-
if(restyleFlags.clearAxisTypes) clearAxisTypes(gd, traces, layoutUpdate);
2098+
if(restyleFlags.clearAxisTypes) helpers.clearAxisTypes(gd, traces, layoutUpdate);
20992099

21002100
// fill in redraw sequence
21012101
var seq = [];
@@ -2150,33 +2150,6 @@ Plotly.update = function update(gd, traceUpdate, layoutUpdate, _traces) {
21502150
});
21512151
};
21522152

2153-
// empty out types for all axes containing these traces
2154-
// so we auto-set them again
2155-
var axLetters = ['x', 'y', 'z'];
2156-
function clearAxisTypes(gd, traces, layoutUpdate) {
2157-
for(var i = 0; i < traces.length; i++) {
2158-
var trace = gd._fullData[i];
2159-
for(var j = 0; j < 3; j++) {
2160-
var ax = Plotly.Axes.getFromTrace(gd, trace, axLetters[j]);
2161-
2162-
// do not clear log type - that's never an auto result so must have been intentional
2163-
if(ax && ax.type !== 'log') {
2164-
var axAttr = ax._name;
2165-
var sceneName = ax._id.substr(1);
2166-
if(sceneName.substr(0, 5) === 'scene') {
2167-
if(layoutUpdate[sceneName] !== undefined) continue;
2168-
axAttr = sceneName + '.' + axAttr;
2169-
}
2170-
var typeAttr = axAttr + '.type';
2171-
2172-
if(layoutUpdate[axAttr] === undefined && layoutUpdate[typeAttr] === undefined) {
2173-
Lib.nestedProperty(gd.layout, typeAttr).set(null);
2174-
}
2175-
}
2176-
}
2177-
}
2178-
}
2179-
21802153
/**
21812154
* Animate to a frame, sequence of frame, frame group, or frame definition
21822155
*

0 commit comments

Comments
 (0)