@railzai/railz-visualizations
Version:
Railz.ai Visualizations
624 lines (587 loc) • 30.5 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 { proxyCustomElement, HTMLElement, h } from '@stencil/core/internal/client';
import { h as highcharts, a as accessibility } from './accessibility.js';
import { c as createCommonjsModule } from './_commonjsHelpers.js';
import { D as isSymbol, r as isNil, t as fromCssObjectToInline, B as roundNumber, j as format, l as parseISO, m as RAILZ_DATE_FORMAT, p as pick, R as RequestServiceInstance, e as errorLog, g as getConfiguration, C as ConfigurationInstance, a as getFilter, b as getOptions, v as validateRequiredParams, E as isIncomeStatements, c as getTitleByReportType } from './chart.utils.js';
import { T as Translations } from './en.js';
import { i as RVParams, g as RVReportTypesUrlMapping, e as RVReportTypes } from './financial-ratios.js';
import { i as RAILZ_PIE_COLORS } from './colors.js';
import { A as ALL_FONTS } from './fonts.js';
import { d as defineCustomElement$3 } from './error-image.js';
import { d as defineCustomElement$2 } from './loading.js';
import { d as defineCustomElement$1 } from './tooltip.js';
import { l as isObject, r as root, i as isEmpty } from './isEmpty.js';
import { i as isEqual } from './isEqual.js';
/** Used to match a single whitespace character. */
var reWhitespace = /\s/;
/**
* Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace
* character of `string`.
*
* @private
* @param {string} string The string to inspect.
* @returns {number} Returns the index of the last non-whitespace character.
*/
function trimmedEndIndex(string) {
var index = string.length;
while (index-- && reWhitespace.test(string.charAt(index))) {}
return index;
}
/** Used to match leading whitespace. */
var reTrimStart = /^\s+/;
/**
* The base implementation of `_.trim`.
*
* @private
* @param {string} string The string to trim.
* @returns {string} Returns the trimmed string.
*/
function baseTrim(string) {
return string
? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, '')
: string;
}
/** Used as references for various `Number` constants. */
var NAN = 0 / 0;
/** Used to detect bad signed hexadecimal string values. */
var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
/** Used to detect binary string values. */
var reIsBinary = /^0b[01]+$/i;
/** Used to detect octal string values. */
var reIsOctal = /^0o[0-7]+$/i;
/** Built-in method references without a dependency on `root`. */
var freeParseInt = parseInt;
/**
* Converts `value` to a number.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to process.
* @returns {number} Returns the number.
* @example
*
* _.toNumber(3.2);
* // => 3.2
*
* _.toNumber(Number.MIN_VALUE);
* // => 5e-324
*
* _.toNumber(Infinity);
* // => Infinity
*
* _.toNumber('3.2');
* // => 3.2
*/
function toNumber(value) {
if (typeof value == 'number') {
return value;
}
if (isSymbol(value)) {
return NAN;
}
if (isObject(value)) {
var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
value = isObject(other) ? (other + '') : other;
}
if (typeof value != 'string') {
return value === 0 ? value : +value;
}
value = baseTrim(value);
var isBinary = reIsBinary.test(value);
return (isBinary || reIsOctal.test(value))
? freeParseInt(value.slice(2), isBinary ? 2 : 8)
: (reIsBadHex.test(value) ? NAN : +value);
}
/**
* Gets the timestamp of the number of milliseconds that have elapsed since
* the Unix epoch (1 January 1970 00:00:00 UTC).
*
* @static
* @memberOf _
* @since 2.4.0
* @category Date
* @returns {number} Returns the timestamp.
* @example
*
* _.defer(function(stamp) {
* console.log(_.now() - stamp);
* }, _.now());
* // => Logs the number of milliseconds it took for the deferred invocation.
*/
var now = function() {
return root.Date.now();
};
/** Error message constants. */
var FUNC_ERROR_TEXT = 'Expected a function';
/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeMax = Math.max,
nativeMin = Math.min;
/**
* Creates a debounced function that delays invoking `func` until after `wait`
* milliseconds have elapsed since the last time the debounced function was
* invoked. The debounced function comes with a `cancel` method to cancel
* delayed `func` invocations and a `flush` method to immediately invoke them.
* Provide `options` to indicate whether `func` should be invoked on the
* leading and/or trailing edge of the `wait` timeout. The `func` is invoked
* with the last arguments provided to the debounced function. Subsequent
* calls to the debounced function return the result of the last `func`
* invocation.
*
* **Note:** If `leading` and `trailing` options are `true`, `func` is
* invoked on the trailing edge of the timeout only if the debounced function
* is invoked more than once during the `wait` timeout.
*
* If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
* until to the next tick, similar to `setTimeout` with a timeout of `0`.
*
* See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
* for details over the differences between `_.debounce` and `_.throttle`.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Function
* @param {Function} func The function to debounce.
* @param {number} [wait=0] The number of milliseconds to delay.
* @param {Object} [options={}] The options object.
* @param {boolean} [options.leading=false]
* Specify invoking on the leading edge of the timeout.
* @param {number} [options.maxWait]
* The maximum time `func` is allowed to be delayed before it's invoked.
* @param {boolean} [options.trailing=true]
* Specify invoking on the trailing edge of the timeout.
* @returns {Function} Returns the new debounced function.
* @example
*
* // Avoid costly calculations while the window size is in flux.
* jQuery(window).on('resize', _.debounce(calculateLayout, 150));
*
* // Invoke `sendMail` when clicked, debouncing subsequent calls.
* jQuery(element).on('click', _.debounce(sendMail, 300, {
* 'leading': true,
* 'trailing': false
* }));
*
* // Ensure `batchLog` is invoked once after 1 second of debounced calls.
* var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
* var source = new EventSource('/stream');
* jQuery(source).on('message', debounced);
*
* // Cancel the trailing debounced invocation.
* jQuery(window).on('popstate', debounced.cancel);
*/
function debounce(func, wait, options) {
var lastArgs,
lastThis,
maxWait,
result,
timerId,
lastCallTime,
lastInvokeTime = 0,
leading = false,
maxing = false,
trailing = true;
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
}
wait = toNumber(wait) || 0;
if (isObject(options)) {
leading = !!options.leading;
maxing = 'maxWait' in options;
maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
trailing = 'trailing' in options ? !!options.trailing : trailing;
}
function invokeFunc(time) {
var args = lastArgs,
thisArg = lastThis;
lastArgs = lastThis = undefined;
lastInvokeTime = time;
result = func.apply(thisArg, args);
return result;
}
function leadingEdge(time) {
// Reset any `maxWait` timer.
lastInvokeTime = time;
// Start the timer for the trailing edge.
timerId = setTimeout(timerExpired, wait);
// Invoke the leading edge.
return leading ? invokeFunc(time) : result;
}
function remainingWait(time) {
var timeSinceLastCall = time - lastCallTime,
timeSinceLastInvoke = time - lastInvokeTime,
timeWaiting = wait - timeSinceLastCall;
return maxing
? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke)
: timeWaiting;
}
function shouldInvoke(time) {
var timeSinceLastCall = time - lastCallTime,
timeSinceLastInvoke = time - lastInvokeTime;
// Either this is the first call, activity has stopped and we're at the
// trailing edge, the system time has gone backwards and we're treating
// it as the trailing edge, or we've hit the `maxWait` limit.
return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
(timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
}
function timerExpired() {
var time = now();
if (shouldInvoke(time)) {
return trailingEdge(time);
}
// Restart the timer.
timerId = setTimeout(timerExpired, remainingWait(time));
}
function trailingEdge(time) {
timerId = undefined;
// Only invoke if we have `lastArgs` which means `func` has been
// debounced at least once.
if (trailing && lastArgs) {
return invokeFunc(time);
}
lastArgs = lastThis = undefined;
return result;
}
function cancel() {
if (timerId !== undefined) {
clearTimeout(timerId);
}
lastInvokeTime = 0;
lastArgs = lastCallTime = lastThis = timerId = undefined;
}
function flush() {
return timerId === undefined ? result : trailingEdge(now());
}
function debounced() {
var time = now(),
isInvoking = shouldInvoke(time);
lastArgs = arguments;
lastThis = this;
lastCallTime = time;
if (isInvoking) {
if (timerId === undefined) {
return leadingEdge(lastCallTime);
}
if (maxing) {
// Handle invocations in a tight loop.
clearTimeout(timerId);
timerId = setTimeout(timerExpired, wait);
return invokeFunc(lastCallTime);
}
}
if (timerId === undefined) {
timerId = setTimeout(timerExpired, wait);
}
return result;
}
debounced.cancel = cancel;
debounced.flush = flush;
return debounced;
}
var variablePie = createCommonjsModule(function (module) {
(function(a){module.exports?(a["default"]=a,module.exports=a):a("undefined"!==typeof Highcharts?Highcharts:void 0);})(function(a){function e(a,b,e,m){a.hasOwnProperty(b)||(a[b]=m.apply(null,e));}a=a?a._modules:{};e(a,"Series/VariablePie/VariablePieSeries.js",[a["Core/Series/SeriesRegistry.js"],a["Core/Utilities.js"]],function(a,
b){var e=this&&this.__extends||function(){var a=function(b,c){a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(c,a){c.__proto__=a;}||function(c,a){for(var h in a)a.hasOwnProperty(h)&&(c[h]=a[h]);};return a(b,c)};return function(b,c){function r(){this.constructor=b;}a(b,c);b.prototype=null===c?Object.create(c):(r.prototype=c.prototype,new r);}}(),m=a.seriesTypes.pie,w=b.arrayMax,x=b.arrayMin,z=b.clamp,A=b.extend,B=b.fireEvent,C=b.merge,n=b.pick;b=function(a){function b(){var c=null!==
a&&a.apply(this,arguments)||this;c.data=void 0;c.options=void 0;c.points=void 0;c.radii=void 0;return c}e(b,a);b.prototype.calculateExtremes=function(){var c=this.chart,a=this.options;var b=this.zData;var e=Math.min(c.plotWidth,c.plotHeight)-2*(a.slicedOffset||0),t={};c=this.center||this.getCenter();["minPointSize","maxPointSize"].forEach(function(c){var b=a[c],h=/%$/.test(b);b=parseInt(b,10);t[c]=h?e*b/100:2*b;});this.minPxSize=c[3]+t.minPointSize;this.maxPxSize=z(c[2],c[3]+t.minPointSize,t.maxPointSize);
b.length&&(c=n(a.zMin,x(b.filter(this.zValEval))),b=n(a.zMax,w(b.filter(this.zValEval))),this.getRadii(c,b,this.minPxSize,this.maxPxSize));};b.prototype.getRadii=function(c,a,b,e){var h=0,l=this.zData,r=l.length,k=[],m="radius"!==this.options.sizeBy,n=a-c;for(h;h<r;h++){var g=this.zValEval(l[h])?l[h]:c;g<=c?g=b/2:g>=a?g=e/2:(g=0<n?(g-c)/n:.5,m&&(g=Math.sqrt(g)),g=Math.ceil(b+g*(e-b))/2);k.push(g);}this.radii=k;};b.prototype.redraw=function(){this.center=null;a.prototype.redraw.apply(this,arguments);};
b.prototype.translate=function(c){this.generatePoints();var b=0,a=this.options,e=a.slicedOffset,m=e+(a.borderWidth||0),l=a.startAngle||0,u=Math.PI/180*(l-90),k=Math.PI/180*(n(a.endAngle,l+360)-90);l=k-u;var y=this.points,w=a.dataLabels.distance;a=a.ignoreHiddenPoint;var g=y.length;this.startAngleRad=u;this.endAngleRad=k;this.calculateExtremes();c||(this.center=c=this.getCenter());for(k=0;k<g;k++){var f=y[k];var p=this.radii[k];f.labelDistance=n(f.options.dataLabels&&f.options.dataLabels.distance,
w);this.maxLabelDistance=Math.max(this.maxLabelDistance||0,f.labelDistance);var d=u+b*l;if(!a||f.visible)b+=f.percentage/100;var q=u+b*l;f.shapeType="arc";f.shapeArgs={x:c[0],y:c[1],r:p,innerR:c[3]/2,start:Math.round(1E3*d)/1E3,end:Math.round(1E3*q)/1E3};d=(q+d)/2;d>1.5*Math.PI?d-=2*Math.PI:d<-Math.PI/2&&(d+=2*Math.PI);f.slicedTranslation={translateX:Math.round(Math.cos(d)*e),translateY:Math.round(Math.sin(d)*e)};var v=Math.cos(d)*c[2]/2;var x=Math.sin(d)*c[2]/2;q=Math.cos(d)*p;p*=Math.sin(d);f.tooltipPos=
[c[0]+.7*v,c[1]+.7*x];f.half=d<-Math.PI/2||d>Math.PI/2?1:0;f.angle=d;v=Math.min(m,f.labelDistance/5);f.labelPosition={natural:{x:c[0]+q+Math.cos(d)*f.labelDistance,y:c[1]+p+Math.sin(d)*f.labelDistance},"final":{},alignment:f.half?"right":"left",connectorPosition:{breakAt:{x:c[0]+q+Math.cos(d)*v,y:c[1]+p+Math.sin(d)*v},touchingSliceAt:{x:c[0]+q,y:c[1]+p}}};}B(this,"afterTranslate");};b.prototype.zValEval=function(a){return "number"!==typeof a||isNaN(a)?null:!0};b.defaultOptions=C(m.defaultOptions,{minPointSize:"10%",
maxPointSize:"100%",zMin:void 0,zMax:void 0,sizeBy:"area",tooltip:{pointFormat:'<span style="color:{point.color}">\u25cf</span> {series.name}<br/>Value: {point.y}<br/>Size: {point.z}<br/>'}});return b}(m);A(b.prototype,{pointArrayMap:["y","z"],parallelArrays:["x","y","z"]});a.registerSeriesType("variablepie",b);return b});e(a,"masters/modules/variable-pie.src.js",[],function(){});});
//# sourceMappingURL=variable-pie.js.map
});
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
*/
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;
};
const incomeStatementsCss = "@font-face{font-family:Inter;src:url(\"../assets/fonts/Inter-italic-var.woff2\");font-family:Inter;src:url(\"../assets/fonts/Inter-upright-var.woff2\")}body,div[class^=railz-],div[class*=\" railz-\"]{font-family:Inter, Roboto, -apple-system, BlinkMacSystemFont, \"Segoe UI\", \"Helvetica Neue\", Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\"}.rv-container{display:flex;padding:16px;position:relative;border:1px solid #eee;border-radius:7px;flex-direction:column;justify-content:space-between;width:auto;height:300px}.rv-container *{font-family:Inter, Roboto, -apple-system, BlinkMacSystemFont, \"Segoe UI\", \"Helvetica Neue\", Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\"}.rv-header-container{display:flex}.rv-title{display:flex;color:#015b7e;font-size:18px;font-weight:600;margin:0;padding:0;text-align:left;flex-grow:1;line-height:1.235}.rv-income-statements-chart-container{visibility:inherit;-webkit-font-smoothing:antialiased;color:rgba(0, 0, 0, 0.87);height:90%;display:flex;margin-left:-10px;flex-direction:row}@media screen and (max-width: 600px){.rv-income-statements-chart-container{flex-direction:column;height:calc(90% + 5px)}}.rv-income-statements-chart-container #rv-income-statements-chart{display:flex;flex-direction:column;flex-grow:1;flex-shrink:1;height:100%}@media screen and (max-width: 600px){.rv-income-statements-chart-container #rv-income-statements-chart{height:90%}}.rv-income-statements-chart-box{visibility:inherit;display:flex;align-items:flex-start;flex-direction:column;justify-content:center}@media screen and (max-width: 600px){.rv-income-statements-chart-box{position:relative;top:-20px;align-items:center}}.rv-income-statements-chart-box-content{-webkit-font-smoothing:antialiased;color:rgba(0, 0, 0, 0.87);display:flex;align-items:flex-start;flex-direction:column;justify-content:left}.rv-income-statements-chart-text{visibility:inherit;-webkit-font-smoothing:antialiased;margin:0;color:#000d;line-height:1.5;font-size:20px;font-weight:700}.rv-income-statements-chart-percentage{visibility:inherit;-webkit-font-smoothing:antialiased;margin:0;line-height:1.5;display:flex;font-size:14px;font-weight:500}.rv-income-statements-chart-percentage .rv-positive{color:#006037}.rv-income-statements-chart-percentage .rv-negative{color:#b30000}.rv-legend{display:flex;flex-direction:column;margin-top:-3px}.rv-legend-value{font-size:14px;color:#070a0e}.rv-legend-name{font-size:12px;font-weight:normal;color:#424242;white-space:normal}";
variablePie(highcharts);
accessibility(highcharts);
const TranslationMapping = {
[RVReportTypes.EXPENSES]: 'EXPENSES',
[RVReportTypes.REVENUE]: 'REVENUES',
};
const IncomeStatements = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
constructor() {
super();
this.__registerHost();
this.__attachShadow();
this.loading = '';
this.debouncedChart = debounce(() => {
highcharts.chart(this.containerRef, this.chartOptions);
}, 50);
/**
* 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 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 (isIncomeStatements(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;
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._summary = reportData === null || reportData === void 0 ? void 0 : reportData.data;
this.updateHighchartsParams(reportData.data);
}
else if (reportData === null || reportData === void 0 ? void 0 : reportData.error) {
this.errorStatusCode = (_a = reportData.error) === null || _a === void 0 ? void 0 : _a.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 = (summary) => {
const chartOptions = getOptionsIncomeStatements(summary, this._options);
if (chartOptions) {
this.loading = '';
this.chartOptions = chartOptions;
}
};
this.renderMain = () => {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
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-income-statements-chart-container" }, h("div", { id: "rv-income-statements-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 } }), h("div", { class: "rv-income-statements-chart-box" }, h("div", { class: "rv-income-statements-chart-box-content" }, !isNil((_g = this._summary) === null || _g === void 0 ? void 0 : _g.percentageChange) && (h("div", { class: "rv-income-statements-chart-percentage" }, ((_h = this._summary) === null || _h === void 0 ? void 0 : _h.percentageChange) >= 0 ? (h("div", { class: "rv-positive", style: (_l = (_k = (_j = this._options) === null || _j === void 0 ? void 0 : _j.chart) === null || _k === void 0 ? void 0 : _k.pie) === null || _l === void 0 ? void 0 : _l.positive }, "\u25B2 ", (_m = this._summary) === null || _m === void 0 ? void 0 :
_m.percentageChange, "%")) : (h("div", { class: "rv-negative", style: (_q = (_p = (_o = this._options) === null || _o === void 0 ? void 0 : _o.chart) === null || _p === void 0 ? void 0 : _p.pie) === null || _q === void 0 ? void 0 : _q.negative }, "\u25BC ", (_r = this._summary) === null || _r === void 0 ? void 0 :
_r.percentageChange, "%")))), h("p", { class: "rv-income-statements-chart-text", style: (_u = (_t = (_s = this._options) === null || _s === void 0 ? void 0 : _s.chart) === null || _t === void 0 ? void 0 : _t.pie) === null || _u === void 0 ? void 0 : _u.total }, ((_v = this._summary) === null || _v === void 0 ? void 0 : _v.totalAmount) < 0 ? '-' : '', "$", roundNumber(((_w = this._summary) === null || _w === void 0 ? void 0 : _w.totalAmount) < 0
? Math.abs((_x = this._summary) === null || _x === void 0 ? void 0 : _x.totalAmount)
: (_y = this._summary) === null || _y === void 0 ? void 0 : _y.totalAmount))))));
};
}
watchContainerRef(newValue, _) {
if (newValue && this.chartOptions) {
highcharts.chart(this.containerRef, this.chartOptions);
}
}
async repaintChartOnResize() {
if (this.containerRef) {
this.debouncedChart();
}
}
async watchConfiguration(newValue, oldValue) {
if (newValue && oldValue && !isEqual(oldValue, newValue)) {
await this.validateParams(newValue, this.filter, this.options);
}
}
async watchFilter(newValue, oldValue) {
if (newValue && oldValue && !isEqual(oldValue, newValue)) {
await this.validateParams(this.configuration, newValue, 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;
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) === false ? ('') : (h("railz-tooltip", { tooltipStyle: Object.assign(Object.assign({ position: 'bottom-center' }, (_h = this._options) === null || _h === void 0 ? void 0 : _h.tooltipIndicator), { style: Object.assign({ marginLeft: '5px' }, (_k = (_j = this._options) === null || _j === void 0 ? void 0 : _j.tooltipIndicator) === null || _k === void 0 ? void 0 : _k.style) }), tooltipText: ((_o = (_m = (_l = this._options) === null || _l === void 0 ? void 0 : _l.content) === null || _m === void 0 ? void 0 : _m.tooltip) === null || _o === void 0 ? void 0 : _o.description) ||
Translations[`RV_TOOLTIP_${TranslationMapping[(_p = this._filter) === null || _p === void 0 ? void 0 : _p.reportType]}`] }))));
};
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 watchers() { return {
"containerRef": ["watchContainerRef"],
"configuration": ["watchConfiguration"],
"filter": ["watchFilter"],
"options": ["watchOptions"]
}; }
static get style() { return incomeStatementsCss; }
}, [1, "railz-income-statements", {
"configuration": [16],
"filter": [16],
"options": [16],
"loading": [32],
"_configuration": [32],
"_filter": [32],
"_options": [32],
"_summary": [32],
"errorStatusCode": [32],
"chartOptions": [32],
"containerRef": [32]
}, [[9, "resize", "repaintChartOnResize"]]]);
function defineCustomElement() {
if (typeof customElements === "undefined") {
return;
}
const components = ["railz-income-statements", "railz-error-image", "railz-loading", "railz-tooltip"];
components.forEach(tagName => { switch (tagName) {
case "railz-income-statements":
if (!customElements.get(tagName)) {
customElements.define(tagName, IncomeStatements);
}
break;
case "railz-error-image":
if (!customElements.get(tagName)) {
defineCustomElement$3();
}
break;
case "railz-loading":
if (!customElements.get(tagName)) {
defineCustomElement$2();
}
break;
case "railz-tooltip":
if (!customElements.get(tagName)) {
defineCustomElement$1();
}
break;
} });
}
export { IncomeStatements as I, defineCustomElement as d };
//# sourceMappingURL=income-statements.js.map