@railzai/railz-visualizations
Version:
Railz.ai Visualizations
99 lines • 4.33 kB
JavaScript
/*!
* Accounting Data as a Service™ is the solution that makes sense of your business customers' financial data.
* Built with Stencil
* Copyright (c) FIS.
*/
import { pick, isNil } from 'lodash-es';
import { format, parseISO } from 'date-fns';
import Translations from '../../config/translations/en.json';
import { ALL_FONTS, RAILZ_PIE_COLORS, RVParams, RVReportTypesUrlMapping, } from '../../types';
import { RequestServiceInstance } from '../../services/request';
import { errorLog } from '../../services/logger';
import { RAILZ_DATE_FORMAT } from '../../types/constants/date';
import { fromCssObjectToInline, roundNumber } from '../../helpers/utils';
export const getOptionsIncomeStatements = (summary, options) => {
var _a, _b, _c, _d, _e;
const data = summary === null || summary === void 0 ? void 0 : summary.subSections.filter((item) => item.amount > 0).map((item) => {
return {
name: item.name,
y: item.amount,
};
});
return {
chart: {
style: Object.assign({ fontFamily: ((_a = options === null || options === void 0 ? void 0 : options.chart) === null || _a === void 0 ? void 0 : _a.fontFamily) || ALL_FONTS }, (_b = options === null || options === void 0 ? void 0 : options.chart) === null || _b === void 0 ? void 0 : _b.style),
backgroundColor: ((_c = options === null || options === void 0 ? void 0 : options.chart) === null || _c === void 0 ? void 0 : _c.backgroundColor) || '#ffffff',
events: {
load() {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const chart = this;
setTimeout(() => {
if (!isNil(chart)) {
try {
chart.reflow();
}
catch (e) { }
}
}, 0);
},
},
},
credits: {
enabled: false,
},
colors: ((_d = options === null || options === void 0 ? void 0 : options.chart) === null || _d === void 0 ? void 0 : _d.colors) || RAILZ_PIE_COLORS,
title: null,
series: [
{
dataLabels: {
enabled: false,
connectorWidth: 0,
connectorPadding: -10,
},
minPointSize: 35,
innerSize: '60%',
zMin: 0,
type: 'variablepie',
showInLegend: true,
data,
id: 'id',
enableMouseTracking: false,
},
],
exporting: {
enabled: false,
},
legend: Object.assign({ align: 'left', layout: 'vertical', verticalAlign: 'middle', marginLeft: 0, floating: false, width: 96, y: 15, x: -10, useHTML: true, itemMarginBottom: 48, labelFormatter: function () {
var _a, _b, _c, _d;
const valueStyle = fromCssObjectToInline((_b = (_a = options === null || options === void 0 ? void 0 : options.chart) === null || _a === void 0 ? void 0 : _a.pie) === null || _b === void 0 ? void 0 : _b.legendValue);
const nameStyle = fromCssObjectToInline((_d = (_c = options === null || options === void 0 ? void 0 : options.chart) === null || _c === void 0 ? void 0 : _c.pie) === null || _d === void 0 ? void 0 : _d.legendName);
return `
<div class="rv-legend">
<span class="rv-legend-value" style="${valueStyle}">$${roundNumber(this.y)}</span>
<span class="rv-legend-name" style="${nameStyle}">${this.name}</span>
</div>`;
} }, (_e = options === null || options === void 0 ? void 0 : options.chart) === null || _e === void 0 ? void 0 : _e.legend),
};
};
/**
* Make API call based on expected parameters for pie data type
*/
export const getReportData = async ({ filter, }) => {
let reportData;
try {
const startDate = format(parseISO(filter.startDate), RAILZ_DATE_FORMAT);
const endDate = format(parseISO(filter.endDate), RAILZ_DATE_FORMAT);
const allParameters = pick(Object.assign(Object.assign({}, filter), { startDate,
endDate }), [RVParams.START_DATE, RVParams.END_DATE, RVParams.REPORT_FREQUENCY, RVParams.CONNECTION_UUID]);
reportData = await RequestServiceInstance.getReportData({
path: RVReportTypesUrlMapping[filter.reportType],
filter: allParameters,
});
}
catch (error) {
errorLog(Translations.RV_NOT_ABLE_TO_RETRIEVE_REPORT_DATA, error);
reportData = { error };
}
return reportData;
};
//# sourceMappingURL=income-statements.utils.js.map