Skip to content

Commit 695f311

Browse files
authored
Merge pull request #3254 from plotly/replace-axes-doTicks
Refactor Axes.doTicks and Axes.doTicksSingle
2 parents 196153e + 6ccc457 commit 695f311

File tree

15 files changed

+1174
-819
lines changed

15 files changed

+1174
-819
lines changed

Diff for: src/components/colorbar/draw.js

+29-11
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ module.exports = function draw(gd, id) {
187187
titlefont: opts.titlefont,
188188
showline: true,
189189
anchor: 'free',
190+
side: 'right',
190191
position: 1
191192
},
192193
cbAxisOut = {
@@ -281,7 +282,8 @@ module.exports = function draw(gd, id) {
281282
Math.round(gs.l) + ',-' +
282283
Math.round(gs.t) + ')');
283284

284-
cbAxisOut._axislayer = container.select('.cbaxis');
285+
var axisLayer = container.select('.cbaxis');
286+
285287
var titleHeight = 0;
286288
if(['top', 'bottom'].indexOf(opts.titleside) !== -1) {
287289
// draw the title so we know how much room it needs
@@ -357,8 +359,7 @@ module.exports = function draw(gd, id) {
357359
.attr('transform', 'translate(0,' +
358360
Math.round(gs.h * (1 - cbAxisOut.domain[1])) + ')');
359361

360-
cbAxisOut._axislayer.attr('transform', 'translate(0,' +
361-
Math.round(-gs.t) + ')');
362+
axisLayer.attr('transform', 'translate(0,' + Math.round(-gs.t) + ')');
362363

363364
var fills = container.select('.cbfills')
364365
.selectAll('rect.cbfill')
@@ -425,20 +426,37 @@ module.exports = function draw(gd, id) {
425426
});
426427

427428
// force full redraw of labels and ticks
428-
cbAxisOut._axislayer.selectAll('g.' + cbAxisOut._id + 'tick,path')
429-
.remove();
430-
431-
cbAxisOut._pos = xLeft + thickPx +
432-
(opts.outlinewidth||0) / 2 - (opts.ticks === 'outside' ? 1 : 0);
433-
cbAxisOut.side = 'right';
429+
axisLayer.selectAll('g.' + cbAxisOut._id + 'tick,path').remove();
434430

435431
// separate out axis and title drawing,
436432
// so we don't need such complicated logic in Titles.draw
437433
// if title is on the top or bottom, we've already drawn it
438434
// this title call only handles side=right
439435
return Lib.syncOrAsync([
440436
function() {
441-
return Axes.doTicksSingle(gd, cbAxisOut, true);
437+
var shift = xLeft + thickPx +
438+
(opts.outlinewidth || 0) / 2 - (opts.ticks === 'outside' ? 1 : 0);
439+
440+
var vals = Axes.calcTicks(cbAxisOut);
441+
var transFn = Axes.makeTransFn(cbAxisOut);
442+
var labelFns = Axes.makeLabelFns(cbAxisOut, shift);
443+
var tickSign = Axes.getTickSigns(cbAxisOut)[2];
444+
445+
Axes.drawTicks(gd, cbAxisOut, {
446+
vals: cbAxisOut.ticks === 'inside' ? Axes.clipEnds(cbAxisOut, vals) : vals,
447+
layer: axisLayer,
448+
path: Axes.makeTickPath(cbAxisOut, shift, tickSign),
449+
transFn: transFn
450+
});
451+
452+
return Axes.drawLabels(gd, cbAxisOut, {
453+
vals: vals,
454+
layer: axisLayer,
455+
transFn: transFn,
456+
labelXFn: labelFns.labelXFn,
457+
labelYFn: labelFns.labelYFn,
458+
labelAnchorFn: labelFns.labelAnchorFn
459+
});
442460
},
443461
function() {
444462
if(['top', 'bottom'].indexOf(opts.titleside) === -1) {
@@ -499,7 +517,7 @@ module.exports = function draw(gd, id) {
499517
// TODO: why are we redrawing multiple times now with this?
500518
// I guess autoMargin doesn't like being post-promise?
501519
var innerWidth = thickPx + opts.outlinewidth / 2 +
502-
Drawing.bBox(cbAxisOut._axislayer.node()).width;
520+
Drawing.bBox(axisLayer.node()).width;
503521
titleEl = titleCont.select('text');
504522
if(titleEl.node() && !titleEl.classed(cn.jsPlaceholder)) {
505523
var mathJaxNode = titleCont

Diff for: src/core.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require('es6-promise').polyfill();
1818
require('../build/plotcss');
1919

2020
// inject default MathJax config
21-
require('./fonts/mathjax_config');
21+
require('./fonts/mathjax_config')();
2222

2323
// include registry module and expose register method
2424
var Registry = require('./registry');

Diff for: src/fonts/mathjax_config.js

+15-21
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,20 @@
1010

1111
/* global MathJax:false */
1212

13-
/**
14-
* Check and configure MathJax
15-
*/
16-
if(typeof MathJax !== 'undefined') {
17-
exports.MathJax = true;
18-
19-
var globalConfig = (window.PlotlyConfig || {}).MathJaxConfig !== 'local';
13+
module.exports = function() {
14+
if(typeof MathJax !== 'undefined') {
15+
var globalConfig = (window.PlotlyConfig || {}).MathJaxConfig !== 'local';
2016

21-
if(globalConfig) {
22-
MathJax.Hub.Config({
23-
messageStyle: 'none',
24-
skipStartupTypeset: true,
25-
displayAlign: 'left',
26-
tex2jax: {
27-
inlineMath: [['$', '$'], ['\\(', '\\)']]
28-
}
29-
});
30-
MathJax.Hub.Configured();
17+
if(globalConfig) {
18+
MathJax.Hub.Config({
19+
messageStyle: 'none',
20+
skipStartupTypeset: true,
21+
displayAlign: 'left',
22+
tex2jax: {
23+
inlineMath: [['$', '$'], ['\\(', '\\)']]
24+
}
25+
});
26+
MathJax.Hub.Configured();
27+
}
3128
}
32-
33-
} else {
34-
exports.MathJax = false;
35-
}
29+
};

Diff for: src/plot_api/plot_api.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ exports.plot = function(gd, data, layout, config) {
350350

351351
// draw ticks, titles, and calculate axis scaling (._b, ._m)
352352
function drawAxes() {
353-
return Axes.doTicks(gd, graphWasEmpty ? '' : 'redraw');
353+
return Axes.draw(gd, graphWasEmpty ? '' : 'redraw');
354354
}
355355

356356
var seq = [
@@ -1797,13 +1797,13 @@ function addAxRangeSequence(seq, rangesAltered) {
17971797
// N.B. leave as sequence of subroutines (for now) instead of
17981798
// subroutine of its own so that finalDraw always gets
17991799
// executed after drawData
1800-
var doTicks = rangesAltered ?
1801-
function(gd) { return Axes.doTicks(gd, Object.keys(rangesAltered), true); } :
1802-
function(gd) { return Axes.doTicks(gd, 'redraw'); };
1800+
var drawAxes = rangesAltered ?
1801+
function(gd) { return Axes.draw(gd, Object.keys(rangesAltered), {skipTitle: true}); } :
1802+
function(gd) { return Axes.draw(gd, 'redraw'); };
18031803

18041804
seq.push(
18051805
subroutines.doAutoRangeAndConstraints,
1806-
doTicks,
1806+
drawAxes,
18071807
subroutines.drawData,
18081808
subroutines.finalDraw
18091809
);

Diff for: src/plot_api/subroutines.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ exports.doLegend = function(gd) {
539539
};
540540

541541
exports.doTicksRelayout = function(gd) {
542-
Axes.doTicks(gd, 'redraw');
542+
Axes.draw(gd, 'redraw');
543543

544544
if(gd._fullLayout._hasOnlyLargeSploms) {
545545
Registry.subplotsRegistry.splom.updateGrid(gd);

0 commit comments

Comments
 (0)