Skip to content

Commit

Permalink
feat(components): add mutation comparison with table
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasKellerer committed Mar 27, 2024
1 parent ec3b244 commit eadd9a7
Show file tree
Hide file tree
Showing 20 changed files with 1,166 additions and 21 deletions.
2 changes: 1 addition & 1 deletion components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"serve": "vite dev",
"test": "vitest",
"lint": "npm run lint:lit-analyzer && npm run lint:eslint",
"lint:eslint": "eslint 'src/**/*.ts'",
"lint:eslint": "eslint 'src/**/*.{ts,tsx}'",
"lint:lit-analyzer": "lit-analyzer",
"format": "prettier \"**/*.{cjs,html,js,json,md,ts,tsx}\" --ignore-path ./.eslintignore --write",
"check-format": "prettier --check \"**/*.{ts,tsx,json,md,mdx,mjs,cjs}\"",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import type { Meta, StoryObj } from '@storybook/web-components';
import { html } from 'lit';
import './mutation-comparison-component';
import '../../components/app';
import { LAPIS_URL, NUCLEOTIDE_INSERTIONS_ENDPOINT, NUCLEOTIDE_MUTATIONS_ENDPOINT } from '../../constants';
import { MutationComparisonProps } from '../../preact/mutationComparison/mutation-comparison';
import nucleotideMutationsSomeVariant from '../../preact/mutationComparison/__mockData__/nucleotideMutationsSomeVariant.json';
import nucleotideInsertionsSomeVariant from '../../preact/mutationComparison/__mockData__/nucleotideInsertionsSomeVariant.json';
import nucleotideMutationsOtherVariant from '../../preact/mutationComparison/__mockData__/nucleotideMutationsOtherVariant.json';
import nucleotideInsertionsOtherVariant from '../../preact/mutationComparison/__mockData__/nucleotideInsertionsOtherVariant.json';

const meta: Meta<MutationComparisonProps> = {
title: 'Visualization/Mutation comparison',
component: 'gs-mutation-comparison-component',
argTypes: {
variants: { control: 'object' },
sequenceType: {
options: ['nucleotide', 'amino acid'],
control: { type: 'radio' },
},
views: {
options: ['table', 'grid'],
control: { type: 'check' },
},
},
};

export default meta;

const Template: StoryObj<MutationComparisonProps> = {
render: (args) => html`
<div class="w-11/12 h-11/12">
<gs-app lapis="${LAPIS_URL}">
<gs-mutation-comparison-component
.variants=${args.variants}
.sequenceType=${args.sequenceType}
.views=${args.views}
></gs-mutation-comparison-component>
</gs-app>
</div>
`,
};

const dateTo = '2022-01-01';
const dateFrom = '2021-01-01';

export const Default = {
...Template,
args: {
variants: [
{
displayName: 'Some variant',
lapisFilter: { country: 'Switzerland', pangoLineage: 'B.1.1.7', dateTo },
},
{
displayName: 'Other variant',
lapisFilter: {
country: 'Switzerland',
pangoLineage: 'B.1.1.7',
dateFrom,
dateTo,
},
},
],
sequenceType: 'nucleotide',
views: ['table'],
},
parameters: {
fetchMock: {
mocks: [
{
matcher: {
name: 'nucleotideMutationsSomeVariant',
url: NUCLEOTIDE_MUTATIONS_ENDPOINT,
query: {
country: 'Switzerland',
pangoLineage: 'B.1.1.7',
dateTo,
minProportion: 0,
},
},
response: {
status: 200,
body: nucleotideMutationsSomeVariant,
},
},
{
matcher: {
name: 'nucleotideInsertionsSomeVariant',
url: NUCLEOTIDE_INSERTIONS_ENDPOINT,
query: { country: 'Switzerland', pangoLineage: 'B.1.1.7', dateTo },
},
response: {
status: 200,
body: nucleotideInsertionsSomeVariant,
},
},
{
matcher: {
name: 'nucleotideMutationsOtherVariant',
url: NUCLEOTIDE_MUTATIONS_ENDPOINT,
query: {
country: 'Switzerland',
pangoLineage: 'B.1.1.7',
dateFrom,
dateTo,
minProportion: 0,
},
},
response: {
status: 200,
body: nucleotideMutationsOtherVariant,
},
},
{
matcher: {
name: 'nucleotideInsertionsOtherVariant',
url: NUCLEOTIDE_INSERTIONS_ENDPOINT,
query: { country: 'Switzerland', pangoLineage: 'B.1.1.7', dateFrom, dateTo },
},
response: {
status: 200,
body: nucleotideInsertionsOtherVariant,
},
},
],
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { customElement, property } from 'lit/decorators.js';
import { SequenceType } from '../../types';
import { PreactLitAdapterWithGridJsStyles } from '../PreactLitAdapterWithGridJsStyles';
import {
MutationComparison,
MutationComparisonVariant,
View,
} from '../../preact/mutationComparison/mutation-comparison';

@customElement('gs-mutation-comparison-component')
export class MutationComparisonComponent extends PreactLitAdapterWithGridJsStyles {
@property({ type: Array })
variants: MutationComparisonVariant[] = [];

@property({ type: String })
sequenceType: SequenceType = 'nucleotide';

@property({ type: Array })
views: View[] = ['table'];

override render() {
return <MutationComparison variants={this.variants} sequenceType={this.sequenceType} views={this.views} />;
}
}

declare global {
interface HTMLElementTagNameMap {
'gs-mutation-comparison-component': MutationComparisonComponent;
}
}
3 changes: 2 additions & 1 deletion components/src/preact/components/chart.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export const ChartStory: StoryObj<GsChartProps> = {
options: {
animation: false,
scales: {
y: getYAxisScale('logarithmic') as any,
// @ts-expect-error-next-line -- chart.js typings are not complete with custom scales
y: getYAxisScale('logarithmic'),
},
},
},
Expand Down
3 changes: 2 additions & 1 deletion components/src/preact/components/chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ const GsChart = ({ configuration, yAxisScaleType }: GsChartProps) => {

useEffect(() => {
if (chartRef.current) {
chartRef.current.options.scales!.y = getYAxisScale(yAxisScaleType) as any;
// @ts-expect-error-next-line -- chart.js typings are not complete with custom scales
chartRef.current.options.scales!.y = getYAxisScale(yAxisScaleType);
chartRef.current.update();
}
}, [yAxisScaleType]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { expect, fn, waitFor, within } from '@storybook/test';
import { Meta, StoryObj } from '@storybook/preact';
import { CheckboxItem, CheckboxSelector, CheckboxSelectorProps } from './checkbox-selector';
import { useState } from 'preact/hooks';

const meta: Meta<CheckboxSelectorProps> = {
title: 'Component/Checkbox Selector',
Expand All @@ -16,15 +15,15 @@ export default meta;

export const CheckboxSelectorStory: StoryObj<CheckboxSelectorProps> = {
render: (args) => {
const [items, setItems] = useState(args.items);
let wrapperStateItems = args.items;

return (
<CheckboxSelector
items={items}
items={wrapperStateItems}
label={args.label}
setItems={(items: CheckboxItem[]) => {
args.setItems(items);
setItems(items);
wrapperStateItems = items;
}}
/>
);
Expand Down
2 changes: 1 addition & 1 deletion components/src/preact/components/table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default meta;

export const TableStory: StoryObj = {
render: (args) => {
return <Table data={args.data} columns={args.columns} pagination={false}></Table>;
return <Table data={args.data} columns={args.columns} pagination={false} />;
},
args: {
data: [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
{
"info": {
"dataVersion": 1709685650
},
"data": [
{
"insertion": "ins_21571:TTT",
"count": 1
},
{
"insertion": "ins_26654:T",
"count": 1
},
{
"insertion": "ins_28250:CTG",
"count": 25
},
{
"insertion": "ins_13915:T",
"count": 1
},
{
"insertion": "ins_27552:TT",
"count": 28
},
{
"insertion": "ins_2170:GAGCCAGGG",
"count": 3
},
{
"insertion": "ins_21305:GAGAGAGAGCAA",
"count": 1
},
{
"insertion": "ins_11305:ATTTCATTGTTT",
"count": 1
},
{
"insertion": "ins_28230:AAACTTGTCA",
"count": 1
},
{
"insertion": "ins_27687:T",
"count": 1
},
{
"insertion": "ins_27553:TGATCAG",
"count": 1
},
{
"insertion": "ins_29903:NNNNNNNNNNNNNNNNN",
"count": 1
},
{
"insertion": "ins_29727:GG",
"count": 1
},
{
"insertion": "ins_29053:A",
"count": 1
},
{
"insertion": "ins_27672:A",
"count": 1
},
{
"insertion": "ins_29735:TACAGT",
"count": 1
},
{
"insertion": "ins_1813:A",
"count": 1
},
{
"insertion": "ins_20793:A",
"count": 1
},
{
"insertion": "ins_11521:T",
"count": 1
},
{
"insertion": "ins_18219:A",
"count": 1
},
{
"insertion": "ins_29005:A",
"count": 1
},
{
"insertion": "ins_2842:AC",
"count": 1
},
{
"insertion": "ins_7021:T",
"count": 1
},
{
"insertion": "ins_14898:A",
"count": 1
},
{
"insertion": "ins_17019:T",
"count": 1
},
{
"insertion": "ins_4013:AGC",
"count": 1
},
{
"insertion": "ins_28250:CT",
"count": 1
},
{
"insertion": "ins_29593:AT",
"count": 2
},
{
"insertion": "ins_2857:A",
"count": 1
},
{
"insertion": "ins_21102:T",
"count": 1
},
{
"insertion": "ins_27231:TACATGGGGG",
"count": 2
},
{
"insertion": "ins_19983:T",
"count": 1
},
{
"insertion": "ins_29725:T",
"count": 1
},
{
"insertion": "ins_29759:CACCGA",
"count": 1
},
{
"insertion": "ins_27863:TT",
"count": 1
}
]
}

0 comments on commit eadd9a7

Please sign in to comment.