X-axis type lost after restyle
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 18.3k
- Forks
- 2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 28
Description
If i create a bar chart with a categorical x-axis, where the x-values are strings of digits, then restyle it with new y-values, the categoricality of the x-axis is lost, and it becomes linear, as if the type had been freshly inferred from the values.
Here is a self-contained example (i'm afraid i don't have a codepen account):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Restyle</title>
<script src="https://cdn.plot.ly/plotly-latest.js"></script>
<script>
addEventListener("DOMContentLoaded", () => {
const plot = document.getElementById("plot");
Plotly.newPlot(plot,
{
data: [{
type: "bar",
x: ["2", "5", "10", "30", "50"],
y: [1, 2, 3, 4, 5]
}],
layout: {
xaxis: {type: "category"}
},
config: {
responsive: true
}
});
document.getElementById("restyle").addEventListener("click", () => {
Plotly.restyle(plot, {y: [[5, 4, 3, 2, 1]]}, 0);
});
});
</script>
</head>
<body>
<div id="plot"></div>
<button id="restyle">Restyle</button>
</body>
</html>
When the page loads, the x-axis is correctly categorical, but when you click the button, it becomes incorrectly linear.
I believe this is the same problem as described in the forum post "X-axis “category” type not honored after Plotly.restyle".
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the self-contained HTML example with Plotly.newPlot and Plotly.restyle, then trace the restyle path that updates the bar chart. Done means the x-axis remains categorical after the y-values are replaced, rather than being re-inferred as linear.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100