-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
194 lines (165 loc) · 6.35 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]> <html class="no-js"> <!--<![endif]-->
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="google-site-verification" content="VbXqzlAem-KxNiseTjfdEbijXhBrI2vrsJNK4p8_i7o" />
<title>Average monthly net wage of employees Indonesia by Province</title>
<meta name="description"
content="Choropleth map of average monthly net wage of employees Indonesia by Province. Danzel Artamadja 2023, built using D3">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="">
<script src="https://d3js.org/d3.v6.min.js"></script>
<script src="https://unpkg.com/topojson@3.0.2/dist/topojson.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3-legend/2.13.0/d3-legend.min.js"></script>
</head>
<body>
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="#">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<script>
//https://jsonkeeper.com/b/4VST
Promise.all([
fetch('https://notwatermango.github.io/choropleth-map-of-average-employee-income-in-indonesia/jsons/dataupah.json'),
fetch('https://notwatermango.github.io/choropleth-map-of-average-employee-income-in-indonesia/jsons/indonesia.json')
])
.then((allres) => {
return Promise.all(allres.map((res) => res.json()));
})
.then((data) => {
var incomeData = data[0];
var topoData = data[1];
const projection = d3.geoEquirectangular().translate([520, 140]).scale(1150).rotate([-120, 0]);
const path = d3.geoPath().projection(projection);
const svg = d3.select("#svg-container").append("svg")
.attr("viewBox", [0, 0, 975, 390]);
var provinces = topojson.feature(topoData, topoData.objects.provinces).features;
const colorScale = d3.scaleLinear()
.domain(d3.extent(incomeData, (d) => d.income))
.range(["#E1EBFD", "#0054ff"]);
incomeData.sort((a, b) => (a.province.localeCompare(b.province)));
provinces.sort((a, b) => (a.properties.state.localeCompare(b.properties.state)));
provinces.forEach((province, index) => {
province.properties = { ...incomeData[index] }
});
// console.log(provinces);
var tooltip = d3.select("#svg-container")
.append("div").style("opacity", 0)
.attr("id", "tooltip")
.style("position", "absolute")
.style("font-size", "0.7rem")
.style("background-color", "lightgreen")
.style("white-space", "nowrap")
.html('')
function mouseover() {
d3.select(this)
.style("opacity", "1")
.attr("stroke", "limegreen")
.attr("stroke-width", "1")
tooltip
.style("opacity", "1")
.style("padding", "0.3rem")
}
const incomeIDR = new Intl.NumberFormat("id-ID", {
style: "currency",
currency: "IDR",
minimumFractionDigits: 3,
});
function mousemove(event, d) {
tooltip
.style("left", d3.pointer(event)[0] + 10 + 'px')
.style("top", d3.pointer(event)[1] - 40 + 'px')
.html(`${d.properties.province}<br>${incomeIDR.format(d.properties.income)}`)
.attr("data-income", d.properties.income)
}
function mouseout() {
d3.select(this)
.style("opacity", "0.8")
.attr("stroke", "none")
tooltip
.style("opacity", "0")
.html('')
.style("padding", "0")
}
svg.selectAll("path")
.data(provinces)
.enter()
.append("path")
.attr("class", "province")
.attr("d", path)
.attr("stroke", "none")
.attr("data-province", (d) => d.properties.province)
.attr("data-income", (d) => d.properties.income)
.attr("fill", (d) => colorScale(d.properties.income))
.style("opacity", "0.8")
.on("mouseover", mouseover)
.on("mousemove", mousemove)
.on("mouseout", mouseout)
var legend = svg.append("g")
.attr("id", "legend")
.attr("x", 900)
.attr("y", 10)
.attr("width", 100)
.attr("height", 100);
svg.append("g")
.attr("id", "legend")
.attr("class", "legendLinear")
.attr("transform", "translate(750,20)");
var legendLinear = d3.legendColor()
.labelFormat((d) => (d / 1000000).toFixed(1))
.shapeWidth(30)
.orient('horizontal')
.scale(colorScale);
svg.select(".legendLinear")
.call(legendLinear);
})
</script>
<style>
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}
.outer {
display: table;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.middle {
display: table-cell;
vertical-align: middle;
}
.inner {
margin-left: auto;
margin-right: auto;
width: 1000px
}
#svg-container {
position: relative;
width: 975px;
}
#legend {
font-size: 0.8rem;
}
</style>
<div class="outer">
<div class="middle">
<div class="inner">
<h1 id="title">Average monthly net wage of employees Indonesia</h1>
<h2 id="description">Rata-rata Upah/Gaji Bersih Sebulan Buruh/Karyawan/Pegawai Menurut Provinsi, 2022 (<a
href="https://www.bps.go.id/statictable/2022/06/29/2189/rata-rata-upah-gaji-bersih-sebulan-buruh-karyawan-pegawai-menurut-provinsi-dan-lapangan-pekerjaan-utama-2022.html"
target="_blank">BPS - Statistics Indonesia</a>)</h2>
<div id="svg-container"></div>
<p>by <a href="https://github.com/notwatermango" target="_blank">Danzel Artamadja</a>, built using <a
href="https://d3js.org/" target="_blank">D3</a>.</p>
</div>
</div>
</div>
</body>
</html>