diff --git a/frontend/src/app/modules/work-package-graphs/embedded/wp-embedded-graph.component.ts b/frontend/src/app/modules/work-package-graphs/embedded/wp-embedded-graph.component.ts index e0baece6f8..f5b94e125e 100644 --- a/frontend/src/app/modules/work-package-graphs/embedded/wp-embedded-graph.component.ts +++ b/frontend/src/app/modules/work-package-graphs/embedded/wp-embedded-graph.component.ts @@ -99,52 +99,9 @@ export class WorkPackageEmbeddedGraphComponent { } }; - let chartTypeDefaults:ChartOptions = {}; - - if (this.chartType === 'horizontalBar') { - chartTypeDefaults = { - scales: { - xAxes: [{ - stacked: true, - ticks: { - callback: (value:number) => { - if (Math.floor(value) === value) { - return value; - } else { - return 0; - } - } - } - }], - yAxes: - [{ - stacked: true - }] - } - }; - } - - if (this.chartType === 'bar') { - chartTypeDefaults = { - scales: { - yAxes: [{ - stacked: true, - ticks: { - callback: (value:number) => { - if (Math.floor(value) === value) { - return value; - } else { - return 0; - } - } - } - }], - xAxes: - [{ - stacked: true - }] - } - }; + let chartTypeDefaults:ChartOptions = {scales:{}}; + if (this.chartType === 'horizontalBar' || this.chartType === 'bar' ) { + this.setChartAxesValues(chartTypeDefaults); } this.chartOptions = Object.assign({}, defaults, chartTypeDefaults, this.inputChartOptions); @@ -177,4 +134,35 @@ export class WorkPackageEmbeddedGraphComponent { this.chartHeight = '100%'; } } + + // function to set ticks of axis + private setChartAxesValues(chartOptions:ChartOptions) { + + let changeableValuesAxis = [{ + stacked: true, + ticks: { + callback: (value:number) => { + if (Math.floor(value) === value) { + return value; + } else { + return null; + } + } + } + }]; + + let constantValuesAxis = [{ + stacked: true + }]; + + if (chartOptions.scales) { + if (this.chartType === 'bar') { + chartOptions.scales.yAxes = changeableValuesAxis; + chartOptions.scales.xAxes = constantValuesAxis; + } else if (this.chartType === 'horizontalBar') { + chartOptions.scales.xAxes = changeableValuesAxis; + chartOptions.scales.yAxes = constantValuesAxis; + } + } + } }