@progress/kendo-vue-charts
Version:
211 lines (210 loc) • 5.23 kB
JavaScript
/**
* @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 k, createVNode as r } from "vue";
import { templateRendering as l, getListeners as d, setRef as f, getRef as y, getDir as g, validatePackage as b } from "@progress/kendo-vue-common";
import { packageMetadata as m } from "../package-metadata.mjs";
import { sankeyTheme as v, Sankey as T } from "@progress/kendo-charts";
import { Tooltip as D } from "./tooltip.mjs";
const h = {
visible: !0,
offset: 12
}, $ = /* @__PURE__ */ k({
name: "KendoSankey",
emits: {
linkclick: null,
linkenter: null,
linkleave: null,
nodeclick: null,
nodeenter: null,
nodeleave: null
},
inheritAttrs: !1,
props: {
dataNodes: {
type: Array,
required: !0
},
dataLinks: {
type: Array,
required: !0
},
disableAutoLayout: Boolean,
disableKeyboardNavigation: Boolean,
dir: String,
labels: Object,
legend: Object,
links: Object,
nodes: Object,
title: Object,
tooltip: Object
},
created() {
b(m), this.instance = null;
},
data() {
return {
currentTooltip: null,
currentDir: void 0
};
},
watch: {
dataNodes: function() {
this.update(this);
},
dataLinks: function() {
this.update(this);
},
links: function() {
this.update(this);
},
nodes: function() {
this.update(this);
},
labels: function() {
this.update(this);
},
title: function() {
this.update(this);
},
legend: function() {
this.update(this);
},
disableAutoLayout: function() {
this.update(this);
},
disableKeyboardNavigation: function() {
this.update(this);
},
dir: function() {
this.update(this);
},
tooltip: function() {
this.update(this);
}
},
computed: {
sankeyClasses() {
const t = this.$attrs.class;
return {
"k-chart k-sankey": !0,
[t]: !!t
};
}
},
mounted() {
this.element = y(this, "element"), this.currentDir = g(this.element, this.$props.dir), this.createSankey(this);
},
unmounted() {
this.destroySankey();
},
methods: {
exportVisual(t) {
return this.instance.exportVisual(t);
},
destroySankey() {
this.instance && (this.instance.destroy(), this.instance = null);
},
createSankey() {
const t = this.element;
if (!t)
return;
const e = this.sankeyOptions(), i = v(t);
this.instance = new T(t, e, i), this.bindEvents(this.instance);
},
update() {
this.instance && this.instance.setOptions(this.sankeyOptions());
},
bindEvents(t) {
t.bind("nodeEnter", this.triggerEvent), t.bind("nodeLeave", this.triggerEvent), t.bind("linkEnter", this.triggerEvent), t.bind("linkLeave", this.triggerEvent), t.bind("nodeClick", this.triggerEvent), t.bind("linkClick", this.triggerEvent), t.bind("tooltipShow", this.onTooltipShow), t.bind("tooltipHide", this.onTooltipHide);
},
triggerEvent(t) {
const e = {
...t,
target: this
};
this.$emit(t.type.toLowerCase(), e);
},
sankeyOptions() {
const {
dataNodes: t,
dataLinks: e,
links: i,
nodes: o,
labels: s,
title: n,
legend: a,
disableAutoLayout: p,
disableKeyboardNavigation: u,
tooltip: c
} = this.$props;
return {
data: {
nodes: t,
links: e
},
links: i,
nodes: o,
labels: s,
title: n,
legend: a,
disableAutoLayout: p,
disableKeyboardNavigation: u,
rtl: this.currentDir === "rtl",
tooltip: {
...h,
...c
}
};
},
onTooltipShow(t) {
const {
visible: e
} = {
...h,
...this.$props.tooltip
};
if (e) {
const i = {
tooltipData: t.tooltipData,
eventData: {
dataItem: t.dataItem,
nodeValue: t.nodeValue,
targetType: t.targetType
}
};
this.currentTooltip = i;
}
},
onTooltipHide() {
this.currentTooltip = null;
}
},
render() {
const {
nodeContent: t,
linkContent: e,
offset: i
} = this.$props.tooltip || {}, o = l.call(this, t, d.call(this)), s = l.call(this, e, d.call(this)), n = this.$props.dir || this.currentDir;
return [r("div", {
ref: f(this, "element"),
class: this.sankeyClasses,
style: this.$attrs.style,
dir: n
}, null), this.currentTooltip && r(D, {
tooltipData: this.currentTooltip.tooltipData,
eventData: this.currentTooltip.eventData,
dir: n,
offset: i || 12,
nodeContent: o,
linkContent: s
}, null)];
}
});
export {
$ as Sankey
};