Skip to content

Commit 5d4a688

Browse files
committed
move haloColor and interaction functions to LineChart
1 parent 3bb9bfe commit 5d4a688

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
onMouseLeave,
4141
onMouseMove,
4242
halo,
43-
chartBackgroundColor = "#d1d1d1",
43+
haloColor = "#d1aad1",
4444
// onClickMarker,
4545
// onMouseEnterMarker,
4646
// onMouseLeaveMarker,
@@ -125,7 +125,7 @@
125125
<path
126126
d={lineFunction(dataArray)}
127127
fill={pathFillColor}
128-
stroke={chartBackgroundColor}
128+
stroke={haloColor}
129129
stroke-width={pathStrokeWidth * 1.2}
130130
stroke-dasharray={pathStrokeDashArray}
131131
></path>

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@
5858
line[key] ?? defaultLineParams[tier][key],
5959
]),
6060
);
61-
return merged;
61+
return {
62+
...merged,
63+
dataId: line.areaCode, // should I just use areaCode in the component itself?
64+
dataArray: line.data, // should I just rename data in the original object so it's not repeated?
65+
};
6266
}
6367
</script>
6468
@@ -99,17 +103,8 @@
99103
defaultLineParams,
100104
tier,
101105
)}
102-
<Line
103-
dataArray={line.data}
104-
{...lineAttributes}
105-
dataId={line.areaCode}
106-
onClick={(event, dataArray, dataId) => (lineHovered = dataId)}
107-
onMouseEnter={(event, dataArray, dataId) => (lineHovered = dataId)}
108-
onMouseMove={(event, dataArray, dataId) => (lineHovered = dataId)}
109-
onMouseLeave={() => (lineHovered = null)}
110-
{...defaultLineParams}
111-
{chartBackgroundColor}
112-
/>
106+
{console.log(lineAttributes)}
107+
<Line {...lineAttributes} {chartBackgroundColor} />
113108
{/each}
114109
</g>
115110

src/routes/playground/create-a-reactive-line-chart/local-lib/LineChart.svelte

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@
6161
.curve(curveLinear),
6262
);
6363
64+
let onClick = (event, dataArray, dataId) => {
65+
lineHovered = dataId;
66+
};
67+
let onMouseEnter = (event, dataArray, dataId) => {
68+
lineHovered = dataId;
69+
};
70+
let onMouseMove = (event, dataArray, dataId) => {
71+
lineHovered = dataId;
72+
};
73+
let onMouseLeave = () => {
74+
lineHovered = null;
75+
};
76+
6477
let lineHovered = $state();
6578
let labelClicked = $state();
6679
let labelHovered = $state();
@@ -132,13 +145,10 @@
132145
);
133146
134147
let tieredLineParams = $derived({
135-
otherTier: {
136-
halo: false,
137-
},
148+
otherTier: {},
138149
invisibles: {
139150
listenForOnHoverEvents: true,
140151
pathStrokeWidth: 1,
141-
halo: false,
142152
},
143153
secondary: {
144154
"pointer-events": "none",
@@ -164,6 +174,11 @@
164174
xFunction: xFunction,
165175
yFunction: yFunction,
166176
areaFunction: areaFunction,
177+
onClick: onClick,
178+
onMouseEnter: onMouseEnter,
179+
onMouseMove: onMouseMove,
180+
onMouseLeave: onMouseLeave,
181+
haloColor: chartBackgroundColor,
167182
};
168183
169184
let defaultLineParams = Object.fromEntries(
@@ -202,15 +217,13 @@
202217
);
203218
204219
let globalTierRules = $derived({
205-
otherTier: {
206-
opacity: nothingSelected ? 1 : 0.5,
207-
},
220+
otherTier: {},
208221
invisibles: { opacity: 0 },
209222
secondary: {
210223
opacity: nothingSelected ? 1 : 0.5,
211224
},
212225
primary: {
213-
opacity: nothingSelected ? 1 : 0.5,
226+
opacity: nothingSelected ? 1 : 0.4,
214227
},
215228
hover: { opacity: 1 },
216229
});

0 commit comments

Comments
 (0)