plotly / plotly/plotly.js

X-axis type lost after restyle

Aperta
#7,225 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug P3
Lingua principale
JavaScript
Stelle
18.3k
Fork
2k
Merge medio
2g 12h
PR unite (30g)
28

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia eseguendo l’esempio HTML autonomo con Plotly.newPlot e Plotly.restyle, quindi segui il percorso di restyle che aggiorna il grafico a barre. Il lavoro è completato quando l’asse x rimane categoriale dopo la sostituzione dei valori y, invece di essere nuovamente dedotto come lineare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript
Ambito
data-visualization
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.