-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
108 lines (92 loc) · 2.91 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
<!DOCTYPE html>
<meta charset="UTF-8">
<title>The Spyder Girl</title>
<svg height="500"></svg>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script>
var data_w = 5;
var svg = d3.select("svg"),
margin = {top: 20, right: 20, bottom: 30, left: 50},
width = +svg.attr("width") - margin.left - margin.right,
height = +svg.attr("height") - margin.top - margin.bottom,
g = svg.append("g").attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var parseTime = d3.timeParse("%Y-%m-%d %H:%M:%S");
var x = d3.scaleTime();
var y = d3.scaleLinear()
.rangeRound([height, 0]);
var line = d3.line()
.curve(d3.curveCardinal)
.x(function(d) { return x(d.date); })
.y(function(d) { return y(d.retweet); })
var line1 = d3.line()
.curve(d3.curveCardinal)
.x(function(d) { return x(d.date); })
.y(function(d) { return y(d.like); })
d3.tsv("twitter.csv", function(d) {
d.date = parseTime(d.date);
d.retweet = +d.retweet;
d.like = +d.like;
return d;
}, function(error, data) {
if (error) throw error;
svg.attr("width", data_w*data.length);
x.rangeRound([data_w*data.length,0]);
x.domain(d3.extent(data, function(d) { return d.date; }));
y.domain(d3.extent(data, function(d) { return d.retweet; }));
g.append("g")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x))
.select(".domain")
.remove();
g.append("g")
.call(d3.axisLeft(y))
.append("text")
.attr("fill", "#000")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", "0.71em")
.attr("text-anchor", "end")
.attr("style", "fill: limegreen")
.text("Retweets");
g.append("g")
.call(d3.axisLeft(y))
.append("text")
.attr("fill", "#000")
.attr("transform", "rotate(-90)")
.attr("y", 20)
.attr("dy", "0.71em")
.attr("text-anchor", "end")
.attr("style", "fill:firebrick")
.text("Likes");
var path = g.append("path")
.datum(data)
.attr("fill", "none")
.attr("stroke", "limegreen")
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round")
.attr("stroke-width", 2)
.attr("d", line);
var path2 = g.append("path")
.datum(data)
.attr("fill", "none")
.attr("stroke", "firebrick")
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round")
.attr("stroke-width", 2)
.attr("d", line1);
var totalLength = path.node().getTotalLength();
path
.attr("stroke-dasharray", totalLength + " " + totalLength)
.attr("stroke-dashoffset", totalLength)
.transition()
.duration(2000)
.attr("stroke-dashoffset", 0);
var totalLength2 = path2.node().getTotalLength();
path2
.attr("stroke-dasharray", totalLength2 + " " + totalLength2)
.attr("stroke-dashoffset", totalLength2)
.transition()
.duration(2000)
.attr("stroke-dashoffset", 0);
});
</script>