@genspectrum/dashboard-components 0.1.3 → 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 (78) hide show
  1. package/custom-elements.json +488 -117
  2. package/dist/dashboard-components.js +904 -466
  3. package/dist/dashboard-components.js.map +1 -1
  4. package/dist/genspectrum-components.d.ts +473 -67
  5. package/dist/style.css +273 -153
  6. package/package.json +11 -7
  7. package/src/preact/aggregatedData/aggregate.stories.tsx +7 -5
  8. package/src/preact/aggregatedData/aggregate.tsx +16 -7
  9. package/src/preact/components/ReferenceGenomesAwaiter.tsx +25 -0
  10. package/src/preact/components/csv-download-button.tsx +8 -2
  11. package/src/preact/components/headline.stories.tsx +19 -1
  12. package/src/preact/components/headline.tsx +25 -5
  13. package/src/preact/components/info.stories.tsx +24 -3
  14. package/src/preact/components/info.tsx +49 -5
  15. package/src/preact/components/min-max-range-slider.tsx +4 -4
  16. package/src/preact/components/percent-intput.tsx +2 -3
  17. package/src/preact/components/resize-container.tsx +23 -0
  18. package/src/preact/components/table.tsx +1 -0
  19. package/src/preact/components/tabs.stories.tsx +2 -2
  20. package/src/preact/components/tabs.tsx +47 -24
  21. package/src/preact/dateRangeSelector/date-range-selector.stories.tsx +36 -4
  22. package/src/preact/dateRangeSelector/date-range-selector.tsx +67 -53
  23. package/src/preact/locationFilter/location-filter.tsx +2 -2
  24. package/src/preact/mutationComparison/getMutationComparisonTableData.spec.ts +5 -5
  25. package/src/preact/mutationComparison/getMutationComparisonTableData.ts +45 -10
  26. package/src/preact/mutationComparison/mutation-comparison-table.tsx +20 -22
  27. package/src/preact/mutationComparison/mutation-comparison-venn.tsx +6 -3
  28. package/src/preact/mutationComparison/mutation-comparison.stories.tsx +11 -1
  29. package/src/preact/mutationComparison/mutation-comparison.tsx +16 -7
  30. package/src/preact/mutationFilter/mutation-filter.stories.tsx +70 -31
  31. package/src/preact/mutationFilter/mutation-filter.tsx +62 -14
  32. package/src/preact/mutations/getInsertionsTableData.spec.ts +6 -4
  33. package/src/preact/mutations/getInsertionsTableData.ts +1 -1
  34. package/src/preact/mutations/getMutationsTableData.spec.ts +9 -19
  35. package/src/preact/mutations/getMutationsTableData.ts +1 -1
  36. package/src/preact/mutations/mutations-insertions-table.tsx +3 -1
  37. package/src/preact/mutations/mutations-table.tsx +3 -1
  38. package/src/preact/mutations/mutations.stories.tsx +11 -1
  39. package/src/preact/mutations/mutations.tsx +24 -7
  40. package/src/preact/prevalenceOverTime/prevalence-over-time-bar-chart.tsx +1 -0
  41. package/src/preact/prevalenceOverTime/prevalence-over-time-bubble-chart.tsx +1 -0
  42. package/src/preact/prevalenceOverTime/prevalence-over-time-line-chart.tsx +1 -0
  43. package/src/preact/prevalenceOverTime/prevalence-over-time.stories.tsx +8 -0
  44. package/src/preact/prevalenceOverTime/prevalence-over-time.tsx +31 -13
  45. package/src/preact/relativeGrowthAdvantage/relative-growth-advantage-chart.tsx +8 -5
  46. package/src/preact/relativeGrowthAdvantage/relative-growth-advantage.stories.tsx +15 -0
  47. package/src/preact/relativeGrowthAdvantage/relative-growth-advantage.tsx +62 -12
  48. package/src/preact/shared/sort/sortInsertions.spec.ts +11 -10
  49. package/src/preact/shared/sort/sortInsertions.ts +10 -17
  50. package/src/preact/shared/sort/sortSubstitutionsAndDeletions.spec.ts +19 -10
  51. package/src/preact/shared/sort/sortSubstitutionsAndDeletions.ts +45 -12
  52. package/src/preact/textInput/text-input.stories.tsx +22 -1
  53. package/src/preact/textInput/text-input.tsx +3 -1
  54. package/src/utils/typeAssertions.spec.ts +31 -0
  55. package/src/utils/typeAssertions.ts +16 -0
  56. package/src/web-components/PreactLitAdapter.tsx +0 -1
  57. package/src/web-components/app.stories.ts +129 -0
  58. package/src/web-components/app.ts +27 -6
  59. package/src/web-components/display/aggregate-component.stories.ts +24 -11
  60. package/src/web-components/display/aggregate-component.tsx +26 -5
  61. package/src/web-components/display/mutation-comparison-component.stories.ts +32 -11
  62. package/src/web-components/display/mutation-comparison-component.tsx +79 -4
  63. package/src/web-components/display/mutations-component.stories.ts +40 -19
  64. package/src/web-components/display/mutations-component.tsx +71 -4
  65. package/src/web-components/display/prevalence-over-time-component.stories.ts +44 -18
  66. package/src/web-components/display/prevalence-over-time-component.tsx +105 -5
  67. package/src/web-components/display/relative-growth-advantage-component.stories.ts +32 -10
  68. package/src/web-components/display/relative-growth-advantage-component.tsx +66 -3
  69. package/src/web-components/input/date-range-selector-component.stories.ts +51 -9
  70. package/src/web-components/input/date-range-selector-component.tsx +69 -4
  71. package/src/web-components/input/location-filter-component.stories.ts +15 -4
  72. package/src/web-components/input/location-filter-component.tsx +2 -6
  73. package/src/web-components/input/mutation-filter-component.stories.ts +33 -12
  74. package/src/web-components/input/mutation-filter-component.tsx +60 -4
  75. package/src/web-components/input/text-input-component.stories.ts +26 -6
  76. package/src/web-components/input/text-input-component.tsx +34 -3
  77. package/src/web-components/display/aggregate-component.mdx +0 -25
  78. package/src/web-components/input/location-filter.mdx +0 -25
