Skip to content

Handle autorange axes with 'reset' doubleClick config option [fixes #278] #285

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

Merged
merged 4 commits into from
Feb 25, 2016
Merged
Show file tree
Hide file tree
Changes from 3 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
16 changes: 9 additions & 7 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,18 @@ axes.saveRangeInitial = function(gd, overwrite) {
var axList = axes.list(gd, '', true),
hasOneAxisChanged = false;

var ax, isNew, hasChanged;

for(var i = 0; i < axList.length; i++) {
ax = axList[i];
var ax = axList[i];
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm always happy to see these kinds of small style changed. No more scrolling all the way to the top of a file to see whether some variable had a value previously!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah. I used to dislike block-scoped var, but I've changed.


isNew = ax._rangeInitial===undefined;
hasChanged = isNew ||
!(ax.range[0]===ax._rangeInitial[0] && ax.range[1]===ax._rangeInitial[1]);
var isNew = (ax._rangeInitial === undefined);
var hasChanged = (
isNew || !(
ax.range[0] === ax._rangeInitial[0] &&
ax.range[1] === ax._rangeInitial[1]
)
);

if((isNew && ax.autorange===false) || (overwrite && hasChanged)) {
if((isNew && ax.autorange === false) || (overwrite && hasChanged)) {
ax._rangeInitial = ax.range.slice();
hasOneAxisChanged = true;
}
Expand Down
26 changes: 13 additions & 13 deletions src/plots/cartesian/axis_ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var Lib = require('../../lib');
var constants = require('./constants');


// convert between axis names (xaxis, xaxis2, etc, elements of td.layout)
// convert between axis names (xaxis, xaxis2, etc, elements of gd.layout)
// and axis id's (x, x2, etc). Would probably have ditched 'xaxis'
// completely in favor of just 'x' if it weren't ingrained in the API etc.
exports.id2name = function id2name(id) {
Expand Down Expand Up @@ -43,8 +43,8 @@ exports.cleanId = function cleanId(id, axLetter) {
// get all axis object names
// optionally restricted to only x or y or z by string axLetter
// and optionally 2D axes only, not those inside 3D scenes
function listNames(td, axLetter, only2d) {
var fullLayout = td._fullLayout;
function listNames(gd, axLetter, only2d) {
var fullLayout = gd._fullLayout;
if(!fullLayout) return [];

function filterAxis(obj, extra) {
Expand Down Expand Up @@ -76,23 +76,23 @@ function listNames(td, axLetter, only2d) {
}

// get all axis objects, as restricted in listNames
exports.list = function(td, axletter, only2d) {
return listNames(td, axletter, only2d)
exports.list = function(gd, axletter, only2d) {
return listNames(gd, axletter, only2d)
.map(function(axName) {
return Lib.nestedProperty(td._fullLayout, axName).get();
return Lib.nestedProperty(gd._fullLayout, axName).get();
});
};

// get all axis ids, optionally restricted by letter
// this only makes sense for 2d axes
exports.listIds = function(td, axletter) {
return listNames(td, axletter, true).map(exports.name2id);
exports.listIds = function(gd, axletter) {
return listNames(gd, axletter, true).map(exports.name2id);
};

// get an axis object from its id 'x','x2' etc
// optionally, id can be a subplot (ie 'x2y3') and type gets x or y from it
exports.getFromId = function(td, id, type) {
var fullLayout = td._fullLayout;
exports.getFromId = function(gd, id, type) {
var fullLayout = gd._fullLayout;

if(type === 'x') id = id.replace(/y[0-9]*/,'');
else if(type === 'y') id = id.replace(/x[0-9]*/,'');
Expand All @@ -101,8 +101,8 @@ exports.getFromId = function(td, id, type) {
};

// get an axis object of specified type from the containing trace
exports.getFromTrace = function(td, fullTrace, type) {
var fullLayout = td._fullLayout;
exports.getFromTrace = function(gd, fullTrace, type) {
var fullLayout = gd._fullLayout;
var ax = null;

if(Plots.traceIs(fullTrace, 'gl3d')) {
Expand All @@ -112,7 +112,7 @@ exports.getFromTrace = function(td, fullTrace, type) {
}
}
else {
ax = exports.getFromId(td, fullTrace[type + 'axis'] || type);
ax = exports.getFromId(gd, fullTrace[type + 'axis'] || type);
}

return ax;
Expand Down
13 changes: 11 additions & 2 deletions src/plots/cartesian/graph_interact.js
Original file line number Diff line number Diff line change
Expand Up @@ -1807,15 +1807,24 @@ function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
else if(doubleClickConfig === 'reset') {
for(i = 0; i < axList.length; i++) {
ax = axList[i];
attrs[ax._name + '.range'] = ax._rangeInitial.slice();

if(!ax._rangeInitial) {
attrs[ax._name + '.autorange'] = true;
}
else {
attrs[ax._name + '.range'] = ax._rangeInitial.slice();
}
}
}
else if(doubleClickConfig === 'reset+autosize') {
for(i = 0; i < axList.length; i++) {
ax = axList[i];

if(ax.fixedrange) continue;
if(ax._rangeInitial === undefined ||
ax.range[0]===ax._rangeInitial[0] && ax.range[1]===ax._rangeInitial[1]) {
ax.range[0] === ax._rangeInitial[0] &&
ax.range[1] === ax._rangeInitial[1]
) {
attrs[ax._name + '.autorange'] = true;
}
else attrs[ax._name + '.range'] = ax._rangeInitial.slice();
Expand Down
Loading