-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdemo.svelte
More file actions
337 lines (309 loc) · 9.38 KB
/
demo.svelte
File metadata and controls
337 lines (309 loc) · 9.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<script lang="ts">
import {
setCatalogue,
setOptions,
translate,
setSiteResult,
getAst,
showToast,
markSiteClaimed,
removeFailedSite,
setFacetCounts,
clearSiteResults,
getHumanReadableQueryAsFormattedString,
type LensCatalogue,
} from "./src/index";
import catalogue from "./demo-catalogue.json";
const barChartBackgroundColors: string[] = ["#052c65", "#0d6efd"];
const barChartHoverColors: string[] = ["#000000"];
setOptions({
language: localStorage.getItem("language") || "en",
texts: {
"lens-dev-test-error": {
en: "Task failed successfully.",
de: "Aufgabe erfolgreich fehlgeschlagen.",
},
"lens-dev-test-info": {
en: "Task sent successfully.",
de: "Aufgabe erfolgreich gesendet.",
},
},
siteMappings: {
riverside: "Riverside",
summit: "Summit",
failingsite: "Failing Site",
},
chartOptions: {
gender: {
hintText: [
"This pie chart shows the proportion of males to females in our [population/data set]. The size of each section represents the percentage of individuals who identify as male or female.",
],
legendMapping: {
male: "Männlich",
female: "Weiblich",
other: "Divers",
},
},
},
tableOptions: {
headerData: [
{
title: "Standorte",
dataKey: "site",
},
{
title: "Patienten",
dataKey: "patients",
},
],
},
resultSummaryOptions: {
title: "Ergebnisse",
infoButtonText: "This is a tooltip",
dataTypes: [
{
title: "Standorte",
dataKey: "collections",
},
{
title: "Patienten",
dataKey: "patients",
},
],
},
});
setCatalogue(catalogue as LensCatalogue);
setFacetCounts({
"blood-group": {
"A+": 10,
"A-": 5,
"B+": 8,
"B-": 2,
},
diagnosis: {
C31: 40,
"C31.0": 20,
C41: 30,
"C41.0": 10,
},
});
window.addEventListener("lens-search-triggered", () => {
console.log("AST:", JSON.stringify(getAst()));
clearSiteResults();
setTimeout(() => {
markSiteClaimed("riverside");
markSiteClaimed("summit");
markSiteClaimed("failingsite");
for (const site of "ABCDEFGHIJ") {
markSiteClaimed("Site " + site);
}
}, 500);
setTimeout(() => {
setSiteResult("riverside", {
totals: {
patients: 9,
},
stratifiers: {
gender: {
male: 5,
female: 4,
other: 0,
},
diagnosis: {
C31: 40,
"C31.0": 20,
C41: 30,
"41.0": 10,
},
},
});
setSiteResult("summit", {
stratifiers: {
gender: {
male: 12,
female: 18,
other: 3,
},
diagnosis: {
C31: 40,
"C31.0": 20,
C41: 30,
"41.0": 10,
},
},
totals: {
patients: 33,
},
});
removeFailedSite("failingsite");
for (const site of "ABCDEFGHIJ") {
setSiteResult("Site " + site, {
totals: {},
stratifiers: {},
});
}
}, 1000);
});
function setLangAndReload(lang: string) {
localStorage.setItem("language", lang);
window.location.reload();
}
window.addEventListener("lens-negotiate-triggered", () => {
const body = encodeURIComponent(
getHumanReadableQueryAsFormattedString(),
);
const a = document.createElement("a");
a.href = `mailto:request@example.com?body=${body}`;
a.click();
});
</script>
<div id="main-wrapper">
<header class="card">
<h1>Lens Demo</h1>
<div>
<button
onclick={() =>
showToast(translate("lens-dev-test-error"), "error")}
>
Error toast test
</button>
<button
onclick={() =>
showToast(translate("lens-dev-test-info"), "info")}
>
Info toast test
</button>
<button onclick={() => setLangAndReload("en")}>🇬🇧</button>
<button onclick={() => setLangAndReload("de")}>🇩🇪</button>
</div>
</header>
<div id="search-wrapper">
<lens-search-bar-multiple></lens-search-bar-multiple>
<lens-query-explain-button></lens-query-explain-button>
<lens-query-spinner></lens-query-spinner>
<lens-search-button></lens-search-button>
</div>
<div id="catalogue-and-grid-wrapper">
<div id="catalogue" class="card">
<lens-catalogue toggle={{ collapsable: false }}></lens-catalogue>
</div>
<div id="main-grid">
<div id="result-summary" class="card">
<lens-result-summary></lens-result-summary>
<lens-search-modified-display></lens-search-modified-display>
</div>
<div id="result-table" class="card">
<lens-result-table
pageSize={10}
showRoundedTo={(value: number) => {
if (value < 10) return "Exact value";
if (value < 100)
return "Rounded to the nearest multiple of 10";
return "Rounded to the nearest multiple of 100";
}}
></lens-result-table>
<lens-negotiate-button></lens-negotiate-button>
</div>
<div class="card">
<lens-chart
title="Gender distribution"
dataKey="gender"
chartType="pie"
displayLegends={true}
enableSorting={true}
></lens-chart>
</div>
<div class="card">
<lens-chart
title="Diagnosis distribution"
dataKey="diagnosis"
chartType="bar"
xAxisTitle="ICD-10 Code"
yAxisTitle="Number of cases"
></lens-chart>
</div>
<div class="card">
<lens-chart
title="Diagnosis distribution (alternative)"
dataKey="diagnosis"
chartType="bar"
indexAxis="y"
scaleType="logarithmic"
xAxisTitle="Number of cases"
yAxisTitle="ICD-10 Code"
enableSorting={true}
backgroundColor={barChartBackgroundColors}
hoverBackgroundColor={barChartHoverColors}
></lens-chart>
</div>
</div>
</div>
<footer class="card">
<lens-about></lens-about>
</footer>
</div>
<lens-toast></lens-toast>
<style>
#main-wrapper {
padding: var(--gap-xs);
gap: var(--gap-xs);
background-color: #f8f8ff;
height: 100vh;
display: flex;
flex-direction: column;
}
.card {
background-color: var(--white);
border-radius: var(--border-radius-small);
border: 1px solid var(--lightest-gray);
padding: var(--gap-xs);
}
header {
display: flex;
justify-content: space-between;
align-items: center;
h1 {
color: var(--blue);
margin: 0;
}
}
#search-wrapper {
display: flex;
gap: var(--gap-xs);
align-items: center;
lens-search-bar-multiple {
flex: 1;
}
}
#catalogue-and-grid-wrapper {
flex: 1;
overflow: hidden;
display: flex;
gap: var(--gap-xs);
}
#catalogue {
flex: 1;
max-width: 30rem;
overflow-y: auto;
}
#main-grid {
flex: 1;
overflow-y: auto;
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: var(--gap-xs);
#result-summary {
grid-column: 1 / -1;
}
}
#result-table {
display: flex;
flex-direction: column;
gap: var(--gap-s);
}
footer {
display: flex;
justify-content: space-between;
align-items: center;
}
</style>