Skip to content

Revise flags of rangebreak pattern #4653

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 12 commits into from
Mar 17, 2020
13 changes: 5 additions & 8 deletions src/plots/cartesian/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,22 +278,19 @@ module.exports = {

pattern: {
valType: 'enumerated',
// TODO could add '%H:%M:%S'
values: ['%w', '%H', ''],
values: ['day of week', 'hour', ''],
dflt: '',
role: 'info',
editType: 'calc',
description: [
'Determines a pattern on the time line that generates breaks.',
'If *%w* - Sunday-based weekday as a decimal number [0, 6].',
'If *%H* - hour (24-hour clock) as a decimal number [0, 23].',
'These are the same directive as in `tickformat`, see',
'https://github.com/d3/d3-time-format#locale_format',
'If *day of week* - Sunday-based weekday as a decimal number [0, 6].',
'If *hour* - hour (24-hour clock) as a decimal number [0, 23].',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this accepts numbers from 0 to 23.999999 right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure.
cc: @alexcjohnson

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's check in on the time-strings here too plz. I don't mind if they're not supported but if they are we should leave it in and document it. :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fractional hours worked in my testing, and time strings did not, but the gold standard is adding a test :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@archmoj your call whether to add these tests here or in another PR but they should be somewhere before the release.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am adding them in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are added in 8cc498e.
At the moment this only works properly for integers [0, 24] as mentioned in db38ce9.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in a333acb.

'for more info.',
'Examples:',
'- { pattern: \'%w\', bounds: [6, 0], operation: \'[]\' }',
'- { pattern: \'day of week\', bounds: [6, 0] }',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this PR implement the default operation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Those changes would be done in a separate PR.

' breaks from Saturday to Monday (i.e. skips the weekends).',
'- { pattern: \'%H\', bounds: [17, 8] }',
'- { pattern: \'hour\', bounds: [17, 8], operation: \'()\' }', // TODO: simplify after revise defaults
' breaks from 5pm to 8am (i.e. skips non-work hours).'
].join(' ')
},
Expand Down
12 changes: 6 additions & 6 deletions src/plots/cartesian/set_convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,14 +625,14 @@ module.exports = function setConvert(ax, fullLayout) {
var doesCrossPeriod = false;

switch(brk.pattern) {
case '%w':
case 'day of week':
bnds = Lib.simpleMap(brk.bounds, cleanNumber);
b0 = bnds[0];
b1 = bnds[1];
vb = (new Date(v)).getUTCDay();
if(bnds[0] > bnds[1]) doesCrossPeriod = true;
break;
case '%H':
case 'hour':
bnds = Lib.simpleMap(brk.bounds, cleanNumber);
b0 = bnds[0];
b1 = bnds[1];
Expand Down Expand Up @@ -699,8 +699,8 @@ module.exports = function setConvert(ax, fullLayout) {
if(!ax.rangebreaks) return rangebreaksOut;

var rangebreaksIn = ax.rangebreaks.slice().sort(function(a, b) {
if(a.pattern === '%w' && b.pattern === '%H') return -1;
else if(b.pattern === '%w' && a.pattern === '%H') return 1;
if(a.pattern === 'day of week' && b.pattern === 'hour') return -1;
else if(b.pattern === 'day of week' && a.pattern === 'hour') return 1;
return 0;
});

Expand Down Expand Up @@ -756,7 +756,7 @@ module.exports = function setConvert(ax, fullLayout) {
var t;

switch(brk.pattern) {
case '%w':
case 'day of week':
b0 = bnds[0] + (op0 === '(' ? 1 : 0);
b1 = bnds[1];
r0Pattern = r0Date.getUTCDay();
Expand All @@ -771,7 +771,7 @@ module.exports = function setConvert(ax, fullLayout) {
r0Date.getUTCSeconds() * ONESEC -
r0Date.getUTCMilliseconds();
break;
case '%H':
case 'hour':
b0 = bnds[0];
b1 = bnds[1];
r0Pattern = r0Date.getUTCHours();
Expand Down
4 changes: 2 additions & 2 deletions test/image/mocks/axes_breaks-finance.json
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@
"rangeslider": { "visible": true },
"rangebreaks": [
{
"pattern": "%w",
"pattern": "day of week",
"bounds": [ 6, 0 ]
},
{
Expand All @@ -376,7 +376,7 @@
"rangeslider": { "visible": true },
"rangebreaks": [
{
"pattern": "%w",
"pattern": "day of week",
"bounds": [ 6, 0 ]
},
{
Expand Down
8 changes: 4 additions & 4 deletions test/image/mocks/axes_breaks-night_autorange-reversed.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
"xaxis": {
"rangebreaks": [
{
"pattern": "%H",
"pattern": "hour",
"bounds": [
18,
6
Expand All @@ -208,7 +208,7 @@
"xaxis2": {
"rangebreaks": [
{
"pattern": "%H",
"pattern": "hour",
"bounds": [
18,
6
Expand Down Expand Up @@ -253,7 +253,7 @@
"yaxis3": {
"rangebreaks": [
{
"pattern": "%H",
"pattern": "hour",
"bounds": [
18,
6
Expand All @@ -270,7 +270,7 @@
"yaxis4": {
"rangebreaks": [
{
"pattern": "%H",
"pattern": "hour",
"bounds": [
18,
6
Expand Down
8 changes: 4 additions & 4 deletions test/image/mocks/axes_breaks-rangeslider.json
Original file line number Diff line number Diff line change
Expand Up @@ -2654,22 +2654,22 @@
"tickfont": {"size": 8},
"rangebreaks": [
{
"pattern": "%w",
"pattern": "day of week",
"bounds": [6, 0],
"operation": "[]"
},
{
"pattern": "%H",
"pattern": "hour",
"bounds": [0, 9],
"operation": "()"
},
{
"pattern": "%H",
"pattern": "hour",
"bounds": [12, 13],
"operation": "()"
},
{
"pattern": "%H",
"pattern": "hour",
"bounds": [15, 21],
"operation": "()"
}
Expand Down
4 changes: 2 additions & 2 deletions test/image/mocks/axes_breaks-weekends-weeknights.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
"xaxis": {
"rangebreaks": [
{
"pattern": "%w",
"pattern": "day of week",
"bounds": [ 6, 0 ],
"operation": "[]"
},
{
"pattern": "%H",
"pattern": "hour",
"bounds": [ 16, 8 ],
"operation": "()"
}
Expand Down
8 changes: 4 additions & 4 deletions test/image/mocks/axes_breaks-weekends_autorange-reversed.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"xaxis": {
"rangebreaks": [
{
"pattern": "%w",
"pattern": "day of week",
"bounds": [
6,
0
Expand All @@ -104,7 +104,7 @@
"xaxis2": {
"rangebreaks": [
{
"pattern": "%w",
"pattern": "day of week",
"bounds": [
6,
0
Expand Down Expand Up @@ -149,7 +149,7 @@
"yaxis3": {
"rangebreaks": [
{
"pattern": "%w",
"pattern": "day of week",
"bounds": [
6,
0
Expand All @@ -166,7 +166,7 @@
"yaxis4": {
"rangebreaks": [
{
"pattern": "%w",
"pattern": "day of week",
"bounds": [
6,
0
Expand Down
Loading