generated from DS4200-Sec2-F22/ic-13
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogram.js
73 lines (58 loc) · 2.23 KB
/
program.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
// First, we need a frame
const FRAME_HEIGHT = 500;
const FRAME_WIDTH = 500;
const MARGINS = {left: 50, right: 50, top: 50, bottom: 50};
const VIS_HEIGHT = FRAME_HEIGHT - MARGINS.left - MARGINS.right;
const VIS_WIDTH = FRAME_WIDTH - MARGINS.top - MARGINS.bottom;
// create the frame of the scatterplot
const FRAME1 = d3.select("#graph1")
.append("svg")
.attr("height", FRAME_HEIGHT)
.attr("width", FRAME_WIDTH)
.attr("class", "frame");
// create the frame of the scatterplot
const FRAME2 = d3.select("#graph2")
.append("svg")
.attr("height", FRAME_HEIGHT)
.attr("width", FRAME_WIDTH)
.attr("class", "frame");
// build the scatterplot onto the canvas using the data in the given file
function build_graph1() {
// read data from the file
d3.csv("data/city-hall.csv").then((data) => {
// adjust the data to the pixels of the canvas
// since number above 10 connot be inputed this number is hardcoded
const X_MAX = 10
const X_SCALE = d3.scaleLinear()
.domain([0, X_MAX])
.range([0, VIS_HEIGHT]);
// adjust the data according to the pixels of the canvas
// since numbers above 10 cannot eb inputted this number is hardcoded
const Y_MAX = 10
const Y_SCALE = d3.scaleLinear()
.domain([0, Y_MAX])
.range([VIS_HEIGHT, 0]);
// make the x_axis
FRAME1.append("g")
.attr("transform", "translate(" + MARGINS.left + "," + (VIS_HEIGHT + MARGINS.top) + ")")
.call(d3.axisBottom(X_SCALE).ticks(10))
.attr("font-size", "10px")
// make the Y-axis
FRAME1.append("g")
.attr("transform", "translate(" + MARGINS.left + "," + MARGINS.top + ")")
.call(d3.axisLeft(Y_SCALE).ticks(10))
.attr("font-size", "10px");
const csvToChartData = csv =>{//shape data to include in timeseries graph
const lines = csv.trim().split('\n');
lines.shift(); //removes titles
return lines.map(line =>{
const[datetime_measured,total_demand] = line.split(',');
return{
x:datetime_measured,
y:total_demand
};
})
}
});
};
build_graph1();