Skip to content

Commit ca49a5a

Browse files
committed
Axis toolpanel fixes
1 parent 4af500a commit ca49a5a

File tree

8 files changed

+97
-77
lines changed

8 files changed

+97
-77
lines changed

src/plot_api/plot_api.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1313,9 +1313,29 @@ function _restyle(gd, aobj, _traces) {
13131313
'xcalendar', 'ycalendar',
13141314
'cumulative', 'cumulative.enabled', 'cumulative.direction', 'cumulative.currentbin',
13151315
'a0', 'da', 'b0', 'db', 'atype', 'btype',
1316-
'cheaterslope', 'carpetid', 'sum'
1316+
'cheaterslope', 'carpetid', 'sum',
13171317
];
13181318

1319+
var carpetAxisAttributes = [
1320+
'color', 'smoothing', 'title', 'titlefont', 'titlefont.size', 'titlefont.family',
1321+
'titlefont.color', 'titleoffset', 'type', 'autorange', 'rangemode', 'range',
1322+
'fixedrange', 'cheatertype', 'tickmode', 'nticks', 'tickvals', 'ticktext',
1323+
'ticks', 'mirror', 'ticklen', 'tickwidth', 'tickcolor', 'showticklabels',
1324+
'tickfont', 'tickfont.size', 'tickfont.family', 'tickfont.color', 'tickprefix',
1325+
'showtickprefix', 'ticksuffix', 'showticksuffix', 'showexponent', 'exponentformat',
1326+
'separatethousands', 'tickformat', 'categoryorder', 'categoryarray', 'labelpadding',
1327+
'labelprefix', 'labelsuffix', 'labelfont', 'labelfont.family', 'labelfont.size',
1328+
'labelfont.color', 'showline', 'linecolor', 'linewidth', 'gridcolor', 'gridwidth',
1329+
'showgrid', 'minorgridcount', 'minorgridwidth', 'minorgridcolor', 'startline',
1330+
'startlinecolor', 'startlinewidth', 'endline', 'endlinewidth', 'endlinecolor',
1331+
'tick0', 'dtick', 'arraytick0', 'arraydtick', 'hoverformat', 'tickangle'
1332+
];
1333+
1334+
for(i = 0; i < carpetAxisAttributes.length; i++) {
1335+
recalcAttrs.push('aaxis.' + carpetAxisAttributes[i]);
1336+
recalcAttrs.push('baxis.' + carpetAxisAttributes[i]);
1337+
}
1338+
13191339
for(i = 0; i < traces.length; i++) {
13201340
if(Registry.traceIs(fullData[traces[i]], 'box')) {
13211341
recalcAttrs.push('name');

src/traces/carpet/axis_attributes.js

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ module.exports = {
5454
// '-' means we haven't yet run autotype or couldn't find any data
5555
// it gets turned into linear in gd._fullLayout but not copied back
5656
// to gd.data like the others are.
57-
values: ['-', 'linear', 'log', 'date', 'category'],
57+
values: ['-', 'linear', 'date', 'category'],
5858
dflt: '-',
5959
role: 'info',
6060
description: [
@@ -160,17 +160,6 @@ module.exports = {
160160
'Used with `tickvals`.'
161161
].join(' ')
162162
},
163-
ticks: {
164-
valType: 'enumerated',
165-
values: ['outside', 'inside', ''],
166-
role: 'style',
167-
description: [
168-
'Determines whether ticks are drawn or not.',
169-
'If **, this axis\' ticks are not drawn.',
170-
'If *outside* (*inside*), this axis\' are drawn outside (inside)',
171-
'the axis lines.'
172-
].join(' ')
173-
},
174163
mirror: {
175164
valType: 'enumerated',
176165
values: [true, 'ticks', false, 'all', 'allticks'],
@@ -187,26 +176,6 @@ module.exports = {
187176
'on all shared-axes subplots.'
188177
].join(' ')
189178
},
190-
ticklen: {
191-
valType: 'number',
192-
min: 0,
193-
dflt: 5,
194-
role: 'style',
195-
description: 'Sets the tick length (in px).'
196-
},
197-
tickwidth: {
198-
valType: 'number',
199-
min: 0,
200-
dflt: 1,
201-
role: 'style',
202-
description: 'Sets the tick width (in px).'
203-
},
204-
tickcolor: {
205-
valType: 'color',
206-
dflt: colorAttrs.defaultLine,
207-
role: 'style',
208-
description: 'Sets the tick color.'
209-
},
210179
showticklabels: {
211180
valType: 'enumerated',
212181
values: ['start', 'end', 'both', 'none'],
@@ -358,9 +327,6 @@ module.exports = {
358327
role: 'style',
359328
description: 'Sets a axis label suffix.'
360329
},
361-
labelfont: extendFlat({}, fontAttrs, {
362-
description: 'Sets the label font.'
363-
}),
364330
// lines and grids
365331
showline: {
366332
valType: 'boolean',
@@ -492,19 +458,4 @@ module.exports = {
492458
role: 'info',
493459
description: 'The stride between grid lines along the axis'
494460
},
495-
hoverformat: {
496-
valType: 'string',
497-
dflt: '',
498-
role: 'style',
499-
description: [
500-
'Sets the hover text formatting rule using d3 formatting mini-languages',
501-
'which are very similar to those in Python. For numbers, see:',
502-
'https://github.com/d3/d3-format/blob/master/README.md#locale_format',
503-
'And for dates see:',
504-
'https://github.com/d3/d3-time-format/blob/master/README.md#locale_format',
505-
'We add one item to d3\'s date formatter: *%{n}f* for fractional seconds',
506-
'with n digits. For example, *2016-10-13 09:15:23.456* with tickformat',
507-
'*%H~%M~%S.%2f* would display *09~15~23.46*'
508-
].join(' ')
509-
},
510461
};

src/traces/carpet/axis_defaults.js

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ var addOpacity = require('../../components/color').addOpacity;
1515
var Registry = require('../../registry');
1616
var Lib = require('../../lib');
1717
var handleTickValueDefaults = require('../../plots/cartesian/tick_value_defaults');
18-
var handleTickMarkDefaults = require('../../plots/cartesian/tick_mark_defaults');
1918
var handleTickLabelDefaults = require('../../plots/cartesian/tick_label_defaults');
2019
var handleCategoryOrderDefaults = require('../../plots/cartesian/category_order_defaults');
2120
var setConvert = require('../../plots/cartesian/set_convert');
@@ -40,6 +39,8 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, options)
4039
font = options.font || {},
4140
attributes = carpetAttrs[letter + 'axis'];
4241

42+
options.noHover = true;
43+
4344
function coerce(attr, dflt) {
4445
return Lib.coerce(containerIn, containerOut, attributes, attr, dflt);
4546
}
@@ -120,13 +121,10 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, options)
120121
size: Math.round(font.size * 1.2),
121122
color: dfltFontColor
122123
});
124+
123125
coerce('titleoffset');
124126

