Skip to content

Commit 72b6558

Browse files
committed
split doTicks into multi-axes and doTicksSingle parts
1 parent 455ff4d commit 72b6558

File tree

6 files changed

+74
-61
lines changed

6 files changed

+74
-61
lines changed

src/components/colorbar/draw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ module.exports = function draw(gd, id) {
418418
// this title call only handles side=right
419419
return Lib.syncOrAsync([
420420
function() {
421-
return Axes.doTicks(gd, cbAxisOut, true);
421+
return Axes.doTicksSingle(gd, cbAxisOut, true);
422422
},
423423
function() {
424424
if(['top', 'bottom'].indexOf(opts.titleside) === -1) {

src/plots/cartesian/axes.js

Lines changed: 58 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,74 +1498,87 @@ axes.makeClipPaths = function(gd) {
14981498
});
14991499
};
15001500

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)
1501+
/** Main multi-axis drawing routine!
15061502
*
15071503
* @param {DOM element} gd : graph div
1508-
* @param {object or string or array of strings} arg : polymorphic argument
1504+
* @param {string or array of strings} arg : polymorphic argument
15091505
* @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
15171506
*
1518-
* Signature 3: Axes.doTicks(gd, 'redraw')
1507+
* Signature 1: Axes.doTicks(gd, 'redraw')
15191508
* use this to clear and redraw all axes on graph
15201509
*
1521-
* Signature 4: Axes.doTicks(gd, '')
1510+
* Signature 2: Axes.doTicks(gd, '')
15221511
* use this to draw all axes on graph w/o the selectAll().remove()
15231512
* of the 'redraw' signature
15241513
*
1525-
* Signature 5: Axes.doTicks(gd, [axId, axId2, ...])
1514+
* Signature 3: Axes.doTicks(gd, [axId, axId2, ...])
15261515
* where the items are axis id string,
15271516
* use this to update multiple axes in one call
15281517
*
1529-
* N.B signatures 3, 4 and 5 reset:
1518+
* N.B doTicks updates:
15301519
* - ax._r (stored range for use by zoom/pan)
15311520
* - ax._rl (stored linearized range for use by zoom/pan)
15321521
*/
15331522
axes.doTicks = function(gd, arg, skipTitle) {
15341523
var fullLayout = gd._fullLayout;
1524+
1525+
if(arg === 'redraw') {
1526+
fullLayout._paper.selectAll('g.subplot').each(function(subplot) {
1527+
var plotinfo = fullLayout._plots[subplot];
1528+
var xa = plotinfo.xaxis;
1529+
var ya = plotinfo.yaxis;
1530+
1531+
plotinfo.xaxislayer.selectAll('.' + xa._id + 'tick').remove();
1532+
plotinfo.yaxislayer.selectAll('.' + ya._id + 'tick').remove();
1533+
if(plotinfo.gridlayer) plotinfo.gridlayer.selectAll('path').remove();
1534+
if(plotinfo.zerolinelayer) plotinfo.zerolinelayer.selectAll('path').remove();
1535+
fullLayout._infolayer.select('.g-' + xa._id + 'title').remove();
1536+
fullLayout._infolayer.select('.g-' + ya._id + 'title').remove();
1537+
});
1538+
}
1539+
1540+
var axList = (!arg || arg === 'redraw') ? axes.listIds(gd) : arg;
1541+
1542+
Lib.syncOrAsync(axList.map(function(axid) {
1543+
return function() {
1544+
if(!axid) return;
1545+
1546+
var axDone = axes.doTicksSingle(gd, axid, skipTitle);
1547+
1548+
var ax = axes.getFromId(gd, axid);
1549+
ax._r = ax.range.slice();
1550+
ax._rl = Lib.simpleMap(ax._r, ax.r2l);
1551+
1552+
return axDone;
1553+
};
1554+
}));
1555+
};
1556+
1557+
/** Per axis drawing routine!
1558+
*
1559+
* This routine draws axis ticks and much more (... grids, labels, title etc.)
1560+
* Supports multiple argument signatures.
1561+
* N.B. this thing is async in general (because of MathJax rendering)
1562+
*
1563+
* @param {DOM element} gd : graph div
1564+
* @param {string or array of strings} arg : polymorphic argument
1565+
* @param {boolean} skipTitle : optional flag to skip axis title draw/update
1566+
* @return {promise}
1567+
*
1568+
* Signature 1: Axes.doTicks(gd, ax)
1569+
* where ax is an axis object as in fullLayout
1570+
*
1571+
* Signature 2: Axes.doTicks(gd, axId)
1572+
* where axId is a axis id string
1573+
*/
1574+
axes.doTicksSingle = function(gd, arg, skipTitle) {
1575+
var fullLayout = gd._fullLayout;
15351576
var independent = false;
15361577
var ax;
15371578

15381579
if(Lib.isPlainObject(arg)) {
15391580
ax = arg;
15401581
independent = true;
1541-
} else if(!arg || arg === 'redraw' || Array.isArray(arg)) {
1542-
var axList = (!arg || arg === 'redraw') ? axes.listIds(gd) : arg;
1543-
1544-
if(arg === 'redraw') {
1545-
fullLayout._paper.selectAll('g.subplot').each(function(subplot) {
1546-
var plotinfo = fullLayout._plots[subplot];
1547-
var xa = plotinfo.xaxis;
1548-
var ya = plotinfo.yaxis;
1549-
1550-
plotinfo.xaxislayer.selectAll('.' + xa._id + 'tick').remove();
1551-
plotinfo.yaxislayer.selectAll('.' + ya._id + 'tick').remove();
1552-
if(plotinfo.gridlayer) plotinfo.gridlayer.selectAll('path').remove();
1553-
if(plotinfo.zerolinelayer) plotinfo.zerolinelayer.selectAll('path').remove();
1554-
fullLayout._infolayer.select('.g-' + xa._id + 'title').remove();
1555-
fullLayout._infolayer.select('.g-' + ya._id + 'title').remove();
1556-
});
1557-
}
1558-
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-
}));
15691582
} else {
15701583
ax = axes.getFromId(gd, arg);
15711584
}

