Spaces:
Running
Running
abril4416 commited on
Commit ·
c04888d
1
Parent(s): 73376e0
Eliminate Plotly autosize feedback loops with explicit wrapper-sized relayout
Browse files
linear-regression/gradient-descent.html
CHANGED
|
@@ -122,6 +122,6 @@
|
|
| 122 |
</main>
|
| 123 |
|
| 124 |
<script src="https://cdn.plot.ly/plotly-2.35.2.min.js"></script>
|
| 125 |
-
<script src="gradient.js?v=
|
| 126 |
</body>
|
| 127 |
</html>
|
|
|
|
| 122 |
</main>
|
| 123 |
|
| 124 |
<script src="https://cdn.plot.ly/plotly-2.35.2.min.js"></script>
|
| 125 |
+
<script src="gradient.js?v=20260814c"></script>
|
| 126 |
</body>
|
| 127 |
</html>
|
linear-regression/gradient.js
CHANGED
|
@@ -48,7 +48,6 @@ const state = {
|
|
| 48 |
landscapeCache: null,
|
| 49 |
landscapeCamera: null,
|
| 50 |
landscapePlotReady: false,
|
| 51 |
-
landscapeResizeObserver: null,
|
| 52 |
landscapeResizeRaf: null,
|
| 53 |
lastLandscapeSize: null,
|
| 54 |
};
|
|
@@ -132,17 +131,6 @@ function initLandscapeInteractions() {
|
|
| 132 |
constrainLandscapeSizeToContainer();
|
| 133 |
});
|
| 134 |
|
| 135 |
-
if (window.ResizeObserver) {
|
| 136 |
-
state.landscapeResizeObserver = new ResizeObserver((entries) => {
|
| 137 |
-
const entry = entries && entries[0];
|
| 138 |
-
const contentRect = entry ? entry.contentRect : null;
|
| 139 |
-
debugResizeLog("ResizeObserver", {
|
| 140 |
-
observed: contentRect ? `${contentRect.width.toFixed(2)}x${contentRect.height.toFixed(2)}` : "n/a",
|
| 141 |
-
});
|
| 142 |
-
queueLandscapeResize(false);
|
| 143 |
-
});
|
| 144 |
-
state.landscapeResizeObserver.observe(landscapePlotWrap);
|
| 145 |
-
}
|
| 146 |
}
|
| 147 |
|
| 148 |
function handleResize() {
|
|
@@ -257,8 +245,8 @@ function queueLandscapeResize(force = false) {
|
|
| 257 |
|
| 258 |
state.landscapeResizeRaf = requestAnimationFrame(() => {
|
| 259 |
state.landscapeResizeRaf = null;
|
| 260 |
-
debugResizeLog("Plotly.
|
| 261 |
-
Plotly.
|
| 262 |
});
|
| 263 |
}
|
| 264 |
|
|
@@ -697,9 +685,13 @@ function renderLandscapePlotly(data) {
|
|
| 697 |
];
|
| 698 |
|
| 699 |
const sceneCamera = state.landscapeCamera || cloneCamera(DEFAULT_CAMERA);
|
|
|
|
|
|
|
| 700 |
|
| 701 |
const layout = {
|
| 702 |
-
autosize:
|
|
|
|
|
|
|
| 703 |
margin: { l: 0, r: 0, t: 8, b: 0 },
|
| 704 |
paper_bgcolor: "#ffffff",
|
| 705 |
scene: {
|
|
|
|
| 48 |
landscapeCache: null,
|
| 49 |
landscapeCamera: null,
|
| 50 |
landscapePlotReady: false,
|
|
|
|
| 51 |
landscapeResizeRaf: null,
|
| 52 |
lastLandscapeSize: null,
|
| 53 |
};
|
|
|
|
| 131 |
constrainLandscapeSizeToContainer();
|
| 132 |
});
|
| 133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
}
|
| 135 |
|
| 136 |
function handleResize() {
|
|
|
|
| 245 |
|
| 246 |
state.landscapeResizeRaf = requestAnimationFrame(() => {
|
| 247 |
state.landscapeResizeRaf = null;
|
| 248 |
+
debugResizeLog("Plotly.relayout(size)", { width, height });
|
| 249 |
+
Plotly.relayout(landscapePlot, { width, height });
|
| 250 |
});
|
| 251 |
}
|
| 252 |
|
|
|
|
| 685 |
];
|
| 686 |
|
| 687 |
const sceneCamera = state.landscapeCamera || cloneCamera(DEFAULT_CAMERA);
|
| 688 |
+
const plotWidth = Math.round(landscapePlotWrap.clientWidth);
|
| 689 |
+
const plotHeight = Math.round(landscapePlotWrap.clientHeight);
|
| 690 |
|
| 691 |
const layout = {
|
| 692 |
+
autosize: false,
|
| 693 |
+
width: plotWidth,
|
| 694 |
+
height: plotHeight,
|
| 695 |
margin: { l: 0, r: 0, t: 8, b: 0 },
|
| 696 |
paper_bgcolor: "#ffffff",
|
| 697 |
scene: {
|
logistic-regression/cost-visualization.html
CHANGED
|
@@ -130,6 +130,6 @@
|
|
| 130 |
</main>
|
| 131 |
|
| 132 |
<script src="https://cdn.plot.ly/plotly-2.35.2.min.js"></script>
|
| 133 |
-
<script src="cost.js?v=
|
| 134 |
</body>
|
| 135 |
</html>
|
|
|
|
| 130 |
</main>
|
| 131 |
|
| 132 |
<script src="https://cdn.plot.ly/plotly-2.35.2.min.js"></script>
|
| 133 |
+
<script src="cost.js?v=20260814c"></script>
|
| 134 |
</body>
|
| 135 |
</html>
|
logistic-regression/cost.js
CHANGED
|
@@ -97,7 +97,6 @@ const state = {
|
|
| 97 |
gridCache: { case1: null, case2: null },
|
| 98 |
plotReady: false,
|
| 99 |
camera3d: null,
|
| 100 |
-
resizeObserver: null,
|
| 101 |
resizeRaf: null,
|
| 102 |
lastPlotSize: null,
|
| 103 |
};
|
|
@@ -563,8 +562,8 @@ function queuePlotResize(force = false) {
|
|
| 563 |
|
| 564 |
state.resizeRaf = requestAnimationFrame(() => {
|
| 565 |
state.resizeRaf = null;
|
| 566 |
-
debugResizeLog("Plotly.
|
| 567 |
-
window.Plotly.
|
| 568 |
});
|
| 569 |
}
|
| 570 |
|
|
@@ -682,6 +681,8 @@ function renderLandscape(caseKey, grid) {
|
|
| 682 |
const meta = caseMeta[caseKey];
|
| 683 |
const view = controls.landscapeView.value;
|
| 684 |
const idx = Math.min(state.stepIndex, Math.max(0, state.trajectory.length - 1));
|
|
|
|
|
|
|
| 685 |
|
| 686 |
const showSurface = controls.toggleSurface.checked;
|
| 687 |
const showContours = controls.toggleContours.checked;
|
|
@@ -765,7 +766,9 @@ function renderLandscape(caseKey, grid) {
|
|
| 765 |
}
|
| 766 |
|
| 767 |
const layout2d = {
|
| 768 |
-
autosize:
|
|
|
|
|
|
|
| 769 |
margin: { l: 58, r: 16, t: 8, b: 50 },
|
| 770 |
xaxis: { title: meta.p1Label },
|
| 771 |
yaxis: { title: meta.p2Label },
|
|
@@ -881,7 +884,9 @@ function renderLandscape(caseKey, grid) {
|
|
| 881 |
}
|
| 882 |
|
| 883 |
const layout3d = {
|
| 884 |
-
autosize:
|
|
|
|
|
|
|
| 885 |
margin: { l: 0, r: 0, t: 8, b: 0 },
|
| 886 |
scene: {
|
| 887 |
xaxis: { title: meta.p1Label, range: [grid.p1Min, grid.p1Max], showspikes: false },
|
|
@@ -1305,19 +1310,6 @@ function bindEvents() {
|
|
| 1305 |
drawClassifier(controls.caseSelect.value);
|
| 1306 |
});
|
| 1307 |
|
| 1308 |
-
if (window.ResizeObserver) {
|
| 1309 |
-
state.resizeObserver = new window.ResizeObserver((entries) => {
|
| 1310 |
-
for (const entry of entries) {
|
| 1311 |
-
if (entry.target === plotWrap) {
|
| 1312 |
-
debugResizeLog("ResizeObserver", {
|
| 1313 |
-
observed: `${entry.contentRect.width.toFixed(2)}x${entry.contentRect.height.toFixed(2)}`,
|
| 1314 |
-
});
|
| 1315 |
-
queuePlotResize(false);
|
| 1316 |
-
}
|
| 1317 |
-
}
|
| 1318 |
-
});
|
| 1319 |
-
state.resizeObserver.observe(plotWrap);
|
| 1320 |
-
}
|
| 1321 |
}
|
| 1322 |
|
| 1323 |
function init() {
|
|
|
|
| 97 |
gridCache: { case1: null, case2: null },
|
| 98 |
plotReady: false,
|
| 99 |
camera3d: null,
|
|
|
|
| 100 |
resizeRaf: null,
|
| 101 |
lastPlotSize: null,
|
| 102 |
};
|
|
|
|
| 562 |
|
| 563 |
state.resizeRaf = requestAnimationFrame(() => {
|
| 564 |
state.resizeRaf = null;
|
| 565 |
+
debugResizeLog("Plotly.relayout(size)", { width, height });
|
| 566 |
+
window.Plotly.relayout(plotEl, { width, height });
|
| 567 |
});
|
| 568 |
}
|
| 569 |
|
|
|
|
| 681 |
const meta = caseMeta[caseKey];
|
| 682 |
const view = controls.landscapeView.value;
|
| 683 |
const idx = Math.min(state.stepIndex, Math.max(0, state.trajectory.length - 1));
|
| 684 |
+
const plotWidth = Math.round(plotWrap.clientWidth);
|
| 685 |
+
const plotHeight = Math.round(plotWrap.clientHeight);
|
| 686 |
|
| 687 |
const showSurface = controls.toggleSurface.checked;
|
| 688 |
const showContours = controls.toggleContours.checked;
|
|
|
|
| 766 |
}
|
| 767 |
|
| 768 |
const layout2d = {
|
| 769 |
+
autosize: false,
|
| 770 |
+
width: plotWidth,
|
| 771 |
+
height: plotHeight,
|
| 772 |
margin: { l: 58, r: 16, t: 8, b: 50 },
|
| 773 |
xaxis: { title: meta.p1Label },
|
| 774 |
yaxis: { title: meta.p2Label },
|
|
|
|
| 884 |
}
|
| 885 |
|
| 886 |
const layout3d = {
|
| 887 |
+
autosize: false,
|
| 888 |
+
width: plotWidth,
|
| 889 |
+
height: plotHeight,
|
| 890 |
margin: { l: 0, r: 0, t: 8, b: 0 },
|
| 891 |
scene: {
|
| 892 |
xaxis: { title: meta.p1Label, range: [grid.p1Min, grid.p1Max], showspikes: false },
|
|
|
|
| 1310 |
drawClassifier(controls.caseSelect.value);
|
| 1311 |
});
|
| 1312 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1313 |
}
|
| 1314 |
|
| 1315 |
function init() {
|