125-
Lib.coerceFont(coerce, 'tickfont', {
126-
family: font.family,
127-
size: Math.round(font.size * 1.2),
128-
color: dfltFontColor
129-
});
127+
coerce('tickangle');
130128

131129
var validRange = (
132130
(containerIn.range || []).length === 2 &&
@@ -144,13 +142,17 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, options)
144142

145143
handleTickValueDefaults(containerIn, containerOut, coerce, axType);
146144
handleTickLabelDefaults(containerIn, containerOut, coerce, axType, options);
147-
handleTickMarkDefaults(containerIn, containerOut, coerce, options);
148145
handleCategoryOrderDefaults(containerIn, containerOut, coerce);
149146

150147
var gridColor = coerce2('gridcolor', addOpacity(dfltColor, 0.3));
151148
var gridWidth = coerce2('gridwidth');
152149
var showGrid = coerce('showgrid');
153150

151+
if(!showGrid) {
152+
delete containerOut.gridcolor;
153+
delete containerOut.gridwidth;
154+
}
155+
154156
var startLineColor = coerce2('startlinecolor', dfltColor);
155157
var startLineWidth = coerce2('startlinewidth', gridWidth);
156158
var showStartLine = coerce('startline', containerOut.showgrid || !!startLineColor || !!startLineWidth);
@@ -176,6 +178,11 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, options)
176178
coerce('minorgridcount');
177179
coerce('minorgridwidth', gridWidth);
178180
coerce('minorgridcolor', addOpacity(gridColor, 0.06));
181+
182+
if(!containerOut.minorgridcount) {
183+
delete containerOut.minorgridwidth;
184+
delete containerOut.minorgridcolor;
185+
}
179186
}
180187

