Skip to content

Commit

Permalink
Merge pull request #3254 from plotly/replace-axes-doTicks
Browse files Browse the repository at this point in the history
Refactor Axes.doTicks and Axes.doTicksSingle
  • Loading branch information
etpinard committed Nov 20, 2018
2 parents 196153e + 6ccc457 commit 695f311
Show file tree
Hide file tree
Showing 15 changed files with 1,174 additions and 819 deletions.
40 changes: 29 additions & 11 deletions src/components/colorbar/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ module.exports = function draw(gd, id) {
titlefont: opts.titlefont,
showline: true,
anchor: 'free',
side: 'right',
position: 1
},
cbAxisOut = {
Expand Down Expand Up @@ -281,7 +282,8 @@ module.exports = function draw(gd, id) {
Math.round(gs.l) + ',-' +
Math.round(gs.t) + ')');

cbAxisOut._axislayer = container.select('.cbaxis');
var axisLayer = container.select('.cbaxis');

var titleHeight = 0;
if(['top', 'bottom'].indexOf(opts.titleside) !== -1) {
// draw the title so we know how much room it needs
Expand Down Expand Up @@ -357,8 +359,7 @@ module.exports = function draw(gd, id) {
.attr('transform', 'translate(0,' +
Math.round(gs.h * (1 - cbAxisOut.domain[1])) + ')');

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

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

// force full redraw of labels and ticks
cbAxisOut._axislayer.selectAll('g.' + cbAxisOut._id + 'tick,path')
.remove();

cbAxisOut._pos = xLeft + thickPx +
(opts.outlinewidth||0) / 2 - (opts.ticks === 'outside' ? 1 : 0);
cbAxisOut.side = 'right';
axisLayer.selectAll('g.' + cbAxisOut._id + 'tick,path').remove();

// separate out axis and title drawing,
// so we don't need such complicated logic in Titles.draw
// if title is on the top or bottom, we've already drawn it
// this title call only handles side=right
return Lib.syncOrAsync([
function() {
return Axes.doTicksSingle(gd, cbAxisOut, true);
var shift = xLeft + thickPx +
(opts.outlinewidth || 0) / 2 - (opts.ticks === 'outside' ? 1 : 0);

var vals = Axes.calcTicks(cbAxisOut);
var transFn = Axes.makeTransFn(cbAxisOut);
var labelFns = Axes.makeLabelFns(cbAxisOut, shift);
var tickSign = Axes.getTickSigns(cbAxisOut)[2];

Axes.drawTicks(gd, cbAxisOut, {
vals: cbAxisOut.ticks === 'inside' ? Axes.clipEnds(cbAxisOut, vals) : vals,
layer: axisLayer,
path: Axes.makeTickPath(cbAxisOut, shift, tickSign),
transFn: transFn
});

return Axes.drawLabels(gd, cbAxisOut, {
vals: vals,
layer: axisLayer,
transFn: transFn,
labelXFn: labelFns.labelXFn,
labelYFn: labelFns.labelYFn,
labelAnchorFn: labelFns.labelAnchorFn
});
},
function() {
if(['top', 'bottom'].indexOf(opts.titleside) === -1) {
Expand Down Expand Up @@ -499,7 +517,7 @@ module.exports = function draw(gd, id) {
// TODO: why are we redrawing multiple times now with this?
// I guess autoMargin doesn't like being post-promise?
var innerWidth = thickPx + opts.outlinewidth / 2 +
Drawing.bBox(cbAxisOut._axislayer.node()).width;
Drawing.bBox(axisLayer.node()).width;
titleEl = titleCont.select('text');
if(titleEl.node() && !titleEl.classed(cn.jsPlaceholder)) {
var mathJaxNode = titleCont
Expand Down
2 changes: 1 addition & 1 deletion src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require('es6-promise').polyfill();
require('../build/plotcss');

// inject default MathJax config
require('./fonts/mathjax_config');
require('./fonts/mathjax_config')();

// include registry module and expose register method
var Registry = require('./registry');
Expand Down
36 changes: 15 additions & 21 deletions src/fonts/mathjax_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,20 @@

/* global MathJax:false */

/**
* Check and configure MathJax
*/
if(typeof MathJax !== 'undefined') {
exports.MathJax = true;

var globalConfig = (window.PlotlyConfig || {}).MathJaxConfig !== 'local';
module.exports = function() {
if(typeof MathJax !== 'undefined') {
var globalConfig = (window.PlotlyConfig || {}).MathJaxConfig !== 'local';

if(globalConfig) {
MathJax.Hub.Config({
messageStyle: 'none',
skipStartupTypeset: true,
displayAlign: 'left',
tex2jax: {
inlineMath: [['$', '$'], ['\\(', '\\)']]
}
});
MathJax.Hub.Configured();
if(globalConfig) {
MathJax.Hub.Config({
messageStyle: 'none',
skipStartupTypeset: true,
displayAlign: 'left',
tex2jax: {
inlineMath: [['$', '$'], ['\\(', '\\)']]
}
});
MathJax.Hub.Configured();
}
}

} else {
exports.MathJax = false;
}
};
10 changes: 5 additions & 5 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ exports.plot = function(gd, data, layout, config) {

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

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

seq.push(
subroutines.doAutoRangeAndConstraints,
doTicks,
drawAxes,
subroutines.drawData,
subroutines.finalDraw
);
Expand Down
2 changes: 1 addition & 1 deletion src/plot_api/subroutines.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ exports.doLegend = function(gd) {
};

exports.doTicksRelayout = function(gd) {
Axes.doTicks(gd, 'redraw');
Axes.draw(gd, 'redraw');

if(gd._fullLayout._hasOnlyLargeSploms) {
Registry.subplotsRegistry.splom.updateGrid(gd);
Expand Down
Loading

0 comments on commit 695f311

Please sign in to comment.