@@ -7,9 +7,20 @@ const mm = mmToPix;
77const  anodeX  =  1.27  *  mm ; 
88const  cathodeX  =  8.83  *  mm ; 
99
10+ const  green  =  '#9eff3c' ; 
11+ const  blue  =  '#2c95fa' ; 
12+ const  cyan  =  '#6cf9dc' ; 
13+ const  yellow  =  '#f1d73c' ; 
14+ const  red  =  '#dc012d' ; 
15+ 
16+ const  colorPalettes : Record < string ,  string [ ] >  =  { 
17+   GYR : [ green ,  green ,  green ,  green ,  green ,  yellow ,  yellow ,  yellow ,  red ,  red ] , 
18+   BCYR : [ blue ,  cyan ,  cyan ,  cyan ,  cyan ,  yellow ,  yellow ,  yellow ,  red ,  red ] , 
19+ } ; 
20+ 
1021@customElement ( 'wokwi-led-bar-graph' ) 
1122export  class  LedBarGraphElement  extends  LitElement  { 
12-   /** The color of a lit segment */ 
23+   /** The color of a lit segment. Either HTML color or the special values GYR / BCYR  */ 
1324  @property ( )  color  =  'red' ; 
1425
1526  /** The color of an unlit segment */ 
@@ -46,6 +57,7 @@ export class LedBarGraphElement extends LitElement {
4657
4758  render ( )  { 
4859    const  {  values,  color,  offColor }  =  this ; 
60+     const  palette  =  colorPalettes [ color ] ; 
4961    return  html ` 
5062      < svg  
5163        width ="10.1mm " 
@@ -63,7 +75,7 @@ export class LedBarGraphElement extends LitElement {
6375        ${ segments . map (  
6476          ( index )  =>  
6577            svg `< rect  x ="2.5 " y ="${ 0.4  +  index  *  2.54 } width ="5 " height ="1.74 " fill ="${   
66-               values [ index ]  ? color  : offColor  
78+               values [ index ]  ? palette ?. [ index ]   ??   color  : offColor  
6779            }  "/> `
6880        ) }  
6981      </ svg >  
0 commit comments