181188
containerOut._separators = options.fullLayout.separators;
@@ -185,16 +192,32 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, options)
185192
orderedCategories(letter, containerOut.categoryorder, containerOut.categoryarray, options.data) :
186193
[];
187194

195+
if(containerOut.showticklabels === 'none') {
196+
delete containerOut.tickfont;
197+
delete containerOut.tickangle;
198+
delete containerOut.showexponent;
199+
delete containerOut.exponentformat;
200+
delete containerOut.tickformat;
201+
delete containerOut.showticksuffix;
202+
delete containerOut.showtickprefix;
203+
}
204+
205+
if(!containerOut.showticksuffix) {
206+
delete containerOut.ticksuffix;
207+
}
208+
209+
if(!containerOut.showtickprefix) {
210+
delete containerOut.tickprefix;
211+
}
212+
188213
// It needs to be coerced, then something above overrides this deep in the axis code,
189214
// but no, we *actually* want to coerce this.
190215
coerce('tickmode');
191216

192-
// We'll never draw this. We just need a couple category management functions.
193-
Lib.coerceFont(coerce, 'labelfont', {
194-
family: font.family,
195-
size: font.size,
196-
color: containerOut.startlinecolor
197-
});
217+
if(!containerOut.title || (containerOut.title && containerOut.title.length === 0)) {
218+
delete containerOut.titlefont;
219+
delete containerOut.titleoffset;
220+
}
198221

199222
return containerOut;
200223
};

src/traces/carpet/calc_labels.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = function calcLabels(trace, axis) {
3131
dxy: gridline.dxy(0, 0),
3232
axis: gridline.axis,
3333
length: gridline.crossAxis.length,
34-
font: gridline.crossAxis.labelfont,
34+
font: gridline.axis.tickfont,
3535
isFirst: i === 0,
3636
isLast: i === gridlines.length - 1
3737
});
@@ -48,7 +48,7 @@ module.exports = function calcLabels(trace, axis) {
4848
dxy: gridline.dxy(gridline.crossLength - 2, 1),
4949
axis: gridline.axis,
5050
length: gridline.crossAxis.length,
51-
font: gridline.crossAxis.labelfont,
51+
font: gridline.axis.tickfont,
5252
isFirst: i === 0,
5353
isLast: i === gridlines.length - 1
5454
});

src/traces/carpet/orient_text.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,19 @@
99

1010
'use strict';
1111

12-
module.exports = function orientText(trace, xaxis, yaxis, xy, dxy) {
12+
module.exports = function orientText(trace, xaxis, yaxis, xy, dxy, refDxy) {
1313
var dx = dxy[0] * trace.dpdx(xaxis);
1414
var dy = dxy[1] * trace.dpdy(yaxis);
1515
var flip = 1;
1616

17+
var offsetMultiplier = 1.0;
18+
if(refDxy) {
19+
var l1 = Math.sqrt(dxy[0] * dxy[0] + dxy[1] * dxy[1]);
20+
var l2 = Math.sqrt(refDxy[0] * refDxy[0] + refDxy[1] * refDxy[1]);
21+
var dot = (dxy[0] * refDxy[0] + dxy[1] * refDxy[1]) / l1 / l2;
22+
offsetMultiplier = Math.max(0.0, dot);
23+
}
24+
1725
var angle = Math.atan2(dy, dx) * 180 / Math.PI;
1826
if(angle < -90) {
1927
angle += 180;
@@ -26,6 +34,7 @@ module.exports = function orientText(trace, xaxis, yaxis, xy, dxy) {
2634
return {
2735
angle: angle,
2836
flip: flip,
29-
p: trace.c2p(xy, xaxis, yaxis)
37+
p: trace.c2p(xy, xaxis, yaxis),
38+
offsetMultplier: offsetMultiplier
3039
};
3140
};

src/traces/carpet/plot.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ function plotOne(gd, plotinfo, cd) {
4747
var boundaryLayer = makeg(gridLayer, 'g', 'boundarylayer');
4848
var labelLayer = makeg(gridLayer, 'g', 'labellayer');
4949

50+
gridLayer.style('opacity', trace.opacity);
51+
5052
drawGridLines(xa, ya, majorLayer, aax, 'a', aax._gridlines, true);
5153
drawGridLines(xa, ya, majorLayer, bax, 'b', bax._gridlines, true);
5254
drawGridLines(xa, ya, minorLayer, aax, 'a', aax._minorgridlines, true);
@@ -142,7 +144,13 @@ function drawAxisLabels(tester, xaxis, yaxis, trace, t, layer, labels, labelClas
142144
labelJoin.each(function(label) {
143145
// Most of the positioning is done in calc_labels. Only the parts that depend upon
144146
// the screen space representation of the x and y axes are here:
145-
var orientation = orientText(trace, xaxis, yaxis, label.xy, label.dxy);
147+
var orientation;
148+
if(label.axis.tickangle === 'auto') {
149+
orientation = orientText(trace, xaxis, yaxis, label.xy, label.dxy);
150+
} else {
151+
var angle = (label.axis.tickangle + 180.0) * Math.PI / 180.0;
152+
orientation = orientText(trace, xaxis, yaxis, label.xy, [Math.cos(angle), Math.sin(angle)]);
153+
}
146154
var direction = (label.endAnchor ? -1 : 1) * orientation.flip;
147155
var bbox = measureText(tester, label.text, label.font);
148156

@@ -184,21 +192,28 @@ function drawAxisTitles(layer, trace, t, xa, ya, maxAExtent, maxBExtent) {
184192
}
185193

186194
function drawAxisTitle(layer, trace, t, xy, dxy, axis, xa, ya, offset, labelClass) {
187-
var titleJoin = layer.selectAll('text.' + labelClass).data([0]);
195+
var data = [];
196+
if(axis.title) data.push(axis.title);
197+
var titleJoin = layer.selectAll('text.' + labelClass).data(data);
188198

189199
titleJoin.enter().append('text')
190200
.classed(labelClass, true);
191201

192-
var orientation = orientText(trace, xa, ya, xy, dxy);
193-
194-
// In addition to the size of the labels, add on some extra padding:
195-
offset += axis.titlefont.size + axis.titleoffset;
196-
197202
// There's only one, but we'll do it as a join so it's updated nicely:
198203
titleJoin.each(function() {
204+
var orientation = orientText(trace, xa, ya, xy, dxy);
205+
206+
if(['start', 'both'].indexOf(axis.showticklabels) === -1) {
207+
offset = 0;
208+
}
209+
210+
// In addition to the size of the labels, add on some extra padding:
211+
offset += axis.titlefont.size + axis.titleoffset;
212+
213+
199214
var el = d3.select(this);
200215

201-
el.text(axis.title)
216+
el.text(axis.title || '')
202217
.attr('transform',
203218
'translate(' + orientation.p[0] + ',' + orientation.p[1] + ') ' +
204219
'rotate(' + orientation.angle + ') ' +

test/image/mocks/airfoil.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

test/image/mocks/cheater.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"data":[
33
{
44
"type":"carpet",
5+
"name": "carpet axis",
6+
"opacity": 0.2,
57
"a":[
68
0.1, 0.1, 0.1, 0.1,
79
0.3, 0.3, 0.3, 0.3,

0 commit comments

Comments
 (0)