Skip to content

Commit 850ef1f

Browse files
committed
WIP unique color per line
1 parent 8b90aee commit 850ef1f

File tree

4 files changed

+44
-11
lines changed

4 files changed

+44
-11
lines changed

src/lib/components/data-vis/line-chart/LineChart.svelte

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,32 @@
126126
},
127127
128128
basicLineParams = {},
129+
colorLineParams = (tier, line, lineIndex) => {
130+
const colorValues = Object.values(colors);
131+
return { pathStrokeColor: colorValues[lineIndex % colorValues.length] };
132+
},
129133
} = $props();
130134
135+
let colors = $state({
136+
teal: "#408A7B",
137+
skyBlue: "#509EC8",
138+
indigo: "#335F91",
139+
ochre: "#BA7F30",
140+
coral: "#E46B6C",
141+
fuchsia: "#BB2765",
142+
lavender: "#736CAC",
143+
ashGrey: "#A0A0A0",
144+
slateGrey: "#636363",
145+
black: "#161616",
146+
forestGreen: "#3C6E3C",
147+
midnightTeal: "#2C5E5E",
148+
dustyRose: "#C86B84",
149+
steelBlue: "#4B6E91",
150+
burntSienna: "#B65C38",
151+
oliveGreen: "#7A8644",
152+
slatePurple: "#64587C",
153+
});
154+
131155
let defaultLineParams = $derived({
132156
xFunction,
133157
yFunction,
@@ -170,11 +194,13 @@
170194
overrideLineParams,
171195
tieredLineParams,
172196
basicLineParams,
197+
colorLineParams,
173198
defaultLineParams,
174199
) {
175200
const listOfProperties = [
176201
...new Set([
177202
...Object.keys(defaultLineParams),
203+
...Object.keys(colorLineParams(tier, line)),
178204
...Object.keys(basicLineParams ?? {}),
179205
...Object.keys(tieredLineParams[tier] ?? {}),
180206
...Object.keys(overrideLineParams(tier, line)),
@@ -187,10 +213,13 @@
187213
overrideLineParams(tier, line)[key] ??
188214
tieredLineParams[tier]?.[key] ??
189215
basicLineParams[key] ??
216+
colorLineParams(tier, line)[key] ??
190217
defaultLineParams[key],
191218
]),
192219
);
193220
221+
console.log(colorLineParams(tier, line));
222+
194223
return {
195224
...merged,
196225
...line,
@@ -203,13 +232,14 @@
203232
Object.keys(tieredLineParams).reduce((acc, tier) => {
204233
acc[tier] = lineChartData.lines
205234
.filter((el) => getLine(tier, el))
206-
.map((line) =>
235+
.map((line, i) =>
207236
generateLineAttributes(
208237
line,
209238
tier,
210239
overrideLineParams,
211240
tieredLineParams,
212241
basicLineParams,
242+
(tier, line) => colorLineParams(tier, line, i),
213243
defaultLineParams,
214244
),
215245
);

src/lib/components/data-vis/line-chart/ValueLabel.svelte

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
let textDimensions = $state();
1616
let verticalPadding = $state(8);
1717
let horizontalPadding = $derived(verticalPadding * 2);
18-
$inspect(markerRect);
1918
</script>
2019

2120
{#if tooltipSnippet === undefined}

src/wrappers/components/data-vis/line-chart/LineChartWrapper.svelte

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -465,13 +465,13 @@
465465
};`,
466466
},
467467
value: function (series, i) {
468-
let colorsArray = [colors.coral, colors.fuschia, colors.purple];
468+
let colorsArray = colors;
469469
470470
return (
471471
{
472-
[englandMedian]: colors.lightblue,
473-
[selectedAreaCode]: colors.teal,
474-
[similarAreas]: colors.darkblue,
472+
[englandMedian]: colors.burntSienna,
473+
[selectedAreaCode]: colors.coral,
474+
[similarAreas]: colors.slatePurple,
475475
}[series] ?? colorsArray[i % colorsArray.length]
476476
);
477477
},
@@ -723,7 +723,7 @@
723723
});
724724
725725
let getColor = function (series, i) {
726-
let colorsArray = [colors.coral, colors.fuschia, colors.purple];
726+
let colorsArray = colors;
727727
728728
return (
729729
{

src/wrappers/components/data-vis/line-chart/line-chart/Examples.svelte

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@
9595
basicLineParams={{ interactiveLines: true }}
9696
tieredLineParams={{
9797
all: {},
98-
hover: { pathStrokeColor: "pink" },
98+
hover: { pathStrokeWidth: 4 },
9999
clicked: {
100-
pathStrokeColor: "red",
100+
pathStrokeWidth: 5,
101101
},
102102
}}
103103
getLine={(tier, el) => {
@@ -131,7 +131,7 @@
131131
} else return true;
132132
}}
133133
tieredLineParams={{
134-
secondary: {},
134+
secondary: { pathStrokeColor: "grey" },
135135
primary: {
136136
halo: true,
137137
pathStrokeWidth: 5,
@@ -174,7 +174,11 @@
174174
x="x"
175175
y="y"
176176
series="areaCode"
177-
basicLineParams={{ includeArea: true, areaFillColor: "lightgrey" }}
177+
basicLineParams={{
178+
includeArea: true,
179+
pathStrokeColor: "darkgrey",
180+
areaFillColor: "lightgrey",
181+
}}
178182
></LineChart>
179183
</div>
180184
<CodeBlock code={codeBlocks.codeBlock1} language="svelte"></CodeBlock>

0 commit comments

Comments
 (0)