Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Remi PLANEL
bioviz-js
Commits
b6331c57
Commit
b6331c57
authored
Apr 02, 2019
by
Remi PLANEL
Browse files
Add layout linear-gene
parent
0e2e850d
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/scripts/layout/linear-gene.ts
0 → 100644
View file @
b6331c57
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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment