-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Eliminate circular dependencies #2032
Conversation
* @return {array} list of ordered subplot ids (strings). | ||
* | ||
*/ | ||
module.exports = function getSubplotIds(layout, type) { |
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 this. Moving this one file broke a long circular chain in which Plots
was required by plots/cartesian/axis_ids.js
.
'use strict'; | ||
|
||
// TODO make this a plot attribute? | ||
module.exports.fontWeight = 'normal'; |
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.
This seems silly to have in its own file but was another one of those couple things that required a giant circular require of top-level Plots
by some deeply nested component.
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.
This is only used in one place, titles
- everywhere else we just implicitly inherit font-weight: normal
.
One can set font-weight: bold
or something on gd
or a parent, and have that inherited by text inside the plot. We could argue about whether that's a reasonable thing to allow (in particular, exports would NOT inherit this bolding) but it seems silly to ONLY explicitly remove this from the title. I'd 🔪 this file AND the place it's used in titles/index.js
. Later if we decide this is important we can apply normal weight to our whole <svg>
elements or something.
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.
By the way, that font weight key has to be exposed on Plots
for this.
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.
By the way, that font weight key has to be exposed on
Plots
for this.
Ah, crazy - as it stands now this PR will break that, but now I get why this was in there in the first place. So it's really just to allow us to make titles bold by default. Then lets have this an attribute of the Titles
object, ie Titles.fontWeight
, so it can be overridden by saying var Titles = require('./components/titles'); Titles.fontWeight = 900;
@@ -1865,7 +1811,7 @@ plots.extendTrace = function(destTrace, srcTrace) { | |||
* The result is the original object reference with the new contents merged in. | |||
*/ | |||
plots.extendLayout = function(destLayout, srcLayout) { | |||
return plots.extendObjectWithContainers(destLayout, srcLayout, plots.layoutArrayContainers); | |||
return plots.extendObjectWithContainers(destLayout, srcLayout, Registry.layoutArrayContainers); |
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.
plots
vs. Registry
was aliased but not updated in quite a few places. It should be otherwise equivalent.
@@ -2008,59 +2008,59 @@ describe('Queue', function() { | |||
}) | |||
.then(function() { | |||
expect(gd.undoQueue.index).toEqual(1); | |||
expect(gd.undoQueue.queue[0].undo.args[0][1]['marker.color']).toEqual([null]); | |||
expect(gd.undoQueue.queue[0].redo.args[0][1]['marker.color']).toEqual('red'); | |||
expect(gd.undoQueue.queue[0].undo.args[0][0]['marker.color']).toEqual([null]); |
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.
With gd
gone from the first argument, these all shifted over one.
@@ -195,7 +195,7 @@ function assertCircularDeps() { | |||
var logs = []; | |||
|
|||
// see https://github.com/plotly/plotly.js/milestone/9 | |||
var MAX_ALLOWED_CIRCULAR_DEPS = 17; | |||
var MAX_ALLOWED_CIRCULAR_DEPS = 0; |
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.
Welll… 1
. In order to actually get all tests passing. 😬
I'm going to put this on ice for just a moment since I got a bit tripped up trying to get rid of the last circular dependency. It suggests moving toward a register approach is probably the right answer, but it gets a little treacherous to keep things testable (spies, in particular) and to avoid introducing any extra circularity. It's proved very doable, but will require just a bit of finesse to really nail it. |
Unchecked memory usage in firefox… I wonder if this is also related to circular dependencies: plotly/plotly.R#483 |
Closing this thing - as this was put on ice ⛸️ Refer to https://github.com/plotly/plotly.js/milestone/9 for more on the topic |
resolves #236.
This PR eliminates all circular dependencies (🎉), mainly by adding
gd._plotAPI.*
(as suggested in #236) which binds (curries?) thegd
to the arguments automatically. That is, you can callgd._plotAPI.redraw()
orgd._plotAPI.restyle([....])
. This eliminates the need forvar Plotly = require('../../plotly')
, which accounted for the vast majority of circular dependencies.I didn't really find a need for nontrivial changes (has the component registry been implemented since #236?) since all other circular dependencies could be resolved by moving one or two functions to their own files. Though it's a bit ugly to require
get_subplot_id.js
separately. I'm open to different thoughts on this.I expect a couple failing tests to remain since
spyOn
got somewhat more tricky to enforce and required binding the API manually in order to make sure it was the correct, spied-upon API.Edit: almost. One circular dependency remains. Remaining issue:
toImage
requires plot api --> circular