Skip to content

Linear value scaling #148

Description

@andrewgoz

The example chart on https://chartscss.org/docs/usage/ shows a drawback of how --size variables work. They are designed to scale between 0 and 1. The example markup does a very simple transformation from table data to --size:

<td style="--size: 0.46"> 46 </td>

The drawback is that the chart bars only use half the chart area, since the largest value is 0.46.

My suggestion is to add the following rule to the standard styles:

.charts-css td {
	--size:calc((var(--value) - var(--valuemin,0)) / (var(--valuemax,1) - var(--valuemin,0)));
}

This still allows the original --size markup to be used unchanged for backward compatibility, but now supports the following changes:

<tbody style="--valuemax: 50">

and

<td style="--value: 46"> 46 </td>

Which allows for a direct copy of table data to CSS --value variable, but better formats the chart to use more of the chart area since it scales values between 0 and 50 (--valuemin and --valuemax) to between 0 and 1.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions