Skip to content

Commit 5557d7b

Browse files
committed
resolves #2547 - target altered axes only on "axrange" edits
- by passing (now correct) alteredRange hash object to doTicksRelayout - by addding new doTicks(gd, [axId, axId2, ...]) call signature - clean up doTicks docstring - N.B. not implemented for Plotly.react (yet)
1 parent 09d5dd0 commit 5557d7b

File tree

3 files changed

+65
-37
lines changed

3 files changed

+65
-37
lines changed

src/plot_api/plot_api.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1689,12 +1689,9 @@ exports.relayout = function relayout(gd, astr, val) {
16891689
// subroutine of its own so that finalDraw always gets
16901690
// executed after drawData
16911691
seq.push(
1692-
// TODO
1693-
// can target specific axes,
1694-
// do not have to redraw all axes here
1695-
// See:
1696-
// https://github.com/plotly/plotly.js/issues/2547
1697-
subroutines.doTicksRelayout,
1692+
function(gd) {
1693+
return subroutines.doTicksRelayout(gd, specs.rangesAltered);
1694+
},
16981695
subroutines.drawData,
16991696
subroutines.finalDraw
17001697
);
@@ -2058,6 +2055,7 @@ function _relayout(gd, aobj) {
20582055

20592056
return {
20602057
flags: flags,
2058+
rangesAltered: rangesAltered,
20612059
undoit: undoit,
20622060
redoit: redoit,
20632061
eventData: Lib.extendDeep({}, redoit)
@@ -2171,7 +2169,9 @@ exports.update = function update(gd, traceUpdate, layoutUpdate, _traces) {
21712169
if(relayoutFlags.layoutstyle) seq.push(subroutines.layoutStyles);
21722170
if(relayoutFlags.axrange) {
21732171
seq.push(
2174-
subroutines.doTicksRelayout,
2172+
function(gd) {
2173+
return subroutines.doTicksRelayout(gd, relayoutSpecs.rangesAltered);
2174+
},
21752175
subroutines.drawData,
21762176
subroutines.finalDraw
21772177
);

src/plot_api/subroutines.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,12 @@ exports.doLegend = function(gd) {
448448
return Plots.previousPromises(gd);
449449
};
450450

451-
exports.doTicksRelayout = function(gd) {
452-
Axes.doTicks(gd, 'redraw');
451+
exports.doTicksRelayout = function(gd, rangesAltered) {
452+
if(rangesAltered) {
453+
Axes.doTicks(gd, Object.keys(rangesAltered), true);
454+
} else {
455+
Axes.doTicks(gd, 'redraw');
456+
}
453457

454458
if(gd._fullLayout._hasOnlyLargeSploms) {
455459
clearGlCanvases(gd);

src/plots/cartesian/axes.js

+52-28
Original file line numberDiff line numberDiff line change
@@ -1498,28 +1498,50 @@ axes.makeClipPaths = function(gd) {
14981498
});
14991499
};
15001500

1501-
// doTicks: draw ticks, grids, and tick labels
1502-
// axid: 'x', 'y', 'x2' etc,
1503-
// blank to do all,
1504-
// 'redraw' to force full redraw, and reset:
1505-
// ax._r (stored range for use by zoom/pan)
1506-
// ax._rl (stored linearized range for use by zoom/pan)
1507-
// or can pass in an axis object directly
1508-
axes.doTicks = function(gd, axid, skipTitle) {
1501+
/** Main axis drawing routine!
1502+
*
1503+
* This routine draws axis ticks and much more (... grids, labels, title etc.)
1504+
* Supports multiple argument signatures.
1505+
* N.B. this thing is async in general (because of MathJax rendering)
1506+
*
1507+
* @param {DOM element} gd : graph div
1508+
* @param {object or string or array of strings} arg : polymorphic argument
1509+
* @param {boolean} skipTitle : optional flag to skip axis title draw/update
1510+
* @return {promise}
1511+
*
1512+
* Signature 1: Axes.doTicks(gd, ax)
1513+
* where ax is an axis object as in fullLayout
1514+
*
1515+
* Signature 2: Axes.doTicks(gd, axId)
1516+
* where axId is a axis id string
1517+
*
1518+
* Signature 3: Axes.doTicks(gd, 'redraw')
1519+
* use this to clear and redraw all axes on graph
1520+
*
1521+
* Signature 4: Axes.doTicks(gd, '')
1522+
* use this to draw all axes on graph w/o the selectAll().remove()
1523+
* of the 'redraw' signature
1524+
*
1525+
* Signature 5: Axes.doTicks(gd, [axId, axId2, ...])
1526+
* where the items are axis id string,
1527+
* use this to update multiple axes in one call
1528+
*
1529+
* N.B signatures 3, 4 and 5 reset:
1530+
* - ax._r (stored range for use by zoom/pan)
1531+
* - ax._rl (stored linearized range for use by zoom/pan)
1532+
*/
1533+
axes.doTicks = function(gd, arg, skipTitle) {
15091534
var fullLayout = gd._fullLayout;
1510-
var ax;
15111535
var independent = false;
1536+
var ax;
15121537

1513-
// allow passing an independent axis object instead of id
1514-
if(typeof axid === 'object') {
1515-
ax = axid;
1516-
axid = ax._id;
1538+
if(Lib.isPlainObject(arg)) {
1539+
ax = arg;
15171540
independent = true;
1518-
}
1519-
else {
1520-
ax = axes.getFromId(gd, axid);
1541+
} else if(!arg || arg === 'redraw' || Array.isArray(arg)) {
1542+
var axList = (!arg || arg === 'redraw') ? axes.listIds(gd) : arg;
15211543

1522-
if(axid === 'redraw') {
1544+
if(arg === 'redraw') {
15231545
fullLayout._paper.selectAll('g.subplot').each(function(subplot) {
15241546
var plotinfo = fullLayout._plots[subplot];
15251547
var xa = plotinfo.xaxis;
@@ -1534,22 +1556,24 @@ axes.doTicks = function(gd, axid, skipTitle) {
15341556
});
15351557
}
15361558

1537-
if(!axid || axid === 'redraw') {
1538-
return Lib.syncOrAsync(axes.list(gd, '', true).map(function(ax) {
1539-
return function() {
1540-
if(!ax._id) return;
1541-
var axDone = axes.doTicks(gd, ax._id);
1542-
ax._r = ax.range.slice();
1543-
ax._rl = Lib.simpleMap(ax._r, ax.r2l);
1544-
return axDone;
1545-
};
1546-
}));
1547-
}
1559+
return Lib.syncOrAsync(axList.map(function(a) {
1560+
return function() {
1561+
if(!a) return;
1562+
var axDone = axes.doTicks(gd, a);
1563+
var ax = axes.getFromId(gd, a);
1564+
ax._r = ax.range.slice();
1565+
ax._rl = Lib.simpleMap(ax._r, ax.r2l);
1566+
return axDone;
1567+
};
1568+
}));
1569+
} else {
1570+
ax = axes.getFromId(gd, arg);
15481571
}
15491572

15501573
// set scaling to pixels
15511574
ax.setScale();
15521575

1576+
var axid = ax._id;
15531577
var axLetter = axid.charAt(0);
15541578
var counterLetter = axes.counterLetter(axid);
15551579
var vals = ax._vals = axes.calcTicks(ax);

0 commit comments

Comments
 (0)