-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
188 lines (152 loc) · 6.63 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>BlackRock Coding Exercise</title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/custom_css.css" rel = "stylesheet">
</head>
<body>
<div class = "navbar navbar-inverse">
<div class="container">
<div class="navbar-brand">Coding samples</div>
</div>
</div>
<div class = "container">
<div class="col-lg-12">
<h4>Hover over to see the CSS transition to a change in size color and a shadow</h4>
<p><a class="box box-hover" role="box">Hover here !!</a></p>
</div>
</div>
<div class = "divider"></div>
<div id = "container" class = "container">
<div class = "col-lg-5 pull-left">
<h4>HTML object Box1 - Hover swaps the boxes</h4>
<p><div class="box1" onmouseover="swapboxes()">Box1</div></p>
</div>
<div class =" col-lg-5 pull-right">
<h4>HTML object Box2 - Hover swaps the boxes</h4>
<p><div class="box2" onmouseover="swapboxes()">Box2</div></p>
</div>
</div>
</div>
<div class = "divider"></div>
<div class = "container">
<div class = "col-lg-12">
<h4>Hover over the bars to see the transition from one bar to another</h4>
<div id = "svg-container"></div>
<script src="js/d3.min.js" charset="utf-8"></script>
<script type="text/javascript">
// Create Global Variable
var dataset;
dataset = [{name: "Honda",mpg: 37, color: "pink"},
{name: "Scion iQ",mpg: 37, color: "plum"},
{name: "Toyota Prius",mpg: 50, color: "powderblue"},
{name: "Ford C-MAX Hybrid",mpg: 43, color: "paleturquoise"},
{name: "BMW Sports Wagon",mpg: 35, color: "palegreen"}];
// Call function
Graph(dataset);
// Create function
function Graph(input) {
// Declare Variables
var margin = {top: 60, right: 60, bottom: 60, left:120},
w = 900 - margin.left - margin.right,
h = 400 - margin.top - margin.bottom;
//Create X Scale for bar graph
var xScale = d3.scale.ordinal()
.domain(input.map(function (d){ return d.name;}))
.rangeRoundBands([0, w], 0.6);
//Create Y Scale for bar graph
var yScale = d3.scale.linear()
.domain([0,d3.max(input, function(d) { return d.mpg; })])
.range([h, 0]);
//Create X Axis
var xAxis = d3.svg.axis()
.scale(xScale)
.orient("bottom");
//Create Y Axis
var yAxis = d3.svg.axis()
.scale(yScale)
.orient('left');
var gap = 10;
//Create SVG element
var svg = d3.select("#svg-container")
.append("svg")
.attr("width", w + margin.left + margin.right)
.attr("height", h + margin.top + margin.bottom + gap*2)
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
//Create X axis
svg.append("g")
.attr("class", "axis x")
.attr("transform", "translate(0," + h + ")")
.call(xAxis);
//Create Title
svg.append("text")
.attr("x", w / 2 )
.attr("y", -20)
.style("text-anchor", "middle")
.text("Car mpg Chart");
//Create X axis label
svg.append("text")
.attr("x", w / 2 )
.attr("y", h + margin.bottom)
.attr("font-family", "sans-serif")
.attr("font-size", "14px")
.style("text-anchor", "middle")
.text("Name of the Car");
//Create Y axis
svg.append("g")
.attr("class", "axis y")
.call(yAxis);
//Create Y axis label
svg.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 0-margin.left)
.attr("x",0 - (h / 2))
.attr("dy", "1em")
.style("text-anchor", "middle")
.text("Miles per Gallon");
//Add rectangles
svg.selectAll(".bar")
.data(input)
.enter()
.append("rect")
.attr("class", "bar")
.attr("x", function(d) { return xScale(d.name); })
.attr("y", function(d) { return yScale(d.mpg) })
.attr("width", xScale.rangeBand())
.attr("height", function(d) { return h - yScale(d.mpg)})
.style("fill", function(d) { return d.color})
.on("mouseover", function() { d3.select(this).style("fill", "orange");})
.on("mouseout", function(d) { d3.select(this).style("fill", function(d) { return d.color});});
};
</script>
</div>
</div>
<div class = "divider"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/d3.min.js" charset="utf-8"></script>
<!--Script for swapping boxes-->
<script type="text/javascript">
function swapboxes() {
//Get the HTML Collection of elements with class name box1 and box2
var box1_Collection = document.getElementById('container').getElementsByClassName('box1');
var box2_Collection = document.getElementById('container').getElementsByClassName('box2');
//get the first elemenst in them
var box1 = box1_Collection.item(0)
var box2 = box2_Collection.item(0)
//Declare a helper to swap box1 and box2
var temp = document.createElement("div")
box1.parentNode.insertBefore(temp,box1)
box2.parentNode.insertBefore(box1,box2)
temp.parentNode.insertBefore(box2,temp)
//delete the helper
temp.parentNode.removeChild(temp)
}
</script>
</body>
</html>