Skip to content
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

Closed
wants to merge 5 commits into from
Closed

Conversation

rreusser
Copy link
Contributor

@rreusser rreusser commented Sep 23, 2017

resolves #236.

This PR eliminates all circular dependencies (🎉), mainly by adding gd._plotAPI.* (as suggested in #236) which binds (curries?) the gd to the arguments automatically. That is, you can call gd._plotAPI.redraw() or gd._plotAPI.restyle([....]). This eliminates the need for var 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

* @return {array} list of ordered subplot ids (strings).
*
*/
module.exports = function getSubplotIds(layout, type) {
Copy link
Contributor Author

@rreusser rreusser Sep 23, 2017

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

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.

Copy link
Collaborator

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.

Copy link
Contributor

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.

Copy link
Collaborator

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

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

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.

@rreusser rreusser changed the title Eliminiate circular dependencies Eliminate circular dependencies Sep 23, 2017
@@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉

Copy link
Contributor Author

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

@rreusser
Copy link
Contributor Author

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.

@rreusser
Copy link
Contributor Author

rreusser commented Oct 12, 2017

Unchecked memory usage in firefox… I wonder if this is also related to circular dependencies: plotly/plotly.R#483

@etpinard
Copy link
Contributor

Closing this thing - as this was put on ice ⛸️

Refer to https://github.com/plotly/plotly.js/milestone/9 for more on the topic

@etpinard etpinard closed this Nov 17, 2017
@etpinard etpinard deleted the eliminate-circularity branch November 17, 2017 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

De-circularize plotly.js require statements
3 participants