-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.html
235 lines (170 loc) · 4.67 KB
/
index.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<!DOCTYPE html>
<meta charset="utf-8">
<style>
div.tooltip {
position: absolute;
text-align: center;
width: 75px;
height: 75px;
padding: 2px;
font: 12px sans-serif;
background: beige;
border: 0px;
border-radius: 8px;
pointer-events: none;
}
svg {
padding: 20px;
background-color: white;
font-size: 12px;
}
.y_axis path {
stroke-width:1.5px;
fill:none;
stroke:red;
}
.y_axis text {
stroke: #666;
stroke-width: 1.5px;
}
.x_axis text {
stroke: #666;
stroke-width: 1.5px;
}
.x_axis line {
stroke-width: 2px;
stroke: red;
shape-rendering: crispEdges
}
.x_axis path {
fill: none;
stroke: red;
shape-rendering: crispEdges
}
.dot {
shape-rendering: geometricPrecision;
stroke: black;
stroke-width: 1px;
}
</style>
<header></header>
<body>
<div id='viz'>
</div>
</body>
<script src="./d3/d3.js"></script>
<script type="text/javascript">
var width = 1200;
var height = 300;
var buffer_width = 30;
var plot_w = width - 2*buffer_width
var plot_h = height - 2*buffer_width
var legendRectSize = 18;
var legendSpacing = 4;
var max_x_val = -Infinity
var min_x_val = Infinity
var max_y_val = -Infinity
var min_y_val = 0
var color = d3.scale.category20();
var div = d3.select("#viz").append("div")
.attr("class", "tooltip")
.style("opacity", 0);
var timeFormat = d3.time.format('%Y-%m-%d');
var time_domain = [];
var x_scale = d3.time.scale();
var y_scale = d3.scale.linear();
var x_axis = d3.svg.axis();
var y_axis = d3.svg.axis().orient("right");
// Getting data
var svg = d3.select('body')
.append('svg')
.attr('width', width)
.attr('height', height)
///.style("background-color", 'purple')
//.append('g')
d3.csv("./data/lobbyistByClient.csv", function(error, data) {
var times = []
// change string (from CSV) into number format
data.forEach(function(d) {
d.hiredDate = timeFormat.parse(d.Date); // returns a Date
d.client = d.Client;
d.cumulative = +d.Cumulative;
if (d.cumulative > max_y_val) {
max_y_val = d.cumulative
};
times.push(d.hiredDate)
});
////////////////////////////////////////////////////////////////////
y_scale.domain([0,max_y_val])
.range([height-buffer_width, buffer_width])
y_axis.scale(y_scale)
svg.append("g")
.attr("class", "y_axis")
.attr("transform", "translate(" + (width-buffer_width) + ",0)")
.call(y_axis);
/// building scale and axis
var max_date = new Date(Math.max.apply(null, times))
var min_date = new Date(Math.min.apply(null, times))
time_domain.push(min_date,max_date)
x_scale.domain(time_domain)
.rangeRound([buffer_width,buffer_width+plot_w])
//.nice()
//.ticks(d3.time.month, 3)
x_axis.scale(x_scale)
svg.append("g")
.attr("class", "x_axis")
.attr("transform", "translate(0," + (height-buffer_width+3) + ")")
.call(x_axis);
////////////////////////////////////////////////////////////////////
//console.log(time_domain)
var color_domain = d3.map(data, function(d){return d.client;}).keys() //gets unique values for industry
color.domain(color_domain)
x = svg.selectAll(".dot")
.data(data)
.enter().append("circle")
.attr("class", "dot")
.attr("r", 4)
.attr('client',function(d) {return d.client})
.attr("cx", function(d,i) {return x_scale(times[i])})
.attr("cy", function(d) {return y_scale(d.cumulative)})
.style("fill", function(d){return color(d.client)})
.on("mouseover", function(d) {
div.transition()
.duration(100)
.style("opacity", .9);
div.html(d.Date + "\n" + d.client)
.style("left", (d3.event.pageX + 5) + "px")
.style("top", (d3.event.pageY - 28) + "px")})
.on("mouseout", function(d) {
div.transition()
.duration(200)
.style("opacity", .0);
//div.html(d.Date + "\n" + d.client)
// .style("opacity", 0);
//.style("height", (get_tooltip_height(d.industry.length)));
});
x.on('click', function() {
var ind = d3.select(this).attr('client')
d3.selectAll("[client='" + String(ind) + "']").transition()
.attr('r',8)
.attr('opacity',1)
.duration(300)
x.filter(function(d,i) {
return d.client != ind})
.transition()
.attr('r',4)
.attr('opacity',.5)
.duration(300)
});
});
// These two buttons don't stop the timer,
// just set flags to indicate that these two elements should stop/start:
// var startbtn=d3.select("#startbtn");
// startbtn.on("click", function() {
// }
// });
// var stopbtn=d3.select("#stopbtn");
// stopbtn.on("click", function() {
// }
// });
</script>