Skip to content

Commit 037a424

Browse files
committed
refactor: enhance edge context with _isPrevious and _similarId for improved edge handling
1 parent 9d5ec55 commit 037a424

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/components/TrackGraph.vue

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<script setup lang="ts">
2+
import { AntQuadratic } from '@/utils/g6';
23
import { getNodeQf, getTrackTreeContext } from '@/utils/node';
34
import { colorList } from '@/utils/others';
45
import { transform } from '@/utils/selector';
56
import type { EdgeData, TreeData } from '@antv/g6';
67
import { Graph, treeToGraphData } from '@antv/g6';
78
import { QueryPath, QueryResult } from '@gkd-kit/selector';
89
import { uniqBy } from 'lodash-es';
9-
import { AntQuadratic } from '@/utils/g6';
1010
1111
const props = withDefaults(
1212
defineProps<{
@@ -74,16 +74,20 @@ const edgeCtx = computed<EdgeContext>(() => {
7474
countMap[key] = count + 1;
7575
const id = key + (count > 0 ? `-${count}` : '');
7676
edgePathMap[id] = path;
77+
78+
const _isPrevious = path.connectWrapper.segment.operator.key === '->';
79+
const _similarId = [path.source.id, path.target.id, Number(_isPrevious)]
80+
.sort()
81+
.join('-');
7782
return {
7883
id,
7984
source: String(path.source.id),
8085
target: String(path.target.id),
81-
_similarId: [path.source.id, path.target.id].sort().join('-'),
86+
_similarId,
87+
_isPrevious,
8288
};
8389
};
84-
const getSimilarId = (edge: EdgeData): string => {
85-
return Reflect.get(edge, '_similarId') as string;
86-
};
90+
const getSimilarId = (edge: EdgeData) => edge._similarId as string;
8791
const resultAndPathList = props.showUnitResults.map((result) => {
8892
return {
8993
result,
@@ -115,7 +119,9 @@ const edgeCtx = computed<EdgeContext>(() => {
115119
return colorList[i % colorList.length];
116120
};
117121
const getCurveOffset = (edge: EdgeData): number => {
118-
const direction = Number(edge.source) > Number(edge.target) ? 1 : -1;
122+
const direction =
123+
(Number(edge.source) > Number(edge.target) ? 1 : -1) *
124+
(edge._isPrevious ? -1 : 1);
119125
const fistSimilarIndex = edgeList.findIndex(
120126
(e) => getSimilarId(e) === getSimilarId(edge),
121127
);

0 commit comments

Comments
 (0)