Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
src/req/renderer/containers/charts/refToVarSNPsDoughnut.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,114 @@ | ||
import * as React from "react"; | ||
import {Chart} from "chart.js"; | ||
|
||
import { VCF2JSONRow } from '../../../varScanMPileup2SNPVCF2JSON'; | ||
|
||
export interface RefToVarSNPsDoughnutProps | ||
{ | ||
snps : Array<VCF2JSONRow>; | ||
height : string; | ||
width : string; | ||
marginBottom : string; | ||
} | ||
|
||
export class RefToVarSNPsDoughnut extends React.Component<RefToVarSNPsDoughnutProps,{}> | ||
{ | ||
private chartRef = React.createRef<HTMLCanvasElement>(); | ||
private chart : Chart | undefined; | ||
|
||
public colours : Array<string>; | ||
|
||
public constructor(props : RefToVarSNPsDoughnutProps) | ||
{ | ||
super(props); | ||
|
||
const randomColour = require("randomcolor"); | ||
|
||
this.colours = new Array<string>(); | ||
|
||
for(let i = 0; i != 16; ++i) | ||
{ | ||
this.colours.push(randomColour()); | ||
} | ||
} | ||
|
||
public updateChart() | ||
{ | ||
if(this.props.snps) | ||
{ | ||
let data : Array<{label : string;num : number}> = new Array(); | ||
|
||
for(let i = 0; i != this.props.snps.length; ++i) | ||
{ | ||
if(this.props.snps[i].ref && this.props.snps[i].var) | ||
{ | ||
let label = `${this.props.snps[i].ref} to ${this.props.snps[i].var}`; | ||
|
||
let item = data.find((x) => { | ||
return x.label == label; | ||
}); | ||
|
||
if(item) | ||
{ | ||
item.num++; | ||
} | ||
|
||
else | ||
data.push({label : label,num : 1}); | ||
|
||
} | ||
} | ||
if(this.chartRef.current) | ||
{ | ||
if(this.chart) | ||
this.chart.destroy(); | ||
|
||
this.chart = new Chart(this.chartRef.current.getContext("2d")!,{ | ||
type: "doughnut", | ||
data : { | ||
datasets: [ | ||
{ | ||
data : data.map((x) => { | ||
return x.num | ||
}), | ||
backgroundColor : this.colours | ||
} | ||
], | ||
labels : data.map((x) => { | ||
return x.label; | ||
}) | ||
}, | ||
options : { | ||
animation : { | ||
animateRotate : true | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
|
||
public componentDidUpdate() | ||
{ | ||
this.updateChart(); | ||
} | ||
|
||
public componentDidMount() | ||
{ | ||
this.updateChart(); | ||
} | ||
|
||
public render() : JSX.Element | ||
{ | ||
return ( | ||
<div style={{ | ||
position : "relative", | ||
height : this.props.height, | ||
width : this.props.width, | ||
marginBottom : this.props.marginBottom | ||
}}> | ||
<canvas ref={this.chartRef}></canvas> | ||
</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