Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
e5725c6
Property `drawminorticklabel` for drawing the label for each minor ti…
my-tien Jun 25, 2024
11fd3f1
Ensure correct spacing between ticklabels and ticks when using drawmi…
my-tien Jun 25, 2024
a3e41af
baseline test mock for drawminorticklabel
my-tien Jun 25, 2024
f7d9abf
Draftlog for PR 7036 (drawminorticklabel)
my-tien Jun 25, 2024
1f52f4e
"noDrawminorticklabel" exception for gl3d plots
my-tien Jun 25, 2024
35a7f51
Fix failing source-syntax check: missing newline in mock
my-tien Jun 27, 2024
0a80d24
Restrict drawminorticklabel to period axes
my-tien Jun 27, 2024
1e7ebc3
Revert "Ensure correct spacing between ticklabels and ticks when usin…
my-tien Jun 27, 2024
0671ebb
Update mock after restricting new property to period axes
my-tien Jun 27, 2024
6fcda1a
baseline image for zzz_drawminorticklabel_period_axes.png
my-tien Jun 27, 2024
21a573c
Refactor periodCompatibleWithTickformat to make behavior clearer.
my-tien Jul 5, 2024
e511fc8
Note about possible future extension of the minor tick label customiz…
my-tien Jul 4, 2024
7585121
Honor ticklabelstep also when using drawminorticklabel
my-tien Jul 5, 2024
e2493a6
drawminorticklabel mock for date_axes_period, date_axes_period2, date…
my-tien Jul 5, 2024
00971f1
Mention in description that drawminorticklabel only applies to period…
my-tien Jul 5, 2024
6f5ba12
Missing trailing newlines for mocks
my-tien Jul 5, 2024
cd7e7c1
Baseline images for new drawminorticklabel mocks
my-tien Jul 5, 2024
ee329a3
Merge remote-tracking branch 'origin-plotly/master' into custom_tick_…
my-tien Jul 5, 2024
0019cb0
Rename drawminorticklabel → ticklabelindex
my-tien Jul 8, 2024
e328c9f
Allow `ticklabelindex` also for non-period date axes and linear axes.
my-tien Jul 8, 2024
a580821
Update `ticklabelindex` description after allowing linear and date axes.
my-tien Jul 8, 2024
16d792c
Add constant ONEMILLI
my-tien Jul 8, 2024
82f1fa0
Fix missing EOF newline in zzz_date_axes_ticklabelindex.json
my-tien Jul 8, 2024
908deec
New and updated baseline images for ticklabelindex mocks
my-tien Jul 8, 2024
884d975
Satisfy eslint rules
my-tien Jul 8, 2024
6fd6bd4
Fix ticklabelindex for reversed axes
my-tien Jul 9, 2024
05d456d
Add `arrayOk` for `ticklabelindex`, add test case to mock
my-tien Jul 9, 2024
d351462
Update baseline image for zzz_ticklabelindex after adding more test c…
my-tien Jul 9, 2024
96a26da
replace Array.isArray with Lib.isArrayOrTypedArray
my-tien Jul 9, 2024
64e14d6
Add to ticklabelindex description how it can be useful for period axes
my-tien Jul 10, 2024
50b1e0f
Mention contributor in draftlog
my-tien Jul 10, 2024
86b43e4
refactor calcTicks
my-tien Jul 10, 2024
0515237
refactor calcTicks
my-tien Jul 10, 2024
b6903e4
comment about possible extra values for ticklabelindex
my-tien Jul 10, 2024
f8974e0
Mention contributor in draftlog for PR 7006
my-tien Jul 10, 2024
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
Prev Previous commit
Next Next commit
Rename drawminorticklabel → ticklabelindex
  • Loading branch information
