-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
32 lines (28 loc) · 1.12 KB
/
main.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
import {axisBottom, axisLeft} from 'https://unpkg.com/d3-axis@^1?module'
import {select} from 'https://unpkg.com/d3-selection@^1?module'
import {scaleLinear} from 'https://unpkg.com/d3-scale@^2?module'
import {json, csv} from 'https://unpkg.com/d3-fetch@^1?module'
const containerElement = document.querySelector('#graph').parentElement
const HEIGHT = 250
const WIDTH = containerElement.clientWidth
const GUTTER = 30
const MARGIN = 10
const xScale = scaleLinear().domain([0, 110]).range([0, WIDTH-GUTTER-MARGIN])
const xAxis = axisBottom(xScale).ticks(10)
const yScale = scaleLinear().domain([1023, 90]).range([0, HEIGHT-GUTTER-MARGIN])
const yAxis = axisLeft(yScale).ticks(6)
select('#graph').remove()
const graph = select(containerElement)
.append('svg')
.attr('id', 'graph')
.attr('viewBox', [0, 0, WIDTH, HEIGHT])
.attr('height', '250')
.attr('width', '100%')
.attr('margin', '0 auto')
.attr('preserveAspectRatio', 'xMinYMin')
graph.append('g')
.attr('transform', `translate(${GUTTER}, ${HEIGHT-GUTTER})`)
.call(xAxis)
graph.append('g')
.attr('transform', `translate(${GUTTER}, ${MARGIN})`)
.call(yAxis)