Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

X-axis type lost after restyle #7225

Open
tomwhoiscontrary opened this issue Oct 10, 2024 · 0 comments
Open

X-axis type lost after restyle #7225

tomwhoiscontrary opened this issue Oct 10, 2024 · 0 comments
Labels
bug something broken P3 backlog

Comments

@tomwhoiscontrary
Copy link

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".

@gvwilson gvwilson added bug something broken P3 backlog labels Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken P3 backlog
Projects
None yet
Development

No branches or pull requests

2 participants