Skip to content

"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

Merged
merged 8 commits into from
Dec 7, 2016
Merged

"calendars" component #1230

merged 8 commits into from
Dec 7, 2016

Conversation

etpinard
Copy link
Contributor

@etpinard etpinard commented Dec 6, 2016

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:

image

That the ~200K world-calendars module is only bundled in dist/plotly.js, the other plotly.js bundle show little 🍔 increase.

- 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.
@etpinard etpinard added this to the v1.21.0 milestone Dec 6, 2016
* 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
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'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

Copy link
Collaborator

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?

Copy link
Contributor Author

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.

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'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.

Copy link
Collaborator

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';
Copy link
Contributor Author

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',
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 need for a calendar valType anymore!

coerce('xcalendar', dfltCalendar);
coerce('ycalendar', dfltCalendar);
var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');
handleCalendarDefaults(traceIn, traceOut, ['x', 'y'], layout);
Copy link
Contributor Author

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: {
Copy link
Contributor Author

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/

Copy link
Collaborator

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?

Copy link
Contributor Author

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);
Copy link
Collaborator

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?

Copy link
Contributor Author

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?

Copy link
Contributor Author

@etpinard etpinard Dec 7, 2016

Choose a reason for hiding this comment

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

That second Annotations.draw call was added in #243 here.

Copy link
Collaborator

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?

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 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.

Copy link
Collaborator

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);

Copy link
Collaborator

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops. My bad.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in cb2c54b

@alexcjohnson
Copy link
Collaborator

@etpinard this looks ready to me! Remaining comments are nonblocking from my perspective 💃

@etpinard etpinard merged commit bc457a9 into world-cals Dec 7, 2016
@etpinard etpinard deleted the world-cals-component branch December 7, 2016 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants