-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.js
116 lines (97 loc) · 3.4 KB
/
init.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
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
/**
* @author Frendhi Saido Danaro
*
*/
function toggle(element) {
document.getElementById(element).style.display = (document.getElementById(element).style.display == "none") ? "" : "none";
}
var m = [0,5,10,20,30,40,50,60,90];
var w = 1000,
wbar = 600,
h = 300;
var data = [
{kem: "Depkominfo", kor: "1.03"},
{kem: "Kementrian Pendayagunaan Aparatur Negara", kor: "1.37"},
{kem: "Kementrian Sekertariat Negara", kor: "1.6"},
{kem: "BMKG", kor: "2.71"},
{kem: "Kementrian Pendidikan Nasional", kor: "2.89"},
{kem: "BPKP", kor: "3.14"},
{kem: "Kementrian Perumahan Rakyat", kor: "4.01"},
{kem: "Mahkamah Agung", kor: "4.79"},
{kem: "Kementrian Dalam Negeri", kor: "9"},
{kem: "Kementrian Kesehatan", kor: "36.5"}
];
var maxX = data[data.length-1].kor;
var mapY = data.map(function(d){ return d.kem;});
var x = d3.scale.linear().range([0,wbar]).domain([0,maxX]),
y = d3.scale.ordinal().rangeRoundBands([0, h], .1).domain(mapY);
var svgbase = d3.select("#infographic")
.append("svg")
.attr("width", w)
.attr("height", h)
.attr("class","background");
var rect = svgbase.selectAll("rect")
.data(data).enter()
.append("svg:g")
.attr("class","main")
.attr("transform","translate(0,0)");
//.on("mouseover.rect", function(){});
rect.append("rect")
.attr("class","chart")
.attr("fill","#FF0000")
.attr("x", m[5])
.attr("y", function(d){
return y(d.kem);
})
.attr("width", function(d){
return x(d.kor);
})
.attr("height", y.rangeBand());
rect.append("text")
.attr("x", m[1])
.attr("y", function(d){
return y(d.kem);
})
.attr("dx", 0)
.attr("dy", "1.5em")
.attr("text-anchor", "start")
.style("fill","#000")
.text(function(d){
return d.kor+" M";
});
rect.append("rect")
.attr("class","over")
.attr("opacity",0.1)
.attr("x", 0)
.attr("y", function(d){
return y(d.kem);
})
.attr("width", wbar+350)
.attr("height", y.rangeBand());
rect.append("text")
.attr("x", wbar+m[8])
.attr("y", function(d){
return y(d.kem);
})
.attr("dx", 0)
.attr("dy", "1.5em")
.attr("text-anchor", "start")
.style("fill","#000")
.text(function(d,i){
var num = data.length - i;
return (num)+". "+d.kem;
});
rect.append("rect")
.attr("class","showus")
.attr("fill","#ffa500")
.attr("x", wbar+m[6])
.attr("y", function(d){
return y(d.kem);
})
.attr("width", 300)
.attr("height", y.rangeBand())
.on("click.rect",function(){
var element = d3.select(this);
element.transition().duration(500)
.attr("width",m[3]);
});