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

Function relayout

src/plot_api/plot_api.js:1712–1767  ·  view source on GitHub ↗

* relayout: update layout attributes of an existing plot * * Can be called two ways: * * Signature 1: * @param {String | HTMLDivElement} gd * the id or dom element of the graph container div * @param {String} astr * attribute string (like `'xaxis.range[0]'`) to update * @param {*} val *

(gd, astr, val)

Source from the content-addressed store, hash-verified

1710 * allows setting multiple attributes simultaneously
1711 */
1712function relayout(gd, astr, val) {
1713 gd = Lib.getGraphDiv(gd);
1714 helpers.clearPromiseQueue(gd);
1715
1716 var aobj = {};
1717 if (typeof astr === 'string') {
1718 aobj[astr] = val;
1719 } else if (Lib.isPlainObject(astr)) {
1720 aobj = Lib.extendFlat({}, astr);
1721 } else {
1722 Lib.warn('Relayout fail.', astr, val);
1723 return Promise.reject();
1724 }
1725
1726 if (Object.keys(aobj).length) gd.changed = true;
1727
1728 var specs = _relayout(gd, aobj);
1729 var flags = specs.flags;
1730
1731 // clear calcdata if required
1732 if (flags.calc) gd.calcdata = undefined;
1733
1734 // fill in redraw sequence
1735
1736 // even if we don't have anything left in aobj,
1737 // something may have happened within relayout that we
1738 // need to wait for
1739 var seq = [Plots.previousPromises];
1740 if (flags.layoutReplot) {
1741 seq.push(subroutines.layoutReplot);
1742 } else if (Object.keys(aobj).length) {
1743 axRangeSupplyDefaultsByPass(gd, flags, specs) || Plots.supplyDefaults(gd);
1744
1745 if (flags.legend) seq.push(subroutines.doLegend);
1746 if (flags.layoutstyle) seq.push(subroutines.layoutStyles);
1747 if (flags.axrange) addAxRangeSequence(seq, specs.rangesAltered);
1748 if (flags.ticks) seq.push(subroutines.doTicksRelayout);
1749 if (flags.modebar) seq.push(subroutines.doModeBar);
1750 if (flags.camera) seq.push(subroutines.doCamera);
1751 if (flags.colorbars) seq.push(subroutines.doColorBars);
1752
1753 seq.push(emitAfterPlot);
1754 }
1755
1756 seq.push(Plots.rehover, Plots.redrag, Plots.reselect);
1757
1758 Queue.add(gd, relayout, [gd, specs.undoit], relayout, [gd, specs.redoit]);
1759
1760 var plotDone = Lib.syncOrAsync(seq, gd);
1761 if (!plotDone || !plotDone.then) plotDone = Promise.resolve(gd);
1762
1763 return plotDone.then(function () {
1764 gd.emit('plotly_relayout', specs.eventData);
1765 return gd;
1766 });
1767}
1768
1769// Optimization mostly for large splom traces where

Callers 1

_doPlotFunction · 0.85

Calls 3

_relayoutFunction · 0.85
addAxRangeSequenceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…