-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
292 lines (270 loc) · 8.33 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
<!DOCTYPE html><html lang="ja"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width"><link rel="icon" href="data:">
<title>福井県観光アンケート(データ出典:福井県観光連盟)</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dayjs/1.11.6/dayjs.min.js"></script>
</head><body>
<h1 id=title></h1>
<div id=ctrlbox>
<div id=prefbox></div>
<label><input type=checkbox id=chkdual>2期間比較</label>
</div>
<div id=divsels></div>
<div id=divs>
<div id=div1>
<div id=divdate></div>
<div id=divpie></div>
</div>
<div id=div2>
<div id=divdate2></div>
<div id=divpie2></div>
</div>
</div>
<hr />
(<a href=https://github.com/code4fukui/fukui-kanko-survey>data on GitHub</a>, <a href="https://github.com/code4fukui/fukui-kanko-stat/">src on GitHub by Code for FUKUI</a>)<br>
<script type="module" src="https://code4fukui.github.io/qr-code/qr-code.js"></script>
<qr-code></qr-code><br>
</div>
<script type="module">
import { ChartPie } from "./ChartPie.js";
import { ChartBar } from "./ChartBar.js";
import { CSV } from "https://js.sabae.cc/CSV.js";
import {} from "./header.js";
import { SurveySelector } from "./survey-selector.js";
import { fetchAreas } from "./area.js";
import { getSurvey } from "./getSurvey.js";
import { Day } from "https://js.sabae.cc/DateTime.js";
const CHART_INDEX_SINGLE = "single";
const CHART_INDEX_MULTI = "multi";
// iOS14以前に関する対応(top-level await未対応のため)
addEventListener("load", async () => {
const areas = await fetchAreas();
title.textContent = document.title;
const surveySelector = new SurveySelector(areas);
// チャートの種類
const chartType = {
"pie": "円グラフ",
"bar": "棒グラフ"
}
// 各チャートの情報
let charts = {
"都道府県": {
type: chartType["pie"],
index: CHART_INDEX_SINGLE
},
"年代": {
type: chartType["bar"],
index: CHART_INDEX_SINGLE
},
"性別": {
type: chartType["pie"],
index: CHART_INDEX_SINGLE
},
"6分類": {
type: chartType["pie"],
index: CHART_INDEX_SINGLE
},
"回答エリア": {
type: chartType["pie"],
index: CHART_INDEX_SINGLE
},
"世帯年収": {
type: chartType["bar"],
index: CHART_INDEX_SINGLE
},
"回答月": {
type: chartType["pie"],
index: CHART_INDEX_SINGLE
},
"満足度": {
type: chartType["pie"],
index: CHART_INDEX_SINGLE
},
"不便さ": {
type: chartType["pie"],
index: CHART_INDEX_SINGLE
},
"NPS": {
type: chartType["pie"],
index: CHART_INDEX_SINGLE
},
"宿泊数(県内)": {
type: chartType["pie"],
index: CHART_INDEX_SINGLE
},
"今後の来訪意向": {
type: chartType["pie"],
index: CHART_INDEX_SINGLE
},
"同行者": {
type: chartType["pie"],
index: CHART_INDEX_SINGLE
},
"訪問目的": {
type: chartType["pie"],
index: CHART_INDEX_MULTI,
delimiter: "\n"
},
"情報収集": {
type: chartType["pie"],
index: CHART_INDEX_MULTI,
delimiter: "\n"
}
};
const sortData = (key, obj) => {
const names = surveySelector.sortSelectCodes(key, Object.keys(obj));
const res = {};
for (const name of names) {
res[name] = obj[name];
}
return res;
};
const show = async (divpie, fromd, tod) => {
divpie.innerHTML = "";
const csv2 = await surveySelector.filter(fromd, tod);
if (csv2.length) {
const names = Object.keys(charts);
names.forEach((name, index) => {
const data = {};
switch (charts[name].index) {
case CHART_INDEX_SINGLE:
for (const d of csv2) {
surveySelector.convertData(name, d);
const v = d[name];
if (!data[v]) {
data[v] = 1;
} else {
data[v]++;
}
}
break;
case CHART_INDEX_MULTI:
for (const d of csv2) {
const values = d[`${name}ALL`].split(charts[name].delimiter);
for (const v of values) {
if (!v) {
continue;
}
if (!data[v]) {
data[v] = 1;
} else {
data[v]++;
}
}
}
break;
}
const data2 = sortData(name, data);
const option = {};
if (window.innerWidth <= 480) {
option.width = window.innerWidth - 8;
option.showlegend = false;
}
const chartPie = new ChartPie(data2, option);
chartPie.id = "chart-pie" + index;
const chartBar = new ChartBar(data2, option);
chartBar.id = "chart-bar" + index;
const div2 = document.createElement("div");
div2.style.display = "inline-block";
const span = document.createElement("span");
const chartTitle = charts[name].index == CHART_INDEX_MULTI ? `${name}(複数回答あり)` : name;
span.textContent = chartTitle + ` (${csv2.length}件)`;
const chartSelect = document.createElement("select");
for (const key in chartType) {
const opt = document.createElement("option");
opt.textContent = chartType[key];
if (charts[name]["type"] == chartType[key]) {
opt.selected = true;
}
chartSelect.appendChild(opt);
};
span.appendChild(document.createElement("br"));
span.appendChild(chartSelect);
div2.appendChild(span);
div2.appendChild(document.createElement("br"));
div2.appendChild(chartPie);
div2.appendChild(chartBar);
divpie.append(div2);
const setChartType = (type) => {
switch (type) {
case chartType["pie"]:
chartPie.style.display = "inline-block";
chartBar.style.display = "none";
break;
case chartType["bar"]:
chartPie.style.display = "none";
chartBar.style.display = "inline-block";
break;
}
};
setChartType(charts[name].type);
chartSelect.onchange = () => {
const type = event.target.value;
setChartType(type);
};
});
};
};
// initial csv
const csv = await getSurvey(new Day().dayBefore(2), new Day());
const dates1 = surveySelector.createDates(divdate);
const show1 = () => {
const fromd = new Day(dates1.infromd.value);
const tod = new Day(dates1.intod.value);
show(divpie, fromd, tod);
};
dates1.infromd.onchange = dates1.intod.onchange = show1;
//dates1.infromd.oninput = dates1.intod.oninput = show1;
show1();
const dates2 = surveySelector.createDates(divdate2);
const show2 = () => {
const fromd = new Day(dates2.infromd.value);
const tod = new Day(dates2.intod.value);
show(divpie2, fromd, tod);
};
dates2.infromd.onchange = dates2.intod.onchange = show2;
//dates2.infromd.oninput = dates2.intod.oninput = show2;
show2();
const showall = () => {
show1();
show2();
};
surveySelector.createSelects(divsels, showall);
chkdual.onchange = () => {
console.log(chkdual.checked);
if (chkdual.checked) {
div2.style.display = "inline-block";
div1.style.width = "48vw";
} else {
div2.style.display = "none";
div1.style.width = "100vw";
}
};
chkdual.onchange();
});
</script>
<style>
body {
text-align: center;
font-family: sans-serif;
}
textarea {
width: 70vw;
height: 8em;
}
#divsels {
margin-bottom: .5em;
}
#divsels select {
height: 7em;
}
#prefbox > * {
margin: .5em .2em;
}
#divs > div {
vertical-align: top;
display: inline-block;
width: 48vw;
}
#prefbox {
display: inline;
}
</style>