Skip to content

Revise operation in rangebreaks #4660

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 7 commits into from
Mar 18, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/plots/cartesian/axis_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,5 @@ function rangebreaksDefaults(itemIn, itemOut, containerOut) {
return;
}
}

coerce('operation');
}
}
20 changes: 1 addition & 19 deletions src/plots/cartesian/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ module.exports = {
editType: 'calc',
description: [
'Sets the lower and upper bounds of this axis rangebreak.',
'Can be used with `operation` to determine the behavior at the bounds.',
'Can be used with `pattern`.'
].join(' ')
},
Expand All @@ -292,7 +291,7 @@ module.exports = {
'Examples:',
'- { pattern: \'' + DAY_OF_WEEK + '\', bounds: [6, 0] }',
' breaks from Saturday to Monday (i.e. skips the weekends).',
'- { pattern: \'' + HOUR + '\', bounds: [17, 8], operation: \'()\' }', // TODO: simplify after revise defaults
'- { pattern: \'' + HOUR + '\', bounds: [17, 8] }',
' breaks from 5pm to 8am (i.e. skips non-work hours).'
].join(' ')
},
Expand Down Expand Up @@ -325,23 +324,6 @@ module.exports = {
].join(' ')
},

operation: {
valType: 'enumerated',
values: ['[]', '()', '[)', '(]'],
dflt: '[]',
role: 'info',
editType: 'calc',
description: [
'Determines if we include or not the bound values within the rangebreak.',
'Closed interval bounds (i.e. starting with *[* or ending with *]*)',
'include the bound value within the rangebreak and thus make coordinates',
'equal to the bound disappear.',
'Open interval bounds (i.e. starting with *(* or ending with *)*)',
'does not include the bound value within the rangebreak and thus keep coordinates',
'equal to the bound on the axis.'
].join(' ')
},

