@genspectrum/dashboard-components 0.10.2 → 0.10.3

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 (52) hide show
  1. package/README.md +19 -19
  2. package/custom-elements.json +49 -33
  3. package/dist/assets/{mutationOverTimeWorker-Di6yP1e6.js.map → mutationOverTimeWorker-CNg_ztNp.js.map} +1 -1
  4. package/dist/components.d.ts +49 -60
  5. package/dist/components.js +203 -45
  6. package/dist/components.js.map +1 -1
  7. package/dist/{dateRangeOption-du8H7LWu.js → dateRangeOption-DjtcAEWq.js} +16 -3
  8. package/dist/dateRangeOption-DjtcAEWq.js.map +1 -0
  9. package/dist/style.css +11 -5
  10. package/dist/util.d.ts +91 -42
  11. package/dist/util.js +1 -1
  12. package/package.json +2 -2
  13. package/src/preact/aggregatedData/aggregate.stories.tsx +14 -0
  14. package/src/preact/aggregatedData/aggregate.tsx +17 -15
  15. package/src/preact/components/error-boundary.stories.tsx +24 -3
  16. package/src/preact/components/error-boundary.tsx +3 -4
  17. package/src/preact/components/error-display.tsx +38 -17
  18. package/src/preact/components/tabs.tsx +2 -2
  19. package/src/preact/mutationFilter/mutation-filter.tsx +26 -13
  20. package/src/preact/mutations/mutations.tsx +16 -12
  21. package/src/preact/mutationsOverTime/mutations-over-time.stories.tsx +14 -0
  22. package/src/preact/mutationsOverTime/mutations-over-time.tsx +18 -14
  23. package/src/preact/numberSequencesOverTime/number-sequences-over-time.stories.tsx +14 -0
  24. package/src/preact/numberSequencesOverTime/number-sequences-over-time.tsx +22 -14
  25. package/src/preact/prevalenceOverTime/prevalence-over-time.stories.tsx +14 -0
  26. package/src/preact/prevalenceOverTime/prevalence-over-time.tsx +28 -19
  27. package/src/preact/relativeGrowthAdvantage/relative-growth-advantage.stories.tsx +14 -0
  28. package/src/preact/relativeGrowthAdvantage/relative-growth-advantage.tsx +18 -15
  29. package/src/preact/shared/charts/confideceInterval.ts +10 -8
  30. package/src/preact/shared/charts/getYAxisMax.ts +10 -5
  31. package/src/preact/statistic/statistics.tsx +10 -8
  32. package/src/preact/textInput/text-input.stories.tsx +14 -0
  33. package/src/preact/textInput/text-input.tsx +16 -11
  34. package/src/query/queryAggregateData.ts +2 -1
  35. package/src/types.ts +12 -1
  36. package/src/utilEntrypoint.ts +7 -0
  37. package/src/web-components/app.stories.ts +17 -2
  38. package/src/web-components/app.ts +17 -5
  39. package/src/web-components/input/gs-mutation-filter.stories.ts +2 -0
  40. package/src/web-components/input/gs-text-input.tsx +2 -2
  41. package/src/web-components/introduction.mdx +4 -4
  42. package/src/web-components/visualization/data_visualization_statistical_analysis.mdx +3 -3
  43. package/src/web-components/visualization/gs-mutations-over-time.tsx +1 -3
  44. package/src/web-components/visualization/gs-mutations.tsx +1 -3
  45. package/src/web-components/visualization/gs-number-sequences-over-time.tsx +1 -3
  46. package/src/web-components/visualization/gs-prevalence-over-time.tsx +3 -6
  47. package/src/web-components/visualization/gs-relative-growth-advantage.tsx +1 -5
  48. package/standalone-bundle/assets/mutationOverTimeWorker-cIyshfj_.js.map +1 -1
  49. package/standalone-bundle/dashboard-components.js +6079 -5944
  50. package/standalone-bundle/dashboard-components.js.map +1 -1
  51. package/standalone-bundle/style.css +1 -1
  52. package/dist/dateRangeOption-du8H7LWu.js.map +0 -1
