ChartsCSS / charts.css

Open source CSS framework for data visualization.

Home Page:https://ChartsCSS.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Enhancement idea: Can we improve things with css `attr` values?

IDisposable opened this issue · comments

Looking at the samples <td style="--size: calc( 60 / 100 );"> $ 60K </td> might be more semantically valuable if we did something like

<td data-value="60" data-total="100" style="--size: calc( attr("data-value") / attr("data-total");"> $ 60K </td> or something similar... and we could have the default style for size be implicitly that calc and do similar for --start. Also would be cool to be able to reach up for the data-total value using the cascading of CSS ;)

When I started developing Charts.CSS I tested all the available methods. There where several use cases where data-* attributes had less flexibility. That is why I decided to use CSS variables.

In your example, the --size calculation is attr("data-value") / attr("data-total"), this is not always the default size.

When you prefer to display stacked chart, you need to change the "total" value. Read the stacked docs, and see the examples on the Simple vs. Percentage section.

In addition, when using CSS variables, you can use math functions everywhere. With data attributes you have to use static value. You can't use calculations like data-total="calc( 2 + 3 + 4 )"