@genspectrum/dashboard-components 0.1.4 → 0.1.5

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 (38) hide show
  1. package/custom-elements.json +213 -78
  2. package/dist/dashboard-components.js +303 -53
  3. package/dist/dashboard-components.js.map +1 -1
  4. package/dist/genspectrum-components.d.ts +288 -69
  5. package/dist/style.css +142 -15
  6. package/package.json +3 -3
  7. package/src/preact/aggregatedData/aggregate.stories.tsx +2 -0
  8. package/src/preact/aggregatedData/aggregate.tsx +9 -4
  9. package/src/preact/components/headline.stories.tsx +19 -1
  10. package/src/preact/components/headline.tsx +9 -1
  11. package/src/preact/components/info.stories.tsx +24 -3
  12. package/src/preact/components/info.tsx +49 -5
  13. package/src/preact/dateRangeSelector/date-range-selector.tsx +10 -10
  14. package/src/preact/mutationComparison/mutation-comparison.stories.tsx +3 -0
  15. package/src/preact/mutationComparison/mutation-comparison.tsx +3 -3
  16. package/src/preact/mutationFilter/mutation-filter.tsx +1 -1
  17. package/src/preact/mutations/mutations.stories.tsx +3 -0
  18. package/src/preact/mutations/mutations.tsx +9 -3
  19. package/src/preact/prevalenceOverTime/prevalence-over-time.stories.tsx +4 -0
  20. package/src/preact/prevalenceOverTime/prevalence-over-time.tsx +14 -4
  21. package/src/preact/relativeGrowthAdvantage/relative-growth-advantage.stories.tsx +3 -0
  22. package/src/preact/relativeGrowthAdvantage/relative-growth-advantage.tsx +49 -4
  23. package/src/web-components/display/aggregate-component.stories.ts +3 -0
  24. package/src/web-components/display/aggregate-component.tsx +15 -1
  25. package/src/web-components/display/mutation-comparison-component.stories.ts +3 -0
  26. package/src/web-components/display/mutation-comparison-component.tsx +7 -0
  27. package/src/web-components/display/mutations-component.stories.ts +27 -7
  28. package/src/web-components/display/mutations-component.tsx +58 -4
  29. package/src/web-components/display/prevalence-over-time-component.stories.ts +24 -0
  30. package/src/web-components/display/prevalence-over-time-component.tsx +93 -5
  31. package/src/web-components/display/relative-growth-advantage-component.stories.ts +21 -0
  32. package/src/web-components/display/relative-growth-advantage-component.tsx +54 -3
  33. package/src/web-components/input/date-range-selector-component.stories.ts +17 -2
  34. package/src/web-components/input/date-range-selector-component.tsx +57 -5
  35. package/src/web-components/input/mutation-filter-component.stories.ts +13 -3
  36. package/src/web-components/input/mutation-filter-component.tsx +50 -2
  37. package/src/web-components/input/text-input-component.stories.ts +14 -3
  38. package/src/web-components/input/text-input-component.tsx +23 -1
@@ -26,7 +26,7 @@ export declare class AggregateComponent extends PreactLitAdapterWithGridJsStyles
26
26
  * The proportion represents the ratio of the aggregated value to the total count of the data
27
27
  * (considering the applied filter).
28
28
  */
29
- views: View_4[];
29
+ views: View[];
30
30
  /**
31
31
  * The filter to apply to the data.
32
32
  */
@@ -43,6 +43,10 @@ export declare class AggregateComponent extends PreactLitAdapterWithGridJsStyles
43
43
  width?: string;
44
44
  height?: string;
45
45
  } | undefined;
46
+ /**
47
+ * The headline of the component. Set to an empty string to hide the headline.
48
+ */
49
+ headline: string | undefined;
46
50
  render(): JSX_2.Element;
47
51
  }
48
52
 
@@ -73,21 +77,48 @@ export declare class App extends LitElement {
73
77
  createRenderRoot(): this;
74
78
  }
75
79
 
