Skip to content

Refactor Axes.doTicks and Axes.doTicksSingle #3254

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 22 commits into from
Nov 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
66c37cd
add Axes.drawOne and companion methods
etpinard Nov 14, 2018
a2271eb
replace Axes.doTicks with Axes.draw
etpinard Nov 14, 2018
8f77f2c
sub doTicksSingle -> drawOne in dragbox and axis transition
etpinard Nov 14, 2018
7a6d24d
move translate, tick, label logic into own generators
etpinard Nov 15, 2018
2d8a963
use Axes.drawTicks and Axes.drawLabels in Colorbar.draw
etpinard Nov 15, 2018
36c1d64
generalize Axes.makeLabelFns to support pads about ticks at angles
etpinard Nov 15, 2018
73a38fd
use Axes drawTicsk, drawGrid and drawLabels in ternary drawAxes
etpinard Nov 15, 2018
38c6ad8
use drawTIcks, drawGrid and drawLabels to draw polar axes
etpinard Nov 16, 2018
2247377
use different transFn for polar ticks, grid and labels when convenient
etpinard Nov 16, 2018
d60e84d
bye-bye Axes.doTicksSingle
etpinard Nov 16, 2018
219eb08
lint (match variable name across axes.js methods)
etpinard Nov 14, 2018
944482c
add 'noCrisp' option to Axes.drawTicks and Axes.drawGrid
etpinard Nov 16, 2018
7033585
add Axes.getTickSigns
etpinard Nov 16, 2018
5858067
move Axes.drawTitle out of Axes.drawLabels
etpinard Nov 16, 2018
eb8e0d0
mv axis calcBoundingBox and autoMargin from drawLabels -> drawOne
etpinard Nov 16, 2018
3b8f7af
more d3-esque pattern in Axes.drawLabels
etpinard Nov 16, 2018
016b8e4
rename noCrisp -> crisp
etpinard Nov 19, 2018
ea6e76f
add jsDoc to new Axes methods
etpinard Nov 19, 2018
187ffd0
wrap mathjax_config into function
etpinard Nov 19, 2018
9c74e94
serve MathJax assets in karma tests (w/o bundling them)
etpinard Nov 19, 2018
ed7be86
test axis title scoot, including MathJax ;)
etpinard Nov 19, 2018
6ccc457
mv mathjax axis title test to a bundle_test suite
etpinard Nov 19, 2018
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
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