Skip to content

Commit

Permalink
Add test to verify expected quantity of ticks
Browse files Browse the repository at this point in the history
  • Loading branch information
ayjayt committed Jan 2, 2024
1 parent 24821c8 commit 9a6de43
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,7 @@ function syncTicks(ax) {
}

function arrayTicks(ax, major) {
if (major === undefined) throw new Error("arrayTicks must specify ticktype")
var rng = Lib.simpleMap(ax.range, ax.r2l);
var exRng = expandRange(rng);
var tickMin = Math.min(exRng[0], exRng[1]);
Expand Down
63 changes: 62 additions & 1 deletion test/jasmine/tests/axes_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ var supplyDefaults = require('../assets/supply_defaults');

describe('Test axes', function() {
'use strict';

describe('swap', function() {
it('should swap most attributes and fix placeholder titles', function() {
var gd = {
Expand Down Expand Up @@ -8217,3 +8216,65 @@ describe('shift tests', function() {
});
});
});
describe('test tickmode calculator', function() {
beforeEach(function() {
gd = createGraphDiv();
});

afterEach(destroyGraphDiv);

function generateTickConfig(){
standardConfig = {tickmode: 'array', ticks: 'inside', ticklen: 1, showticklabels: false};

// Number of ticks will be random
var n = Math.floor(Math.random() * 99) + 1;
tickVals = [];
for(let i = 0; i <= n; i++) tickVals.push(i);
standardConfig['tickvals'] = tickVals;
standardConfig['ticktext'] = tickVals;
return standardConfig;
}
var ticksOff = {tickmode:"array", ticks: '', tickvals:[], ticktext:[], ticklen: 0, showticklabels: false};
// the goal is target the arrayTicks() function, the subject of PR: https://github.com/plotly/plotly.js/pull/6829
// we test xMajor and xMinor in on/on on/off off/on and off/off
// since we can't unit test functions that are not exported, we shim functions we don't care about instead and
// test the nearest exported functions (calcTicks)
describe('arrayTicks', function() {
for(let i = 0; i < 4; i++) {
(function(i) {
it('should return the specified correct number of major ticks and minor ticks', function() {
const BOTH = 0;
const MAJOR = 1;
const MINOR = 2;
const NEITHER = 3;
var xMajorConfig = ticksOff;
var xMinorConfig = ticksOff;
if(i == BOTH) {
xMajorConfig = generateTickConfig();
xMinorConfig = generateTickConfig();
} else if(i == MAJOR) {
xMajorConfig = generateTickConfig();
} else if(i==MINOR) {
xMinorConfig = generateTickConfig();
} else if(i == NEITHER) {
// Do nothing, all ticks off
}
xaxis = {
r2l: Lib.cleanNumber,
d2l: Lib.cleanNumber,
_separators: ',',
range: [0, 1000],
...xMajorConfig,
minor: {
...xMinorConfig,
},
};
Axes.prepMinorTicks = function() { return }; // Not part of this test
Axes.prepTicks = function() { return }; // Not part of this test
ticksOut = Axes.calcTicks(xaxis);
expect(ticksOut.length).toEqual(xMajorConfig.tickvals.length + xMinorConfig.tickvals.length);
});
})(i);
}
});
});

0 comments on commit 9a6de43

Please sign in to comment.