@genspectrum/dashboard-components 0.9.1 → 0.10.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 (31) hide show
  1. package/custom-elements.json +168 -5
  2. package/dist/assets/{mutationOverTimeWorker-DuWGESoO.js.map → mutationOverTimeWorker-CvZg52rf.js.map} +1 -1
  3. package/dist/components.d.ts +49 -1
  4. package/dist/components.js +268 -128
  5. package/dist/components.js.map +1 -1
  6. package/dist/style.css +41 -0
  7. package/dist/util.d.ts +16 -0
  8. package/package.json +2 -2
  9. package/src/preact/components/confidence-interval-selector.tsx +1 -1
  10. package/src/preact/components/min-max-range-slider.tsx +4 -4
  11. package/src/preact/components/percent-intput.tsx +2 -2
  12. package/src/preact/mutationFilter/mutation-filter.tsx +0 -1
  13. package/src/preact/mutationFilter/parseMutation.spec.ts +30 -0
  14. package/src/preact/mutationFilter/sequenceTypeFromSegment.ts +3 -2
  15. package/src/preact/prevalenceOverTime/prevalence-over-time.stories.tsx +4 -4
  16. package/src/preact/prevalenceOverTime/prevalence-over-time.tsx +11 -1
  17. package/src/preact/statistic/__mockData__/denominator.json +13 -0
  18. package/src/preact/statistic/__mockData__/numerator.json +13 -0
  19. package/src/preact/statistic/statistics.stories.tsx +81 -0
  20. package/src/preact/statistic/statistics.tsx +78 -0
  21. package/src/query/queryGeneralStatistics.ts +18 -0
  22. package/src/utils/mutations.ts +3 -3
  23. package/src/web-components/visualization/gs-prevalence-over-time.stories.ts +1 -1
  24. package/src/web-components/visualization/gs-prevalence-over-time.tsx +2 -2
  25. package/src/web-components/visualization/gs-statistics.stories.ts +95 -0
  26. package/src/web-components/visualization/gs-statistics.tsx +83 -0
  27. package/src/web-components/visualization/index.ts +1 -0
  28. package/standalone-bundle/assets/{mutationOverTimeWorker-MVSt1FVw.js.map → mutationOverTimeWorker-CypX_PYM.js.map} +1 -1
  29. package/standalone-bundle/dashboard-components.js +4422 -4350
  30. package/standalone-bundle/dashboard-components.js.map +1 -1
  31. package/standalone-bundle/style.css +1 -1
