-
Notifications
You must be signed in to change notification settings - Fork 2
/
title.js
91 lines (83 loc) · 2.33 KB
/
title.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
86
87
88
89
90
91
function addtitle()
{
var margin = {top: 10, right: 5, bottom: 5, left: 10};
var svg = d3.select(".barchartsvg");
svg.append("g")
.attr("class", "title")
.append("text")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "start")
.text("Farm 2 Consumer");
var infogroup = svg.append("g")
.attr("class", "infogroup");
infogroup
.append("text")
.attr("transform", "translate(" + margin.left + "," + (margin.top+40) + ")")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "start")
.text("Of your grocery spendings at retail stores,");
infogroup
.append("text")
.attr("transform", "translate(" + margin.left + "," + (margin.top+60) + ")")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "start")
.text("how much goes to farmers?");
}
function addlegend(type)
{
var legendgroup = d3.select(".barchartsvg").append("g")
.attr("class", "legendgroup");
if(type == "price")
{
// legends
legendgroup
.append("line")
.attr("class", "retailline")
.attr("x1", 10)
.attr("y1", (margin.top+100))
.attr("x2", 40)
.attr("y2", (margin.top+100));
legendgroup
.append("line")
.attr("class", "farmline")
.attr("x1", 10)
.attr("y1", (margin.top+115))
.attr("x2", 40)
.attr("y2", (margin.top+115));
legendgroup
.append("text")
.attr("transform", "translate(" + (margin.left+40) + "," + (margin.top+90) + ")")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "start")
.text("Retail prices (inflation adjusted)");
legendgroup
.append("text")
.attr("transform", "translate(" + (margin.left+40) + "," + (margin.top+105) + ")")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "start")
.text("Farm prices (inflation adjusted)");
}
else if(type == "percent")
{
legendgroup
.append("line")
.attr("class", "percentline")
.attr("x1", 10)
.attr("y1", (margin.top+100))
.attr("x2", 40)
.attr("y2", (margin.top+100));
legendgroup
.append("text")
.attr("transform", "translate(" + (margin.left+40) + "," + (margin.top+90) + ")")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "start")
.text("(Farm Price / Retail Price) * 100 ");
}
}