plotly / plotly/plotly.py

Add css for loading visual hint to plotly figure div

Abierto
#2,375 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

feature P3
Lenguaje dominante
Python
Estrellas
18.8k
Forks
2.8k
Merge medio
16 h 26 min
PR fusionados (30 d)
21

Descripción

On a slow Internet connection, when loading a webpage with a plotly figure getting plotly from the cdn (created with include_plotlyjs=False), there is no visual indication that the figure is loading, the page is just empty and frozen until the figure is rendered. An alternative would be to add a loading div which would contain a rotating circle when the plotly fig div is rotating.

Here is an example of code (courtesy of @GaelVaroquaux)

Current plotly figure

<html>
<head><meta charset="utf-8" /></head>
<body>
    <div>
        
                <script type="text/javascript">window.PlotlyConfig = {MathJaxConfig: 'local'};</script>
        <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>    
            <div id="5ce67915-186c-4a00-9800-072154c9af49" class="plotly-graph-div" style="height:100%; width:100%;"></div>
            <script type="text/javascript">
                
                    window.PLOTLYENV=window.PLOTLYENV || {};
                    
                if (document.getElementById("5ce67915-186c-4a00-9800-072154c9af49")) {
                    Plotly.newPlot(
                        '5ce67915-186c-4a00-9800-072154c9af49',
                        [{"type": "scatter", "x": [1, 2], "y": [2, 2]}],
                        {"template": {}},
                        {"responsive": true}
                    )
                };
                
            </script>
        </div>
</body>
</html>

and adding the loading component

<html>
<head><meta charset="utf-8" /></head>
<body>
    <div>
    <style>
    div.plotly-graph-loading {text-align: center; display: none;}

    @keyframes spinner-border {
        to { transform: rotate(360deg); }
    }

    div.plotly-graph-div:empty + div.plotly-graph-loading {
        margin: -50% auto 0 auto;
        display: block;
        width: 3rem;
        height: 3rem;
        vertical-align: text-bottom;
        border: .4rem solid #222;
        border-right-color: transparent;
        border-radius: 50%;
        animation: spinner-border 1s linear infinite;
    }
    </style>

        
            <div id="5ce67915-186c-4a00-9800-072154c9af49" class="plotly-graph-div" style="height:100%; width:100%;"></div>
	    <div class="plotly-graph-loading" role="status"></div>
                <script type="text/javascript">window.PlotlyConfig = {MathJaxConfig: 'local'};</script>
        <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>    
            <script type="text/javascript">
                
                    window.PLOTLYENV=window.PLOTLYENV || {};
                    
                if (document.getElementById("5ce67915-186c-4a00-9800-072154c9af49")) {
                    Plotly.newPlot(
                        '5ce67915-186c-4a00-9800-072154c9af49',
                        [{"type": "scatter", "x": [1, 2], "y": [2, 2]}],
                        {"template": {}},
                        {"responsive": true}
                    )
                };
                
            </script>
        </div>
</body>
</html>

This is a small addition but it can be helpful to show that something will happen. What do you think @nicolaskruchten @jonmease? I'm happy to make a PR but wanted to discuss it with you first.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Localiza el código que genera el div de la figura de Plotly y su HTML circundante; después, compáralo con el componente de carga mostrado en el issue. Verifica el resultado con una carga lenta desde el CDN: una figura vacía debería mostrar un indicador de carga que desaparezca una vez que Plotly renderice la figura.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
css, html, python
Área
data-visualization, frontend
Tipo de issue
Nueva funcionalidad
Dificultad
3/5
Tiempo estimado
Medio día
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.