@@ -1,8 +1,9 @@
1
1
  import { type FunctionComponent } from 'preact';
2
2
  import { useContext } from 'preact/hooks';
3
+ import z from 'zod';
3
4
 
4
5
  import { queryGeneralStatistics } from '../../query/queryGeneralStatistics';
5
- import { type LapisFilter } from '../../types';
6
+ import { lapisFilterSchema } from '../../types';
6
7
  import { LapisUrlContext } from '../LapisUrlContext';
7
8
  import { ErrorBoundary } from '../components/error-boundary';
8
9
  import { LoadingDisplay } from '../components/loading-display';
@@ -11,19 +12,20 @@ import { ResizeContainer } from '../components/resize-container';
11
12
  import { formatProportion } from '../shared/table/formatProportion';
12
13
  import { useQuery } from '../useQuery';
13
14
 
14
- export type StatisticsProps = {
15
- width: string;
16
- height: string;
17
- numeratorFilter: LapisFilter;
18
- denominatorFilter: LapisFilter;
19
- };
15
+ const statisticsPropsSchema = z.object({
16
+ width: z.string(),
17
+ height: z.string(),
18
+ numeratorFilter: lapisFilterSchema,
19
+ denominatorFilter: lapisFilterSchema,
20
+ });
21
+ export type StatisticsProps = z.infer<typeof statisticsPropsSchema>;
20
22
 
21
23
  export const Statistics: FunctionComponent<StatisticsProps> = (componentProps) => {
22
24
  const { width, height } = componentProps;
23
25
  const size = { height, width };
24
26
 
25
27
  return (
26
- <ErrorBoundary size={size}>
28
+ <ErrorBoundary size={size} schema={statisticsPropsSchema} componentProps={componentProps}>
27
29
  <ResizeContainer size={size}>
28
30
  <StatisticsInner {...componentProps} />
29
31
  </ResizeContainer>
@@ -6,6 +6,7 @@ import { TextInput, type TextInputProps } from './text-input';
6
6
  import { previewHandles } from '../../../.storybook/preview';
7
7
  import { AGGREGATED_ENDPOINT, LAPIS_URL } from '../../constants';
8
8
  import { LapisUrlContext } from '../LapisUrlContext';
9
+ import { expectInvalidAttributesErrorMessage } from '../shared/stories/expectInvalidAttributesErrorMessage';
9
10
 
10
11
  const meta: Meta<TextInputProps> = {
11
12
  title: 'Input/TextInput',
@@ -93,3 +94,16 @@ export const WithInitialValue: StoryObj<TextInputProps> = {
93
94
  });
94
95
  },
95
96
  };
97
+
98
+ export const WithNoLapisField: StoryObj<TextInputProps> = {
99
+ ...Default,
100
+ args: {
101
+ ...Default.args,
102
+ lapisField: '',
103
+ },
104
+ play: async ({ canvasElement, step }) => {
105
+ step('expect error message', async () => {
106
+ await expectInvalidAttributesErrorMessage(canvasElement, 'String must contain at least 1 character(s)');
107
+ });
108
+ },
109
+ };
@@ -1,5 +1,6 @@
1
1
  import { type FunctionComponent } from 'preact';
2
2
  import { useContext, useRef } from 'preact/hooks';
3
+ import z from 'zod';
3
4
 
4
5
  import { fetchAutocompleteList } from './fetchAutocompleteList';
5
6
  import { LapisUrlContext } from '../LapisUrlContext';
@@ -9,21 +10,25 @@ import { NoDataDisplay } from '../components/no-data-display';
9
10
  import { ResizeContainer } from '../components/resize-container';
10
11
  import { useQuery } from '../useQuery';
11
12
 
12
- export interface TextInputInnerProps {
13
- lapisField: string;
14
- placeholderText: string;
15
- initialValue: string;
16
- }
13
+ const textInputInnerPropsSchema = z.object({
14
+ lapisField: z.string().min(1),
15
+ placeholderText: z.string().optional(),
16
+ initialValue: z.string().optional(),
17
+ });
17
18
 
