-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
398 lines (370 loc) · 11.3 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
<!DOCTYPE html><html lang="ja"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width"><link rel="icon" href="data:">
<title>上場企業ダッシュボード</title>
<meta property="og:title" content="上場企業ダッシュボード">
<meta name="format-detection" content="telephone=no"/>
<style>
body {
font-family: sans-serif;
text-align: center;
margin: 0;
padding: 0;
}
h1 {
margin: 0;
font-size: 5vw;
padding: 2vw 0;
margin-bottom: 1vw;
background-color: #ff5959;
color: white;
}
h1 a {
text-decoration: none;
color: white !important;
}
h3 {
padding: .2em 0;
margin: 0;
}
#back {
margin: .5em;
}
.sub {
font-size: 83%;
display: inline-block;
background-color: white;
padding: 0 .3em;
}
.name {
font-size: min(2.5vw, 20px);
}
.num {
font-weight: bold;
}
.created {
color: #fd3a3a;
}
.terminated {
color:#718ab2;
}
/* tabularmaps */
#tmapc {
max-width: 800px;
margin: 0 auto;
}
#tmapc > div > span {
font-size: min(1.5vw, 15px);
align-items: center;
justify-content: center;
border-radius: .5vw;
border: .1vw solid #333;
padding: .1vw .1vw;
margin: .2vw;
}
/* other */
select {
font-size: 20px;
margin: 0 0 .5em 0;
}
#detail {
text-align: left;
padding: .3em;
font-size: 90%;
overflow: scroll;
display: inline-block;
border: 1px solid gray;
width: 90vw;
max-width: 700px;
height: 10em;
}
/* credit */
.credit {
margin: 20px;
text-align: center;
font-size: 80%;
}
a {
color: #666 !important;
}
.links {
margin: 0;
margin-bottom: 1em;
x-background-color: #fd3a3a;
background-color: #ff6969;
}
.links a {
display: inline-block;
padding: .3em;
margin: 0.1 1em;
color: white !important;
text-decoration: none;
}
</style>
</head>
<body>
<h1><a href=./>上場企業ダッシュボード <span id=tmtitle></span></a></h1>
<select id="selindustry"></select>
<select id="selmarket"></select>
<select id="selsize">
<option value=0>時価総額</option>
<option value=1>1兆円以上</option>
<option value=2>1000億円以上</option>
<option value=3>1000億円未満</option>
</select>
<select id="selyear">
<option value=0>設立年</option>
<option value=1996>1996年以降</option>
<option value=2000>2000年以降</option>
<option value=2010>2010年以降</option>
<option value=2020>2020年以降</option>
</select>
<label><input id="chkdiff" type="checkbox">差分</label>
<br>
<div id="tmapc"></div>
<button id="back">戻る</button><br>
<div><span id=lastUpdate></span> *設立年は832社(21.7%)が調査中</div>
<div id="detail"></div>
<link rel="stylesheet" href="banner.css">
<div id="banners"></div>
<div class="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>
LAYOUT: <a href=https://github.com/tabularmaps/areamap/blob/master/tabularmaps_japan.csv>TabularMaps Japan - 日本カラム地図 CSV</a> CC0 <a href=https://github.com/tabularmaps/hq>カラム地図 / TabularMaps on Github</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 { ArrayUtil } from "https://js.sabae.cc/ArrayUtil.js";
import { encodeHTML } from "https://js.sabae.cc/encodeHTML.js";
import tabularmaps from "https://code4fukui.github.io/gBizINFO/tabularmapsjapan.js";
import { JAPAN_PREF, JAPAN_PREF_EN } from "https://js.sabae.cc/JAPAN_PREF.js";
import { Num } from "https://js.sabae.cc/Num.js";
import { setSelectMarket, markets, setSelectIndustry, industry17 } from "./setSelect.js";
import "./banner.js";
const convertJapanEn2Ja = (en) => {
return JAPAN_PREF[JAPAN_PREF_EN.indexOf(en)];
};
const fixMarketCap = (yen_m, plus) => yen_m ? (plus && yen_m >=0 ? "+" : "") + Num.fixbig(yen_m, true) + "円" : "-";
setSelectMarket(selmarket);
setSelectIndustry(selindustry);
const show = async () => {
const list = await CSV.fetchJSON("./data/marketcap/index.csv");
const latest = list[list.length - 1];
console.log(latest);
const data = await CSV.fetchJSON("./data/marketcap/" + latest.file);
console.log(data.length); // old 3805 -> 3813
data.sort((a, b) => b.marketcap_m - a.marketcap_m);
const past = list[list.length - 2];
let datapast = null;
const sumMarketCap = (list, bsum = false) => {
if (!chkdiff.checked || bsum) {
const sum = list.reduce((pre, i) => pre + parseInt(i.marketcap_m), 0);
return sum;
} else {
let sum = 0;
for (const i of list) {
const n = parseInt(i.marketcap_m);
const pp = datapast.find(j => j.seccode == i.seccode);
if (pp) {
sum += n - pp.marketcap_m;
} else {
sum += n;
}
}
return sum;
}
};
lastUpdate.textContent = `更新日: ${latest.date} (差分は${past.date}から)`;
const showunit = "社";
const getData = () => {
let ret = data;
const market = selmarket.value;
if (market != "all") {
ret = ret.filter(i => i.market == market);
}
const industry = selindustry.value;
if (industry != "all") {
ret = ret.filter(i => i.type == industry);
}
const y = selyear.value;
if (y > 0) {
ret = ret.filter(i => i.since && i.since >= y);
}
const s = parseInt(selsize.value);
if (s > 0) {
if (s == 1) {
ret = ret.filter(i => i.marketcap_m >= 1000000);
} else if (s == 2) {
ret = ret.filter(i => i.marketcap_m >= 100000);
} else if (s == 3) {
ret = ret.filter(i => i.marketcap_m < 100000);
}
}
return ret;
};
//const showname = sel.value;
const getKPI = (pname, cname) => {
const data = getData();
if (pname == "日本") {
const p = data.filter(i => i.pref == cname);
const unit = showunit;
if (!p) {
return { kpi: 0, mcap: 0 };
}
return { kpi: p.length, mcap: sumMarketCap(p) };
} else {
const p = data.filter(i => i.pref == pname);
const unit = showunit;
if (!p) {
return { kpi: 0, mcap: 0 };
}
const cityMatch = (s1, s2) => s1.startsWith(s2) || s1.endsWith(s2);
const list = p.filter(d => cityMatch(d.city, cname));
const kpi = list.length;
const mcap = sumMarketCap(list);
return { kpi, mcap };
}
};
const colorTabularMaps = (pname, tmap) => {
let min = 10000000000;
let max = -min;
for (const c of tmap.children) {
const cname = c.cellname;
if (cname !== "-") {
const { mcap } = getKPI(pname, cname);
const kpi = mcap;
if (isNaN(kpi)) continue;
if (kpi < min) min = kpi;
if (kpi > max) max = kpi;
}
}
//max = 100;
const n2log = (n) => {
//return Math.log((Math.E - 1) * n + 1);
return Math.pow(n, .5);
//return n;
};
for (const c of tmap.children) {
const cname = c.cellname;
if (cname !== "-") {
const { mcap } = getKPI(pname, cname);
const kpi = mcap;
if (isNaN(kpi)) {
continue;
}
//const n = (parseFloat(kpi) - min) / (max - min);
const maxabs = Math.max(Math.abs(max), Math.abs(min));
if (kpi == 0) {
c.style.backgroundColor = "white";
c.style.color = "black";
} else if (kpi > 0) {
//const n = kpi > max ? 1 : n2log((kpi - min) / (max - min));
const n = kpi > maxabs ? 1 : n2log(kpi / maxabs);
const h = 7;
const s = 80;
const l = 97 - n * 47;
const col = `hsl(${h},${s}%,${l}%)`;
//const col = `rgba(200,50,50,${l / 100 * .5})`;
c.style.backgroundColor = col;
c.style.color = l > 70 ? "black" : "white";
} else if (kpi < 0) {
const n = kpi < -maxabs ? 1 : n2log(kpi / -maxabs);
//const n = parseFloat(kpi) / min;
const h = 220;
const s = 50;
const l = 95 - n * 40;
const col = `hsl(${h},${s}%,${l}%)`;
//const col = `rgba(200,50,50,${l / 100 * .5})`;
c.style.backgroundColor = col;
c.style.color = l > 70 ? "black" : "white";
}
}
}
};
const showDetail = (cname) => {
const data = getData();
let p = null;
if (!cname) {
p = data;
cname = "全国";
} else {
p = data.filter(i => i.pref == cname);
if (!p) {
p = [];
}
}
const n = p.length;
const add = (p) => {
const child = cname == "全国" ? "pref" : "city";
const cities0 = ArrayUtil.toUnique(p.map(d => d[child]));
const cnts = cities0.map(c => ({ name: c, cnt: p.filter(p => p[child] == c).length }));
cnts.sort((a, b) => b.cnt - a.cnt);
const cities = cnts.map(c => c.name);
const pp = [];
for (const c of cities) {
const p2 = p.filter(p => p[child] == c);
const html = `<h3>${c} ${p2.length}社</h3>` + p2.map(d => {
const market = markets[d.market];
const res = { name: encodeHTML(d.name), seccode: d.seccode, market, mcap: d.marketcap_m };
if (datapast) {
const p = datapast.find(i => i.seccode == d.seccode);
if (p) {
res.mcapd = d.marketcap_m - p.marketcap_m;
}
}
return res;
}).map(({ name, seccode, market, mcap, mcapd }) => `
<a href="https://www.google.com/search?q=${name}">${name}</a>
(<a href="https://finance.yahoo.co.jp/quote/${seccode}.T">${seccode}</a>
${market}) ${fixMarketCap(mcap)}${mcapd === undefined ? "" : " " + fixMarketCap(mcapd, true)}
`).join("<br>");
pp.push(html);
}
return pp.join("");
}
const market = selmarket.value != "all" ? markets[selmarket.value] : "";
const industry = selindustry.value != "all" ? ` (${industry17.find(i => i.type == selindustry.value).name})` : "";
const head = `<h3>${cname}の東証${market}上場企業${n}社${industry} 時価総額合計${fixMarketCap(sumMarketCap(p, true))}${!datapast ? "" : " " + fixMarketCap(sumMarketCap(p), true)}</h3>`;
detail.innerHTML = head + add(p);
};
const setCellContent = (c, pname, cname) => {
c.textContent = "";
const cr = tag => document.createElement(tag);
const div = cr("div");
div.className = "name";
div.textContent = cname;
c.appendChild(div);
const div2 = cr("div");
div2.className = "val";
const { kpi, mcap } = getKPI(pname, cname);
div2.innerHTML = `<span class=num>${kpi}社</span><br><span class=num2>${fixMarketCap(mcap, chkdiff.checked)}</span>`;
c.appendChild(div2);
if (pname == "日本") {
c.onclick = () => {
showDetail(cname);
};
}
};
const show2 = async () => {
if (chkdiff.checked && !datapast) {
datapast = await CSV.fetchJSON("./data/marketcap/" + past.file);
}
tabularmaps.showJapan(setCellContent, colorTabularMaps, false);
const pname = convertJapanEn2Ja(document.location.hash.substring(1));
showDetail(pname);
};
show2();
selmarket.oninput = () => show2();
selindustry.oninput = () => show2();
selyear.oninput= () => show2();
selsize.oninput= () => show2();
chkdiff.oninput = () => show2();
addEventListener("hashchange", () => {
const pname = convertJapanEn2Ja(document.location.hash.substring(1));
showDetail(pname);
});
};
await show();
</script>
<script type="module" src="https://code4fukui.github.io/qr-code/qr-code.js"></script>
<qr-code></qr-code><br>
</body>
</html>