add a new method to set the axis values

pull/8365/head
bsatarnejad 5 years ago
parent dbd6924268
commit 1ba0b951da
  1. 80
      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;
}
}
}
}

Loading…
Cancel
Save