my-tien committed Jul 8, 2024
commit 0019cb041a255a83fac4d682169a19b0bea4bbd7
2 changes: 1 addition & 1 deletion draftlogs/7036_add.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- Add axis property `drawminorticklabel` for drawing the label for each minor tick n positions away from a major tick [[#7036](https://github.com/plotly/plotly.js/pull/7036)]
- Add axis property `ticklabelindex` for drawing the label for each minor tick n positions away from a major tick [[#7036](https://github.com/plotly/plotly.js/pull/7036)]
20 changes: 10 additions & 10 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ axes.calcTicks = function calcTicks(ax, opts) {
var calendar = ax.calendar;
var ticklabelstep = ax.ticklabelstep;
var isPeriod = ax.ticklabelmode === 'period';
var drawMinorTickLabel = ax.drawminorticklabel;
var ticklabelIndex = ax.ticklabelindex;
var rng = Lib.simpleMap(ax.range, ax.r2l, undefined, undefined, opts);
var axrev = (rng[1] < rng[0]);
var minRange = Math.min(rng[0], rng[1]);
Expand All @@ -923,7 +923,7 @@ axes.calcTicks = function calcTicks(ax, opts) {
var tickVals = [];
var minorTickVals = [];
// all ticks for which labels are drawn which is not necessarily the major ticks when
// `drawminorticklabel` is set.
// `ticklabelindex` is set.
var labelTickVals = [];

var hasMinor = ax.minor && (ax.minor.ticks || ax.minor.showgrid);
Expand Down Expand Up @@ -1079,20 +1079,20 @@ axes.calcTicks = function calcTicks(ax, opts) {
}
}

// check if drawMinorTickLabel makes sense, otherwise ignore it
// check if ticklabelIndex makes sense, otherwise ignore it
if(!minorTickVals || minorTickVals.length < 2) {
drawMinorTickLabel = false;
ticklabelIndex = false;
} else {
var diff = minorTickVals[1].value - minorTickVals[0].value;
if(!periodCompatibleWithTickformat(diff, ax.tickformat)) {
drawMinorTickLabel = false;
ticklabelIndex = false;
}
}
// Determine for which ticks to draw labels
if(!drawMinorTickLabel) {
if (!ticklabelIndex) {
labelTickVals = tickVals;
} else {
// Collect and sort all major and minor ticks, to find the minor ticks `drawMinorTickLabel`
// Collect and sort all major and minor ticks, to find the minor ticks `ticklabelIndex`
// steps away from each major tick. For those minor ticks we want to draw the label.

var allTickVals = tickVals.concat(minorTickVals);
Expand All @@ -1115,7 +1115,7 @@ axes.calcTicks = function calcTicks(ax, opts) {
.filter(function(index) { return index !== null; });

majorTickIndices.forEach(function(majorIdx) {
var minorIdx = majorIdx + drawMinorTickLabel;
var minorIdx = majorIdx + ticklabelIndex;
if(minorIdx >= 0 && minorIdx < allTickVals.length) {
labelTickVals.push(allTickVals[minorIdx]);
}
Expand Down Expand Up @@ -1239,7 +1239,7 @@ axes.calcTicks = function calcTicks(ax, opts) {
var _value = tickVals[i].value;

if(_minor) {
if(drawMinorTickLabel && labelTickVals.indexOf(tickVals[i]) !== -1) {
if (ticklabelIndex && labelTickVals.indexOf(tickVals[i]) !== -1) {
t = setTickLabel(ax, tickVals[i]);
} else {
t = { x: _value };
Expand All @@ -1250,7 +1250,7 @@ axes.calcTicks = function calcTicks(ax, opts) {
lastVisibleHead = ax._prevDateHead;
t = setTickLabel(ax, tickVals[i]);
if(tickVals[i].skipLabel ||
drawMinorTickLabel && labelTickVals.indexOf(tickVals[i]) === -1) {
ticklabelIndex && labelTickVals.indexOf(tickVals[i]) === -1) {
hideLabel(t);
}

Expand Down
4 changes: 2 additions & 2 deletions src/plots/cartesian/axis_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, coerce,
}
}

if(!options.noDrawminorticklabel && axType === 'date' && containerOut.ticklabelmode === 'period') {
coerce('drawminorticklabel');
if(!options.noTicklabelindex && axType === 'date' && containerOut.ticklabelmode === 'period') {
coerce('ticklabelindex');
}

var ticklabelposition = '';
Expand Down
4 changes: 2 additions & 2 deletions src/plots/cartesian/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -721,15 +721,15 @@ module.exports = {
'outside and vice versa.'
].join(' ')
},
drawminorticklabel: {
ticklabelindex: {
// In the future maybe add `arrayOk: true` for labeling several minor ticks, e.g. [-1, 0, 1]
valType: 'integer',
editType: 'calc',
description: [
'Only for date axes with `ticklabelmode` *period*.',
'Instead of drawing the major tick label, draw the label for the minor tick',
'that is n positions away from the major tick. E.g. to always draw the label for the',
'minor tick before each major tick, choose `drawminorticklabel` -1'
'minor tick before each major tick, choose `ticklabelindex` -1'
].join(' ')
},
mirror: {
Expand Down
2 changes: 1 addition & 1 deletion src/plots/gl3d/layout/axis_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, options) {
data: options.data,
showGrid: true,
noAutotickangles: true,
noDrawminorticklabel: true,
noTicklabelindex: true,
noTickson: true,
noTicklabelmode: true,
noTicklabelshift: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
},
"tickcolor": "red",
"ticklabelmode": "period",
"drawminorticklabel": 4,
"ticklabelindex": 4,
"anchor": "y"
},
"xaxis2": {
Expand All @@ -170,7 +170,7 @@
"tickcolor": "red",
"ticklabelmode": "period",
"anchor": "y2",
"drawminorticklabel": 1
"ticklabelindex": 1
},
"xaxis3": {
"ticklabelstep": 2,
Expand All @@ -181,7 +181,7 @@
"tickcolor": "red",
"ticklabelmode": "period",
"anchor": "y3",
"drawminorticklabel": 1
"ticklabelindex": 1
},
"xaxis4": {
"ticklabelstep": 2,
Expand All @@ -192,7 +192,7 @@
"tickcolor": "red",
"ticklabelmode": "period",
"anchor": "y4",
"drawminorticklabel": 1
"ticklabelindex": 1
},
"xaxis5": {
"ticklabelstep": 2,
Expand All @@ -203,7 +203,7 @@
"tickcolor": "red",
"ticklabelmode": "period",
"anchor": "y5",
"drawminorticklabel": -2
"ticklabelindex": -2
},
"xaxis6": {
"ticklabelstep": 2,
Expand All @@ -214,7 +214,7 @@
"tickcolor": "red",
"ticklabelmode": "period",
"anchor": "y6",
"drawminorticklabel": 2
"ticklabelindex": 2
},
"xaxis7": {
"ticklabelstep": 2,
Expand All @@ -225,7 +225,7 @@
"tickcolor": "red",
"ticklabelmode": "period",
"anchor": "y7",
"drawminorticklabel": -3
"ticklabelindex": -3
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
],
"ticklabelmode": "period",
"tickformat": "%b %d, %Y",
"drawminorticklabel": 1,
"ticklabelindex": 1,
"tickangle": 30
},
"xaxis2": {
Expand All @@ -152,7 +152,7 @@
],
"ticklabelmode": "period",
"anchor": "y2",
"drawminorticklabel": -1,
"ticklabelindex": -1,
"tickangle": 20
},
"xaxis3": {
Expand All @@ -165,7 +165,7 @@
],
"ticklabelmode": "period",
"anchor": "y3",
"drawminorticklabel": 2,
"ticklabelindex": 2,
"tickangle": 20
},
"xaxis4": {
Expand All @@ -178,7 +178,7 @@
],
"ticklabelmode": "period",
"anchor": "y4",
"drawminorticklabel": 1,
"ticklabelindex": 1,
"tickangle": 20
},
"xaxis5": {
Expand All @@ -191,7 +191,7 @@
],
"ticklabelmode": "period",
"anchor": "y5",
"drawminorticklabel": -1,
"ticklabelindex": -1,
"tickangle": 20
},
"xaxis6": {
Expand All @@ -204,7 +204,7 @@
],
"ticklabelmode": "period",
"anchor": "y6",
"drawminorticklabel": 2,
"ticklabelindex": 2,
"tickangle": 20
},
"xaxis7": {
Expand All @@ -217,7 +217,7 @@
],
"ticklabelmode": "period",
"anchor": "y7",
"drawminorticklabel": -2,
"ticklabelindex": -2,
"tickangle": 20
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
"ticks": "outside",
"ticklabelmode": "period",
"tickcolor": "red",
"drawminorticklabel": 4
"ticklabelindex": 4
},
"xaxis2": {
"anchor": "y2",
Expand All @@ -163,7 +163,7 @@
"ticks": "outside",
"ticklabelmode": "period",
"tickcolor": "red",
"drawminorticklabel": -1
"ticklabelindex": -1
},
"xaxis3": {
"anchor": "y3",
Expand All @@ -174,7 +174,7 @@
"ticks": "outside",
"ticklabelmode": "period",
"tickcolor": "red",
"drawminorticklabel": -1
"ticklabelindex": -1
},
"xaxis4": {
"anchor": "y4",
Expand All @@ -185,7 +185,7 @@
"ticks": "outside",
"ticklabelmode": "period",
"tickcolor": "red",
"drawminorticklabel": 2
"ticklabelindex": 2
},
"xaxis5": {
"anchor": "y5",
Expand All @@ -196,7 +196,7 @@
"ticks": "outside",
"ticklabelmode": "period",
"tickcolor": "red",
"drawminorticklabel": 1
"ticklabelindex": 1
},
"xaxis6": {
"anchor": "y6",
Expand All @@ -207,7 +207,7 @@
"ticks": "outside",
"ticklabelmode": "period",
"tickcolor": "red",
"drawminorticklabel": -3
"ticklabelindex": -3
},
"xaxis7": {
"anchor": "y7",
Expand All @@ -218,7 +218,7 @@
"ticks": "outside",
"ticklabelmode": "period",
"tickcolor": "red",
"drawminorticklabel": 5
"ticklabelindex": 5
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
"bargap": 0.1,
"xaxis": {
"title": {
"text": "xaxis: `drawminorticklabel` is ignored because tickformat is incompatible with minor ticks"
"text": "xaxis: `ticklabelindex` is ignored because tickformat is incompatible with minor ticks"
},
"dtick": "M12",
"minor": {
Expand All @@ -158,7 +158,7 @@
},
"tickformat": "%Y",
"ticklabelmode": "period",
"drawminorticklabel": -1,
"ticklabelindex": -1,
"ticklen": 18,
"type": "date"
},
Expand All @@ -174,7 +174,7 @@
"ticks": "outside"
},
"tickformat": "%b %Y",
"drawminorticklabel": -1,
"ticklabelindex": -1,
"tickangle": 90,
"ticklabelmode": "period",
"ticklen": 18,
Expand Down
20 changes: 10 additions & 10 deletions test/plot-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -14097,11 +14097,6 @@
],
"valType": "info_array"
},
"drawminorticklabel": {
"description": "Only for date axes with `ticklabelmode` *period*. Instead of drawing the major tick label, draw the label for the minor tick that is n positions away from the major tick. E.g. to always draw the label for the minor tick before each major tick, choose `drawminorticklabel` -1",
"editType": "calc",
"valType": "integer"
},
"dtick": {
"description": "Sets the step in-between ticks on this axis. Use with `tick0`. Must be a positive number, or special strings available to *log* and *date* axes. If the axis `type` is *log*, then ticks are set every 10^(n*dtick) where n is the tick number. For example, to set a tick mark at 1, 10, 100, 1000, ... set dtick to 1. To set tick marks at 1, 100, 10000, ... set dtick to 2. To set tick marks at 1, 5, 25, 125, 625, 3125, ... set dtick to log_10(5), or 0.69897000433. *log* has several special values; *L<f>*, where `f` is a positive number, gives ticks linearly spaced in value (but not position). For example `tick0` = 0.1, `dtick` = *L0.5* will put ticks at 0.1, 0.6, 1.1, 1.6 etc. To show powers of 10 plus small digits between, use *D1* (all digits) or *D2* (only 2 and 5). `tick0` is ignored for *D1* and *D2*. If the axis `type` is *date*, then you must convert the time to milliseconds. For example, to set the interval between ticks to one day, set `dtick` to 86400000.0. *date* also has special values *M<n>* gives ticks spaced by a number of months. `n` must be a positive integer. To set ticks on the 15th of every third month, set `tick0` to *2000-01-15* and `dtick` to *M3*. To set ticks every 4 years, set `dtick` to *M48*",
"editType": "ticks",
Expand Down Expand Up @@ -15121,6 +15116,11 @@
},
"role": "object"
},
"ticklabelindex": {
"description": "Only for date axes with `ticklabelmode` *period*. Instead of drawing the major tick label, draw the label for the minor tick that is n positions away from the major tick. E.g. to always draw the label for the minor tick before each major tick, choose `ticklabelindex` -1",
"editType": "calc",
"valType": "integer"
},
"ticklabelmode": {
"description": "Determines where tick labels are drawn with respect to their corresponding ticks and grid lines. Only has an effect for axes of `type` *date* When set to *period*, tick labels are drawn in the middle of the period between ticks.",
"dflt": "instant",
Expand Down Expand Up @@ -15740,11 +15740,6 @@
],
"valType": "info_array"
},
"drawminorticklabel": {
"description": "Only for date axes with `ticklabelmode` *period*. Instead of drawing the major tick label, draw the label for the minor tick that is n positions away from the major tick. E.g. to always draw the label for the minor tick before each major tick, choose `drawminorticklabel` -1",
"editType": "calc",
"valType": "integer"
},
"dtick": {
"description": "Sets the step in-between ticks on this axis. Use with `tick0`. Must be a positive number, or special strings available to *log* and *date* axes. If the axis `type` is *log*, then ticks are set every 10^(n*dtick) where n is the tick number. For example, to set a tick mark at 1, 10, 100, 1000, ... set dtick to 1. To set tick marks at 1, 100, 10000, ... set dtick to 2. To set tick marks at 1, 5, 25, 125, 625, 3125, ... set dtick to log_10(5), or 0.69897000433. *log* has several special values; *L<f>*, where `f` is a positive number, gives ticks linearly spaced in value (but not position). For example `tick0` = 0.1, `dtick` = *L0.5* will put ticks at 0.1, 0.6, 1.1, 1.6 etc. To show powers of 10 plus small digits between, use *D1* (all digits) or *D2* (only 2 and 5). `tick0` is ignored for *D1* and *D2*. If the axis `type` is *date*, then you must convert the time to milliseconds. For example, to set the interval between ticks to one day, set `dtick` to 86400000.0. *date* also has special values *M<n>* gives ticks spaced by a number of months. `n` must be a positive integer. To set ticks on the 15th of every third month, set `tick0` to *2000-01-15* and `dtick` to *M3*. To set ticks every 4 years, set `dtick` to *M48*",
"editType": "ticks",
Expand Down Expand Up @@ -16447,6 +16442,11 @@
},
"role": "object"
},
"ticklabelindex": {
"description": "Only for date axes with `ticklabelmode` *period*. Instead of drawing the major tick label, draw the label for the minor tick that is n positions away from the major tick. E.g. to always draw the label for the minor tick before each major tick, choose `ticklabelindex` -1",
"editType": "calc",
"valType": "integer"
},
"ticklabelmode": {
"description": "Determines where tick labels are drawn with respect to their corresponding ticks and grid lines. Only has an effect for axes of `type` *date* When set to *period*, tick labels are drawn in the middle of the period between ticks.",
"dflt": "instant",
Expand Down