@@ -2069,24 +2069,85 @@ function _relayout(gd, aobj) {
2069
2069
} ;
2070
2070
}
2071
2071
2072
+ /**
2073
+ * update: update trace and layout attributes of an existing plot
2074
+ *
2075
+ * @param {string id or DOM element } gd
2076
+ * the id or DOM element of the graph container div
2077
+ * @param {object } traceUpdate
2078
+ * attribute object `{astr1: val1, astr2: val2 ...}`
2079
+ * corresponding to updates in the plot's traces
2080
+ * @param {object } layoutUpdate
2081
+ * attribute object `{astr1: val1, astr2: val2 ...}`
2082
+ * corresponding to updates in the plot's layout
2083
+ * @param {number or array } traces (optional)
2084
+ * integer or array of integers for the traces to alter (all if omitted)
2085
+ *
2086
+ */
2087
+ Plotly . update = function update ( gd , traceUpdate , layoutUpdate , indices ) {
2088
+ gd = helpers . getGraphDiv ( gd ) ;
2089
+ helpers . clearPromiseQueue ( gd ) ;
2072
2090
2091
+ if ( gd . framework && gd . framework . isPolar ) {
2092
+ return Promise . resolve ( gd ) ;
2073
2093
}
2074
2094
2095
+ if ( ! Lib . isPlainObject ( traceUpdate ) ) traceUpdate = { } ;
2096
+ if ( ! Lib . isPlainObject ( layoutUpdate ) ) layoutUpdate = { } ;
2075
2097
2098
+ if ( Object . keys ( traceUpdate ) . length ) gd . changed = true ;
2099
+ if ( Object . keys ( layoutUpdate ) . length ) gd . changed = true ;
2076
2100
2101
+ var restyleSpecs = _restyle ( gd , traceUpdate , indices ) ,
2102
+ restyleFlags = restyleSpecs . flags ;
2077
2103
2104
+ var relayoutSpecs = _relayout ( gd , layoutUpdate ) ,
2105
+ relayoutFlags = relayoutSpecs . flags ;
2078
2106
2107
+ // clear calcdata if required
2108
+ if ( restyleFlags . clearCalc || relayoutFlags . docalc ) gd . calcdata = undefined ;
2079
2109
2110
+ // fill in redraw sequence
2111
+ var seq = [ ] ;
2080
2112
2113
+ if ( restyleFlags . fullReplot && relayoutFlags . layoutReplot ) {
2114
+ var layout = gd . layout ;
2115
+ gd . layout = undefined ;
2116
+ seq . push ( function ( ) { return Plotly . plot ( gd , gd . data , layout ) ; } ) ;
2117
+ }
2118
+ else if ( restyleFlags . fullReplot ) {
2119
+ seq . push ( Plotly . plot ) ;
2120
+ }
2121
+ else if ( relayoutFlags . layoutReplot ) {
2122
+ seq . push ( subroutines . layoutReplot ) ;
2081
2123
}
2124
+ else {
2125
+ seq . push ( Plots . previousPromises ) ;
2126
+ Plots . supplyDefaults ( gd ) ;
2082
2127
2128
+ if ( restyleFlags . dostyle ) seq . push ( subroutines . doTraceStyle ) ;
2129
+ if ( restyleFlags . docolorbars ) seq . push ( subroutines . doColorBars ) ;
2130
+ if ( relayoutFlags . dolegend ) seq . push ( subroutines . doLegend ) ;
2131
+ if ( relayoutFlags . dolayoutstyle ) seq . push ( subroutines . layoutStyles ) ;
2132
+ if ( relayoutFlags . doticks ) seq . push ( subroutines . doTicksRelayout ) ;
2133
+ if ( relayoutFlags . domodebar ) seq . push ( subroutines . doModeBar ) ;
2083
2134
}
2084
2135
2136
+ Queue . add ( gd ,
2137
+ update , [ gd , restyleSpecs . undoit , relayoutSpecs . undoit , restyleSpecs . traces ] ,
2138
+ update , [ gd , restyleSpecs . redoit , relayoutSpecs . redoit , restyleSpecs . traces ]
2139
+ ) ;
2085
2140
2141
+ var plotDone = Lib . syncOrAsync ( seq , gd ) ;
2086
2142
if ( ! plotDone || ! plotDone . then ) plotDone = Promise . resolve ( gd ) ;
2087
2143
2088
2144
return plotDone . then ( function ( ) {
2145
+ subroutines . setRangeSliderRange ( gd , relayoutSpecs . eventData ) ;
2089
2146
2147
+ gd . emit ( 'plotly_update' , {
2148
+ data : restyleSpecs . eventData ,
2149
+ layout : relayoutSpecs . eventData
2150
+ } ) ;
2090
2151
2091
2152
return gd ;
2092
2153
} ) ;
0 commit comments