-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindexToShare.html
102 lines (92 loc) · 2.81 KB
/
indexToShare.html
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
98
99
100
101
102
<!--go by week, month, or year. We'll start by showing each month side-by-side. Also need to show legend-->
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.chart text {
fill: white;
font: 10px sans-serif;
text-anchor: end;
}
.run {
fill: red;
}
.ride {
fill: blue;
}
</style>
<head></head>
<body>
<!-- This is where we call the chart -->
<svg class="chart"></svg>
<div id = "myDiv"></div>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="https://d3js.org/d3-time.v1.min.js"></script>
<script>
//this is where we are defining dates
var startDate = new Date('January 1, 2017');
var endDate = new Date('December 31, 2017');
console.log(startDate.getTime());
console.log(endDate.getTime());
function getMonthsObject(startDate, endDate){
var months = d3.timeMonth.range(d3.timeMonth.floor(startDate), d3.timeMonth.ceil(endDate));
var monthsList = [];
for(i=0; i<months.length; i++){
monthsList.push({month:months[i], runTotal:0, rideTotal:0})
}
return monthsList
}
//this is where we make the access token happen through the URL locally
var getQueryString = function ( field, url ) {
var href = url ? url : window.location.href;
var reg = new RegExp( '[?&]' + field + '=([^&#]*)', 'i' );
var string = reg.exec(href);
return string ? string[1] : null;
};
//this is where we loop through the data
function getRuns(activities){
var monthsObject = getMonthsObject(startDate, endDate);
for(var j=0; j<monthsObject.length; j++){
monthsObject[j].rideTotal=15
monthsObject[j].runTotal=5
}
//this is the chart
console.log(monthsObject)
var data = monthsObject
var width = 420,
barHeight = 20;
var x = d3.scale.linear()
.domain([0, 100])
.range([0, 400]);
//setting the height and width of the chart
var chart = d3.select(".chart")
.attr("width", width)
.attr("height", barHeight * data.length);
//g is where the bar chart will be drawn
var bar = chart.selectAll("g")
.data(data)
.enter().append("g")
//translate to leave room for the top and left margins
.attr("transform", function(d, i) { return "translate(0," + i * barHeight + ")"; });
bar.append("rect")
.attr("class", "run")
.attr("width", function(d){return x(d.runTotal);
})
.attr("height", barHeight - 1);
bar.append("rect")
.attr("class", "ride")
.attr("width", function(d){return x(d.rideTotal);
})
.attr("height", barHeight - 1);
bar.append("text")
.attr("x", function(d) {return x(d.runTotal) - 3; })
.attr("y", barHeight / 2)
.attr("dy", ".35em")
.text(function(d) { return d.runTotal; });
bar.append("text")
.attr("x", function(d) {return x(d.rideTotal) - 3; })
.attr("y", barHeight / 2)
.attr("dy", ".35em")
.text(function(d) { return d.rideTotal; });
}
</script>
</body>