Skip to content

Commit 756366f

Browse files
author
Miles Hinchliffe
committed
Merge branch 'main-check-merge' of github.com:communitiesuk/oflog_svelte_component_library into main-check-merge
2 parents 529b020 + 5af2f4c commit 756366f

File tree

99 files changed

+2524
-600
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+2524
-600
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ Thumbs.db
2121
vite.config.js.timestamp-*
2222
vite.config.ts.timestamp-*
2323

24-
*.mdc
24+
*.mdc
25+
.github/*.md

src/lib/assets/images/homepage-illustration.svg

Lines changed: 1 addition & 0 deletions
Loading

src/lib/assets/images/masthead-illustration.svg

Lines changed: 123 additions & 0 deletions
Loading

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
yFunction,
3131
lineEnding,
3232
dataId,
33-
onClickLine,
34-
onMouseEnterLine,
35-
onMouseLeaveLine,
33+
onClickSeries,
34+
onMouseEnterSeries,
35+
onMouseLeaveSeries,
3636
halo,
3737
chartBackgroundColor,
3838
invisibleStrokeWidth,
@@ -44,18 +44,20 @@
4444
// labelText,
4545
// labelColor,
4646
// labelTextColor,
47-
lineClicked,
48-
lineHovered,
47+
clickedSeries,
48+
hoveredSeries,
4949
activeMarkerId,
5050
series,
5151
y,
52+
id,
5253
x,
5354
markers,
5455
markerFill,
5556
markerRadius,
5657
markerShape,
5758
markerStroke,
5859
markerStrokeWidth,
60+
tier,
5961
} = $props();
6062
6163
let linePath = $derived(lineFunction(dataArray));
@@ -87,17 +89,15 @@
8789

8890
<g
8991
data-id={dataId}
90-
onclick={interactive ? (e) => onClickLine(e, dataArray, dataId) : null}
91-
onmouseenter={interactive
92-
? (e) => onMouseEnterLine(e, dataArray, dataId)
93-
: null}
94-
onmouseleave={interactive
95-
? (e) => onMouseLeaveLine(e, dataArray, dataId)
96-
: null}
92+
{id}
93+
onclick={interactive ? (e) => onClickSeries(dataId, tier) : null}
94+
onmouseenter={interactive ? (e) => onMouseEnterSeries(dataId, tier) : null}
95+
onmouseleave={interactive ? (e) => onMouseLeaveSeries(dataId, tier) : null}
9796
role="button"
9897
tabindex="0"
99-
onkeydown={(e) => e.key === "Enter" && onClickLine(e, dataArray)}
98+
onkeydown={(e) => e.key === "Enter" && onClickSeries(e, dataArray)}
10099
{opacity}
100+
pointer-events={interactive ? null : "none"}
101101
>
102102
{#if includeArea}
103103
<path d={areaFunction(dataArray)} fill={areaFillColor}></path>

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

Lines changed: 92 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -9,44 +9,85 @@
99
import Lines from "$lib/components/data-vis/line-chart/Lines.svelte";
1010
1111
let {
12-
getColor,
13-
tieredLineParams,
14-
colors,
15-
xFunction,
16-
yFunction,
17-
lineFunction,
18-
lineClicked,
19-
lineHovered,
20-
labelClicked = $bindable(),
21-
labelHovered = $bindable(),
22-
svgWidth = $bindable(500),
23-
activeMarkerId,
24-
onClickLine,
25-
onMouseEnterLine,
26-
onMouseLeaveLine,
27-
onClickLabel,
28-
onMouseEnterLabel,
29-
onMouseLeaveLabel,
12+
// Required
13+
series,
14+
y,
15+
x,
16+
lineChartData,
17+
18+
// ask
19+
xFunction = (number) => {
20+
return scaleLinear()
21+
.domain([2015, 2022])
22+
.range([0, svgWidth - paddingLeft - paddingRight])(number);
23+
},
24+
yFunction = (number) => {
25+
return scaleLinear()
26+
.domain([0, 100])
27+
.range([svgHeight - paddingTop - paddingBottom, 0])(number);
28+
},
29+
lineFunction = line()
30+
.x((d) => xFunction(d[x]))
31+
.y((d) => yFunction(d[y]))
32+
.curve(curveLinear),
33+
labelText,
34+
35+
basicLineParams, // contains functions
36+
tooltipContent, // snippet
37+
38+
onClickSeries = (series, tier) => {
39+
if (clickedSeries === dataId) {
40+
clickedSeries = null;
41+
} else {
42+
clickedSeries = series;
43+
clickedTier = tier;
44+
}
45+
},
46+
onMouseLeaveSeries = (series, tier) => {
47+
if (hoveredSeries === series) {
48+
hoveredSeries = null;
49+
hoveredTier = null;
50+
}
51+
},
52+
onMouseEnterSeries = (series, tier) => {
53+
if (hoveredSeries !== series) {
54+
hoveredSeries = series;
55+
hoveredTier = tier;
56+
}
57+
},
3058
onClickMarker,
3159
onMouseEnterMarker,
3260
onMouseLeaveMarker,
61+
62+
// Optional
63+
clickedSeries = $bindable(undefined),
64+
hoveredSeries = undefined,
65+
overrideLineParams = () => ({}),
66+
getLine = () => true,
67+
nothingSelected = true,
68+
svgWidth = $bindable(500),
3369
svgHeight = 500,
3470
paddingTop = 50,
3571
paddingBottom = 50,
3672
paddingLeft = 50,
3773
paddingRight = 150,
38-
lineChartData,
39-
interactiveLines,
40-
chartBackgroundColor,
41-
getLine,
42-
basicLineParams,
43-
overrideLineParams,
44-
nothingSelected = $bindable(),
45-
globalTierRules,
46-
labelText,
47-
series,
48-
y,
49-
x,
74+
activeMarkerId = undefined,
75+
chartBackgroundColor = "#f5f5f5",
76+
seriesLabels = $bindable(false),
77+
globalTierRules = {
78+
otherTier: {},
79+
secondary: {
80+
opacity: nothingSelected ? 1 : 0.5,
81+
},
82+
primary: {
83+
opacity: nothingSelected ? 1 : 0.4,
84+
},
85+
hover: { opacity: 1 },
86+
clicked: { opacity: 1 },
87+
},
88+
tieredLineParams = {
89+
all: {},
90+
},
5091
} = $props();
5192
5293
let chartWidth = $derived(svgWidth - paddingLeft - paddingRight);
@@ -60,19 +101,19 @@
60101
// );
61102
62103
let selectedLine = $derived([
63-
lineHovered,
64-
lineClicked,
65-
labelHovered,
66-
labelClicked,
104+
hoveredSeries,
105+
clickedSeries,
106+
hoveredSeries,
107+
clickedSeries,
67108
]);
68109
69110
function handleClickOutside(event) {
70111
if (
71-
lineClicked != event.target.parentElement.dataset.id ||
72-
(labelClicked && !event.target.closest('[id^="label"]'))
112+
clickedSeries &&
113+
!event.target.closest('[id^="line"]') &&
114+
!event.target.closest('[id^="label"]')
73115
) {
74-
labelClicked = null;
75-
lineClicked = null;
116+
clickedSeries = null;
76117
}
77118
}
78119
@@ -125,6 +166,12 @@
125166
return acc;
126167
}, {}),
127168
);
169+
170+
function hasShowLabel(objOfArrays) {
171+
return Object.values(objOfArrays).some((array) =>
172+
array.some((obj) => obj.showLabel === true),
173+
);
174+
}
128175
</script>
129176
130177
<div bind:clientWidth={svgWidth}>
@@ -144,20 +191,15 @@
144191
{chartWidth}
145192
{xFunction}
146193
{yFunction}
147-
bind:labelClicked
148-
bind:labelHovered
149-
lineHovered
150-
lineClicked
194+
{hoveredSeries}
195+
{clickedSeries}
151196
{chartHeight}
152197
{globalTierRules}
153198
{chartBackgroundColor}
154-
bind:nothingSelected
155-
{onMouseEnterLine}
156-
{onMouseLeaveLine}
157-
{onClickLine}
158-
{onClickLabel}
159-
{onMouseEnterLabel}
160-
{onMouseLeaveLabel}
199+
{nothingSelected}
200+
{onMouseEnterSeries}
201+
{onClickSeries}
202+
{onMouseLeaveSeries}
161203
{onClickMarker}
162204
{onMouseEnterMarker}
163205
{onMouseLeaveMarker}
@@ -166,6 +208,7 @@
166208
{series}
167209
{y}
168210
{x}
211+
{tooltipContent}
169212
></Lines>
170213
</g>
171214
<g data-role="y-axis">

0 commit comments

Comments
 (0)