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.
232 stars 19 forks source link

Colorstops show black color (ie invalid color) at 100% of segarc range #57

Closed AmoebeLabs closed 2 years ago

AmoebeLabs commented 2 years ago

Bug description

Sometimes the colorstops shows a black color at the end of the range although the colorstop value is larger then the maximum value.

The following colorstop should work for a value of 60: it should show orange, but shows black in the segmentedarc. It should even work with an end value of 55: that color should be used for any value larger than 55...

Screenshots are from example view-sake10.yml

But it doesn't work for some reason

colorstops_boiler_water_blue2orange:
  template:
    type: colorstops
    defaults:
      - thegap: 1
      - theFill: true
      - theStroke: false
  colorstops:
    gap: '[[thegap]]'
    fill: '[[theFill]]'
    stroke: '[[theStroke]]'
    colors:
      0: '#0094ff'
      5: '#1793e7' 
      10: '#2e92d0' 
      15: '#4591b9' 
      20: '#5c91a2' 
      25: '#73908b' 
      30: '#8b8f73' 
      35: '#a28e5c' 
      40: '#b98e45' 
      45: '#d08d2e' 
      50: '#e78c17'
      55: '#ff8c00'
      65: '#ff8c00'

Still going strong just above 55 degrees: image

And at 60 degrees, full range of segarc: image

(Optional): Suggested Solution

It seems that the setting lastcolor is the culprit: it doesn't calculate the segment/entry in the colorstop in the correct way...

AmoebeLabs commented 2 years ago

The problem is that the colorstop must match the min/max scale.

In this case the last entry is 65:, and the max scale is 60. So the 65 is ignored!

Another fix is that if the last entry is 55, the software now checks if a colorstop is defined for the max scale value, and if not, it just adds the last color in the list again at that value to make sure there is a value for the max scale value.