forked from nicgirault/circosJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaxes.js
97 lines (90 loc) · 2.58 KB
/
axes.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
import range from 'lodash/range'
import reduce from 'lodash/reduce'
import {arc} from 'd3-shape'
import logger from './logger'
const _buildAxisData = (value, axesGroup, conf) => {
return {
value: value,
thickness: axesGroup.thickness || 1,
color: axesGroup.color || '#d3d3d3',
opacity: axesGroup.opacity || conf.opacity
}
}
export const _buildAxesData = (conf) => {
return reduce(conf.axes, (aggregator, axesGroup) => {
if (!axesGroup.position && !axesGroup.spacing) {
logger.warn('Skipping axe group with no position and spacing defined')
return aggregator
}
if (axesGroup.position) {
aggregator.push(_buildAxisData(axesGroup.position, axesGroup, conf))
}
if (axesGroup.spacing) {
const builtAxes = range(
axesGroup.start || conf.cmin,
axesGroup.end || conf.cmax,
axesGroup.spacing
)
.map((value) => {
return _buildAxisData(value, axesGroup, conf)
})
return aggregator.concat(builtAxes)
}
return aggregator
}, [])
}
export const renderAxes = (parentElement, conf, instance, scale) => {
const axes = _buildAxesData(conf)
const axis = arc()
.innerRadius((d) => {
return conf.direction === 'in'
? conf.outerRadius - scale(d.value)
: conf.innerRadius + scale(d.value)
})
.outerRadius((d) => {
return conf.direction === 'in'
? conf.outerRadius - scale(d.value)
: conf.innerRadius + scale(d.value)
})
.startAngle(0)
.endAngle((d) => d.length)
const selection = parentElement
.selectAll('.axis')
.data((blockData) => {
const block = instance._layout.blocks[blockData.key]
return axes.map((d) => {
return {
value: d.value,
thickness: d.thickness,
color: d.color,
opacity: d.opacity,
block_id: blockData.key,
length: block.end - block.start
}
})
})
.enter()
.append('path')
.attr('opacity', (d) => d.opacity)
.attr('class', 'axis')
.attr('d', axis)
.attr('stroke-width', (d) => d.thickness)
.attr('stroke', (d) => d.color)
if (conf.showAxesTooltip) {
selection.on('mouseover', (d, i) => {
instance.tip
.html(d.value)
.transition()
.style('opacity', 0.9)
.style('left', (event.pageX) + 'px')
.style('top', (event.pageY - 28) + 'px')
})
selection.on('mouseout', (d, i) => {
instance.tip
.transition()
.duration(500)
.style('opacity', 0)
})
}
return selection
}