-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
231 lines (194 loc) · 6.74 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
<html>
<head>
<style>
.graphContainer {
overflow-x: scroll;
overflow-y: scroll;
}
</style>
</head>
<body>
Select Input File : <input type="file" id="file-input"/>
<div id="chartContainer-1" class="graphContainer"></div>
<div id="chartContainer-2" class="graphContainer"> <H1> Speaker Distribution</H1></div>
<div id="chartContainer-3" class="graphContainer"></div>
<div id="chartContainer-4" class="graphContainer"></div>
<script src="lib/d3.js"></script>
<script src="lib/dimple.min.js"></script>
<script src="lib/sampleData.js"></script>
<script type="text/javascript">
function readSingleFile(e) {
var file = e.target.files[0];
if (!file) {
return;
}
var reader = new FileReader();
reader.onload = function (e) {
var contents = e.target.result;
loadGraph(contents);
};
reader.readAsText(file);
}
function displayContents(contents) {
var element = document.getElementById('file-content');
element.innerHTML = contents;
}
document.getElementById('file-input')
.addEventListener('change', readSingleFile, false);
function graphForContainer1(data) {
var nestedData = {};
var locale = "en-us";
data.forEach(function (d) {
var dateObj = new Date(d["TimeStamp"]);
//var month = dateObj.toLocaleString(locale, { month: "short" });
var summerizedDate = dateObj.getDate() + '/' + (dateObj.getMonth() + 1) + '/' + dateObj.getFullYear();
if (!nestedData[summerizedDate]) {
nestedData[summerizedDate] = {};
nestedData[summerizedDate][d["Medium"]] = 1;
} else {
if (nestedData[summerizedDate][d["Medium"]]) {
nestedData[summerizedDate][d["Medium"]] += 1;
} else {
nestedData[summerizedDate][d["Medium"]] = 1;
}
}
});
var summerizedData = [];
var dataObj;
for (i in nestedData) {
Object.keys(nestedData[i]).forEach(function (key) {
dataObj = {
TimeStamp: i,
}
dataObj['Medium'] = key;
dataObj['Views'] = nestedData[i][key];
summerizedData.push(dataObj);
});
}
var svg = dimple.newSvg("#chartContainer-1", '100%', 400);
// Create the chart as usual
var myChart = new dimple.chart(svg, summerizedData);
//myChart.setBounds(100, 80, 100, 300)
var x = myChart.addTimeAxis("x", "TimeStamp", "%d/%m/%Y", "%B %d");
var y = myChart.addMeasureAxis("y", "Views");
myChart.addSeries("Medium", dimple.plot.bubble);
var s = myChart.addSeries("Medium", dimple.plot.line);
s.lineMarkers = true;
myChart.addLegend(180, 10, 360, 20, "right");
myChart.draw();
}
function graphForContainer2(data) {
var nestedData = {};
data.forEach(function (d) {
if (!d["Speaker"]) {
return;
}
if (!nestedData[d["Speaker"]]) {
nestedData[d["Speaker"]] = 1;
} else {
nestedData[d["Speaker"]] += 1;
}
});
var summerizedData = [];
var dataObj;
for (i in nestedData) {
dataObj = {
Speaker: i,
}
dataObj['Views'] = nestedData[i];
summerizedData.push(dataObj);
}
var svg = dimple.newSvg("#chartContainer-2", 900, 400);
var myChart = new dimple.chart(svg, summerizedData);
//myChart.setBounds(20, 20, 460, 360)
myChart.addMeasureAxis("p", "Views");
myChart.addSeries("Speaker", dimple.plot.pie);
myChart.addLegend(100, 20, 90, 300, "left");
myChart.draw();
}
function graphForContainer3(data) {
var nestedTypeData = {};
var nestedSCAPData = {};
data.forEach(function (d) {
if (!d["Type"]) {
return;
}
if (!nestedTypeData[d["Type"]]) {
nestedTypeData[d["Type"]] = 1;
} else {
nestedTypeData[d["Type"]] += 1;
}
if (!d["SCAP"]) {
return;
}
if (!nestedSCAPData[d["SCAP"]]) {
nestedSCAPData[d["SCAP"]] = 1;
} else {
nestedSCAPData[d["SCAP"]] += 1;
}
});
var summerizedData = [];
var dataObj;
for (i in nestedTypeData) {
dataObj = {
Type: i,
}
dataObj['Views'] = nestedTypeData[i];
summerizedData.push(dataObj);
}
for (i in nestedSCAPData) {
dataObj = {
SCAP: i,
}
dataObj['Views'] = nestedSCAPData[i];
summerizedData.push(dataObj);
}
var svg = dimple.newSvg("#chartContainer-3", 590, 400);
var myChart = new dimple.chart(svg, summerizedData);
myChart.setBounds(20, 20, 460, 360)
myChart.addMeasureAxis("p", "Views");
var outerRing = myChart.addSeries("SCAP", dimple.plot.pie);
var innerRing = myChart.addSeries("Type", dimple.plot.pie);
// Negatives are calculated from outside edge, positives from center
outerRing.innerRadius = "-30px";
innerRing.outerRadius = "-40px";
innerRing.innerRadius = "-70px";
myChart.addLegend(500, 20, 90, 300, "left");
myChart.draw();
}
function graphForContainer4(data) {
var nestedData = {};
data.forEach(function (d) {
if (!nestedData[d["Resource"]]) {
nestedData[d["Resource"]] = 1;
} else {
nestedData[d["Resource"]] += 1;
}
});
var summerizedData = [];
var dataObj;
for (i in nestedData) {
dataObj = {
Resource: i,
}
dataObj['Views'] = nestedData[i];
summerizedData.push(dataObj);
}
var svg = dimple.newSvg("#chartContainer-4", '100%', 400);
var myChart = new dimple.chart(svg, summerizedData);
//myChart.setBounds(60, 30, 510, 305)
var x = myChart.addCategoryAxis("x", "Resource");
myChart.addMeasureAxis("y", "Views");
myChart.addSeries(null, dimple.plot.bar);
myChart.draw();
}
function loadGraph(dataInText) {
var data = d3.csvParse(dataInText);
graphForContainer1(data);
graphForContainer2(data)
graphForContainer3(data)
graphForContainer4(data)
}
</script>
</body>
</html>