@vunk/graph 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/index.d.ts +0 -0
- package/api/index.mjs +1 -0
- package/api/user/index.d.ts +3 -0
- package/api/user/index.mjs +18 -0
- package/api/user/types.d.ts +5 -0
- package/components/_plugin-vue_export-helper.mjs +9 -0
- package/components/context-menu/index.css +1 -0
- package/components/context-menu/index.d.ts +2 -0
- package/components/context-menu/index.mjs +1797 -0
- package/components/graph/index.css +5 -0
- package/components/graph/index.d.ts +6 -0
- package/components/graph/index.mjs +110 -0
- package/components/graph/src/ctx.d.ts +12 -0
- package/components/graph/src/index.vue.d.ts +74 -0
- package/components/graph/src/types.d.ts +7 -0
- package/components/graph/src/useGraph.d.ts +3 -0
- package/components/graph/src/useSigma.d.ts +3 -0
- package/components/graph-view-ui/index.css +8 -0
- package/components/graph-view-ui/index.d.ts +4 -0
- package/components/graph-view-ui/index.mjs +81 -0
- package/components/graph-view-ui/src/ctx.d.ts +11 -0
- package/components/graph-view-ui/src/index.vue.d.ts +17 -0
- package/components/graph-view-ui/src/types.d.ts +1 -0
- package/components/hover-edge/index.d.ts +4 -0
- package/components/hover-edge/index.mjs +179 -0
- package/components/hover-edge/src/ctx.d.ts +42 -0
- package/components/hover-edge/src/index.vue.d.ts +194 -0
- package/components/hover-edge/src/types.d.ts +4 -0
- package/components/hover-highlight/index.d.ts +4 -0
- package/components/hover-highlight/index.mjs +133 -0
- package/components/hover-highlight/src/ctx.d.ts +33 -0
- package/components/hover-highlight/src/index.vue.d.ts +45 -0
- package/components/hover-highlight/src/types.d.ts +1 -0
- package/components/hover-node/index.d.ts +4 -0
- package/components/hover-node/index.mjs +146 -0
- package/components/hover-node/src/ctx.d.ts +35 -0
- package/components/hover-node/src/index.vue.d.ts +148 -0
- package/components/hover-node/src/types.d.ts +4 -0
- package/components/label/index.css +30 -0
- package/components/label/index.d.ts +6 -0
- package/components/label/index.mjs +145 -0
- package/components/label/src/core.d.ts +5 -0
- package/components/label/src/ctx.d.ts +24 -0
- package/components/label/src/index.vue.d.ts +33 -0
- package/components/label/src/types.d.ts +1 -0
- package/components/label/src/view.vue.d.ts +28 -0
- package/components/layout-forceatlas2/index.d.ts +5 -0
- package/components/layout-forceatlas2/index.mjs +1617 -0
- package/components/layout-forceatlas2/src/ctx.d.ts +9 -0
- package/components/layout-forceatlas2/src/index.vue.d.ts +14 -0
- package/components/layout-forceatlas2/src/types.d.ts +1 -0
- package/components/layout-forceatlas2/src/use.d.ts +16 -0
- package/components/link-guide/index.css +9 -0
- package/components/link-guide/index.d.ts +4 -0
- package/components/link-guide/index.mjs +118 -0
- package/components/link-guide/src/ctx.d.ts +11 -0
- package/components/link-guide/src/index.vue.d.ts +27 -0
- package/components/link-guide/src/types.d.ts +1 -0
- package/components/popup/index.css +32 -0
- package/components/popup/index.d.ts +5 -0
- package/components/popup/index.mjs +136 -0
- package/components/popup/src/core.d.ts +24 -0
- package/components/popup/src/ctx.d.ts +16 -0
- package/components/popup/src/index.vue.d.ts +73 -0
- package/components/popup/src/provider.vue.d.ts +46 -0
- package/components/popup/src/types.d.ts +1 -0
- package/components/search/index.d.ts +4 -0
- package/components/search/index.mjs +218 -0
- package/components/search/src/ctx.d.ts +53 -0
- package/components/search/src/index.vue.d.ts +83 -0
- package/components/search/src/types.d.ts +16 -0
- package/composables/index.d.ts +1 -0
- package/composables/index.mjs +1 -0
- package/index.css +90 -0
- package/index.d.ts +10 -0
- package/index.esm.js +10 -0
- package/package.json +108 -0
- package/shared/graph/index.d.ts +17 -0
- package/shared/graph/index.mjs +19 -0
- package/shared/index.d.ts +0 -0
- package/shared/index.mjs +1 -0
- package/stores/index.d.ts +0 -0
- package/stores/index.mjs +1 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { provide, inject, defineComponent, ref, onMounted, onBeforeUnmount, createElementBlock, openBlock, createElementVNode, createVNode, unref, withCtx, createBlock, createCommentVNode, renderSlot } from 'vue';
|
|
2
|
+
import { VkLabelProvider } from '@vunk/graph/components/label';
|
|
3
|
+
import { VkPopupProvider } from '@vunk/graph/components/popup';
|
|
4
|
+
import Sigma from 'sigma';
|
|
5
|
+
import Graph from 'graphology';
|
|
6
|
+
|
|
7
|
+
const props = {
|
|
8
|
+
/**
|
|
9
|
+
* Sigma.js 的初始化配置项
|
|
10
|
+
*/
|
|
11
|
+
defaultOptions: {
|
|
12
|
+
type: Object,
|
|
13
|
+
default: () => ({})
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const emits = {};
|
|
17
|
+
|
|
18
|
+
const key$1 = "vunk-graph";
|
|
19
|
+
function initGraph() {
|
|
20
|
+
const graph = new Graph();
|
|
21
|
+
provide(key$1, graph);
|
|
22
|
+
return graph;
|
|
23
|
+
}
|
|
24
|
+
function useGraph() {
|
|
25
|
+
const graph = inject(key$1);
|
|
26
|
+
if (!graph) {
|
|
27
|
+
throw new Error("Graph is not provided");
|
|
28
|
+
}
|
|
29
|
+
return graph;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const key = "vunk-graph-sigma";
|
|
33
|
+
function provideSigma(sigma) {
|
|
34
|
+
provide(key, sigma);
|
|
35
|
+
}
|
|
36
|
+
function useSigma() {
|
|
37
|
+
const sigma = inject(key);
|
|
38
|
+
if (!sigma) {
|
|
39
|
+
throw new Error("Sigma is not provided");
|
|
40
|
+
}
|
|
41
|
+
return sigma;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const _hoisted_1 = { class: "vkg-grap-x" };
|
|
45
|
+
var _sfc_main = /* @__PURE__ */ defineComponent({
|
|
46
|
+
...{
|
|
47
|
+
name: "VkGraph"
|
|
48
|
+
},
|
|
49
|
+
__name: "index",
|
|
50
|
+
props: props,
|
|
51
|
+
emits,
|
|
52
|
+
setup(__props, { emit: __emit }) {
|
|
53
|
+
const props = __props;
|
|
54
|
+
const emit = __emit;
|
|
55
|
+
const elRef = ref();
|
|
56
|
+
const graph = initGraph();
|
|
57
|
+
const ready = ref(false);
|
|
58
|
+
onMounted(() => {
|
|
59
|
+
const sigma = new Sigma(graph, elRef.value, {
|
|
60
|
+
renderEdgeLabels: true,
|
|
61
|
+
enableEdgeEvents: true,
|
|
62
|
+
...props.defaultOptions
|
|
63
|
+
});
|
|
64
|
+
provideSigma(sigma);
|
|
65
|
+
ready.value = true;
|
|
66
|
+
emit("load", { sigma, graph });
|
|
67
|
+
onBeforeUnmount(() => {
|
|
68
|
+
sigma.kill();
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
return (_ctx, _cache) => {
|
|
72
|
+
return openBlock(), createElementBlock("div", _hoisted_1, [
|
|
73
|
+
createElementVNode(
|
|
74
|
+
"div",
|
|
75
|
+
{
|
|
76
|
+
ref_key: "elRef",
|
|
77
|
+
ref: elRef,
|
|
78
|
+
class: "vkg-grap"
|
|
79
|
+
},
|
|
80
|
+
null,
|
|
81
|
+
512
|
|
82
|
+
/* NEED_PATCH */
|
|
83
|
+
),
|
|
84
|
+
createVNode(unref(VkLabelProvider), null, {
|
|
85
|
+
default: withCtx(() => [
|
|
86
|
+
ready.value ? (openBlock(), createBlock(unref(VkPopupProvider), { key: 0 }, {
|
|
87
|
+
default: withCtx(() => [
|
|
88
|
+
renderSlot(_ctx.$slots, "default")
|
|
89
|
+
]),
|
|
90
|
+
_: 3
|
|
91
|
+
/* FORWARDED */
|
|
92
|
+
})) : createCommentVNode("v-if", true)
|
|
93
|
+
]),
|
|
94
|
+
_: 3
|
|
95
|
+
/* FORWARDED */
|
|
96
|
+
})
|
|
97
|
+
]);
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
var types = /*#__PURE__*/Object.freeze({
|
|
103
|
+
__proto__: null
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
_sfc_main.install = (app) => {
|
|
107
|
+
app.component(_sfc_main.name || "VkGraph", _sfc_main);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export { _sfc_main as VkGraph, types as __VkGraph, _sfc_main as default, useGraph, useSigma };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PropType } from 'vue';
|
|
2
|
+
import type { DefaultOptions } from './types';
|
|
3
|
+
export declare const props: {
|
|
4
|
+
/**
|
|
5
|
+
* Sigma.js 的初始化配置项
|
|
6
|
+
*/
|
|
7
|
+
defaultOptions: {
|
|
8
|
+
type: PropType<DefaultOptions>;
|
|
9
|
+
default: () => {};
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export declare const emits: {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Ref } from 'vue';
|
|
2
|
+
declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
3
|
+
defaultOptions: {
|
|
4
|
+
type: import("vue").PropType<import("./types").DefaultOptions>;
|
|
5
|
+
default: () => {};
|
|
6
|
+
};
|
|
7
|
+
}>, {
|
|
8
|
+
props: import("@vue/shared").LooseRequired<Readonly<import("vue").ExtractPropTypes<{
|
|
9
|
+
defaultOptions: {
|
|
10
|
+
type: import("vue").PropType<import("./types").DefaultOptions>;
|
|
11
|
+
default: () => {};
|
|
12
|
+
};
|
|
13
|
+
}>> & Readonly<{}> & {}>;
|
|
14
|
+
emit: (event: string, ...args: any[]) => void;
|
|
15
|
+
elRef: Ref<HTMLDivElement, HTMLDivElement>;
|
|
16
|
+
graph: import("graphology").default<import("graphology-types").Attributes, import("graphology-types").Attributes, import("graphology-types").Attributes>;
|
|
17
|
+
ready: Ref<boolean, boolean>;
|
|
18
|
+
readonly VkLabelProvider: import("vue").DefineComponent<{}, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
}>[], {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
21
|
+
readonly VkPopupProvider: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
22
|
+
modelValue: {
|
|
23
|
+
type: BooleanConstructor;
|
|
24
|
+
default: boolean;
|
|
25
|
+
};
|
|
26
|
+
closeable: {
|
|
27
|
+
type: BooleanConstructor;
|
|
28
|
+
default: boolean;
|
|
29
|
+
};
|
|
30
|
+
}>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
31
|
+
'update:modelValue': null;
|
|
32
|
+
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
33
|
+
modelValue: {
|
|
34
|
+
type: BooleanConstructor;
|
|
35
|
+
default: boolean;
|
|
36
|
+
};
|
|
37
|
+
closeable: {
|
|
38
|
+
type: BooleanConstructor;
|
|
39
|
+
default: boolean;
|
|
40
|
+
};
|
|
41
|
+
}>> & Readonly<{
|
|
42
|
+
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
43
|
+
}>, {
|
|
44
|
+
modelValue: boolean;
|
|
45
|
+
closeable: boolean;
|
|
46
|
+
}, {}, {
|
|
47
|
+
VkGraphViewUi: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
48
|
+
coordinates: {
|
|
49
|
+
type: import("vue").PropType<number[]>;
|
|
50
|
+
default: () => number[];
|
|
51
|
+
};
|
|
52
|
+
}>, {
|
|
53
|
+
style: Ref<import("@vunk/shared").NormalObject, import("@vunk/shared").NormalObject>;
|
|
54
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
55
|
+
coordinates: {
|
|
56
|
+
type: import("vue").PropType<number[]>;
|
|
57
|
+
default: () => number[];
|
|
58
|
+
};
|
|
59
|
+
}>> & Readonly<{}>, {
|
|
60
|
+
coordinates: number[];
|
|
61
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
62
|
+
GlobalRenderer: import("vue").DefineComponent<{}, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
63
|
+
[key: string]: any;
|
|
64
|
+
}>[][], {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
65
|
+
}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
66
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
67
|
+
defaultOptions: {
|
|
68
|
+
type: import("vue").PropType<import("./types").DefaultOptions>;
|
|
69
|
+
default: () => {};
|
|
70
|
+
};
|
|
71
|
+
}>> & Readonly<{}>, {
|
|
72
|
+
defaultOptions: Partial<import("sigma/dist/declarations/src/settings").Settings<import("graphology-types").Attributes, import("graphology-types").Attributes, import("graphology-types").Attributes>> | undefined;
|
|
73
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
74
|
+
export default _default;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { useSigma } from '@vunk/graph/components/graph';
|
|
2
|
+
import { defineComponent, ref, onMounted, watch, onBeforeUnmount, createElementBlock, openBlock, normalizeStyle, renderSlot } from 'vue';
|
|
3
|
+
import { _ as _export_sfc } from '../_plugin-vue_export-helper.mjs';
|
|
4
|
+
|
|
5
|
+
const props = {
|
|
6
|
+
/**
|
|
7
|
+
* 图表内的坐标点 [x, y]
|
|
8
|
+
*/
|
|
9
|
+
coordinates: {
|
|
10
|
+
type: Array,
|
|
11
|
+
default: () => [0, 0]
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const emits = {};
|
|
15
|
+
|
|
16
|
+
var _sfc_main = defineComponent({
|
|
17
|
+
name: "VkGraphViewUi",
|
|
18
|
+
props,
|
|
19
|
+
emits,
|
|
20
|
+
setup(props2) {
|
|
21
|
+
const sigma = useSigma();
|
|
22
|
+
const style = ref({
|
|
23
|
+
"position": "absolute",
|
|
24
|
+
"left": "0",
|
|
25
|
+
"top": "0",
|
|
26
|
+
"display": "none",
|
|
27
|
+
"--vkg-graph-ratio": "1",
|
|
28
|
+
"--vkg-graph-spacing": "1px"
|
|
29
|
+
});
|
|
30
|
+
const updatePosition = () => {
|
|
31
|
+
if (!props2.coordinates || props2.coordinates.length < 2) {
|
|
32
|
+
style.value.display = "none";
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const [x, y] = props2.coordinates;
|
|
36
|
+
const pos = sigma.graphToViewport({ x, y });
|
|
37
|
+
const ratio = sigma.getCamera().ratio;
|
|
38
|
+
style.value["--vkg-graph-ratio"] = ratio.toString();
|
|
39
|
+
style.value["--vkg-graph-spacing"] = `${1 / ratio}px`;
|
|
40
|
+
style.value.left = `${pos.x}px`;
|
|
41
|
+
style.value.top = `${pos.y}px`;
|
|
42
|
+
style.value.display = "block";
|
|
43
|
+
};
|
|
44
|
+
onMounted(() => {
|
|
45
|
+
sigma.on("afterRender", updatePosition);
|
|
46
|
+
watch(() => props2.coordinates, updatePosition, { deep: true, immediate: true });
|
|
47
|
+
});
|
|
48
|
+
onBeforeUnmount(() => {
|
|
49
|
+
sigma.off("afterRender", updatePosition);
|
|
50
|
+
});
|
|
51
|
+
return {
|
|
52
|
+
style
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
58
|
+
return openBlock(), createElementBlock(
|
|
59
|
+
"div",
|
|
60
|
+
{
|
|
61
|
+
class: "vkg-graph-view-ui",
|
|
62
|
+
style: normalizeStyle(_ctx.style)
|
|
63
|
+
},
|
|
64
|
+
[
|
|
65
|
+
renderSlot(_ctx.$slots, "default")
|
|
66
|
+
],
|
|
67
|
+
4
|
|
68
|
+
/* STYLE */
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
var VkGraphViewUi = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
|
|
72
|
+
|
|
73
|
+
var types = /*#__PURE__*/Object.freeze({
|
|
74
|
+
__proto__: null
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
VkGraphViewUi.install = (app) => {
|
|
78
|
+
app.component(VkGraphViewUi.name || "VkGraphViewUi", VkGraphViewUi);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export { VkGraphViewUi, types as __VkGraphViewUi, VkGraphViewUi as default };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { NormalObject } from '@vunk/shared';
|
|
2
|
+
declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
3
|
+
coordinates: {
|
|
4
|
+
type: import("vue").PropType<number[]>;
|
|
5
|
+
default: () => number[];
|
|
6
|
+
};
|
|
7
|
+
}>, {
|
|
8
|
+
style: import("vue").Ref<NormalObject, NormalObject>;
|
|
9
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
10
|
+
coordinates: {
|
|
11
|
+
type: import("vue").PropType<number[]>;
|
|
12
|
+
default: () => number[];
|
|
13
|
+
};
|
|
14
|
+
}>> & Readonly<{}>, {
|
|
15
|
+
coordinates: number[];
|
|
16
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
17
|
+
export default _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { defineComponent, reactive, watch, onMounted, onBeforeUnmount, createBlock, createCommentVNode, openBlock, unref, withCtx, renderSlot } from 'vue';
|
|
2
|
+
import { ContextMenu } from '@vunk/graph/components/context-menu';
|
|
3
|
+
import { useSigma, useGraph } from '@vunk/graph/components/graph';
|
|
4
|
+
|
|
5
|
+
const props = {
|
|
6
|
+
/**
|
|
7
|
+
* 是否启用右键菜单功能
|
|
8
|
+
*/
|
|
9
|
+
contextMenu: {
|
|
10
|
+
type: Boolean,
|
|
11
|
+
default: false
|
|
12
|
+
},
|
|
13
|
+
/**
|
|
14
|
+
* 当前高亮的边 ID。支持 v-model。
|
|
15
|
+
*/
|
|
16
|
+
modelValue: {
|
|
17
|
+
type: String,
|
|
18
|
+
default: ""
|
|
19
|
+
},
|
|
20
|
+
/**
|
|
21
|
+
* 移除时的延迟时间 (ms)
|
|
22
|
+
*/
|
|
23
|
+
leaveDelay: {
|
|
24
|
+
type: Number,
|
|
25
|
+
default: 100
|
|
26
|
+
},
|
|
27
|
+
/**
|
|
28
|
+
* 进入时的延迟时间 (ms)
|
|
29
|
+
*/
|
|
30
|
+
enterDelay: {
|
|
31
|
+
type: Number,
|
|
32
|
+
default: 0
|
|
33
|
+
},
|
|
34
|
+
/**
|
|
35
|
+
* 悬浮时高亮显示时的颜色
|
|
36
|
+
*/
|
|
37
|
+
activeColor: {
|
|
38
|
+
type: String,
|
|
39
|
+
default: "#409EFF"
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const emits = {
|
|
43
|
+
"update:modelValue": null,
|
|
44
|
+
"rightClick": (e) => e
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
var _sfc_main = /* @__PURE__ */ defineComponent({
|
|
48
|
+
...{ name: "VkHoverEdge" },
|
|
49
|
+
__name: "index",
|
|
50
|
+
props: props,
|
|
51
|
+
emits,
|
|
52
|
+
setup(__props, { emit: __emit }) {
|
|
53
|
+
const props = __props;
|
|
54
|
+
const emit = __emit;
|
|
55
|
+
const sigma = useSigma();
|
|
56
|
+
const graph = useGraph();
|
|
57
|
+
const contextmenuState = reactive({
|
|
58
|
+
edge: "",
|
|
59
|
+
show: false,
|
|
60
|
+
options: {
|
|
61
|
+
x: 0,
|
|
62
|
+
y: 0
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
let oldNodeReducer = null;
|
|
66
|
+
let oldEdgeReducer = null;
|
|
67
|
+
let isApplied = false;
|
|
68
|
+
watch(() => props.modelValue, (edgeId) => {
|
|
69
|
+
if (edgeId && graph.hasEdge(edgeId)) {
|
|
70
|
+
if (!isApplied) {
|
|
71
|
+
oldNodeReducer = sigma.getSetting("nodeReducer");
|
|
72
|
+
oldEdgeReducer = sigma.getSetting("edgeReducer");
|
|
73
|
+
isApplied = true;
|
|
74
|
+
}
|
|
75
|
+
sigma.setSetting("edgeReducer", (edge, data) => {
|
|
76
|
+
const baseData = oldEdgeReducer ? oldEdgeReducer(edge, data) : data;
|
|
77
|
+
if (edge === edgeId) {
|
|
78
|
+
const res = { ...baseData, zIndex: 10, forceLabel: true };
|
|
79
|
+
if (props.activeColor) {
|
|
80
|
+
res.color = props.activeColor;
|
|
81
|
+
}
|
|
82
|
+
return res;
|
|
83
|
+
}
|
|
84
|
+
return baseData;
|
|
85
|
+
});
|
|
86
|
+
} else {
|
|
87
|
+
if (isApplied) {
|
|
88
|
+
sigma.setSetting("nodeReducer", oldNodeReducer);
|
|
89
|
+
sigma.setSetting("edgeReducer", oldEdgeReducer);
|
|
90
|
+
isApplied = false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
let enterTimer = null;
|
|
95
|
+
let leaveTimer = null;
|
|
96
|
+
function enterHandler({ edge }) {
|
|
97
|
+
clearTimeout(leaveTimer);
|
|
98
|
+
enterTimer = setTimeout(() => {
|
|
99
|
+
emit("update:modelValue", edge);
|
|
100
|
+
}, props.enterDelay);
|
|
101
|
+
}
|
|
102
|
+
function leaveHandler() {
|
|
103
|
+
clearTimeout(enterTimer);
|
|
104
|
+
leaveTimer = setTimeout(() => {
|
|
105
|
+
if (props.contextMenu && contextmenuState.show)
|
|
106
|
+
return;
|
|
107
|
+
emit("update:modelValue", "");
|
|
108
|
+
}, props.leaveDelay);
|
|
109
|
+
}
|
|
110
|
+
onMounted(() => {
|
|
111
|
+
sigma.on("enterEdge", enterHandler);
|
|
112
|
+
sigma.on("leaveEdge", leaveHandler);
|
|
113
|
+
});
|
|
114
|
+
onBeforeUnmount(() => {
|
|
115
|
+
clearTimeout(enterTimer);
|
|
116
|
+
clearTimeout(leaveTimer);
|
|
117
|
+
sigma.off("enterEdge", enterHandler);
|
|
118
|
+
sigma.off("leaveEdge", leaveHandler);
|
|
119
|
+
if (isApplied) {
|
|
120
|
+
sigma.setSetting("nodeReducer", oldNodeReducer);
|
|
121
|
+
sigma.setSetting("edgeReducer", oldEdgeReducer);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
onMounted(() => {
|
|
125
|
+
sigma.on("rightClickEdge", rightClickHandler);
|
|
126
|
+
sigma.on("rightClickStage", rightClickHandler);
|
|
127
|
+
});
|
|
128
|
+
onBeforeUnmount(() => {
|
|
129
|
+
sigma.off("rightClickEdge", rightClickHandler);
|
|
130
|
+
sigma.off("rightClickStage", rightClickHandler);
|
|
131
|
+
});
|
|
132
|
+
function rightClickHandler({ event }) {
|
|
133
|
+
if (props.modelValue) {
|
|
134
|
+
const { original } = event;
|
|
135
|
+
original.preventDefault();
|
|
136
|
+
contextmenuState.show = true;
|
|
137
|
+
contextmenuState.edge = props.modelValue;
|
|
138
|
+
contextmenuState.options.x = original.x;
|
|
139
|
+
contextmenuState.options.y = original.y;
|
|
140
|
+
emit("rightClick", {
|
|
141
|
+
edge: props.modelValue,
|
|
142
|
+
original
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function changeContextmenuShow(show) {
|
|
147
|
+
!show && leaveHandler();
|
|
148
|
+
}
|
|
149
|
+
return (_ctx, _cache) => {
|
|
150
|
+
return _ctx.contextMenu ? (openBlock(), createBlock(unref(ContextMenu), {
|
|
151
|
+
key: 0,
|
|
152
|
+
show: contextmenuState.show,
|
|
153
|
+
"onUpdate:show": [
|
|
154
|
+
_cache[0] || (_cache[0] = ($event) => contextmenuState.show = $event),
|
|
155
|
+
changeContextmenuShow
|
|
156
|
+
],
|
|
157
|
+
options: contextmenuState.options
|
|
158
|
+
}, {
|
|
159
|
+
default: withCtx(() => [
|
|
160
|
+
renderSlot(_ctx.$slots, "default", {
|
|
161
|
+
edge: contextmenuState.edge
|
|
162
|
+
})
|
|
163
|
+
]),
|
|
164
|
+
_: 3
|
|
165
|
+
/* FORWARDED */
|
|
166
|
+
}, 8, ["show", "options"])) : createCommentVNode("v-if", true);
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
var types = /*#__PURE__*/Object.freeze({
|
|
172
|
+
__proto__: null
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
_sfc_main.install = (app) => {
|
|
176
|
+
app.component(_sfc_main.name || "VkHoverEdge", _sfc_main);
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
export { _sfc_main as VkHoverEdge, types as __VkHoverEdge, _sfc_main as default };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { RightClickEvent } from './types';
|
|
2
|
+
export declare const props: {
|
|
3
|
+
/**
|
|
4
|
+
* 是否启用右键菜单功能
|
|
5
|
+
*/
|
|
6
|
+
contextMenu: {
|
|
7
|
+
type: BooleanConstructor;
|
|
8
|
+
default: boolean;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* 当前高亮的边 ID。支持 v-model。
|
|
12
|
+
*/
|
|
13
|
+
modelValue: {
|
|
14
|
+
type: StringConstructor;
|
|
15
|
+
default: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* 移除时的延迟时间 (ms)
|
|
19
|
+
*/
|
|
20
|
+
leaveDelay: {
|
|
21
|
+
type: NumberConstructor;
|
|
22
|
+
default: number;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* 进入时的延迟时间 (ms)
|
|
26
|
+
*/
|
|
27
|
+
enterDelay: {
|
|
28
|
+
type: NumberConstructor;
|
|
29
|
+
default: number;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* 悬浮时高亮显示时的颜色
|
|
33
|
+
*/
|
|
34
|
+
activeColor: {
|
|
35
|
+
type: StringConstructor;
|
|
36
|
+
default: string;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export declare const emits: {
|
|
40
|
+
'update:modelValue': null;
|
|
41
|
+
rightClick: (e: RightClickEvent) => RightClickEvent;
|
|
42
|
+
};
|