-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Trace Module Functionality #180
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
Conversation
@@ -9,38 +9,29 @@ | |||
|
|||
'use strict'; | |||
|
|||
var Plotly = require('../../plotly'); |
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.
In all the traces/*/index.js
, we can now get rid of the Plotly
dependency, and no longer call Plots.register
- instead calling it from the register
function in src/index.js
.
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.
🍻
… agnostic-geo-trace
@@ -12,6 +12,8 @@ | |||
var Plotly = require('../../plotly'); | |||
var d3 = require('d3'); | |||
|
|||
var Pie = require('../../traces/pie'); |
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.
Let's require in pie/style_one.js
directly, so that once we split out Pie
from the core, legend won't bundle all of Pie
into its module.
|
||
Plotly.register({ | ||
traces: { | ||
bar: require('./traces/bar'), |
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.
Nice!
Bringing @bpostlethwaite and @alexcjohnson for some thoughts on the API:
- I'm thinking that making
Plotly.register
take an option object might not be necessary.
// this might be sufficient
Plotly.register([require('plotly.js/bar'), require('plotly.js/box')]);
// or even where we would loop over the argument object
Plotly.register(require('plotly.js/bar'), require('plotly.js/box'));
Granted, passing an object with key traces
makes the API easily extendible to registering components down the road. But, do users need to know that they are registering trace or component modules? Could we handle the trace / component split behind the scene inside the register
function (e.g. by adding a type property to each trace module)?
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.
The trace modules have _type
in them right now, but it's more their name - I just followed the names of the arguments for the Plots.register
function. I'd be happy to go either way with this though - the object notation allows for easily extending functionality in the future, but it is a bit more verbose. Up to you guys.
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'd go for the simplest form (loop over arguments). Another reason: you're not using the keys of this object - which is good, because we don't want users making their own names for the trace types, this should come from the module itself. But then why bother having an object with keys?
Re: components - either behind the scenes, or just make a different function like registerComponent
. Doesn't make a big difference, I don't think.
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.
+1 for loop over arguments.
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.
👍 simplest
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.
What makes a component registerable? How can users do
Plotly.register(myComponent)
if we want users to be able to do that in the future an object notation may be necessary so we can allow certain requirements to be turned on/off during the registration process.
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.
it would be nice to make it clear what is registerable though.
What makes a component registerable?
Maybe we could store another meta property in the trace modules? e.g.
var PlotlyBar = require('plotly.js/lib/bar');
console.log(PlotlyBar.moduleType); // => 'trace'
and down the road, registerable component modules could have moduleType
set to 'component'
.
Moreover, Plotly.register
should error out if given a module without moduleType
.
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 like using arguments unless it's the only way because it isn't as easily portable (you would have to use Array.spread)
Wouldn't arguments.length
by enough?
@mdtusz that said, I'm ok with Plotly.register
taken a single array as arguments. Your call.
Can we go with registerTraces as the function name,
I'd vote for a single Plotly.register
and taking care of the distinction between trace and component modules behind the scenes.
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'll add a moduleType
field too then.
Do we want to get rid of the _
's though? I'm happy either way, so its up to 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.
Let's get rid of the _
's. No need to add complexity here.
|
||
Plots.registerSubplot(Gl2d); |
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.
🐄 could you bump this line back up against var Gl2d = ...
@mdtusz Question: So, we're still building the list of registered trace modules in the |
@mdtusz Awesome work. plotly.js is now only a few step away from modularity 🎉 TODO:
In a future PR:
|
Regarding Webpack: I think I was wrong in my understanding of how it bundles 😐. After some basic testing, it seems that you can modify modules from anywhere and have the changes persist throughout the bundle. Because Webpack doesn't know how to deal with transforms in the
They all have their plusses and minuses so I'd like to hear your thoughts on it. It will also depend on how we would like to expose the trace modules for users. |
fantastic 🍻
I think (1) is possible. Only with this option can we guarantee that no code will be duplicated require statement to another while bundling. Here's the list of all modules required in plotly.js to need a browserify transform: We have access to all the |
💃 💃 💃 |
There isn't much actual change in code, more just rearrangement and a few different accessors to use trace modules.
The traces still use the original
register
andgetModule
functions insrc/plots/plots
, however instead of being called from the trace module itself,register
is now called from aregister
function exposed byPlotly
so that end users will be able to pick and choose traces of their liking (once the trace modules are a bit more modularized out)Because of the changes, some "side-effects" needed to be fixed - mainly with pathing in tests and a few other files.