@@ -7,9 +7,20 @@ const mm = mmToPix;
7
7
const anodeX = 1.27 * mm ;
8
8
const cathodeX = 8.83 * mm ;
9
9
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
+
10
21
@customElement ( 'wokwi-led-bar-graph' )
11
22
export 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 */
13
24
@property ( ) color = 'red' ;
14
25
15
26
/** The color of an unlit segment */
@@ -46,6 +57,7 @@ export class LedBarGraphElement extends LitElement {
46
57
47
58
render ( ) {
48
59
const { values, color, offColor } = this ;
60
+ const palette = colorPalettes [ color ] ;
49
61
return html `
50
62
< svg
51
63
width ="10.1mm "
@@ -63,7 +75,7 @@ export class LedBarGraphElement extends LitElement {
63
75
${ segments . map (
64
76
( index ) =>
65
77
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
67
79
} "/> `
68
80
) }
69
81
</ svg >
0 commit comments