Skip to content

Commit

Permalink
Enhancement/highcharts category axis title (#763)
Browse files Browse the repository at this point in the history
* Add xAxis options

* Add interface FhiDiagramCategoryAxis
  • Loading branch information
proand authored Dec 12, 2024
1 parent 4a56206 commit 490368b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 3 deletions.
10 changes: 8 additions & 2 deletions projects/fhi-angular-highcharts/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# 5.2.0
# Unreleased

> Nov 27, 2024
* :tada: **Enhancement** Add option `categoryAxis` to `FhiDiagramOptions`, and add support for setting the category axis title [(#763)](https://github.com/folkehelseinstituttet/Fhi.Frontend.Demo/pull/763)

## 5.2.0

> Nov 27, 2024
* :tada: **Enhancement** Add test for disabling all other diagram types except `columnAndLine` (and `table`) if 2 units or more are defined in the diagram options. Also clean up existing tests for disabling diagram types [(#761)](https://github.com/folkehelseinstituttet/Fhi.Frontend.Demo/pull/761)
* :bug: **Bugfix** Make tooltip show zero decimals when `unit.decimals` set to `0`. Also fix inconsisten values for max decimals.
* :bug: **Bugfix** Make tooltip show zero decimals when `unit.decimals` set to `0`. Also fix inconsisten values for max decimals [(#744)](https://github.com/folkehelseinstituttet/Fhi.Frontend.Demo/pull/744)

## 5.1.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ export const OptionsCharts = {
xAxis: {
allowDecimals: false,
type: 'category',
title: {
text: undefined,
},
},
yAxis: {
allowDecimals: false,
title: {
text: null,
text: undefined,
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface FhiDiagramCategoryAxis {
title: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import { FhiDiagramSerie } from './fhi-diagram-serie.model';
import { FhiDiagramUnit } from './fhi-diagram-unit.model';
import { FhiDiagramControls } from './fhi-diagram-controls.model';
import { FhiDiagramFooter } from './fhi-diagram-footer.model';
import { FhiDiagramCategoryAxis } from './fhi-diagram-category-axis.model';

export type FhiDiagramTypeIds = keyof typeof DiagramTypeIds;
export type FhiTableOrientations = keyof typeof TableOrientations;

export interface FhiDiagramOptions {
activeDiagramType?: FhiDiagramTypeIds;
categoryAxis?: FhiDiagramCategoryAxis;
controls?: FhiDiagramControls;
description?: string;
footer?: FhiDiagramFooter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
SeriesOptionsType,
TooltipOptions,
XAxisLabelsOptions,
XAxisOptions,
YAxisOptions,
} from 'highcharts';

Expand Down Expand Up @@ -126,6 +127,8 @@ export class OptionsService {

private updateChartOptions(options: Options): Options {
options.series = this.getSeriesWithoutFlaggedDataPoints() as SeriesOptionsType[];
options.xAxis = this.getXAxis(options.xAxis as XAxisOptions, this.diagramOptions);

if (this.diagramOptions.units?.length === 1) {
options.yAxis = this.getYAxis(options.yAxis as YAxisOptions, this.diagramOptions.units[0]);
} else {
Expand Down Expand Up @@ -192,6 +195,12 @@ export class OptionsService {
return tooltip;
}

private getXAxis(xAxis: XAxisOptions, diagramOptions: FhiDiagramOptions): XAxisOptions {
xAxis = xAxis ? xAxis : {};
xAxis.title.text = diagramOptions.categoryAxis?.title;
return xAxis;
}

private getYAxis(yAxis: YAxisOptions, unit?: FhiDiagramUnit): YAxisOptions {
const hasDecimalData = !!this.metadataForSeries.find((serie) => serie.hasDecimalData);
const hasNegativeData = !!this.metadataForSeries.find((serie) => serie.hasNegativeData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ export class HighchartsComponent implements OnInit {
series: undefined,
activeDiagramType: 'column',
title: this.titles.title_3a,
categoryAxis: {
title: 'Uke',
},
controls: {
downloadButton: {
show: true,
Expand Down

0 comments on commit 490368b

Please sign in to comment.