76
- declare type ConfidenceIntervalMethod = 'wilson' | 'none';
77
-
78
- declare type CustomSelectOption<CustomLabel extends string> = {
79
- label: CustomLabel;
80
- dateFrom: string;
81
- dateTo: string;
82
- };
83
-
84
80
  /**
85
- * @fires {CustomEvent<{ dateFrom: string; dateTo: string; }>} gs-date-range-changed - When the date range has changed
81
+ * ## Context
82
+ * This component is a group of input fields designed to specify a date range. It consists of 3 fields:
83
+ *
84
+ * - a select field to choose a predefined date range,
85
+ * - an input field with an attached date picker for the start date,
86
+ * - an input field with an attached date picker for the end date.
87
+ *
88
+ * Setting a value in the select field will overwrite the previous values of the start and end date.
89
+ * Setting a value in either of the date pickers will set the select field to "custom",
90
+ * which represents an arbitrary date range.
91
+ *
92
+ * @fires {CustomEvent<{ dateFrom: string; dateTo: string; }>} gs-date-range-changed
93
+ * Fired when:
94
+ * - The select field is changed,
95
+ * - A date is selected in either of the date pickers,
96
+ * - A date was typed into either of the date input fields, and the input field loses focus ("on blur").
97
+ * Contains the dates in the format `YYYY-MM-DD`.
86
98
  */
87
- export declare class DateRangeSelectorComponent<CustomLabel extends string> extends PreactLitAdapter {
88
- customSelectOptions: CustomSelectOption<CustomLabel>[];
99
+ export declare class DateRangeSelectorComponent extends PreactLitAdapter {
100
+ /**
101
+ * An array of custom options that the select field should provide,
102
+ * in addition to the predefined options.
103
+ * The `label` will be shown to the user, and it will be available as `initialValue`.
104
+ * The dates must be in the format `YYYY-MM-DD`.
105
+ */
106
+ customSelectOptions: {
107
+ label: string;
108
+ dateFrom: string;
109
+ dateTo: string;
110
+ }[];
111
+ /**
112
+ * The `dateFrom` value to use in the `allTimes` preset in the format `YYYY-MM-DD`.
113
+ */
89
114
  earliestDate: string | undefined;
90
- initialValue: PresetOptionValues | CustomLabel | string | undefined;
115
+ /**
116
+ * The initial value to use for this date range selector.
117
+ * Must be a valid label from the preset labels or a `label` given in the `customSelectOptions`.
118
+ *
119
+ * If the value is invalid, the component will default to `'last6Months'`.
120
+ */
121
+ initialValue: 'custom' | 'allTimes' | 'last2Weeks' | 'lastMonth' | 'last2Months' | 'last3Months' | 'last6Months' | string | undefined;
91
122
  render(): JSX_2.Element;
92
123
  }
93
124
 
@@ -223,22 +254,109 @@ export declare class MutationComparisonComponent extends PreactLitAdapterWithGri
223
254
  width?: string;
224
255
  height?: string;
225
256
  } | undefined;
257
+ /**
258
+ * The headline of the component. Set to an empty string to hide the headline.
259
+ */
260
+ headline: string | undefined;
226
261
  render(): JSX_2.Element;
227
262
  }
228
263
 
229
264
  /**
230
- * @fires {CustomEvent<SelectedMutationFilterStrings>} gs-mutation-filter-changed - When the mutation filter values have changed
231
- * @fires {CustomEvent<SelectedMutationFilterStrings>} gs-mutation-filter-on-blur - When the mutation filter has lost focus
265
+ * ## Context
266
+ * This component provides an input field to specify filters for nucleotide and amino acid mutations and insertions.
267
+ *
268
+ * Input values have to be provided one at a time and submitted by pressing the Enter key or by clicking the '+' button.
269
+ * After submission, the component validates the input and fires an event with the selected mutations.
270
+ * All previously selected mutations are displayed at the input field and added to the event.
271
+ * Users can remove a mutation by clicking the 'x' button next to the mutation.
272
+ *
273
+ * Validation of the input is performed according to the following rules:
274
+ *
275
+ * Mutations have to conform to the following format: `<gene/segment>:<symbol at reference><position><Substituted symbol/Deletion>`
276
+ * - Gene/segment: The gene or segment where the mutation occurs. Must be contained in the reference genome
277
+ * (Optional for elements with only one gene/segment)
278
+ * - Symbol at reference: The symbol at the reference position. (Optional)
279
+ * - Position: The position of the mutation. (Required)
280
+ * - Substituted symbol/Deletion: The substituted symbol or '-' for a deletion. (Required)
281
+ * Example: S:614G, 614G, 614- or 614G
282
+ *
283
+ * Insertions have to conform to the following format: `ins_<gene/segment>:<position>:<Inserted symbols>`
284
+ * - Gene/segment: The gene or segment where the insertion occurs. Must be contained in the reference genome
285
+ * (Optional for elements with only one gene/segment)
286
+ * - Position: The position of the insertion. (Required)
287
+ * - Inserted symbols: The symbols that are inserted. (Required)
288
+ * Example: ins_S:614:G, ins_614:G
289
+ *
290
+ * @fires {CustomEvent<{
291
+ * nucleotideMutations: string[],
292
+ * aminoAcidMutations: string[],
293
+ * nucleotideInsertions: string[],
294
+ * aminoAcidInsertions: string[]
295
+ * }>} gs-mutation-filter-changed
296
+ * Fired when:
297
+ * - The user has submitted a valid mutation or insertion
298
+ * - The user has removed a mutation or insertion
299
+ *
300
+ * @fires {CustomEvent<{
301
+ * nucleotideMutations: string[],
302
+ * aminoAcidMutations: string[],
303
+ * nucleotideInsertions: string[],
304
+ * aminoAcidInsertions: string[]
305
+ * }>} gs-mutation-filter-on-blur
306
+ * Fired when:
307
+ * - the mutation filter has lost focus
308
+ * Contains the selected mutations in the format
232
309
  */
