-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpiechart.html
213 lines (194 loc) · 4.69 KB
/
piechart.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<!DOCTYPE html><html lang="ja"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width"><link rel="icon" href="data:">
<title>東証時価総額ダッシュボード</title>
</head>
<body>
<h1><a href=./piechart.html>東証時価総額ダッシュボード</a></h1>
<select id="selpref"></select>
<select id="selindustry"></select>
<select id="selmarket"></select>
<br>
<div class=piechart>
<canvas id="canvas"></canvas>
<div class="tbl" id="tbl"></div>
</div>
<div class=piechart>
<canvas id="canvas2"></canvas>
<div class="tbl" id="tbl2"></div>
</div>
<div id=lastUpdate></div>
<link rel="stylesheet" href="banner.css">
<div id="banners"></div>
<div id="credit">
DATA: <a href="https://disclosure2.edinet-fsa.go.jp/WEEK0010.aspx">EDINET</a>, <a href="https://www.houjin-bangou.nta.go.jp/">国税庁法人番号公表サイト</a><br>
Lib: <a href=https://github.com/code4fukui/piechart/>piechart</a><br>
<a href=https://github.com/code4fukui/EDINET/>data and src on GitHub</a><br>
</div>
<script type="module">
import { CSV } from "https://js.sabae.cc/CSV.js";
//import { showPieChart } from "./showPieChart.js";
import { showPieChart } from "https://code4fukui.github.io/piechart/showPieChart.js";
import { setSelectMarket, markets, setSelectIndustry, industry17, setSelectPref } from "./setSelect.js";
import { removeHash } from "https://js.sabae.cc/removeHash.js";
import "./banner.js";
setSelectPref(selpref);
setSelectMarket(selmarket);
setSelectIndustry(selindustry);
const calcAll = (list, pref = true) => {
const res = {};
for (const i of list) {
const name = i.name.replace(/株式会社/, "") + " (" + (pref ? i.pref : i.city) + ")";
res[name] = i.marketcap_m;
}
return res;
};
const calcPref = (list) => {
const res = {};
for (const i of list) {
if (!res[i.pref]) {
res[i.pref] = 0;
}
res[i.pref] += i.marketcap_m;
}
return res;
};
const calcCity = (list, pref) => {
const res = {};
for (const i of list) {
if (!res[i.city]) {
res[i.city] = 0;
}
res[i.city] += i.marketcap_m;
}
return res;
};
const index = await CSV.fetchJSON("./data/marketcap/index.csv");
const latest = index[index.length - 1];
console.log(latest);
const list = await CSV.fetchJSON("./data/marketcap/" + latest.file);
lastUpdate.textContent = "更新日: " + latest.date;
console.log(list.length); // old 3805 -> 3813
//const url = "./data/list_with_marketcap.csv";
//const list = await CSV.fetchJSON(url);
list.forEach(i => {
i.marketcap_m = parseInt(i.marketcap_m)
});
const unit = "百万円";
const getData = () => {
return list.filter(i => {
if (selpref.value != "all" && i.pref != selpref.value) {
return false;
} else if (selmarket.value != "all" && i.market != selmarket.value) {
return false;
} else if (selindustry.value != "all" && i.type != selindustry.value) {
return false;
}
return true;
});
};
const sels = [selpref, selindustry, selmarket];
document.location.hash.substring(1).split(",").forEach((n, idx) => sels[idx].selectedIndex = n);
const show = () => {
const data = getData();
const prefmode = selpref.value == "all";
showPieChart(canvas, tbl, calcAll(data, prefmode), unit);
showPieChart(canvas2, tbl2, prefmode ? calcPref(data) : calcCity(data), unit);
document.location.hash = sels.map(i => i.selectedIndex).join(",");
if (document.location.hash == "#0,0,0") {
removeHash();
}
};
show();
sels.forEach(i => i.oninput = () => show());
</script>
<style>
body {
font-family: sans-serif;
text-align: center;
margin: 0;
padding: 0;
}
h1 {
margin: 0;
font-size: 4vw;
padding: 2vw 0;
margin-bottom: 1vw;
background-color: #ff5959;
color: white;
}
h1 a {
text-decoration: none;
color: white !important;
}
.piechart {
display: inline-block;
margin: 1em;
}
.piechart canvas {
display: inline-block;
width: 400px;
height: 400px;
}
.tbl {
margin-top: 1em;
display: inline-block;
vertical-align: top;
}
.tbl table td:first-child {
text-align: left;
}
table {
border-collapse: collapse;
display: inline-block;
text-align: right;
}
td {
font-size: 70%;
border: 1px solid #444;
padding: 2px;
x-white-space: nowrap;
word-break: break-all;
}
select {
font-size: 16px;
}
#credit a {
color: gray !important;
text-decoration: none;
}
#credit {
margin-top: 1em;
font-size: 80%;
}
#head {
font-size: 80%;
margin-bottom: .5em;
}
#head a {
color: gray !important;
text-decoration: none;
}
#title {
margin-top: 1em;
}
button {
margin: 3px;
background-color: white;
}
@media screen and (max-width: 440px) {
.piechart {
margin: 0;
}
canvas {
display: inline-block;
width: 360px;
height: 360px;
}
}
#credit {
margin-top: 1em;
}
</style>
<script type="module" src="https://code4fukui.github.io/qr-code/qr-code.js"></script>
<qr-code></qr-code><br>
</body>
</html>