diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index f2c3c83..db289a8 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -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) diff --git a/resources/assets/js/user/stats.js b/resources/assets/js/user/stats.js index 6077499..adb9628 100644 --- a/resources/assets/js/user/stats.js +++ b/resources/assets/js/user/stats.js @@ -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); \ No newline at end of file +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); \ No newline at end of file diff --git a/resources/views/user/stats.blade.php b/resources/views/user/stats.blade.php index fce9380..997a1de 100644 --- a/resources/views/user/stats.blade.php +++ b/resources/views/user/stats.blade.php @@ -30,13 +30,6 @@ @endsection @push('script') - - - - - - - - + @endpush \ No newline at end of file