-
-
Couldn't load subscription status.
- 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
Changes from 3 commits
a03d64d
d52a803
05ab23c
db2c3a3
c48f551
550a375
e481a13
84c2a6f
9a0416a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 !== -1) { | ||
| 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 !== -1) { | ||
| // convert to integers i.e 'Monday' --> 1 | ||
| itemOut.bounds[i] = bnds[i] = q; | ||
| } | ||
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,18 @@ function rangebreaksDefaults(itemIn, itemOut, containerOut) { | |
| } | ||
| } | ||
| } | ||
|
|
||
| var weekSTR = [ | ||
| 'sun', | ||
| 'mon', | ||
| 'tue', | ||
| 'wed', | ||
| 'thu', | ||
| 'fri', | ||
| 'sat' | ||
| ]; | ||
|
|
||
| function indexOfDay(v) { | ||
| var str = String(v).substr(0, 3).toLowerCase(); | ||
| return weekSTR.indexOf(str); | ||
|
||
| } | ||
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)-coerceforinfo_arrayalready does this.But if somehow I'm mistaken about that, you'd need to also shorten
bndsso you don't lengthenitemOut.boundsagain 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.lengthis 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
bndsat all -coercehandles 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 arraycoerceisn'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
coercedo the right thing so the individualsupplyDefaultsfunctions 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.