@@ -1,5 +1,4 @@
1
1
  import flatpickr from 'flatpickr';
2
- import { type FunctionComponent } from 'preact';
3
2
  import 'flatpickr/dist/flatpickr.min.css';
4
3
  import { useEffect, useRef, useState } from 'preact/hooks';
5
4
 
@@ -7,24 +6,53 @@ import { toYYYYMMDD } from './dateConversion';
7
6
  import { Select } from '../components/select';
8
7
  import type { ScaleType } from '../shared/charts/getYAxisScale';
9
8
 
10
- export type CustomSelectOption = { label: string; dateFrom: string; dateTo: string };
9
+ export type CustomSelectOption<CustomLabel extends string> = { label: CustomLabel; dateFrom: string; dateTo: string };
11
10
 
12
- export interface DateRangeSelectorProps {
13
- customSelectOptions: CustomSelectOption[];
11
+ export interface DateRangeSelectorProps<CustomLabel extends string> {
12
+ customSelectOptions: CustomSelectOption<CustomLabel>[];
14
13
  earliestDate?: string;
14
+ initialValue?: PresetOptionValues | CustomLabel;
15
15
  }
16
16
 
17
- export const DateRangeSelector: FunctionComponent<DateRangeSelectorProps> = ({
17
+ export const PRESET_VALUE_CUSTOM = 'custom';
18
+ export const PRESET_VALUE_ALL_TIMES = 'allTimes';
19
+ export const PRESET_VALUE_LAST_2_WEEKS = 'last2Weeks';
20
+ export const PRESET_VALUE_LAST_MONTH = 'lastMonth';
21
+ export const PRESET_VALUE_LAST_2_MONTHS = 'last2Months';
22
+ export const PRESET_VALUE_LAST_3_MONTHS = 'last3Months';
23
+ export const PRESET_VALUE_LAST_6_MONTHS = 'last6Months';
24
+
25
+ export const presets = {
26
+ [PRESET_VALUE_CUSTOM]: { label: 'Custom' },
27
+ [PRESET_VALUE_ALL_TIMES]: { label: 'All times' },
28
+ [PRESET_VALUE_LAST_2_WEEKS]: { label: 'Last 2 weeks' },
29
+ [PRESET_VALUE_LAST_MONTH]: { label: 'Last month' },
30
+ [PRESET_VALUE_LAST_2_MONTHS]: { label: 'Last 2 months' },
31
+ [PRESET_VALUE_LAST_3_MONTHS]: { label: 'Last 3 months' },
32
+ [PRESET_VALUE_LAST_6_MONTHS]: { label: 'Last 6 months' },
33
+ };
34
+
35
+ export type PresetOptionValues = keyof typeof presets;
36
+
37
+ export const DateRangeSelector = <CustomLabel extends string>({
18
38
  customSelectOptions,
19
39
  earliestDate = '1900-01-01',
20
- }) => {
21
- const datePickerRef = useRef<HTMLInputElement>(null);
22
- const endDatePickerRef = useRef<HTMLInputElement>(null);
40
+ initialValue,
41
+ }: DateRangeSelectorProps<CustomLabel>) => {
42
+ const fromDatePickerRef = useRef<HTMLInputElement>(null);
43
+ const toDatePickerRef = useRef<HTMLInputElement>(null);
23
44
  const divRef = useRef<HTMLDivElement>(null);
24
45
  const [dateFromPicker, setDateFromPicker] = useState<flatpickr.Instance | null>(null);
25
46
  const [dateToPicker, setDateToPicker] = useState<flatpickr.Instance | null>(null);
26
47
 
27
- const [selectedDateRange, setSelectedDateRange] = useState('last6Months');
48
+ const selectableOptions = getSelectableOptions(customSelectOptions);
49
+
50
+ const [selectedDateRange, setSelectedDateRange] = useState<CustomLabel | PresetOptionValues>(
51
+ initialValue !== undefined && selectableOptions.some((option) => option.value === initialValue)
52
+ ? initialValue
53
+ : PRESET_VALUE_LAST_6_MONTHS,
54
+ );
55
+
28
56
  const [selectedDates, setSelectedDates] = useState<{ dateFrom: Date; dateTo: Date }>({
29
57
  dateFrom: getDatesForSelectorValue('last6Months', customSelectOptions, earliestDate).dateFrom,
30
58
  dateTo: getDatesForSelectorValue('last6Months', customSelectOptions, earliestDate).dateTo,
@@ -36,18 +64,18 @@ export const DateRangeSelector: FunctionComponent<DateRangeSelectorProps> = ({
36
64
  dateFormat: 'Y-m-d',
37
65
  };
38
66
 
39
- if (datePickerRef.current) {
67
+ if (fromDatePickerRef.current) {
40
68
  setDateFromPicker(
41
- flatpickr(datePickerRef.current, {
69
+ flatpickr(fromDatePickerRef.current, {
42
70
  ...commonConfig,
43
71
  defaultDate: selectedDates.dateFrom,
44
72
  }),
45
73
  );
46
74
  }
47
75
 
48
- if (endDatePickerRef.current) {
76
+ if (toDatePickerRef.current) {
49
77
  setDateToPicker(
50
- flatpickr(endDatePickerRef.current, {
78
+ flatpickr(toDatePickerRef.current, {
51
79
  ...commonConfig,
52
80
  defaultDate: selectedDates.dateTo,
53
81
  }),
@@ -59,29 +87,9 @@ export const DateRangeSelector: FunctionComponent<DateRangeSelectorProps> = ({
59
87
  dateToPicker?.destroy();
60
88
  };
61
89
  // eslint-disable-next-line react-hooks/exhaustive-deps
62
- }, [datePickerRef, endDatePickerRef]);
63
-
64
- const selectableOptions = () => {
65
- const presetOptions = [
66
- { label: 'Custom', value: 'custom' },
67
- { label: 'All times', value: 'allTimes' },
68
- { label: 'Last 2 weeks', value: 'last2Weeks' },
69
- { label: 'Last month', value: 'lastMonth' },
70
- { label: 'Last 2 weeks', value: 'last2Weeks' },
71
- { label: 'Last month', value: 'lastMonth' },
72
- { label: 'Last 2 months', value: 'last2Months' },
73
- { label: 'Last 3 months', value: 'last3Months' },
74
- { label: 'Last 6 months', value: 'last6Months' },
75
- ];
76
-
77
- const customOptions = customSelectOptions.map((customSelectOption) => {
78
- return { label: customSelectOption.label, value: customLabelToOptionValue(customSelectOption.label) };
79
- });
90
+ }, [fromDatePickerRef, toDatePickerRef]);
80
91
 
81
- return [...presetOptions, ...customOptions];
82
- };
83
-
84
- const onSelectChange = (value: string) => {
92
+ const onSelectChange = (value: CustomLabel | PresetOptionValues) => {
85
93
  setSelectedDateRange(value);
86
94
 
87
95
  const dateRange = getDatesForSelectorValue(value, customSelectOptions, earliestDate);
@@ -145,21 +153,21 @@ export const DateRangeSelector: FunctionComponent<DateRangeSelectorProps> = ({
145
153
  return (
146
154
  <div class='join' ref={divRef}>
147
155
  <Select
148
- items={selectableOptions()}
156
+ items={selectableOptions}
149
157
  selected={selectedDateRange}
150
158
  selectStyle='select-bordered rounded-none join-item'
151
159
  onChange={(event: Event) => {
152
160
  event.preventDefault();
153
161
  const select = event.target as HTMLSelectElement;
154
162
  const value = select.value as ScaleType;
155
- onSelectChange(value);
163
+ onSelectChange(value as CustomLabel | PresetOptionValues);
156
164
  }}
157
165
  />
158
166
  <input
159
167
  class='input input-bordered rounded-none join-item'
160
168
  type='text'
161
169
  placeholder='Date from'
162
- ref={datePickerRef}
170
+ ref={fromDatePickerRef}
163
171
  onChange={onChangeDateFrom}
164
172
  onBlur={onChangeDateFrom}
165
173
  />
@@ -167,59 +175,65 @@ export const DateRangeSelector: FunctionComponent<DateRangeSelectorProps> = ({
167
175
  class='input input-bordered rounded-none join-item'
168
176
  type='text'
169
177
  placeholder='Date to'
170
- ref={endDatePickerRef}
178
+ ref={toDatePickerRef}
171
179
  onChange={onChangeDateTo}
172
- onBlur={onChangeDateFrom}
180
+ onBlur={onChangeDateTo}
173
181
  />
174
182
  </div>
175
183
  );
176
184
  };
177
185
 
178
- const customLabelToOptionValue = (customLabel: string) => {
179
- return `${customLabel}customLabel`;
186
+ const getSelectableOptions = <Label extends string>(customSelectOptions: CustomSelectOption<Label>[]) => {
187
+ const presetOptions = Object.entries(presets).map(([key, value]) => {
188
+ return { label: value.label, value: key };
189
+ });
190
+
191
+ const customOptions = customSelectOptions.map((customSelectOption) => {
192
+ return { label: customSelectOption.label, value: customSelectOption.label };
193
+ });
194
+
195
+ return [...presetOptions, ...customOptions];
180
196
  };
181
197
 
182
- const getDatesForSelectorValue = (
198
+ const getDatesForSelectorValue = <Label extends string>(
183
199
  selectorValue: string,
184
- customSelectOptions: CustomSelectOption[],
200
+ customSelectOptions: CustomSelectOption<Label>[],
185
201
  earliestDate: string,
186
202
  ) => {
187
203
  const today = new Date();
188
204
 
189
- const customSelectOption = customSelectOptions.find(
190
- (option) => customLabelToOptionValue(option.label) === selectorValue,
191
- );
205
+ const customSelectOption = customSelectOptions.find((option) => option.label === selectorValue);
192
206
  if (customSelectOption) {
193
207
  return { dateFrom: new Date(customSelectOption.dateFrom), dateTo: new Date(customSelectOption.dateTo) };
194
208
  }
195
209
 
196
210
  switch (selectorValue) {
197
- case 'last2Weeks': {
211
+ case PRESET_VALUE_LAST_2_WEEKS: {
198
212
  const twoWeeksAgo = new Date(today);
199
213
  twoWeeksAgo.setDate(today.getDate() - 14);
200
214
  return { dateFrom: twoWeeksAgo, dateTo: today };
201
215
  }
202
- case 'lastMonth': {
216
+ case PRESET_VALUE_LAST_MONTH: {
203
217
  const lastMonth = new Date(today);
204
218
  lastMonth.setMonth(today.getMonth() - 1);
205
219
  return { dateFrom: lastMonth, dateTo: today };
206
220
  }
207
- case 'last2Months': {
221
+ case PRESET_VALUE_LAST_2_MONTHS: {
208
222
  const twoMonthsAgo = new Date(today);
209
223
  twoMonthsAgo.setMonth(today.getMonth() - 2);
210
224
  return { dateFrom: twoMonthsAgo, dateTo: today };
211
225
  }
212
- case 'last3Months': {
226
+ case PRESET_VALUE_LAST_3_MONTHS: {
213
227
  const threeMonthsAgo = new Date(today);
214
228
  threeMonthsAgo.setMonth(today.getMonth() - 3);
215
229
  return { dateFrom: threeMonthsAgo, dateTo: today };
216
230
  }
217
- case 'last6Months': {
231
+ case PRESET_VALUE_LAST_6_MONTHS: {
218
232
  const sixMonthsAgo = new Date(today);
219
233
  sixMonthsAgo.setMonth(today.getMonth() - 6);
220
234
  return { dateFrom: sixMonthsAgo, dateTo: today };
221
235
  }
222
- case 'allTimes': {
236
+ case PRESET_VALUE_ALL_TIMES: {
223
237
  return { dateFrom: new Date(earliestDate), dateTo: today };
224
238
  }
225
239
  default:
@@ -5,11 +5,11 @@ import { LapisUrlContext } from '../LapisUrlContext';
5
5
  import { useQuery } from '../useQuery';
6
6
 
7
7
  export type LocationFilterProps = {
8
- value?: string;
8
+ initialValue?: string;
9
9
  fields: string[];
10
10
  };
11
11
 
12
- export const LocationFilter = ({ value: initialValue, fields }: LocationFilterProps) => {
12
+ export const LocationFilter = ({ initialValue, fields }: LocationFilterProps) => {
13
13
  const lapis = useContext(LapisUrlContext);
14
14
 
15
15
  const [value, setValue] = useState(initialValue ?? '');
@@ -51,12 +51,12 @@ describe('getPrevalenceOverTimeTableData', () => {
51
51
 
52
52
  expect(result).toEqual([
53
53
  {
54
- mutation: 'A123T',
54
+ mutation: new Substitution(undefined, 'A', 'T', 123),
55
55
  'Test 1 prevalence': 0.123,
56
56
  'Test 2 prevalence': 0.345,
57
57
  },
58
58
  {
59
- mutation: 'G234A',
59
+ mutation: new Substitution(undefined, 'G', 'A', 234),
60
60
  'Test 1 prevalence': 0.567,
61
61
  'Test 2 prevalence': 0.789,
62
62
  },
@@ -106,17 +106,17 @@ describe('getPrevalenceOverTimeTableData', () => {
106
106
 
107
107
  expect(result).toEqual([
108
108
  {
109
- mutation: 'A200T',
109
+ mutation: new Substitution(undefined, 'A', 'T', 200),
110
110
  'Test 1 prevalence': inRange,
111
111
  'Test 2 prevalence': belowRange,
112
112
  },
113
113
  {
114
- mutation: 'A300T',
114
+ mutation: new Substitution(undefined, 'A', 'T', 300),
115
115
  'Test 1 prevalence': inRange,
116
116
  'Test 2 prevalence': inRange,
117
117
  },
118
118
  {
119
- mutation: 'A400T',
119
+ mutation: new Substitution(undefined, 'A', 'T', 400),
120
120
  'Test 1 prevalence': inRange,
121
121
  'Test 2 prevalence': aboveRange,
122
122
  },
@@ -1,35 +1,53 @@
1
1
  import { type MutationData } from './queryMutationData';
2
2
  import { type Dataset } from '../../operator/Dataset';
3
+ import { type Deletion, type Substitution } from '../../utils/mutations';
3
4
  import { type ProportionInterval } from '../components/proportion-selector';
4
5
 
5
6
  type Proportions = {
6
7
  [displayName: string]: number;
7
8
  };
8
9
 
10
+ type MutationComparisonRow = {
11
+ mutation: Substitution | Deletion;
12
+ proportions: Proportions;
13
+ };
14
+
9
15
  export function getMutationComparisonTableData(data: Dataset<MutationData>, proportionInterval: ProportionInterval) {
10
- const mutationsToProportions = new Map<string, Proportions>();
16
+ const mutationsToProportions = new Map<string, MutationComparisonRow>();
11
17
 
12
18
  for (const mutationData of data.content) {
13
19
  for (const mutationEntry of mutationData.data) {
14
- const mutation = mutationEntry.mutation.toString();
15
- const proportions = mutationsToProportions.get(mutation) || {};
16
- proportions[mutationData.displayName] = mutationEntry.proportion;
17
- mutationsToProportions.set(mutation, proportions);
20
+ const mutationKey = mutationEntry.mutation.toString();
21
+ const existingRow = mutationsToProportions.get(mutationKey);
22
+
23
+ if (!existingRow) {
24
+ mutationsToProportions.set(
25
+ mutationKey,
26
+ initializeMutationRow(mutationEntry.mutation, mutationData.displayName, mutationEntry.proportion),
27
+ );
28
+ } else {
29
+ existingRow.proportions = updateProportions(
30
+ existingRow.proportions,
31
+ mutationData.displayName,
32
+ mutationEntry.proportion,
33
+ );
34
+ mutationsToProportions.set(mutationKey, existingRow);
35
+ }
18
36
  }
19
37
  }
20
38
 
21
- return [...mutationsToProportions.entries()]
22
- .map(([mutation, proportions]) => {
39
+ return [...mutationsToProportions.values()]
40
+ .map((row) => {
23
41
  return {
24
- mutation,
42
+ mutation: row.mutation,
25
43
  ...data.content
26
44
  .map((mutationData) => {
27
45
  return {
28
- [`${mutationData.displayName} prevalence`]: proportions[mutationData.displayName] || 0,
46
+ [`${mutationData.displayName} prevalence`]: row.proportions[mutationData.displayName] || 0,
29
47
  };
30
48
  })
31
49
  .reduce((acc, val) => ({ ...acc, ...val }), {}),
32
- } as { mutation: string } & Proportions;
50
+ } as { mutation: Substitution | Deletion } & Proportions;
33
51
  })
34
52
  .filter((row) =>
35
53
  Object.values(row).some(
@@ -38,3 +56,20 @@ export function getMutationComparisonTableData(data: Dataset<MutationData>, prop
38
56
  ),
39
57
  );
40
58
  }
59
+
60
+ function initializeMutationRow(
61
+ mutation: Substitution | Deletion,
62
+ displayName: string,
63
+ proportion: number,
64
+ ): MutationComparisonRow {
65
+ return {
66
+ mutation,
67
+ proportions: {
68
+ [displayName]: proportion,
69
+ },
70
+ };
71
+ }
72
+
73
+ function updateProportions(proportions: Proportions, displayName: string, proportion: number): Proportions {
74
+ return { ...proportions, [displayName]: proportion };
75
+ }
@@ -3,6 +3,7 @@ import { type FunctionComponent } from 'preact';
3
3
  import { getMutationComparisonTableData } from './getMutationComparisonTableData';
4
4
  import { type MutationData } from './queryMutationData';
5
5
  import { type Dataset } from '../../operator/Dataset';
6
+ import { type Deletion, type Substitution } from '../../utils/mutations';
6
7
  import { type ProportionInterval } from '../components/proportion-selector';
7
8
  import { Table } from '../components/table';
8
9
  import { sortSubstitutionsAndDeletions } from '../shared/sort/sortSubstitutionsAndDeletions';
@@ -14,30 +15,27 @@ export interface MutationsTableProps {
14
15
  }
15
16
 
16
17
  export const MutationComparisonTable: FunctionComponent<MutationsTableProps> = ({ data, proportionInterval }) => {
17
- const getHeaders = () => {
18
- return [
19
- {
20
- name: 'Mutation',
21
- sort: {
22
- compare: (a: string, b: string) => {
23
- return sortSubstitutionsAndDeletions(a, b);
24
- },
25
- },
18
+ const headers = [
19
+ {
20
+ name: 'Mutation',
21
+ sort: {
22
+ compare: sortSubstitutionsAndDeletions,
26
23
  },
27
- {
28
- name: 'Prevalence',
29
- columns: data.content.map((mutationData) => {
30
- return {
31
- name: mutationData.displayName,
32
- sort: true,
33
- formatter: (cell: number) => formatProportion(cell),
34
- };
35
- }),
36
- },
37
- ];
38
- };
24
+ formatter: (cell: Substitution | Deletion) => cell.toString(),
25
+ },
26
+ {
27
+ name: 'Prevalence',
28
+ columns: data.content.map((mutationData) => {
29
+ return {
30
+ name: mutationData.displayName,
31
+ sort: true,
32
+ formatter: (cell: number) => formatProportion(cell),
33
+ };
34
+ }),
35
+ },
36
+ ];
39
37
 
40
38
  const tableData = getMutationComparisonTableData(data, proportionInterval).map((row) => Object.values(row));
41
39
 
42
- return <Table data={tableData} columns={getHeaders()} pagination={true} />;
40
+ return <Table data={tableData} columns={headers} pagination={true} />;
43
41
  };
@@ -64,6 +64,7 @@ export const MutationComparisonVenn: FunctionComponent<MutationComparisonVennPro
64
64
  type: 'venn',
65
65
  data: sets,
66
66
  options: {
67
+ maintainAspectRatio: false,
67
68
  scales: {
68
69
  x: {
69
70
  ticks: {
@@ -114,9 +115,11 @@ export const MutationComparisonVenn: FunctionComponent<MutationComparisonVennPro
114
115
  }
115
116
 
116
117
  return (
117
- <>
118
- <GsChart configuration={config} />
118
+ <div className='h-full flex flex-col'>
119
+ <div className='flex-1'>
120
+ <GsChart configuration={config} />
121
+ </div>
119
122
  <div class='flex flex-wrap break-words m-2' ref={divRef} />
120
- </>
123
+ </div>
121
124
  );
122
125
  };
@@ -27,6 +27,8 @@ const meta: Meta<MutationComparisonProps> = {
27
27
  options: ['table', 'venn'],
28
28
  control: { type: 'check' },
29
29
  },
30
+ size: [{ control: 'object' }],
31
+ headline: { control: 'text' },
30
32
  },
31
33
  parameters: {
32
34
  fetchMock: {
@@ -75,7 +77,13 @@ const Template: StoryObj<MutationComparisonProps> = {
75
77
  render: (args) => (
76
78
  <LapisUrlContext.Provider value={LAPIS_URL}>
77
79
  <ReferenceGenomeContext.Provider value={referenceGenome}>
78
- <MutationComparison variants={args.variants} sequenceType={args.sequenceType} views={args.views} />
80
+ <MutationComparison
81
+ variants={args.variants}
82
+ sequenceType={args.sequenceType}
83
+ views={args.views}
84
+ size={args.size}
85
+ headline={args.headline}
86
+ />
79
87
  </ReferenceGenomeContext.Provider>
80
88
  </LapisUrlContext.Provider>
81
89
  ),
@@ -101,6 +109,8 @@ export const TwoVariants: StoryObj<MutationComparisonProps> = {
101
109
  ],
102
110
  sequenceType: 'nucleotide',
103
111
  views: ['table', 'venn'],
112
+ size: { width: '100%', height: '700px' },
113
+ headline: 'Mutation comparison',
104
114
  },
105
115
  };
106
116
 
@@ -17,6 +17,7 @@ import { type DisplayedMutationType, MutationTypeSelector } from '../components/
17
17
  import { NoDataDisplay } from '../components/no-data-display';
18
18
  import { type ProportionInterval } from '../components/proportion-selector';
19
19
  import { ProportionSelectorDropdown } from '../components/proportion-selector-dropdown';
20
+ import { ResizeContainer, type Size } from '../components/resize-container';
20
21
  import Tabs from '../components/tabs';
21
22
  import { useQuery } from '../useQuery';
22
23
 
@@ -31,17 +32,23 @@ export interface MutationComparisonProps {
31
32
  variants: MutationComparisonVariant[];
32
33
  sequenceType: SequenceType;
33
34
  views: View[];
35
+ size?: Size;
36
+ headline?: string;
34
37
  }
35
38
 
36
- export const MutationComparison: FunctionComponent<MutationComparisonProps> = ({ variants, sequenceType, views }) => {
39
+ export const MutationComparison: FunctionComponent<MutationComparisonProps> = ({
40
+ variants,
41
+ sequenceType,
42
+ views,
43
+ size,
44
+ headline = 'Mutation comparison',
45
+ }) => {
37
46
  const lapis = useContext(LapisUrlContext);
38
47
 
39
48
  const { data, error, isLoading } = useQuery(async () => {
40
49
  return queryMutationData(variants, sequenceType, lapis);
41
50
  }, [variants, sequenceType, lapis]);
42
51
 
43
- const headline = 'Mutation comparison';
44
-
45
52
  if (isLoading) {
46
53
  return (
47
54
  <Headline heading={headline}>
@@ -67,9 +74,11 @@ export const MutationComparison: FunctionComponent<MutationComparisonProps> = ({
67
74
  }
68
75
 
69
76
  return (
70
- <Headline heading={headline}>
71
- <MutationComparisonTabs data={data.mutationData} sequenceType={sequenceType} views={views} />
72
- </Headline>
77
+ <ResizeContainer size={size} defaultSize={{ height: '700px', width: '100%' }}>
78
+ <Headline heading={headline}>
79
+ <MutationComparisonTabs data={data.mutationData} sequenceType={sequenceType} views={views} />
80
+ </Headline>
81
+ </ResizeContainer>
73
82
  );
74
83
  };
75
84
 
@@ -173,7 +182,7 @@ const Toolbar: FunctionComponent<ToolbarProps> = ({
173
182
  getData={() => getMutationComparisonTableData({ content: filteredData }, proportionInterval)}
174
183
  filename='mutation_comparison.csv'
175
184
  />
176
- <Info className='mx-1' content='Info for mutation comparison' />
185
+ <Info>Info for mutation comparison</Info>
177
186
  </div>
178
187
  );
179
188
  };