@@ -63,7 +63,7 @@ plots.hasSimpleAPICommandBindings = commandModule.hasSimpleAPICommandBindings;
6363plots . findSubplotIds = function findSubplotIds ( data , type ) {
6464 var subplotIds = [ ] ;
6565
66- if ( plots . subplotsRegistry [ type ] === undefined ) return subplotIds ;
66+ if ( ! plots . subplotsRegistry [ type ] ) return subplotIds ;
6767
6868 var attr = plots . subplotsRegistry [ type ] . attr ;
6969
@@ -90,7 +90,7 @@ plots.findSubplotIds = function findSubplotIds(data, type) {
9090plots . getSubplotIds = function getSubplotIds ( layout , type ) {
9191 var _module = plots . subplotsRegistry [ type ] ;
9292
93- if ( _module === undefined ) return [ ] ;
93+ if ( ! _module ) return [ ] ;
9494
9595 // layout must be 'fullLayout' here
9696 if ( type === 'cartesian' && ( ! layout . _has || ! layout . _has ( 'cartesian' ) ) ) return [ ] ;
@@ -124,14 +124,14 @@ plots.getSubplotIds = function getSubplotIds(layout, type) {
124124 * Get the data trace(s) associated with a given subplot.
125125 *
126126 * @param {array } data plotly full data array.
127- * @param {object } layout plotly full layout object .
128- * @param {string } subplotId subplot ids to look for.
127+ * @param {string } type subplot type to look for .
128+ * @param {string } subplotId subplot id to look for.
129129 *
130130 * @return {array } list of trace objects.
131131 *
132132 */
133133plots . getSubplotData = function getSubplotData ( data , type , subplotId ) {
134- if ( plots . subplotsRegistry [ type ] === undefined ) return [ ] ;
134+ if ( ! plots . subplotsRegistry [ type ] ) return [ ] ;
135135
136136 var attr = plots . subplotsRegistry [ type ] . attr ,
137137 subplotData = [ ] ,
@@ -157,6 +157,31 @@ plots.getSubplotData = function getSubplotData(data, type, subplotId) {
157157 return subplotData ;
158158} ;
159159
160+ /**
161+ * Get calcdata traces(s) associated with a given subplot
162+ *
163+ * @param {array } calcData (as in gd.calcdata)
164+ * @param {string } type subplot type
165+ * @param {string } subplotId subplot id to look for
166+ *
167+ * @return {array } array of calcdata traces
168+ */
169+ plots . getSubplotCalcData = function ( calcData , type , subplotId ) {
170+ if ( ! plots . subplotsRegistry [ type ] ) return [ ] ;
171+
172+ var attr = plots . subplotsRegistry [ type ] . attr ;
173+ var subplotCalcData = [ ] ;
174+
175+ for ( var i = 0 ; i < calcData . length ; i ++ ) {
176+ var calcTrace = calcData [ i ] ,
177+ trace = calcTrace [ 0 ] . trace ;
178+
179+ if ( trace [ attr ] === subplotId ) subplotCalcData . push ( calcTrace ) ;
180+ }
181+
182+ return subplotCalcData ;
183+ } ;
184+
160185// in some cases the browser doesn't seem to know how big
161186// the text is at first, so it needs to draw it,
162187// then wait a little, then draw it again
@@ -2027,3 +2052,67 @@ plots.doCalcdata = function(gd, traces) {
20272052 calcdata [ i ] = cd ;
20282053 }
20292054} ;
2055+
2056+ plots . generalUpdatePerTraceModule = function ( subplot , subplotCalcData , subplotLayout ) {
2057+ var traceHashOld = subplot . traceHash ,
2058+ traceHash = { } ,
2059+ i ;
2060+
2061+ function filterVisible ( calcDataIn ) {
2062+ var calcDataOut = [ ] ;
2063+
2064+ for ( var i = 0 ; i < calcDataIn . length ; i ++ ) {
2065+ var calcTrace = calcDataIn [ i ] ,
2066+ trace = calcTrace [ 0 ] . trace ;
2067+
2068+ if ( trace . visible === true ) calcDataOut . push ( calcTrace ) ;
2069+ }
2070+
2071+ return calcDataOut ;
2072+ }
2073+
2074+ // build up moduleName -> calcData hash
2075+ for ( i = 0 ; i < subplotCalcData . length ; i ++ ) {
2076+ var calcTraces = subplotCalcData [ i ] ,
2077+ trace = calcTraces [ 0 ] . trace ;
2078+
2079+ // skip over visible === false traces
2080+ // as they don't have `_module` ref
2081+ if ( trace . visible ) {
2082+ traceHash [ trace . type ] = traceHash [ trace . type ] || [ ] ;
2083+ traceHash [ trace . type ] . push ( calcTraces ) ;
2084+ }
2085+ }
2086+
2087+ var moduleNamesOld = Object . keys ( traceHashOld ) ;
2088+ var moduleNames = Object . keys ( traceHash ) ;
2089+
2090+ // when a trace gets deleted, make sure that its module's
2091+ // plot method is called so that it is properly
2092+ // removed from the DOM.
2093+ for ( i = 0 ; i < moduleNamesOld . length ; i ++ ) {
2094+ var moduleName = moduleNamesOld [ i ] ;
2095+
2096+ if ( moduleNames . indexOf ( moduleName ) === - 1 ) {
2097+ var fakeCalcTrace = traceHashOld [ moduleName ] [ 0 ] ,
2098+ fakeTrace = fakeCalcTrace [ 0 ] . trace ;
2099+
2100+ fakeTrace . visible = false ;
2101+ traceHash [ moduleName ] = [ fakeCalcTrace ] ;
2102+ }
2103+ }
2104+
2105+ // update list of module names to include 'fake' traces added above
2106+ moduleNames = Object . keys ( traceHash ) ;
2107+
2108+ // call module plot method
2109+ for ( i = 0 ; i < moduleNames . length ; i ++ ) {
2110+ var moduleCalcData = traceHash [ moduleNames [ i ] ] ,
2111+ _module = moduleCalcData [ 0 ] [ 0 ] . trace . _module ;
2112+
2113+ _module . plot ( subplot , filterVisible ( moduleCalcData ) , subplotLayout ) ;
2114+ }
2115+
2116+ // update moduleName -> calcData hash
2117+ subplot . traceHash = traceHash ;
2118+ } ;
0 commit comments