Commit ca2a2aea authored by Clement Ho's avatar Clement Ho

Merge branch '35136-barchart-not-display-label-at-0-hour' into 'master'

Fix bar chart does not display label at hour 0

Closes #35136

See merge request !13330
parents 2b781c78 2b9a64a2
import Chart from 'vendor/Chart'; import Chart from 'vendor/Chart';
import _ from 'underscore';
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
const projectChartData = JSON.parse(document.getElementById('projectChartData').innerHTML); const projectChartData = JSON.parse(document.getElementById('projectChartData').innerHTML);
...@@ -27,28 +28,25 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -27,28 +28,25 @@ document.addEventListener('DOMContentLoaded', () => {
return generateChart(); return generateChart();
}; };
const chartData = (keys, values) => { const chartData = data => ({
const data = { labels: Object.keys(data),
labels: keys, datasets: [{
datasets: [{ fillColor: 'rgba(220,220,220,0.5)',
fillColor: 'rgba(220,220,220,0.5)', strokeColor: 'rgba(220,220,220,1)',
strokeColor: 'rgba(220,220,220,1)', barStrokeWidth: 1,
barStrokeWidth: 1, barValueSpacing: 1,
barValueSpacing: 1, barDatasetSpacing: 1,
barDatasetSpacing: 1, data: _.values(data),
data: values, }],
}], });
};
return data; const hourData = chartData(projectChartData.hour);
};
const hourData = chartData(projectChartData.hour.keys, projectChartData.hour.values);
responsiveChart($('#hour-chart'), hourData); responsiveChart($('#hour-chart'), hourData);
const dayData = chartData(projectChartData.weekDays.keys, projectChartData.weekDays.values); const dayData = chartData(projectChartData.weekDays);
responsiveChart($('#weekday-chart'), dayData); responsiveChart($('#weekday-chart'), dayData);
const monthData = chartData(projectChartData.month.keys, projectChartData.month.values); const monthData = chartData(projectChartData.month);
responsiveChart($('#month-chart'), monthData); responsiveChart($('#month-chart'), monthData);
const data = projectChartData.languages; const data = projectChartData.languages;
......
...@@ -78,8 +78,8 @@ ...@@ -78,8 +78,8 @@
%script#projectChartData{ type: "application/json" } %script#projectChartData{ type: "application/json" }
- projectChartData = {}; - projectChartData = {};
- projectChartData['hour'] = { 'keys' => @commits_per_time.keys, 'values' => @commits_per_time.values } - projectChartData['hour'] = @commits_per_time
- projectChartData['weekDays'] = { 'keys' => @commits_per_week_days.keys, 'values' => @commits_per_week_days.values } - projectChartData['weekDays'] = @commits_per_week_days
- projectChartData['month'] = { 'keys' => @commits_per_month.keys, 'values' => @commits_per_month.values } - projectChartData['month'] = @commits_per_month
- projectChartData['languages'] = @languages - projectChartData['languages'] = @languages
= projectChartData.to_json.html_safe = projectChartData.to_json.html_safe
---
title: Fix bar chart does not display label at 0 hour
merge_request: 35136
author: Jason Dai
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment