Commit b6331c57 authored by Remi  PLANEL's avatar Remi PLANEL
Browse files

Add layout linear-gene

parent 0e2e850d
import { GeneData, PositionedGeneData } from "../component/sequence/gene";
import { scaleLinear } from "d3-scale";
export default function linearGene(
data: Array<GeneData>,
width: number,
geneOffset: number
) {
const sumLength = data.reduce((accum, gene) => accum + gene.length, 0);
const sumGeneOffset = (data.length - 1) * geneOffset;
const xScale = scaleLinear().domain([0, sumLength - sumGeneOffset]).range([0, width])
return data.reduce(function (
accum: PositionedGeneData[],
gene: GeneData,
i: number,
data: GeneData[]
) {
if (i > 0) {
const previousGene = accum[i - 1];
accum.push({
...gene,
position: {
x: previousGene.position.x + previousGene.position.width + geneOffset,
y: 0,
width: xScale(gene.length)
}
});
return accum;
}
else {
accum.push({
...gene,
position: {
x: 0,
y: 0,
width: xScale(gene.length)
}
});
return accum;
}
}, []);
}
\ No newline at end of file
Supports Markdown
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