233
310
  export declare class MutationFilterComponent extends PreactLitAdapter {
311
+ /**
312
+ * The initial value to use for this mutation filter.
313
+ * Must be either
314
+ * - an array of strings of valid mutations.
315
+ * - an object with the keys `nucleotideMutations`, `aminoAcidMutations`, `nucleotideInsertions` and `aminoAcidInsertions` and corresponding string arrays.
316
+ */
234
317
  initialValue: SelectedMutationFilterStrings | string[] | undefined;
235
318
  render(): JSX_2.Element;
236
319
  }
237
320
 
321
+ /**
322
+ * This component displays mutations (substitutions, deletions and insertions) for a given variant.
323
+ *
324
+ * ## Views
325
+ *
326
+ * ### Table View
327
+ *
328
+ * The table view shows all substitutions and deletions for the given variant.
329
+ * It shows the type (substitution or deletion), the total count of the mutation
330
+ * and the proportion of the mutation in the variant.
331
+ * The proportion is relative to the total number of sequences matching
332
+ * the specified sequence filters with non-ambiguous reads at that position.
333
+ *
334
+ * The proportion interval filter can be used to filter the displayed mutations on client side.
335
+ *
336
+ * ### Grid View
337
+ *
338
+ * The grid view shows the proportion of each sequence symbol (nucleotide or amino acid) for each position that has a mutation.
339
+ * Only positions with at least one mutation in the selected proportion interval are shown.
340
+ *
341
+ * ### Insertions View
342
+ *
343
+ * The insertions view shows the count of all insertions for the given variant.
344
+ *
345
+ */
238
346
  export declare class MutationsComponent extends PreactLitAdapterWithGridJsStyles {
239
- variant: LapisFilter;
240
- sequenceType: SequenceType;
241
- views: View[];
347
+ /**
348
+ * The `variant` will be sent as is to LAPIS to filter the mutation data.
349
+ * It must be a valid LAPIS filter object.
350
+ */
351
+ variant: Record<string, string | number | null | boolean>;
352
+ /**
353
+ * The type of the sequence for which the mutations should be shown.
354
+ */
355
+ sequenceType: 'nucleotide' | 'amino acid';
356
+ /**
357
+ * A list of tabs with views that this component should provide.
358
+ */
359
+ views: ('table' | 'grid' | 'insertions')[];
242
360
  /**
243
361
  * The size of the component.
244
362
  *
@@ -251,13 +369,13 @@ export declare class MutationsComponent extends PreactLitAdapterWithGridJsStyles
251
369
  width?: string;
252
370
  height?: string;
253
371
  } | undefined;
372
+ /**
373
+ * The headline of the component. Set to an empty string to hide the headline.
374
+ */
375
+ headline: string | undefined;
254
376
  render(): JSX_2.Element;
255
377
  }
256
378
 
257
- declare type NamedLapisFilter = LapisFilter & {
258
- displayName: string;
259
- };
260
-
261
379
  declare abstract class PreactLitAdapter extends ReactiveElement {
262
380
  static styles: CSSResult[];
263
381
  /* Excluded from this release type: lapis */
@@ -270,39 +388,87 @@ declare abstract class PreactLitAdapterWithGridJsStyles extends PreactLitAdapter
270
388
  static styles: CSSResult[];
271
389
  }
272
390
 
