-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(components): add mutation comparison venn diagram
- Loading branch information
1 parent
74308f3
commit c490020
Showing
12 changed files
with
733 additions
and
119 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
components/src/preact/mutationComparison/mutation-comparison-venn.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { FunctionComponent } from 'preact'; | ||
import { ArcSlice, extractSets, VennDiagramController } from 'chartjs-chart-venn'; | ||
import { useEffect, useRef } from 'preact/hooks'; | ||
import { ActiveElement, Chart, ChartConfiguration, ChartEvent, registerables } from 'chart.js'; | ||
import GsChart from '../components/chart'; | ||
import { MutationData } from './mutation-comparison'; | ||
import { Dataset } from '../../operator/Dataset'; | ||
|
||
Chart.register(...registerables, VennDiagramController, ArcSlice); | ||
|
||
export interface MutationComparisonVennProps { | ||
data: Dataset<MutationData>; | ||
} | ||
|
||
export const MutationComparisonVenn: FunctionComponent<MutationComparisonVennProps> = ({ data }) => { | ||
const divRef = useRef<HTMLDivElement>(null); | ||
const noElementSelectedMessage = 'You have no elements selected. Click in the venn diagram to select.'; | ||
useEffect(() => { | ||
if (divRef.current === null) { | ||
return; | ||
} | ||
divRef.current.innerText = noElementSelectedMessage; | ||
}, [divRef]); | ||
|
||
if (data.content.length > 5) { | ||
return <div>Too many variants to display. Maximum are five. </div>; | ||
} | ||
|
||
const sets = extractSets( | ||
data.content | ||
.map((mutationData) => { | ||
return { | ||
...mutationData, | ||
data: mutationData.data.filter((mutationEntry) => mutationEntry.type !== 'insertion'), | ||
}; | ||
}) | ||
.map((mutationData) => { | ||
return { | ||
label: mutationData.displayName, | ||
values: mutationData.data.map((mutationEntry) => mutationEntry.mutation.toString()), | ||
}; | ||
}), | ||
); | ||
|
||
const config: ChartConfiguration = { | ||
type: 'venn', | ||
data: sets, | ||
options: { | ||
scales: { | ||
x: { | ||
ticks: { | ||
color: 'black', | ||
font: { | ||
size: 20, | ||
}, | ||
}, | ||
}, | ||
y: { | ||
ticks: { | ||
color: 'blue', | ||
font: { | ||
size: 20, | ||
}, | ||
}, | ||
}, | ||
}, | ||
events: ['click'], | ||
onClick(_: ChartEvent, elements: ActiveElement[]) { | ||
if (elements.length === 0) { | ||
divRef.current!.innerText = noElementSelectedMessage; | ||
} | ||
}, | ||
backgroundColor: '#f5f5f5', | ||
animation: false, | ||
layout: { | ||
padding: 30, | ||
}, | ||
plugins: { | ||
legend: { | ||
display: false, | ||
}, | ||
tooltip: { | ||
filter: (tooltipItem: { dataset: { data: { values: string[] }[] }; dataIndex: number }) => { | ||
const values = tooltipItem.dataset.data[tooltipItem.dataIndex].values; | ||
|
||
divRef.current!.innerText = `Mutations: ${values.join(', ')}` || ''; | ||
return false; | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
return ( | ||
<> | ||
<GsChart configuration={config} /> | ||
<div class='flex flex-wrap break-words m-2' ref={divRef}> | ||
{''} | ||
</div> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters