Skip to content

Commit

Permalink
feat(components): initial mutations over time component
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasKellerer committed Jul 17, 2024
1 parent 48ea46e commit 7007045
Show file tree
Hide file tree
Showing 32 changed files with 12,935 additions and 49 deletions.
15 changes: 14 additions & 1 deletion components/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"flatpickr": "^4.6.13",
"gridjs": "^6.2.0",
"lit": "^3.1.3",
"object-hash": "^3.0.0",
"preact": "^10.20.1",
"zod": "^3.23.0"
},
Expand All @@ -87,6 +88,7 @@
"@storybook/web-components": "^8.0.9",
"@storybook/web-components-vite": "^8.0.9",
"@types/node": "^20.12.7",
"@types/object-hash": "^3.0.6",
"@typescript-eslint/eslint-plugin": "^7.14.1",
"@typescript-eslint/parser": "^7.14.1",
"autoprefixer": "^10.4.19",
Expand Down
2 changes: 1 addition & 1 deletion components/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const LAPIS_URL = 'https://lapis.cov-spectrum.org/open/v2/';
export const LAPIS_URL = 'https://lapis.cov-spectrum.org/open/v2';

export const AGGREGATED_ENDPOINT = `${LAPIS_URL}/sample/aggregated`;
export const NUCLEOTIDE_MUTATIONS_ENDPOINT = `${LAPIS_URL}/sample/nucleotideMutations`;
Expand Down
4 changes: 3 additions & 1 deletion components/src/operator/FillMissingOperator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ describe('FillMissingOperator', () => {
const query = new FillMissingOperator(
child,
'id',
(ids) => [Math.min(...ids), Math.max(...ids)],
(ids) => {
return { min: Math.min(...ids), max: Math.max(...ids) };
},
(min, max) => {
const result = [];
for (let i = min; i <= max; i++) {
Expand Down
6 changes: 4 additions & 2 deletions components/src/operator/FillMissingOperator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ export class FillMissingOperator<Data, KeyToFill extends keyof Data> implements
constructor(
private child: Operator<Data>,
private keyField: KeyToFill,
private getMinMaxFn: (values: Iterable<Data[KeyToFill]>) => [Data[KeyToFill], Data[KeyToFill]] | null,
private getMinMaxFn: (
values: Iterable<Data[KeyToFill]>,
) => { min: Data[KeyToFill]; max: Data[KeyToFill] } | null,
private getAllRequiredKeysFn: (min: Data[KeyToFill], max: Data[KeyToFill]) => Data[KeyToFill][],
private defaultValueFn: (key: Data[KeyToFill]) => Data,
) {}
Expand All @@ -17,7 +19,7 @@ export class FillMissingOperator<Data, KeyToFill extends keyof Data> implements
if (minMax === null) {
return childEvaluated;
}
const [min, max] = minMax;
const { min, max } = minMax;
const requiredKeys = this.getAllRequiredKeysFn(min, max);
const content = childEvaluated.content;
for (const key of requiredKeys) {
Expand Down
16 changes: 12 additions & 4 deletions components/src/preact/mutationComparison/queryMutationData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ export function filterMutationData(
data: MutationData[],
displayedSegments: DisplayedSegment[],
displayedMutationTypes: DisplayedMutationType[],
) {
return data.map((mutationEntry) => ({
displayName: mutationEntry.displayName,
data: filterBySegmentAndMutationType(mutationEntry.data, displayedSegments, displayedMutationTypes),
}));
}

export function filterBySegmentAndMutationType(
data: SubstitutionOrDeletionEntry[],
displayedSegments: DisplayedSegment[],
displayedMutationTypes: DisplayedMutationType[],
) {
const byDisplayedSegments = (mutationEntry: SubstitutionOrDeletionEntry) => {
if (mutationEntry.mutation.segment === undefined) {
Expand All @@ -45,8 +56,5 @@ export function filterMutationData(
);
};

return data.map((mutationEntry) => ({
displayName: mutationEntry.displayName,
data: mutationEntry.data.filter(byDisplayedSegments).filter(byDisplayedMutationTypes),
}));
return data.filter(byDisplayedSegments).filter(byDisplayedMutationTypes);
}
Loading

0 comments on commit 7007045

Please sign in to comment.