[FEATURE]: line graphs with line color based on value

Abierto
#8,093 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
45/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
javascript

Línea de trabajo

Start with the scatter attributes in src/traces/scatter/attributes.js, the defaults in line_defaults.js, and gradientWithBounds in src/components/drawing/index.js. Review how fill gradients, legend icons, and image tests are handled, then resolve the proposed line.gradient API with maintainers. Done includes line rendering, reference images, a draftlogs/ changelog, and a rebuilt generated schema; scattergl is out of scope.

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

Descripción

enhancement feature P3 size: 3
Description

Line graphs can have only one colour per series.
Sometime it is very useful to have the line colour variable based on value, to show visually ranges.

For example, I am using right now Apexcharts for energy prices and I obtain:

Image
Why should this feature be added?

Provide information visually, without the need of reading values, which is useful when preparing graph which must be understood easily and also by less technical people.

I can open a PR if the feature is approved. It would be generated by LLM and tested myself.

Mocks/Designs

See screenshot above.

Notes

Related: https://github.com/plotly/plotly.js/issues/5259

This is Claude asked about the complexity of the implementation:

Area graphs: works today

Scatter traces have a fillgradient attribute (src/traces/scatter/attributes.js:387). Set it to type: 'vertical' and give start/stop in y-axis units. Colour scales accept the same position twice, so a scale can switch colour sharply instead of blending. That makes thresholds possible:

// thresholds 2 and 4, gradient spans y = 0..6
fillgradient: {
  type: 'vertical', start: 0, stop: 6,
  colorscale: [[0, base], [2/6, base], [2/6, 'orange'],
               [4/6, 'orange'], [4/6, 'red'], [1, 'red']]
}

Lines and stepped lines: needs a new attribute

line.color takes one colour only. The drawing helper behind fillgradient (gradientWithBounds in src/components/drawing/index.js:462) can already colour a line instead of a fill. So the feature would mostly reuse existing code:

  • New attributes: add them to the scatter line settings, plus their defaults in line_defaults.js.
  • Drawing: call the existing helper on the line, in the same way the fill code does.
  • Other pieces:
    • the legend icon;
    • image tests (a human must generate the reference images);
    • a changelog file in draftlogs/;
    • a rebuild of the generated schema.

It would work for all line shapes, including hv, vh, hvh, vhv and spline. It would not cover the WebGL version (scattergl), and stacked areas would be coloured by their stacked height.

For the settings, I suggest a line.gradient that copies fillgradient (type, start, stop, colorscale). That keeps the API consistent, and plotly.js puts consistency first. Your threshold list could be added on top of that as an easier way to write the stepped colour scale. The maintainers should decide on that part.

Lenguaje dominante
JavaScript
Estrellas
18.4k
Forks
2.1k
Merge medio
2 d 16 h
PR fusionados (30 d)
11

Preparar el entorno

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.

Más de plotly/plotly.js

Todos los issues de plotly/plotly.js

Issues similares

Más issues de JavaScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.