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

Combine geo and ternary genaral update pattern #1291

Merged
merged 8 commits into from Jan 16, 2017

Conversation

etpinard
Copy link
Contributor

Cartesian, geo and ternary subplots (i.e. all SVG/d3 subplots) draw traces using the trace modules' plot method which expects as input the calcdata traces corresponding to all traces of a given trace type on a given subplot.

Previously, geo and ternary subplot used similar but not-exactly-equivalent logic to handle add/remove/modify updates. This PR - mainly by making ternary subplot use gd.calcdata instead of gd._fullData traces - unifies the geo and ternary logic into Plots.generalUpdatePerTraceModule (I hope you like the name). Cartesian subplots on the other hand are (still) in a world of their own - unifying all SVG/d3 subplots will have to wait.

By doing so, this PR also fixes a bug where:

Plotly.plot('graph', [{
  type: 'scattergeo',   // or 'scatterternary'
  visible: false,
  lon: [/* ... */],
  lat: [/* ... */]
}, {
  type: 'scattergeo',   // or 'scatterternary'
  lon: [/* ... */],
  lat: [/* ... */]
}])

would lead to exception and fail to render. See commit in particular this line for more details.

- so that the same logic can be share for geo and ternary
  subplots (and maybe cartesian subplots down the road)
- fix bug occurring when the first trace on a given subplot
  had `visible: false` (which yielded an exception)
- fix bug occurring when the first trace on a given ternary subplot
  had `visible: false` (which yielded an exception)
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.

💃

}

this.traceHash = traceHash;
Plots.generalUpdatePerTraceModule(this, geoCalcData, geoLayout);
Copy link
Contributor

Choose a reason for hiding this comment

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

Lots of trace-specific code moved elsewhere. I like it already. 👏

* @return {array} array of calcdata traces
*/
plots.getSubplotCalcData = function(calcData, type, subplotId) {
if(plots.subplotsRegistry[type] === undefined) return [];
Copy link
Contributor

Choose a reason for hiding this comment

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

if(!plots.subplotsRegistry[type]) but that's really nitpicky.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. Done in 83c2722


// when a trace gets deleted, make sure that its module's
// plot method is called so that it is properly
// removed from the DOM.
Copy link
Contributor

Choose a reason for hiding this comment

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

👏 Yes.

@@ -2027,3 +2052,67 @@ plots.doCalcdata = function(gd, traces) {
calcdata[i] = cd;
}
};

plots.generalUpdatePerTraceModule = function(subplot, subplotCalcData, subplotLayout) {
var traceHashOld = subplot.traceHash,
Copy link
Contributor

Choose a reason for hiding this comment

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

I always feel like the mutate-existing-data approach contributes a bit to fragility, but I understand why these things are as they are.

expect(out3.traceHash.A.length).toEqual(1);
expect(out3.traceHash.A[0][0].trace.visible).toBe(false);
expect(out3.traceHash.C.length).toEqual(1);
expect(out3.traceHash.C[0][0].trace.visible).toBe(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

The tests are great. 👍

@etpinard etpinard merged commit 8bd4c97 into master Jan 16, 2017
@etpinard etpinard deleted the geo-ternary-visible-false-1st-trace branch January 16, 2017 19:38
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.

None yet

2 participants