Skip to content

Commit 1b7cc72

Browse files
committed
add interactive and shaded area examples
1 parent 5f21d3e commit 1b7cc72

File tree

1 file changed

+60
-6
lines changed

1 file changed

+60
-6
lines changed

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

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
return found ? { ...found, lines: found.lines.slice(0, 5) } : null;
1717
})();
1818
19+
const dataForOneLine = (() => {
20+
const found = data.dataInFormatForLineChart.find(
21+
(el) => el.metric === "Household waste recycling rate",
22+
);
23+
return found ? { ...found, lines: found.lines.slice(0, 1) } : null;
24+
})();
25+
1926
let accordionSnippetSections = [
2027
{
2128
id: "1",
@@ -29,17 +36,26 @@
2936
},
3037
{
3138
id: "3",
32-
heading: "3. Chart with different tiers",
39+
heading: "3. Line chart with different tiers",
3340
content: Example3,
3441
},
3542
{
3643
id: "4",
37-
heading: "4. Chart with interactive markers",
44+
heading: "4. Line chart with interactive markers",
3845
content: Example4,
3946
},
47+
{
48+
id: "5",
49+
heading: "5. Line chart with shaded area",
50+
content: Example5,
51+
},
4052
];
4153
4254
let activeMarkerId = $state();
55+
let clickedSeries = $state();
56+
let hoveredSeries = $state();
57+
let clickedTier = $state();
58+
let hoveredTier = $state();
4359
</script>
4460

4561
<div>
@@ -71,7 +87,33 @@
7187

7288
{#snippet Example2()}
7389
<div class="p-5 bg-white">
74-
<LineChart {lineChartData} x="x" y="y" series="areaCode"></LineChart>
90+
<LineChart
91+
{lineChartData}
92+
x="x"
93+
y="y"
94+
series="areaCode"
95+
basicLineParams={{ interactiveLines: true }}
96+
tieredLineParams={{
97+
all: {},
98+
hover: { pathStrokeColor: "pink" },
99+
clicked: {
100+
pathStrokeColor: "red",
101+
},
102+
}}
103+
getLine={(tier, el) => {
104+
if (tier === "all") {
105+
return true;
106+
}
107+
if (tier === "hover") {
108+
return [hoveredSeries].includes(el.areaCode);
109+
}
110+
if (tier === "clicked") {
111+
return [clickedSeries].includes(el.areaCode);
112+
}
113+
}}
114+
bind:clickedSeries
115+
bind:hoveredSeries
116+
></LineChart>
75117
</div>
76118
<CodeBlock code={codeBlocks.codeBlock1} language="svelte"></CodeBlock>
77119
{/snippet}
@@ -83,8 +125,8 @@
83125
x="x"
84126
y="y"
85127
series="areaCode"
86-
getLine={(key, el) => {
87-
if (key === "primary") {
128+
getLine={(tier, el) => {
129+
if (tier === "primary") {
88130
return ["E07000224"].includes(el.areaCode);
89131
} else return true;
90132
}}
@@ -94,7 +136,6 @@
94136
halo: true,
95137
pathStrokeWidth: 5,
96138
pathStrokeColor: "red",
97-
interactiveLines: true,
98139
},
99140
}}
100141
></LineChart>
@@ -119,3 +160,16 @@
119160
</div>
120161
<CodeBlock code={codeBlocks.codeBlock1} language="svelte"></CodeBlock>
121162
{/snippet}
163+
164+
{#snippet Example5()}
165+
<div class="p-5 bg-white">
166+
<LineChart
167+
lineChartData={dataForOneLine}
168+
x="x"
169+
y="y"
170+
series="areaCode"
171+
basicLineParams={{ includeArea: true, areaFillColor: "lightgrey" }}
172+
></LineChart>
173+
</div>
174+
<CodeBlock code={codeBlocks.codeBlock1} language="svelte"></CodeBlock>
175+
{/snippet}

0 commit comments

Comments
 (0)