-
Notifications
You must be signed in to change notification settings - Fork 0
/
bots.js
85 lines (73 loc) · 2.27 KB
/
bots.js
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
var barWidth = 3;
var options = {
barWidth: barWidth,
ipScale: 1,
reqScale: 0.014,
maxHeight: 1500,
maxWidth: dataset.length * barWidth
};
(function(options) {
var barWidth = options.barWidth;
var ipScale = options.ipScale;
var reqScale = options.reqScale;
var maxHeight = options.maxHeight;
var maxWidth = options.maxWidth;
function graphit(options) {
var className = options['className'];
var heightFunc = options['heightFunc'];
var color = options['color'];
var scale = options['scale'] || 1;
var opacity = options['opacity'] || 1;
function mouseOver(d) {
d3.select(this).style("fill", "yellow");
$('.message').addClass('show').text("requests: " + d[0] + ", IPs: " + d[1] + ", total requests: " + d[0]*d[1]);
}
function mouseOut(d) {
d3.select(this).style("fill", color);
$('.message').removeClass('show');
}
d3.select('svg').selectAll(className)
.data(dataset)
.enter()
.append("rect")
.attr("class", className)
.attr("width", "4")
.attr("y", function(d) {
return maxHeight - heightFunc(d);
})
.attr("x", function(d, i) {
return i*barWidth;
})
.attr("height", heightFunc)
.style("fill", color)
.style("fill-opacity", opacity)
.on("mouseover", mouseOver)
.on("mouseout", mouseOut);
}
$(function() {
$('.annotation').text(annotation);
d3.select("body")
.append("svg")
.attr("width", maxWidth)
.attr("height", maxHeight)
.style("background-color", "lightgray");
graphit({
className: 'ip',
color: 'teal',
heightFunc: function(d) {
return d[1] * ipScale;
},
opacity: 1,
scale: ipScale
});
graphit({
className: 'total-requests',
color: 'gray',
heightFunc: function(d) {
return d[0]*d[1] * reqScale;
},
opacity: 0.8,
scale: reqScale
});
});
})(options);