-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
295 lines (265 loc) · 8.26 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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<!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">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" />
<title>FP-Tree Simulator</title>
<style>
.tree ul {
padding-top: 20px; position: relative;
transition: all 0.5s;
}
.tree li {
float: left; text-align: center;
list-style-type: none;
position: relative;
padding: 20px 5px 0 5px;
transition: all 0.5s;
}
/*We will use ::before and ::after to draw the connectors*/
.tree li::before, .tree li::after{
content: '';
position: absolute; top: 0; right: 50%;
border-top: 1px solid #ccc;
width: 50%; height: 20px;
}
.tree li::after{
right: auto; left: 50%;
border-left: 1px solid #ccc;
}
/*We need to remove left-right connectors from elements without
any siblings*/
.tree li:only-child::after, .tree li:only-child::before {
display: none;
}
/*Remove space from the top of single children*/
.tree li:only-child{ padding-top: 0;}
/*Remove left connector from first child and
right connector from last child*/
.tree li:first-child::before, .tree li:last-child::after{
border: 0 none;
}
/*Adding back the vertical connector to the last nodes*/
.tree li:last-child::before{
border-right: 1px solid #ccc;
border-radius: 0 5px 0 0;
}
.tree li:first-child::after{
border-radius: 5px 0 0 0;
}
/*Time to add downward connectors from parents*/
.tree ul ul::before{
content: '';
position: absolute; top: 0; left: 50%;
border-left: 1px solid #ccc;
width: 0; height: 20px;
}
.tree li a{
border: 1px solid #ccc;
padding: 4px 8px;
text-decoration: none;
font-weight: 900;
display: inline-block;
border-radius: 10px;
transition: all 0.5s;
}
.tree li a.selected {
color: #ffffff;
background-color: #5bc0de;;
}
/*Time for some hover effects*/
/*We will apply the hover effect the the lineage of the element also*/
.tree li a:hover, .tree li a:hover+ul li a {
background: #c8e4f8; color: #000; border: 1px solid #94a0b4;
}
/*Connector styles on hover*/
.tree li a:hover+ul li::after,
.tree li a:hover+ul li::before,
.tree li a:hover+ul::before,
.tree li a:hover+ul ul::before{
border-color: #94a0b4;
}
</style>
</head>
<body>
<div class="container">
<h1>FP-Tree Simulator</h1>
<div class="row">
<div class="col-xs-9">
<fieldset>
<div class="form-group">
<label for="input-area">Input</label>
<textarea id="input-area" class="form-control" rows="10">{f,a,c,d,g,i,m,p}
{a,b,c,f,l,m,o}
{b,f,h,j,o,w}
{b,c,k,s,p}
{a,f,c,e,l,p,m,n}</textarea>
</div>
<div class="form-inline">
<div class="form-group">
<label for="input-area">Min Support</label>
<input type="text" id="input-min-support" class="form-control" value="3">
</div>
<button class="btn btn-info" onclick="FPTreeSim.cleanData()">Submit</button>
</div>
</fieldset>
</div>
<div class="col-xs-3">
<table class="table table-striped">
<thead>
<tr>
<th>Item</th>
<th>Frequency</th>
</tr>
</thead>
<tbody id="table-freq"></tbody>
</table>
</div>
</div>
<div class="row">
<div class="col-xs-4">
<table class="table table-striped">
<thead>
<tr>
<th>Row #</th>
<th>Items</th>
<th>Frequent Items</th>
<th></th>
</tr>
</thead>
<tbody id="table-items"></tbody>
</table>
</div>
<div id="fp-tree" class="col-xs-8 tree" style="min-height:500px"></div>
</div>
<p>
<hr>
Released under the MIT License | <a href="https://github.com/janithl/FPTreeSimulator">Source Code</a>
</p>
</div>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script type="text/javascript">
var FPTreeSim = {
sets : [],
items : {},
minSupport : 0,
orderedFreqItems: [],
prevNode : 'tree-origin',
currentNodeLevel: 0,
currentRowLevel : 0,
nodeAnimation : null,
cleanData: function() {
FPTreeSim.sets = [];
FPTreeSim.items = {};
FPTreeSim.minSupport = 0;
FPTreeSim.orderedFreqItems = [];
FPTreeSim.prevNode = 'tree-origin';
FPTreeSim.currentNodeLevel = 0;
FPTreeSim.currentRowLevel = 0;
clearInterval(FPTreeSim.nodeAnimation);
FPTreeSim.nodeAnimation = null;
var text = document.getElementById('input-area').value.toLowerCase();
document.getElementById('input-area').value = text.replace(/[^a-z{},\n]/ig, '');
FPTreeSim.minSupport = parseInt(document.getElementById('input-min-support').value);
FPTreeSim.identifySets(text);
},
identifySets: function(text) {
var cansets = text.replace(/[{}]/ig, '').split('\n');
for(var i = 0; i < cansets.length; i++) {
cansets[i] = cansets[i].replace(/[\s]/ig, '').split(',');
}
FPTreeSim.sets = cansets;
FPTreeSim.getItemCounts();
},
getItemCounts: function() {
for(var i = 0; i < FPTreeSim.sets.length; i++) {
for(var j = 0; j < FPTreeSim.sets[i].length; j++) {
var item = FPTreeSim.sets[i][j];
if(FPTreeSim.items.hasOwnProperty(item)) {
FPTreeSim.items[item] += 1;
}
else if(item !== '') {
FPTreeSim.items[item] = 1;
}
}
}
FPTreeSim.renderFrequentItems();
},
renderFrequentItems: function() {
var row = '', itemlist = [];
for(var i in FPTreeSim.items) {
if(FPTreeSim.items[i] >= FPTreeSim.minSupport) {
itemlist.push({name: i, count: FPTreeSim.items[i]});
}
}
itemlist.sort(function(a, b) { return b.count - a.count; });
for(var j = 0; j < itemlist.length; j++) {
row += '<tr><td>' + itemlist[j].name + '</td><td>' + itemlist[j].count + '</td></tr>';
}
document.getElementById('table-freq').innerHTML = row;
FPTreeSim.renderItemTable();
},
renderItemTable: function() {
var row = '', freqItems = '';
for(var i = 0; i < FPTreeSim.sets.length; i++) {
freqItems = '';
row += '<tr><td>' + (i + 1) + '</td><td>{' + FPTreeSim.sets[i].join(', ') + '}</td>';
for(var j in FPTreeSim.items) {
if(FPTreeSim.items[j] >= FPTreeSim.minSupport && FPTreeSim.sets[i].indexOf(j) > -1) {
FPTreeSim.orderedFreqItems.push(j);
freqItems += '<span id="freq-item-' + j + '-' + i + '" class="label label-default">' + j + '</span> ';
}
}
row += '<td>{' + freqItems + '}</td></tr>';
FPTreeSim.orderedFreqItems.push('|');
}
document.getElementById('table-items').innerHTML = row;
FPTreeSim.renderGraph();
},
renderGraph: function() {
document.getElementById('fp-tree').innerHTML = '<ul><li id="tree-origin">' +
'<a href="#" id="tree-origin-label">{}</a><ul id="tree-origin-children"></ul></li></ul>';
FPTreeSim.nodeAnimation = setInterval(FPTreeSim.renderNode, 1800);
},
renderNode: function() {
$('a.selected').removeClass('selected');
var item = FPTreeSim.orderedFreqItems.splice(0, 1);
if(item.length === 0) {
clearInterval(FPTreeSim.nodeAnimation);
FPTreeSim.nodeAnimation = null;
}
else if(item.toString() === '|') {
FPTreeSim.currentNodeLevel = 0;
FPTreeSim.currentRowLevel++;
FPTreeSim.prevNode = 'tree-origin';
}
else {
var itemNode = document.getElementById('tree-node-' + item + '-' + FPTreeSim.currentNodeLevel + '-label');
if(itemNode === null || itemNode.parentNode.parentNode.id !== FPTreeSim.prevNode + '-children') {
document.getElementById(FPTreeSim.prevNode + '-children').innerHTML += '<li id="tree-node-' +
item + '-' + FPTreeSim.currentNodeLevel + '">' +
'<a href="#" id="tree-node-' + item + '-' + FPTreeSim.currentNodeLevel + '-label">' +
item + ': 1</a><ul id="tree-node-' + item + '-' + FPTreeSim.currentNodeLevel +
'-children" class="hide"></ul></li>';
document.getElementById(FPTreeSim.prevNode + '-children').className = '';
itemNode = document.getElementById('tree-node-' + item + '-' + FPTreeSim.currentNodeLevel + '-label');
}
else {
setTimeout(function() {
var comps = itemNode.innerHTML.split(':');
itemNode.innerHTML = comps[0] + ': ' + (parseInt(comps[1]) + 1);
}, 900);
}
/** highlight graph node and freq items row item */
itemNode.className = 'selected';
document.getElementById('freq-item-' + item + '-' + FPTreeSim.currentRowLevel).className = 'label label-info';
FPTreeSim.prevNode = 'tree-node-' + item + '-' + FPTreeSim.currentNodeLevel;
FPTreeSim.currentNodeLevel++;
}
}
};
</script>
</body>
</html>