@genspectrum/dashboard-components 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +109 -0
  3. package/custom-elements.json +1587 -0
  4. package/dist/dashboard-components.js +7322 -0
  5. package/dist/dashboard-components.js.map +1 -0
  6. package/dist/genspectrum-components.d.ts +298 -0
  7. package/dist/style.css +2930 -0
  8. package/package.json +109 -0
  9. package/src/constants.ts +6 -0
  10. package/src/index.ts +1 -0
  11. package/src/lapisApi/ReferenceGenome.ts +30 -0
  12. package/src/lapisApi/__mockData__/referenceGenome.json +58 -0
  13. package/src/lapisApi/lapisApi.ts +99 -0
  14. package/src/lapisApi/lapisTypes.ts +51 -0
  15. package/src/operator/Dataset.ts +3 -0
  16. package/src/operator/DivisionOperator.spec.ts +27 -0
  17. package/src/operator/DivisionOperator.ts +60 -0
  18. package/src/operator/FetchAggregatedOperator.ts +44 -0
  19. package/src/operator/FetchInsertionsOperator.ts +24 -0
  20. package/src/operator/FetchSubstitutionsOrDeletionsOperator.ts +49 -0
  21. package/src/operator/FillMissingOperator.spec.ts +26 -0
  22. package/src/operator/FillMissingOperator.ts +30 -0
  23. package/src/operator/GroupByAndSumOperator.spec.ts +26 -0
  24. package/src/operator/GroupByAndSumOperator.ts +26 -0
  25. package/src/operator/GroupByOperator.spec.ts +43 -0
  26. package/src/operator/GroupByOperator.ts +32 -0
  27. package/src/operator/MapOperator.spec.ts +13 -0
  28. package/src/operator/MapOperator.ts +16 -0
  29. package/src/operator/MockOperator.spec.ts +11 -0
  30. package/src/operator/MockOperator.ts +12 -0
  31. package/src/operator/Operator.ts +5 -0
  32. package/src/operator/SlidingOperator.spec.ts +52 -0
  33. package/src/operator/SlidingOperator.ts +23 -0
  34. package/src/operator/SortOperator.spec.ts +13 -0
  35. package/src/operator/SortOperator.ts +16 -0
  36. package/src/preact/LapisUrlContext.ts +3 -0
  37. package/src/preact/ReferenceGenomeContext.ts +5 -0
  38. package/src/preact/components/SegmentSelector.tsx +62 -0
  39. package/src/preact/components/chart.stories.tsx +42 -0
  40. package/src/preact/components/chart.tsx +32 -0
  41. package/src/preact/components/checkbox-selector.stories.tsx +56 -0
  42. package/src/preact/components/checkbox-selector.tsx +46 -0
  43. package/src/preact/components/confidence-interval-selector.tsx +45 -0
  44. package/src/preact/components/csv-download-button.stories.tsx +25 -0
  45. package/src/preact/components/csv-download-button.tsx +51 -0
  46. package/src/preact/components/error-display.stories.tsx +22 -0
  47. package/src/preact/components/error-display.tsx +5 -0
  48. package/src/preact/components/headline.stories.tsx +29 -0
  49. package/src/preact/components/headline.tsx +16 -0
  50. package/src/preact/components/info.stories.tsx +22 -0
  51. package/src/preact/components/info.tsx +16 -0
  52. package/src/preact/components/loading-display.stories.tsx +20 -0
  53. package/src/preact/components/loading-display.tsx +5 -0
  54. package/src/preact/components/min-max-percent-slider.css +40 -0
  55. package/src/preact/components/min-max-range-slider.tsx +95 -0
  56. package/src/preact/components/mutation-type-selector.tsx +30 -0
  57. package/src/preact/components/no-data-display.stories.tsx +20 -0
  58. package/src/preact/components/no-data-display.tsx +5 -0
  59. package/src/preact/components/percent-intput.tsx +49 -0
  60. package/src/preact/components/proportion-selector-dropdown.stories.tsx +66 -0
  61. package/src/preact/components/proportion-selector-dropdown.tsx +33 -0
  62. package/src/preact/components/proportion-selector.stories.tsx +81 -0
  63. package/src/preact/components/proportion-selector.tsx +43 -0
  64. package/src/preact/components/scaling-selector.stories.tsx +25 -0
  65. package/src/preact/components/scaling-selector.tsx +36 -0
  66. package/src/preact/components/select.stories.tsx +42 -0
  67. package/src/preact/components/select.tsx +21 -0
  68. package/src/preact/components/table.stories.tsx +24 -0
  69. package/src/preact/components/table.tsx +51 -0
  70. package/src/preact/components/tabs.stories.tsx +60 -0
  71. package/src/preact/components/tabs.tsx +49 -0
  72. package/src/preact/dateRangeSelector/date-range-selector.stories.tsx +32 -0
  73. package/src/preact/dateRangeSelector/date-range-selector.tsx +228 -0
  74. package/src/preact/dateRangeSelector/dateConversion.ts +8 -0
  75. package/src/preact/locationFilter/__mockData__/aggregated.json +775 -0
  76. package/src/preact/locationFilter/fetchAutocompletionList.spec.ts +36 -0
  77. package/src/preact/locationFilter/fetchAutocompletionList.ts +43 -0
  78. package/src/preact/locationFilter/location-filter.stories.tsx +50 -0
  79. package/src/preact/locationFilter/location-filter.tsx +112 -0
  80. package/src/preact/mutationComparison/__mockData__/nucleotideMutationsOtherVariant.json +295 -0
  81. package/src/preact/mutationComparison/__mockData__/nucleotideMutationsSomeVariant.json +304 -0
  82. package/src/preact/mutationComparison/fetchMutationData.spec.ts +118 -0
  83. package/src/preact/mutationComparison/getMutationComparisonTableData.spec.ts +125 -0
  84. package/src/preact/mutationComparison/getMutationComparisonTableData.ts +40 -0
  85. package/src/preact/mutationComparison/mutation-comparison-table.tsx +43 -0
  86. package/src/preact/mutationComparison/mutation-comparison-venn.tsx +122 -0
  87. package/src/preact/mutationComparison/mutation-comparison.stories.tsx +152 -0
  88. package/src/preact/mutationComparison/mutation-comparison.tsx +179 -0
  89. package/src/preact/mutationComparison/queryMutationData.ts +53 -0
  90. package/src/preact/mutationFilter/mutation-filter.stories.tsx +164 -0
  91. package/src/preact/mutationFilter/mutation-filter.tsx +268 -0
  92. package/src/preact/mutationFilter/parseAndValidateMutation.ts +54 -0
  93. package/src/preact/mutationFilter/parseMutation.spec.ts +150 -0
  94. package/src/preact/mutationFilter/sequenceTypeFromSegment.spec.ts +66 -0
  95. package/src/preact/mutationFilter/sequenceTypeFromSegment.ts +20 -0
  96. package/src/preact/mutations/__mockData__/nucleotideInsertions.json +252 -0
  97. package/src/preact/mutations/__mockData__/nucleotideMutations.json +880 -0
  98. package/src/preact/mutations/getInsertionsTableData.spec.ts +36 -0
  99. package/src/preact/mutations/getInsertionsTableData.ts +10 -0
  100. package/src/preact/mutations/getMutationsGridData.spec.ts +135 -0
  101. package/src/preact/mutations/getMutationsGridData.ts +92 -0
  102. package/src/preact/mutations/getMutationsTableData.spec.ts +94 -0
  103. package/src/preact/mutations/getMutationsTableData.ts +17 -0
  104. package/src/preact/mutations/mutations-grid.tsx +84 -0
  105. package/src/preact/mutations/mutations-insertions-table.tsx +33 -0
  106. package/src/preact/mutations/mutations-table.tsx +47 -0
  107. package/src/preact/mutations/mutations.stories.tsx +95 -0
  108. package/src/preact/mutations/mutations.tsx +192 -0
  109. package/src/preact/mutations/queryMutations.ts +55 -0
  110. package/src/preact/prevalenceOverTime/__mockData__/denominator.json +1700 -0
  111. package/src/preact/prevalenceOverTime/__mockData__/denominatorOneVariant.json +608 -0
  112. package/src/preact/prevalenceOverTime/__mockData__/numeratorEG.json +1560 -0
  113. package/src/preact/prevalenceOverTime/__mockData__/numeratorJN1.json +592 -0
  114. package/src/preact/prevalenceOverTime/__mockData__/numeratorOneVariant.json +604 -0
  115. package/src/preact/prevalenceOverTime/getPrevalenceOverTimeTableData.spec.ts +67 -0
  116. package/src/preact/prevalenceOverTime/getPrevalenceOverTimeTableData.ts +18 -0
  117. package/src/preact/prevalenceOverTime/prevalence-over-time-bar-chart.tsx +105 -0
  118. package/src/preact/prevalenceOverTime/prevalence-over-time-bubble-chart.tsx +86 -0
  119. package/src/preact/prevalenceOverTime/prevalence-over-time-line-chart.tsx +141 -0
  120. package/src/preact/prevalenceOverTime/prevalence-over-time-table.tsx +46 -0
  121. package/src/preact/prevalenceOverTime/prevalence-over-time.stories.tsx +165 -0
  122. package/src/preact/prevalenceOverTime/prevalence-over-time.tsx +202 -0
  123. package/src/preact/relativeGrowthAdvantage/__mockData__/denominator.json +376 -0
  124. package/src/preact/relativeGrowthAdvantage/__mockData__/numerator.json +332 -0
  125. package/src/preact/relativeGrowthAdvantage/relative-growth-advantage-chart.tsx +138 -0
  126. package/src/preact/relativeGrowthAdvantage/relative-growth-advantage.stories.tsx +71 -0
  127. package/src/preact/relativeGrowthAdvantage/relative-growth-advantage.tsx +136 -0
  128. package/src/preact/shared/charts/LogitScale.ts +48 -0
  129. package/src/preact/shared/charts/colors.ts +26 -0
  130. package/src/preact/shared/charts/confideceInterval.ts +29 -0
  131. package/src/preact/shared/charts/getYAxisScale.ts +16 -0
  132. package/src/preact/shared/charts/scales.ts +16 -0
  133. package/src/preact/shared/icons/DeleteIcon.tsx +17 -0
  134. package/src/preact/shared/sort/sortInsertions.spec.ts +47 -0
  135. package/src/preact/shared/sort/sortInsertions.ts +21 -0
  136. package/src/preact/shared/sort/sortMutationPositions.spec.ts +31 -0
  137. package/src/preact/shared/sort/sortMutationPositions.ts +14 -0
  138. package/src/preact/shared/sort/sortSubstitutionsAndDeletions.spec.ts +47 -0
  139. package/src/preact/shared/sort/sortSubstitutionsAndDeletions.ts +17 -0
  140. package/src/preact/shared/table/formatProportion.ts +3 -0
  141. package/src/preact/textInput/__mockData__/aggregated_hosts.json +24 -0
  142. package/src/preact/textInput/fetchAutocompleteList.ts +9 -0
  143. package/src/preact/textInput/text-input.stories.tsx +49 -0
  144. package/src/preact/textInput/text-input.tsx +73 -0
  145. package/src/preact/useQuery.ts +27 -0
  146. package/src/query/queryInsertions.ts +14 -0
  147. package/src/query/queryPrevalenceOverTime.ts +126 -0
  148. package/src/query/queryRelativeGrowthAdvantage.ts +131 -0
  149. package/src/query/querySubstitutionsOrDeletions.ts +19 -0
  150. package/src/styles/tailwind.css +3 -0
  151. package/src/styles/tailwind.d.ts +3 -0
  152. package/src/types.ts +23 -0
  153. package/src/utils/mutations.spec.ts +64 -0
  154. package/src/utils/mutations.ts +165 -0
  155. package/src/utils/temporal.spec.ts +97 -0
  156. package/src/utils/temporal.ts +348 -0
  157. package/src/utils/test-utils.ts +5 -0
  158. package/src/utils/type-utils.ts +15 -0
  159. package/src/utils/utils.spec.ts +16 -0
  160. package/src/utils/utils.ts +38 -0
  161. package/src/web-components/PreactLitAdapter.tsx +62 -0
  162. package/src/web-components/PreactLitAdapterWithGridJsStyles.tsx +12 -0
  163. package/src/web-components/app.ts +51 -0
  164. package/src/web-components/display/index.ts +4 -0
  165. package/src/web-components/display/mutation-comparison-component.stories.ts +138 -0
  166. package/src/web-components/display/mutation-comparison-component.tsx +31 -0
  167. package/src/web-components/display/mutations-component.stories.ts +107 -0
  168. package/src/web-components/display/mutations-component.tsx +27 -0
  169. package/src/web-components/display/prevalence-over-time-component.stories.ts +205 -0
  170. package/src/web-components/display/prevalence-over-time-component.tsx +46 -0
  171. package/src/web-components/display/relative-growth-advantage-component.stories.ts +89 -0
  172. package/src/web-components/display/relative-growth-advantage-component.tsx +37 -0
  173. package/src/web-components/index.ts +3 -0
  174. package/src/web-components/input/date-range-selector-component.stories.ts +53 -0
  175. package/src/web-components/input/date-range-selector-component.tsx +33 -0
  176. package/src/web-components/input/index.ts +4 -0
  177. package/src/web-components/input/location-filter-component.stories.ts +184 -0
  178. package/src/web-components/input/location-filter-component.tsx +68 -0
  179. package/src/web-components/input/location-filter.mdx +25 -0
  180. package/src/web-components/input/mutation-filter-component.stories.ts +97 -0
  181. package/src/web-components/input/mutation-filter-component.tsx +27 -0
  182. package/src/web-components/input/text-input-component.stories.ts +92 -0
  183. package/src/web-components/input/text-input-component.tsx +30 -0
  184. package/src/web-components/lapis-context.ts +3 -0
  185. package/src/web-components/reference-genome-context.ts +5 -0
  186. package/src/web-components/withinShadowRoot.story.ts +34 -0
