Commit 62cfdbe7 authored by Remi  PLANEL's avatar Remi PLANEL
Browse files

Export function that update wholeChromosome part and/or selectedChromosome

parent 096c403b
import { select, Selection } from "d3-selection"
import GeneComponent from "./sequence/gene"; import GeneComponent from "./sequence/gene";
import GenomeAxis from "./sequence/genome-axis"; import GenomeAxis from "./sequence/genome-axis";
import GlobalGenomeAxis from "./sequence/genome-axis-with-selection"; import BrushableGenomeAxis from "./sequence/brushable-genome-axis";
// D3
import { select, Selection } from "d3-selection";
import { drag } from "d3-drag"; import { drag } from "d3-drag";
//types //types
import { GenomeBrowserData } from "../types"; import { GeneData, GenomeBrowserData, GenericAxisData, BrushableAxisData } from "../types";
export default function () { export default function () {
const genomeAxis = GenomeAxis(); const selectedChromosomeAxis = GenomeAxis();
const geneComponent = GeneComponent(); const geneComponent = GeneComponent();
const globalGenomeAxisComponent = GlobalGenomeAxis(); const wholeChromosomeAxis = BrushableGenomeAxis();
let width = 900;
let genomesBrowserU: Selection<SVGElement, GenomeBrowserData, SVGElement, any> | null = null;
function genomeBrowser( function genomeBrowser(
_selection: Selection<SVGElement, Array<GenomeBrowserData>, HTMLElement, any>, _selection: Selection<SVGElement, Array<GenomeBrowserData>, HTMLElement, any>,
width: number, w: number,
height: number height: number
) { ) {
width = w;
_selection.each(function (_data: Array<GenomeBrowserData>) { _selection.each(function (_data: Array<GenomeBrowserData>) {
const container = select(this); const container = select(this);
const genomeBrowser = container const genomeBrowser = container
...@@ -44,11 +47,12 @@ export default function () { ...@@ -44,11 +47,12 @@ export default function () {
genomeBrowser.exit().remove(); genomeBrowser.exit().remove();
//UPDATE //UPDATE
const genomesBrowserU = genomeBrowser.merge(genomeBrowserE); genomesBrowserU = genomeBrowser.merge(genomeBrowserE);
genomesBrowserU genomesBrowserU
.select<SVGRectElement>("rect.genome-browser-background") .select<SVGRectElement>("rect.genome-browser-background")
.attr("width", width) .attr("width", width)
.attr("height", height).call( .attr("height", height)
.call(
drag<SVGRectElement, GenomeBrowserData>() drag<SVGRectElement, GenomeBrowserData>()
.on("start", (d: GenomeBrowserData) => { .on("start", (d: GenomeBrowserData) => {
...@@ -67,26 +71,40 @@ export default function () { ...@@ -67,26 +71,40 @@ export default function () {
} }
}) })
); );
genomesBrowserU.each(function (data) {
genomesBrowserU const { chromosome: { genes }, axis: { chromosome, global } } = data;
.select<SVGElement>("g.chromosome-axis") updateWholeChromosomeAxis(global);
.datum(({ axis: { global } }) => global) updateSelectedChromosome(chromosome, genes);
.call(globalGenomeAxisComponent, width, 0); });
});
}
function updateSelectedChromosome(axis: GenericAxisData, genes: GeneData[]) {
if (genomesBrowserU !== null) {
genomesBrowserU genomesBrowserU
.select<SVGElement>("g.axis") .select<SVGElement>("g.axis")
.datum(({ axis: { chromosome } }) => chromosome) .datum(axis)
.call(genomeAxis, width, 70); .call(selectedChromosomeAxis, width, 70);
genomesBrowserU genomesBrowserU
.select<SVGElement>(".genes") .select<SVGElement>(".genes")
.attr("transform", "translate(0, 80)") .attr("transform", "translate(0, 80)")
.datum(({ chromosome: { genes } }) => genes) .datum(genes)
.call(geneComponent, genomeAxis.scale(), 40) .call(geneComponent, selectedChromosomeAxis.scale(), 30)
}
};
function updateWholeChromosomeAxis(axis: BrushableAxisData) {
}); if (genomesBrowserU) {
genomesBrowserU
.select<SVGElement>("g.chromosome-axis")
.datum(({ axis: { global } }) => global)
.call(wholeChromosomeAxis, width, 0);
}
} }
genomeBrowser.updateSelectedChromosome = updateSelectedChromosome;
return genomeBrowser; return genomeBrowser;
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment