Skip to content
Snippets Groups Projects
Commit 9cb35d92 authored by Remi  PLANEL's avatar Remi PLANEL
Browse files

change gene fill color + add background line

parent b6103c9a
No related branches found
No related tags found
No related merge requests found
Pipeline #129908 waiting for manual action with stages
in 4 minutes and 23 seconds
...@@ -23,27 +23,28 @@ const svgRef = ref<SVGElement | null>(null) ...@@ -23,27 +23,28 @@ const svgRef = ref<SVGElement | null>(null)
const structureHeight = ref(130) const structureHeight = ref(130)
const geneHeight = ref(40) const geneHeight = ref(40)
const linkHeight = ref(20) const linkHeight = ref(20)
const geneColor = ref("#faf4e6")
const margin = ref<PlotMargin>({ const margin = ref<PlotMargin>({
marginTop: 5, marginTop: 5,
marginRight: 7, marginRight: 20,
marginBottom: 5, marginBottom: 5,
marginLeft: 7, marginLeft: 20,
}) })
const gbContainer = ref(null) const gbContainer = ref(null)
const geneToHighlight = ref<string | null>(null) const geneToHighlight = ref<string | null>(null)
const snackbar = ref(false) const snackbar = ref(false)
const color = d3.scaleOrdinal(d3.schemeCategory10); // const color = d3.scaleOrdinal(d3.schemeCategory10);
const domain = computed(() => { const domain = computed(() => {
const genes = toValue(computedGenes) const genes = toValue(computedGenes)
return genes?.map(d => { return d.gene }) return genes?.map(d => { return d.gene })
}) })
const innerPadding = ref<number>(8) const innerPadding = ref<number>(30)
const totalGeneLength = computed(() => { const totalGeneLength = computed(() => {
const genes = toValue(computedGenes) const genes = toValue(computedGenes)
return genes.reduce((acc, curr) => { return genes.reduce((acc, curr) => {
return acc + (curr?.size ?? 10) + innerPadding.value return acc + (curr?.size ?? 10)
}, 0) }, 0) + innerPadding.value * (genes.length - 1)
}) })
...@@ -75,7 +76,7 @@ const computedGenes = computed<StructureOperonGene[]>(() => { ...@@ -75,7 +76,7 @@ const computedGenes = computed<StructureOperonGene[]>(() => {
const genes = toValue(genesProps) const genes = toValue(genesProps)
if (genes !== null && genes?.length > 0) { if (genes !== null && genes?.length > 0) {
let currentSumSize = 0 let currentSumSize = 0
return genes.map((d) => { return genes.map((d,i) => {
const size = d?.size ?? 10 const size = d?.size ?? 10
const position = currentSumSize const position = currentSumSize
currentSumSize = position + size + innerPadding.value currentSumSize = position + size + innerPadding.value
...@@ -255,16 +256,31 @@ function draw() { ...@@ -255,16 +256,31 @@ function draw() {
if (svgRef.value !== null) { if (svgRef.value !== null) {
const svg = d3.select<SVGElement, any>(svgRef.value); const svg = d3.select<SVGElement, any>(svgRef.value);
const { marginLeft, marginTop } = toValue(margin) const { marginLeft, marginRight } = toValue(margin)
const gx = createOrSelect<SVGGElement, SVGElement>(svg, 'g', 'x-axis') // const gx = createOrSelect<SVGGElement, SVGElement>(svg, 'g', 'x-axis')
const gOperon = createOrSelect<SVGGElement, SVGElement>(svg, "g", "operon") const gOperon = createOrSelect<SVGGElement, SVGElement>(svg, "g", "operon")
const yScaleVal = toValue(yScale)
const geneHeightVal = toValue(geneHeight)
const gOperonLine = createOrSelect<SVGLineElement, SVGGElement>(gOperon, "line", "chromosome-line")
gOperonLine
.attr("x1", -marginLeft)
.attr("y1", yScaleVal.gene + geneHeightVal / 2)
.attr("x2", computedPlotWidth.value + marginRight)
.attr("y2", yScaleVal.gene + geneHeightVal / 2)
.attr("stroke", "black")
.attr("stroke-width", "2px")
gOperon gOperon
.attr("transform", `translate(${marginLeft},0)`) .attr("transform", `translate(${marginLeft},0)`)
.call(drawLinks) .call(drawLinks)
.call(drawGenes) .call(drawGenes)
.call(drawStructure) .call(drawStructure)
.call(drawGenesLabel) .call(drawGenesLabel)
} }
} }
...@@ -340,6 +356,11 @@ function drawStructure(operonGroup: d3.Selection<SVGGElement, any, SVGElement | ...@@ -340,6 +356,11 @@ function drawStructure(operonGroup: d3.Selection<SVGGElement, any, SVGElement |
function drawGenes(operonGroup: d3.Selection<SVGGElement, any, SVGElement | null, any>) { function drawGenes(operonGroup: d3.Selection<SVGGElement, any, SVGElement | null, any>) {
const genesWithCoordVal = toValue(geneNodesWithY) const genesWithCoordVal = toValue(geneNodesWithY)
const genes = genesWithCoordVal const genes = genesWithCoordVal
const genesSelection = operonGroup const genesSelection = operonGroup
.selectAll("g.gene-grp") // get all "existing" lines in svg .selectAll("g.gene-grp") // get all "existing" lines in svg
.data<StructureOperonGeneWithCoordinate>(genes) // sync them with our data .data<StructureOperonGeneWithCoordinate>(genes) // sync them with our data
...@@ -360,6 +381,7 @@ function drawGenes(operonGroup: d3.Selection<SVGGElement, any, SVGElement | null ...@@ -360,6 +381,7 @@ function drawGenes(operonGroup: d3.Selection<SVGGElement, any, SVGElement | null
geneToHighlight.value = null geneToHighlight.value = null
}) })
gGene gGene
.append("path") .append("path")
.classed("gene", true) .classed("gene", true)
...@@ -383,11 +405,11 @@ function drawGenes(operonGroup: d3.Selection<SVGGElement, any, SVGElement | null ...@@ -383,11 +405,11 @@ function drawGenes(operonGroup: d3.Selection<SVGGElement, any, SVGElement | null
const genePathSelection = genesSelection const genePathSelection = genesSelection
.select("path.gene") .select("path.gene")
// .attr("stroke", d => d?.highlight ? d3.color(color(d.system))?.darker() : null) .attr("stroke", "black")
.attr("stroke-width", d => d?.highlight ? 4 : 0) .attr("stroke-width", 2)
genePathSelection genePathSelection
.transition() .transition()
.attr("fill", d => d?.highlight ? d3.color(color(d.system))?.brighter() : color(d.system)) .attr("fill", d => d?.highlight ? d3.color(geneColor.value)?.darker() : geneColor.value)
genePathSelection genePathSelection
.attr("d", d => drawGene(d).toString()) .attr("d", d => drawGene(d).toString())
......
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