Skip to content
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

Implement ticklabelstep on 2D axes & colorbars #6088

Merged
merged 26 commits into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
49362b8
implement ticklabeljump on cartesian axes & colorbars
archmoj Jan 21, 2022
29ab444
jump label based on tick index
archmoj Jan 21, 2022
3b259ed
persistent tick labels
archmoj Jan 24, 2022
2676d24
rename attribute to skipticklabels and update description
archmoj Jan 25, 2022
87e3340
noskipticklabels > noSkipticklabels
archmoj Feb 3, 2022
272534c
jumpLabel > skipLabel
archmoj Feb 3, 2022
3734680
respect tick0 for monthly dtick
archmoj Feb 3, 2022
3d46d98
preserve date heads while skipping labels
archmoj Feb 3, 2022
a72616a
add test for date axes
archmoj Feb 3, 2022
89a2d91
skipticklabels > ticklabelstep
archmoj Feb 3, 2022
e973258
more skipticklabels > ticklabelstep
archmoj Feb 3, 2022
7587333
revise dflt
archmoj Feb 3, 2022
ad2b9a0
update schema changes
archmoj Feb 3, 2022
e91bd55
do not allow steps on multicategory and log axes
archmoj Feb 3, 2022
43af54a
improve description
archmoj Feb 3, 2022
be33ec3
update schema
archmoj Feb 3, 2022
cd65497
no effect when array tickmode
archmoj Feb 3, 2022
eed58e0
update schema
archmoj Feb 3, 2022
a883124
update PR log
archmoj Feb 3, 2022
bea95b1
Update src/plots/cartesian/layout_attributes.js
archmoj Feb 4, 2022
25724fb
schema diff
archmoj Feb 4, 2022
40a5532
simplify process of skipping labels
archmoj Feb 4, 2022
bbb4064
ensure heads when labels are skipped
archmoj Feb 4, 2022
61598b8
use last visible for rangebreaks too
archmoj Feb 4, 2022
ee7628a
refactor - use hideLabel function
archmoj Feb 4, 2022
d834bbb
fix typo hideLabel
archmoj Feb 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/colorbar/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ module.exports = overrideAll({
ticklen: axesAttrs.ticklen,
tickwidth: axesAttrs.tickwidth,
tickcolor: axesAttrs.tickcolor,
ticklabeljump: axesAttrs.ticklabeljump,
showticklabels: axesAttrs.showticklabels,
tickfont: fontAttrs({
description: 'Sets the color bar\'s tick label font'
Expand Down
1 change: 1 addition & 0 deletions src/components/colorbar/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,7 @@ function mockColorBarAxis(gd, opts, zrange) {
showticklabels: opts.showticklabels,
ticklabelposition: opts.ticklabelposition,
ticklabeloverflow: opts.ticklabeloverflow,
ticklabeljump: opts.ticklabeljump,
tickfont: opts.tickfont,
tickangle: opts.tickangle,
tickformat: opts.tickformat,
Expand Down
34 changes: 30 additions & 4 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,8 @@ axes.calcTicks = function calcTicks(ax, opts) {
var minRange = Math.min(rng[0], rng[1]);
var maxRange = Math.max(rng[0], rng[1]);

var isDLog = (ax.type === 'log') && !(isNumeric(ax.dtick) || ax.dtick.charAt(0) === 'L');
var numDtick = isNumeric(ax.dtick);
var isDLog = (ax.type === 'log') && !(numDtick || ax.dtick.charAt(0) === 'L');
var isPeriod = ax.ticklabelmode === 'period';

// find the first tick
Expand Down Expand Up @@ -834,13 +835,25 @@ axes.calcTicks = function calcTicks(ax, opts) {
x = axes.tickIncrement(x, ax.dtick, !axrev, ax.calendar);
}

var ticklabeljump = ax.ticklabeljump;

var maxTicks = Math.max(1000, ax._length || 0);
var tickVals = [];
var xPrevious = null;

var dTick = numDtick ? ax.dtick : ax._roughDTick;

var id = Math.round((
ax.r2l(x) -
ax.r2l(ax.tick0)
) / dTick) - 1;

for(;
(axrev) ? (x >= endTick) : (x <= endTick);
x = axes.tickIncrement(x, ax.dtick, axrev, ax.calendar)
) {
id++;

if(ax.rangebreaks) {
if(!axrev) {
if(x < startTick) continue;
Expand All @@ -858,10 +871,16 @@ axes.calcTicks = function calcTicks(ax, opts) {
minor = true;
}

tickVals.push({
var obj = {
minor: minor,
value: x
});
};

if(ticklabeljump && (id % (ticklabeljump + 1))) {
obj.jumpLabel = true;
}

tickVals.push(obj);
}

if(isPeriod) positionPeriodTicks(tickVals, ax, ax._definedDelta);
Expand Down Expand Up @@ -927,6 +946,10 @@ axes.calcTicks = function calcTicks(ax, opts) {
_minor // noSuffixPrefix
);

if(tickVals[i].jumpLabel) {
t.jumpLabel = true;
}

p = tickVals[i].periodX;
if(p !== undefined) {
t.periodX = p;
Expand Down Expand Up @@ -2966,7 +2989,10 @@ axes.drawLabels = function(gd, ax, opts) {
var axId = ax._id;
var axLetter = axId.charAt(0);
var cls = opts.cls || axId + 'tick';
var vals = opts.vals;

var vals = ax.ticklabeljump ?
opts.vals.filter(function(d) { return !d.jumpLabel; }) :
opts.vals;

var labelFns = opts.labelFns;
var tickAngle = opts.secondary ? 0 : ax.tickangle;
Expand Down
10 changes: 10 additions & 0 deletions src/plots/cartesian/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,16 @@ module.exports = {
'To set ticks every 4 years, set `dtick` to *M48*'
].join(' ')
},
ticklabeljump: {
valType: 'integer',
min: 0,
dflt: 0,
editType: 'ticks',
description: [
'Sets the step between ticklabels.',
'Could be used to hide labels between every n-th ticks.'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right that dticklabel isn't a good name as it implies it should have the same units as dtick instead of being an integer multiplying dtick. I don't love jump though. Some thoughts:

  • ticksperlabel (feels to me like the most precise name, and it's fairly concise, but it sort of makes it look like the ticks are modified rather than the labels)
  • skipticklabels (but then it should mean "how many do we skip," ie 1 should mean "show every 2nd" and 0 should be the default behavior - add one to get the current meaning)
  • any other suggestions?

If we keep the current meaning, the default and min should be 1 instead of 0. Either way the description could be made more explicit, something like:

Sets the spacing between tick labels as compared to the spacing between ticks. A value of 1 (default) means each tick gets a label. A larger value n means only every nth tick is labeled. tick0 determines which labels are shown.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I uses skipticklabels in 2676d24.
But how about ticklabelpace?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, let's stick with skipticklabels - I still don't love it but it's the best we have so far.

].join(' ')
},
tickvals: {
valType: 'data_array',
editType: 'ticks',
Expand Down
2 changes: 2 additions & 0 deletions src/plots/cartesian/tick_label_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ module.exports = function handleTickLabelDefaults(containerIn, containerOut, coe
color: dfltFontColor
});

if(!options.noTicklabeljump) coerce('ticklabeljump');

if(!options.noAng) coerce('tickangle');

if(axType !== 'category') {
Expand Down
1 change: 1 addition & 0 deletions src/plots/gl3d/layout/axis_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, options) {
showGrid: true,
noTickson: true,
noTicklabelmode: true,
noTicklabeljump: true,
noTicklabelposition: true,
noTicklabeloverflow: true,
bgColor: options.bgColor,
Expand Down
1 change: 1 addition & 0 deletions src/plots/polar/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var axisTickAttrs = overrideAll({
ticklen: axesAttrs.ticklen,
tickwidth: axesAttrs.tickwidth,
tickcolor: axesAttrs.tickcolor,
ticklabeljump: axesAttrs.ticklabeljump,
showticklabels: axesAttrs.showticklabels,
showtickprefix: axesAttrs.showtickprefix,
tickprefix: axesAttrs.tickprefix,
Expand Down
1 change: 1 addition & 0 deletions src/plots/smith/layout_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ function handleDefaults(contIn, contOut, coerce, opts) {
}

handleTickLabelDefaults(axIn, axOut, coerceAxis, axOut.type, {
noTicklabeljump: true,
noAng: !isRealAxis,
noExp: true,
font: {
Expand Down
1 change: 1 addition & 0 deletions src/plots/ternary/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var ternaryAxesAttrs = {
ticklen: axesAttrs.ticklen,
tickwidth: axesAttrs.tickwidth,
tickcolor: axesAttrs.tickcolor,
ticklabeljump: axesAttrs.ticklabeljump,
showticklabels: axesAttrs.showticklabels,
showtickprefix: axesAttrs.showtickprefix,
tickprefix: axesAttrs.tickprefix,
Expand Down
1 change: 1 addition & 0 deletions src/traces/carpet/ab_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function mimickAxisDefaults(traceIn, traceOut, fullLayout, dfltColor) {
var axOut = Template.newContainer(traceOut, axName);

var defaultOptions = {
noTicklabeljump: true,
tickfont: 'x',
id: axLetter + 'axis',
letter: axLetter,
Expand Down
1 change: 1 addition & 0 deletions src/traces/indicator/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ module.exports = {
ticklen: axesAttrs.ticklen,
tickwidth: axesAttrs.tickwidth,
tickcolor: axesAttrs.tickcolor,
ticklabeljump: axesAttrs.ticklabeljump,
showticklabels: axesAttrs.showticklabels,
tickfont: fontAttrs({
description: 'Sets the color bar\'s tick label font'
Expand Down
Binary file modified test/image/baselines/h-colorbar05.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/indicator_attrs.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/period_positioning7.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/polar_ticks.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/ternary_array_styles.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions test/image/mocks/h-colorbar05.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"len": 0.5,
"ticks": "inside",
"dtick": 20,
"ticklabeljump": 1,
"ticklabelposition": "inside right",
"ticklen": 5,
"bgcolor": "rgba(255,255,0,0.5)",
Expand Down Expand Up @@ -46,6 +47,7 @@
}
},
"xaxis": {
"ticklabeljump": 1,
"side": "top"
}
}
Expand Down
1 change: 1 addition & 0 deletions test/image/mocks/indicator_attrs.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"tickwidth": 5,
"tickcolor": "blue",
"showticklabels": true,
"ticklabeljump": 1,
"tickfont": {
"family": "Arial",
"size": 16,
Expand Down
1 change: 1 addition & 0 deletions test/image/mocks/period_positioning7.json
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@
"dtick": 604800000,
"tickformat": "%W",
"ticklabelmode": "period",
"ticklabeljump": 3,
"tickcolor": "black"
}
}
Expand Down
1 change: 1 addition & 0 deletions test/image/mocks/polar_ticks.json
Original file line number Diff line number Diff line change
Expand Up @@ -1854,6 +1854,7 @@
},
"radialaxis": {},
"angularaxis": {
"ticklabeljump": 2,
"dtick": 10,
"tickfont": {
"size": 10,
Expand Down
7 changes: 7 additions & 0 deletions test/image/mocks/ternary_array_styles.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,16 @@
"layout": {
"ternary": {
"aaxis": {
"ticklabeljump": 3,
"dtick": 0.05,
"showline": true,
"ticks": "inside",
"showgrid": true,
"color": "#ccc"
},
"baxis": {
"ticklabeljump": 1,
"dtick": 0.1,
"showline": true,
"ticks": "inside",
"showgrid": true,
Expand All @@ -132,6 +136,9 @@
},
"height": 450,
"width": 700,
"legend": {
"orientation": "h"
},
"autosize": false
}
}