Skip to content

Commit 05d456d

Browse files
committed
Add arrayOk for ticklabelindex, add test case to mock
1 parent 6fd6bd4 commit 05d456d

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

src/plots/cartesian/axes.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,8 @@ axes.calcTicks = function calcTicks(ax, opts) {
911911
var ticklabelstep = ax.ticklabelstep;
912912
var isPeriod = ax.ticklabelmode === 'period';
913913
var isReversed = ax.range[0] > ax.range[1];
914-
var ticklabelIndex = ax.ticklabelindex;
914+
var ticklabelIndex = (Array.isArray(ax.ticklabelindex) || !ax.ticklabelindex) ?
915+
ax.ticklabelindex : [ax.ticklabelindex];
915916
var rng = Lib.simpleMap(ax.range, ax.r2l, undefined, undefined, opts);
916917
var axrev = (rng[1] < rng[0]);
917918
var minRange = Math.min(rng[0], rng[1]);
@@ -1117,11 +1118,17 @@ axes.calcTicks = function calcTicks(ax, opts) {
11171118
})
11181119
.filter(function(index) { return index !== null; });
11191120

1121+
var uniqueIndices = []; // ensure that each label is only drawn once
11201122
majorTickIndices.forEach(function(majorIdx) {
1121-
var minorIdx = majorIdx + ticklabelIndex;
1122-
if(minorIdx >= 0 && minorIdx < allTickVals.length) {
1123-
labelTickVals.push(allTickVals[minorIdx]);
1124-
}
1123+
ticklabelIndex.map(function(nextLabelIdx) {
1124+
var minorIdx = majorIdx + nextLabelIdx;
1125+
if(uniqueIndices.indexOf(minorIdx) === -1) {
1126+
uniqueIndices.push(minorIdx);
1127+
if(minorIdx >= 0 && minorIdx < allTickVals.length) {
1128+
labelTickVals.push(allTickVals[minorIdx]);
1129+
}
1130+
}
1131+
});
11251132
});
11261133
}
11271134

src/plots/cartesian/layout_attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,8 +722,8 @@ module.exports = {
722722
].join(' ')
723723
},
724724
ticklabelindex: {
725-
// In the future maybe add `arrayOk: true` for labeling several minor ticks, e.g. [-1, 0, 1]
726725
valType: 'integer',
726+
arrayOk: true,
727727
editType: 'calc',
728728
description: [
729729
'Only for axes with `type` *date* or *linear*.',

test/image/mocks/zzz_ticklabelindex.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164
},
165165
"xaxis2": {
166166
"title": {
167-
"text": "xaxis2: Period before each major tick is labeled"
167+
"text": "xaxis2: Period before, after each major tick and in the center between major ticks are labeled"
168168
},
169169
"dtick": "M12",
170170
"minor": {
@@ -175,7 +175,7 @@
175175
},
176176
"tickformat": "%b %Y",
177177
"autorange": "reversed",
178-
"ticklabelindex": -1,
178+
"ticklabelindex": [-1, 0, 6],
179179
"tickangle": 90,
180180
"ticklabelmode": "period",
181181
"ticklen": 18,

test/plot-schema.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15117,10 +15117,16 @@
1511715117
"role": "object"
1511815118
},
1511915119
"ticklabelindex": {
15120+
"arrayOk": true,
1512015121
"description": "Only for axes with `type` *date* or *linear*. 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",
1512115122
"editType": "calc",
1512215123
"valType": "integer"
1512315124
},
15125+
"ticklabelindexsrc": {
15126+
"description": "Sets the source reference on Chart Studio Cloud for `ticklabelindex`.",
15127+
"editType": "none",
15128+
"valType": "string"
15129+
},
1512415130
"ticklabelmode": {
1512515131
"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.",
1512615132
"dflt": "instant",
@@ -16443,10 +16449,16 @@
1644316449
"role": "object"
1644416450
},
1644516451
"ticklabelindex": {
16452+
"arrayOk": true,
1644616453
"description": "Only for axes with `type` *date* or *linear*. 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",
1644716454
"editType": "calc",
1644816455
"valType": "integer"
1644916456
},
16457+
"ticklabelindexsrc": {
16458+
"description": "Sets the source reference on Chart Studio Cloud for `ticklabelindex`.",
16459+
"editType": "none",
16460+
"valType": "string"
16461+
},
1645016462
"ticklabelmode": {
1645116463
"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.",
1645216464
"dflt": "instant",

0 commit comments

Comments
 (0)