AmoebeLabs / swiss-army-knife-card

The versatile custom Swiss Army Knife card for Home Assistant allows you to create your unique visualization using several graphical tools, styling options and animations.
237 stars 21 forks source link

Add colorstops, colorstopgradients and linear gradients to the segmented-arc #5

Open AmoebeLabs opened 4 years ago

AmoebeLabs commented 4 years ago

The Problem To Be Solved

Add colorstops, colorstopgradients and linear gradients to the segmented-arc, just as the horse-shoe already is capable of. This will be a lot of work, as you can also color the scale with this.

(Optional): Suggested Solution

Take the horseshoe as an example, but also check other sources for examples around this. Maybe there are better and easier solutions as the segmented-arc is completely different implemented compared to the horseshoe.

Difficulties with gradients

The segmented arc is constructed using separate path's for each segment. This probably means you can't use any gradient solutions that exactly follow the path:

Segment color list as an alternative

One alternative to a full gradient are segmented gradients as shown below in the third arc (CPU 31 %):

image

And with the scale added, and filled using the same color list: image

In this case a list of 10 colors is defined in the segmented arc with also 10 segments (must be changed, colorlist defines number of segments) for example. Each segment gets its own 'fixed' color. Depending on the chosen colorlist, this can look like a nice gradient...

2020.10.13: First results with some hacking in the creation and rendering of the segmented arc with a colorstop:

image

Configuration in this case:

Number of segments is the number of colors in the colorlist. Simple.

Colorstops

The full arc (ie all segments) get the color according to the colorstop. This requires rewriting of the all the segments if a new colorstop is reached or, and that is easier, setting the fill color to the colorstop value.

Segments as colorstops

When using a colorstop list for the creation of the segments, each segment can have its own color. This might already be usable for CPU load, temperature, battery percentage, disk/ram percentage, etc.

In this case the segments can be of different size. Unknown if current implementation can handle this. But using a separate color for each segment is no problem, as the fill color can be specified using javascript.

Example:

Segment value ranges are

Depending on the size of the full segmented arc (degrees), these segments can be calculated. Say the arc is 90 degrees, then the segments are:

When using this option, the scale will have the colors according to the colorstops.

Configuration in this case:

Structure

If we use a separate structure under segments for each style, then there is a 1:1 link between them

segments:
  fixedcolor:
    dash: 36
    gap: 1
    color: 'red'
segments:
  colorlist:
    colors:
      - color1
      - color2
      - color3
    gap: 1
segments:
  colorstops:
    colors:
      - 00: color1
      - 40: color2
      - 80: color3
    gap: 1
segments:
  simplegradient:
    colors:
      - color1
      - color2
    dash: 10 (degrees) OR count: 10 (nr of segments)
    gap: 1

Implementation

// als je ook een colorstop list als segmenten wilt laten zien, dan zul
// je bijv. net als d3 een lijst van segmentgroottes moeten opbouwen.
// standaard dus [20,20,20,15] bijv. zoals in de for loop al gebeurd, maar dan in een array.
// dan dat array laten plotten met gegevens.
//
// dan kun je ook van de colorstop een array maken [40,20,10] bijv. voor kleuren groen, geel, rood bijv.
// dan kun je een schaal neerzetten en zien hoever de waarde eigenlijk is. al bijna in het rood bijv.
AmoebeLabs commented 4 years ago

Added "segments as colorstops" option

AmoebeLabs commented 3 years ago

Added first version of colorstop, where the color of all the segments are the current color segment.

AmoebeLabs commented 3 years ago

Note for colorstop gradient & simple gradient:

Note: It might be possible to use the __getGradientValue(startcolor, endcolor, value0-1). Colors can be fetched from the configuration & segments. And the value might use the min/max and current angles.