MCPcopy Index your code
hub / github.com/plotly/plotly.js / react

Function react

src/plot_api/plot_api.js:2582–2749  ·  view source on GitHub ↗

* Plotly.react: * A plot/update method that takes the full plot state (same API as plot/newPlot) * and diffs to determine the minimal update pathway * * @param {string id or DOM element} gd * the id or DOM element of the graph container div * @param {array of objects} data * array o

(gd, data, layout, config)

Source from the content-addressed store, hash-verified

2580 *
2581 */
2582function react(gd, data, layout, config) {
2583 var frames, plotDone;
2584
2585 function addFrames() {
2586 return exports.addFrames(gd, frames);
2587 }
2588
2589 gd = Lib.getGraphDiv(gd);
2590 helpers.clearPromiseQueue(gd);
2591
2592 var oldFullData = gd._fullData;
2593 var oldFullLayout = gd._fullLayout;
2594
2595 // you can use this as the initial draw as well as to update
2596 if (!Lib.isPlotDiv(gd) || !oldFullData || !oldFullLayout) {
2597 plotDone = exports.newPlot(gd, data, layout, config);
2598 } else {
2599 if (Lib.isPlainObject(data)) {
2600 var obj = data;
2601 data = obj.data;
2602 layout = obj.layout;
2603 config = obj.config;
2604 frames = obj.frames;
2605 }
2606
2607 var configChanged = false;
2608 // assume that if there's a config at all, we're reacting to it too,
2609 // and completely replace the previous config
2610 if (config) {
2611 const oldConfig = Lib.extendDeepAll({}, gd._context);
2612 gd._context = undefined;
2613 setPlotContext(gd, config);
2614 configChanged = !helpers.collectionsAreEqual(oldConfig, gd._context);
2615 }
2616
2617 if (configChanged) {
2618 // Save event listeners as newPlot will remove them
2619 const eventListeners = gd._ev.eventNames().map((name) => [name, gd._ev.listeners(name)]);
2620 plotDone = exports.newPlot(gd, data, layout, config).then(() => {
2621 for (const [name, callbacks] of eventListeners) {
2622 callbacks.forEach((cb) => gd.on(name, cb));
2623 }
2624
2625 // Call react in case transition should have occurred along with config change
2626 return exports.react(gd, data, layout, config);
2627 });
2628 } else {
2629 gd.data = data || [];
2630 helpers.cleanData(gd.data);
2631 gd.layout = layout || {};
2632 helpers.cleanLayout(gd.layout);
2633
2634 applyUIRevisions(gd.data, gd.layout, oldFullData, oldFullLayout);
2635
2636 // "true" skips updating calcdata and remapping arrays from calcTransforms,
2637 // which supplyDefaults usually does at the end, but we may need to NOT do
2638 // if the diff (which we haven't determined yet) says we'll recalc
2639 Plots.supplyDefaults(gd, { skipUpdateCalc: true });

Callers

nothing calls this directly

Calls 8

setPlotContextFunction · 0.85
applyUIRevisionsFunction · 0.85
diffLayoutFunction · 0.85
diffDataFunction · 0.85
updateAutosizeFunction · 0.85
addAxRangeSequenceFunction · 0.85
drawOneFunction · 0.50
drawFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…