-
Notifications
You must be signed in to change notification settings - Fork 192
/
index.js
51 lines (40 loc) · 1.26 KB
/
index.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
const container = document.querySelector('d3fc-svg');
const xScale = d3.scaleLinear().domain([0, 1]);
const yScale = d3.scaleLinear().domain([0, 1]);
const horizontalLine = fc
.annotationSvgLine()
.label('')
.xScale(xScale)
.yScale(yScale);
const verticalLine = fc
.annotationSvgLine()
.orient('vertical')
.label('')
.xScale(xScale)
.yScale(yScale);
const xAxis = d3.axisBottom(xScale);
const yAxis = d3.axisRight(yScale);
const xAxisJoin = fc.dataJoin('g', 'x-axis');
const yAxisJoin = fc.dataJoin('g', 'y-axis');
const svg = d3.select(container).select('svg');
d3.select(container)
.on('draw', () => {
svg.append('g')
.datum([0.15, 0.85])
.call(horizontalLine);
svg.append('g')
.datum([0.2, 0.4, 0.6, 0.8])
.call(verticalLine);
})
.on('measure', event => {
const { width, height } = event.detail;
xScale.range([10, width - 30]);
yScale.range([5, height - 20]);
xAxisJoin(svg, d => [d])
.attr('transform', `translate(0, ${height - 20})`)
.call(xAxis);
yAxisJoin(svg, d => [d])
.attr('transform', `translate(${width - 30}, 0)`)
.call(yAxis);
});
container.requestRedraw();