@vunk/graph 0.0.3 → 0.0.5
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/components/context-menu-stage/index.d.ts +3 -0
- package/components/context-menu-stage/index.mjs +79 -0
- package/components/context-menu-stage/src/ctx.d.ts +15 -0
- package/components/context-menu-stage/src/index.vue.d.ts +123 -0
- package/components/graph/index.d.ts +2 -0
- package/components/graph/index.mjs +85 -5
- package/components/graph/src/index.vue.d.ts +2 -0
- package/components/graph/src/useEdgeReducer.d.ts +13 -0
- package/components/graph/src/useNodeReducer.d.ts +13 -0
- package/components/hover-edge/index.mjs +19 -31
- package/components/hover-edge/src/index.vue.d.ts +3 -3
- package/components/hover-highlight/index.mjs +45 -50
- package/composables/index.d.ts +1 -1
- package/composables/index.mjs +1 -1
- package/index.d.ts +1 -0
- package/index.esm.js +1 -0
- package/package.json +5 -1
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { ContextMenu } from '@vunk/graph/components/context-menu';
|
|
2
|
+
import { useSigma } from '@vunk/graph/composables';
|
|
3
|
+
import { useModelComputed } from '@vunk/core/composables';
|
|
4
|
+
import { defineComponent, reactive, onMounted, onBeforeUnmount, resolveComponent, createBlock, openBlock, withCtx, renderSlot } from 'vue';
|
|
5
|
+
import { _ as _export_sfc } from '../_plugin-vue_export-helper.mjs';
|
|
6
|
+
|
|
7
|
+
const props = {
|
|
8
|
+
/**
|
|
9
|
+
* 是否显示右键菜单。支持 v-model。
|
|
10
|
+
*/
|
|
11
|
+
modelValue: {
|
|
12
|
+
type: Boolean,
|
|
13
|
+
default: void 0
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const emits = {
|
|
17
|
+
"update:modelValue": (val) => typeof val === "boolean",
|
|
18
|
+
"rightClick": (e) => !!e
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
var _sfc_main = defineComponent({
|
|
22
|
+
name: "VkContextMenuStage",
|
|
23
|
+
components: {
|
|
24
|
+
ContextMenu
|
|
25
|
+
},
|
|
26
|
+
props,
|
|
27
|
+
emits,
|
|
28
|
+
setup(props2, { emit }) {
|
|
29
|
+
const sigma = useSigma();
|
|
30
|
+
const show = useModelComputed({
|
|
31
|
+
default: false,
|
|
32
|
+
key: "modelValue"
|
|
33
|
+
}, props2, emit);
|
|
34
|
+
const contextmenuState = reactive({
|
|
35
|
+
options: {
|
|
36
|
+
x: 0,
|
|
37
|
+
y: 0
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
function rightClickHandler({ event }) {
|
|
41
|
+
const { original } = event;
|
|
42
|
+
original.preventDefault();
|
|
43
|
+
contextmenuState.options.x = original.x;
|
|
44
|
+
contextmenuState.options.y = original.y;
|
|
45
|
+
show.value = true;
|
|
46
|
+
emit("rightClick", {
|
|
47
|
+
original
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
onMounted(() => {
|
|
51
|
+
sigma.on("rightClickStage", rightClickHandler);
|
|
52
|
+
});
|
|
53
|
+
onBeforeUnmount(() => {
|
|
54
|
+
sigma.off("rightClickStage", rightClickHandler);
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
show,
|
|
58
|
+
contextmenuState
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
64
|
+
const _component_ContextMenu = resolveComponent("ContextMenu");
|
|
65
|
+
return openBlock(), createBlock(_component_ContextMenu, {
|
|
66
|
+
show: _ctx.show,
|
|
67
|
+
"onUpdate:show": _cache[0] || (_cache[0] = ($event) => _ctx.show = $event),
|
|
68
|
+
options: _ctx.contextmenuState.options
|
|
69
|
+
}, {
|
|
70
|
+
default: withCtx(() => [
|
|
71
|
+
renderSlot(_ctx.$slots, "default")
|
|
72
|
+
]),
|
|
73
|
+
_: 3
|
|
74
|
+
/* FORWARDED */
|
|
75
|
+
}, 8, ["show", "options"]);
|
|
76
|
+
}
|
|
77
|
+
var VkContextMenuStage = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
|
|
78
|
+
|
|
79
|
+
export { VkContextMenuStage, VkContextMenuStage as default };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const props: {
|
|
2
|
+
/**
|
|
3
|
+
* 是否显示右键菜单。支持 v-model。
|
|
4
|
+
*/
|
|
5
|
+
modelValue: {
|
|
6
|
+
type: BooleanConstructor;
|
|
7
|
+
default: undefined;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export declare const emits: {
|
|
11
|
+
'update:modelValue': (val: boolean) => boolean;
|
|
12
|
+
rightClick: (e: {
|
|
13
|
+
original: MouseEvent;
|
|
14
|
+
}) => boolean;
|
|
15
|
+
};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
2
|
+
modelValue: {
|
|
3
|
+
type: BooleanConstructor;
|
|
4
|
+
default: undefined;
|
|
5
|
+
};
|
|
6
|
+
}>, {
|
|
7
|
+
show: import("vue").WritableComputedRef<boolean, boolean>;
|
|
8
|
+
contextmenuState: {
|
|
9
|
+
options: {
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
15
|
+
'update:modelValue': (val: boolean) => boolean;
|
|
16
|
+
rightClick: (e: {
|
|
17
|
+
original: MouseEvent;
|
|
18
|
+
}) => boolean;
|
|
19
|
+
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
20
|
+
modelValue: {
|
|
21
|
+
type: BooleanConstructor;
|
|
22
|
+
default: undefined;
|
|
23
|
+
};
|
|
24
|
+
}>> & Readonly<{
|
|
25
|
+
onRightClick?: ((e: {
|
|
26
|
+
original: MouseEvent;
|
|
27
|
+
}) => any) | undefined;
|
|
28
|
+
"onUpdate:modelValue"?: ((val: boolean) => any) | undefined;
|
|
29
|
+
}>, {
|
|
30
|
+
modelValue: boolean;
|
|
31
|
+
}, {}, {
|
|
32
|
+
ContextMenu: {
|
|
33
|
+
new (...args: any[]): import("vue").CreateComponentPublicInstanceWithMixins<Readonly<import("vue").ExtractPropTypes<{
|
|
34
|
+
options: {
|
|
35
|
+
type: import("vue").PropType<import("@vunk/graph/components/context-menu").MenuOptions>;
|
|
36
|
+
default: null;
|
|
37
|
+
};
|
|
38
|
+
show: {
|
|
39
|
+
type: BooleanConstructor;
|
|
40
|
+
default: boolean;
|
|
41
|
+
};
|
|
42
|
+
}>> & {
|
|
43
|
+
onClose?: ((...args: any[]) => any) | undefined;
|
|
44
|
+
"onUpdate:show"?: ((...args: any[]) => any) | undefined;
|
|
45
|
+
}, {
|
|
46
|
+
closeMenu: () => void;
|
|
47
|
+
isClosed: () => boolean;
|
|
48
|
+
getMenuRef: () => import("@vunk/graph/components/context-menu").ContextSubMenuInstance | undefined;
|
|
49
|
+
getMenuDimensions: () => {
|
|
50
|
+
width: number;
|
|
51
|
+
height: number;
|
|
52
|
+
};
|
|
53
|
+
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
54
|
+
close: (...args: any[]) => void;
|
|
55
|
+
"update:show": (...args: any[]) => void;
|
|
56
|
+
}, import("vue").PublicProps, {
|
|
57
|
+
options: import("@vunk/graph/components/context-menu").MenuOptions;
|
|
58
|
+
show: boolean;
|
|
59
|
+
}, true, {}, {}, import("vue").GlobalComponents, import("vue").GlobalDirectives, string, {}, any, import("vue").ComponentProvideOptions, {
|
|
60
|
+
P: {};
|
|
61
|
+
B: {};
|
|
62
|
+
D: {};
|
|
63
|
+
C: {};
|
|
64
|
+
M: {};
|
|
65
|
+
Defaults: {};
|
|
66
|
+
}, Readonly<import("vue").ExtractPropTypes<{
|
|
67
|
+
options: {
|
|
68
|
+
type: import("vue").PropType<import("@vunk/graph/components/context-menu").MenuOptions>;
|
|
69
|
+
default: null;
|
|
70
|
+
};
|
|
71
|
+
show: {
|
|
72
|
+
type: BooleanConstructor;
|
|
73
|
+
default: boolean;
|
|
74
|
+
};
|
|
75
|
+
}>> & {
|
|
76
|
+
onClose?: ((...args: any[]) => any) | undefined;
|
|
77
|
+
"onUpdate:show"?: ((...args: any[]) => any) | undefined;
|
|
78
|
+
}, {
|
|
79
|
+
closeMenu: () => void;
|
|
80
|
+
isClosed: () => boolean;
|
|
81
|
+
getMenuRef: () => import("@vunk/graph/components/context-menu").ContextSubMenuInstance | undefined;
|
|
82
|
+
getMenuDimensions: () => {
|
|
83
|
+
width: number;
|
|
84
|
+
height: number;
|
|
85
|
+
};
|
|
86
|
+
}, {}, {}, {}, {
|
|
87
|
+
options: import("@vunk/graph/components/context-menu").MenuOptions;
|
|
88
|
+
show: boolean;
|
|
89
|
+
}>;
|
|
90
|
+
__isFragment?: never;
|
|
91
|
+
__isTeleport?: never;
|
|
92
|
+
__isSuspense?: never;
|
|
93
|
+
} & import("vue").ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<{
|
|
94
|
+
options: {
|
|
95
|
+
type: import("vue").PropType<import("@vunk/graph/components/context-menu").MenuOptions>;
|
|
96
|
+
default: null;
|
|
97
|
+
};
|
|
98
|
+
show: {
|
|
99
|
+
type: BooleanConstructor;
|
|
100
|
+
default: boolean;
|
|
101
|
+
};
|
|
102
|
+
}>> & {
|
|
103
|
+
onClose?: ((...args: any[]) => any) | undefined;
|
|
104
|
+
"onUpdate:show"?: ((...args: any[]) => any) | undefined;
|
|
105
|
+
}, {
|
|
106
|
+
closeMenu: () => void;
|
|
107
|
+
isClosed: () => boolean;
|
|
108
|
+
getMenuRef: () => import("@vunk/graph/components/context-menu").ContextSubMenuInstance | undefined;
|
|
109
|
+
getMenuDimensions: () => {
|
|
110
|
+
width: number;
|
|
111
|
+
height: number;
|
|
112
|
+
};
|
|
113
|
+
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
114
|
+
close: (...args: any[]) => void;
|
|
115
|
+
"update:show": (...args: any[]) => void;
|
|
116
|
+
}, string, {
|
|
117
|
+
options: import("@vunk/graph/components/context-menu").MenuOptions;
|
|
118
|
+
show: boolean;
|
|
119
|
+
}, {}, string, {}, import("vue").GlobalComponents, import("vue").GlobalDirectives, string, import("vue").ComponentProvideOptions> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & (new () => {
|
|
120
|
+
$slots: Partial<Record<number, (_: any) => any>>;
|
|
121
|
+
});
|
|
122
|
+
}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
123
|
+
export default _default;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import VkGraph from './src/index.vue';
|
|
2
2
|
export * as __VkGraph from './src/types';
|
|
3
|
+
export { useEdgeReducer } from './src/useEdgeReducer';
|
|
3
4
|
export { useGraph } from './src/useGraph';
|
|
5
|
+
export { useNodeReducer } from './src/useNodeReducer';
|
|
4
6
|
export { useSigma } from './src/useSigma';
|
|
5
7
|
export { VkGraph, };
|
|
6
8
|
export default VkGraph;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { provide, inject, defineComponent, ref, onMounted, onBeforeUnmount, createElementBlock, openBlock, createElementVNode, createVNode, unref, withCtx, createBlock, createCommentVNode, renderSlot } from 'vue';
|
|
1
|
+
import { shallowReactive, provide, inject, defineComponent, ref, onMounted, onBeforeUnmount, createElementBlock, openBlock, createElementVNode, createVNode, unref, withCtx, createBlock, createCommentVNode, renderSlot } from 'vue';
|
|
2
2
|
import { VkLabelProvider } from '@vunk/graph/components/label';
|
|
3
3
|
import { VkPopupProvider } from '@vunk/graph/components/popup';
|
|
4
4
|
import Sigma from 'sigma';
|
|
@@ -17,20 +17,96 @@ const emits = {
|
|
|
17
17
|
load: (e) => e
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
const key$
|
|
20
|
+
const key$3 = "vunk-graph-edge_reducer";
|
|
21
|
+
function initEdgeReducer() {
|
|
22
|
+
const middlewares = shallowReactive([]);
|
|
23
|
+
function addMiddleware(middleware) {
|
|
24
|
+
middlewares.push(middleware);
|
|
25
|
+
}
|
|
26
|
+
function removeMiddleware(middleware) {
|
|
27
|
+
const index = middlewares.indexOf(middleware);
|
|
28
|
+
if (index > -1) {
|
|
29
|
+
middlewares.splice(index, 1);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function edgeReducer(edge, data) {
|
|
33
|
+
let currentData = { ...data };
|
|
34
|
+
for (const middleware of middlewares) {
|
|
35
|
+
const res = middleware(edge, currentData);
|
|
36
|
+
if (res) {
|
|
37
|
+
currentData = { ...currentData, ...res };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return currentData;
|
|
41
|
+
}
|
|
42
|
+
const context = {
|
|
43
|
+
edgeReducer,
|
|
44
|
+
addMiddleware,
|
|
45
|
+
removeMiddleware
|
|
46
|
+
};
|
|
47
|
+
provide(key$3, context);
|
|
48
|
+
return context;
|
|
49
|
+
}
|
|
50
|
+
function useEdgeReducer() {
|
|
51
|
+
const edgeReducerContext = inject(key$3);
|
|
52
|
+
if (!edgeReducerContext) {
|
|
53
|
+
throw new Error("EdgeReducer is not provided");
|
|
54
|
+
}
|
|
55
|
+
return edgeReducerContext;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const key$2 = "vunk-graph";
|
|
21
59
|
function initGraph() {
|
|
22
60
|
const graph = new Graph();
|
|
23
|
-
provide(key$
|
|
61
|
+
provide(key$2, graph);
|
|
24
62
|
return graph;
|
|
25
63
|
}
|
|
26
64
|
function useGraph() {
|
|
27
|
-
const graph = inject(key$
|
|
65
|
+
const graph = inject(key$2);
|
|
28
66
|
if (!graph) {
|
|
29
67
|
throw new Error("Graph is not provided");
|
|
30
68
|
}
|
|
31
69
|
return graph;
|
|
32
70
|
}
|
|
33
71
|
|
|
72
|
+
const key$1 = "vunk-graph-node_reducer";
|
|
73
|
+
function initNodeReducer() {
|
|
74
|
+
const middlewares = shallowReactive([]);
|
|
75
|
+
function addMiddleware(middleware) {
|
|
76
|
+
middlewares.push(middleware);
|
|
77
|
+
}
|
|
78
|
+
function removeMiddleware(middleware) {
|
|
79
|
+
const index = middlewares.indexOf(middleware);
|
|
80
|
+
if (index > -1) {
|
|
81
|
+
middlewares.splice(index, 1);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function nodeReducer(node, data) {
|
|
85
|
+
let currentData = { ...data };
|
|
86
|
+
for (const middleware of middlewares) {
|
|
87
|
+
const res = middleware(node, currentData);
|
|
88
|
+
if (res) {
|
|
89
|
+
currentData = { ...currentData, ...res };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return currentData;
|
|
93
|
+
}
|
|
94
|
+
const context = {
|
|
95
|
+
nodeReducer,
|
|
96
|
+
addMiddleware,
|
|
97
|
+
removeMiddleware
|
|
98
|
+
};
|
|
99
|
+
provide(key$1, context);
|
|
100
|
+
return context;
|
|
101
|
+
}
|
|
102
|
+
function useNodeReducer() {
|
|
103
|
+
const nodeReducerContext = inject(key$1);
|
|
104
|
+
if (!nodeReducerContext) {
|
|
105
|
+
throw new Error("NodeReducer is not provided");
|
|
106
|
+
}
|
|
107
|
+
return nodeReducerContext;
|
|
108
|
+
}
|
|
109
|
+
|
|
34
110
|
const key = "vunk-graph-sigma";
|
|
35
111
|
function provideSigma(sigma) {
|
|
36
112
|
provide(key, sigma);
|
|
@@ -54,6 +130,8 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
54
130
|
setup(__props, { emit: __emit }) {
|
|
55
131
|
const props = __props;
|
|
56
132
|
const emit = __emit;
|
|
133
|
+
const { nodeReducer } = initNodeReducer();
|
|
134
|
+
const { edgeReducer } = initEdgeReducer();
|
|
57
135
|
const elRef = ref();
|
|
58
136
|
const graph = initGraph();
|
|
59
137
|
const ready = ref(false);
|
|
@@ -61,6 +139,8 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
61
139
|
const sigma = new Sigma(graph, elRef.value, {
|
|
62
140
|
renderEdgeLabels: true,
|
|
63
141
|
enableEdgeEvents: true,
|
|
142
|
+
nodeReducer,
|
|
143
|
+
edgeReducer,
|
|
64
144
|
...props.defaultOptions
|
|
65
145
|
});
|
|
66
146
|
provideSigma(sigma);
|
|
@@ -109,4 +189,4 @@ _sfc_main.install = (app) => {
|
|
|
109
189
|
app.component(_sfc_main.name || "VkGraph", _sfc_main);
|
|
110
190
|
};
|
|
111
191
|
|
|
112
|
-
export { _sfc_main as VkGraph, types as __VkGraph, _sfc_main as default, useGraph, useSigma };
|
|
192
|
+
export { _sfc_main as VkGraph, types as __VkGraph, _sfc_main as default, useEdgeReducer, useGraph, useNodeReducer, useSigma };
|
|
@@ -14,6 +14,8 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
|
|
|
14
14
|
onLoad?: ((e: import("./types").LoadEvent) => any) | undefined;
|
|
15
15
|
}> & {}>;
|
|
16
16
|
emit: (event: "load", e: import("./types").LoadEvent) => void;
|
|
17
|
+
nodeReducer: (node: string, data: any) => Partial<import("sigma/types").NodeDisplayData>;
|
|
18
|
+
edgeReducer: (edge: string, data: any) => Partial<import("sigma/types").EdgeDisplayData>;
|
|
17
19
|
elRef: Ref<HTMLDivElement, HTMLDivElement>;
|
|
18
20
|
graph: import("graphology").default<import("graphology-types").Attributes, import("graphology-types").Attributes, import("graphology-types").Attributes>;
|
|
19
21
|
ready: Ref<boolean, boolean>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { EdgeDisplayData } from 'sigma/types';
|
|
2
|
+
type Middleware = (edge: string, data: any) => Partial<EdgeDisplayData> | null;
|
|
3
|
+
export declare function initEdgeReducer(): {
|
|
4
|
+
edgeReducer: (edge: string, data: any) => Partial<EdgeDisplayData>;
|
|
5
|
+
addMiddleware: (middleware: Middleware) => void;
|
|
6
|
+
removeMiddleware: (middleware: Middleware) => void;
|
|
7
|
+
};
|
|
8
|
+
export declare function useEdgeReducer(): {
|
|
9
|
+
edgeReducer: (edge: string, data: any) => Partial<EdgeDisplayData> | null;
|
|
10
|
+
addMiddleware: (middleware: Middleware) => void;
|
|
11
|
+
removeMiddleware: (middleware: Middleware) => void;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { NodeDisplayData } from 'sigma/types';
|
|
2
|
+
type Middleware = (node: string, data: any) => Partial<NodeDisplayData> | null;
|
|
3
|
+
export declare function initNodeReducer(): {
|
|
4
|
+
nodeReducer: (node: string, data: any) => Partial<NodeDisplayData>;
|
|
5
|
+
addMiddleware: (middleware: Middleware) => void;
|
|
6
|
+
removeMiddleware: (middleware: Middleware) => void;
|
|
7
|
+
};
|
|
8
|
+
export declare function useNodeReducer(): {
|
|
9
|
+
nodeReducer: (node: string, data: any) => Partial<NodeDisplayData> | null;
|
|
10
|
+
addMiddleware: (middleware: Middleware) => void;
|
|
11
|
+
removeMiddleware: (middleware: Middleware) => void;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineComponent, reactive, watch, onMounted, onBeforeUnmount, createBlock, createCommentVNode, openBlock, unref, withCtx, renderSlot } from 'vue';
|
|
2
2
|
import { ContextMenu } from '@vunk/graph/components/context-menu';
|
|
3
|
-
import { useSigma, useGraph } from '@vunk/graph/components/graph';
|
|
3
|
+
import { useSigma, useGraph, useEdgeReducer } from '@vunk/graph/components/graph';
|
|
4
4
|
|
|
5
5
|
const props = {
|
|
6
6
|
/**
|
|
@@ -61,6 +61,7 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
61
61
|
const emit = __emit;
|
|
62
62
|
const sigma = useSigma();
|
|
63
63
|
const graph = useGraph();
|
|
64
|
+
const { addMiddleware, removeMiddleware } = useEdgeReducer();
|
|
64
65
|
const contextmenuState = reactive({
|
|
65
66
|
edge: "",
|
|
66
67
|
show: false,
|
|
@@ -69,34 +70,25 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
69
70
|
y: 0
|
|
70
71
|
}
|
|
71
72
|
});
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
oldNodeReducer = sigma.getSetting("nodeReducer");
|
|
79
|
-
oldEdgeReducer = sigma.getSetting("edgeReducer");
|
|
80
|
-
isApplied = true;
|
|
81
|
-
}
|
|
82
|
-
sigma.setSetting("edgeReducer", (edge, data) => {
|
|
83
|
-
const baseData = oldEdgeReducer ? oldEdgeReducer(edge, data) : data;
|
|
84
|
-
if (edge === edgeId) {
|
|
85
|
-
const res = { ...baseData, zIndex: 10, forceLabel: true };
|
|
86
|
-
if (props.activeColor) {
|
|
87
|
-
res.color = props.activeColor;
|
|
88
|
-
}
|
|
89
|
-
return res;
|
|
90
|
-
}
|
|
91
|
-
return baseData;
|
|
92
|
-
});
|
|
93
|
-
} else {
|
|
94
|
-
if (isApplied) {
|
|
95
|
-
sigma.setSetting("nodeReducer", oldNodeReducer);
|
|
96
|
-
sigma.setSetting("edgeReducer", oldEdgeReducer);
|
|
97
|
-
isApplied = false;
|
|
73
|
+
function edgeMiddleware(edge) {
|
|
74
|
+
const edgeId = props.modelValue;
|
|
75
|
+
if (edgeId && graph.hasEdge(edgeId) && edge === edgeId) {
|
|
76
|
+
const res = { zIndex: 10, forceLabel: true };
|
|
77
|
+
if (props.activeColor) {
|
|
78
|
+
res.color = props.activeColor;
|
|
98
79
|
}
|
|
80
|
+
return res;
|
|
99
81
|
}
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
watch(() => props.modelValue, () => {
|
|
85
|
+
sigma.refresh();
|
|
86
|
+
});
|
|
87
|
+
onMounted(() => {
|
|
88
|
+
addMiddleware(edgeMiddleware);
|
|
89
|
+
});
|
|
90
|
+
onBeforeUnmount(() => {
|
|
91
|
+
removeMiddleware(edgeMiddleware);
|
|
100
92
|
});
|
|
101
93
|
let enterTimer = null;
|
|
102
94
|
let leaveTimer = null;
|
|
@@ -128,10 +120,6 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
128
120
|
clearTimeout(leaveTimer);
|
|
129
121
|
sigma.off("enterEdge", enterHandler);
|
|
130
122
|
sigma.off("leaveEdge", leaveHandler);
|
|
131
|
-
if (isApplied) {
|
|
132
|
-
sigma.setSetting("nodeReducer", oldNodeReducer);
|
|
133
|
-
sigma.setSetting("edgeReducer", oldEdgeReducer);
|
|
134
|
-
}
|
|
135
123
|
});
|
|
136
124
|
onMounted(() => {
|
|
137
125
|
sigma.on("rightClickEdge", rightClickHandler);
|
|
@@ -56,6 +56,8 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
|
|
|
56
56
|
emit: ((event: "rightClick", e: import("./types").RightClickEvent) => void) & ((event: "update:modelValue", ...args: any[]) => void);
|
|
57
57
|
sigma: import("sigma").default<import("graphology-types").Attributes, import("graphology-types").Attributes, import("graphology-types").Attributes>;
|
|
58
58
|
graph: import("graphology").default<import("graphology-types").Attributes, import("graphology-types").Attributes, import("graphology-types").Attributes>;
|
|
59
|
+
addMiddleware: (middleware: (edge: string, data: any) => Partial<import("sigma/types").EdgeDisplayData> | null) => void;
|
|
60
|
+
removeMiddleware: (middleware: (edge: string, data: any) => Partial<import("sigma/types").EdgeDisplayData> | null) => void;
|
|
59
61
|
contextmenuState: {
|
|
60
62
|
edge: string;
|
|
61
63
|
show: boolean;
|
|
@@ -64,9 +66,7 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
|
|
|
64
66
|
y: number;
|
|
65
67
|
};
|
|
66
68
|
};
|
|
67
|
-
|
|
68
|
-
oldEdgeReducer: any;
|
|
69
|
-
isApplied: boolean;
|
|
69
|
+
edgeMiddleware: (edge: string) => any;
|
|
70
70
|
enterTimer: any;
|
|
71
71
|
leaveTimer: any;
|
|
72
72
|
enterHandler: ({ edge }: {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useSigma } from '@vunk/graph/composables';
|
|
1
|
+
import { useSigma, useNodeReducer, useEdgeReducer } from '@vunk/graph/composables';
|
|
2
2
|
import { defineComponent, watch, onMounted, onUnmounted, renderSlot } from 'vue';
|
|
3
3
|
import { _ as _export_sfc } from '../_plugin-vue_export-helper.mjs';
|
|
4
4
|
|
|
@@ -43,52 +43,49 @@ var _sfc_main = defineComponent({
|
|
|
43
43
|
setup(props2, { emit }) {
|
|
44
44
|
const sigma = useSigma();
|
|
45
45
|
const graph = sigma.getGraph();
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (nodeId)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
isApplied = true;
|
|
55
|
-
}
|
|
56
|
-
const hoveredColor = sigma.getNodeDisplayData(nodeId)?.color || "";
|
|
57
|
-
sigma.setSetting("nodeReducer", (node, data) => {
|
|
58
|
-
const baseData = oldNodeReducer ? oldNodeReducer(node, data) : data;
|
|
59
|
-
if (node === nodeId) {
|
|
60
|
-
return { ...baseData, zIndex: 3 };
|
|
61
|
-
}
|
|
62
|
-
if (graph.hasEdge(node, nodeId) || graph.hasEdge(nodeId, node)) {
|
|
63
|
-
return { ...baseData, zIndex: 2 };
|
|
64
|
-
}
|
|
65
|
-
return {
|
|
66
|
-
...baseData,
|
|
67
|
-
zIndex: 0,
|
|
68
|
-
label: "",
|
|
69
|
-
color: props2.nodeFadeColor,
|
|
70
|
-
highlighted: false
|
|
71
|
-
};
|
|
72
|
-
});
|
|
73
|
-
sigma.setSetting("edgeReducer", (edge, data) => {
|
|
74
|
-
const baseData = oldEdgeReducer ? oldEdgeReducer(edge, data) : data;
|
|
75
|
-
if (graph.hasExtremity(edge, nodeId)) {
|
|
76
|
-
return { ...baseData, color: hoveredColor, zIndex: 10 };
|
|
77
|
-
}
|
|
78
|
-
return {
|
|
79
|
-
...baseData,
|
|
80
|
-
color: props2.edgeFadeColor,
|
|
81
|
-
label: "",
|
|
82
|
-
zIndex: 0
|
|
83
|
-
};
|
|
84
|
-
});
|
|
85
|
-
} else {
|
|
86
|
-
if (isApplied) {
|
|
87
|
-
sigma.setSetting("nodeReducer", oldNodeReducer);
|
|
88
|
-
sigma.setSetting("edgeReducer", oldEdgeReducer);
|
|
89
|
-
isApplied = false;
|
|
90
|
-
}
|
|
46
|
+
const { addMiddleware: addNodeMiddleware, removeMiddleware: removeNodeMiddleware } = useNodeReducer();
|
|
47
|
+
const { addMiddleware: addEdgeMiddleware, removeMiddleware: removeEdgeMiddleware } = useEdgeReducer();
|
|
48
|
+
const nodeMiddleware = (node) => {
|
|
49
|
+
const nodeId = props2.modelValue;
|
|
50
|
+
if (!nodeId)
|
|
51
|
+
return null;
|
|
52
|
+
if (node === nodeId) {
|
|
53
|
+
return { zIndex: 3 };
|
|
91
54
|
}
|
|
55
|
+
if (graph.hasEdge(node, nodeId) || graph.hasEdge(nodeId, node)) {
|
|
56
|
+
return { zIndex: 2 };
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
zIndex: 0,
|
|
60
|
+
label: "",
|
|
61
|
+
color: props2.nodeFadeColor,
|
|
62
|
+
highlighted: false
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
const edgeMiddleware = (edge) => {
|
|
66
|
+
const nodeId = props2.modelValue;
|
|
67
|
+
if (!nodeId)
|
|
68
|
+
return null;
|
|
69
|
+
const hoveredColor = sigma.getNodeDisplayData(nodeId)?.color || "";
|
|
70
|
+
if (graph.hasExtremity(edge, nodeId)) {
|
|
71
|
+
return { color: hoveredColor, zIndex: 10 };
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
color: props2.edgeFadeColor,
|
|
75
|
+
label: "",
|
|
76
|
+
zIndex: 0
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
watch(() => props2.modelValue, () => {
|
|
80
|
+
sigma.refresh();
|
|
81
|
+
});
|
|
82
|
+
onMounted(() => {
|
|
83
|
+
addNodeMiddleware(nodeMiddleware);
|
|
84
|
+
addEdgeMiddleware(edgeMiddleware);
|
|
85
|
+
});
|
|
86
|
+
onUnmounted(() => {
|
|
87
|
+
removeNodeMiddleware(nodeMiddleware);
|
|
88
|
+
removeEdgeMiddleware(edgeMiddleware);
|
|
92
89
|
});
|
|
93
90
|
let timer = null;
|
|
94
91
|
const enterHandler = ({ node }) => {
|
|
@@ -108,10 +105,8 @@ var _sfc_main = defineComponent({
|
|
|
108
105
|
clearTimeout(timer);
|
|
109
106
|
sigma.off("enterNode", enterHandler);
|
|
110
107
|
sigma.off("leaveNode", leaveHandler);
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
sigma.setSetting("edgeReducer", oldEdgeReducer);
|
|
114
|
-
}
|
|
108
|
+
removeNodeMiddleware(nodeMiddleware);
|
|
109
|
+
removeEdgeMiddleware(edgeMiddleware);
|
|
115
110
|
});
|
|
116
111
|
return {};
|
|
117
112
|
}
|
package/composables/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { useGraph, useSigma } from '@vunk/graph/components/graph';
|
|
1
|
+
export { useEdgeReducer, useGraph, useNodeReducer, useSigma } from '@vunk/graph/components/graph';
|
package/composables/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { useGraph, useSigma } from '@vunk/graph/components/graph';
|
|
1
|
+
export { useEdgeReducer, useGraph, useNodeReducer, useSigma } from '@vunk/graph/components/graph';
|
package/index.d.ts
CHANGED
package/index.esm.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vunk/graph",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "",
|
|
6
6
|
"license": "ISC",
|
|
@@ -71,6 +71,10 @@
|
|
|
71
71
|
"import": "./components/graph/index.mjs",
|
|
72
72
|
"types": "./components/graph/index.d.ts"
|
|
73
73
|
},
|
|
74
|
+
"./components/context-menu-stage": {
|
|
75
|
+
"import": "./components/context-menu-stage/index.mjs",
|
|
76
|
+
"types": "./components/context-menu-stage/index.d.ts"
|
|
77
|
+
},
|
|
74
78
|
"./components/context-menu": {
|
|
75
79
|
"import": "./components/context-menu/index.mjs",
|
|
76
80
|
"types": "./components/context-menu/index.d.ts"
|