* update: update trace and layout attributes of an existing plot * * @param {String | HTMLDivElement} gd * the id or DOM element of the graph container div * @param {Object} traceUpdate * attribute object `{astr1: val1, astr2: val2 ...}` * corresponding to updates in the plot's traces * @p
(gd, traceUpdate, layoutUpdate, _traces)
| 2235 | * |
| 2236 | */ |
| 2237 | function update(gd, traceUpdate, layoutUpdate, _traces) { |
| 2238 | gd = Lib.getGraphDiv(gd); |
| 2239 | helpers.clearPromiseQueue(gd); |
| 2240 | |
| 2241 | if (!Lib.isPlainObject(traceUpdate)) traceUpdate = {}; |
| 2242 | if (!Lib.isPlainObject(layoutUpdate)) layoutUpdate = {}; |
| 2243 | |
| 2244 | if (Object.keys(traceUpdate).length) gd.changed = true; |
| 2245 | if (Object.keys(layoutUpdate).length) gd.changed = true; |
| 2246 | |
| 2247 | var traces = helpers.coerceTraceIndices(gd, _traces); |
| 2248 | |
| 2249 | var restyleSpecs = _restyle(gd, Lib.extendFlat({}, traceUpdate), traces); |
| 2250 | var restyleFlags = restyleSpecs.flags; |
| 2251 | |
| 2252 | var relayoutSpecs = _relayout(gd, Lib.extendFlat({}, layoutUpdate)); |
| 2253 | var relayoutFlags = relayoutSpecs.flags; |
| 2254 | |
| 2255 | // clear calcdata and/or axis types if required |
| 2256 | if (restyleFlags.calc || relayoutFlags.calc) gd.calcdata = undefined; |
| 2257 | if (restyleFlags.clearAxisTypes) helpers.clearAxisTypes(gd, traces, layoutUpdate); |
| 2258 | |
| 2259 | // fill in redraw sequence |
| 2260 | var seq = []; |
| 2261 | |
| 2262 | if (relayoutFlags.layoutReplot) { |
| 2263 | // N.B. works fine when both |
| 2264 | // relayoutFlags.layoutReplot and restyleFlags.fullReplot are true |
| 2265 | seq.push(subroutines.layoutReplot); |
| 2266 | } else if (restyleFlags.fullReplot) { |
| 2267 | seq.push(exports._doPlot); |
| 2268 | } else { |
| 2269 | seq.push(Plots.previousPromises); |
| 2270 | axRangeSupplyDefaultsByPass(gd, relayoutFlags, relayoutSpecs) || Plots.supplyDefaults(gd); |
| 2271 | |
| 2272 | if (restyleFlags.style) seq.push(subroutines.doTraceStyle); |
| 2273 | if (restyleFlags.colorbars || relayoutFlags.colorbars) seq.push(subroutines.doColorBars); |
| 2274 | if (relayoutFlags.legend) seq.push(subroutines.doLegend); |
| 2275 | if (relayoutFlags.layoutstyle) seq.push(subroutines.layoutStyles); |
| 2276 | if (relayoutFlags.axrange) addAxRangeSequence(seq, relayoutSpecs.rangesAltered); |
| 2277 | if (relayoutFlags.ticks) seq.push(subroutines.doTicksRelayout); |
| 2278 | if (relayoutFlags.modebar) seq.push(subroutines.doModeBar); |
| 2279 | if (relayoutFlags.camera) seq.push(subroutines.doCamera); |
| 2280 | |
| 2281 | seq.push(emitAfterPlot); |
| 2282 | } |
| 2283 | |
| 2284 | seq.push(Plots.rehover, Plots.redrag, Plots.reselect); |
| 2285 | |
| 2286 | Queue.add(gd, update, [gd, restyleSpecs.undoit, relayoutSpecs.undoit, restyleSpecs.traces], update, [ |
| 2287 | gd, |
| 2288 | restyleSpecs.redoit, |
| 2289 | relayoutSpecs.redoit, |
| 2290 | restyleSpecs.traces |
| 2291 | ]); |
| 2292 | |
| 2293 | var plotDone = Lib.syncOrAsync(seq, gd); |
| 2294 | if (!plotDone || !plotDone.then) plotDone = Promise.resolve(gd); |
nothing calls this directly
no test coverage detected
searching dependent graphs…