Skip to content

Commit

Permalink
fix(core/reports): xlsreport charts various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
robzan8 committed Jan 22, 2024
1 parent b01a7fe commit a7e564a
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions projects/core/reports/src/xls-report/xls-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,20 @@ function alertAndThrow(err: string) {
throw new Error(err);
}

// converts to boolean an option from an excel cell
function bool(cell: undefined | null | string | boolean): boolean {
if (!cell || cell === 'false') {
return false;
}
return true;
}

function _buildChart(name: string, sheet: {[key: string]: string}[]): AjfWidget {
if (sheet == null || sheet.length === 0) {
alertAndThrow('Empty sheet for chart ' + name);
}
const data = sheet[0];
const optionsNames = ['chartType', 'title', 'stacked', 'beginAtZeroX', 'beginAtZeroY'];
const optionsNames = ['chartType', 'title', 'stacked', 'beginAtZeroX', 'beginAtZeroY', 'maintainAspectRatio'];
const options: {[key: string]: string} = {};
for (const name of optionsNames) {
if (data[name] != null) {
Expand Down Expand Up @@ -225,6 +233,7 @@ function _buildChart(name: string, sheet: {[key: string]: string}[]): AjfWidget
labelsFormula = {formula: labelsJs};
}

const stacked = bool(options['stacked']);
const dataset: AjfChartDataset[] = [];
Object.keys(data).forEach((key, index) => {
let xs = '';
Expand Down Expand Up @@ -260,7 +269,7 @@ function _buildChart(name: string, sheet: {[key: string]: string}[]): AjfWidget
type === AjfChartType.PolarArea || type === AjfChartType.Doughnut;
const color = multipleColors ? backgroundColor : backgroundColor[index];
const datasetOptions: any = {backgroundColor: color, tension: 0};
if (type === AjfChartType.Line && !options['stacked']) {
if (type === AjfChartType.Line && !stacked) {
datasetOptions.backgroundColor = 'transparent';
datasetOptions.borderColor = color;
datasetOptions.pointBackgroundColor = color;
Expand All @@ -275,6 +284,7 @@ function _buildChart(name: string, sheet: {[key: string]: string}[]): AjfWidget
} as AjfChartDataset);
});

const maintainAspectRatio = bool(options['maintainAspectRatio']);
return createWidget({
name,
widgetType: AjfWidgetType.Chart,
Expand All @@ -283,25 +293,20 @@ function _buildChart(name: string, sheet: {[key: string]: string}[]): AjfWidget
dataset,
options: {
responsive: true,
maintainAspectRatio: false,
maintainAspectRatio,
legend: {display: true, position: 'bottom'},
title: {
display: true,
text: options['title'] || '',
},
scales: {
xAxes: [{
ticks: {beginAtZero: options['beginAtZeroX']},
}],
yAxes: [{
stacked: options['stacked'],
ticks: {beginAtZero: options['stacked'] || options['beginAtZeroY']},
}],
xAxes: [{stacked, ticks: {beginAtZero: bool(options['beginAtZeroX'])}}],
yAxes: [{stacked, ticks: {beginAtZero: stacked || bool(options['beginAtZeroY'])}}],
},
},
styles: {
...widgetStyle,
...{width: '100%', height: '400px', padding: '10px'},
...{width: '100%', height: maintainAspectRatio ? undefined : '400px', padding: '10px'},
},
exportable: true,
} as AjfWidgetCreate);
Expand Down

0 comments on commit a7e564a

Please sign in to comment.