/
company_diff.html
122 lines (106 loc) · 3.6 KB
/
company_diff.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
<!DOCTYPE html><html lang="ja"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width">
<title>日本の法人数推移(2021/7/14基準)</title>
<link rel="stylesheet" href="https://unpkg.com/sakura.css/css/sakura.css" type="text/css">
<meta property="og:title" content="創廃業グラフ">
<meta name="format-detection" content="telephone=no"/>
<style>
body {
max-width: 85vw;
}
#msg {
font-size: 130%;
margin: 1em;
}
</style>
<script type="module">
import * as d3 from "https://cdn.skypack.dev/d3@7";
import { Day } from "https://js.sabae.cc/DateTime.js";
import { ArrayUtil } from "https://js.sabae.cc/ArrayUtil.js";
import { Num } from "https://js.sabae.cc/Num.js";
window.onload = async () => {
// set the dimensions and margins of the graph
const margin = { top: 40, right: 10, bottom: 30, left: 60 };
const width = 800 - margin.left - margin.right;
const height = 500 - margin.top - margin.bottom;
// append the svg object to the body of the page
const svg = d3.select("#my_dataviz")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", `translate(${margin.left}, ${margin.top})`);
//Read the data
const data = await d3.csv("./data/diff_summary.csv");
let org = 0;
data.forEach(d => {
d.ncreated = parseInt(d.ncreated);
d.nterminated = parseInt(d.nterminated);
d.n = d.ncreated - d.nterminated + org;
org = d.n;
});
const max = ArrayUtil.max(data, (d) => d.n + d.ncreated);
const maxy = max.n + max.ncreated;
const parseTime = d3.timeParse("%Y-%m-%d");
const orgday = new Day(data[0].date).getDayOfGregorian();
data.forEach(d => {
//d.x = new Day(d.date).getDayOfGregorian() - orgday;
//d.x = new Date(d.date); // new Day(d.date).getDayOfGregorian() - orgday;
d.x = parseTime(d.date);
});
const maxx = data[data.length - 1].x;
console.log(maxx, maxy);
// set axis
//const x = d3.scaleLinear()
const x = d3.scaleTime()
//.domain([0, maxx])
.domain([data[0].x, data[data.length - 1].x])
.range([0, width]);
const y = d3.scaleLinear()
.domain([0, maxy])
.range([height, 0]);
// Add X axis
svg.append("g")
.attr("transform", `translate(0, ${height})`)
.call(d3.axisBottom(x).tickFormat(d3.timeFormat("%m/%e")));
svg.append("g")
.call(d3.axisLeft(y));
// Show confidence interval
svg.append("path")
.datum(data)
.attr("fill", "#cce5df")
.attr("stroke", "none")
.attr("d", d3.area()
.x(d => x(d.x))
.y0(d => y(d.n - d.nterminated))
.y1(d => y(d.n + d.ncreated))
);
// Add the line
svg
.append("path")
.datum(data)
.attr("fill", "none")
.attr("stroke", "steelblue")
.attr("stroke-width", 1.5)
.attr("d", d3.line()
.x(d => x(d.x))
.y(d => y(d.n))
);
//
const ncsum = data.reduce((pre, d) => pre + d.ncreated, 0);
const ntsum = data.reduce((pre, d) => pre + d.nterminated, 0);
const sum = ncsum - ntsum; // data[data.length - 1].ncreated;
msg.textContent = `2021-07-14から、新規${Num.addComma(ncsum)}法人、廃止${Num.addComma(ntsum)}法人、合計${sum > 0 ? "+" : ""}${Num.addComma(sum)}法人`;
};
</script>
</head>
<body>
<h1>日本の法人数推移(2021/7/14基準)</h1>
<div id="my_dataviz"></div>
<div id="msg"></div>
<div class="credit">
Related: <a href=./company_dashboard.html>創廃業ダッシュボード</a><br>
APP: CC BY <a href=https://fukuno.jig.jp/3335>@taisukef 福野泰介</a><br>
DATA: <a href="https://www.houjin-bangou.nta.go.jp/">国税庁法人番号公表サイト</a> → (<a href="https://github.com/code4fukui/gBizINFO/">gBizINFO CSV化ツール on GitHub</a>)<br>
</div>
</body>
</html>