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

add small coef to align text in genes

parent 2d8fe0e4
No related branches found
No related tags found
1 merge request!25Draft: Resolve "Add genome browser in wiki instead of svg"
Pipeline #114164 passed
...@@ -3,7 +3,7 @@ import * as d3 from "d3"; ...@@ -3,7 +3,7 @@ import * as d3 from "d3";
import { useDisplay } from 'vuetify' import { useDisplay } from 'vuetify'
import { useElementSize } from '@vueuse/core' import { useElementSize } from '@vueuse/core'
const { width } = useDisplay() const { width } = useDisplay()
const height = ref(200) const height = ref(150)
const color = d3.scaleOrdinal([-1, 1], d3.schemeSet1); const color = d3.scaleOrdinal([-1, 1], d3.schemeSet1);
const data = ref([ const data = ref([
{ start: 20, end: 30, strand: 1, name: "toto" }, { start: 20, end: 30, strand: 1, name: "toto" },
...@@ -21,10 +21,14 @@ const computedWidth = computed(() => { ...@@ -21,10 +21,14 @@ const computedWidth = computed(() => {
const marginLeftGb = ref(10) const marginLeftGb = ref(10)
const marginRightGb = ref(10) const marginRightGb = ref(10)
const marginBottomGb = ref(10)
const innerWidth = computed(() => { const innerWidth = computed(() => {
return computedWidth.value - marginLeftGb.value - marginRightGb.value return computedWidth.value - marginLeftGb.value - marginRightGb.value
}) })
const innerHeigth = computed(() => {
return height.value - marginBottomGb.value
})
const minRange = ref(0) const minRange = ref(0)
const maxRange = ref(innerWidth.value) const maxRange = ref(innerWidth.value)
...@@ -40,7 +44,7 @@ const xScale = ref(d3.scaleLinear() ...@@ -40,7 +44,7 @@ const xScale = ref(d3.scaleLinear()
); );
const yScale = ref(d3.scaleLinear() const yScale = ref(d3.scaleLinear()
.domain([-1, 1]) .domain([-1, 1])
.range([0, height.value])); .range([0, innerHeigth.value]));
...@@ -55,7 +59,7 @@ const computedData = computed(() => { ...@@ -55,7 +59,7 @@ const computedData = computed(() => {
const width = xScale.value(gene.end) - xScale.value(gene.start) const width = xScale.value(gene.end) - xScale.value(gene.start)
const height = yScale.value(-0.5) const height = yScale.value(-0.5)
const x = xScale.value(gene.start) + marginLeftGb.value const x = xScale.value(gene.start) + marginLeftGb.value
const y = gene.strand < 0 ? yScale.value(0.25) : yScale.value(-0.75) const y = gene.strand < 0 ? yScale.value(0.25) - marginBottomGb.value : yScale.value(-0.75) - marginBottomGb.value
return { return {
...gene, ...gene,
...@@ -97,7 +101,10 @@ function positionText(selection) { ...@@ -97,7 +101,10 @@ function positionText(selection) {
d3.select(this) d3.select(this)
.text('') .text('')
} else { } else {
const x = d.width / 2 - textWidth / 2 const halfW = d.width / 2
const halfTw = textWidth / 2
const k = d.height / 8
const x = d.strand > 0 ? halfW - halfTw - k : halfW - halfTw + k
d3.select(this) d3.select(this)
.attr("transform", `translate(${x},${d.height / 2})`) .attr("transform", `translate(${x},${d.height / 2})`)
} }
...@@ -114,6 +121,7 @@ function drawGenes(genesSelection) { ...@@ -114,6 +121,7 @@ function drawGenes(genesSelection) {
g.append("path") g.append("path")
g.append("text") g.append("text")
.attr("fill", "white") .attr("fill", "white")
.attr("dominant-baseline", "middle")
g.append("title") g.append("title")
}, },
update => { update => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment