Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9e9da55

Browse filesBrowse files
authored
Merge pull request #6829 from geopozo/pikul-arrayTicks-duplicate-tick-bug
Add switch to specify major/minor in `axes.arrayTicks()`
2 parents f6c33bd + 1051bb7 commit 9e9da55
Copy full SHA for 9e9da55

File tree

3 files changed

+72
-5
lines changed
Filter options

3 files changed

+72
-5
lines changed

‎draftlogs/6829_fix.md

Copy file name to clipboard
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Add argument to `arrayTicks()` to render major OR minor [[#6829](https://github.com/plotly/plotly.js/pull/6829)]

‎src/plots/cartesian/axes.js

Copy file name to clipboardExpand all lines: src/plots/cartesian/axes.js
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -949,10 +949,10 @@ axes.calcTicks = function calcTicks(ax, opts) {
949949
if(mockAx.tickmode === 'array') {
950950
if(major) {
951951
tickVals = [];
952-
ticksOut = arrayTicks(ax);
952+
ticksOut = arrayTicks(ax, !isMinor);
953953
} else {
954954
minorTickVals = [];
955-
minorTicks = arrayTicks(ax);
955+
minorTicks = arrayTicks(ax, !isMinor);
956956
}
957957
continue;
958958
}
@@ -1261,7 +1261,7 @@ function syncTicks(ax) {
12611261
return ticksOut;
12621262
}
12631263

1264-
function arrayTicks(ax) {
1264+
function arrayTicks(ax, majorOnly) {
12651265
var rng = Lib.simpleMap(ax.range, ax.r2l);
12661266
var exRng = expandRange(rng);
12671267
var tickMin = Math.min(exRng[0], exRng[1]);
@@ -1279,10 +1279,10 @@ function arrayTicks(ax) {
12791279

12801280
var ticksOut = [];
12811281
for(var isMinor = 0; isMinor <= 1; isMinor++) {
1282+
if((majorOnly !== undefined) && ((majorOnly && isMinor) || (majorOnly === false && !isMinor))) continue;
12821283
if(isMinor && !ax.minor) continue;
12831284
var vals = !isMinor ? ax.tickvals : ax.minor.tickvals;
12841285
var text = !isMinor ? ax.ticktext : [];
1285-
12861286
if(!vals) continue;
12871287

12881288

‎test/jasmine/tests/axes_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/axes_test.js
+67-1Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ var supplyDefaults = require('../assets/supply_defaults');
2828

2929
describe('Test axes', function() {
3030
'use strict';
31-
3231
describe('swap', function() {
3332
it('should swap most attributes and fix placeholder titles', function() {
3433
var gd = {
@@ -8217,3 +8216,70 @@ describe('shift tests', function() {
82178216
});
82188217
});
82198218
});
8219+
describe('test tickmode calculator', function() {
8220+
var gd;
8221+
8222+
beforeEach(function() {
8223+
gd = createGraphDiv();
8224+
});
8225+
8226+
afterEach(destroyGraphDiv);
8227+
8228+
function generateTickConfig() {
8229+
var standardConfig = {tickmode: 'array', ticks: 'inside', ticklen: 1, showticklabels: false};
8230+
8231+
// Number of ticks will be random
8232+
Lib.seedPseudoRandom();
8233+
var n = (Lib.pseudoRandom() * 99) + 1;
8234+
var tickVals = [];
8235+
for(var i = 0; i <= n; i++) {
8236+
tickVals.push(i);
8237+
}
8238+
standardConfig.tickvals = tickVals;
8239+
standardConfig.ticktext = tickVals;
8240+
return standardConfig;
8241+
}
8242+
var ticksOff = {tickmode: 'array', ticks: '', tickvals: [], ticktext: [], ticklen: 0, showticklabels: false};
8243+
8244+
function _assert(expLength) {
8245+
var ax = gd._fullLayout.xaxis;
8246+
8247+
// all positions
8248+
var positions =
8249+
ax._vals
8250+
.filter(function(d) { return d; })
8251+
.map(function(d) { return d.x; });
8252+
8253+
expect(positions.length).toEqual(expLength);
8254+
}
8255+
8256+
describe('arrayTicks', function() {
8257+
it('should return the specified correct number of major ticks and minor ticks', function(done) {
8258+
var xMajorConfig = ticksOff;
8259+
var xMinorConfig = ticksOff;
8260+
xMajorConfig = generateTickConfig();
8261+
xMinorConfig = generateTickConfig();
8262+
xMajorConfig.range = [0, 1000];
8263+
xMajorConfig.minor = xMinorConfig;
8264+
Plotly.newPlot(gd, {
8265+
data: [{
8266+
x: [0, 1],
8267+
y: [0, 1]
8268+
}],
8269+
layout: {
8270+
width: 400,
8271+
height: 400,
8272+
margin: {
8273+
t: 40,
8274+
b: 40,
8275+
l: 40,
8276+
r: 40
8277+
},
8278+
xaxis: xMajorConfig,
8279+
}
8280+
}).then(function() {
8281+
_assert(xMajorConfig.tickvals.length + xMinorConfig.tickvals.length);
8282+
}).then(done, done.fail);
8283+
});
8284+
});
8285+
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.