/
index.html
178 lines (157 loc) · 5.9 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
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.axis--x path {
display: none;
}
.line {
fill: none;
stroke: steelblue;
stroke-width: 1.5px;
}
div.tooltip {
position: relative;
text-align: center;
width: 653px;
height: 60px;
padding: 1px;
font: 12px sans-serif;
background: #eee;
border: 1px;
border-radius: 0px;
pointer-events: none;
}
.imgwrapper {
width: 80%;
display: block;
}
</style>
<body>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-90662312-1', 'auto');
ga('send', 'pageview');
</script>
<div class = "fluid-container">
<div class="row">
<h1 style="text-align: center;"> Commodity Prices and News Stories </h1>
<div class="col-md-12" id="commodity-graph">
<span></span>
<div style="width: 1020px; height: 800px; margin: 0 auto;"><svg></svg></div>
<h5 style="text-align: center;"> Keywords shown above for each month were found by tokenizing news stories,
stemming the tokens and then calculating a term frequency-inverse document frequency score.</h5>
</div>
<h1 style="text-align: center;"> Popular Keywords - Months when Price Fell </h1>
<div class="col-md-offset-2 col-md-10">
<div class="imgwrapper">
<img src="negativePrice.png" class="img-responsive center-block">
</div>
</div>
<div class="col-md-12">
<h5 style="text-align: center;"> The word clouds represent words that were popular for each month the price rose/fell from the previous month. The size of the word is relative to the number of times it featured in a news headline during that month.</h5>
</div>
<h1 style="text-align: center;"> Popular Keywords - Months when Price Rose </h1>
<div class="col-md-offset-2 col-md-10">
<div class="imgwrapper">
<img src="positivePrice.png" class="img-responsive center-block">
</div>
</div>
<div class="col-md-12">
<h3 style="text-align: center;"> Datasets Used</h3>
<ul>
<li> IMF Primary Commodity Prices - Monthly Data: http://www.imf.org/external/np/res/commod/index.aspx</li>
<li> Daily News for Stock Market Prediction - Kaggle - Dataset created by Aaron7Sun - https://www.kaggle.com/aaron7sun/stocknews</li>
</ul>
</div>
</div>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script type="text/javascript">
var margin = {top:20, right: 20, bottom: 30, left: 50},
width = 1020 - margin.left - margin.right,
height=680 - margin.top - margin.bottom;
var parseTime = d3.timeParse("%Y-%m");
var x = d3.scaleTime()
.rangeRound([0, width]);
var y = d3.scaleLinear()
.rangeRound([height, 0]);
var div = d3.select("span").append("div")
.attr("class", "tooltip")
.style("opacity", 0);
var line = d3.line()
.x(function(d) {return x(d.Date); })
.y(function(d) {return y(d.Price); })
var svg = d3.select("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
g = svg.append("g").attr("transform", "translate(" + margin.left + "," + margin.top + ")");
d3.csv("visualisation_data.csv", function(d) {
d.Date = parseTime(d.Date);
d.Price = +d.Price;
return d;
}, function(error, data) {
if (error) throw error;
x.domain(d3.extent(data, function(d) {return d.Date; }));
y.domain(d3.extent(data, function(d) {return d.Price }));
g.append("g")
.attr("class", "axis axis--y")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x));
g.append("g")
.attr("class", "axis axis--y")
.call(d3.axisLeft(y))
.append("text")
.attr("fill", "#000")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", "0.71em")
.style("text-anchor", "end")
.text("Price ($)");
g.append("path")
.datum(data)
.attr("class", "line")
.attr("d", line);
svg.selectAll("dot")
.data(data)
.enter().append("circle")
.attr("r", 3)
.attr("cx", function(d) { return x(d.Date); })
.attr("cy", function(d) { return y(d.Price); })
.attr("transform", "translate(" + margin.left + "," + margin.top + ")")
.on("mouseover", function(d) {
d3.select(this).transition()
.duration(200)
.style("fill", "orange");
div.transition()
.duration(200)
.style("opacity", .9);
div.html("<b>Date:</b><br>" + formatDate(d.Date) + "<br/><b>Keywords:</b><br>" + d.Keywords)
.style("left", function(d) { if (d3.event.pageX < 700) {
displacement = (d3.event.pageX - 100) + "px"
} else {
displacement = (d3.event.pageX - 600) + "px"
}
return displacement
})
.style("top", (d3.event.pageY - 28) + "px");
})
.on("mouseout", function(d) {
d3.select(this).transition()
.duration(500)
.style("fill", "black");
div.transition()
.duration(500)
.style("opacity", 0);
});
})
var formatDate = d3.timeFormat("%B-%Y")
</script>
</body>
</html>