Skip to content

Commit 6c0c976

Browse files
committed
feat(led-graph-bar): add palette presets (GYR/BCYR)
1 parent d66e039 commit 6c0c976

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/led-bar-graph-element.stories.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,9 @@ Green.args = { color: 'lime' };
2525

2626
export const Off = Template.bind({});
2727
Off.args = { color: 'lime', values: '[]' };
28+
29+
export const SpecialGYR = Template.bind({});
30+
SpecialGYR.args = { color: 'GYR', values: '[1,1,1,1,1,1,1,1,1,1]' };
31+
32+
export const SpecialBCYR = Template.bind({});
33+
SpecialBCYR.args = { color: 'BCYR', values: '[1,1,1,1,1,1,1,1,1,1]' };

src/led-bar-graph-element.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,20 @@ const mm = mmToPix;
77
const anodeX = 1.27 * mm;
88
const 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')
1122
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 */
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

Comments
 (0)