-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Handle weekday strings in rangebreaks #4661
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
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a03d64d
Handle day of week str - add auto dflt for pattern
archmoj d52a803
add tests to handle weekday strings
archmoj 05ab23c
mention matching logic in description
archmoj db2c3a3
attempt improve performance (a bit) by using object lookup, early ret…
archmoj c48f551
no need to cast string to string
archmoj 550a375
improve matching - only need to test first two bounds - avoid touchin…
archmoj e481a13
validate numberic bounds when using patterns
archmoj 84c2a6f
simplify default logic
archmoj 9a0416a
correct axes default logic
archmoj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ var handleCategoryOrderDefaults = require('./category_order_defaults'); | |
var handleLineGridDefaults = require('./line_grid_defaults'); | ||
var setConvert = require('./set_convert'); | ||
|
||
var DAY_OF_WEEK = require('./constants').WEEKDAY_PATTERN; | ||
|
||
/** | ||
* options: object containing: | ||
* | ||
|
@@ -161,6 +163,27 @@ function rangebreaksDefaults(itemIn, itemOut, containerOut) { | |
itemOut.bounds = itemOut.bounds.slice(0, 2); | ||
} | ||
|
||
var dfltPattern = ''; | ||
var i, q; | ||
for(i = 0; i < bnds.length; i++) { | ||
q = indexOfDay(bnds[i]); | ||
if(q) { | ||
dfltPattern = DAY_OF_WEEK; | ||
break; | ||
} | ||
} | ||
var pattern = coerce('pattern', dfltPattern); | ||
|
||
if(pattern === DAY_OF_WEEK) { | ||
for(i = 0; i < bnds.length; i++) { | ||
q = indexOfDay(bnds[i]); | ||
if(q) { | ||
// convert to integers i.e 'Sunday' --> 0 | ||
itemOut.bounds[i] = bnds[i] = q - 1; | ||
} | ||
alexcjohnson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
if(containerOut.autorange === false) { | ||
var rng = containerOut.range; | ||
|
||
|
@@ -175,8 +198,6 @@ function rangebreaksDefaults(itemIn, itemOut, containerOut) { | |
return; | ||
} | ||
} | ||
|
||
coerce('pattern'); | ||
} else { | ||
var values = coerce('values'); | ||
|
||
|
@@ -189,3 +210,21 @@ function rangebreaksDefaults(itemIn, itemOut, containerOut) { | |
} | ||
} | ||
} | ||
|
||
// these numbers are one more than what bounds would be mapped to | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clever way to avoid having to distinguish 0 from undefined :) |
||
var dayStrToNum = { | ||
sun: 1, | ||
mon: 2, | ||
tue: 3, | ||
wed: 4, | ||
thu: 5, | ||
fri: 6, | ||
sat: 7 | ||
}; | ||
|
||
function indexOfDay(v) { | ||
if(typeof v !== 'string') return; | ||
return dayStrToNum[ | ||
String(v).substr(0, 3).toLowerCase() | ||
archmoj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
]; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you have to do this
slice(0, 2)
-coerce
forinfo_array
already does this.But if somehow I'm mistaken about that, you'd need to also shorten
bnds
so you don't lengthenitemOut.bounds
again in the loops below.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any place where
itemOut.bounds.length
is changed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
itemOut.bounds[i] = bnds[i] = q;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. I revised the new logic in 550a375.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, you don't need to worry about the length of
bnds
at all -coerce
handles that sobnds
(anditemOut.bounds
) is eitherundefined
(since it has no default value) or it's an array of length 2 - or less, I just tested this, if you pass in a shorter arraycoerce
isn't going to pad it since the inner values don't have defaults either, but that's OK, it'll just look like undefined for missing values and get filtered out in the type checks.Can you please take all these length checks out? We put a lot of effort into making
coerce
do the right thing so the individualsupplyDefaults
functions could be simple and readable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. Addressed in 84c2a6f.