-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Cartesian subplot updates using data joins #946
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
Changes from 1 commit
c877c27
ff26691
40fc7f9
652b905
e85a6c7
43d227a
937c54b
78faa3f
f8017f2
c239602
f4aee1e
ab96422
8c09af2
b00d716
ae3ab55
a708381
e78b099
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,9 +10,9 @@ | |
| 'use strict'; | ||
|
|
||
| var d3 = require('d3'); | ||
| var Lib = require('../../lib'); | ||
| var Plots = require('../plots'); | ||
| var Axes = require('./axes'); | ||
|
|
||
| var constants = require('./constants'); | ||
|
|
||
| exports.name = 'cartesian'; | ||
|
|
@@ -147,20 +147,33 @@ exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) | |
| } | ||
| } | ||
| } | ||
|
|
||
| var hadCartesian = (oldFullLayout._has && oldFullLayout._has('cartesian')); | ||
| var hasCartesian = (newFullLayout._has && newFullLayout._has('cartesian')); | ||
|
|
||
| if(hadCartesian && !hasCartesian) { | ||
| var subplotLayers = oldFullLayout._cartesianlayer.selectAll('.subplot'); | ||
|
|
||
| subplotLayers.call(purgeSubplotLayers, oldFullLayout); | ||
| oldFullLayout._defs.selectAll('.axesclip').remove(); | ||
| } | ||
| }; | ||
|
|
||
| exports.drawFramework = function(gd) { | ||
| var fullLayout = gd._fullLayout, | ||
| subplotData = makeSubplotData(gd); | ||
|
|
||
| var subplotLayers = fullLayout._cartesianlayer.selectAll('.subplot') | ||
| .data(subplotData, String); | ||
| .data(subplotData, Lib.identity); | ||
|
|
||
| subplotLayers.enter().append('g') | ||
| .classed('subplot', true); | ||
|
|
||
| subplotLayers.order(); | ||
|
|
||
| subplotLayers.exit() | ||
| .call(purgeSubplotLayers, fullLayout); | ||
|
|
||
| subplotLayers.each(function(subplot) { | ||
| var plotgroup = d3.select(this), | ||
| plotinfo = fullLayout._plots[subplot]; | ||
|
|
@@ -316,6 +329,23 @@ function makeSubplotLayer(plotgroup, gd, subplot) { | |
| .classed('crisp', true); | ||
| } | ||
|
|
||
| function purgeSubplotLayers(layers, fullLayout) { | ||
| if(!layers) return; | ||
|
|
||
| layers.each(function(subplot) { | ||
| var plotgroup = d3.select(this), | ||
| clipId = 'clip' + fullLayout._uid + subplot + 'plot'; | ||
|
|
||
| plotgroup.remove(); | ||
| fullLayout._draggers.selectAll('g.' + subplot).remove(); | ||
| fullLayout._defs.select('#' + clipId).remove(); | ||
|
|
||
| // do not remove individual axis <clipPath>s here | ||
| // as other subplots may need them | ||
| }); | ||
| } | ||
|
|
||
|
|
||
| function joinLayer(parent, nodeType, className) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good enough for
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, def. We use this pattern all over the place, and it's invalid in d3 v4 without some minor modifications, so would be good to extract.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll defer that to a future PR. |
||
| var layer = parent.selectAll('.' + className) | ||
| .data([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.
See http://codepen.io/etpinard/pen/mAEBVz for example of this pattern