forked from nicgirault/circosJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcircos.js
111 lines (102 loc) · 2.83 KB
/
circos.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import defaultsDeep from 'lodash/defaultsDeep'
import forEach from 'lodash/forEach'
import isArray from 'lodash/isArray'
import map from 'lodash/map'
import {select} from 'd3-selection'
import Layout from './layout/index'
import render from './render'
import Text from './tracks/Text'
import Highlight from './tracks/Highlight'
import Histogram from './tracks/Histogram'
import Chords from './tracks/Chords'
import Heatmap from './tracks/Heatmap'
import Line from './tracks/Line'
import Scatter from './tracks/Scatter'
import Stack from './tracks/Stack'
import {initClipboard} from './clipboard'
const defaultConf = {
width: 700,
height: 700,
container: 'circos',
defaultTrackWidth: 10
}
class Core {
constructor (conf) {
this.tracks = {}
this._layout = null
this.conf = defaultsDeep(conf, defaultConf)
const container = select(this.conf.container);
this.svg = container.append('svg')
if (select('body').select('.circos-tooltip').empty()) {
this.tip = select('body').append('div')
.attr('class', 'circos-tooltip')
.style('opacity', 0)
} else {
this.tip = select('body').select('.circos-tooltip')
}
this.clipboard = initClipboard(this.conf.container)
}
removeTracks (trackIds) {
if (typeof (trackIds) === 'undefined') {
map(this.tracks, (track, id) => {
this.svg.select('.' + id).remove()
})
this.tracks = {}
} else if (typeof (trackIds) === 'string') {
this.svg.select('.' + trackIds).remove()
delete this.tracks[trackIds]
} else if (isArray(trackIds)) {
forEach(trackIds, function (trackId) {
this.svg.select('.' + trackId).remove()
delete this.tracks[trackId]
})
} else {
console.warn('removeTracks received an unhandled attribute type')
}
return this
}
layout (data, conf) {
this._layout = new Layout(conf, data)
return this
}
chords (id, data, conf) {
this.tracks[id] = new Chords(this, conf, data)
return this
}
heatmap (id, data, conf) {
this.tracks[id] = new Heatmap(this, conf, data)
return this
}
highlight (id, data, conf) {
this.tracks[id] = new Highlight(this, conf, data)
return this
}
histogram (id, data, conf) {
this.tracks[id] = new Histogram(this, conf, data)
return this
}
line (id, data, conf) {
this.tracks[id] = new Line(this, conf, data)
return this
}
scatter (id, data, conf) {
this.tracks[id] = new Scatter(this, conf, data)
return this
}
stack (id, data, conf) {
this.tracks[id] = new Stack(this, conf, data)
return this
}
text (id, data, conf) {
this.tracks[id] = new Text(this, conf, data)
return this
}
render (ids, removeTracks) {
render(ids, removeTracks, this)
}
}
const Circos = (conf) => {
const instance = new Core(conf)
return instance
}
module.exports = Circos