グラフ画面のデータ参照を少しだけマシにした
This commit is contained in:
parent
2c396da84e
commit
1348054858
@ -127,8 +127,19 @@ SQL
|
|||||||
$hour = (int)$data->hour;
|
$hour = (int)$data->hour;
|
||||||
$hourlySum[$hour] += $data->count;
|
$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)
|
public function okazu($name)
|
||||||
|
20
resources/assets/js/user/stats.js
vendored
20
resources/assets/js/user/stats.js
vendored
@ -62,15 +62,7 @@ function createBarGraph(id, labels, data) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: これはいくらなんでもひどすぎるだろ
|
const graphData = JSON.parse(document.getElementById('graph-data').textContent);
|
||||||
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);
|
|
||||||
|
|
||||||
new CalHeatMap().init({
|
new CalHeatMap().init({
|
||||||
itemSelector: '#cal-heatmap',
|
itemSelector: '#cal-heatmap',
|
||||||
@ -80,11 +72,11 @@ new CalHeatMap().init({
|
|||||||
weekStartOnMonday: false,
|
weekStartOnMonday: false,
|
||||||
start: new Date().setMonth(new Date().getMonth() - 9),
|
start: new Date().setMonth(new Date().getMonth() - 9),
|
||||||
range: 10,
|
range: 10,
|
||||||
data: dailySum,
|
data: graphData.dailySum,
|
||||||
legend: [1, 2, 3, 4]
|
legend: [1, 2, 3, 4]
|
||||||
});
|
});
|
||||||
|
|
||||||
createLineGraph('monthly-graph', monthlyKey, monthlySum);
|
createLineGraph('monthly-graph', graphData.monthlyKey, graphData.monthlySum);
|
||||||
createLineGraph('yearly-graph', yearlyKey, yearlySum);
|
createLineGraph('yearly-graph', graphData.yearlyKey, graphData.yearlySum);
|
||||||
createBarGraph('hourly-graph', hourlyKey, hourlySum);
|
createBarGraph('hourly-graph', graphData.hourlyKey, graphData.hourlySum);
|
||||||
createBarGraph('dow-graph', ['日', '月', '火', '水', '木', '金', '土'], dowSum);
|
createBarGraph('dow-graph', ['日', '月', '火', '水', '木', '金', '土'], graphData.dowSum);
|
@ -30,13 +30,6 @@
|
|||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
@push('script')
|
@push('script')
|
||||||
<script id="graph-daily-sum" type="application/javascript">@json($dailySum)</script>
|
<script id="graph-data" type="application/javascript">@json($graphData)</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 src="{{ mix('js/user/stats.js') }}"></script>
|
<script src="{{ mix('js/user/stats.js') }}"></script>
|
||||||
@endpush
|
@endpush
|
Loading…
Reference in New Issue
Block a user