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
16 changes: 8 additions & 8 deletions src/plots/cartesian/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,22 +279,22 @@ module.exports = {
pattern: {
valType: 'enumerated',
// TODO could add '%H:%M:%S'
values: ['%w', '%H', ''],
values: ['day of week', 'time of day', ''],
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 *time of day* - hour (24-hour clock) as a decimal number [0, 23].',
'*day of week* and *time of day* are similar to *%w* and *%H* directives',
'applied in `tickformat`, see https://github.com/d3/d3-time-format#locale_format',
'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] }',
' breaks from 5pm to 8am (i.e. skips non-work hours).'
'- { pattern: \'time of day\', bounds: [16, 8] }',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

bounds should be [18, 8] ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems reasonable (to me) to set operation' dfltback to "()" for thetime of day` case.

' breaks from 4pm to 8am (i.e. skips non-work hours).'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

from 6pm to 9am ?

Copy link
Contributor

Choose a reason for hiding this comment

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

sure

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 reverted the hour example and added operation fix in 94f8ef8.
We will come back to finalize this when revising defaults in the following PR.

].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 'time of day':
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 === 'time of day') return -1;
else if(b.pattern === 'day of week' && a.pattern === 'time of day') 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 'time of day':
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": "time of day",
"bounds": [
18,
6
Expand All @@ -208,7 +208,7 @@
"xaxis2": {
"rangebreaks": [
{
"pattern": "%H",
"pattern": "time of day",
"bounds": [
18,
6
Expand Down Expand Up @@ -253,7 +253,7 @@
"yaxis3": {
"rangebreaks": [
{
"pattern": "%H",
"pattern": "time of day",
"bounds": [
18,
6
Expand All @@ -270,7 +270,7 @@
"yaxis4": {
"rangebreaks": [
{
"pattern": "%H",
"pattern": "time of day",
"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": "time of day",
"bounds": [0, 9],
"operation": "()"
},
{
"pattern": "%H",
"pattern": "time of day",
"bounds": [12, 13],
"operation": "()"
},
{
"pattern": "%H",
"pattern": "time of day",
"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": "time of day",
"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