Skip to content

Commit 6cacabd

Browse files
author
Miles Hinchliffe
committed
Add meta data to testData.json and pass as prop
1 parent b6cb6df commit 6cacabd

File tree

4 files changed

+49
-99
lines changed

4 files changed

+49
-99
lines changed

src/lib/components/data-vis/table/Table.svelte

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
44
// import { areSameLanguages } from "@maptiler/sdk";
55
6-
let { componentNameProp = undefined, data = undefined } = $props();
6+
let {
7+
componentNameProp = undefined,
8+
data = undefined,
9+
metricDirection = undefined,
10+
metaData = undefined,
11+
} = $props();
712
813
let localCopyOfData = $state([...data]);
914
@@ -78,25 +83,6 @@
7883
}
7984
8085
const colorKey = Object.entries({ Good: 1, Ok: 0.5, Bad: 0 });
81-
82-
const metricInfo = {
83-
"Household waste recycling rate": {
84-
direction: "higher-is-better",
85-
explainer: "Percentage of household waste sent for recycling.",
86-
label: "Household recycling rate (%)",
87-
},
88-
"Recycling contamination rate": {
89-
direction: "lower-is-better",
90-
explainer:
91-
"Percentage of recycling that is contaminated and cannot be processed.",
92-
label: "Recycling contamination rate (%)",
93-
},
94-
"Residual household waste": {
95-
direction: "lower-is-better",
96-
explainer: "Amount of non-recyclable waste per household (kg/year).",
97-
label: "Household waste (kg)",
98-
},
99-
};
10086
</script>
10187

