[FEATURE]: Better error message for axis scaling.
Opened this issue · 3 comments
Description
Currently, when a Plotly chart is rendered inside a container <div> that is too small (e.g., height = 0 or very small), Plotly.js throws a very broad error:
Uncaught (in promise) Error: Something went wrong with axis scaling
The error stack traces to internal scaling functions, but it provides no actionable guidance for the developer. In my case, the issue was resolved by explicitly setting a minimum height on the container:
#plotlyContainer {
min-height: 600px;
}The error message should instead clearly indicate that the container element is too small to render the chart, so developers can quickly diagnose the problem.
Why should this feature be added?
- Improved developer experience: The current error is misleading and vague. Many users may spend significant time debugging chart data or layout issues when the root cause is the container size.
- Faster debugging: A clear, descriptive error such as "Plotly container height is too small to render the chart" would allow developers to quickly fix layout issues.
- Prevents unnecessary workarounds: Developers currently have to discover these issues through trial and error.
Mocks/Designs
No visual mockups required. The requested change is purely to improve the clarity of the error message.
Notes
- This could potentially be implemented as a validation step during
Plotly.newPlotthat checks the container's computed height and width before rendering. - It might also be helpful to provide a warning in the console if either dimension is below a certain threshold.
Hi @umer936 thank you for the report, I'm always in favor of more specific error messages.
Do you have a minimal example which reproduces the situation where the Uncaught (in promise) Error: Something went wrong with axis scaling error is raised due to the div being too small? I'm having trouble reproducing it on my own but I might just not have quite the right settings.
Hmm... I've been trying to replicate it in Codepen but struggling to. It certainly does it in my working copy which loads in 68MB of data into Heatmap with hovertemplate and colorbar and such. (Both are Plotly 3.1.1). I'll keep working on this to get it to do the same crash in a more minimal example.
Nevermind, that wasn't too bad.
https://codepen.io/umer936-the-looper/pen/EaPJpBr
<script src="https://cdnjs.cloudflare.com/ajax/libs/plotly.js/3.1.1/plotly.min.js"
integrity="sha512-QaIUFweb9pyRnQZEYIujSDTHndibSwqsTSb69aedsfAAUpJRUE5yyYfaNAJIbTDuNECyHR/Cc0N7lQJrp0IEpA=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<!-- NEED THE HEIGHT OTHERWISE PLOTLY FAILS - https://github.com/plotly/plotly.js/issues/7568-->
<!-- add this to #plotlyContainer to fix -->
<!-- style="height:600px;"-->
<div id="plotlyContainer" >
<div id="plotSpinner" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div>
<script>
async function fetchData() {
const rows = 2, cols = 3;
const flat = new Float32Array([1, 0, 3, 4, 0, 6]);
return Array.from({ length: rows }, (_, y) =>
Array.from(flat.subarray(y * cols, (y + 1) * cols))
);
}
fetchData().then(data => {
Plotly.newPlot('plotlyContainer', [{ z: data, type: 'heatmap' }]);
});
</script>In my actual use, #plotSpinner is a Bootstrap 5 spinner that gets removed when the plot data is parsed and loaded.