-
Notifications
You must be signed in to change notification settings - Fork 236
/
Copy pathbounds.js
38 lines (32 loc) · 1.09 KB
/
bounds.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
export default (config, xScale) => selection => {
const {
margin,
bound: { format: dateFormat },
label: { width: labelWidth },
line: { height: lineHeight },
} = config;
const bounds = selection.selectAll('.bound').data(d => d);
const numberRows = selection.data()[0].length;
bounds.exit().remove();
const boundTextGroup = bounds
.enter()
.filter((_, i) => !i)
.append('g')
.classed('bound', true)
.attr(
'transform',
`translate(${labelWidth}, ${lineHeight * numberRows + margin.top})`
);
boundTextGroup
.append('text')
.classed('start', true)
.text(dateFormat(xScale.domain()[0]));
boundTextGroup
.append('text')
.classed('end', true)
.attr('x', xScale.range()[1] - margin.right)
.attr('text-anchor', 'end')
.text(dateFormat(xScale.domain()[1]));
bounds.selectAll('.bound text.start').text(dateFormat(xScale.domain()[0]));
bounds.selectAll('.bound text.end').text(dateFormat(xScale.domain()[1]));
};