10288
{#snippet propNameAndValue(marginTW, paddingTW, text)}
@@ -108,8 +94,6 @@
10894
<div class="p-4">
10995
<h4>{componentNameProp} component</h4>
11096

111-
<br />
112-
11397
<div class="legend">
11498
<div>Colour key:</div>
11599
{#each colorKey as key}
@@ -126,10 +110,10 @@
126110
><tr>
127111
<th class="col-one-header">Area</th>
128112
{#each metrics as metric}
129-
<th title={metricInfo[metric].explainer}>
113+
<th title={metaData[metric].explainer}>
130114
<div class="header">
131115
<div class="header-top">
132-
<div class="metric">{metricInfo[metric].label}</div>
116+
<div class="metric">{metaData[metric].label}</div>
133117
<div class="sorting-button">
134118
<button
135119
onclick={() => {
@@ -146,7 +130,7 @@
146130
</div>
147131
</div>
148132
<div class="metric-explainer">
149-
{metricInfo[metric].explainer}
133+
{metaData[metric].explainer}
150134
</div>
151135
</div>
152136
</th>
@@ -158,7 +142,7 @@
158142
<tr>
159143
<td class="areas">{row["areaName"]}</td>
160144
{#each metrics as metric}
161-
{#if metricInfo[metric].direction === "higher-is-better"}
145+
{#if metaData[metric].direction === "Higher is better"}
162146
<td
163147
style="background-color: {normToColor(
164148
row[metric + '__normalised'],

src/routes/+layout.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ export const load: LayoutLoad = async (event) => {
108108

109109
let tableData = Object.values(groupedTableData);
110110

111+
let metaData = testData.metaData
112+
111113
return {
112114
metrics,
113115
areas,
@@ -123,5 +125,6 @@ export const load: LayoutLoad = async (event) => {
123125
componentDirectories,
124126
uiComponents,
125127
componentTree,
128+
metaData,
126129
};
127130
};

src/wrappers/components/data-vis/table/TableWrapper.svelte

Lines changed: 16 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -169,79 +169,23 @@
169169
value: data.tableData,
170170
},
171171
{
172-
name: "jsObjectProp",
173-
category: "Input props",
174-
value: [
175-
{
176-
name: "Pikachu",
177-
type: "Electric",
178-
color: "#fde047",
179-
},
180-
{
181-
name: "Charmander",
182-
type: "Fire",
183-
color: "#fca5a5",
184-
},
185-
{
186-
name: "Squirtle",
187-
type: "Water",
188-
color: "#93c5fd",
189-
},
190-
{
191-
name: "Bulbasaur",
192-
type: "Grass",
193-
color: "#86efac",
194-
},
195-
],
196-
description: {
197-
markdown: true,
198-
arr: [
199-
`This prop passes the selected a JS object to the component.`,
200-
`The object can be directly edited. A notification will alert the user is any edits create an invalid object`,
201-
],
202-
},
203-
},
204-
{
205-
name: "functionProp",
206-
category: "Fixed props",
207-
208-
isRequired: true,
209-
value: function (event, pokemon) {
210-
window.alert(
211-
`The ${this.name} function has been triggered. Open the 'Fixed props' panel to see updated values.`,
212-
);
213-
214-
this.functionElements.counter += 1;
215-
Object.keys(this.functionElements.dataset).forEach((el) => {
216-
this.functionElements.dataset[el] = event.currentTarget.dataset[el];
217-
});
218-
},
219-
functionElements: {
220-
dataset: { role: null, id: null },
221-
counter: 0,
222-
functionAsString: `function (event, pokemon) {
223-
window.alert(
224-
"The \${this.name} function has been triggered. Open the 'Fixed props' panel to see updated values.",
225-
);
226-
227-
this.functionElements.counter += 1;
228-
Object.keys(this.functionElements.dataset).forEach((el) => {
229-
this.functionElements.dataset[el] = event.currentTarget.dataset[el];
230-
});
231-
}`,
232-
},
233-
description: {
234-
markdown: true,
235-
arr: [
236-
`This prop passes a function to the ${pageName} component. It works slightly differently to other props.`,
237-
`Firstly, it is not editable via the UI.`,
238-
`Secondly, the code snippet on the left is not actually based on the value. Instead, it is example code based on the <code>functionElements.functionAsString</code> property, and is optional.`,
239-
,
240-
`For event functions, you can define your function so that it updates the <code>functionElements.counter</code> property each time it runs.`,
241-
`For event functions, you can also define your function so that it grabs data from its target, which are then stored in <code>functionElements.dataset</code> and displayed in the UI (trigger your event to see this in action).`,
242-
],
243-
},
172+
name: "metaData",
173+
category: "Data",
174+
visible: false,
175+
value: data.metaData,
244176
},
177+
// {
178+
// name: "metricDirection",
179+
// category: "Input props",
180+
// propType: "radio",
181+
// options: ["Higher is better", "Lower is better"],
182+
// description: {
183+
// markdown: true,
184+
// arr: [
185+
// `Select the metric direction. Is a higher or lower metric value good?`,
186+
// ],
187+
// },
188+
// },
245189
]),
246190
);
247191

static/data/testData.json

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52542,5 +52542,24 @@
5254252542
"E07000052": "West Dorset",
5254352543
"E07000191": "West Somerset",
5254452544
"E07000053": "Weymouth and Portland"
52545+
},
52546+
"metaData" : {
52547+
52548+
"Household waste recycling rate": {
52549+
"direction": "Higher is better",
52550+
"explainer": "Percentage of household waste sent for recycling.",
52551+
"label": "Household recycling rate (%)"
52552+
},
52553+
"Recycling contamination rate": {
52554+
"direction": "Lower is better",
52555+
"explainer":
52556+
"Percentage of recycling that is contaminated and cannot be processed.",
52557+
"label": "Recycling contamination rate (%)"
52558+
},
52559+
"Residual household waste": {
52560+
"direction": "Lower is better",
52561+
"explainer": "Amount of non-recyclable waste per household (kg/year).",
52562+
"label": "Household waste (kg)"
52563+
}
52564+
}
5254552565
}
52546-
}

0 commit comments

Comments
 (0)