Skip to content

Commit 397bf63

Browse files
committed
set period0 to be on first Monday of 2000
- and improve test for the case of stack and default weekly period on Monday
1 parent 83b22a0 commit 397bf63

File tree

5 files changed

+87
-5
lines changed

5 files changed

+87
-5
lines changed

src/traces/scatter/attributes.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,22 @@ function axisPeriod(axis) {
2929
'Only relevant when the axis `type` is *date*.',
3030
'Sets the period positioning in milliseconds or *M<n>* on the ' + axis + ' axis.',
3131
'Special values in the form of *M<n>* could be used to declare',
32-
'the number of "average" months. In this case `n` must be a positive integer.'
32+
'the number of months. In this case `n` must be a positive integer.'
3333
].join(' ')
3434
};
3535
}
3636

3737
function axisPeriod0(axis) {
3838
return {
3939
valType: 'any',
40-
dflt: 0,
4140
role: 'info',
4241
editType: 'calc',
4342
description: [
4443
'Only relevant when the axis `type` is *date*.',
45-
'Sets the base for period positioning in milliseconds or date string on the ' + axis + ' axis.'
44+
'Sets the base for period positioning in milliseconds or date string on the ' + axis + ' axis.',
45+
'When `' + axis + 'period` is round number of weeks,',
46+
'the `' + axis + 'period0` by default would be on a Monday i.e. 1970-01-05,',
47+
'otherwise it would be at 1970-01-01.'
4648
].join(' ')
4749
};
4850
}

src/traces/scatter/period_defaults.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@
88

99
'use strict';
1010

11+
var numConstants = require('../../constants/numerical');
12+
var ONEWEEK = numConstants.ONEWEEK;
13+
14+
function getPeriod0Dflt(period) {
15+
var n = period / ONEWEEK;
16+
17+
return Math.round(n) === n ?
18+
'1970-01-05' : // a Monday
19+
'1970-01-01';
20+
}
21+
1122
module.exports = function handlePeriodDefaults(traceIn, traceOut, layout, coerce, opts) {
1223
if(!opts) {
1324
opts = {
@@ -19,15 +30,15 @@ module.exports = function handlePeriodDefaults(traceIn, traceOut, layout, coerce
1930
if(opts.x) {
2031
var xperiod = coerce('xperiod');
2132
if(xperiod) {
22-
coerce('xperiod0');
33+
coerce('xperiod0', getPeriod0Dflt(xperiod));
2334
coerce('xperiodalignment');
2435
}
2536
}
2637

2738
if(opts.y) {
2839
var yperiod = coerce('yperiod');
2940
if(yperiod) {
30-
coerce('yperiod0');
41+
coerce('yperiod0', getPeriod0Dflt(yperiod));
3142
coerce('yperiodalignment');
3243
}
3344
}
47 KB
Loading
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"data": [
3+
{
4+
"marker": {
5+
"opacity": 0.5,
6+
"line": {
7+
"width": 2,
8+
"color": "white"
9+
}
10+
},
11+
"textposition": "inside",
12+
"textangle": 0,
13+
"texttemplate": "%{x|%A %d %b %Y}",
14+
"hovertemplate": "%{x|%A}, %{y}",
15+
"type": "bar",
16+
"y": [
17+
21,
18+
21,
19+
21,
20+
21,
21+
12,
22+
12,
23+
12,
24+
12,
25+
12,
26+
12,
27+
12,
28+
28,
29+
28,
30+
28
31+
],
32+
"x": [
33+
"2020-01-16",
34+
"2020-01-17",
35+
"2020-01-18",
36+
"2020-01-19",
37+
"2020-01-20",
38+
"2020-01-21",
39+
"2020-01-22",
40+
"2020-01-23",
41+
"2020-01-24",
42+
"2020-01-25",
43+
"2020-01-26",
44+
"2020-01-27",
45+
"2020-01-28",
46+
"2020-01-29"
47+
],
48+
"xperiod": 604800000
49+
}
50+
],
51+
"layout": {
52+
"width": 600,
53+
"height": 400,
54+
"margin": {
55+
"t": 50
56+
},
57+
"hovermode": "closest",
58+
"barmode": "stack",
59+
"bargap": 0,
60+
"xaxis": {
61+
"dtick": 86400000,
62+
"ticklabelmode": "period",
63+
"tickformat": "%a %m-%d",
64+
"tickcolor": "black"
65+
}
66+
}
67+
}

test/jasmine/tests/mock_test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,7 @@ var list = [
761761
'period_positioning5',
762762
'period_positioning6',
763763
'period_positioning7',
764+
'period_positioning8',
764765
'picnic_heatmap',
765766
'pie_aggregated',
766767
'pie_automargin',
@@ -1821,6 +1822,7 @@ figs['period_positioning4'] = require('@mocks/period_positioning4');
18211822
figs['period_positioning5'] = require('@mocks/period_positioning5');
18221823
figs['period_positioning6'] = require('@mocks/period_positioning6');
18231824
figs['period_positioning7'] = require('@mocks/period_positioning7');
1825+
figs['period_positioning8'] = require('@mocks/period_positioning8');
18241826
figs['picnic_heatmap'] = require('@mocks/picnic_heatmap');
18251827
figs['pie_aggregated'] = require('@mocks/pie_aggregated');
18261828
figs['pie_automargin'] = require('@mocks/pie_automargin');

0 commit comments

Comments
 (0)