RED-7853: Fixed lines not showing when only one month is displayed.
This commit is contained in:
parent
a68eb42fd7
commit
76be93f9a7
@ -6,6 +6,8 @@ import { ChartBlue, ChartGreen, ChartRed } from '../../utils/constants';
|
|||||||
import { getLabelsFromLicense, getLineConfig } from '../../utils/functions';
|
import { getLabelsFromLicense, getLineConfig } from '../../utils/functions';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
||||||
|
import { addPaddingToArray } from '@utils/functions';
|
||||||
|
import { ILicenseData } from '@red/domain';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'red-license-page-usage',
|
selector: 'red-license-page-usage',
|
||||||
@ -31,6 +33,10 @@ export class LicensePageUsageComponent {
|
|||||||
|
|
||||||
#getPagesDatasets(): ChartDataset[] {
|
#getPagesDatasets(): ChartDataset[] {
|
||||||
const monthlyData = this.licenseService.selectedLicenseReport.monthlyData;
|
const monthlyData = this.licenseService.selectedLicenseReport.monthlyData;
|
||||||
|
if (monthlyData.length === 1) {
|
||||||
|
const empty = monthlyData.map(() => ({ numberOfAnalyzedPages: 0 } as ILicenseData))[0];
|
||||||
|
addPaddingToArray<ILicenseData>(monthlyData, empty);
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import dayjs, { Dayjs } from 'dayjs';
|
import dayjs, { Dayjs } from 'dayjs';
|
||||||
import { FillTarget } from 'chart.js';
|
import { FillTarget } from 'chart.js';
|
||||||
import { hexToRgba } from '@utils/functions';
|
import { addPaddingToArray, hexToRgba } from '@utils/functions';
|
||||||
import { ILicenseReport } from '@red/domain';
|
import { ILicenseReport } from '@red/domain';
|
||||||
import { ComplexFillTarget } from 'chart.js/dist/types';
|
import { ComplexFillTarget } from 'chart.js/dist/types';
|
||||||
|
|
||||||
@ -32,14 +32,19 @@ export const getLineConfig: (
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const getLabelsFromLicense = (license: ILicenseReport) => {
|
export const getLabelsFromLicense = (license: ILicenseReport) => {
|
||||||
let startMonth = dayjs(license.startDate).startOf('month');
|
const startMonth = dayjs(license.startDate).startOf('month');
|
||||||
const endMonth = dayjs(license.endDate).endOf('month');
|
const endMonth = dayjs(license.endDate).endOf('month');
|
||||||
|
let monthIterator = startMonth;
|
||||||
|
|
||||||
const result = [];
|
const result = [];
|
||||||
|
|
||||||
while (startMonth.isBefore(endMonth)) {
|
while (monthIterator.isBefore(endMonth)) {
|
||||||
result.push(verboseDate(startMonth));
|
result.push(verboseDate(monthIterator));
|
||||||
startMonth = startMonth.add(1, 'month');
|
monthIterator = monthIterator.add(1, 'month');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (startMonth.month() === endMonth.month()) {
|
||||||
|
addPaddingToArray<string>(result, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@ -115,3 +115,8 @@ export function moveElementInArray<T>(array: T[], element: T, index: number) {
|
|||||||
result.splice(index, 0, element);
|
result.splice(index, 0, element);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function addPaddingToArray<T>(array: T[], emptyElement: T) {
|
||||||
|
array.splice(0, 0, emptyElement);
|
||||||
|
array.push(emptyElement);
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user