273
- declare type PresetOptionValues = keyof typeof presets;
274
-
275
- declare const presets: {
276
- custom: {
277
- label: string;
278
- };
279
- allTimes: {
280
- label: string;
281
- };
282
- last2Weeks: {
283
- label: string;
284
- };
285
- lastMonth: {
286
- label: string;
287
- };
288
- last2Months: {
289
- label: string;
290
- };
291
- last3Months: {
292
- label: string;
293
- };
294
- last6Months: {
295
- label: string;
296
- };
297
- };
298
-
391
+ /**
392
+ * This component displays the prevalence over time of one or more variants.
393
+ * The prevalence is calculated as the ratio of the number of cases of each variant given as `numerator`
394
+ * to the number of cases of the variant given as `denominator`.
395
+ *
396
+ * In the chart views,
397
+ * - the user can select whether to display a confidence interval (not available in the bubble chart).
398
+ * The confidence interval is calculated using [Wilson score interval](https://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval),
399
+ * with a confidence level of 95%.
400
+ * - the x-axis shows time steps in the selected `granularity`.
401
+ * - the user can select the y-axis scale (linear, logistic, logit).
402
+ *
403
+ * ## Views
404
+ *
405
+ * ### Bar View
406
+ *
407
+ * Displays the prevalence over time as a bar chart.
408
+ * Shows a bar for each variant in the `numerator` on every time step.
409
+ *
410
+ * ### Line View
411
+ *
412
+ * Displays the prevalence over time as a line chart.
413
+ * Each data point is connected for better visibility.
414
+ * Shows a line for each variant in the `numerator`.
415
+ *
416
+ * ### Bubble View
417
+ *
418
+ * Displays the prevalence over time as a bubble chart.
419
+ * The size of the bubbles represents the number of cases of the `denominator` variant.
420
+ * The height of the bubbles represents the prevalence of the `numerator` variants.
421
+ *
422
+ * ### Table View
423
+ *
424
+ * Displays the prevalence over time as a table with one row per time point.
425
+ */
299
426
  export declare class PrevalenceOverTimeComponent extends PreactLitAdapterWithGridJsStyles {
300
- numerator: NamedLapisFilter | NamedLapisFilter[];
301
- denominator: NamedLapisFilter;
302
- granularity: TemporalGranularity;
427
+ /**
428
+ * Either a single variant or an array of variants to compare.
429
+ * This must be a valid LAPIS filter object with an additional `displayName` property
430
+ * which will be used as the label for the variant in the views,
431
+ * or an array of such objects.
432
+ */
433
+ numerator: (Record<string, string | number | null | boolean> & {
434
+ displayName: string;
435
+ }) | (Record<string, string | number | null | boolean> & {
436
+ displayName: string;
437
+ })[];
438
+ /**
439
+ * The variant that the variants in `numerator` are compared to.
440
+ */
441
+ denominator: Record<string, string | number | null | boolean> & {
442
+ displayName: string;
443
+ };
444
+ /**
445
+ * The granularity of the time axis.
446
+ */
447
+ granularity: 'day' | 'week' | 'month' | 'year';
448
+ /**
449
+ * The number of time steps to use for smoothing the data.
450
+ * `0` means no smoothing.
451
+ * Must be a non-negative integer.
452
+ *
453
+ * For a given time, the shown value is the mean of the neighbouring measured values.
454
+ * The `smoothingWindow` value provides the number of neighbouring values to take into account.
455
+ * The resulting time is computed via `Math.floor(smoothingWindow / 2)`.
456
+ */
303
457
  smoothingWindow: number;
304
- views: View_2[];
305
- confidenceIntervalMethods: ConfidenceIntervalMethod[];
458
+ /**
459
+ * A list of tabs with views that this component should provide.
460
+ */
461
+ views: ('bar' | 'line' | 'bubble' | 'table')[];
462
+ /**
463
+ * A list of methods to calculate the confidence interval.
464
+ * The option `none` is always available and disables confidence intervals.
465
+ * Pass an empty array to disable the confidence interval selector.
466
+ */
467
+ confidenceIntervalMethods: ('wilson' | 'none')[];
468
+ /**
469
+ * The headline of the component. Set to an empty string to hide the headline.
470
+ */
471
+ headline: string | undefined;
306
472
  /**
307
473
  * The size of the component.
308
474
  *
@@ -361,11 +527,52 @@ declare const referenceGenomeResponse: default_2.ZodObject<{
361
527
  }[];
362
528
  }>;
363
529
 
530
+ /**
531
+ * We assume a discrete time model, where new infections happen exactly every `generationTime` days.
532
+ * This is what we call a "generation".
533
+ *
534
+ * This component estimates the relative growth advantage of a variant by performing a logistic regression.
535
+ * Based on the inferred logistic growth rate, we derive the relative growth advantage (per generation).
536
+ *
537
+ * For details on the scientific method, see:
538
+ * Chen, Chaoran, et al. "Quantification of the spread of SARS-CoV-2 variant B.1.1.7 in Switzerland." Epidemics (2021);
539
+ * doi: [10.1016/j.epidem.2021.100480](https://doi.org/10.1016/j.epidem.2021.100480)
540
+ *
541
+ * This component fetches aggregated data from LAPIS.
542
+ * Then the data is sent to `https://cov-spectrum.org/api/v2/computed/model/chen2021Fitness`
543
+ * which performs the logistic regression and calculates the relative growth advantage.
544
+ *
545
+ * ## Views
546
+ *
547
+ * ### Line View
548
+ *
549
+ * The line view shows the relative growth advantage over time in a line chart.
550
+ * The dots in the plot show the proportions of the focal variant (`numerator`) to the `denominator` variant
551
+ * for every day as observed in the data.
552
+ * The line shows a logistic curve fitted to the data points, including a 95% confidence interval.
553
+ */
364
554
  export declare class RelativeGrowthAdvantageComponent extends PreactLitAdapter {
365
- numerator: LapisFilter;
366
- denominator: LapisFilter;
555
+ /**
556
+ * The LAPIS filter for the focal variant.
557
+ */
558
+ numerator: Record<string, string | number | null | boolean>;
559
+ /**
560
+ * The LAPIS filter for the variant that the focal variant (`numerator`) should be compared to.
561
+ */
562
+ denominator: Record<string, string | number | null | boolean>;
563
+ /**
564
+ * The generation time represents the number of days over which the variant's relative growth advantage is measured.
565
+ * For example, if we set a generation time of 7 days, then we estimate the growth advantage per week.
566
+ */
367
567
  generationTime: number;
368
- views: View_3[];
568
+ /**
569
+ * A list of tabs with views that this component should provide.
570
+ */
571
+ views: 'line'[];
572
+ /**
573
+ * The headline of the component. Set to an empty string to hide the headline.
574
+ */
575
+ headline: string | undefined;
369
576
  /**
370
577
  * The size of the component.
371
578
  *
@@ -392,8 +599,6 @@ declare type SelectedMutationFilterStrings = {
392
599
  [Key in keyof SelectedFilters]: string[];
393
600
  };
394
601
 
395
- declare type SequenceType = 'nucleotide' | 'amino acid';
396
-
397
602
  declare class Substitution implements Mutation {
398
603
  readonly segment: string | undefined;
399
604
  readonly valueAtReference: string | undefined;
@@ -406,25 +611,39 @@ declare class Substitution implements Mutation {
406
611
  static parse(mutationStr: string): Substitution | null;
407
612
  }
408
613
 
409
- declare type TemporalGranularity = 'day' | 'week' | 'month' | 'year';
410
-
411
614
  /**
412
- * @fires {CustomEvent<Record<string, string>>} gs-text-input-changed - When the text input has changed
615
+ *
616
+ * ## Context
617
+ *
618
+ * This component provides a text input field to specify filters for arbitrary fields of this Lapis instance.
619
+ *
620
+ * @fires {CustomEvent<Record<string, string>>} gs-text-input-changed
621
+ * Fired when the input field is changed.
622
+ * The `details` of this event contain an object with the `lapisField` as key and the input value as value.
623
+ * Example:
624
+ * ```
625
+ * {
626
+ * "host": "Homo sapiens"
627
+ * }
628
+ * ```
413
629
  */
414
630
  export declare class TextInputComponent extends PreactLitAdapter {
631
+ /**
632
+ * The initial value to use for this text input.
633
+ */
415
634
  initialValue: string | undefined;
635
+ /**
636
+ * The Lapis field name to use for this text input.
637
+ */
416
638
  lapisField: string;
639
+ /**
640
+ * The placeholder text to display in the input field.
641
+ */
417
642
  placeholderText: string | undefined;
418
643
  render(): JSX_2.Element;
419
644
  }
420
645
 
421
- declare type View = 'table' | 'grid' | 'insertions';
422
-
423
- declare type View_2 = 'bar' | 'line' | 'bubble' | 'table';
424
-
425
- declare type View_3 = 'line';
426
-
427
- declare type View_4 = 'table';
646
+ declare type View = 'table';
428
647
 
429
648
  export { }
430
649
 
@@ -473,7 +692,7 @@ declare global {
473
692
 
474
693
  declare global {
475
694
  interface HTMLElementTagNameMap {
476
- 'gs-date-range-selector': DateRangeSelectorComponent<string>;
695
+ 'gs-date-range-selector': DateRangeSelectorComponent;
477
696
  }
478
697
  interface HTMLElementEventMap {
479
698
  'gs-date-range-changed': CustomEvent<{