18
- export interface TextInputProps extends TextInputInnerProps {
19
- width: string;
20
- }
19
+ const textInputPropsSchema = textInputInnerPropsSchema.extend({
20
+ width: z.string(),
21
+ });
21
22
 
22
- export const TextInput: FunctionComponent<TextInputProps> = ({ width, ...innerProps }) => {
23
+ export type TextInputInnerProps = z.infer<typeof textInputInnerPropsSchema>;
24
+ export type TextInputProps = z.infer<typeof textInputPropsSchema>;
25
+
26
+ export const TextInput: FunctionComponent<TextInputProps> = (props) => {
27
+ const { width, ...innerProps } = props;
23
28
  const size = { width, height: '3rem' };
24
29
 
25
30
  return (
26
- <ErrorBoundary size={size} layout='horizontal'>
31
+ <ErrorBoundary size={size} layout='horizontal' componentProps={props} schema={textInputPropsSchema}>
27
32
  <ResizeContainer size={size}>
28
33
  <TextInputInner {...innerProps} />
29
34
  </ResizeContainer>
@@ -76,7 +81,7 @@ const TextInputInner: FunctionComponent<TextInputInnerProps> = ({ lapisField, pl
76
81
  <input
77
82
  type='text'
78
83
  class='input input-bordered w-full'
79
- placeholder={placeholderText !== undefined ? placeholderText : lapisField}
84
+ placeholder={placeholderText ?? lapisField}
80
85
  onInput={onInput}
81
86
  ref={inputRef}
82
87
  list={lapisField}
@@ -1,8 +1,9 @@
1
1
  import { FetchAggregatedOperator } from '../operator/FetchAggregatedOperator';
2
2
  import { SortOperator } from '../operator/SortOperator';
3
- import { type InitialSort } from '../preact/aggregatedData/aggregate';
4
3
  import { type LapisFilter } from '../types';
5
4
 
5
+ export type InitialSort = { field: string; direction: 'ascending' | 'descending' };
6
+
6
7
  export type AggregateData = (Record<string, string | null | number | boolean> & {
7
8
  count: number;
8
9
  proportion: number;
package/src/types.ts CHANGED
@@ -18,7 +18,13 @@ export const namedLapisFilterSchema = z.object({
18
18
  });
19
19
  export type NamedLapisFilter = z.infer<typeof namedLapisFilterSchema>;
20
20
 
21
- export type TemporalGranularity = 'day' | 'week' | 'month' | 'year';
21
+ export const temporalGranularitySchema = z.union([
22
+ z.literal('day'),
23
+ z.literal('week'),
24
+ z.literal('month'),
25
+ z.literal('year'),
26
+ ]);
27
+ export type TemporalGranularity = z.infer<typeof temporalGranularitySchema>;
22
28
 
23
29
  export const sequenceTypeSchema = z.union([z.literal('nucleotide'), z.literal('amino acid')]);
24
30
  export type SequenceType = z.infer<typeof sequenceTypeSchema>;
@@ -53,6 +59,11 @@ export type MutationEntry = SubstitutionEntry | DeletionEntry | InsertionEntry;
53
59
  export const views = {
54
60
  table: 'table',
55
61
  venn: 'venn',
62
+ grid: 'grid',
63
+ insertions: 'insertions',
64
+ bar: 'bar',
65
+ line: 'line',
66
+ bubble: 'bubble',
56
67
  } as const;
57
68
 
58
69
  export const mutationComparisonViewSchema = z.union([z.literal(views.table), z.literal(views.venn)]);
@@ -11,4 +11,11 @@ export {
11
11
  type SequenceType,
12
12
  views,
13
13
  type MutationComparisonView,
14
+ type TemporalGranularity,
14
15
  } from './types';
16
+
17
+ export { type SelectedMutationFilterStrings } from './preact/mutationFilter/mutation-filter';
18
+
19
+ export { type ConfidenceIntervalMethod } from './preact/shared/charts/confideceInterval';
20
+
21
+ export { type AxisMax, type YAxisMaxConfig } from './preact/shared/charts/getYAxisMax';
@@ -57,6 +57,21 @@ export const Default: StoryObj<{ lapis: string }> = {
57
57
  },
58
58
  };
59
59
 
60
+ export const WithNoLapisUrl: StoryObj<{ lapis: string }> = {
61
+ ...Default,
62
+ args: {
63
+ ...Default.args,
64
+ lapis: 'notAValidUrl',
65
+ },
66
+ play: async ({ canvasElement }) => {
67
+ const canvas = within(canvasElement);
68
+
69
+ await waitFor(() => {
70
+ expect(canvas.getByText("Error: Invalid LAPIS URL: 'notAValidUrl'", { exact: false })).toBeVisible();
71
+ });
72
+ },
73
+ };
74
+
60
75
  export const DelayFetchingReferenceGenome: StoryObj<{ lapis: string }> = {
61
76
  ...Template,
62
77
  parameters: {
@@ -83,13 +98,13 @@ export const DelayFetchingReferenceGenome: StoryObj<{ lapis: string }> = {
83
98
  export const FailsToFetchReferenceGenome: StoryObj<{ lapis: string }> = {
84
99
  ...Template,
85
100
  args: {
86
- lapis: 'definitely-not-a-valid-url',
101
+ lapis: 'https://url.to.lapis-definitely-not-a-valid-url',
87
102
  },
88
103
  play: async ({ canvasElement }) => {
89
104
  const canvas = within(canvasElement);
90
105
 
91
106
  await waitFor(() => {
92
- expect(canvas.getByText('Error', { exact: false })).toBeVisible();
107
+ expect(canvas.getByText('Error: Cannot fetch reference genome.', { exact: false })).toBeVisible();
93
108
  });
94
109
  },
95
110
  };
@@ -3,12 +3,15 @@ import { Task } from '@lit/task';
3
3
  import { html, LitElement } from 'lit';
4
4
  import { customElement, property } from 'lit/decorators.js';
5
5
  import { type DetailedHTMLProps, type HTMLAttributes } from 'react';
6
+ import z from 'zod';
6
7
 
7
8
  import { lapisContext } from './lapis-context';
8
9
  import { referenceGenomeContext } from './reference-genome-context';
9
10
  import { type ReferenceGenome } from '../lapisApi/ReferenceGenome';
10
11
  import { fetchReferenceGenome } from '../lapisApi/lapisApi';
11
12
 
13
+ const lapisUrlSchema = z.string().url();
14
+
12
15
  /**
13
16
  * ## Context
14
17
  *
@@ -50,7 +53,9 @@ export class App extends LitElement {
50
53
  */
51
54
  private updateReferenceGenome = new Task(this, {
52
55
  task: async () => {
53
- this.referenceGenome = await fetchReferenceGenome(this.lapis);
56
+ const lapisUrl = lapisUrlSchema.parse(this.lapis);
57
+
58
+ this.referenceGenome = await fetchReferenceGenome(lapisUrl);
54
59
  },
55
60
  args: () => [this.lapis],
56
61
  });
@@ -58,10 +63,13 @@ export class App extends LitElement {
58
63
  override render() {
59
64
  return this.updateReferenceGenome.render({
60
65
  complete: () => html``, // Children will be rendered in the light DOM anyway. We can't use slots without a shadow DOM.
61
- error: () =>
62
- html` <div class="m-2 w-full alert alert-error">
63
- Error: Cannot fetch reference genome. Is LAPIS available?
64
- </div>`,
66
+ error: (error) => {
67
+ if (error instanceof z.ZodError) {
68
+ return GsAppError(`Invalid LAPIS URL: '${this.lapis}'`);
69
+ }
70
+
71
+ return GsAppError('Cannot fetch reference genome. Is LAPIS available?');
72
+ },
65
73
  });
66
74
  }
67
75
 
@@ -70,6 +78,10 @@ export class App extends LitElement {
70
78
  }
71
79
  }
72
80
 
81
+ function GsAppError(error: string) {
82
+ return html` <div class="m-2 w-full alert alert-error">Error: ${error}</div>`;
83
+ }
84
+
73
85
  declare global {
74
86
  interface HTMLElementTagNameMap {
75
87
  'gs-app': App;
@@ -60,6 +60,7 @@ const Template: StoryObj<MutationFilterProps> = {
60
60
  export const Default: StoryObj<MutationFilterProps> = {
61
61
  ...Template,
62
62
  args: {
63
+ ...Template.args,
63
64
  initialValue: ['A123T'],
64
65
  },
65
66
  };
@@ -105,6 +106,7 @@ export const FiresFilterChangedEvent: StoryObj<MutationFilterProps> = {
105
106
  export const MultiSegmentedReferenceGenomes: StoryObj<MutationFilterProps> = {
106
107
  ...Template,
107
108
  args: {
109
+ ...Template.args,
108
110
  initialValue: ['seg1:123T', 'gene2:56', 'ins_seg2:78:AAA'],
109
111
  },
110
112
  parameters: {
@@ -27,7 +27,7 @@ export class TextInputComponent extends PreactLitAdapter {
27
27
  * The initial value to use for this text input.
28
28
  */
29
29
  @property()
30
- initialValue: string = '';
30
+ initialValue: string | undefined = undefined;
31
31
 
32
32
  /**
33
33
  * Required.
@@ -42,7 +42,7 @@ export class TextInputComponent extends PreactLitAdapter {
42
42
  * The placeholder text to display in the input field.
43
43
  */
44
44
  @property()
45
- placeholderText: string = '';
45
+ placeholderText: string | undefined = undefined;
46
46
 
47
47
  /**
48
48
  * The width of the component.
@@ -24,10 +24,10 @@ data of a specific instance of [LAPIS](https://github.com/GenSpectrum/LAPIS).
24
24
 
25
25
  We primarily provide two kinds of components:
26
26
 
27
- - Visualization components (charts, tables, etc.).
28
- Those components fetch data from the LAPIS instance and visualize it.
29
- - Input components that let you specify sequence filters for the LAPIS requests.
30
- Input changes will fire events that can be listened to by the visualization components. It is the responsibility of the dashbaord maintainer to listen to those events and to wire the data correctly into the visualization components.
27
+ - Visualization components (charts, tables, etc.).
28
+ Those components fetch data from the LAPIS instance and visualize it.
29
+ - Input components that let you specify sequence filters for the LAPIS requests.
30
+ Input changes will fire events that can be listened to by the visualization components. It is the responsibility of the dashbaord maintainer to listen to those events and to wire the data correctly into the visualization components.
31
31
 
32
32
  ## Installation
33
33
 
@@ -12,9 +12,9 @@ By default, it is set to a linear scale.
12
12
 
13
13
  In general, for each scale the displayed height of a value is calculated by applying the corresponding scale function.
14
14
 
15
- - Linear: `value`
16
- - Logarithmic: `ln(value)`
17
- - Logistic: `ln(value / (1 - value))`
15
+ - Linear: `value`
16
+ - Logarithmic: `ln(value)`
17
+ - Logistic: `ln(value / (1 - value))`
18
18
 
19
19
  ## Confidence Intervals
20
20
 
@@ -33,9 +33,7 @@ import { PreactLitAdapterWithGridJsStyles } from '../PreactLitAdapterWithGridJsS
33
33
  @customElement('gs-mutations-over-time')
34
34
  export class MutationsOverTimeComponent extends PreactLitAdapterWithGridJsStyles {
35
35
  /**
36
- * Required.
37
- *
38
- * LAPIS filter to select the displayed data.
36
+ * LAPIS filter to select the displayed data. If not provided, all data is displayed.
39
37
  */
40
38
  @property({ type: Object })
41
39
  lapisFilter: Record<string, string | number | null | boolean> = {};
@@ -35,9 +35,7 @@ import { PreactLitAdapterWithGridJsStyles } from '../PreactLitAdapterWithGridJsS
35
35
  @customElement('gs-mutations')
36
36
  export class MutationsComponent extends PreactLitAdapterWithGridJsStyles {
37
37
  /**
38
- * Required.
39
- *
40
- * LAPIS filter to select the displayed data.
38
+ * LAPIS filter to select the displayed data. If not provided, all data is displayed.
41
39
  */
42
40
  @property({ type: Object })
43
41
  lapisFilter: Record<string, string | number | null | boolean> = {};
@@ -25,8 +25,6 @@ export class NumberSequencesOverTimeComponent extends PreactLitAdapterWithGridJs
25
25
  // prettier-ignore
26
26
  // The multiline union type must not start with `|` because it looks weird in the Storybook docs
27
27
  /**
28
- * Required.
29
- *
30
28
  * Either a LAPIS filter or an array of LAPIS filters to fetch the number of sequences for.
31
29
  *
32
30
  * The `lapisFilter` will be sent as is to LAPIS to select the data.
@@ -54,7 +52,7 @@ export class NumberSequencesOverTimeComponent extends PreactLitAdapterWithGridJs
54
52
  * Must be a field of type `date` in LAPIS.
55
53
  */
56
54
  @property({ type: String })
57
- lapisDateField: string = 'date';
55
+ lapisDateField: string = '';
58
56
 
59
57
  /**
60
58
  * A list of tabs with views that this component should provide.
@@ -47,7 +47,6 @@ export class PrevalenceOverTimeComponent extends PreactLitAdapterWithGridJsStyle
47
47
  // prettier-ignore
48
48
  // The multiline union type must not start with `|` because it looks weird in the Storybook docs
49
49
  /**
50
- * Required.
51
50
  * Either a LAPIS filter or an array of LAPIS filters to calculate the prevalence for.
52
51
  *
53
52
  * The `lapisFilter` will be sent as is to LAPIS to select the data.
@@ -57,7 +56,7 @@ export class PrevalenceOverTimeComponent extends PreactLitAdapterWithGridJsStyle
57
56
  * It should be human-readable.
58
57
  *
59
58
  */
60
- @property({type: Object})
59
+ @property({ type: Object })
61
60
  numeratorFilter:
62
61
  {
63
62
  lapisFilter: Record<string, string | number | null | boolean>;
@@ -66,11 +65,9 @@ export class PrevalenceOverTimeComponent extends PreactLitAdapterWithGridJsStyle
66
65
  | {
67
66
  lapisFilter: Record<string, string | number | null | boolean>;
68
67
  displayName: string;
69
- }[] = {displayName: '', lapisFilter: {}};
68
+ }[] = { displayName: '', lapisFilter: {} };
70
69
 
71
70
  /**
72
- * Required.
73
- *
74
71
  * The LAPIS filter, to select the data of the reference.
75
72
  * It must be a valid LAPIS filter object.
76
73
  */
@@ -133,7 +130,7 @@ export class PrevalenceOverTimeComponent extends PreactLitAdapterWithGridJsStyle
133
130
  * Must be a field of type `date` in LAPIS.
134
131
  */
135
132
  @property({ type: String })
136
- lapisDateField: string = 'date';
133
+ lapisDateField: string = '';
137
134
 
138
135
  /**
139
136
  * The maximum number of rows to display in the table view.
@@ -38,8 +38,6 @@ import { PreactLitAdapter } from '../PreactLitAdapter';
38
38
  @customElement('gs-relative-growth-advantage')
39
39
  export class RelativeGrowthAdvantageComponent extends PreactLitAdapter {
40
40
  /**
41
- * Required.
42
- *
43
41
  * LAPIS filter to select the data of the focal variant.
44
42
  * It must be a valid LAPIS filter object.
45
43
  */
@@ -47,8 +45,6 @@ export class RelativeGrowthAdvantageComponent extends PreactLitAdapter {
47
45
  numeratorFilter: Record<string, string | number | null | boolean> = {};
48
46
 
49
47
  /**
50
- * Required.
51
- *
52
48
  * LAPIS filter to select the data of the baseline variant.
53
49
  * It must be a valid LAPIS filter object.
54
50
  */
@@ -92,7 +88,7 @@ export class RelativeGrowthAdvantageComponent extends PreactLitAdapter {
92
88
  * Must be a field of type `date` in LAPIS.
93
89
  */
94
90
  @property({ type: String })
95
- lapisDateField: string = 'date';
91
+ lapisDateField: string = '';
96
92
 
97
93
  /**
98
94
  * The maximum value for the y-axis on all graphs in linear view.