@@ -0,0 +1,332 @@
1
+ {
2
+ "errors": [],
3
+ "info": {
4
+ "apiVersion": 1,
5
+ "dataVersion": 1709685650,
6
+ "deprecationDate": null,
7
+ "deprecationInfo": null,
8
+ "acknowledgement": null
9
+ },
10
+ "data": [
11
+ {
12
+ "date": "2021-01-30",
13
+ "count": 72
14
+ },
15
+ {
16
+ "date": "2021-01-31",
17
+ "count": 53
18
+ },
19
+ {
20
+ "date": "2021-02-01",
21
+ "count": 153
22
+ },
23
+ {
24
+ "date": "2021-02-02",
25
+ "count": 82
26
+ },
27
+ {
28
+ "date": "2021-02-03",
29
+ "count": 80
30
+ },
31
+ {
32
+ "date": "2021-02-04",
33
+ "count": 75
34
+ },
35
+ {
36
+ "date": "2021-02-05",
37
+ "count": 119
38
+ },
39
+ {
40
+ "date": "2021-02-06",
41
+ "count": 66
42
+ },
43
+ {
44
+ "date": "2021-02-07",
45
+ "count": 51
46
+ },
47
+ {
48
+ "date": "2021-02-08",
49
+ "count": 73
50
+ },
51
+ {
52
+ "date": "2021-02-09",
53
+ "count": 66
54
+ },
55
+ {
56
+ "date": "2021-02-10",
57
+ "count": 55
58
+ },
59
+ {
60
+ "date": "2021-02-11",
61
+ "count": 75
62
+ },
63
+ {
64
+ "date": "2021-02-12",
65
+ "count": 69
66
+ },
67
+ {
68
+ "date": "2021-02-13",
69
+ "count": 75
70
+ },
71
+ {
72
+ "date": "2021-02-14",
73
+ "count": 47
74
+ },
75
+ {
76
+ "date": "2021-02-15",
77
+ "count": 67
78
+ },
79
+ {
80
+ "date": "2021-02-16",
81
+ "count": 66
82
+ },
83
+ {
84
+ "date": "2021-02-17",
85
+ "count": 82
86
+ },
87
+ {
88
+ "date": "2021-02-18",
89
+ "count": 29
90
+ },
91
+ {
92
+ "date": "2021-02-19",
93
+ "count": 64
94
+ },
95
+ {
96
+ "date": "2021-02-20",
97
+ "count": 46
98
+ },
99
+ {
100
+ "date": "2021-02-21",
101
+ "count": 79
102
+ },
103
+ {
104
+ "date": "2021-02-22",
105
+ "count": 108
106
+ },
107
+ {
108
+ "date": "2021-02-23",
109
+ "count": 109
110
+ },
111
+ {
112
+ "date": "2021-02-24",
113
+ "count": 80
114
+ },
115
+ {
116
+ "date": "2021-02-25",
117
+ "count": 60
118
+ },
119
+ {
120
+ "date": "2021-02-26",
121
+ "count": 34
122
+ },
123
+ {
124
+ "date": "2021-02-27",
125
+ "count": 51
126
+ },
127
+ {
128
+ "date": "2021-02-28",
129
+ "count": 44
130
+ },
131
+ {
132
+ "date": "2021-03-01",
133
+ "count": 112
134
+ },
135
+ {
136
+ "date": "2020-12-07",
137
+ "count": 2
138
+ },
139
+ {
140
+ "date": "2020-12-11",
141
+ "count": 1
142
+ },
143
+ {
144
+ "date": "2020-12-12",
145
+ "count": 2
146
+ },
147
+ {
148
+ "date": "2020-12-13",
149
+ "count": 1
150
+ },
151
+ {
152
+ "date": "2020-12-14",
153
+ "count": 1
154
+ },
155
+ {
156
+ "date": "2020-12-16",
157
+ "count": 5
158
+ },
159
+ {
160
+ "date": "2020-12-17",
161
+ "count": 1
162
+ },
163
+ {
164
+ "date": "2020-12-18",
165
+ "count": 1
166
+ },
167
+ {
168
+ "date": "2020-12-19",
169
+ "count": 1
170
+ },
171
+ {
172
+ "date": "2020-12-21",
173
+ "count": 6
174
+ },
175
+ {
176
+ "date": "2020-12-22",
177
+ "count": 3
178
+ },
179
+ {
180
+ "date": "2020-12-23",
181
+ "count": 1
182
+ },
183
+ {
184
+ "date": "2020-12-24",
185
+ "count": 5
186
+ },
187
+ {
188
+ "date": "2020-12-25",
189
+ "count": 2
190
+ },
191
+ {
192
+ "date": "2020-12-26",
193
+ "count": 10
194
+ },
195
+ {
196
+ "date": "2020-12-27",
197
+ "count": 3
198
+ },
199
+ {
200
+ "date": "2020-12-28",
201
+ "count": 9
202
+ },
203
+ {
204
+ "date": "2020-12-29",
205
+ "count": 9
206
+ },
207
+ {
208
+ "date": "2020-12-30",
209
+ "count": 15
210
+ },
211
+ {
212
+ "date": "2020-12-31",
213
+ "count": 9
214
+ },
215
+ {
216
+ "date": "2021-01-01",
217
+ "count": 39
218
+ },
219
+ {
220
+ "date": "2021-01-02",
221
+ "count": 8
222
+ },
223
+ {
224
+ "date": "2021-01-03",
225
+ "count": 14
226
+ },
227
+ {
228
+ "date": "2021-01-04",
229
+ "count": 21
230
+ },
231
+ {
232
+ "date": "2021-01-05",
233
+ "count": 22
234
+ },
235
+ {
236
+ "date": "2021-01-06",
237
+ "count": 13
238
+ },
239
+ {
240
+ "date": "2021-01-07",
241
+ "count": 15
242
+ },
243
+ {
244
+ "date": "2021-01-08",
245
+ "count": 22
246
+ },
247
+ {
248
+ "date": "2021-01-09",
249
+ "count": 38
250
+ },
251
+ {
252
+ "date": "2021-01-10",
253
+ "count": 50
254
+ },
255
+ {
256
+ "date": "2021-01-11",
257
+ "count": 34
258
+ },
259
+ {
260
+ "date": "2021-01-12",
261
+ "count": 18
262
+ },
263
+ {
264
+ "date": "2021-01-13",
265
+ "count": 16
266
+ },
267
+ {
268
+ "date": "2021-01-14",
269
+ "count": 15
270
+ },
271
+ {
272
+ "date": "2021-01-15",
273
+ "count": 30
274
+ },
275
+ {
276
+ "date": "2021-01-16",
277
+ "count": 17
278
+ },
279
+ {
280
+ "date": "2021-01-17",
281
+ "count": 18
282
+ },
283
+ {
284
+ "date": "2021-01-18",
285
+ "count": 36
286
+ },
287
+ {
288
+ "date": "2021-01-19",
289
+ "count": 44
290
+ },
291
+ {
292
+ "date": "2021-01-20",
293
+ "count": 42
294
+ },
295
+ {
296
+ "date": "2021-01-21",
297
+ "count": 30
298
+ },
299
+ {
300
+ "date": "2021-01-22",
301
+ "count": 28
302
+ },
303
+ {
304
+ "date": "2021-01-23",
305
+ "count": 31
306
+ },
307
+ {
308
+ "date": "2021-01-24",
309
+ "count": 39
310
+ },
311
+ {
312
+ "date": "2021-01-25",
313
+ "count": 59
314
+ },
315
+ {
316
+ "date": "2021-01-26",
317
+ "count": 72
318
+ },
319
+ {
320
+ "date": "2021-01-27",
321
+ "count": 85
322
+ },
323
+ {
324
+ "date": "2021-01-28",
325
+ "count": 58
326
+ },
327
+ {
328
+ "date": "2021-01-29",
329
+ "count": 93
330
+ }
331
+ ]
332
+ }
@@ -0,0 +1,138 @@
1
+ import { Chart, type ChartConfiguration, registerables, type TooltipItem } from 'chart.js';
2
+
3
+ import { type YearMonthDay } from '../../utils/temporal';
4
+ import GsChart from '../components/chart';
5
+ import { LogitScale } from '../shared/charts/LogitScale';
6
+ import { singleGraphColorRGBByName } from '../shared/charts/colors';
7
+ import { confidenceIntervalDataLabel } from '../shared/charts/confideceInterval';
8
+ import { getYAxisScale, type ScaleType } from '../shared/charts/getYAxisScale';
9
+
10
+ interface RelativeGrowthAdvantageChartData {
11
+ t: YearMonthDay[];
12
+ proportion: number[];
13
+ ciLower: number[];
14
+ ciUpper: number[];
15
+ observed: number[];
16
+ params: {
17
+ fd: {
18
+ value: number;
19
+ ciLower: number;
20
+ ciUpper: number;
21
+ };
22
+ };
23
+ }
24
+
25
+ interface RelativeGrowthAdvantageChartProps {
26
+ data: RelativeGrowthAdvantageChartData;
27
+ yAxisScaleType: ScaleType;
28
+ }
29
+
30
+ Chart.register(...registerables, LogitScale);
31
+
32
+ const RelativeGrowthAdvantageChart = ({ data, yAxisScaleType }: RelativeGrowthAdvantageChartProps) => {
33
+ const config: ChartConfiguration = {
34
+ type: 'line',
35
+ data: {
36
+ labels: data.t,
37
+ datasets: datasets(data),
38
+ },
39
+ options: {
40
+ animation: false,
41
+ scales: {
42
+ y: getYAxisScale(yAxisScaleType),
43
+ },
44
+ plugins: {
45
+ legend: {
46
+ display: false,
47
+ },
48
+ tooltip: tooltip(),
49
+ },
50
+ },
51
+ };
52
+
53
+ return (
54
+ <>
55
+ <GsChart configuration={config} />
56
+ <div>
57
+ Advantage: {(data.params.fd.value * 100).toFixed(2)}% ({(data.params.fd.ciLower * 100).toFixed(2)}% -{' '}
58
+ {(data.params.fd.ciUpper * 100).toFixed(2)}%)
59
+ </div>
60
+ </>
61
+ );
62
+ };
63
+
64
+ const datasets = (data: RelativeGrowthAdvantageChartData) => {
65
+ return [
66
+ {
67
+ type: 'line' as const,
68
+ label: 'Prevalence',
69
+ data: data.proportion,
70
+ borderWidth: 1,
71
+ pointRadius: 0,
72
+ borderColor: singleGraphColorRGBByName('indigo'),
73
+ backgroundColor: singleGraphColorRGBByName('indigo'),
74
+ },
75
+ {
76
+ type: 'line' as const,
77
+ label: 'CI Lower',
78
+ data: data.ciLower,
79
+ borderWidth: 1,
80
+ pointRadius: 0,
81
+ fill: '+1',
82
+ backgroundColor: singleGraphColorRGBByName('indigo', 0.3),
83
+ },
84
+ {
85
+ type: 'line' as const,
86
+ label: 'CI Upper',
87
+ data: data.ciUpper,
88
+ borderWidth: 1,
89
+ pointRadius: 0,
90
+ fill: '-1',
91
+ backgroundColor: singleGraphColorRGBByName('indigo', 0.3),
92
+ },
93
+ {
94
+ type: 'scatter' as const,
95
+ label: 'Observed',
96
+ data: data.observed,
97
+ pointBackgroundColor: singleGraphColorRGBByName('green'),
98
+ pointRadius: 2,
99
+ },
100
+ ];
101
+ };
102
+
103
+ const tooltip = () => {
104
+ return {
105
+ mode: 'index' as const,
106
+ intersect: false,
107
+ filter: ({ datasetIndex }: TooltipItem<'line'>) => {
108
+ return datasetIndex !== 1 && datasetIndex !== 2;
109
+ },
110
+ callbacks: {
111
+ label: (context: TooltipItem<'line'>) => {
112
+ switch (context.datasetIndex) {
113
+ case 0: {
114
+ const value = context.dataset.data[context.dataIndex];
115
+ const ciLower = context.dataset.data[context.dataIndex + 1];
116
+ const ciUpper = context.dataset.data[context.dataIndex + 2];
117
+ if (typeof value !== 'number' || typeof ciLower !== 'number' || typeof ciUpper !== 'number') {
118
+ return '';
119
+ }
120
+ return confidenceIntervalDataLabel(value, ciLower, ciUpper, context.dataset.label);
121
+ }
122
+
123
+ case 3: {
124
+ const value = context.dataset.data[context.dataIndex];
125
+ if (typeof value !== 'number') {
126
+ return '';
127
+ }
128
+ return `Observed: ${value.toFixed(3)}`;
129
+ }
130
+ default:
131
+ return '';
132
+ }
133
+ },
134
+ },
135
+ };
136
+ };
137
+
138
+ export default RelativeGrowthAdvantageChart;
@@ -0,0 +1,71 @@
1
+ import denominator from './__mockData__/denominator.json';
2
+ import numerator from './__mockData__/numerator.json';
3
+ import { RelativeGrowthAdvantage, type RelativeGrowthAdvantageProps } from './relative-growth-advantage';
4
+ import { AGGREGATED_ENDPOINT, LAPIS_URL } from '../../constants';
5
+ import { LapisUrlContext } from '../LapisUrlContext';
6
+
7
+ export default {
8
+ title: 'Visualization/RelativeGrowthAdvantage',
9
+ component: RelativeGrowthAdvantage,
10
+ parameters: {
11
+ fetchMock: {},
12
+ },
13
+ };
14
+
15
+ export const Primary = {
16
+ render: (args: RelativeGrowthAdvantageProps) => (
17
+ <LapisUrlContext.Provider value={LAPIS_URL}>
18
+ <RelativeGrowthAdvantage
19
+ numerator={args.numerator}
20
+ denominator={args.denominator}
21
+ generationTime={args.generationTime}
22
+ views={args.views}
23
+ />
24
+ </LapisUrlContext.Provider>
25
+ ),
26
+ args: {
27
+ numerator: { country: 'Switzerland', pangoLineage: 'B.1.1.7', dateFrom: '2020-12-01', dateTo: '2021-03-01' },
28
+ denominator: { country: 'Switzerland', dateFrom: '2020-12-01', dateTo: '2021-03-01' },
29
+ generationTime: 7,
30
+ views: ['line'],
31
+ },
32
+ parameters: {
33
+ fetchMock: {
34
+ mocks: [
35
+ {
36
+ matcher: {
37
+ name: 'numerator',
38
+ url: AGGREGATED_ENDPOINT,
39
+ body: {
40
+ country: 'Switzerland',
41
+ pangoLineage: 'B.1.1.7',
42
+ dateFrom: '2020-12-01',
43
+ dateTo: '2021-03-01',
44
+ fields: ['date'],
45
+ },
46
+ },
47
+ response: {
48
+ status: 200,
49
+ body: numerator,
50
+ },
51
+ },
52
+ {
53
+ matcher: {
54
+ name: 'denominator',
55
+ url: AGGREGATED_ENDPOINT,
56
+ body: {
57
+ country: 'Switzerland',
58
+ dateFrom: '2020-12-01',
59
+ dateTo: '2021-03-01',
60
+ fields: ['date'],
61
+ },
62
+ },
63
+ response: {
64
+ status: 200,
65
+ body: denominator,
66
+ },
67
+ },
68
+ ],
69
+ },
70
+ },
71
+ };
@@ -0,0 +1,136 @@
1
+ import { type FunctionComponent } from 'preact';
2
+ import { useContext, useState } from 'preact/hooks';
3
+
4
+ import RelativeGrowthAdvantageChart from './relative-growth-advantage-chart';
5
+ import {
6
+ queryRelativeGrowthAdvantage,
7
+ type RelativeGrowthAdvantageData,
8
+ } from '../../query/queryRelativeGrowthAdvantage';
9
+ import { type LapisFilter } from '../../types';
10
+ import { LapisUrlContext } from '../LapisUrlContext';
11
+ import { ErrorDisplay } from '../components/error-display';
12
+ import Headline from '../components/headline';
13
+ import Info from '../components/info';
14
+ import { LoadingDisplay } from '../components/loading-display';
15
+ import { NoDataDisplay } from '../components/no-data-display';
16
+ import { ScalingSelector } from '../components/scaling-selector';
17
+ import Tabs from '../components/tabs';
18
+ import { type ScaleType } from '../shared/charts/getYAxisScale';
19
+ import { useQuery } from '../useQuery';
20
+
21
+ export type View = 'line';
22
+
23
+ export interface RelativeGrowthAdvantageProps {
24
+ numerator: LapisFilter;
25
+ denominator: LapisFilter;
26
+ generationTime: number;
27
+ views: View[];
28
+ }
29
+
30
+ export const RelativeGrowthAdvantage: FunctionComponent<RelativeGrowthAdvantageProps> = ({
31
+ numerator,
32
+ denominator,
33
+ generationTime,
34
+ views,
35
+ }) => {
36
+ const lapis = useContext(LapisUrlContext);
37
+ const [yAxisScaleType, setYAxisScaleType] = useState<ScaleType>('linear');
38
+
39
+ const { data, error, isLoading } = useQuery(
40
+ () => queryRelativeGrowthAdvantage(numerator, denominator, generationTime, lapis),
41
+ [lapis, numerator, denominator, generationTime, views],
42
+ );
43
+
44
+ const headline = 'Relative growth advantage';
45
+ if (isLoading) {
46
+ return (
47
+ <Headline heading={headline}>
48
+ <LoadingDisplay />
49
+ </Headline>
50
+ );
51
+ }
52
+
53
+ if (error !== null) {
54
+ return (
55
+ <Headline heading={headline}>
56
+ <ErrorDisplay error={error} />
57
+ </Headline>
58
+ );
59
+ }
60
+
61
+ if (data === null) {
62
+ return (
63
+ <Headline heading={headline}>
64
+ <NoDataDisplay />
65
+ </Headline>
66
+ );
67
+ }
68
+
69
+ return (
70
+ <Headline heading={headline}>
71
+ <RelativeGrowthAdvantageTabs
72
+ data={data}
73
+ yAxisScaleType={yAxisScaleType}
74
+ setYAxisScaleType={setYAxisScaleType}
75
+ views={views}
76
+ />
77
+ </Headline>
78
+ );
79
+ };
80
+
81
+ type RelativeGrowthAdvantageTabsProps = {
82
+ data: NonNullable<RelativeGrowthAdvantageData>;
83
+ yAxisScaleType: ScaleType;
84
+ setYAxisScaleType: (scaleType: ScaleType) => void;
85
+ views: View[];
86
+ };
87
+
88
+ const RelativeGrowthAdvantageTabs: FunctionComponent<RelativeGrowthAdvantageTabsProps> = ({
89
+ data,
90
+ yAxisScaleType,
91
+ setYAxisScaleType,
92
+ views,
93
+ }) => {
94
+ const getTab = (view: View) => {
95
+ switch (view) {
96
+ case 'line':
97
+ return {
98
+ title: 'Line',
99
+ content: (
100
+ <RelativeGrowthAdvantageChart
101
+ data={{
102
+ ...data.estimatedProportions,
103
+ observed: data.observedProportions,
104
+ params: data.params,
105
+ }}
106
+ yAxisScaleType={yAxisScaleType}
107
+ />
108
+ ),
109
+ };
110
+ }
111
+ };
112
+
113
+ const tabs = views.map((view) => getTab(view));
114
+ const toolbar = () => (
115
+ <RelativeGrowthAdvantageToolbar yAxisScaleType={yAxisScaleType} setYAxisScaleType={setYAxisScaleType} />
116
+ );
117
+
118
+ return <Tabs tabs={tabs} toolbar={toolbar} />;
119
+ };
120
+
121
+ type RelativeGrowthAdvantageToolbarProps = {
122
+ yAxisScaleType: ScaleType;
123
+ setYAxisScaleType: (scaleType: ScaleType) => void;
124
+ };
125
+
126
+ const RelativeGrowthAdvantageToolbar: FunctionComponent<RelativeGrowthAdvantageToolbarProps> = ({
127
+ yAxisScaleType,
128
+ setYAxisScaleType,
129
+ }) => {
130
+ return (
131
+ <div class='flex'>
132
+ <ScalingSelector yAxisScaleType={yAxisScaleType} setYAxisScaleType={setYAxisScaleType} />
133
+ <Info className='ml-1' content='Line chart' />
134
+ </div>
135
+ );
136
+ };