UNPKG

@carbon/charts

Version:
1,331 lines (1,330 loc) 46 kB
import { ah as et, ai as st, aD as H, aE as w, aF as R, as as N, aG as at, aH as nt, aI as ot, ay as P, aA as k, g as p, w as E, c as F, v as rt, ax as $, J as z, Y as Z, a as L, r as Q, a9 as W, ar as C, L as X, au as it, aJ as lt, aq as O } from "../color-scale-utils-C1aV7-HR.mjs"; import { S as b, a0 as U, d as Y, e as q, t as ct } from "../axis-scales-CFRGPXH8.mjs"; import { b as ut, c as I, a as pt } from "../array-CtuAxDOt.mjs"; function ht(c, t, e, s) { for (var a = -1, n = c == null ? 0 : c.length; ++a < n; ) { var o = c[a]; t(s, o, e(o), c); } return s; } function gt(c, t, e, s) { return ut(c, function(a, n, o) { t(s, a, e(a), o); }), s; } function ft(c, t) { return function(e, s) { var a = st(e) ? ht : gt, n = {}; return a(e, c, et(s), n); }; } function mt(c) { for (var t = -1, e = c == null ? 0 : c.length, s = {}; ++t < e; ) { var a = c[t]; H(s, a[0], a[1]); } return s; } var dt = Object.prototype, Dt = dt.hasOwnProperty, yt = ft(function(c, t, e) { Dt.call(c, e) ? c[e].push(t) : H(c, e, [t]); }); function bt(c, t) { let e = 0; for (let s of c) s != null && (s = +s) >= s && ++e; return e; } function vt(c) { return c; } function xt(c = w) { if (c === w) return J; if (typeof c != "function") throw new TypeError("compare is not a function"); return (t, e) => { const s = c(t, e); return s || s === 0 ? s : (c(e, e) === 0) - (c(t, t) === 0); }; } function J(c, t) { return (c == null || !(c >= c)) - (t == null || !(t >= t)) || (c < t ? -1 : c > t ? 1 : 0); } var Ct = Array.prototype, Tt = Ct.slice; function V(c) { return () => c; } function Ot(c, t, e) { let s; for (; ; ) { const a = R(c, t, e); if (a === s || a === 0 || !isFinite(a)) return [c, t]; a > 0 ? (c = Math.floor(c / a) * a, t = Math.ceil(t / a) * a) : a < 0 && (c = Math.ceil(c * a) / a, t = Math.floor(t * a) / a), s = a; } } function At(c) { return Math.max(1, Math.ceil(Math.log(bt(c)) / Math.LN2) + 1); } function Gt() { var c = vt, t = N, e = At; function s(a) { Array.isArray(a) || (a = Array.from(a)); var n, o = a.length, r, i, l = new Array(o); for (n = 0; n < o; ++n) l[n] = c(a[n], n, a); var u = t(l), g = u[0], h = u[1], f = e(l, g, h); if (!Array.isArray(f)) { const y = h, S = +f; if (t === N && ([g, h] = Ot(g, h, S)), f = at(g, h, S), f[0] <= g && (i = R(g, h, S)), f[f.length - 1] >= h) if (y >= h && t === N) { const T = R(g, h, S); isFinite(T) && (T > 0 ? h = (Math.floor(h / T) + 1) * T : T < 0 && (h = (Math.ceil(h * -T) + 1) / -T)); } else f.pop(); } for (var m = f.length, d = 0, D = m; f[d] <= g; ) ++d; for (; f[D - 1] > h; ) --D; (d || D < m) && (f = f.slice(d, D), m = D - d); var x = new Array(m + 1), A; for (n = 0; n <= m; ++n) A = x[n] = [], A.x0 = n > 0 ? f[n - 1] : g, A.x1 = n < m ? f[n] : h; if (isFinite(i)) { if (i > 0) for (n = 0; n < o; ++n) (r = l[n]) != null && g <= r && r <= h && x[Math.min(m, Math.floor((r - g) / i))].push(a[n]); else if (i < 0) { for (n = 0; n < o; ++n) if ((r = l[n]) != null && g <= r && r <= h) { const y = Math.floor((g - r) * i); x[Math.min(m, y + (f[y] <= r))].push(a[n]); } } } else for (n = 0; n < o; ++n) (r = l[n]) != null && g <= r && r <= h && x[nt(f, r, 0, m)].push(a[n]); return x; } return s.value = function(a) { return arguments.length ? (c = typeof a == "function" ? a : V(a), s) : c; }, s.domain = function(a) { return arguments.length ? (t = typeof a == "function" ? a : V([a[0], a[1]]), s) : t; }, s.thresholds = function(a) { return arguments.length ? (e = typeof a == "function" ? a : V(Array.isArray(a) ? Tt.call(a) : a), s) : e; }, s; } function tt(c, t, e = 0, s = 1 / 0, a) { if (t = Math.floor(t), e = Math.floor(Math.max(0, e)), s = Math.floor(Math.min(c.length - 1, s)), !(e <= t && t <= s)) return c; for (a = a === void 0 ? J : xt(a); s > e; ) { if (s - e > 600) { const i = s - e + 1, l = t - e + 1, u = Math.log(i), g = 0.5 * Math.exp(2 * u / 3), h = 0.5 * Math.sqrt(u * g * (i - g) / i) * (l - i / 2 < 0 ? -1 : 1), f = Math.max(e, Math.floor(t - l * g / i + h)), m = Math.min(s, Math.floor(t + (i - l) * g / i + h)); tt(c, t, f, m, a); } const n = c[t]; let o = e, r = s; for (M(c, e, t), a(c[s], n) > 0 && M(c, e, s); o < r; ) { for (M(c, o, r), ++o, --r; a(c[o], n) < 0; ) ++o; for (; a(c[r], n) > 0; ) --r; } a(c[e], n) === 0 ? M(c, e, r) : (++r, M(c, r, s)), r <= t && (e = r + 1), t <= r && (s = r - 1); } return c; } function M(c, t, e) { const s = c[t]; c[t] = c[e], c[e] = s; } function B(c, t, e) { if (c = Float64Array.from(ot(c)), !(!(s = c.length) || isNaN(t = +t))) { if (t <= 0 || s < 2) return P(c); if (t >= 1) return k(c); var s, a = (s - 1) * t, n = Math.floor(a), o = k(tt(c, n).subarray(0, n + 1)), r = P(c.subarray(n + 1)); return o + (r - o) * (a - n); } } function K(c, t) { if ((o = c.length) > 1) for (var e = 1, s, a, n = c[t[0]], o, r = n.length; e < o; ++e) for (a = n, n = c[t[e]], s = 0; s < r; ++s) n[s][1] += n[s][0] = isNaN(a[s][1]) ? a[s][0] : a[s][1]; } function j(c) { for (var t = c.length, e = new Array(t); --t >= 0; ) e[t] = t; return e; } function Mt(c, t) { return c[t]; } function St(c) { const t = []; return t.key = c, t; } function _() { var c = I([]), t = j, e = K, s = Mt; function a(n) { var o = Array.from(c.apply(this, arguments), St), r, i = o.length, l = -1, u; for (const g of n) for (r = 0, ++l; r < i; ++r) (o[r][l] = [0, +s(g, o[r].key, l, n)]).data = g; for (r = 0, u = pt(t(o)); r < i; ++r) o[u[r]].index = r; return e(o, u), o; } return a.keys = function(n) { return arguments.length ? (c = typeof n == "function" ? n : I(Array.from(n)), a) : c; }, a.value = function(n) { return arguments.length ? (s = typeof n == "function" ? n : I(+n), a) : s; }, a.order = function(n) { return arguments.length ? (t = n == null ? j : typeof n == "function" ? n : I(Array.from(n)), a) : t; }, a.offset = function(n) { return arguments.length ? (e = n ?? K, a) : e; }, a; } function Et(c, t) { if ((i = c.length) > 0) for (var e, s = 0, a, n, o, r, i, l = c[t[0]].length; s < l; ++s) for (o = r = 0, e = 0; e < i; ++e) (n = (a = c[t[e]][s])[1] - a[0]) > 0 ? (a[0] = o, a[1] = o += n) : n < 0 ? (a[1] = r, a[0] = r += n) : (a[0] = 0, a[1] = n); } function qt(c) { const t = c.trim(); return ["=", "+", "-", "@", " ", "\r"].includes(t.charAt(0)) ? ` ${t}` : /[,\"\n]/.test(t) ? `"${t}"` : t; } class v { constructor(t) { this.state = { options: {} }, this.colorScale = {}, this.colorClassNames = {}, this.services = t; } formatTable({ headers: t, cells: e }) { const s = this.getOptions(), { code: a, date: n, number: o } = p(s, "locale"), r = p(s, "tabularRepModal", "tableHeadingFormatter"), i = p(s, "tabularRepModal", "tableCellFormatter"), { cartesianScales: l } = this.services, u = l?.getDomainAxisScaleType(); let g; return u === b.TIME && (g = (f) => n(f, a, { month: "short", day: "numeric", year: "numeric" })), [ typeof r == "function" ? r(t) : t, ...typeof i == "function" ? i(e) : e.map((f) => { g && (f[1] = g(f[1])); for (const m in f) { const d = f[m]; typeof d == "number" && (f[m] = o(d, a)); } return f; }) ]; } getAllDataFromDomain(t) { if (!this.getData()) return null; const e = this.getOptions(); let s = this.getData(); const a = this.getDataGroups(), { groupMapsTo: n } = p(e, "data"), o = p(e, "axes"); return t && (s = s.filter((r) => t.includes(r[n]))), o && Object.keys(o).forEach((r) => { const i = o[r].mapsTo, l = o[r].scaleType; if ((l === b.LINEAR || l === b.LOG) && (s = s.map((u) => ({ ...u, [i]: u[i] === null ? u[i] : Number(u[i]) }))), i && o[r].domain) if (l === b.LABELS) s = s.filter( (u) => o[r].domain.includes(u[i]) ); else { const [u, g] = o[r].domain; s = s.filter( (h) => !(i in h) || h[i] >= u && h[i] <= g ); } }), s.filter((r) => a.find((i) => i.name === r[n])); } /** * Charts that have group configs passed into them, only want to retrieve the display data relevant to that chart * @param groups the included datasets for the particular chart */ getDisplayData(t) { if (!this.get("data")) return null; const { ACTIVE: e } = E.items.status, s = this.getDataGroups(t), { groupMapsTo: a } = this.getOptions().data; return this.getAllDataFromDomain(t).filter((o) => s.find( (r) => r.name === o[a] && r.status === e )); } getData() { return this.get("data"); } isDataEmpty() { return !this.getData().length; } /** * Sets the data for the current instance. * * This method sanitizes the provided data, generates data groups, * and updates the instance's state with the sanitized data and data groups. * * @param {any} newData - The new data to be set. This data will be cloned and sanitized. * @returns {any} - The sanitized version of the provided data. */ setData(t) { const e = this.sanitize(F(t)), s = this.generateDataGroups(e); return this.set({ data: e, dataGroups: s }), e; } getDataGroups(t) { return p(this.getOptions(), "data", "loading") ? [] : t ? this.get("dataGroups").filter((s) => t.includes(s.name)) : this.get("dataGroups"); } getActiveDataGroups(t) { const { ACTIVE: e } = E.items.status; return this.getDataGroups(t).filter((s) => s.status === e); } getDataGroupNames(t) { return this.getDataGroups(t).map((s) => s.name); } getActiveDataGroupNames(t) { return this.getActiveDataGroups(t).map((s) => s.name); } aggregateBinDataByGroup(t) { return yt(t, "group"); } getBinConfigurations() { const t = this.getDisplayData(), e = this.getOptions(), s = this.services.cartesianScales.getMainXAxisPosition(), a = this.services.cartesianScales.getDomainIdentifier(), n = e.axes[s], { groupMapsTo: o } = e.data, { bins: r = rt.defaultBins } = n, i = Array.isArray(r), l = Gt().value((f) => f[a]).thresholds(r)(t); if (i) l[l.length - 1].x1 = r[r.length - 1]; else { const f = l[0].x1 - l[0].x0; l[l.length - 1].x1 = +l[l.length - 1].x0 + f; } const u = i ? [r[0], r[r.length - 1]] : [l[0].x0, l[l.length - 1].x1], g = Array.from(new Set(t.map((f) => f[o]))), h = []; return l.forEach((f) => { const m = `${f.x0}-${f.x1}`, d = this.aggregateBinDataByGroup(f); g.forEach((D) => { h.push({ group: D, key: m, value: d[D] || 0, bin: f.x0 }); }); }), { bins: l, binsDomain: u }; } getBinnedStackedData() { const t = this.getOptions(), { groupMapsTo: e } = t.data, s = this.getActiveDataGroupNames(), { bins: a } = this.getBinConfigurations(), n = this.getDataValuesGroupedByKeys({ bins: a }); return _().keys(s)(n).map((o, r) => Object.keys(o).filter((i) => !isNaN(i)).map((i) => { const l = o[i]; return l[e] = s[r], l; })); } getGroupedData(t) { const e = this.getDisplayData(t), s = {}, { groupMapsTo: a } = this.getOptions().data; return e.map((n) => { const o = n[a]; s[o] !== null && s[o] !== void 0 ? s[o].push(n) : s[o] = [n]; }), Object.keys(s).map((n) => ({ name: n, data: s[n] })); } getStackKeys({ bins: t = null, groups: e = null } = { bins: null, groups: null }) { const s = this.getOptions(), a = this.getDisplayData(e); let n; t ? n = t.map((i) => `${i.x0}:${i.x1}`) : n = $( a.map((i) => { const l = this.services.cartesianScales.getDomainIdentifier(i); return i[l] instanceof Date ? z(i[l]) : i[l] && typeof i[l].toString == "function" ? i[l].toString() : i[l]; }) ); const o = this.services.cartesianScales.domainAxisPosition, r = s.axes[o].scaleType; return r === b.TIME ? n.sort((i, l) => { const u = new Date(i), g = new Date(l); return u - g; }) : (r === b.LOG || r === b.LINEAR) && n.sort((i, l) => i - l), n; } getDataValuesGroupedByKeys({ bins: t = null, groups: e = null }) { const s = this.getOptions(), { groupMapsTo: a } = s.data, n = this.getDisplayData(e), o = this.getDataGroupNames(), r = this.getStackKeys({ bins: t, groups: e }); return t ? r.map((i) => { const [l, u] = i.split(":"), g = { x0: l, x1: u }, h = t.find((f) => f.x0.toString() === l.toString()); return o.forEach((f) => { g[f] = h.filter( (m) => m[a] === f ).length; }), g; }) : r.map((i) => { const l = { sharedStackKey: i }; return o.forEach((u) => { const g = n.find((f) => { const m = this.services.cartesianScales.getDomainIdentifier(f); return f[a] === u && Object.prototype.hasOwnProperty.call(f, m) && (f[m] instanceof Date ? z(f[m]) === i : f[m].toString() === i); }), h = this.services.cartesianScales.getRangeIdentifier(l); l[u] = g ? g[h] : null; }), l; }); } getStackedData({ percentage: t = !1, groups: e = null, divergent: s = !1 }) { const a = this.getOptions(), { groupMapsTo: n } = a.data, o = this.getActiveDataGroupNames(e), r = this.getDataValuesGroupedByKeys({ groups: e }); if (t) { const l = mt(r.map((u) => [u.sharedStackKey, 0])); r.forEach((u) => { o.forEach((g) => { l[u.sharedStackKey] += u[g]; }); }), r.forEach((u) => { o.forEach((g) => { const h = l[u.sharedStackKey]; l[u.sharedStackKey] ? u[g] = u[g] / h * 100 : u[g] = 0; }); }); } return (s ? _().offset(Et) : _()).keys(o)(r).map((l, u) => Object.keys(l).filter((g) => !isNaN(g)).map((g) => { const h = l[g]; return h[n] = o[u], h; })); } /** * Retrieves the current options from the instance's state. * * @returns {any} - The current options stored in the instance's state. */ getOptions() { return this.state.options; } set(t, e) { this.state = Object.assign({}, this.state, t); const s = Object.assign( { skipUpdate: !1, animate: !0 }, // default configs e ); s.skipUpdate || this.update(s.animate); } get(t) { return t ? this.state[t] : this.state; } /** * Updates the current options for the instance. * * This method retrieves the existing options, updates the legend additional items, * and merges the new options with the existing ones. The instance's state is then updated * with the merged options. * * @param {any} newOptions - The new options to be set. These options will be merged with the existing options. */ setOptions(t) { const e = this.getOptions(); Z(e, t), this.set({ options: L(e, t) }); } /** * * Updates miscellanous information within the model * such as the color scales, or the legend data labels */ update(t = !0) { this.getDisplayData() && (this.updateAllDataGroups(), this.setCustomColorScale(), this.setColorClassNames(), this.services.events.dispatchEvent(U.Model.UPDATE, { animate: t })); } /* * Data labels */ toggleDataLabel(t) { const { ACTIVE: e, DISABLED: s } = E.items.status, a = this.getDataGroups(), n = a.some((h) => h.status === s), o = a.filter((h) => h.status === e), r = this.getOptions(), i = n || r.data.selectedGroups.length > 0; if (i) if (o.length === 1 && o[0].name === t) a.forEach((h, f) => { a[f].status = e; }); else { const h = a.findIndex((f) => f.name === t); a[h].status = a[h].status === s ? e : s; } else a.forEach((h, f) => { a[f].status = h.name === t ? e : s; }); const l = a.filter((h) => h.status === e), u = a.some((h) => h.status === s), g = i && o.length === 1 && o[0].name === t; u || i && !g ? r.data.selectedGroups = l.map((h) => h.name) : r.data.selectedGroups = [], this.services.events.dispatchEvent(U.Legend.ITEMS_UPDATE, { dataGroups: a }), this.set({ dataGroups: a }); } /** * Should the data point be filled? * @param group * @param key * @param data * @param defaultFilled the default for this chart */ getIsFilled(t, e, s, a) { const n = this.getOptions(); return n.getIsFilled ? n.getIsFilled(t, e, s, a) : a; } getFillColor(t, e, s) { const a = this.getOptions(), n = p(this.colorScale, t); return a.getFillColor ? a.getFillColor(t, e, s, n) : n; } getStrokeColor(t, e, s) { const a = this.getOptions(), n = p(this.colorScale, t); return a.getStrokeColor ? a.getStrokeColor(t, e, s, n) : n; } isUserProvidedColorScaleValid() { const t = p(this.getOptions(), "color", "scale"), e = this.getDataGroups(); return t == null || Object.keys(t).length == 0 ? !1 : e.some( (s) => Object.keys(t).includes(s.name) ); } getColorClassName(t) { const e = this.colorClassNames(t.dataGroupName); let s = t.originalClassName; return t.classNameTypes.forEach( (a) => s = t.originalClassName ? `${s} ${a}-${e}` : `${a}-${e}` ), s || ""; } /** * For charts that might hold an associated status for their dataset */ getStatus() { return null; } getAllDataGroupsNames() { return this.allDataGroups; } /** * Converts data provided in the older format to tabular * */ transformToTabularData(t) { console.warn( "We've updated the charting data format to be tabular by default. The current format you're using is deprecated and will be removed in v1.0, read more here https://charts.carbondesignsystem.com/" ); const e = [], { datasets: s, labels: a } = t; return s.forEach((n) => { n.data.forEach((o, r) => { let i; const l = p(n, "label"); if (l === null) { const g = p(a, r); g ? i = g : i = "Ungrouped"; } else i = l; const u = { group: i, key: a[r] }; isNaN(o) ? (u.value = o.value, u.date = o.date) : u.value = o, e.push(u); }); }), e; } getTabularDataArray() { return []; } exportToCSV() { const e = this.getTabularDataArray().map( (o) => o.map((r) => `"${(r === "&ndash;" ? "–" : r).split(/[,;'"`]/).map((u) => qt(u)).join("")}"`) ).map((o) => o.join(",")).join(` `), s = this.getOptions(); let a = "myChart"; const n = p(s, "fileDownload", "fileName"); typeof n == "function" ? a = n("csv") : typeof n == "string" && (a = n), this.services.files.downloadCSV(e, `${a}.csv`); } getTabularData(t) { return Array.isArray(t) ? t : this.transformToTabularData(t); } sanitize(t) { return t = this.getTabularData(t), t; } /* * Data groups */ updateAllDataGroups() { this.allDataGroups ? this.getDataGroupNames().forEach((t) => { this.allDataGroups.indexOf(t) === -1 && this.allDataGroups.push(t); }) : this.allDataGroups = this.getDataGroupNames(); } generateDataGroups(t) { const { groupMapsTo: e } = this.getOptions().data, { ACTIVE: s, DISABLED: a } = E.items.status, n = this.getOptions(), o = $(t.map((i) => i[e])); n.data.selectedGroups.length && (n.data.selectedGroups.every( (l) => o.includes(l) ) || (n.data.selectedGroups = [])); const r = (i) => !n.data.selectedGroups.length || n.data.selectedGroups.includes(i) ? s : a; return o.map((i) => ({ name: i, status: r(i) })); } /* * Fill scales */ setCustomColorScale() { if (!this.isUserProvidedColorScaleValid()) return; const t = this.getOptions(), e = p(t, "color", "scale"); Object.keys(e).forEach((a) => { this.allDataGroups.includes(a) || console.warn(`"${a}" does not exist in data groups.`); }), this.allDataGroups.filter((a) => e[a]).forEach( (a) => this.colorScale[a] = e[a] ); } /* * Color palette */ setColorClassNames() { const t = p(this.getOptions(), "color", "pairing"); let e = p(t, "numberOfVariants"); (!e || e < this.allDataGroups.length) && (e = this.allDataGroups.length); let s = p(t, "option"); const a = Q.pairingOptions, n = e > 5 ? 14 : e, o = `${n}-color`; s = s <= a[o] ? s : 1; const r = this.allDataGroups.map( (i, l) => `${n}-${s}-${l % 14 + 1}` ); this.colorClassNames = W().range(r).domain(this.allDataGroups); } } class G extends v { // can't be protected as it's used by two-dimensional-axes.ts constructor(t) { super(t), this.axisFlavor = Y.DEFAULT; } // get the scales information // needed for getTabularArray() assignRangeAndDomains() { const { cartesianScales: t } = this.services, e = this.getOptions(), s = t.isDualAxes(), a = { primaryDomain: t.domainAxisPosition, primaryRange: t.rangeAxisPosition, secondaryDomain: null, secondaryRange: null }; return s && (a.secondaryDomain = t.secondaryDomainAxisPosition, a.secondaryRange = t.secondaryRangeAxisPosition), Object.keys(a).forEach( (n) => { const o = a[n]; t.scales[o] ? a[n] = { position: o, label: t.getScaleLabel(o), identifier: p(e, "axes", o, "mapsTo") } : a[n] = null; } ), a; } getTabularDataArray() { const t = this.getDisplayData(), e = this.getOptions(), { groupMapsTo: s } = e.data, { primaryDomain: a, primaryRange: n, secondaryDomain: o, secondaryRange: r } = this.assignRangeAndDomains(), { number: i, code: l } = p(this.getOptions(), "locale"), u = [ "Group", a.label, n.label, ...o ? [o.label] : [], ...r ? [r.label] : [] ], g = t.map((h) => [ h[s], h[a.identifier] === null ? "&ndash;" : h[a.identifier], h[n.identifier] === null || isNaN(h[n.identifier]) ? "&ndash;" : i(h[n.identifier], l), ...o ? [ h[o.identifier] === null ? "&ndash;" : h[o.identifier] ] : [], ...r ? [ h[r.identifier] === null || isNaN(h[r.identifier]) ? "&ndash;" : h[r.identifier] ] : [] ]); return super.formatTable({ headers: u, cells: g }); } setData(t) { let e; if (t && (e = super.setData(t), p(this.getOptions(), "zoomBar", q.TOP, "enabled"))) { const s = p( this.getOptions(), "zoomBar", q.TOP, "data" ); this.setZoomBarData(s); } return e; } /** * Sets the zoom bar data for the current instance. * * This method sanitizes the provided zoom bar data or uses the display data if no explicit * zoom data is provided. It normalizes the zoom bar data by aggregating values based on unique * dates and updates the instance's state with the normalized data. * * @param {any} [newZoomBarData] - The new zoom bar data to be set. If not provided, the display data will be used. */ setZoomBarData(t) { const e = t ? this.sanitize(F(t)) : this.getDisplayData(); let s = e; const { cartesianScales: a } = this.services; if (e && a.domainAxisPosition && a.rangeAxisPosition) { const n = a.getDomainIdentifier(), o = a.getRangeIdentifier(); let r = e.map((i) => i[n].getTime()); r = $(r).sort(), s = r.map((i) => { let l = 0; const u = {}; return e.forEach((g) => { g[n].getTime() === i && (l += g[o]); }), u[n] = new Date(i), u[o] = l, u; }); } this.set({ zoomBarData: s }); } getZoomBarData() { return this.get("zoomBarData"); } sanitizeDateValues(t) { const e = this.getOptions(); if (!e.axes) return t; const s = []; return Object.keys(q).forEach((a) => { const n = q[a], o = e.axes[n]; if (o && o.scaleType === b.TIME) { const r = o.mapsTo; (r !== null || r !== void 0) && s.push(r); } }), s.length > 0 && t.forEach((a) => { s.forEach((n) => { p(a, n, "getTime") === null && (a[n] = new Date(a[n])); }); }), t; } sanitize(t) { return t = super.sanitize(t), t = this.sanitizeDateValues(t), t; } } class kt extends G { constructor(t) { super(t); } getTabularDataArray() { const t = this.getDisplayData(), { number: e, code: s } = p(this.getOptions(), "locale"); t.sort((o, r) => o.source.localeCompare(r.source)); const a = ["Source", "Target", "Value"], n = [ ...t.map((o) => [ o.source, o.target, o.value === null ? "&ndash;" : e(o.value, s) ]) ]; return super.formatTable({ headers: a, cells: n }); } } class Ft extends G { constructor(t) { super(t); } getBoxQuartiles(t) { return { q_25: B(t, 0.25), q_50: B(t, 0.5), q_75: B(t, 0.75) }; } getBoxplotData() { const t = this.getOptions(), { groupMapsTo: e } = t.data, s = this.getGroupedData(), a = []; for (const { name: n, data: o } of s) { const r = this.services.cartesianScales.getRangeIdentifier(), i = o.map((y) => y[r]).sort(w), l = { [e]: n, counts: i, quartiles: this.getBoxQuartiles(i), outliers: null, whiskers: null }, u = l.quartiles.q_25, g = l.quartiles.q_75, h = (g - u) * 1.5, f = u - h, m = g + h, d = [], D = []; for (const y of i) y < f || y > m ? d.push(y) : D.push(y); l.outliers = d; const x = P(D), A = k(D); l.whiskers = { min: x || P([l.quartiles.q_25, l.quartiles.q_50, l.quartiles.q_75]), max: A || k([l.quartiles.q_25, l.quartiles.q_50, l.quartiles.q_75]) }, a.push(l); } return a; } getTabularDataArray() { const t = this.getOptions(), { groupMapsTo: e } = t.data, s = this.getBoxplotData(), { number: a, code: n } = p(t, "locale"), o = ["Group", "Minimum", "Q1", "Median", "Q3", "Maximum", "IQR", "Outlier(s)"], r = [ ...s.map((i) => { let l = p(i, "outliers"); return (l === null || l.length === 0) && (l = ["&ndash;"]), [ i[e], p(i, "whiskers", "min") !== null ? a(p(i, "whiskers", "min"), n) : "&ndash;", p(i, "quartiles", "q_25") !== null ? a(p(i, "quartiles", "q_25"), n) : "&ndash;", p(i, "quartiles", "q_50") !== null ? a(p(i, "quartiles", "q_50"), n) : "&ndash;", p(i, "quartiles", "q_75") !== null ? a(p(i, "quartiles", "q_75"), n) : "&ndash;", p(i, "whiskers", "max") !== null ? a(p(i, "whiskers", "max"), n) : "&ndash;", p(i, "quartiles", "q_75") !== null && p(i, "quartiles", "q_25") !== null ? (a( p(i, "quartiles", "q_75") - p(i, "quartiles", "q_25") ), n) : "&ndash;", l.map((u) => a(u, n)).join(",") ]; }) ]; return super.formatTable({ headers: o, cells: r }); } setColorClassNames() { const e = p(this.getOptions(), "color", "pairing"); let s = p(e, "option"); const a = Q.pairingOptions; s = s <= a["1-color"] ? s : 1; const n = this.allDataGroups.map(() => `1-${s}-1`); this.colorClassNames = W().range(n).domain(this.allDataGroups); } } class Vt extends G { constructor(t) { super(t); } /** * Determines the index of the performance area titles to use * @param datum * @returns number */ getMatchingRangeIndexForDatapoint(t) { let e; for (let s = t.ranges.length - 1; s > 0; s--) { const a = t.ranges[s]; if (t.value >= a) return e = s, e; } return 0; } getTabularDataArray() { const t = this.getDisplayData(), e = this.getOptions(), { groupMapsTo: s } = e.data, a = this.services.cartesianScales.getRangeIdentifier(), { number: n, code: o } = p(e, "locale"), r = p(e, "bullet", "performanceAreaTitles"), i = ["Title", "Group", "Value", "Target", "Percentage", "Performance"], l = [ ...t.map((u) => [ u.title, u[s], u.value === null ? "&ndash;" : n(u.value, o), p(u, "marker") === null ? "&ndash;" : n(u.marker, o), p(u, "marker") === null ? "&ndash;" : `${n(Math.floor(u[a] / u.marker * 100), o)}%`, r[this.getMatchingRangeIndexForDatapoint(u)] ]) ]; return super.formatTable({ headers: i, cells: l }); } } class Bt extends v { constructor(t) { super(t), this._colorScale = void 0, this._matrix = {}; } /** * @override * @param value * @returns string */ getFillColor(t) { return this._colorScale(t); } /** * Helper function that will generate a dictionary */ getCombinedData() { if (C(this._matrix)) { const t = this.getOptions(), e = this.getDisplayData(); !C(e) && !C(t.geoData.objects.countries) && (t.geoData.objects.countries.geometries.forEach((s) => { this._matrix[s.properties.NAME] = s; }), e.forEach((s) => { this._matrix[s.name] ? this._matrix[s.name].value = s.value || null : console.warn(`Data point ${s} is missing geographical data.`); })); } return this._matrix; } /** * Generate tabular data from display data * @returns Array<Object> */ getTabularDataArray() { const t = this.getDisplayData(), { number: e, code: s } = p(this.getOptions(), "locale"), a = ["Country ID", "Country Name", "Value"], n = [ ...t.map((o) => [ o.id === null ? "&ndash;" : o.id, o.name, o.value === null ? "&ndash;" : e(o.value, s) ]) ]; return super.formatTable({ headers: a, cells: n }); } // Uses quantize scale to return class names getColorClassName(t) { return `${t.originalClassName || ""} ${this._colorScale(t.value)}`; } setColorClassNames() { const t = p(this.getOptions(), "color"); this._colorScale = X(this.getDisplayData(), t); } } class _t extends v { constructor(t) { super(t), this.parentNode = !1, this.set({ depth: 2 }, { skipUpdate: !0 }); } setData(t) { super.setData(t), this.setDataGroups(), t.length === 1 && (this.parentNode = !0), this.setZoom(); } setOptions(t) { const e = this.getOptions(), s = L({}, t, this.getZoomOptions(t)); Z(e, s); const a = this.getHierarchyLevel(), n = p(e, "circlePack", "depth"); this.set({ options: L(e, s), depth: n && n < 4 ? n : a }); } getZoomOptions(t) { if (!this.getDisplayData()) return {}; const e = this.getDisplayData(), s = t || this.getOptions(), a = e.length === 1 && p(e, 0, "children") ? p(e, 0, "children") : e; let n = this.getHierarchyLevel(); return a.some((o) => { if (o.children && o.children.some((r) => r.children)) return n = 3, !1; }), p(s, "canvasZoom", "enabled") === !0 && n > 2 ? { legend: { additionalItems: [ { type: ct.ZOOM, name: "Click to zoom" } ] } } : null; } setZoom(t) { this.setOptions(this.getZoomOptions(t)); } // update the hierarchy level updateHierarchyLevel(t) { this.set({ depth: t }); } getHierarchyLevel() { return this.get("depth"); } hasParentNode() { return this.parentNode; } // set the datagroup name on the items that are it's children setDataGroups() { const t = this.getData(), e = this.getOptions(), { groupMapsTo: s } = e.data, a = t.map((n) => { const o = n[s]; return this.setChildrenDataGroup(n, o); }); this.set( { data: a }, { skipUpdate: !0 } ); } // sets name recursively down the node tree setChildrenDataGroup(t, e) { return t.children ? { ...t, dataGroupName: e, children: t.children.map((s) => this.setChildrenDataGroup(s, e)) } : { ...t, dataGroupName: e }; } getTabularDataArray() { const t = this.getDisplayData(), { number: e, code: s } = p(this.getOptions(), "locale"), a = ["Child", "Parent", "Value"], n = []; return t.forEach((o) => { let r = o.value ? o.value : 0; o.children && (r += this.getChildrenDatums(o.children, o.name, n, 0)), n.push(["&ndash;", o.name, e(r, s)]); }), super.formatTable({ headers: a, cells: n }); } /** * Recursively determine the relationship between all the nested elements in the child * @private * @param {any} children - The children nodes to process. * @param {any} parent - The parent node associated with the children. * @param {string[][]} [result=[]] - An array to accumulate the resulting data. * @param {number} [totalSum=0] - The running total sum of values processed. * @returns {number} Sum. */ getChildrenDatums(t, e, s = [], a = 0) { const n = e, { number: o, code: r } = p(this.getOptions(), "locale"); return t.forEach((i) => { const l = i.name; let u = 0; if (i.children) i.children.length > 0 && (typeof i.value == "number" && (a += i.value), u += this.getChildrenDatums(i.children, l, s, u), s.push([l, n, o(u, r)]), a += u); else { let g = 0; typeof i.value == "number" && (g = i.value, a += i.value), s.push([i.name, n, o(g, r)]); } }), a; } } class wt extends v { constructor(t) { super(t); } getTabularData(t) { const e = super.getTabularData(t); return t !== e && e.forEach((s) => { s.key && s.key !== s.group && (s.group = s.key); }), e; } getTabularDataArray() { const t = this.getDisplayData(), e = this.getOptions(), { groupMapsTo: s } = e.data, { valueMapsTo: a } = e.pie, { number: n, code: o } = p(e, "locale"), r = ["Group", "Value"], i = [ ...t.map((l) => [ l[s], l[a] === null ? "&ndash;" : n(l[a], o) ]) ]; return super.formatTable({ headers: r, cells: i }); } sanitize(t) { return this.getTabularData(t).sort((s, a) => a.value - s.value); } } class Rt extends v { constructor(t) { super(t); } getDataGroups() { return super.getDataGroups().filter((t) => t.name !== "delta"); } getTabularDataArray() { const t = this.getDisplayData(), e = this.getOptions(), { groupMapsTo: s } = e.data, { number: a, code: n } = p(this.getOptions(), "locale"), o = ["Group", "Value"], r = [ ...t.map((i) => [ i[s], i.value === null ? "&ndash;" : a(i.value, n) ]) ]; return super.formatTable({ headers: o, cells: r }); } } class $t extends G { constructor(t) { super(t), this.axisFlavor = Y.HOVERABLE, this._colorScale = void 0, this._domains = [], this._ranges = [], this._matrix = {}; const e = p(this.getOptions(), "axes"); if (p(e, "left", "scaleType") && p(e, "left", "scaleType") !== b.LABELS || p(e, "right", "scaleType") && p(e, "right", "scaleType") !== b.LABELS || p(e, "top", "scaleType") && p(e, "top", "scaleType") !== b.LABELS || p(e, "bottom", "scaleType") && p(e, "bottom", "scaleType") !== b.LABELS) throw Error("Heatmap only supports label scaletypes."); } /** * Get the custom color domain options from chart configuration * @returns ColorDomainOptions or undefined */ getColorDomainOptions() { const t = this.getOptions(); return p(t, "heatmap", "colorDomain"); } /** * Get min and maximum value of the display data * @returns Array consisting of smallest and largest values in data */ getValueDomain() { const t = N(this.getDisplayData(), (a) => a.value), e = it().domain(t).nice().domain(); e[0] > 0 ? e[0] = 0 : e[0] === 0 && e[1] === 0 && (e[0] = 0, e[1] = 1), e[0] < 0 && e[1] > 0 && (Math.abs(e[0]) > e[1] ? e[1] = Math.abs(e[0]) : e[0] = -e[1]); const s = this.getColorDomainOptions(); return s && (typeof s.min == "number" && (e[0] = s.min), typeof s.max == "number" && (e[1] = s.max)), e; } /** * @override * @param value * @returns string */ getFillColor(t) { return this._colorScale(t); } /** * Generate a list of all unique domains * @returns String[] */ getUniqueDomain() { if (C(this._domains)) { const t = this.getDisplayData(), { cartesianScales: e } = this.services, s = e.getDomainIdentifier(), a = e.getMainXAxisPosition(), n = e.getCustomDomainValuesByposition(a); if (n) return n; this._domains = Array.from( new Set( t.map((o) => o[s]) ) ); } return this._domains; } /** * Generates a list of all unique ranges * @returns String[] */ getUniqueRanges() { if (C(this._ranges)) { const t = this.getDisplayData(), { cartesianScales: e } = this.services, s = e.getRangeIdentifier(), a = e.getMainYAxisPosition(), n = e.getCustomDomainValuesByposition(a); if (n) return n; this._ranges = Array.from( new Set( t.map((o) => o[s]) ) ); } return this._ranges; } /** * Generates a matrix (If doesn't exist) and returns it * @returns Object */ getMatrix() { if (C(this._matrix)) { const t = this.getUniqueDomain(), e = this.getUniqueRanges(), s = this.services.cartesianScales.getDomainIdentifier(), a = this.services.cartesianScales.getRangeIdentifier(), n = {}; e.forEach((o) => { n[o] = { value: null, index: -1 }; }), t.forEach((o) => { this._matrix[o] = F(n); }), this.getDisplayData().forEach((o, r) => { this._matrix[o[s]][o[a]] = { value: o.value, index: r }; }); } return this._matrix; } /** * Sets the data for the current instance. * * This method sanitizes the provided data, generates data groups, * and updates the instance's state with the sanitized data and data groups. * It also resets the `_domains`, `_ranges`, and `_matrix` attributes to their empty states. * * @param {any} newData - The new data to be set. This data will be cloned and sanitized. * @returns {any} - The sanitized version of the provided data. */ setData(t) { const e = this.sanitize(F(t)), s = this.generateDataGroups(e); return this.set({ data: e, dataGroups: s }), this._domains = [], this._ranges = [], this._matrix = {}, e; } /** * Converts Object matrix into a single array * @returns object[] */ getMatrixAsArray() { C(this._matrix) && this.getMatrix(); const t = this.getUniqueDomain(), e = this.getUniqueRanges(), s = this.services.cartesianScales.getDomainIdentifier(), a = this.services.cartesianScales.getRangeIdentifier(), n = []; return t.forEach((o) => { e.forEach((r) => { const i = { value: this._matrix[o][r].value, index: this._matrix[o][r].index }; i[s] = o, i[a] = r, n.push(i); }); }), n; } /** * Generate tabular data from display data * @returns Array<Object> */ getTabularDataArray() { const t = this.getDisplayData(), { primaryDomain: e, primaryRange: s } = this.assignRangeAndDomains(), { number: a, code: n } = p(this.getOptions(), "locale"), o = [e.label, s.label, "Value"], r = [ ...t.map((i) => [ i[e.identifier] === null ? "&ndash;" : i[e.identifier], i[s.identifier] === null ? "&ndash;" : i[s.identifier], i.value === null ? "&ndash;" : a(i.value, n) ]) ]; return super.formatTable({ headers: o, cells: r }); } // Uses quantize scale to return class names getColorClassName(t) { return `${t.originalClassName} ${this._colorScale(t.value)}`; } setColorClassNames() { const t = this.getOptions(), e = p(t, "color", "gradient", "colors"), s = !C(e); let a = p(t, "color", "pairing", "option"); const n = this.getValueDomain(), o = n[0] < 0 && n[1] > 0 ? "diverge" : "mono"; (a < 1 && a > 4 && o === "mono" || a < 1 && a > 2 && o === "diverge") && (a = 1); const r = s ? e : []; if (!s) { const u = o === "diverge" ? 17 : 11; for (let g = 1; g < u + 1; g++) r.push(`fill-${o}-${a}-${g}`); } this._colorScale = lt().domain(n).range(r); const i = p(this.getOptions(), "color"), l = this.getColorDomainOptions(); this._colorScale = X(this.getDisplayData(), i, l); } } class Lt extends G { getTabularDataArray() { const t = this.getOptions(), { groupMapsTo: e } = t.data, { number: s, code: a } = p(this.getOptions(), "locale"), n = this.getBinnedStackedData(), o = [ O(t, "bins.rangeLabel") || "Range", ...n.map((i) => O(i, `0.${e}`)) ], r = [ ...O(n, 0).map((i, l) => [ `${s(Number(O(i, "data.x0")), a)}${s( Number(O(i, "data.x1")), a )}`, ...n.map( (u) => s(O(u[l], `data.${O(u[l], e)}`), a) ) ]) ]; return super.formatTable({ headers: o, cells: r }); } } class zt extends v { constructor(t) { super(t); } getMaximumDomain(t) { return t.reduce((s, a) => s + a.value, 0); } /** * Use a provided color for the bar or default to carbon color if no status provided. * Defaults to carbon color otherwise. * @param group dataset group label */ getFillColor(t) { const e = this.getOptions(), s = p(e, "color", "scale"), a = this.getStatus(); return s || !a ? super.getFillColor(t) : null; } /** * Get the associated status for the data by checking the ranges */ getStatus() { const t = this.getOptions(), s = p(this.getDisplayData())?.reduce((o, r) => o + r.value, 0) ?? 0, a = p(t, "meter", "proportional") ? s : s > 100 ? 100 : s, n = p(t, "meter", "status", "ranges"); if (n) { const o = n.filter( (r) => r.range[0] <= a && a <= r.range[1] ); if (o.length > 0) return o[0].status; } return null; } getTabularDataArray() { const t = this.getDisplayData(), e = this.getOptions(), { groupMapsTo: s } = e.data, a = this.getStatus(), n = p(e, "meter", "proportional"), { number: o, code: r } = p(this.getOptions(), "locale"); let i = [], l = [], u; if (n === null) { u = 100; const g = t[0]; i = ["Group", "Value", ...a ? ["Status"] : []], l = [ [ g[s], g.value === null ? "&ndash;" : o(g.value, r), ...a ? [a] : [] ] ]; } else { const g = p(n, "total"); u = g || this.getMaximumDomain(t), i = ["Group", "Value", "Percentage of total"], l = [ ...t.map((h) => { let f; h.value !== null && h.value !== void 0 ? f = Number(h.value) : f = 0; const m = Number((h.value / u * 100).toFixed(2)); return [ h[s], h.value === null ? "&ndash;" : o(f, r), o(m, r) + " %" ]; }) ]; } return super.formatTable({ headers: i, cells: l }); } } class Ut extends G { constructor(t) { super(t); } getTabularDataArray() { const t = this.getOptions(), e = this.getGroupedData(), { angle: s, value: a } = p(t, "radar", "axes"), { number: n, code: o } = p(t, "locale"), r = p(e, "0", "data").map((u) => u[s]), i = ["Group", ...r], l = [ ...e.map((u) => [ u.name, ...r.map( (g, h) => p(u, "data", h, a) !== null ? n(p(u, "data", h, a), o) : "&ndash;" ) ]) ]; return super.formatTable({ headers: i, cells: l }); } } class Kt extends v { constructor(t) { super(t); } /** * Retrieves and formats tabular data from the display data. * * @returns {any[]} An object containing the headers and cells of the tabular data. */ getTabularDataArray() { const t = this.getDisplayData(), e = ["Child", "Parent"], s = []; return t.forEach((a) => { this.getChildrenDatums(a, s), s.push([a.name, "&ndash;"]); }), super.formatTable({ headers: e, cells: s }); } /** * Determine the child parent relationship in nested data * @private * @param {any} datum - The datum node to process. * @param {any[]} [result=[]] - An array to accumulate the resulting data. * @returns {any[]} The accumulated result array. */ getChildrenDatums(t, e = []) { t.children && t.children.length > 0 && t.children.forEach((s) => { this.getChildrenDatums(s, e), e.push([s.name, t.name]); }); } } class jt extends v { constructor(t) { super(t); } getTabularDataArray() { const t = this.getDisplayData(), { number: e, code: s } = p(this.getOptions(), "locale"), a = ["Child", "Group", "Value"], n = []; return t.forEach((o) => { Array.isArray(o.children) ? o.children.forEach((r) => { n.push([ r.name, o.name, r.value === null ? "&ndash;" : e(r.value, s) ]); }) : p(o.name) !== null && p(o.value) && n.push(["", o.name, e(o.value, s)]); }), super.formatTable({ headers: a, cells: n }); } } class Ht extends v { constructor(t) { super(t); } getTabularDataArray() { const t = this.getDisplayData(), e = this.getOptions(), { fontSizeMapsTo: s, wordMapsTo: a } = e.wordCloud, { groupMapsTo: n } = e.data, { code: o, number: r } = p(e, "locale"), i = [e.tooltip.wordLabel, "Group", e.tooltip.valueLabel], l = [ ...t.map((u) => [ u[a], u[n], r(u[s], o) ]) ]; return super.formatTable({ headers: i, cells: l }); } } export { kt as AlluvialChartModel, Ft as BoxplotChartModel, Vt as BulletChartModel, v as ChartModel, Lt as ChartModelBinned, G as ChartModelCartesian, Bt as ChoroplethModel, _t as CirclePackChartModel, Rt as GaugeChartModel, $t as HeatmapModel, zt as MeterChartModel, wt as PieChartModel, Ut as RadarChartModel, Kt as TreeChartModel, jt as TreemapChartModel, Ht as WordCloudModel }; //# sourceMappingURL=index.mjs.map