Skip to content

Handle weekday strings in rangebreaks #4661

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

Merged
merged 9 commits into from
Mar 19, 2020
Prev Previous commit
Next Next commit
add tests to handle weekday strings
  • Loading branch information
archmoj committed Mar 18, 2020
commit d52a803e751e5645e2c220b3d02a52c453defbb8
27 changes: 27 additions & 0 deletions test/jasmine/tests/axes_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,33 @@ describe('Test axes', function() {
expect(layoutOut.xaxis2.rangebreaks[0].pattern).toBe('day of week', 'coerced');
expect(layoutOut.xaxis3.rangebreaks[0].pattern).toBe(undefined, 'not coerce, using *values*');
});

it('should auto default rangebreaks.pattern to *day of week* when *bounds* include a weekday string and convert bounds to integer days', function() {
layoutIn = {
xaxis: {type: 'date', rangebreaks: [
{bounds: ['Saturday', 'Monday']}
]},
xaxis2: {type: 'date', rangebreaks: [
{bounds: ['sun', 'thu']},
{bounds: ['mon', 'fri']},
{bounds: ['tue', 'sat']},
{bounds: ['wed', '-1']}
]}
};
layoutOut._subplots.xaxis.push('x2');
supplyLayoutDefaults(layoutIn, layoutOut, fullData);

expect(layoutOut.xaxis.rangebreaks[0].pattern).toBe('day of week', 'complete Capital');
expect(layoutOut.xaxis2.rangebreaks[0].pattern).toBe('day of week', '3-letter case');
expect(layoutOut.xaxis2.rangebreaks[0].bounds[0]).toBe(0, 'convert sun');
expect(layoutOut.xaxis2.rangebreaks[1].bounds[0]).toBe(1, 'convert mon');
expect(layoutOut.xaxis2.rangebreaks[2].bounds[0]).toBe(2, 'convert tue');
expect(layoutOut.xaxis2.rangebreaks[3].bounds[0]).toBe(3, 'convert wed');
expect(layoutOut.xaxis2.rangebreaks[0].bounds[1]).toBe(4, 'convert thu');
expect(layoutOut.xaxis2.rangebreaks[1].bounds[1]).toBe(5, 'convert fri');
expect(layoutOut.xaxis2.rangebreaks[2].bounds[1]).toBe(6, 'convert sat');
expect(layoutOut.xaxis2.rangebreaks[3].bounds[1]).toBe('-1', 'string');
});
});

describe('constraints relayout', function() {
Expand Down