UNPKG

@railzai/railz-visualizations

Version:
265 lines 10.9 kB
/*! * Accounting Data as a Service™ is the solution that makes sense of your business customers' financial data. * Built with Stencil * Copyright (c) FIS. */ /* eslint-disable @typescript-eslint/no-unused-vars */ import { Component, h, Prop, State, Watch } from '@stencil/core'; import Highcharts from 'highcharts'; import indicators from 'highcharts/indicators/indicators'; import trendline from 'highcharts/indicators/trendline'; import highchartsAccessibility from 'highcharts/modules/accessibility'; import { isEmpty, isEqual } from 'lodash-es'; import Translations from '../../config/translations/en.json'; import { errorLog } from '../../services/logger'; import { getConfiguration, getFilter, getHighchartsParams, getOptions, validateRequiredParams, } from '../../helpers/chart.utils'; import { ConfigurationInstance } from '../../services/configuration'; import { getTitleByReportType, isStatements } from '../../helpers/utils'; import { formatData, getReportData } from './statements-chart.utils'; indicators(Highcharts); trendline(Highcharts); highchartsAccessibility(Highcharts); export class StatementsChart { constructor() { this.loading = ''; /** * Validates if configuration was passed correctly before setting filter * @param configuration - Config for authentication * @param filter - filter to decide chart type to show * @param options: Whitelabeling options * @param content - content to text that should display * @param triggerRequest - indicate if api request should be made */ this.validateParams = async (configuration, filter, options, triggerRequest = true) => { this._configuration = getConfiguration(configuration); if (this._configuration) { ConfigurationInstance.configuration = this._configuration; try { this._filter = getFilter(filter); this._options = getOptions(options); if (validateRequiredParams(this._filter)) { if (isStatements(this._filter.reportType)) { if (triggerRequest) { await this.requestReportData(); } } else { this.errorStatusCode = 500; errorLog(Translations.RV_ERROR_INVALID_REPORT_TYPE); } } else { this.errorStatusCode = 204; } } catch (e) { this.errorStatusCode = 500; errorLog(e); } } else { this.errorStatusCode = 0; } }; this.propsUpdated = async (triggerRequest = true) => { await this.validateParams(this.configuration, this.filter, this.options, triggerRequest); }; /** * Request report data based on filter and configuration param * Formats retrieved data into Highcharts format using formatData * Updated Highchart params using updateHighchartsParams */ this.requestReportData = async () => { var _a, _b, _c, _d, _e, _f; this.errorStatusCode = undefined; this.loading = Translations.RV_LOADING_REPORT; try { const reportData = (await getReportData({ filter: this._filter, })); if (reportData === null || reportData === void 0 ? void 0 : reportData.data) { this._dataFormatted = formatData({ summary: reportData.data, reportType: (_a = this._filter) === null || _a === void 0 ? void 0 : _a.reportType, reportFrequency: (_b = this._filter) === null || _b === void 0 ? void 0 : _b.reportFrequency, chart: (_c = this._options) === null || _c === void 0 ? void 0 : _c.chart, date: (_e = (_d = this._options) === null || _d === void 0 ? void 0 : _d.content) === null || _e === void 0 ? void 0 : _e.date, }); this.updateHighchartsParams(); } else if (reportData === null || reportData === void 0 ? void 0 : reportData.error) { this.errorStatusCode = (_f = reportData.error) === null || _f === void 0 ? void 0 : _f.statusCode; } else { this.errorStatusCode = reportData === null || reportData === void 0 ? void 0 : reportData.status; } } catch (error) { errorLog(Translations.RV_NOT_ABLE_TO_PARSE_REPORT_DATA, error); } finally { this.loading = ''; } }; /** * Using getHighchartsParams,Combine generic stacked bar line * chart options and formatted data based on the report type * into one option for highcharts */ this.updateHighchartsParams = () => { const options = getHighchartsParams({ dataFormatted: this._dataFormatted, options: this._options, }); if (options) { this.loading = ''; this.chartOptions = options; } }; this.renderMain = () => { var _a, _b, _c, _d, _e, _f; if (this.errorStatusCode !== undefined) { return (h("railz-error-image", Object.assign({ statusCode: this.errorStatusCode || 500 }, (_a = this._options) === null || _a === void 0 ? void 0 : _a.errorIndicator))); } if (!isEmpty(this.loading)) { return h("railz-loading", Object.assign({ loadingText: this.loading }, (_b = this._options) === null || _b === void 0 ? void 0 : _b.loadingIndicator)); } return (h("div", { class: "rv-statement-chart-container", id: "railz-chart", ref: (el) => (this.containerRef = el), style: { width: (_d = (_c = this._options) === null || _c === void 0 ? void 0 : _c.chart) === null || _d === void 0 ? void 0 : _d.width, height: (_f = (_e = this._options) === null || _e === void 0 ? void 0 : _e.chart) === null || _f === void 0 ? void 0 : _f.height } })); }; } watchContainerRef(newValue, _) { if (newValue && this.chartOptions) { Highcharts.chart(this.containerRef, this.chartOptions); } } async watchFilter(newValue, oldValue) { if (newValue && oldValue && !isEqual(oldValue, newValue)) { await this.validateParams(this.configuration, newValue, this.options); } } async watchConfiguration(newValue, oldValue) { if (newValue && oldValue && !isEqual(oldValue, newValue)) { await this.validateParams(newValue, this.filter, this.options); } } async watchOptions(newValue, oldValue) { if (newValue && oldValue && !isEqual(oldValue, newValue)) { await this.validateParams(this.configuration, this.filter, newValue); } } componentWillLoad() { this.propsUpdated && this.propsUpdated(); } render() { var _a, _b, _c, _d; if (this.errorStatusCode === 0) { return null; } const TitleElement = () => { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r; return (h("p", { class: "rv-title", style: (_b = (_a = this._options) === null || _a === void 0 ? void 0 : _a.title) === null || _b === void 0 ? void 0 : _b.style }, ((_d = (_c = this._options) === null || _c === void 0 ? void 0 : _c.content) === null || _d === void 0 ? void 0 : _d.title) || getTitleByReportType((_e = this._filter) === null || _e === void 0 ? void 0 : _e.reportType) || '', ' ', ((_g = (_f = this._options) === null || _f === void 0 ? void 0 : _f.tooltipIndicator) === null || _g === void 0 ? void 0 : _g.visible) && ((_k = (_j = (_h = this._options) === null || _h === void 0 ? void 0 : _h.content) === null || _j === void 0 ? void 0 : _j.tooltip) === null || _k === void 0 ? void 0 : _k.description) ? (h("railz-tooltip", { tooltipStyle: Object.assign(Object.assign({ position: 'bottom-center' }, (_l = this._options) === null || _l === void 0 ? void 0 : _l.tooltipIndicator), { style: Object.assign({ marginLeft: '5px' }, (_o = (_m = this._options) === null || _m === void 0 ? void 0 : _m.tooltipIndicator) === null || _o === void 0 ? void 0 : _o.style) }), tooltipText: (_r = (_q = (_p = this._options) === null || _p === void 0 ? void 0 : _p.content) === null || _q === void 0 ? void 0 : _q.tooltip) === null || _r === void 0 ? void 0 : _r.description })) : null)); }; return (h("div", { class: "rv-container", style: (_b = (_a = this._options) === null || _a === void 0 ? void 0 : _a.container) === null || _b === void 0 ? void 0 : _b.style }, ((_d = (_c = this._options) === null || _c === void 0 ? void 0 : _c.title) === null || _d === void 0 ? void 0 : _d.visible) === false ? ('') : (h("div", { class: "rv-header-container" }, h(TitleElement, null))), this.renderMain())); } static get is() { return "railz-statements-chart"; } static get encapsulation() { return "shadow"; } static get originalStyleUrls() { return { "$": ["./statements-chart.scss"] }; } static get styleUrls() { return { "$": ["statements-chart.css"] }; } static get properties() { return { "configuration": { "type": "unknown", "mutable": false, "complexType": { "original": "RVConfiguration", "resolved": "RVConfiguration", "references": { "RVConfiguration": { "location": "import", "path": "../../types" } } }, "required": true, "optional": false, "docs": { "tags": [], "text": "Configuration information like authentication configuration" } }, "filter": { "type": "unknown", "mutable": false, "complexType": { "original": "RVFilterStatements", "resolved": "RVFilterBalanceSheet | RVFilterCashflowStatements | RVFilterIncomeStatements", "references": { "RVFilterStatements": { "location": "import", "path": "../../types" } } }, "required": true, "optional": false, "docs": { "tags": [], "text": "Filter information to query the backend APIs" } }, "options": { "type": "unknown", "mutable": false, "complexType": { "original": "RVOptions", "resolved": "RVOptions", "references": { "RVOptions": { "location": "import", "path": "../../types" } } }, "required": false, "optional": true, "docs": { "tags": [], "text": "For whitelabeling styling" } } }; } static get states() { return { "loading": {}, "_configuration": {}, "_filter": {}, "_options": {}, "_dataFormatted": {}, "errorStatusCode": {}, "chartOptions": {}, "containerRef": {} }; } static get watchers() { return [{ "propName": "containerRef", "methodName": "watchContainerRef" }, { "propName": "filter", "methodName": "watchFilter" }, { "propName": "configuration", "methodName": "watchConfiguration" }, { "propName": "options", "methodName": "watchOptions" }]; } } //# sourceMappingURL=statements-chart.js.map