Skip to content

Commit 9d56f64

Browse files
committed
pass through props to track interactions, reinstate areaFunction
1 parent 1928dfb commit 9d56f64

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

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

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,14 @@
1010
import ValueLabel from "./ValueLabel.svelte";
1111
1212
let {
13-
// Required
1413
series,
1514
y,
1615
x,
1716
lineChartData,
1817
1918
tooltipSnippet = undefined,
20-
tooltipContent = "tooltipContent",
19+
tooltipContent = "default",
2120
22-
// ask
2321
xFunction = (number) => {
2422
return scaleLinear()
2523
.domain([2015, 2022])
@@ -37,11 +35,14 @@
3735
labelText = "labelText",
3836
3937
onClickSeries = (series, tier) => {
40-
if (clickedSeries === dataId) {
38+
if (clickedSeries === series) {
4139
clickedSeries = null;
40+
hoveredSeries = null;
4241
} else {
4342
clickedSeries = series;
4443
clickedTier = tier;
44+
hoveredSeries = series;
45+
hoveredTier = tier;
4546
}
4647
},
4748
onMouseLeaveSeries = (series, tier) => {
@@ -91,10 +92,11 @@
9192
currentMousePosition = undefined,
9293
markerRect = undefined,
9394
clickedSeries = $bindable(undefined),
94-
hoveredSeries = undefined,
95-
hoveredTier = undefined,
95+
hoveredSeries = $bindable(undefined),
96+
hoveredTier = $bindable(undefined),
97+
clickedTier = $bindable(undefined),
9698
overrideLineParams = () => ({}),
97-
getLine = (key, el) => {
99+
getLine = (tier, el) => {
98100
return true;
99101
},
100102
nothingSelected = true,
@@ -142,13 +144,13 @@
142144
143145
let chartWidth = $derived(svgWidth - paddingLeft - paddingRight);
144146
let chartHeight = $derived(svgHeight - paddingTop - paddingBottom);
145-
// let areaFunction = $derived(
146-
// area()
147-
// .y0((d) => yFunction(0))
148-
// .x((d) => xFunction(d.x))
149-
// .y1((d) => yFunction(d.y))
150-
// .curve(curveLinear),
151-
// );
147+
let areaFunction = $derived(
148+
area()
149+
.y0((d) => yFunction(0))
150+
.x((d) => xFunction(d.x))
151+
.y1((d) => yFunction(d.y))
152+
.curve(curveLinear),
153+
);
152154
153155
let selectedLine = $derived([hoveredSeries, clickedSeries]);
154156
@@ -240,11 +242,14 @@
240242
{tieredDataObject}
241243
dataArray={lineChartData.lines}
242244
{lineFunction}
245+
{areaFunction}
243246
{chartWidth}
244247
{xFunction}
245248
{yFunction}
246249
{hoveredSeries}
247250
{clickedSeries}
251+
{clickedTier}
252+
{hoveredTier}
248253
{chartHeight}
249254
{globalTierRules}
250255
{chartBackgroundColor}
@@ -282,7 +287,7 @@
282287
{#if activeMarkerId}
283288
<ValueLabel
284289
{activeMarkerId}
285-
labelColor="grey"
290+
labelColor="lightgrey"
286291
labelTextColor="black"
287292
{tooltipContent}
288293
{xFunction}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@
1010
tieredDataObject,
1111
dataArray,
1212
lineFunction,
13+
areaFunction,
1314
chartWidth,
1415
xFunction,
1516
yFunction,
1617
clickedSeries,
1718
hoveredSeries,
19+
clickedTier,
20+
hoveredTier,
1821
chartHeight,
1922
globalTierRules,
2023
chartBackgroundColor = "#fafafa",
@@ -70,13 +73,16 @@
7073
{tier}
7174
{chartBackgroundColor}
7275
{lineFunction}
76+
{areaFunction}
7377
{xFunction}
7478
{yFunction}
7579
{onMouseEnterSeries}
7680
{onMouseLeaveSeries}
7781
{onClickSeries}
7882
{clickedSeries}
7983
{hoveredSeries}
84+
{clickedTier}
85+
{hoveredTier}
8086
{series}
8187
{y}
8288
{x}

0 commit comments

Comments
 (0)