Skip to content

Commit e00af90

Browse files
committed
Handle breaks on date axes only for now
- revise dvalue dflt - fixup tests
1 parent 76a265e commit e00af90

13 files changed

+517
-176
lines changed

src/plots/cartesian/axis_defaults.js

+12-19
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ var handleCategoryOrderDefaults = require('./category_order_defaults');
2121
var handleLineGridDefaults = require('./line_grid_defaults');
2222
var setConvert = require('./set_convert');
2323

24-
var ONEDAY = require('../../constants/numerical').ONEDAY;
25-
2624
/**
2725
* options: object containing:
2826
*
@@ -121,17 +119,16 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, coerce,
121119
}
122120
}
123121

124-
// TODO
125-
// - does this make sense for 'log', 'category' and 'multicategory' axis types ??
126-
127-
var breaks = containerIn.breaks;
128-
if(Array.isArray(breaks) && breaks.length) {
129-
handleArrayContainerDefaults(containerIn, containerOut, {
130-
name: 'breaks',
131-
inclusionAttr: 'enabled',
132-
handleItemDefaults: breaksDefaults
133-
});
134-
setConvert(containerOut, layoutOut);
122+
if(containerOut.type === 'date') {
123+
var breaks = containerIn.breaks;
124+
if(Array.isArray(breaks) && breaks.length) {
125+
handleArrayContainerDefaults(containerIn, containerOut, {
126+
name: 'breaks',
127+
inclusionAttr: 'enabled',
128+
handleItemDefaults: breaksDefaults
129+
});
130+
setConvert(containerOut, layoutOut);
131+
}
135132
}
136133

137134
return containerOut;
@@ -145,8 +142,6 @@ function breaksDefaults(itemIn, itemOut, containerOut) {
145142
var enabled = coerce('enabled');
146143

147144
if(enabled) {
148-
var isDateAxis = containerOut.type === 'date';
149-
150145
var bnds = coerce('bounds');
151146

152147
if(bnds && bnds.length >= 2) {
@@ -169,14 +164,12 @@ function breaksDefaults(itemIn, itemOut, containerOut) {
169164
}
170165
}
171166

172-
if(isDateAxis) {
173-
coerce('pattern');
174-
}
167+
coerce('pattern');
175168
} else {
176169
var values = coerce('values');
177170

178171
if(values && values.length) {
179-
coerce('dvalue', isDateAxis ? ONEDAY : 1);
172+
coerce('dvalue');
180173
} else {
181174
itemOut.enabled = false;
182175
return;

src/plots/cartesian/layout_attributes.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var templatedArray = require('../../plot_api/plot_template').templatedArray;
1616

1717
var FORMAT_LINK = require('../../constants/docs').FORMAT_LINK;
1818
var DATE_FORMAT_LINK = require('../../constants/docs').DATE_FORMAT_LINK;
19-
19+
var ONEDAY = require('../../constants/numerical').ONEDAY;
2020
var constants = require('./constants');
2121

2222
module.exports = {
@@ -256,7 +256,8 @@ module.exports = {
256256
dflt: true,
257257
editType: 'calc',
258258
description: [
259-
'Determines whether this axis break is enabled or disabled.'
259+
'Determines whether this axis break is enabled or disabled.',
260+
'Please note that `breaks` only work for *date* axis type.'
260261
].join(' ')
261262
},
262263

@@ -271,7 +272,7 @@ module.exports = {
271272
description: [
272273
'Sets the lower and upper bounds of this axis break.',
273274
'Can be used with `operation` to determine the behavior at the bounds.',
274-
'On *date* axes, it can be used with `pattern`.'
275+
'Can be used with `pattern`.'
275276
].join(' ')
276277
},
277278

@@ -283,7 +284,6 @@ module.exports = {
283284
role: 'info',
284285
editType: 'calc',
285286
description: [
286-
'Only coerced on *date* axes.',
287287
'Determines a pattern on the time line that generates breaks.',
288288
'If *%w* - Sunday-based weekday as a decimal number [0, 6].',
289289
'If *%H* - hour (24-hour clock) as a decimal number [0, 23].',
@@ -319,10 +319,10 @@ module.exports = {
319319
role: 'info',
320320
editType: 'calc',
321321
min: 0,
322+
dflt: ONEDAY,
322323
description: [
323324
'Sets the spread of each `values` item.',
324-
'For *linear* axes, the default is *1*.',
325-
'For *date* axes, the default is one day in milliseconds.'
325+
'The default is one day in milliseconds.'
326326
].join(' ')
327327
},
328328

src/plots/cartesian/set_convert.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,9 @@ module.exports = function setConvert(ax, fullLayout) {
640640
vb = (new Date(v)).getUTCHours();
641641
if(bnds[0] > bnds[1]) doesCrossPeriod = true;
642642
break;
643-
default:
643+
case '':
644+
// N.B. should work on date axes as well!
645+
// e.g. { bounds: ['2020-01-04', '2020-01-05 23:59'] }
644646
bnds = Lib.simpleMap(brk.bounds, ax.d2c);
645647
if(bnds[0] <= bnds[1]) {
646648
b0 = bnds[0];
@@ -650,6 +652,7 @@ module.exports = function setConvert(ax, fullLayout) {
650652
b1 = bnds[0];
651653
}
652654
vb = v;
655+
break;
653656
}
654657

655658
if(doesCrossPeriod) {
5.16 KB
Loading
5.14 KB
Loading

test/image/baselines/axes_breaks.png

7.72 KB
Loading

test/image/mocks/axes_breaks-bars.json

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
"data": [
33
{
44
"type": "bar",
5-
"y": [ 0, 2 ],
5+
"y": [
6+
"1970-01-01 00:00:00.000",
7+
"1970-01-01 00:00:00.002"
8+
],
69
"x": [ 1, 2 ],
710
"orientation": "h",
811
"marker": {
@@ -21,7 +24,10 @@
2124
"yaxis": {
2225
"breaks": [
2326
{
24-
"bounds": [ 0, 2 ],
27+
"bounds": [
28+
"1970-01-01 00:00:00.000",
29+
"1970-01-01 00:00:00.002"
30+
],
2531
"operation": "()"
2632
}
2733
]

test/image/mocks/axes_breaks-tickvals.json

+31-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,43 @@
11
{
22
"data": [
33
{
4-
"x": [ -20, 0, 10, 50, 90, 100, 150, 190, 200 ]
4+
"x": [
5+
"1969-12-31 23:59:59.980",
6+
"1970-01-01 00:00:00.000",
7+
"1970-01-01 00:00:00.010",
8+
"1970-01-01 00:00:00.050",
9+
"1970-01-01 00:00:00.090",
10+
"1970-01-01 00:00:00.100",
11+
"1970-01-01 00:00:00.150",
12+
"1970-01-01 00:00:00.190",
13+
"1970-01-01 00:00:00.200"
14+
]
515
}
616
],
717
"layout": {
818
"xaxis": {
919
"breaks": [
10-
{ "bounds": [ -1, 90 ] },
11-
{ "bounds": [ 101, 189 ] }
20+
{"bounds": [
21+
"1969-12-31 23:59:59.999",
22+
"1970-01-01 00:00:00.090"
23+
]},
24+
{"bounds": [
25+
"1970-01-01 00:00:00.101",
26+
"1970-01-01 00:00:00.189"
27+
]}
28+
],
29+
"tickvals": [
30+
"1969-12-31 23:59:59.980",
31+
"1969-12-31 23:59:59.990",
32+
"1970-01-01 00:00:00.000",
33+
"1970-01-01 00:00:00.010",
34+
"1970-01-01 00:00:00.050",
35+
"1970-01-01 00:00:00.090",
36+
"1970-01-01 00:00:00.100",
37+
"1970-01-01 00:00:00.150",
38+
"1970-01-01 00:00:00.190",
39+
"1970-01-01 00:00:00.200"
1240
],
13-
"tickvals": [ -20, -10, 0, 10, 50, 90, 100, 150, 190, 200 ],
1441
"ticktext": [ "<b>(-20)</b>", "<b>(10)</b>", "<b>(0)</b>" ],
1542
"zeroline": true
1643
},

test/image/mocks/axes_breaks.json

+56-8
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,58 @@
11
{
22
"data": [
33
{
4-
"y": [ 0, 10, 50, 90, 100, 150, 190, 200 ],
4+
"y": [
5+
"1970-01-01 00:00:00.000",
6+
"1970-01-01 00:00:00.010",
7+
"1970-01-01 00:00:00.050",
8+
"1970-01-01 00:00:00.090",
9+
"1970-01-01 00:00:00.100",
10+
"1970-01-01 00:00:00.150",
11+
"1970-01-01 00:00:00.190",
12+
"1970-01-01 00:00:00.200"
13+
],
514
"xaxis": "x",
615
"yaxis": "y"
716
},
817
{
9-
"y": [ 0, 10, 50, 90, 100, 150, 190, 200 ],
18+
"y": [
19+
"1970-01-01 00:00:00.000",
20+
"1970-01-01 00:00:00.010",
21+
"1970-01-01 00:00:00.050",
22+
"1970-01-01 00:00:00.090",
23+
"1970-01-01 00:00:00.100",
24+
"1970-01-01 00:00:00.150",
25+
"1970-01-01 00:00:00.190",
26+
"1970-01-01 00:00:00.200"
27+
],
1028
"xaxis": "x2",
1129
"yaxis": "y2"
1230
},
1331
{
14-
"x": [ 0, 10, 50, 90, 100, 150, 190, 200 ],
32+
"x": [
33+
"1970-01-01 00:00:00.000",
34+
"1970-01-01 00:00:00.010",
35+
"1970-01-01 00:00:00.050",
36+
"1970-01-01 00:00:00.090",
37+
"1970-01-01 00:00:00.100",
38+
"1970-01-01 00:00:00.150",
39+
"1970-01-01 00:00:00.190",
40+
"1970-01-01 00:00:00.200"
41+
],
1542
"xaxis": "x3",
1643
"yaxis": "y3"
1744
},
1845
{
19-
"x": [ 0, 10, 50, 90, 100, 150, 190, 200 ],
46+
"x": [
47+
"1970-01-01 00:00:00.000",
48+
"1970-01-01 00:00:00.010",
49+
"1970-01-01 00:00:00.050",
50+
"1970-01-01 00:00:00.090",
51+
"1970-01-01 00:00:00.100",
52+
"1970-01-01 00:00:00.150",
53+
"1970-01-01 00:00:00.190",
54+
"1970-01-01 00:00:00.200"
55+
],
2056
"xaxis": "x4",
2157
"yaxis": "y4"
2258
}
@@ -25,14 +61,26 @@
2561
"grid": { "rows": 2, "columns": 2, "pattern": "independent" },
2662
"yaxis": {
2763
"breaks": [
28-
{ "bounds": [ 11, 89 ] },
29-
{ "bounds": [ 101, 189 ] }
64+
{"bounds": [
65+
"1970-01-01 00:00:00.011",
66+
"1970-01-01 00:00:00.089"
67+
]},
68+
{ "bounds": [
69+
"1970-01-01 00:00:00.101",
70+
"1970-01-01 00:00:00.189"
71+
]}
3072
]
3173
},
3274
"xaxis3": {
3375
"breaks": [
34-
{ "bounds": [ 11, 89 ] },
35-
{ "bounds": [ 101, 189 ] }
76+
{"bounds": [
77+
"1970-01-01 00:00:00.011",
78+
"1970-01-01 00:00:00.089"
79+
]},
80+
{"bounds": [
81+
"1970-01-01 00:00:00.101",
82+
"1970-01-01 00:00:00.189"
83+
]}
3684
]
3785
},
3886
"shapes": [

0 commit comments

Comments
 (0)