-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotviz.js
More file actions
224 lines (203 loc) · 6.93 KB
/
Copy pathplotviz.js
File metadata and controls
224 lines (203 loc) · 6.93 KB
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
// Generated by CoffeeScript 1.10.0
(function() {
var ArcChart, BUCKETS, BUCKET_COUNT, Bucket, NONCES_PER_BUCKET, TOTAL_NONCE_COUNT, chart, elm, j, p, parse, ref, render, results;
p = function() {
return console.log.apply(this, arguments);
};
elm = function(tag, attributes, builder) {
var add, child, children, el, j, len, name, value, xmlns;
if (builder == null) {
builder = void 0;
}
if (arguments.length < 3 && !$.isPlainObject(attributes)) {
builder = attributes;
attributes = {};
}
xmlns = attributes.xmlns;
el = xmlns != null ? document.createElementNS(xmlns, tag) : document.createElement(tag);
for (name in attributes) {
value = attributes[name];
el.setAttribute(name, value);
}
add = function(el, child) {
if (typeof child === typeof '') {
child = document.createTextNode(child);
}
return el.appendChild(child);
};
if (builder != null) {
children = typeof builder === typeof Function ? builder() : builder;
if ($.isArray(children)) {
for (j = 0, len = children.length; j < len; j++) {
child = children[j];
add(el, child);
}
} else {
add(el, children);
}
}
return el;
};
Bucket = (function() {
function Bucket(first_nonce1) {
this.first_nonce = first_nonce1;
this.next_nonce = this.first_nonce.plus(NONCES_PER_BUCKET);
this.reset();
}
Bucket.prototype.reset = function() {
return this.nonces = Big(0);
};
Bucket.prototype.consider = function(first_nonce, nonce_count) {
var length, next_nonce;
next_nonce = first_nonce.plus(nonce_count);
if (first_nonce.lt(this.first_nonce)) {
first_nonce = this.first_nonce;
}
if (this.next_nonce.lt(next_nonce)) {
next_nonce = this.next_nonce;
}
length = next_nonce.minus(first_nonce);
if (!length.lt(0)) {
return this.nonces = this.nonces.plus(length);
}
};
Bucket.prototype.toString = function() {
return {
first_nonce: this.first_nonce.toString(),
nonces: this.nonces.toString()
};
};
return Bucket;
})();
({
ArcChart: ArcChart = (function() {
function ArcChart(canvas_element1) {
this.canvas_element = canvas_element1;
}
ArcChart.prototype.show = function(values, styler) {
var center_x, center_y, ct, from_angle, full_sweep, i, inner_radius, j, len, radius, results, scale, sweep, to_angle, to_north, value, x, y;
ct = this.canvas_element.getContext('2d');
radius = this.canvas_element.height / 2 - 16;
center_x = this.canvas_element.width / 2;
center_y = this.canvas_element.height / 2;
inner_radius = radius / 2;
to_north = 2 * Math.PI * -1 / 4;
full_sweep = 2 * Math.PI;
results = [];
for (i = j = 0, len = values.length; j < len; i = ++j) {
value = values[i];
scale = values.length;
from_angle = full_sweep * i / scale;
sweep = full_sweep / scale;
to_angle = from_angle + sweep;
ct.fillStyle = styler(value, i);
ct.beginPath();
ct.arc(center_x, center_y, radius, to_north + from_angle, to_north + to_angle);
x = center_x + Math.sin(to_angle) * inner_radius;
y = center_y - Math.cos(to_angle) * inner_radius;
ct.lineTo(x, y);
ct.arc(center_x, center_y, inner_radius, to_north + to_angle, to_north + from_angle, true);
results.push(ct.fill());
}
return results;
};
return ArcChart;
})()
});
BUCKET_COUNT = 128;
TOTAL_NONCE_COUNT = Big("18446744073709551616");
NONCES_PER_BUCKET = TOTAL_NONCE_COUNT.div(BUCKET_COUNT);
BUCKETS = (function() {
results = [];
for (var j = 0, ref = BUCKET_COUNT - 1; 0 <= ref ? j <= ref : j >= ref; 0 <= ref ? j++ : j--){ results.push(j); }
return results;
}).apply(this).map(function(i) {
return new Bucket(NONCES_PER_BUCKET.times(i));
});
parse = function(data) {
var bucket, file_name, first_nonce, groups, k, l, len, len1, len2, len3, line, lines, m, nonce_count, o, ref1, results1;
for (k = 0, len = BUCKETS.length; k < len; k++) {
bucket = BUCKETS[k];
bucket.reset();
}
lines = data.trim().split("\n");
for (l = 0, len1 = lines.length; l < len1; l++) {
line = lines[l];
groups = line.match(/[^\\\/]+$/);
file_name = groups[0];
if (groups = file_name.match(/^\d+_(\d+)_(\d+)(_\d+)?$/)) {
ref1 = groups.slice(1, 3), first_nonce = ref1[0], nonce_count = ref1[1];
for (m = 0, len2 = BUCKETS.length; m < len2; m++) {
bucket = BUCKETS[m];
bucket.consider(Big(first_nonce), Big(nonce_count));
}
} else {
throw "Unexpected form: " + file_name;
}
}
results1 = [];
for (o = 0, len3 = BUCKETS.length; o < len3; o++) {
bucket = BUCKETS[o];
results1.push(p(bucket.toString()));
}
return results1;
};
chart = null;
render = function() {
var bucket, emptiest_bucket, fullest_bucket, k, len, range, styler;
emptiest_bucket = BUCKETS[0];
fullest_bucket = BUCKETS[0];
for (k = 0, len = BUCKETS.length; k < len; k++) {
bucket = BUCKETS[k];
if (bucket.nonces.lt(emptiest_bucket.nonces)) {
emptiest_bucket = bucket;
}
if (bucket.nonces.gt(fullest_bucket.nonces)) {
fullest_bucket = bucket;
}
}
range = fullest_bucket.nonces.plus(1).minus(emptiest_bucket.nonces);
styler = function(bucket, i) {
var color, intensity, rgb, scale, to_hex;
scale = 360 * 2 / 3;
intensity = Math.round((bucket.nonces.minus(emptiest_bucket.nonces)).times(scale).div(range));
color = new HSV(0.01 + scale - intensity, 75, 90);
rgb = ColorConverter.toRGB(color);
to_hex = function(n) {
n = n.toString(16);
if (n.length === 1) {
n = "0" + n;
}
return n;
};
return "#" + [rgb.r, rgb.g, rgb.b].map(to_hex).join('');
};
return chart.show(BUCKETS, styler);
};
$(document).ready(function() {
var attributes, button, canvas, canvas_element, input, textarea, viewport_height, viewport_width;
button = $('#button');
input = $('#input');
textarea = input.find('textarea');
viewport_width = document.body.clientWidth;
viewport_height = document.documentElement.clientHeight;
attributes = {
width: viewport_width,
height: viewport_height
};
canvas_element = elm('canvas', attributes);
($('#canvas_box')).append(canvas_element);
canvas = $(canvas_element);
chart = new ArcChart(canvas_element);
button.click(function() {
button.fadeOut('fast');
return input.fadeIn('fast');
});
return textarea.on('input', function() {
parse(textarea.val());
render();
input.fadeOut('fast');
return canvas.fadeIn('fast');
});
});
}).call(this);