package/dist/style.css CHANGED
@@ -1561,6 +1561,38 @@ html {
1561
1561
  .select[multiple] {
1562
1562
  height: auto;
1563
1563
  }
1564
+ .stat {
1565
+ display: inline-grid;
1566
+ width: 100%;
1567
+ grid-template-columns: repeat(1, 1fr);
1568
+ -moz-column-gap: 1rem;
1569
+ column-gap: 1rem;
1570
+ border-color: var(--fallback-bc,oklch(var(--bc)/var(--tw-border-opacity)));
1571
+ --tw-border-opacity: 0.1;
1572
+ padding-left: 1.5rem;
1573
+ padding-right: 1.5rem;
1574
+ padding-top: 1rem;
1575
+ padding-bottom: 1rem;
1576
+ }
1577
+ .stat-title {
1578
+ grid-column-start: 1;
1579
+ white-space: nowrap;
1580
+ color: var(--fallback-bc,oklch(var(--bc)/0.6));
1581
+ }
1582
+ .stat-value {
1583
+ grid-column-start: 1;
1584
+ white-space: nowrap;
1585
+ font-size: 2.25rem;
1586
+ line-height: 2.5rem;
1587
+ font-weight: 800;
1588
+ }
1589
+ .stat-desc {
1590
+ grid-column-start: 1;
1591
+ white-space: nowrap;
1592
+ font-size: 0.75rem;
1593
+ line-height: 1rem;
1594
+ color: var(--fallback-bc,oklch(var(--bc)/0.6));
1595
+ }
1564
1596
  .steps {
1565
1597
  display: inline-grid;
1566
1598
  grid-auto-flow: column;
@@ -3427,6 +3459,15 @@ input.tab:checked + .tab-content,
3427
3459
  .sm\:max-w-5xl {
3428
3460
  max-width: 64rem;
3429
3461
  }
3462
+
3463
+ .sm\:flex-row {
3464
+ flex-direction: row;
3465
+ }
3466
+
3467
+ .sm\:text-4xl {
3468
+ font-size: 2.25rem;
3469
+ line-height: 2.5rem;
3470
+ }
3430
3471
  }.flatpickr-calendar{background:transparent;opacity:0;display:none;text-align:center;visibility:hidden;padding:0;-webkit-animation:none;animation:none;direction:ltr;border:0;font-size:14px;line-height:24px;border-radius:5px;position:absolute;width:307.875px;-webkit-box-sizing:border-box;box-sizing:border-box;-ms-touch-action:manipulation;touch-action:manipulation;background:#fff;-webkit-box-shadow:1px 0 0 #e6e6e6,-1px 0 0 #e6e6e6,0 1px 0 #e6e6e6,0 -1px 0 #e6e6e6,0 3px 13px rgba(0,0,0,0.08);box-shadow:1px 0 0 #e6e6e6,-1px 0 0 #e6e6e6,0 1px 0 #e6e6e6,0 -1px 0 #e6e6e6,0 3px 13px rgba(0,0,0,0.08)}.flatpickr-calendar.open,.flatpickr-calendar.inline{opacity:1;max-height:640px;visibility:visible}.flatpickr-calendar.open{display:inline-block;z-index:99999}.flatpickr-calendar.animate.open{-webkit-animation:fpFadeInDown 300ms cubic-bezier(.23,1,.32,1);animation:fpFadeInDown 300ms cubic-bezier(.23,1,.32,1)}.flatpickr-calendar.inline{display:block;position:relative;top:2px}.flatpickr-calendar.static{position:absolute;top:calc(100% + 2px)}.flatpickr-calendar.static.open{z-index:999;display:block}.flatpickr-calendar.multiMonth .flatpickr-days .dayContainer:nth-child(n+1) .flatpickr-day.inRange:nth-child(7n+7){-webkit-box-shadow:none !important;box-shadow:none !important}.flatpickr-calendar.multiMonth .flatpickr-days .dayContainer:nth-child(n+2) .flatpickr-day.inRange:nth-child(7n+1){-webkit-box-shadow:-2px 0 0 #e6e6e6,5px 0 0 #e6e6e6;box-shadow:-2px 0 0 #e6e6e6,5px 0 0 #e6e6e6}.flatpickr-calendar .hasWeeks .dayContainer,.flatpickr-calendar .hasTime .dayContainer{border-bottom:0;border-bottom-right-radius:0;border-bottom-left-radius:0}.flatpickr-calendar .hasWeeks .dayContainer{border-left:0}.flatpickr-calendar.hasTime .flatpickr-time{height:40px;border-top:1px solid #e6e6e6}.flatpickr-calendar.noCalendar.hasTime .flatpickr-time{height:auto}.flatpickr-calendar:before,.flatpickr-calendar:after{position:absolute;display:block;pointer-events:none;border:solid transparent;content:'';height:0;width:0;left:22px}.flatpickr-calendar.rightMost:before,.flatpickr-calendar.arrowRight:before,.flatpickr-calendar.rightMost:after,.flatpickr-calendar.arrowRight:after{left:auto;right:22px}.flatpickr-calendar.arrowCenter:before,.flatpickr-calendar.arrowCenter:after{left:50%;right:50%}.flatpickr-calendar:before{border-width:5px;margin:0 -5px}.flatpickr-calendar:after{border-width:4px;margin:0 -4px}.flatpickr-calendar.arrowTop:before,.flatpickr-calendar.arrowTop:after{bottom:100%}.flatpickr-calendar.arrowTop:before{border-bottom-color:#e6e6e6}.flatpickr-calendar.arrowTop:after{border-bottom-color:#fff}.flatpickr-calendar.arrowBottom:before,.flatpickr-calendar.arrowBottom:after{top:100%}.flatpickr-calendar.arrowBottom:before{border-top-color:#e6e6e6}.flatpickr-calendar.arrowBottom:after{border-top-color:#fff}.flatpickr-calendar:focus{outline:0}.flatpickr-wrapper{position:relative;display:inline-block}.flatpickr-months{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex}.flatpickr-months .flatpickr-month{background:transparent;color:rgba(0,0,0,0.9);fill:rgba(0,0,0,0.9);height:34px;line-height:1;text-align:center;position:relative;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;overflow:hidden;-webkit-box-flex:1;-webkit-flex:1;-ms-flex:1;flex:1}.flatpickr-months .flatpickr-prev-month,.flatpickr-months .flatpickr-next-month{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;text-decoration:none;cursor:pointer;position:absolute;top:0;height:34px;padding:10px;z-index:3;color:rgba(0,0,0,0.9);fill:rgba(0,0,0,0.9)}.flatpickr-months .flatpickr-prev-month.flatpickr-disabled,.flatpickr-months .flatpickr-next-month.flatpickr-disabled{display:none}.flatpickr-months .flatpickr-prev-month i,.flatpickr-months .flatpickr-next-month i{position:relative}.flatpickr-months .flatpickr-prev-month.flatpickr-prev-month,.flatpickr-months .flatpickr-next-month.flatpickr-prev-month{/*
3431
3472
  /*rtl:begin:ignore*/left:0/*
3432
3473
  /*rtl:end:ignore*/}/*
package/dist/util.d.ts CHANGED
@@ -196,6 +196,22 @@ declare global {
196
196
  }
197
197
 
198
198
 
199
+ declare global {
200
+ interface HTMLElementTagNameMap {
201
+ 'gs-statistics': StatisticsComponent;
202
+ }
203
+ }
204
+
205
+
206
+ declare global {
207
+ namespace JSX {
208
+ interface IntrinsicElements {
209
+ 'gs-statistics': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
210
+ }
211
+ }
212
+ }
213
+
214
+
199
215
  declare global {
200
216
  interface HTMLElementTagNameMap {
201
217
  'gs-date-range-selector': DateRangeSelectorComponent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@genspectrum/dashboard-components",
3
- "version": "0.9.1",
3
+ "version": "0.10.1",
4
4
  "description": "GenSpectrum web components for building dashboards",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0-only",
@@ -132,7 +132,7 @@
132
132
  "storybook": "^8.0.9",
133
133
  "storybook-addon-fetch-mock": "^2.0.0",
134
134
  "tailwindcss": "^3.4.3",
135
- "typescript": "~5.6.2",
135
+ "typescript": "~5.7.2",
136
136
  "vite": "^5.2.10",
137
137
  "vite-plugin-dts": "^4.0.3",
138
138
  "vitest": "^2.0.1"
@@ -20,7 +20,7 @@ export const ConfidenceIntervalSelector: FunctionComponent<ConfidenceIntervalSel
20
20
 
21
21
  const items = [
22
22
  { label: 'Confidence interval method', value: 'none', disabled: true },
23
- ...confidenceIntervalMethods.concat('none').map((method) => {
23
+ ...confidenceIntervalMethods.map((method) => {
24
24
  switch (method) {
25
25
  case 'wilson':
26
26
  return { label: 'Wilson, 95% CI', value: 'wilson' };
@@ -75,8 +75,8 @@ export const MinMaxRangeSlider: FunctionComponent<MinMaxPercentSliderProps> = ({
75
75
  type='range'
76
76
  value={min}
77
77
  onInput={onMinChange}
78
- min={rangeMin}
79
- max={rangeMax}
78
+ min={`${rangeMin}`}
79
+ max={`${rangeMax}`}
80
80
  step={step}
81
81
  style={{ background, zIndex: 1, height: 0 }}
82
82
  />
@@ -84,8 +84,8 @@ export const MinMaxRangeSlider: FunctionComponent<MinMaxPercentSliderProps> = ({
84
84
  id='toSlider'
85
85
  type='range'
86
86
  value={max}
87
- min={rangeMin}
88
- max={rangeMax}
87
+ min={`${rangeMin}`}
88
+ max={`${rangeMax}`}
89
89
  step={step}
90
90
  onInput={onMaxChange}
91
91
  style={{ background, zIndex: zIndexTo }}
@@ -44,8 +44,8 @@ export const PercentInput: FunctionComponent<PercentInputProps> = ({
44
44
  <input
45
45
  type='number'
46
46
  step={0.1}
47
- min={0}
48
- max={100}
47
+ min='0'
48
+ max='100'
49
49
  value={internalPercentage}
50
50
  onInput={handleInputChange}
51
51
  lang='en'
@@ -303,7 +303,6 @@ const SelectedFilter = ({ handleRemoveValue, mutationFilter }: SelectedFilterPro
303
303
  return (
304
304
  <span
305
305
  key={mutationFilter.value.toString()}
306
- name={mutationFilter.value.toString()}
307
306
  className='center p-2 m-1 inline-flex text-black rounded-md'
308
307
  style={{
309
308
  backgroundColor: backgroundColorMap(mutationFilter),
@@ -35,6 +35,16 @@ describe('parseMutation', () => {
35
35
  input: 'ins_gene1:10:ACGT',
36
36
  expected: { type: 'aminoAcidInsertions', value: new InsertionClass('gene1', 10, 'ACGT') },
37
37
  },
38
+ {
39
+ name: 'should parse amino acid insertions in all upper case',
40
+ input: 'INS_GENE1:10:ACGT',
41
+ expected: { type: 'aminoAcidInsertions', value: new InsertionClass('GENE1', 10, 'ACGT') },
42
+ },
43
+ {
44
+ name: 'should parse amino acid insertions in all lower case',
45
+ input: 'ins_gene1:10:acgt',
46
+ expected: { type: 'aminoAcidInsertions', value: new InsertionClass('gene1', 10, 'acgt') },
47
+ },
38
48
  {
39
49
  name: 'should parse amino acid insertion with LAPIS-style wildcard',
40
50
  input: 'ins_gene1:10:?AC?GT',
@@ -78,6 +88,16 @@ describe('parseMutation', () => {
78
88
  input: 'gene1:A123-',
79
89
  expected: { type: 'aminoAcidMutations', value: new DeletionClass('gene1', 'A', 123) },
80
90
  },
91
+ {
92
+ name: 'should parse amino acid deletion in all upper case',
93
+ input: 'GENE1:A123-',
94
+ expected: { type: 'aminoAcidMutations', value: new DeletionClass('GENE1', 'A', 123) },
95
+ },
96
+ {
97
+ name: 'should parse amino acid deletion in all lower case',
98
+ input: 'gene1:a123-',
99
+ expected: { type: 'aminoAcidMutations', value: new DeletionClass('gene1', 'a', 123) },
100
+ },
81
101
  {
82
102
  name: 'should parse amino acid deletion without valueAtReference',
83
103
  input: 'gene1:123-',
@@ -123,6 +143,16 @@ describe('parseMutation', () => {
123
143
  input: 'gene1:A123T',
124
144
  expected: { type: 'aminoAcidMutations', value: new SubstitutionClass('gene1', 'A', 'T', 123) },
125
145
  },
146
+ {
147
+ name: 'should parse amino acid substitution in all upper case',
148
+ input: 'GENE1:A123T',
149
+ expected: { type: 'aminoAcidMutations', value: new SubstitutionClass('GENE1', 'A', 'T', 123) },
150
+ },
151
+ {
152
+ name: 'should parse amino acid substitution in all lower case',
153
+ input: 'gene1:a123t',
154
+ expected: { type: 'aminoAcidMutations', value: new SubstitutionClass('gene1', 'a', 't', 123) },
155
+ },
126
156
  {
127
157
  name: 'should return null for substitution with segment not in reference genome',
128
158
  input: 'notInReferenceGenome:A123T',
@@ -9,11 +9,12 @@ export const sequenceTypeFromSegment = (
9
9
  return isSingleSegmented(referenceGenome) ? 'nucleotide' : undefined;
10
10
  }
11
11
 
12
- if (referenceGenome.nucleotideSequences.some((sequence) => sequence.name === possibleSegment)) {
12
+ const segment = possibleSegment.toLowerCase();
13
+ if (referenceGenome.nucleotideSequences.some((sequence) => sequence.name.toLowerCase() === segment)) {
13
14
  return 'nucleotide';
14
15
  }
15
16
 
16
- if (referenceGenome.genes.some((gene) => gene.name === possibleSegment)) {
17
+ if (referenceGenome.genes.some((gene) => gene.name.toLowerCase() === segment)) {
17
18
  return 'amino acid';
18
19
  }
19
20
  return undefined;
@@ -30,7 +30,7 @@ export default {
30
30
  control: { type: 'check' },
31
31
  },
32
32
  confidenceIntervalMethods: {
33
- options: ['wilson'],
33
+ options: ['none', 'wilson'],
34
34
  control: { type: 'check' },
35
35
  },
36
36
  width: { control: 'text' },
@@ -73,7 +73,7 @@ export const TwoVariants: StoryObj<PrevalenceOverTimeProps> = {
73
73
  granularity: 'month',
74
74
  smoothingWindow: 0,
75
75
  views: ['bar', 'line', 'bubble', 'table'],
76
- confidenceIntervalMethods: ['wilson'],
76
+ confidenceIntervalMethods: ['none', 'wilson'],
77
77
  width: '100%',
78
78
  height: '700px',
79
79
  lapisDateField: 'date',
@@ -147,7 +147,7 @@ export const OneVariant: StoryObj<PrevalenceOverTimeProps> = {
147
147
  granularity: 'day',
148
148
  smoothingWindow: 7,
149
149
  views: ['bar', 'line', 'bubble', 'table'],
150
- confidenceIntervalMethods: ['wilson'],
150
+ confidenceIntervalMethods: ['none', 'wilson'],
151
151
  width: '100%',
152
152
  height: '700px',
153
153
  lapisDateField: 'date',
@@ -205,7 +205,7 @@ export const ShowsNoDataBanner: StoryObj<PrevalenceOverTimeProps> = {
205
205
  granularity: 'day',
206
206
  smoothingWindow: 7,
207
207
  views: ['bar', 'line', 'bubble', 'table'],
208
- confidenceIntervalMethods: ['wilson'],
208
+ confidenceIntervalMethods: ['none', 'wilson'],
209
209
  width: '100%',
210
210
  height: '700px',
211
211
  lapisDateField: 'date',
@@ -1,5 +1,5 @@
1
1
  import { type FunctionComponent } from 'preact';
2
- import { useContext, useState } from 'preact/hooks';
2
+ import { useContext, useEffect, useState } from 'preact/hooks';
3
3
 
4
4
  import { getPrevalenceOverTimeTableData } from './getPrevalenceOverTimeTableData';
5
5
  import PrevalenceOverTimeBarChart from './prevalence-over-time-bar-chart';
@@ -97,6 +97,16 @@ const PrevalenceOverTimeTabs: FunctionComponent<PrevalenceOverTimeTabsProps> = (
97
97
  const [confidenceIntervalMethod, setConfidenceIntervalMethod] = useState<ConfidenceIntervalMethod>(
98
98
  confidenceIntervalMethods.length > 0 ? confidenceIntervalMethods[0] : 'none',
99
99
  );
100
+
101
+ useEffect(() => {
102
+ setConfidenceIntervalMethod((confidenceIntervalMethod) => {
103
+ if (!confidenceIntervalMethods.includes(confidenceIntervalMethod)) {
104
+ return confidenceIntervalMethods.length > 0 ? confidenceIntervalMethods[0] : 'none';
105
+ }
106
+ return confidenceIntervalMethod;
107
+ });
108
+ }, [confidenceIntervalMethods]);
109
+
100
110
  const yAxisMaxConfig = { linear: yAxisMaxLinear, logarithmic: yAxisMaxLogarithmic };
101
111
 
102
112
  const getTab = (view: View) => {
@@ -0,0 +1,13 @@
1
+ {
2
+ "data": [
3
+ {
4
+ "count": 2468
5
+ }
6
+ ],
7
+ "info": {
8
+ "dataVersion": "1712315293",
9
+ "requestId": "4603a85e-ae5e-495d-aee5-778a3af862c1",
10
+ "requestInfo": "sars_cov-2_nextstrain_open on s1.int.genspectrum.org at 2024-04-24T15:31:40.596677441",
11
+ "reportTo": "Please report to https://github.com/GenSpectrum/LAPIS/issues in case you encounter any unexpected issues. Please include the request ID and the requestInfo in your report."
12
+ }
13
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "data": [
3
+ {
4
+ "count": 1234
5
+ }
6
+ ],
7
+ "info": {
8
+ "dataVersion": "1712315293",
9
+ "requestId": "4603a85e-ae5e-495d-aee5-778a3af862c1",
10
+ "requestInfo": "sars_cov-2_nextstrain_open on s1.int.genspectrum.org at 2024-04-24T15:31:40.596677441",
11
+ "reportTo": "Please report to https://github.com/GenSpectrum/LAPIS/issues in case you encounter any unexpected issues. Please include the request ID and the requestInfo in your report."
12
+ }
13
+ }
@@ -0,0 +1,81 @@
1
+ import { type Meta, type StoryObj } from '@storybook/preact';
2
+ import { expect, waitFor, within } from '@storybook/test';
3
+
4
+ import { AGGREGATED_ENDPOINT, LAPIS_URL } from '../../constants';
5
+ import { LapisUrlContext } from '../LapisUrlContext';
6
+ import denominatorData from './__mockData__/denominator.json';
7
+ import numeratorData from './__mockData__/numerator.json';
8
+ import { Statistics, type StatisticsProps } from './statistics';
9
+
10
+ const meta: Meta<StatisticsProps> = {
11
+ title: 'Visualization/Statistics',
12
+ component: Statistics,
13
+ argTypes: {
14
+ width: { control: 'text' },
15
+ height: { control: 'text' },
16
+ },
17
+ parameters: {
18
+ fetchMock: {
19
+ mocks: [
20
+ {
21
+ matcher: {
22
+ name: 'denominatorData',
23
+ url: AGGREGATED_ENDPOINT,
24
+ body: {
25
+ fields: [],
26
+ country: 'USA',
27
+ division: 'Alabama',
28
+ },
29
+ },
30
+ response: {
31
+ status: 200,
32
+ body: denominatorData,
33
+ },
34
+ },
35
+ {
36
+ matcher: {
37
+ name: 'numeratorData',
38
+ url: AGGREGATED_ENDPOINT,
39
+ body: {
40
+ fields: [],
41
+ country: 'USA',
42
+ },
43
+ },
44
+ response: {
45
+ status: 200,
46
+ body: numeratorData,
47
+ },
48
+ },
49
+ ],
50
+ },
51
+ },
52
+ };
53
+
54
+ export default meta;
55
+
56
+ export const Default: StoryObj<StatisticsProps> = {
57
+ render: (args) => (
58
+ <LapisUrlContext.Provider value={LAPIS_URL}>
59
+ <Statistics {...args} />
60
+ </LapisUrlContext.Provider>
61
+ ),
62
+ args: {
63
+ numeratorFilter: {
64
+ country: 'USA',
65
+ },
66
+ denominatorFilter: {
67
+ country: 'USA',
68
+ division: 'Alabama',
69
+ },
70
+ width: '100%',
71
+ height: '100%',
72
+ },
73
+ play: async ({ canvasElement }) => {
74
+ const canvas = within(canvasElement);
75
+
76
+ await waitFor(async () => {
77
+ await expect(canvas.getByText('1,234')).toBeInTheDocument();
78
+ await expect(canvas.getByText('50.00%')).toBeInTheDocument();
79
+ });
80
+ },
81
+ };
@@ -0,0 +1,78 @@
1
+ import { type FunctionComponent } from 'preact';
2
+ import { useContext } from 'preact/hooks';
3
+
4
+ import { queryGeneralStatistics } from '../../query/queryGeneralStatistics';
5
+ import { type LapisFilter } from '../../types';
6
+ import { LapisUrlContext } from '../LapisUrlContext';
7
+ import { ErrorBoundary } from '../components/error-boundary';
8
+ import { LoadingDisplay } from '../components/loading-display';
9
+ import { NoDataDisplay } from '../components/no-data-display';
10
+ import { ResizeContainer } from '../components/resize-container';
11
+ import { formatProportion } from '../shared/table/formatProportion';
12
+ import { useQuery } from '../useQuery';
13
+
14
+ export type StatisticsProps = {
15
+ width: string;
16
+ height: string;
17
+ numeratorFilter: LapisFilter;
18
+ denominatorFilter: LapisFilter;
19
+ };
20
+
21
+ export const Statistics: FunctionComponent<StatisticsProps> = (componentProps) => {
22
+ const { width, height } = componentProps;
23
+ const size = { height, width };
24
+
25
+ return (
26
+ <ErrorBoundary size={size}>
27
+ <ResizeContainer size={size}>
28
+ <StatisticsInner {...componentProps} />
29
+ </ResizeContainer>
30
+ </ErrorBoundary>
31
+ );
32
+ };
33
+
34
+ export const StatisticsInner: FunctionComponent<StatisticsProps> = (componentProps) => {
35
+ const { numeratorFilter, denominatorFilter } = componentProps;
36
+ const lapis = useContext(LapisUrlContext);
37
+
38
+ const { data, error, isLoading } = useQuery(async () => {
39
+ return queryGeneralStatistics(numeratorFilter, denominatorFilter, lapis);
40
+ }, [numeratorFilter, denominatorFilter, lapis]);
41
+
42
+ if (isLoading) {
43
+ return <LoadingDisplay />;
44
+ }
45
+
46
+ if (error !== null) {
47
+ throw error;
48
+ }
49
+
50
+ if (data === null) {
51
+ return <NoDataDisplay />;
52
+ }
53
+
54
+ return <MetricDataTabs data={data} />;
55
+ };
56
+
57
+ type MetricDataTabsProps = {
58
+ data: { count: number; proportion: number };
59
+ };
60
+
61
+ const MetricDataTabs: FunctionComponent<MetricDataTabsProps> = ({ data }) => {
62
+ const { count, proportion } = data;
63
+ return (
64
+ <div className='flex flex-col sm:flex-row rounded-md border-2 border-gray-100'>
65
+ <div className='stat'>
66
+ <div className='stat-title'>Sequences</div>
67
+ <div className='stat-value text-2xl sm:text-4xl'>{count.toLocaleString('en-us')}</div>
68
+ <div className='stat-desc'>The total number of sequenced samples</div>
69
+ </div>
70
+
71
+ <div className='stat'>
72
+ <div className='stat-title'>Overall proportion</div>
73
+ <div className='stat-value text-2xl sm:text-4xl'>{formatProportion(proportion)}</div>
74
+ <div className='stat-desc'>The proportion among all sequenced samples</div>
75
+ </div>
76
+ </div>
77
+ );
78
+ };
@@ -0,0 +1,18 @@
1
+ import { type LapisFilter } from '../types';
2
+ import { queryAggregateData } from './queryAggregateData';
3
+
4
+ export async function queryGeneralStatistics(
5
+ numeratorFilter: LapisFilter,
6
+ denominatorFilter: LapisFilter,
7
+ lapis: string,
8
+ signal?: AbortSignal,
9
+ ) {
10
+ const numeratorCount = await queryAggregateData(numeratorFilter, [], lapis, undefined, signal);
11
+ const denominatorCount = await queryAggregateData(denominatorFilter, [], lapis, undefined, signal);
12
+
13
+ if (numeratorCount.length === 0 || denominatorCount.length === 0) {
14
+ throw new Error('No data found for the given filters');
15
+ }
16
+
17
+ return { proportion: numeratorCount[0].count / denominatorCount[0].count, count: numeratorCount[0].count };
18
+ }
@@ -14,7 +14,7 @@ export interface MutationClass extends Mutation {
14
14
  }
15
15
 
16
16
  export const substitutionRegex =
17
- /^((?<segment>[A-Za-z0-9_-]+)(?=:):)?(?<valueAtReference>[A-Za-z])?(?<position>\d+)(?<substitutionValue>[A-Za-z.])?$/;
17
+ /^((?<segment>[A-Z0-9_-]+)(?=:):)?(?<valueAtReference>[A-Z])?(?<position>\d+)(?<substitutionValue>[A-Z.])?$/i;
18
18
 
19
19
  export interface Substitution extends Mutation {
20
20
  type: 'substitution';
@@ -68,7 +68,7 @@ export class SubstitutionClass implements MutationClass, Substitution {
68
68
  }
69
69
  }
70
70
 
71
- export const deletionRegex = /^((?<segment>[A-Za-z0-9_-]+)(?=:):)?(?<valueAtReference>[A-Za-z])?(?<position>\d+)(-)$/;
71
+ export const deletionRegex = /^((?<segment>[A-Z0-9_-]+)(?=:):)?(?<valueAtReference>[A-Z])?(?<position>\d+)(-)$/i;
72
72
 
73
73
  export interface Deletion extends Mutation {
74
74
  type: 'deletion';
@@ -119,7 +119,7 @@ export class DeletionClass implements MutationClass, Deletion {
119
119
  }
120
120
 
121
121
  export const insertionRegexp =
122
- /^ins_((?<segment>[A-Za-z0-9_-]+)(?=:):)?(?<position>\d+):(?<insertedSymbols>(([A-Za-z?]|(\.\*))+))$/i;
122
+ /^ins_((?<segment>[A-Z0-9_-]+)(?=:):)?(?<position>\d+):(?<insertedSymbols>(([A-Z?]|(\.\*))+))$/i;
123
123
 
124
124
  export interface Insertion extends Mutation {
125
125
  type: 'insertion';
@@ -46,7 +46,7 @@ const meta: Meta<Required<PrevalenceOverTimeProps>> = {
46
46
  control: { type: 'check' },
47
47
  },
48
48
  confidenceIntervalMethods: {
49
- options: ['wilson'],
49
+ options: ['none', 'wilson'],
50
50
  control: { type: 'check' },
51
51
  },
52
52
  width: { control: 'text' },
@@ -103,11 +103,11 @@ export class PrevalenceOverTimeComponent extends PreactLitAdapterWithGridJsStyle
103
103
 
104
104
  /**
105
105
  * A list of methods to calculate the confidence interval.
106
- * The option `none` is always available and disables confidence intervals.
107
106
  * Pass an empty array to disable the confidence interval selector.
107
+ * The first entry will be selected by default.
108
108
  */
109
109
  @property({ type: Array })
110
- confidenceIntervalMethods: ('wilson' | 'none')[] = ['wilson'];
110
+ confidenceIntervalMethods: ('wilson' | 'none')[] = ['none', 'wilson'];
111
111
 
112
112
  /**
113
113
  * The width of the component.
@@ -0,0 +1,95 @@
1
+ import { type Meta, type StoryObj } from '@storybook/web-components';
2
+ import { html } from 'lit';
3
+
4
+ import { withComponentDocs } from '../../../.storybook/ComponentDocsBlock';
5
+ import { AGGREGATED_ENDPOINT, LAPIS_URL } from '../../constants';
6
+ import denominatorData from '../../preact/statistic/__mockData__/denominator.json';
7
+ import numeratorData from '../../preact/statistic/__mockData__/numerator.json';
8
+ import { type StatisticsProps } from '../../preact/statistic/statistics';
9
+
10
+ import './gs-statistics';
11
+ import '../app';
12
+
13
+ const codeExample = `
14
+ <gs-statistics
15
+ numeratorFilter='{"country": "USA", "division": "Alabama}'
16
+ denominatorFilter='{"country": "USA"}'
17
+ width='100%'
18
+ height='700px'
19
+ ></gs-statistics>`;
20
+
21
+ const meta: Meta<Required<StatisticsProps>> = {
22
+ title: 'Visualization/Statistics',
23
+ component: 'gs-statistics',
24
+ argTypes: {
25
+ width: { control: 'text' },
26
+ height: { control: 'text' },
27
+ },
28
+ parameters: withComponentDocs({
29
+ fetchMock: {
30
+ mocks: [
31
+ {
32
+ matcher: {
33
+ name: 'denominatorData',
34
+ url: AGGREGATED_ENDPOINT,
35
+ body: {
36
+ fields: [],
37
+ country: 'USA',
38
+ },
39
+ },
40
+ response: {
41
+ status: 200,
42
+ body: denominatorData,
43
+ },
44
+ },
45
+ {
46
+ matcher: {
47
+ name: 'numeratorData',
48
+ url: AGGREGATED_ENDPOINT,
49
+ body: {
50
+ fields: [],
51
+ country: 'USA',
52
+ division: 'Alabama',
53
+ },
54
+ },
55
+ response: {
56
+ status: 200,
57
+ body: numeratorData,
58
+ },
59
+ },
60
+ ],
61
+ },
62
+ componentDocs: {
63
+ opensShadowDom: true,
64
+ expectsChildren: false,
65
+ codeExample,
66
+ },
67
+ }),
68
+ tags: ['autodocs'],
69
+ };
70
+
71
+ export default meta;
72
+
73
+ export const Default: StoryObj<Required<StatisticsProps>> = {
74
+ render: (args) => html`
75
+ <gs-app lapis="${LAPIS_URL}">
76
+ <gs-statistics
77
+ .numeratorFilter=${args.numeratorFilter}
78
+ .denominatorFilter=${args.denominatorFilter}
79
+ .width=${args.width}
80
+ .height=${args.height}
81
+ ></gs-statistics>
82
+ </gs-app>
83
+ `,
84
+ args: {
85
+ denominatorFilter: {
86
+ country: 'USA',
87
+ },
88
+ numeratorFilter: {
89
+ country: 'USA',
90
+ division: 'Alabama',
91
+ },
92
+ width: '100%',
93
+ height: '700px',
94
+ },
95
+ };