グラフ画面のデータ参照を少しだけマシにした

This commit is contained in:
shibafu 2019-03-05 01:08:17 +09:00
parent 2c396da84e
commit 1348054858
3 changed files with 19 additions and 23 deletions

View File

@ -127,8 +127,19 @@ SQL
$hour = (int)$data->hour;
$hourlySum[$hour] += $data->count;
}
$graphData = [
'dailySum' => $dailySum,
'dowSum' => $dowSum,
'monthlyKey' => array_keys($monthlySum),
'monthlySum' => array_values($monthlySum),
'yearlyKey' => array_keys($yearlySum),
'yearlySum' => array_values($yearlySum),
'hourlyKey' => array_keys($hourlySum),
'hourlySum' => array_values($hourlySum),
];
return view('user.stats')->with(compact('user', 'dailySum', 'monthlySum', 'yearlySum', 'dowSum', 'hourlySum'));
return view('user.stats')->with(compact('user', 'graphData'));
}
public function okazu($name)

View File

@ -62,15 +62,7 @@ function createBarGraph(id, labels, data) {
});
}
// TODO: これはいくらなんでもひどすぎるだろ
const dailySum = JSON.parse(document.getElementById('graph-daily-sum').textContent);
const monthlyKey = JSON.parse(document.getElementById('graph-monthly-key').textContent);
const monthlySum = JSON.parse(document.getElementById('graph-monthly-sum').textContent);
const yearlyKey = JSON.parse(document.getElementById('graph-yearly-key').textContent);
const yearlySum = JSON.parse(document.getElementById('graph-yearly-sum').textContent);
const hourlyKey = JSON.parse(document.getElementById('graph-hourly-key').textContent);
const hourlySum = JSON.parse(document.getElementById('graph-hourly-sum').textContent);
const dowSum = JSON.parse(document.getElementById('graph-dow-sum').textContent);
const graphData = JSON.parse(document.getElementById('graph-data').textContent);
new CalHeatMap().init({
itemSelector: '#cal-heatmap',
@ -80,11 +72,11 @@ new CalHeatMap().init({
weekStartOnMonday: false,
start: new Date().setMonth(new Date().getMonth() - 9),
range: 10,
data: dailySum,
data: graphData.dailySum,
legend: [1, 2, 3, 4]
});
createLineGraph('monthly-graph', monthlyKey, monthlySum);
createLineGraph('yearly-graph', yearlyKey, yearlySum);
createBarGraph('hourly-graph', hourlyKey, hourlySum);
createBarGraph('dow-graph', ['日', '月', '火', '水', '木', '金', '土'], dowSum);
createLineGraph('monthly-graph', graphData.monthlyKey, graphData.monthlySum);
createLineGraph('yearly-graph', graphData.yearlyKey, graphData.yearlySum);
createBarGraph('hourly-graph', graphData.hourlyKey, graphData.hourlySum);
createBarGraph('dow-graph', ['日', '月', '火', '水', '木', '金', '土'], graphData.dowSum);

View File

@ -30,13 +30,6 @@
@endsection
@push('script')
<script id="graph-daily-sum" type="application/javascript">@json($dailySum)</script>
<script id="graph-monthly-key" type="application/javascript">@json(array_keys($monthlySum))</script>
<script id="graph-monthly-sum" type="application/javascript">@json(array_values($monthlySum))</script>
<script id="graph-yearly-key" type="application/javascript">@json(array_keys($yearlySum))</script>
<script id="graph-yearly-sum" type="application/javascript">@json(array_values($yearlySum))</script>
<script id="graph-hourly-key" type="application/javascript">@json(array_keys($hourlySum))</script>
<script id="graph-hourly-sum" type="application/javascript">@json(array_values($hourlySum))</script>
<script id="graph-dow-sum" type="application/javascript">@json($dowSum)</script>
<script id="graph-data" type="application/javascript">@json($graphData)</script>
<script src="{{ mix('js/user/stats.js') }}"></script>
@endpush