-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Add switch to specify major/minor in axes.arrayTicks()
#6829
Changes from 4 commits
9eb6bc4
24821c8
9a6de43
392b103
41ae65d
095ce0c
69345fc
365231d
00cdcc8
cd3b261
1051bb7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Add argument to `arrayTicks()` to render major OR minor [[#6829](https://github.com/plotly/plotly.js/pull/6829)] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = { | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use |
||
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please declare this function outside the loop and use ES5 to pass the syntax test. |
||
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], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of mocking the |
||
...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); | ||
} | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need this line?
After you added it in 9a6de43, some tests failed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's good actually!
I put that line in there to force failure if other calls relied on default behavior.
Jasmine is wonky on my local box so I didn't catch those failed tests before push.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The arrayTicks will now behave in a legacy manner if the caller isn't aware to use the major/minor switch.