Skip to content

Commit f8e6c54

Browse files
committed
move LineChart.svelte from playground to data-vis
1 parent 9646cad commit f8e6c54

File tree

1 file changed

+4
-34
lines changed

1 file changed

+4
-34
lines changed
Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
import { highlight } from "$lib/utils/syntax-highlighting/shikiHighlight";
99
import Lines from "$lib/components/data-vis/line-chart/Lines.svelte";
1010
11-
let { data } = $props();
11+
let { lineChartData, interactiveLines, showAllData, chartBackgroundColor } =
12+
$props();
1213
1314
let svgWidth = $state(),
1415
svgHeight = 600;
1516
16-
let chartBackgroundColor = "#f5f5f5";
17-
1817
/*let staticMargin = { top: 10, right: 20, bottom: 20, left: 10 };
1918
let dynamicMargin = $derived({ top: 0, right: 0, bottom: 0, left: 0 });
2019
let totalMargin = $derived({
@@ -28,7 +27,7 @@
2827
let chartWidth = $derived(svgWidth - totalMargin.left - totalMargin.right);
2928
let chartHeight = $derived(svgHeight - totalMargin.top - totalMargin.bottom);
3029
31-
let flatData = $derived(data.lines.map((el) => el.data).flat());
30+
let flatData = $derived(lineChartData.lines.map((el) => el.data).flat());
3231
3332
let allYears = $derived(flatData.map((el) => el.x));
3433
@@ -85,15 +84,12 @@
8584
labelHovered,
8685
labelClicked,
8786
]);
88-
$inspect({ selectedLine });
8987
9088
let nothingSelected = $derived(selectedLine.every((item) => item == null));
9189
let selectedAreaCode = $state("E09000033");
9290
let englandMedian = $state("E06000040");
9391
let similarAreas = $state("E07000224");
9492
95-
let interactiveLines = $state(["primary", "secondary"]);
96-
9793
function handleClickOutside(event) {
9894
if (
9995
lineClicked != event.target.parentElement.dataset.id ||
@@ -131,8 +127,6 @@
131127
base: [colors.coral, colors.fuschia, colors.purple],
132128
});
133129
134-
let showAllData = true;
135-
136130
let lookupObj = $derived({
137131
[englandMedian]: colors.lightblue,
138132
[selectedAreaCode]: colors.teal,
@@ -146,7 +140,7 @@
146140
}
147141
148142
let dataArray = $derived(
149-
data.lines.map((el, i) => {
143+
lineChartData.lines.map((el, i) => {
150144
const tiers = [];
151145
el.areaCode == lineClicked
152146
? tiers.push("clicked")
@@ -261,30 +255,6 @@
261255
});
262256
</script>
263257
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-
288258
<div bind:clientWidth={svgWidth}>
289259
<svg
290260
onclick={handleClickOutside}

0 commit comments

Comments
 (0)