forked from artzub/blackhole.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
169 lines (153 loc) · 5.38 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
<!DOCTYPE html>
<html>
<head>
<title>BlackHole.js</title>
<meta charset="utf-8">
<style>
.console {
top: 0;
right: 0;
position: absolute;
z-index: 10;
list-style: none;
}
.console > li > ul {
display: block;
}
.console > li:hover > ul {
display: block;
}
#canvas-svg {
width: 700px;
height: 700px;
position: relative;
}
</style>
</head>
<body>
<ul class="console">
<li>Setting
<ul id="bh-setting"></ul>
</li>
</ul>
<div><span id="status"></span></div>
<div id="canvas-svg"></div>
<br/>
<br/>
<button id="buttonTest">Test</button>
<br/>
<textarea name="" id="testText" cols="100" rows="50"></textarea>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="blackhole.js"></script>
<script>
function test() {
var data = (function () {
var res = [];
var doc = new DOMParser();
doc = doc.parseFromString(d3.select("#testText").property("value"), 'text/xml');
doc = d3.select(doc);
doc.selectAll('event').each(function (d) {
d = d3.select(this);
var a = d.attr('action');
res.push({
id : res.length,
date: +d.attr('date'),
author: d.attr('author'),
filename: d.attr('filename'),
action: a,
actOrder: a === 'A' ? 0 : a === 'M' ? 1 : 2
});
});
return res;
})();
bh.stop();
cur = 0;
all = data.length;
bh.start(data, 0, 0);
}
var uiStatus = d3.select("#status")
, bh = d3.blackHole("#canvas-svg")
, all
, cur
, df = d3.time.format('%d-%m-%Y')
, pf = d3.format('%')
;
function prints(items, l, r) {
cur += items ? items.length : 0;
uiStatus.text([
"items:",
pf(cur / all),
" from:",
df(new Date(l)),
" to:",
df(new Date(r))
].join(''));
}
function printm() {
//console.log("m", [].slice.call(arguments));
}
var stepDate = 24 * 60 * 60 * 1000;
bh.on('getGroupBy', function(d) { return d.date; })
.on('getParent', function(d) {return d.author;})
.on('getParentKey', function(d) {return d;})
.on('getChildKey', function(d) {return d.filename;})
.on('getCategoryKey', function(d) {return d.filename.replace(/.*?\.(.*)$/, '.$1'); })
.on('getParentLabel', function(d) {return d.nodeValue; })
.on('getChildLabel', function(d) {return d.nodeValue.filename.replace(/.*\/(.*)$/, "$1"); })
.on('calcRightBound', function(l) { return l + stepDate; })
.on('getVisibleByStep', function(d) { return !(d.action == "D"); })
.on('getCreateNearParent', function(d) {return d.action == "A";})
.on('finished', function() { uiStatus.text("Completed!!!"); })
.on('starting', function() {
uiStatus.text("Start...");
cur = 0;
})
.on('started', function() {
uiStatus.text("Run...");
cur = 0;
})
.on('processing', prints)
//.on('processed', prints)
.on('parsing', function() {
uiStatus.text(cur++ + ' of ' + all);
})
.on('mouseovernode', printm)
.on('mouseoutnode', printm)
.on('mousemove', printm)
.sort(function(a, b) {
return d3.ascending(a.date + '_' + a.actOrder, b.date + '_' + b.actOrder);
})
;
bh.setting.drawTrack = true;
bh.setting.asyncParsing = true;
bh.style('background', "#000");
function chch(d) {
bh.setting[d] = this.checked;
}
d3.select("#bh-setting")
.selectAll("li")
.data(d3.keys(bh.setting).filter(function(d) {
var val = bh.setting[d];
return typeof val === "boolean";
}))
.enter()
.append('li')
.each(function(d) {
var item = d3.select(this);
item.append('input')
.datum(d)
.attr("id", "bh-s-" + d)
.attr("type", "checkbox")
.attr("checked", bh.setting[d] ? "checked" : null)
.on('change', chch)
;
item.append('label')
.text(d)
.attr("for", "bh-s-" + d)
;
})
;
d3.select("#buttonTest").on('click', test);
</script>
</body>
</html>