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

Aberta
#8,093 1 comentário 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
5/5
Tempo estimado
Mais de uma semana
Facilidade para iniciantes
45/100
Tipo de issue
Funcionalidade
Clareza
Razoavelmente clara
Status de atividade
Ativa
Stack de tecnologia
javascript

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
JavaScript
Estrelas
18.4k
Forks
2.1k
Merge médio
2d 16h
PRs com merge (30d)
11

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de plotly/plotly.js

Todas as issues de plotly/plotly.js

Issues semelhantes

Mais issues de JavaScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.