import TimeSeriesChartController from "controllers/time_series_chart_controller"; // Net worth chart for the Reports page. Inherits all drawing behavior from // the time series chart and extends the tooltip with a per-account-group // breakdown of assets and liabilities at the hovered point. export default class extends TimeSeriesChartController { static values = { assetsLabel: { type: String, default: "Assets" }, liabilitiesLabel: { type: String, default: "Liabilities" }, }; _normalizeDataPoints() { super._normalizeDataPoints(); const rawValues = this.dataValue.values || []; this._normalDataPoints = this._normalDataPoints.map((point, i) => ({ ...point, assets: rawValues[i]?.assets, liabilities: rawValues[i]?.liabilities, groups: rawValues[i]?.groups || [], })); } _tooltipTemplate(datum) { return `${super._tooltipTemplate(datum)}${this._breakdownTemplate(datum)}`; } _breakdownTemplate(datum) { const assetGroups = datum.groups.filter( (group) => group.classification === "asset", ); const liabilityGroups = datum.groups.filter( (group) => group.classification === "liability", ); const sections = [ this._sectionTemplate(this.assetsLabelValue, datum.assets, assetGroups), this._sectionTemplate( this.liabilitiesLabelValue, datum.liabilities, liabilityGroups, ), ] .filter(Boolean) .join(""); if (!sections) return ""; return `
${sections}
`; } _sectionTemplate(label, total, groups) { if (groups.length === 0) return ""; const rows = groups .map( (group) => `
${group.name}
${this._extractFormattedValue(group.value)}
`, ) .join(""); return `
${label} ${this._extractFormattedValue(total)}
${rows}
`; } }