-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
"calendars" component #1230
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
"calendars" component #1230
Conversation
- use Registry in lib.dates.js to invoke world-calendar logic on-demand.
- ... only when calendars is registered. - replace 'calendar' valType with the appropriate 'enumarated' val object -
- replace layoutNodes list with _module.schema object which allow multiple distinct attribute (e.g. with different description) for each nodes
- ++ allow trace and transform attributes to be filled by component modules.
* For fast conversion btwn world calendars and epoch ms, the Julian Day Number | ||
* of the unix epoch. From calendars.instance().newDate(1970, 1, 1).toJD() | ||
*/ | ||
EPOCHJD: 2440587.5 |
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'm not super happy about this, but I had to find a way to make EPOCHJD
requirable in both lib/dates.js
and components/calendars/
in a non-circular way
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.
If the whole contents of the if(calendar)
blocks went into the component, you wouldn't need EPOCHJD
in dates at all, would you?
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.
Sure. This will lead to some return object destructuring though. I'll see how bad it gets.
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'm not sure I want to go through with this.
Moving all the logic from the if(calendar)
blocks to the calendars component would involved passing oddly named variables to new routines and return sets of values and even mutating them in findExactDates
.
I understand that if would be nice to put all the world-calendar logic in one place, but it would make the code less readable, unless we start duplicating some dates.js
logic in the calendars component.
The current implementation is both DRY and readable - which gets my vote.
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.
Sure, lets leave it as is.
Registry.getComponentMethod('calendars', 'CANONICAL_TICK')[calendar]; | ||
} | ||
else { | ||
return sunday ? '2000-01-02' : '2000-01-01'; |
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.
maybe these gregorian defaults should be placed elsewhere ...
@@ -16,6 +16,25 @@ var constants = require('../../constants/numerical'); | |||
var EPOCHJD = constants.EPOCHJD; | |||
var ONEDAY = constants.ONEDAY; | |||
|
|||
var attributes = { | |||
valType: 'enumerated', |
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.
no need for a calendar
valType anymore!
coerce('xcalendar', dfltCalendar); | ||
coerce('ycalendar', dfltCalendar); | ||
var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults'); | ||
handleCalendarDefaults(traceIn, traceOut, ['x', 'y'], layout); |
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.
a little ugly, but Registry
gets it done
module.exports = { | ||
moduleType: 'component', | ||
name: 'calendars', | ||
|
||
schema: { |
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.
some fancy (slightly hacky) declaration to make sure that calendar attributes will show up on https://community.plot.ly/
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.
how will we know to keep this up to date?
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.
how will we know to keep this up to date?
good question. There's got to be a way to test this.
@@ -312,7 +312,7 @@ Plotly.plot = function(gd, data, layout, config) { | |||
|
|||
// show annotations and shapes | |||
Registry.getComponentMethod('shapes', 'draw')(gd); | |||
Registry.getComponentMethod('annoations', 'draw')(gd); |
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.
how did this not get caught before?
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.
Not sure. Annotations.draw
gets called twice in Plotly.plot
. Maybe one too many?
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.
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 wonder if we can run (most of) our tests in a mode where all components are registered, and Registry.getComponentMethod
throws an error if it doesn't find what it's looking for, rather than returning noop
?
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 wonder if we can run (most of) our tests in a mode where all components are registered
That's currently the case as most tests have var Plotly = require('@lib/index.js')
which registers all traces and components.
Registry.getComponentMethod throws an error if it doesn't find what it's looking for, rather than returning noop?
Yeah, we could mutate the Registry
export in the test suite. Let me try that.
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.
cool - not in this PR though, unless it's super easy :)
@@ -26,6 +27,9 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout | |||
var x = coerce('x'), | |||
y = coerce('y'); | |||
|
|||
var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults'); | |||
handleCalendarDefaults(traceIn, traceOut, ['x', 'y'], layout); | |||
|
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.
previously we coerced calendars after the return on no data - was it intentional to move this up?
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.
Oops. My bad.
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.
done in cb2c54b
@etpinard this looks ready to me! Remaining comments are nonblocking from my perspective 💃 |
to be merged in #1220
This PR makes @alexcjohnson's world-calendars a requirable component in
plotly.js/lib/
. This new"calendars"
component will be included by default only in the main plotly.js bundle. The changes proposed here effectively 🔪 my concerns in #1220 (review)Off this branch:
That the ~200K
world-calendars
module is only bundled indist/plotly.js
, the other plotly.js bundle show little 🍔 increase.