Merge branch 'RED-7853' into 'master'
RED-7853: Fixed lines not showing when only one month is displayed. See merge request redactmanager/red-ui!197
This commit is contained in:
commit
a5ba313375
@ -6,6 +6,8 @@ import { ChartBlue, ChartGreen, ChartRed } from '../../utils/constants';
|
||||
import { getLabelsFromLicense, getLineConfig } from '../../utils/functions';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
||||
import { addPaddingToArray } from '@utils/functions';
|
||||
import { ILicenseData } from '@red/domain';
|
||||
|
||||
@Component({
|
||||
selector: 'red-license-page-usage',
|
||||
@ -34,6 +36,10 @@ export class LicensePageUsageComponent {
|
||||
|
||||
#getPagesDatasets(): ChartDataset[] {
|
||||
const monthlyData = this.licenseService.selectedLicenseReport.monthlyData;
|
||||
if (monthlyData.length === 1) {
|
||||
const empty = monthlyData.map(() => ({ numberOfAnalyzedPages: 0 }) as ILicenseData)[0];
|
||||
addPaddingToArray<ILicenseData>(monthlyData, empty);
|
||||
}
|
||||
|
||||
return [
|
||||
{
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import dayjs, { Dayjs } from 'dayjs';
|
||||
import { FillTarget } from 'chart.js';
|
||||
import { hexToRgba } from '@utils/functions';
|
||||
import { addPaddingToArray, hexToRgba } from '@utils/functions';
|
||||
import { ILicenseReport } from '@red/domain';
|
||||
import { ComplexFillTarget } from 'chart.js/dist/types';
|
||||
|
||||
@ -32,14 +32,19 @@ export const getLineConfig: (
|
||||
});
|
||||
|
||||
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');
|
||||
let monthIterator = startMonth;
|
||||
|
||||
const result = [];
|
||||
|
||||
while (startMonth.isBefore(endMonth)) {
|
||||
result.push(verboseDate(startMonth));
|
||||
startMonth = startMonth.add(1, 'month');
|
||||
while (monthIterator.isBefore(endMonth)) {
|
||||
result.push(verboseDate(monthIterator));
|
||||
monthIterator = monthIterator.add(1, 'month');
|
||||
}
|
||||
|
||||
if (startMonth.month() === endMonth.month()) {
|
||||
addPaddingToArray<string>(result, '');
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -133,3 +133,8 @@ export function calcTextWidthInPixels(text: string): number {
|
||||
|
||||
return width;
|
||||
}
|
||||
|
||||
export function addPaddingToArray<T>(array: T[], emptyElement: T) {
|
||||
array.push(emptyElement);
|
||||
array.splice(0, 0, emptyElement);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user