mirror of
https://gitee.com/antv/g6.git
synced 2024-11-30 10:48:24 +08:00
fix: update polyline
This commit is contained in:
parent
466c9cee71
commit
d3c7ba7dd2
@ -37,7 +37,11 @@ import { getExtension } from '../../util/extension';
|
||||
import { convertToNumber } from '../../util/type';
|
||||
import { isTreeLayout } from '../../util/layout';
|
||||
import { hasTreeBehaviors } from '../../util/behavior';
|
||||
import { EdgeCollisionChecker, QuadTree } from '../../util/polyline';
|
||||
import {
|
||||
EdgeCollisionChecker,
|
||||
QuadTree,
|
||||
isPolylineWithObstacleAvoidance,
|
||||
} from '../../util/polyline';
|
||||
|
||||
/**
|
||||
* Manages the data transform extensions;
|
||||
@ -133,13 +137,18 @@ export class DataController {
|
||||
return this.graphCore.getRelatedEdges(nodeId, direction);
|
||||
}
|
||||
|
||||
public findNearEdges(nodeId: ID, transientItem?: Node) {
|
||||
public findNearEdges(
|
||||
nodeId: ID,
|
||||
transientItem?: Node,
|
||||
onlyPolyline?: boolean,
|
||||
) {
|
||||
const edges = this.graphCore.getAllEdges();
|
||||
|
||||
const canvasBBox = this.graph.getRenderBBox(undefined) as AABB;
|
||||
const quadTree = new QuadTree(canvasBBox, 4);
|
||||
|
||||
edges.forEach((edge) => {
|
||||
if (onlyPolyline && !isPolylineWithObstacleAvoidance(edge)) return;
|
||||
const {
|
||||
data: { x: sourceX, y: sourceY },
|
||||
} = this.graphCore.getNode(edge.source);
|
||||
|
@ -521,18 +521,15 @@ export class ItemController {
|
||||
);
|
||||
}
|
||||
|
||||
const newNearEdges = this.graph.getNearEdgesData(id);
|
||||
const relatedEdges = graphCore.getRelatedEdges(id);
|
||||
const adjacentEdgeInnerModels = isPointPreventPolylineOverlap(
|
||||
innerModel,
|
||||
)
|
||||
? uniq(
|
||||
(this.nearEdgesCache.get(id) || [])
|
||||
.concat(newNearEdges)
|
||||
.concat(relatedEdges),
|
||||
)
|
||||
: relatedEdges;
|
||||
this.nearEdgesCache.set(id, newNearEdges);
|
||||
const adjacentEdgeInnerModels = graphCore.getRelatedEdges(id);
|
||||
|
||||
if (isPointPreventPolylineOverlap(innerModel)) {
|
||||
const newNearEdges = this.graph.getNearEdgesData(id, true);
|
||||
const prevNearEdges = this.nearEdgesCache.get(id) || [];
|
||||
adjacentEdgeInnerModels.push(...newNearEdges);
|
||||
adjacentEdgeInnerModels.push(...prevNearEdges);
|
||||
this.nearEdgesCache.set(id, newNearEdges);
|
||||
}
|
||||
|
||||
adjacentEdgeInnerModels.forEach((edge) => {
|
||||
edgeIdsToUpdate.add(edge.id);
|
||||
|
@ -1031,11 +1031,15 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
||||
* @param nodeId id of the start node
|
||||
* @returns nearby edges' data array
|
||||
*/
|
||||
public getNearEdgesData(nodeId: ID): EdgeModel[] {
|
||||
public getNearEdgesData(nodeId: ID, onlyPolyline?: boolean): EdgeModel[] {
|
||||
const transientItem = this.itemController.getTransientItem(
|
||||
nodeId,
|
||||
) as unknown as Node;
|
||||
return this.dataController.findNearEdges(nodeId, transientItem);
|
||||
return this.dataController.findNearEdges(
|
||||
nodeId,
|
||||
transientItem,
|
||||
onlyPolyline,
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Get one-hop node ids from a start node.
|
||||
|
@ -171,9 +171,11 @@ export class DragNode extends Behavior {
|
||||
}
|
||||
|
||||
/** Retrieve the nearby edges for a given node using quadtree collision detection. */
|
||||
private getNearEdgesForNodes(nodeIds: ID[]) {
|
||||
private getNearEdgesForNodes(nodeIds: ID[], onlyPolyline?: boolean) {
|
||||
return uniq(
|
||||
nodeIds.flatMap((nodeId) => this.graph.getNearEdgesData(nodeId)),
|
||||
nodeIds.flatMap((nodeId) =>
|
||||
this.graph.getNearEdgesData(nodeId, onlyPolyline),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -341,6 +343,7 @@ export class DragNode extends Behavior {
|
||||
|
||||
this.hiddenNearEdges = this.getNearEdgesForNodes(
|
||||
preventPolylineOverlapNodeIds,
|
||||
true,
|
||||
).filter((edge) => !hiddenEdgesIds.includes(edge.id));
|
||||
const hiddenNearEdgesIds = this.hiddenNearEdges.map((edge) => edge.id);
|
||||
|
||||
|
@ -118,7 +118,7 @@ export interface IGraph<
|
||||
* @param nodeId id of the start node
|
||||
* @returns nearby edges' data array
|
||||
*/
|
||||
getNearEdgesData: (nodeId: ID) => EdgeModel[];
|
||||
getNearEdgesData: (nodeId: ID, onlyPolyline?: boolean) => EdgeModel[];
|
||||
/**
|
||||
* Get one-hop node ids from a start node.
|
||||
* @param nodeId id of the start node
|
||||
|
Loading…
Reference in New Issue
Block a user