forked from nicgirault/circosJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender.js
53 lines (45 loc) · 1.29 KB
/
render.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import forEach from 'lodash/forEach'
import sortBy from 'lodash/sortBy'
import renderLayout from './layout/render'
export default function render (ids = [], removeTracks, circos) {
const renderAll = ids.length === 0
const svg = circos.svg
.attr('width', circos.conf.width)
.attr('height', circos.conf.height)
if (removeTracks) {
forEach(circos.tracks, (track, trackId) => {
svg.select('.' + trackId).remove()
})
}
let translated = svg.select('.all')
if (translated.empty()) {
translated = svg.append('g')
.attr('class', 'all')
.attr(
'transform',
`translate(
${parseInt(circos.conf.width / 2)},
${parseInt(circos.conf.height / 2)}
)`
)
}
forEach(circos.tracks, (track, trackId) => {
if (renderAll || trackId in ids) {
track.render(circos, translated, trackId)
}
})
if (renderAll || 'layout' in ids) {
renderLayout(translated, circos)
}
// re-order tracks and layout according to z-index
const trackContainers = svg.selectAll('.all > g').remove()
const sortedTrackContainers = sortBy(
trackContainers._groups[0],
(elt) => elt.getAttribute('z-index')
)
svg.select('.all').selectAll('g')
.data(sortedTrackContainers)
.enter()
.append((d) => d)
return circos
}