Skip to content

Commit 40c6df6

Browse files
committed
add jasmine tests for various tickformat using period mode
1 parent e265f0d commit 40c6df6

File tree

1 file changed

+237
-0
lines changed

1 file changed

+237
-0
lines changed

test/jasmine/tests/axes_test.js

+237
Original file line numberDiff line numberDiff line change
@@ -5196,6 +5196,243 @@ describe('Test axes', function() {
51965196
});
51975197
});
51985198
});
5199+
5200+
describe('label positioning using *ticklabelmode*: "period"', function() {
5201+
var gd;
5202+
5203+
beforeEach(function() {
5204+
gd = createGraphDiv();
5205+
});
5206+
5207+
afterEach(destroyGraphDiv);
5208+
5209+
function _assert(msg, exp) {
5210+
var labelPositions = gd._fullLayout.xaxis._vals.map(function(d) { return d.periodX; });
5211+
expect(labelPositions).withContext(msg).toEqual(exp);
5212+
}
5213+
5214+
['%Y', '%y'].forEach(function(tickformat) {
5215+
it('should respect yearly tickformat that includes ' + tickformat, function(done) {
5216+
Plotly.newPlot(gd, {
5217+
data: [{
5218+
x: ['2020-01-01', '2026-01-01']
5219+
}],
5220+
layout: {
5221+
width: 1000,
5222+
xaxis: {
5223+
ticklabelmode: 'period',
5224+
tickformat: tickformat
5225+
}
5226+
}
5227+
})
5228+
.then(function() {
5229+
_assert('', [
5230+
1562079600000,
5231+
1593615600000,
5232+
1625238000000,
5233+
1656774000000,
5234+
1688310000000,
5235+
1719846000000,
5236+
1751468400000,
5237+
1783004400000
5238+
]);
5239+
})
5240+
.catch(failTest)
5241+
.then(done);
5242+
});
5243+
});
5244+
5245+
it('should respect quarters tickformat that includes %q', function(done) {
5246+
Plotly.newPlot(gd, {
5247+
data: [{
5248+
x: ['2020-01-01', '2022-01-01']
5249+
}],
5250+
layout: {
5251+
width: 1000,
5252+
xaxis: {
5253+
ticklabelmode: 'period',
5254+
tickformat: '%Y-%q'
5255+
}
5256+
}
5257+
})
5258+
.then(function() {
5259+
_assert('', [
5260+
1573832700000,
5261+
1581781500000,
5262+
1589643900000,
5263+
1597506300000,
5264+
1605455100000,
5265+
1613403900000,
5266+
1621179900000,
5267+
1629042300000,
5268+
1636991100000,
5269+
1644939900000
5270+
]);
5271+
})
5272+
.catch(failTest)
5273+
.then(done);
5274+
});
5275+
5276+
['%B', '%b', '%m'].forEach(function(tickformat) {
5277+
it('should respect monthly tickformat that includes ' + tickformat, function(done) {
5278+
Plotly.newPlot(gd, {
5279+
data: [{
5280+
x: ['2020-01-01', '2020-07-01']
5281+
}],
5282+
layout: {
5283+
width: 1000,
5284+
xaxis: {
5285+
ticklabelmode: 'period',
5286+
tickformat: '%q-' + tickformat
5287+
}
5288+
}
5289+
})
5290+
.then(function() {
5291+
_assert('', [
5292+
1576473300000,
5293+
1579151700000,
5294+
1581830100000,
5295+
1584335700000,
5296+
1587014100000,
5297+
1589606100000,
5298+
1592284500000,
5299+
1594876500000
5300+
]);
5301+
})
5302+
.catch(failTest)
5303+
.then(done);
5304+
});
5305+
});
5306+
5307+
it('should respect Sunday-based week tickformat that includes %U', function(done) {
5308+
Plotly.newPlot(gd, {
5309+
data: [{
5310+
x: ['2020-02-01', '2020-04-01']
5311+
}],
5312+
layout: {
5313+
width: 1000,
5314+
xaxis: {
5315+
ticklabelmode: 'period',
5316+
tickformat: '%b-%U'
5317+
}
5318+
}
5319+
})
5320+
.then(function() {
5321+
_assert('', [
5322+
1580299200000,
5323+
1580904000000,
5324+
1581508800000,
5325+
1582113600000,
5326+
1582718400000,
5327+
1583323200000,
5328+
1583928000000,
5329+
1584532800000,
5330+
1585137600000,
5331+
1585742400000
5332+
]);
5333+
})
5334+
.catch(failTest)
5335+
.then(done);
5336+
});
5337+
5338+
['%V', '%W'].forEach(function(tickformat) {
5339+
it('should respect Monday-based week tickformat that includes ' + tickformat, function(done) {
5340+
Plotly.newPlot(gd, {
5341+
data: [{
5342+
x: ['2020-02-01', '2020-04-01']
5343+
}],
5344+
layout: {
5345+
width: 1000,
5346+
xaxis: {
5347+
ticklabelmode: 'period',
5348+
tickformat: '%b-' + tickformat
5349+
}
5350+
}
5351+
})
5352+
.then(function() {
5353+
_assert('', [
5354+
1580385600000,
5355+
1580990400000,
5356+
1581595200000,
5357+
1582200000000,
5358+
1582804800000,
5359+
1583409600000,
5360+
1584014400000,
5361+
1584619200000,
5362+
1585224000000,
5363+
1585828800000
5364+
]);
5365+
})
5366+
.catch(failTest)
5367+
.then(done);
5368+
});
5369+
});
5370+
5371+
['%A', '%a', '%d', '%e', '%j', '%u', '%w', '%x'].forEach(function(tickformat) {
5372+
it('should respect daily tickformat that includes ' + tickformat, function(done) {
5373+
Plotly.newPlot(gd, {
5374+
data: [{
5375+
x: ['2020-01-01', '2020-01-08']
5376+
}],
5377+
layout: {
5378+
width: 1000,
5379+
xaxis: {
5380+
ticklabelmode: 'period',
5381+
tickformat: '%b-' + tickformat
5382+
}
5383+
}
5384+
})
5385+
.then(function() {
5386+
_assert('', [
5387+
1577793600000,
5388+
1577880000000,
5389+
1577966400000,
5390+
1578052800000,
5391+
1578139200000,
5392+
1578225600000,
5393+
1578312000000,
5394+
1578398400000,
5395+
1578484800000
5396+
]);
5397+
})
5398+
.catch(failTest)
5399+
.then(done);
5400+
});
5401+
});
5402+
5403+
['%f', '%L', '%Q', '%s', '%S', '%M', '%H', '%I', '%p', '%X'].forEach(function(tickformat) {
5404+
it('should respect daily tickformat that includes ' + tickformat, function(done) {
5405+
Plotly.newPlot(gd, {
5406+
data: [{
5407+
x: ['2020-01-01', '2020-01-02']
5408+
}],
5409+
layout: {
5410+
width: 1000,
5411+
xaxis: {
5412+
ticklabelmode: 'period',
5413+
tickformat: '%a-' + tickformat
5414+
}
5415+
}
5416+
})
5417+
.then(function() {
5418+
_assert('', [
5419+
1577826000000,
5420+
1577836800000,
5421+
1577847600000,
5422+
1577858400000,
5423+
1577869200000,
5424+
1577880000000,
5425+
1577890800000,
5426+
1577901600000,
5427+
1577912400000,
5428+
1577923200000
5429+
]);
5430+
})
5431+
.catch(failTest)
5432+
.then(done);
5433+
});
5434+
});
5435+
});
51995436
});
52005437

52015438
function getZoomInButton(gd) {

0 commit comments

Comments
 (0)