Skip to content

Commit 2066581

Browse files
Copilotivanvpetrov
andcommitted
chore(extras): polish axis auto-hide docs and tests
Co-authored-by: ivanvpetrov <110455887+ivanvpetrov@users.noreply.github.com> Agent-Logs-Url: https://github.com/IgniteUI/igniteui-angular/sessions/0938b32f-510b-4e57-aa3b-bc186cb5b085
1 parent 0ecc116 commit 2066581

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

projects/igniteui-angular-extras/src/lib/directives/chart-integration/chart-integration.directive.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ describe('IgxChartIntegrationDirective', () => {
291291

292292
it('should auto-hide y-axis and skip series creation when autoHideYAxisWhenNoData is enabled and no numeric values exist', () => {
293293
directive.autoHideYAxisWhenNoData = true;
294-
directive.chartData = [{ name: 'A', value: Number.NaN }, { name: 'B', value: undefined as any }];
294+
directive.chartData = [{ name: 'A', value: Number.NaN }, { name: 'B', value: Number.NaN }];
295295

296296
const axisAddArgs: any[] = [];
297297
const seriesAddSpy = jasmine.createSpy('seriesAdd');

projects/igniteui-angular-extras/src/lib/directives/chart-integration/chart-integration.directive.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ export class IgxChartIntegrationDirective {
8989
@Input()
9090
public defaultLabelMemberPath: string = undefined;
9191

92+
/**
93+
* When set to `true`, the directive automatically hides the Y-axis if the
94+
* selected numeric member paths do not contain finite numeric values in the
95+
* current data view.
96+
*
97+
* @default false
98+
*/
9299
@Input()
93100
public autoHideYAxisWhenNoData = false;
94101

@@ -285,17 +292,17 @@ export class IgxChartIntegrationDirective {
285292
const customComponentOptions: IChartComponentOptions = this.customChartComponentOptions.get(type) || {};
286293
const customChartOptions = customComponentOptions.chartOptions || {};
287294
const customSeriesModel = customComponentOptions.seriesModel || {};
288-
const valueMemberPathsWithData = this._valueMemberPaths.filter(memberPath => this.hasSeriesData(memberPath));
289-
const valueMemberPathsForSeries = this.autoHideYAxisWhenNoData ? valueMemberPathsWithData : this._valueMemberPaths;
295+
const pathsWithData = this._valueMemberPaths.filter(memberPath => this.hasSeriesData(memberPath));
296+
const seriesPaths = this.autoHideYAxisWhenNoData ? pathsWithData : this._valueMemberPaths;
290297
chartComponentOptions.chartOptions = { ...this.dataChartOptions, ...customChartOptions };
291298
if (type.indexOf('Scatter') !== -1) {
292299
this.addScatterChartDataOptions(type, chartComponentOptions);
293300
} else {
294301
chartComponentOptions.seriesModel = { ...this.dataChartSeriesOptionsModel, ...customSeriesModel };
295-
const hideYAxis = this.autoHideYAxisWhenNoData && valueMemberPathsWithData.length === 0;
302+
const hideYAxis = this.autoHideYAxisWhenNoData && pathsWithData.length === 0;
296303
this.setAxisLabelOption(type, chartComponentOptions, hideYAxis);
297304
const options: IOptions[] = [];
298-
valueMemberPathsForSeries.forEach(valueMemberPath => {
305+
seriesPaths.forEach(valueMemberPath => {
299306
const dataOptions = {
300307
title: valueMemberPath,
301308
valueMemberPath
@@ -352,6 +359,13 @@ export class IgxChartIntegrationDirective {
352359
return dataRecord;
353360
}
354361

362+
/**
363+
* Checks whether the current data set contains at least one finite numeric
364+
* value for the provided member path.
365+
*
366+
* @param memberPath The numeric member path to inspect.
367+
* @returns `true` when at least one finite number exists for the path.
368+
*/
355369
private hasSeriesData(memberPath: string): boolean {
356370
return this._chartData.some(record => Number.isFinite(record[memberPath]));
357371
}

0 commit comments

Comments
 (0)