/*
gap: {
valType: 'number',
Expand Down
25 changes: 4 additions & 21 deletions src/plots/cartesian/set_convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -620,10 +620,6 @@ module.exports = function setConvert(ax, fullLayout) {
var brk = rangebreaksIn[i];

if(brk.enabled) {
var op = brk.operation;
var op0 = op.charAt(0);
var op1 = op.charAt(1);

if(brk.bounds) {
var pattern = brk.pattern;
bnds = Lib.simpleMap(brk.bounds, pattern ?
Expand Down Expand Up @@ -671,24 +667,17 @@ module.exports = function setConvert(ax, fullLayout) {
break;
}

if(
(op0 === '(' ? vb > b0 : vb >= b0) &&
(op1 === ')' ? vb < b1 : vb <= b1)
) return BADNUM;
if(vb >= b0 && vb < b1) return BADNUM;
} else {
var vals = Lib.simpleMap(brk.values, ax.d2c).sort(Lib.sorterAsc);
var onOpenBound = false;

for(var j = 0; j < vals.length; j++) {
b0 = vals[j];
b1 = b0 + brk.dvalue;
if(
(op0 === '(' ? v > b0 : v >= b0) &&
(op1 === ')' ? v < b1 : v <= b1)
) return BADNUM;
if(v >= b0 && v < b1) return BADNUM;

if(onOpenBound && op0 === '(' && v === b0) return BADNUM;
onOpenBound = op1 === ')' && v === b1;
if(onOpenBound && v === b0) return BADNUM;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like onOpenBound can just be 🔪 at this point?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good eye. Done in c4dde70.

}
}
}
Expand Down Expand Up @@ -737,14 +726,9 @@ module.exports = function setConvert(ax, fullLayout) {
var brk = rangebreaksIn[i];

if(brk.enabled) {
var op = brk.operation;
var op0 = op.charAt(0);
var op1 = op.charAt(1);

if(brk.bounds) {
if(brk.pattern) {
bnds = Lib.simpleMap(brk.bounds, cleanNumber);
if(bnds[0] === bnds[1] && op === '()') continue;

// r0 value as date
var r0Date = new Date(r0);
Expand All @@ -761,12 +745,11 @@ module.exports = function setConvert(ax, fullLayout) {

switch(brk.pattern) {
case WEEKDAY_PATTERN:
b0 = bnds[0] + (op0 === '(' ? 1 : 0);
b0 = bnds[0];
b1 = bnds[1];
r0Pattern = r0Date.getUTCDay();
r0PatternDelta = b0 - r0Pattern;
bndDelta = (b1 >= b0 ? b1 - b0 : (b1 + 7) - b0) * ONEDAY;
if(op1 === ']') bndDelta += ONEDAY;
step = 7 * ONEDAY;

t = r0 + r0PatternDelta * ONEDAY -
Expand Down
Binary file removed test/image/baselines/axes_breaks-bars.png
Binary file not shown.
Binary file modified test/image/baselines/axes_breaks-rangeslider.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/axes_breaks-values.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/axes_breaks-weekends-weeknights.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 0 additions & 36 deletions test/image/mocks/axes_breaks-bars.json

This file was deleted.

10 changes: 4 additions & 6 deletions test/image/mocks/axes_breaks-finance.json
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,10 @@
"rangebreaks": [
{
"pattern": "day of week",
"bounds": [ 6, 0 ]
"bounds": [ 6, 1 ]
},
{
"values": ["2017-01-16"],
"operation": "()"
"values": ["2017-01-16"]
}
]
},
Expand All @@ -377,11 +376,10 @@
"rangebreaks": [
{
"pattern": "day of week",
"bounds": [ 6, 0 ]
"bounds": [ 6, 1 ]
},
{
"values": ["2017-01-16"],
"operation": "()"
"values": ["2017-01-16"]
}
]
},
Expand Down
12 changes: 4 additions & 8 deletions test/image/mocks/axes_breaks-night_autorange-reversed.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@
"bounds": [
18,
6
],
"operation": "[)"
]
}
],
"domain": [
Expand All @@ -212,8 +211,7 @@
"bounds": [
18,
6
],
"operation": "[)"
]
}
],
"autorange": "reversed",
Expand Down Expand Up @@ -257,8 +255,7 @@
"bounds": [
18,
6
],
"operation": "[)"
]
}
],
"anchor": "x3",
Expand All @@ -274,8 +271,7 @@
"bounds": [
18,
6
],
"operation": "[)"
]
}
],
"autorange": "reversed",
Expand Down
12 changes: 4 additions & 8 deletions test/image/mocks/axes_breaks-rangeslider.json
Original file line number Diff line number Diff line change
Expand Up @@ -2655,23 +2655,19 @@
"rangebreaks": [
{
"pattern": "day of week",
"bounds": [6, 0],
"operation": "[]"
"bounds": [6, 1]
},
{
"pattern": "hour",
"bounds": [0, 9],
"operation": "()"
"bounds": [0, 9]
},
{
"pattern": "hour",
"bounds": [12, 13],
"operation": "()"
"bounds": [12, 13]
},
{
"pattern": "hour",
"bounds": [15, 21],
"operation": "()"
"bounds": [15, 21]
}
],
"rangeslider": { "visible": true }
Expand Down
4 changes: 2 additions & 2 deletions test/image/mocks/axes_breaks-tickvals.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
{"bounds": [
"1969-12-31 23:59:59.999",
"1970-01-01 00:00:00.090"
], "operation": "()"},
]},
{"bounds": [
"1970-01-01 00:00:00.101",
"1970-01-01 00:00:00.189"
], "operation": "()"}
]}
],
"tickvals": [
"1969-12-31 23:59:59.980",
Expand Down
2 changes: 1 addition & 1 deletion test/image/mocks/axes_breaks-values.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"layout": {
"xaxis": {
"rangebreaks": [
{ "values": [ "2020-01-04", "2020-01-05" ], "operation": "()" }
{ "values": [ "2020-01-03 23:59:59", "2020-01-05" ] }
]
}
}
Expand Down
6 changes: 2 additions & 4 deletions test/image/mocks/axes_breaks-weekends-weeknights.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@
"rangebreaks": [
{
"pattern": "day of week",
"bounds": [ 6, 0 ],
"operation": "[]"
"bounds": [ 6, 1 ]
},
{
"pattern": "hour",
"bounds": [ 16, 8 ],
"operation": "()"
"bounds": [ 16.001, 8 ]
Copy link
Collaborator

Choose a reason for hiding this comment

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

🙃

}
]
},
Expand Down
20 changes: 8 additions & 12 deletions test/image/mocks/axes_breaks-weekends_autorange-reversed.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@
"pattern": "day of week",
"bounds": [
6,
0
],
"operation": "[]"
1
]
}
],
"domain": [
Expand All @@ -107,9 +106,8 @@
"pattern": "day of week",
"bounds": [
6,
0
],
"operation": "[]"
1
]
}
],
"autorange": "reversed",
Expand Down Expand Up @@ -152,9 +150,8 @@
"pattern": "day of week",
"bounds": [
6,
0
],
"operation": "[]"
1
]
}
],
"anchor": "x3",
Expand All @@ -169,9 +166,8 @@
"pattern": "day of week",
"bounds": [
6,
0
],
"operation": "[]"
1
]
}
],
"autorange": "reversed",
Expand Down
Loading