UNPKG

@progress/kendo-vue-charts

Version:
157 lines (156 loc) 4.88 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ import { defineComponent as h, createVNode as a, h as r, isVNode as d } from "vue"; import { getTemplate as l, classNames as c } from "@progress/kendo-vue-common"; import { InstanceObserver as f } from "@progress/kendo-charts"; import { TooltipPoint as u } from "./Point.mjs"; import { SharedTooltipContent as m } from "./SharedTooltipContent.mjs"; import { TooltipPopup as S } from "./Popup.mjs"; function T(t) { return typeof t == "function" || Object.prototype.toString.call(t) === "[object Object]" && !d(t); } const C = "k-chart-shared-tooltip", y = "k-chart-tooltip-inverse", v = /* @__PURE__ */ h({ name: "KendoSeriesTooltip", // static contextType = ChartContext; data() { return { popupShown: !1, popupAlign: void 0, popupOffset: void 0, popupContext: {}, popupStyles: void 0, className: void 0, shared: void 0 }; }, inject: { optionsState: { default: {} }, observersState: { default: null }, dispatchObservers: { default: null } }, // chartObserver: InstanceObserver; mounted() { this.chartObserver = new f(this, { showTooltip: "onShowTooltip", hideTooltip: "onHideTooltip" }), this.dispatchObservers({ type: "add", payload: this.chartObserver }); }, unmounted() { this.dispatchObservers({ type: "remove", payload: this.chartObserver }); }, render() { let t; const e = this.popupShown ? function() { const n = this.findRenderFunction(); if (this.shared) { const p = a(m, { categoryText: this.popupContext.categoryText, colorMarker: this.popupContext.colorMarker, colspan: this.popupContext.colspan, nameColumn: this.popupContext.nameColumn, points: this.popupContext.points }, null); return l.call(this, { h: r, template: n, defaultRendering: p, additionalProps: Object.assign({}, this.popupContext) }); } else { const p = this.popupContext.point, i = this.findRenderFunctionByIndex(p.series.index), o = r("span", { innerHTML: this.popupContext.point.formattedValue }); return i !== null ? l.call(this, { h: r, template: i, defaultRendering: o, additionalProps: Object.assign({}, this.popupContext) }) : n !== null ? l.call(this, { h: r, template: n, defaultRendering: o, additionalProps: Object.assign({}, this.popupContext) }) : o; } } : Function.prototype, s = c({ [C]: this.shared, [y]: !!this.className }); return a(S, { popupShown: this.popupShown, popupAlign: this.popupAlign, popupOffset: this.popupOffset, popupStyles: this.popupStyles, className: s }, T(t = e.call(this)) ? t : { default: () => [t] }); }, methods: { onShowTooltip(t) { const { anchor: e, style: s, shared: n, className: p, crosshair: i } = t; let o; i || (n ? o = this.createSharedTooltipContext(t) : o = this.createTooltipContext(t), this.popupShown = !0, this.popupAlign = e.align, this.popupOffset = e.point, this.popupContext = o, this.popupStyles = s, this.className = p, this.shared = n); }, onHideTooltip() { this.popupShown = !1, this.popupStyles = {}, this.className = void 0; }, createSharedTooltipContext(t) { const { points: e, categoryText: s } = t, n = e.filter((o) => typeof o.series.name != "undefined").length > 0, p = t.series.length > 1; let i = 1; return n && i++, p && i++, { categoryText: s, colorMarker: p, colspan: i, nameColumn: n, points: t.points.map((o) => new u(o, t.format)) }; }, createTooltipContext(t) { const { point: e, format: s } = t; return { point: new u(e, s) }; }, findRenderFunctionByIndex(t) { const e = this.optionsState.series; return e !== void 0 && Array.isArray(e) && e[t] !== void 0 && e[t].hasOwnProperty("tooltip") && e[t].tooltip.hasOwnProperty("render") ? e[t].tooltip.render : null; }, findRenderFunction() { const t = this.optionsState.tooltip; return t !== void 0 && t.hasOwnProperty("render") ? t.render : null; } } }); export { v as SeriesTooltip };