@genspectrum/dashboard-components 0.9.0 → 0.9.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.
- package/dist/components.js +49 -28
- package/dist/components.js.map +1 -1
- package/dist/style.css +2 -2
- package/package.json +1 -1
- package/src/preact/components/no-data-display.tsx +2 -2
- package/src/preact/mutationsOverTime/mutations-over-time-grid.tsx +2 -3
- package/src/preact/relativeGrowthAdvantage/relative-growth-advantage.stories.tsx +91 -0
- package/src/preact/relativeGrowthAdvantage/relative-growth-advantage.tsx +6 -0
- package/src/query/queryRelativeGrowthAdvantage.ts +61 -24
- package/standalone-bundle/dashboard-components.js +2035 -2013
- package/standalone-bundle/dashboard-components.js.map +1 -1
- package/standalone-bundle/style.css +1 -1
package/dist/style.css
CHANGED
|
@@ -3416,9 +3416,9 @@ input.tab:checked + .tab-content,
|
|
|
3416
3416
|
.peer:hover ~ .peer-hover\:visible {
|
|
3417
3417
|
visibility: visible;
|
|
3418
3418
|
}
|
|
3419
|
-
@container (min-width:
|
|
3419
|
+
@container (min-width: 2rem) {
|
|
3420
3420
|
|
|
3421
|
-
.\@\[
|
|
3421
|
+
.\@\[2rem\]\:visible {
|
|
3422
3422
|
visibility: visible;
|
|
3423
3423
|
}
|
|
3424
3424
|
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type FunctionComponent } from 'preact';
|
|
2
2
|
|
|
3
|
-
export const NoDataDisplay: FunctionComponent = () => {
|
|
3
|
+
export const NoDataDisplay: FunctionComponent<{ message?: string }> = ({ message = 'No data available.' }) => {
|
|
4
4
|
return (
|
|
5
5
|
<div className='h-full w-full rounded-md border-2 border-gray-100 p-2 flex items-center justify-center'>
|
|
6
|
-
<div>
|
|
6
|
+
<div>{message}</div>
|
|
7
7
|
</div>
|
|
8
8
|
);
|
|
9
9
|
};
|
|
@@ -43,7 +43,6 @@ const MutationsOverTimeGrid: FunctionComponent<MutationsOverTimeGridProps> = ({
|
|
|
43
43
|
gridTemplateRows: `repeat(${shownMutations.length}, 24px)`,
|
|
44
44
|
gridTemplateColumns: `${MUTATION_CELL_WIDTH_REM}rem repeat(${dates.length}, minmax(0.05rem, 1fr))`,
|
|
45
45
|
}}
|
|
46
|
-
className='@container'
|
|
47
46
|
>
|
|
48
47
|
{shownMutations.map((mutation, rowIndex) => {
|
|
49
48
|
return (
|
|
@@ -122,9 +121,9 @@ const ProportionCell: FunctionComponent<{
|
|
|
122
121
|
backgroundColor: getColorWithingScale(value.proportion, colorScale),
|
|
123
122
|
color: getTextColorForScale(value.proportion, colorScale),
|
|
124
123
|
}}
|
|
125
|
-
className={`w-full h-full text-center hover:font-bold text-xs group`}
|
|
124
|
+
className={`w-full h-full text-center hover:font-bold text-xs group @container`}
|
|
126
125
|
>
|
|
127
|
-
<span className='invisible @[
|
|
126
|
+
<span className='invisible @[2rem]:visible'>{formatProportion(value.proportion, 0)}</span>
|
|
128
127
|
</div>
|
|
129
128
|
</Tooltip>
|
|
130
129
|
</div>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type StoryObj } from '@storybook/preact';
|
|
2
|
+
import { expect, waitFor, within } from '@storybook/test';
|
|
2
3
|
|
|
3
4
|
import denominator from './__mockData__/denominatorFilter.json';
|
|
4
5
|
import numerator from './__mockData__/numeratorFilter.json';
|
|
@@ -99,3 +100,93 @@ export const Primary: StoryObj<RelativeGrowthAdvantageProps> = {
|
|
|
99
100
|
},
|
|
100
101
|
},
|
|
101
102
|
};
|
|
103
|
+
|
|
104
|
+
export const TooFewDataToComputeGrowthAdvantage: StoryObj<RelativeGrowthAdvantageProps> = {
|
|
105
|
+
...Primary,
|
|
106
|
+
args: {
|
|
107
|
+
...Primary.args,
|
|
108
|
+
numeratorFilter: {
|
|
109
|
+
country: 'Switzerland',
|
|
110
|
+
pangoLineage: 'B.1.1.7',
|
|
111
|
+
dateFrom: '2021-02-28',
|
|
112
|
+
dateTo: '2021-03-01',
|
|
113
|
+
},
|
|
114
|
+
denominatorFilter: {
|
|
115
|
+
country: 'Switzerland',
|
|
116
|
+
dateFrom: '2021-02-28',
|
|
117
|
+
dateTo: '2021-03-01',
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
parameters: {
|
|
121
|
+
fetchMock: {
|
|
122
|
+
mocks: [
|
|
123
|
+
{
|
|
124
|
+
matcher: {
|
|
125
|
+
name: 'numeratorFilter',
|
|
126
|
+
url: AGGREGATED_ENDPOINT,
|
|
127
|
+
body: {
|
|
128
|
+
country: 'Switzerland',
|
|
129
|
+
pangoLineage: 'B.1.1.7',
|
|
130
|
+
dateFrom: '2021-02-28',
|
|
131
|
+
dateTo: '2021-03-01',
|
|
132
|
+
fields: ['date'],
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
response: {
|
|
136
|
+
status: 200,
|
|
137
|
+
body: {
|
|
138
|
+
data: [
|
|
139
|
+
{
|
|
140
|
+
date: '2021-02-28',
|
|
141
|
+
count: 5,
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
date: '2021-03-01',
|
|
145
|
+
count: 5,
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
matcher: {
|
|
153
|
+
name: 'denominatorFilter',
|
|
154
|
+
url: AGGREGATED_ENDPOINT,
|
|
155
|
+
body: {
|
|
156
|
+
country: 'Switzerland',
|
|
157
|
+
dateFrom: '2021-02-28',
|
|
158
|
+
dateTo: '2021-03-01',
|
|
159
|
+
fields: ['date'],
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
response: {
|
|
163
|
+
status: 200,
|
|
164
|
+
body: {
|
|
165
|
+
data: [
|
|
166
|
+
{
|
|
167
|
+
date: '2021-02-28',
|
|
168
|
+
count: 5,
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
date: '2021-03-01',
|
|
172
|
+
count: 7,
|
|
173
|
+
},
|
|
174
|
+
],
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
],
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
play: async ({ canvasElement }) => {
|
|
182
|
+
const canvas = within(canvasElement);
|
|
183
|
+
|
|
184
|
+
await waitFor(() => {
|
|
185
|
+
const notEnoughDataMessage = canvas.queryByText(
|
|
186
|
+
'It was not possible to estimate the relative growth advantage',
|
|
187
|
+
{ exact: false },
|
|
188
|
+
);
|
|
189
|
+
return expect(notEnoughDataMessage).toBeVisible();
|
|
190
|
+
});
|
|
191
|
+
},
|
|
192
|
+
};
|
|
@@ -3,6 +3,7 @@ import { useContext, useState } from 'preact/hooks';
|
|
|
3
3
|
|
|
4
4
|
import RelativeGrowthAdvantageChart from './relative-growth-advantage-chart';
|
|
5
5
|
import {
|
|
6
|
+
NotEnoughDataToComputeFitError,
|
|
6
7
|
queryRelativeGrowthAdvantage,
|
|
7
8
|
type RelativeGrowthAdvantageData,
|
|
8
9
|
} from '../../query/queryRelativeGrowthAdvantage';
|
|
@@ -62,6 +63,11 @@ export const RelativeGrowthAdvantageInner: FunctionComponent<RelativeGrowthAdvan
|
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
if (error !== null) {
|
|
66
|
+
if (error instanceof NotEnoughDataToComputeFitError) {
|
|
67
|
+
return (
|
|
68
|
+
<NoDataDisplay message='It was not possible to estimate the relative growth advantage due to insufficient data in the specified filter.' />
|
|
69
|
+
);
|
|
70
|
+
}
|
|
65
71
|
throw error;
|
|
66
72
|
}
|
|
67
73
|
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import { FetchAggregatedOperator } from '../operator/FetchAggregatedOperator';
|
|
2
2
|
import { MapOperator } from '../operator/MapOperator';
|
|
3
3
|
import { RenameFieldOperator } from '../operator/RenameFieldOperator';
|
|
4
|
+
import { UserFacingError } from '../preact/components/error-display';
|
|
4
5
|
import { type LapisFilter } from '../types';
|
|
5
6
|
import { getMinMaxTemporal, TemporalCache, type YearMonthDayClass } from '../utils/temporalClass';
|
|
6
7
|
|
|
7
8
|
export type RelativeGrowthAdvantageData = Awaited<ReturnType<typeof queryRelativeGrowthAdvantage>>;
|
|
8
9
|
|
|
10
|
+
export class NotEnoughDataToComputeFitError extends Error {
|
|
11
|
+
constructor() {
|
|
12
|
+
super('Not enough data to compute computeFit');
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
9
16
|
export async function queryRelativeGrowthAdvantage<LapisDateField extends string>(
|
|
10
17
|
numerator: LapisFilter,
|
|
11
18
|
denominator: LapisFilter,
|
|
@@ -54,6 +61,37 @@ export async function queryRelativeGrowthAdvantage<LapisDateField extends string
|
|
|
54
61
|
requestData.k.push(numeratorCounts.get(d.date) ?? 0);
|
|
55
62
|
}
|
|
56
63
|
});
|
|
64
|
+
|
|
65
|
+
const responseData = await computeFit(generationTime, maxDate, minDate, requestData, signal);
|
|
66
|
+
|
|
67
|
+
const transformed = {
|
|
68
|
+
...responseData,
|
|
69
|
+
estimatedProportions: {
|
|
70
|
+
...responseData.estimatedProportions,
|
|
71
|
+
t: responseData.estimatedProportions.t.map((t) => minDate.addDays(t)),
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
const observedProportions = transformed.estimatedProportions.t.map(
|
|
75
|
+
(t) => (numeratorCounts.get(t) ?? 0) / (denominatorCounts.get(t) ?? 0),
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
...transformed,
|
|
80
|
+
observedProportions,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async function computeFit(
|
|
85
|
+
generationTime: number,
|
|
86
|
+
maxDate: YearMonthDayClass,
|
|
87
|
+
minDate: YearMonthDayClass,
|
|
88
|
+
requestData: {
|
|
89
|
+
t: number[];
|
|
90
|
+
k: number[];
|
|
91
|
+
n: number[];
|
|
92
|
+
},
|
|
93
|
+
signal: AbortSignal | undefined,
|
|
94
|
+
) {
|
|
57
95
|
const requestPayload = {
|
|
58
96
|
config: {
|
|
59
97
|
alpha: 0.95,
|
|
@@ -66,15 +104,29 @@ export async function queryRelativeGrowthAdvantage<LapisDateField extends string
|
|
|
66
104
|
},
|
|
67
105
|
data: requestData,
|
|
68
106
|
};
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
107
|
+
|
|
108
|
+
let response;
|
|
109
|
+
try {
|
|
110
|
+
response = await fetch('https://cov-spectrum.org/api/v2/computed/model/chen2021Fitness', {
|
|
111
|
+
method: 'POST',
|
|
112
|
+
headers: {
|
|
113
|
+
'Content-Type': 'application/json',
|
|
114
|
+
},
|
|
115
|
+
body: JSON.stringify(requestPayload),
|
|
116
|
+
signal,
|
|
117
|
+
});
|
|
118
|
+
} catch {
|
|
119
|
+
throw new UserFacingError(
|
|
120
|
+
'Failed to compute relative growth advantage',
|
|
121
|
+
'Could not connect to the server that computes the relative growth advantage. Please try again later.',
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (!response.ok) {
|
|
126
|
+
throw new NotEnoughDataToComputeFitError();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return (await response.json()) as {
|
|
78
130
|
estimatedAbsoluteNumbers: {
|
|
79
131
|
t: number[];
|
|
80
132
|
variantCases: number[];
|
|
@@ -109,21 +161,6 @@ export async function queryRelativeGrowthAdvantage<LapisDateField extends string
|
|
|
109
161
|
};
|
|
110
162
|
};
|
|
111
163
|
};
|
|
112
|
-
const transformed = {
|
|
113
|
-
...responseData,
|
|
114
|
-
estimatedProportions: {
|
|
115
|
-
...responseData.estimatedProportions,
|
|
116
|
-
t: responseData.estimatedProportions.t.map((t) => minDate.addDays(t)),
|
|
117
|
-
},
|
|
118
|
-
};
|
|
119
|
-
const observedProportions = transformed.estimatedProportions.t.map(
|
|
120
|
-
(t) => (numeratorCounts.get(t) ?? 0) / (denominatorCounts.get(t) ?? 0),
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
return {
|
|
124
|
-
...transformed,
|
|
125
|
-
observedProportions,
|
|
126
|
-
};
|
|
127
164
|
}
|
|
128
165
|
|
|
129
166
|
function toYearMonthDay(d: { date: string | null; count: number }) {
|