|
16 | 16 | return found ? { ...found, lines: found.lines.slice(0, 5) } : null;
|
17 | 17 | })();
|
18 | 18 |
|
| 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 | +
|
19 | 26 | let accordionSnippetSections = [
|
20 | 27 | {
|
21 | 28 | id: "1",
|
|
29 | 36 | },
|
30 | 37 | {
|
31 | 38 | id: "3",
|
32 |
| - heading: "3. Chart with different tiers", |
| 39 | + heading: "3. Line chart with different tiers", |
33 | 40 | content: Example3,
|
34 | 41 | },
|
35 | 42 | {
|
36 | 43 | id: "4",
|
37 |
| - heading: "4. Chart with interactive markers", |
| 44 | + heading: "4. Line chart with interactive markers", |
38 | 45 | content: Example4,
|
39 | 46 | },
|
| 47 | + { |
| 48 | + id: "5", |
| 49 | + heading: "5. Line chart with shaded area", |
| 50 | + content: Example5, |
| 51 | + }, |
40 | 52 | ];
|
41 | 53 |
|
42 | 54 | let activeMarkerId = $state();
|
| 55 | + let clickedSeries = $state(); |
| 56 | + let hoveredSeries = $state(); |
| 57 | + let clickedTier = $state(); |
| 58 | + let hoveredTier = $state(); |
43 | 59 | </script>
|
44 | 60 |
|
45 | 61 | <div>
|
|
71 | 87 |
|
72 | 88 | {#snippet Example2()}
|
73 | 89 | <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> |
75 | 117 | </div>
|
76 | 118 | <CodeBlock code={codeBlocks.codeBlock1} language="svelte"></CodeBlock>
|
77 | 119 | {/snippet}
|
|
83 | 125 | x="x"
|
84 | 126 | y="y"
|
85 | 127 | series="areaCode"
|
86 |
| - getLine={(key, el) => { |
87 |
| - if (key === "primary") { |
| 128 | + getLine={(tier, el) => { |
| 129 | + if (tier === "primary") { |
88 | 130 | return ["E07000224"].includes(el.areaCode);
|
89 | 131 | } else return true;
|
90 | 132 | }}
|
|
94 | 136 | halo: true,
|
95 | 137 | pathStrokeWidth: 5,
|
96 | 138 | pathStrokeColor: "red",
|
97 |
| - interactiveLines: true, |
98 | 139 | },
|
99 | 140 | }}
|
100 | 141 | ></LineChart>
|
|
119 | 160 | </div>
|
120 | 161 | <CodeBlock code={codeBlocks.codeBlock1} language="svelte"></CodeBlock>
|
121 | 162 | {/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