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

Refactor PlotSchema #1144

Merged
merged 11 commits into from
Nov 15, 2016
Merged

Refactor PlotSchema #1144

merged 11 commits into from
Nov 15, 2016

Conversation

etpinard
Copy link
Contributor

This PR significantly refactor PlotSchema.get() in an effort to reduce the level of (hard-coded) abstractions required to built the schema and to make it play better for custom modules.

In brief,

  • the circa 2014 _nestedModules and _composedModules attribute abstractions are gone
  • Plotly.registry now builds Plots.layoutArrayContainer automatically cc @rreusser
  • add frames and animation attributes to Plotly.PlotSchema.get() output
  • makes array containers schema tree creation more robust - see b56bf0c
  • fix bug where rangeslider and rangeselector where listed as available under layout.yaxis
  • removes some useless exports on Annotations
  • removes a bunch of circular dependencies cc De-circularize plotly.js require statements #236

- instead require attribute module into trace attribute modules
  directly.
- that abstraction was mostly obsolete
- the only remaining 'composed-module' was Fx,
  simply merge its attribute into base layout attributes.
- remove _nestedModule and _composedModule handlers
- find module attribute from registry (as opposed to the
  internal Plotly object and other obsolete methods)
- add layoutNodes to better handler rangeslider and rangeselector
- and lower the max circular dep limit
- (now that this doesn't cause circular deps anymore)
- instead of simply removing the trailing 's' of the container
  name
- instead of relying on a hard-coded list
@etpinard etpinard added status: reviewable bug something broken labels Nov 15, 2016
@etpinard etpinard added this to the v1.20.0 milestone Nov 15, 2016
@etpinard
Copy link
Contributor Author

Commit e9f679a is a little hard to read. I'd recommend reviewing plot_api/plot_schema.js as if it were a new file.

Copy link
Contributor

@rreusser rreusser left a comment

Choose a reason for hiding this comment

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

Approving since I have no specific requirements for changes, but I think it would be nice to very briefly document a few of the parts that touch things fairly close to the surface, in particular the attribute flags and what sort of effect they have.

@@ -15,7 +15,7 @@ var extendFlat = require('../../lib/extend').extendFlat;


module.exports = {
_isLinkedToArray: true,
_isLinkedToArray: 'annotation',
Copy link
Contributor

Choose a reason for hiding this comment

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

I've never been able to figure out quite what _isLinkedToArray actually does. It seems to remove the key and trigger some sort of crawl with a key of length - 1 which seems like the sort of thing that would de-pluralize, but this is just a guess.

Perhaps it's a way of defining, for example, button attrs but using a buttons container?

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've never been able to figure out quite what _isLinkedToArray

It's essentially the plot schema version of Plots.layoutArrayContainers. With this PR, both are now united.

Giving a name to the items in the array container is (again) only relevant for plotly.py at the moment. Previously, the item names were simply the container name minus the 's'. This PR make item naming more robust / flexible.

@@ -105,7 +105,7 @@ function assertCircularDeps() {
// as of v1.17.0 - 2016/09/08
// see https://github.com/plotly/plotly.js/milestone/9
// for more details
var MAX_ALLOWED_CIRCULAR_DEPS = 34;
var MAX_ALLOWED_CIRCULAR_DEPS = 17;
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉

var IS_SUBPLOT_OBJ = '_isSubplotObj';
var IS_LINKED_TO_ARRAY = '_isLinkedToArray';
var DEPRECATED = '_deprecated';
var UNDERSCORE_ATTRS = [IS_SUBPLOT_OBJ, IS_LINKED_TO_ARRAY, DEPRECATED];
Copy link
Contributor

@rreusser rreusser Nov 15, 2016

Choose a reason for hiding this comment

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

Is it possible to document what these do, perhaps here? A general frustration regarding attribute definitions is that I make up things like role or underscored attributes based on copying from similar examples, but I don't really have any idea what they mean or do. In particular:

  • _deprecated seems like mainly just an annotation. Do the docs use this in deciding how to display things?
  • _isLinkedToArray seems to have something to do with pluralization and containers, but I haven't figured out what it means beyond that.
  • _isSubplotObj: Seems like an annotation, perhaps used elsewhere? I can't find that it actually does anything, at least within plotly.js.
  • role: Not underscored, but in a similar boat. data_array seems to be important for extracting data out of the json. style affects theming in different environments, if I recall correctly. Do the other options like info_array have any effect? I usually write it because it seems friendly to include, but I don't know if it means anything.

There's probably very little be gained in documenting the internals, but attribute definitions seem like a common thing that people without deep knowledge of the internals probably end up touching pretty regularly, so it might be nice to communicate the meaning somewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

_deprecated

These are simply deprecated keys that don't show up on https://plot.ly/javascript/reference/ and friends, but that plotly.py (still) considers valid.

_isLinkedToArray

See #1144 (comment)

_isSubplotObj

Subplot layout containers e.g. layout.xaxis , layout.scene can be input as layout.xaxis2 or layout.scene10, Plotly.validate and plotly.py need to know about that.

role

Has no effect in plotly.js (yet). At the moment, it is only used for plotly.py's strip style method which removes all role: 'style' keys from a given figure.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, my mistake. data_array is a valType, not a role. Which affects streambed parsing, I think.

@etpinard etpinard merged commit 0e0928b into master Nov 15, 2016
@etpinard etpinard deleted the plot-schema-from-registry branch November 15, 2016 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants