|
8 | 8 | import { highlight } from "$lib/utils/syntax-highlighting/shikiHighlight";
|
9 | 9 | import Lines from "$lib/components/data-vis/line-chart/Lines.svelte";
|
10 | 10 |
|
11 |
| - let { data } = $props(); |
| 11 | + let { lineChartData, interactiveLines, showAllData, chartBackgroundColor } = |
| 12 | + $props(); |
12 | 13 |
|
13 | 14 | let svgWidth = $state(),
|
14 | 15 | svgHeight = 600;
|
15 | 16 |
|
16 |
| - let chartBackgroundColor = "#f5f5f5"; |
17 |
| -
|
18 | 17 | /*let staticMargin = { top: 10, right: 20, bottom: 20, left: 10 };
|
19 | 18 | let dynamicMargin = $derived({ top: 0, right: 0, bottom: 0, left: 0 });
|
20 | 19 | let totalMargin = $derived({
|
|
28 | 27 | let chartWidth = $derived(svgWidth - totalMargin.left - totalMargin.right);
|
29 | 28 | let chartHeight = $derived(svgHeight - totalMargin.top - totalMargin.bottom);
|
30 | 29 |
|
31 |
| - let flatData = $derived(data.lines.map((el) => el.data).flat()); |
| 30 | + let flatData = $derived(lineChartData.lines.map((el) => el.data).flat()); |
32 | 31 |
|
33 | 32 | let allYears = $derived(flatData.map((el) => el.x));
|
34 | 33 |
|
|
85 | 84 | labelHovered,
|
86 | 85 | labelClicked,
|
87 | 86 | ]);
|
88 |
| - $inspect({ selectedLine }); |
89 | 87 |
|
90 | 88 | let nothingSelected = $derived(selectedLine.every((item) => item == null));
|
91 | 89 | let selectedAreaCode = $state("E09000033");
|
92 | 90 | let englandMedian = $state("E06000040");
|
93 | 91 | let similarAreas = $state("E07000224");
|
94 | 92 |
|
95 |
| - let interactiveLines = $state(["primary", "secondary"]); |
96 |
| -
|
97 | 93 | function handleClickOutside(event) {
|
98 | 94 | if (
|
99 | 95 | lineClicked != event.target.parentElement.dataset.id ||
|
|
131 | 127 | base: [colors.coral, colors.fuschia, colors.purple],
|
132 | 128 | });
|
133 | 129 |
|
134 |
| - let showAllData = true; |
135 |
| -
|
136 | 130 | let lookupObj = $derived({
|
137 | 131 | [englandMedian]: colors.lightblue,
|
138 | 132 | [selectedAreaCode]: colors.teal,
|
|
146 | 140 | }
|
147 | 141 |
|
148 | 142 | let dataArray = $derived(
|
149 |
| - data.lines.map((el, i) => { |
| 143 | + lineChartData.lines.map((el, i) => { |
150 | 144 | const tiers = [];
|
151 | 145 | el.areaCode == lineClicked
|
152 | 146 | ? tiers.push("clicked")
|
|
261 | 255 | });
|
262 | 256 | </script>
|
263 | 257 |
|
264 |
| -<h3>Example Usage</h3> |
265 |
| -<pre><code use:highlight |
266 |
| - >{` |
267 |
| -<script> |
268 |
| - import LineChart from './LineChart.svelte'; |
269 |
| - |
270 |
| - const data = { |
271 |
| - lines: [ |
272 |
| - { |
273 |
| - areaCode: "E07000223", |
274 |
| - data: [ |
275 |
| - { x: 2019, y: 45 }, |
276 |
| - { x: 2020, y: 72 }, |
277 |
| - { x: 2021, y: 89 } |
278 |
| - ] |
279 |
| - } |
280 |
| - ] |
281 |
| - }; |
282 |
| -<\/script> |
283 |
| -
|
284 |
| -<LineChart {data} /> |
285 |
| -`}</code |
286 |
| - ></pre> |
287 |
| -
|
288 | 258 | <div bind:clientWidth={svgWidth}>
|
289 | 259 | <svg
|
290 | 260 | onclick={handleClickOutside}
|
|
0 commit comments