src/plots/cartesian/dragbox.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var FROM_TL = require('../../constants/alignment').FROM_TL;
2626

2727
var Plots = require('../plots');
2828

29-
var doTicks = require('./axes').doTicks;
29+
var doTicksSingle = require('./axes').doTicksSingle;
3030
var getFromId = require('./axis_ids').getFromId;
3131
var prepSelect = require('./select').prepSelect;
3232
var clearSelect = require('./select').clearSelect;
@@ -585,7 +585,7 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
585585
updates = {};
586586
for(i = 0; i < activeAxIds.length; i++) {
587587
var axId = activeAxIds[i];
588-
doTicks(gd, axId, true);
588+
doTicksSingle(gd, axId, true);
589589
var ax = getFromId(gd, axId);
590590
updates[ax._name + '.range[0]'] = ax.range[0];
591591
updates[ax._name + '.range[1]'] = ax.range[1];

src/plots/cartesian/transition_axes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ module.exports = function transitionAxes(gd, newLayout, transitionOpts, makeOnCo
125125
activeAxIds = [xa._id, ya._id];
126126

127127
for(i = 0; i < activeAxIds.length; i++) {
128-
Axes.doTicks(gd, activeAxIds[i], true);
128+
Axes.doTicksSingle(gd, activeAxIds[i], true);
129129
}
130130

131131
function redrawObjs(objArray, method, shortCircuit) {

src/plots/polar/polar.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function Polar(gd, id) {
6060
.attr('class', id);
6161

6262
// unfortunately, we have to keep track of some axis tick settings
63-
// so that we don't have to call Axes.doTicks with its special redraw flag
63+
// so that we don't have to call Axes.doTicksSingle with its special redraw flag
6464
this.radialTickLayout = null;
6565
this.angularTickLayout = null;
6666
}
@@ -286,7 +286,7 @@ proto.updateRadialAxis = function(fullLayout, polarLayout) {
286286
anchor: 'free',
287287
position: 0,
288288

289-
// dummy truthy value to make Axes.doTicks draw the grid
289+
// dummy truthy value to make Axes.doTicksSingle draw the grid
290290
_counteraxis: true,
291291

292292
// don't use automargins routine for labels
@@ -302,7 +302,7 @@ proto.updateRadialAxis = function(fullLayout, polarLayout) {
302302
// rotate auto tick labels by 180 if in quadrant II and III to make them
303303
// readable from left-to-right
304304
//
305-
// TODO try moving deeper in doTicks for better results?
305+
// TODO try moving deeper in doTicksSingle for better results?
306306
if(ax.tickangle === 'auto' && (a0 > 90 && a0 <= 270)) {
307307
ax.tickangle = 180;
308308
}
@@ -324,7 +324,7 @@ proto.updateRadialAxis = function(fullLayout, polarLayout) {
324324
_this.radialTickLayout = newTickLayout;
325325
}
326326

327-
Axes.doTicks(gd, ax, true);
327+
Axes.doTicksSingle(gd, ax, true);
328328

329329
updateElement(layers['radial-axis'], radialLayout.showticklabels || radialLayout.ticks, {
330330
transform: strTranslate(cx, cy) + strRotate(-radialLayout.angle)
@@ -413,7 +413,7 @@ proto.updateAngularAxis = function(fullLayout, polarLayout) {
413413
anchor: 'free',
414414
position: 0,
415415

416-
// dummy truthy value to make Axes.doTicks draw the grid
416+
// dummy truthy value to make Axes.doTicksSingle draw the grid
417417
_counteraxis: true,
418418

419419
// don't use automargins routine for labels
@@ -460,7 +460,7 @@ proto.updateAngularAxis = function(fullLayout, polarLayout) {
460460
setScale(ax, angularLayout, fullLayout);
461461

462462
// wrapper around c2rad from setConvertAngular
463-
// note that linear ranges are always set in degrees for Axes.doTicks
463+
// note that linear ranges are always set in degrees for Axes.doTicksSingle
464464
function c2rad(d) {
465465
return ax.c2rad(d.x, 'degrees');
466466
}
@@ -530,7 +530,7 @@ proto.updateAngularAxis = function(fullLayout, polarLayout) {
530530
_this.angularTickLayout = newTickLayout;
531531
}
532532

533-
Axes.doTicks(gd, ax, true);
533+
Axes.doTicksSingle(gd, ax, true);
534534

535535
updateElement(layers['angular-line'].select('path'), angularLayout.showline, {
536536
d: pathSectorClosed(radius, sector),
@@ -833,7 +833,7 @@ proto.updateRadialDrag = function(fullLayout, polarLayout) {
833833
if((drange > 0) !== (rprime > range0[0])) return;
834834
rng1 = radialAxis.range[1] = rprime;
835835

836-
Axes.doTicks(gd, _this.radialAxis, true);
836+
Axes.doTicksSingle(gd, _this.radialAxis, true);
837837
layers['radial-grid']
838838
.attr('transform', strTranslate(cx, cy))
839839
.selectAll('path').attr('transform', null);
@@ -961,7 +961,7 @@ proto.updateAngularDrag = function(fullLayout, polarLayout) {
961961
}
962962

963963
setConvertAngular(angularAxis);
964-
Axes.doTicks(gd, angularAxis, true);
964+
Axes.doTicksSingle(gd, angularAxis, true);
965965

966966
if(_this._hasClipOnAxisFalse && !isFullCircle(sector)) {
967967
// mutate sector to trick isPtWithinSector

src/plots/ternary/ternary.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,9 @@ proto.drawAxes = function(doTitles) {
376376
caxis = _this.caxis;
377377
// 3rd arg true below skips titles, so we can configure them
378378
// correctly later on.
379-
Axes.doTicks(gd, aaxis, true);
380-
Axes.doTicks(gd, baxis, true);
381-
Axes.doTicks(gd, caxis, true);
379+
Axes.doTicksSingle(gd, aaxis, true);
380+
Axes.doTicksSingle(gd, baxis, true);
381+
Axes.doTicksSingle(gd, caxis, true);
382382

383383
if(doTitles) {
384384
var apad = Math.max(aaxis.showticklabels ? aaxis.tickfont.size / 2 : 0,

0 commit comments

Comments
 (0)