-
Notifications
You must be signed in to change notification settings - Fork 1
/
bar.html
86 lines (70 loc) · 1.68 KB
/
bar.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
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>Progress bar in chunks</title>
<style>
body {
text-align: center;
}
.container-bar {
display: inline-block;
position: relative;
text-align: left;
}
.info {
position: absolute;
right: 0px;
}
.progress {
border: 1px solid #aaa;
border-radius: 4px;
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.3);
background-color: rgba(0, 0, 0, 0.1);
}
.bar {
fill: steelblue;
}
</style>
</head>
<body>
<div class="container-bar">
<span>Episodes</span>
<span class="info"></span>
</div>
</body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var width = 500,
height = 20;
var x = d3.scale.linear()
.range([0, width])
var y = d3.scale.ordinal()
.rangeRoundBands([0, height], 0);
var xAxis = d3.svg.axis()
.scale(x)
.orient("top");
var svg = d3.select(".container-bar")
.attr("style", "width: "+(width+2)+"px")
.append("svg")
.attr("class", "progress")
.attr("width", width)
.attr("height", height)
.append("g");
data = [1, 2, 3, 4, 5, 6, 7, 9, 10,
11, 13, 16, 20, 21, 22, 23, 28, 29,
30, 32, 33, 34,
40, 45, 46, 47, 49,
50];
x.domain([0, d3.max(data)]).nice();
y.domain(data.map(function(d) { return 0; }));
svg.selectAll(".bar")
.data(data)
.enter().append("rect")
.attr("class", "bar")
.attr("x", function(d) { return x(d-1); })
.attr("y", function(d) { return 0; })
.attr("width", function(d) { return Math.abs(x(d) - x(d-1)); })
.attr("height", y.rangeBand());
d3.select(".info")
.text(data.length+'/'+d3.max(data));
</script>