Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugin): minimap #5603

Open
wants to merge 8 commits into
base: v5
Choose a base branch
from
Open

feat(plugin): minimap #5603

wants to merge 8 commits into from

Conversation

vaynevayne
Copy link
Contributor

No description provided.

options: { refresh, size, padding, mode, hideEdge },
} = this;

await this.context.graph.render();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该是监听 AFTER_RENDER 事件后执行

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不行 ,这个事件不会触发还是什么, minimap不会显示

this.canvas.appendChild(group);
const minimapBBox = this.canvas.getRoot().getRenderBounds();

const graphBBox = this.context.canvas.document.documentElement.getRenderBounds();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

context.canvas.getBounds 能够获取画布内元素的总体包围盒

private cloneKeyShapes(shapes: (Node | Edge | Combo)[], group: Group = new Group()) {
// 建立 minimap shape 到 main shape 的映射关系到实例, 后面走入更新流程就不需要再clone了
shapes.forEach((shape) => {
// graphItem 存的是引用? 原图上消失,这里就会是空?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

理论上都是对象引用,但不应该回出现原图上消失,这里变为空的情况

}

if (!minimapItem.destroyed) {
minimapItem.style = { ...minimapItem.style, ...graphItem.style };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议访问 .attributes 来获取样式,设置样式使用 .attr(...)
.style 是一个 proxy,通常用于获取/设置单个样式属性

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image attr废弃了吧, 看描述还是使用style?

Copy link
Contributor

@Aarebecca Aarebecca Apr 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

废弃的只是 attr() 签名

image

通过 xxx.style = { ... } 的方式并不能正确的设置样式

});
}

public getEvents() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个方法没有用了,定义了也不会生效。更新的话需要显式监听

graph.on(GraphEvent.AFTER_ELEMENT_UPDATE, ...); // 在元素更新之后触发

import { ID } from '@antv/graphlib';
import { createDOM, debounce, uniqueId } from '@antv/util';

import Moveable from 'moveable';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果只用到了简单的拖拽能力的话,建议内部实现逻辑就好了,这个包体积还是蛮大的

import { ID } from '@antv/graphlib';
import { createDOM, debounce, uniqueId } from '@antv/util';

import Moveable from 'moveable';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里空行删一下

const controller_4 = new AbortController();
const controller_5 = new AbortController();

this.controllerList.push(controller_1, controller_2, controller_3, controller_4, controller_5);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这些 AbortController 没看到哪里在使用呢

'<div class="g6-minimap-container" style="position: relative;height:100%" ></div>',
);

// if (isSafari || isFireFox) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

内部实现的话使用原生 DragEvent 就好了,不用通过 mouse 事件模拟

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

模拟不了吧, 拖动会复制一份出来,可以在整个屏幕拖动, 要实现鼠标跟随效果, 只能mouse模拟
moveable这个包, react-movable 支持treesharking, 原生js的不支持 有点蛋疼,
有没有其他的包推荐?

const controller = new AbortController();
const controller_2 = new AbortController();
const controller_3 = new AbortController();
this.controllerList.push(controller, controller_2, controller_3);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里也是,没用的话可以去掉

this.context.graph.on(GraphEvent.AFTER_RENDER, this.drawerCanvas.bind(this)); // 在元素更新之后触发
this.context.graph.on(GraphEvent.AFTER_ELEMENT_STATE_CHANGE, this.handleUpdateCanvas.bind(this)); // 在元素更新之后触发
this.context.graph.on(GraphEvent.AFTER_ELEMENT_VISIBILITY_CHANGE, this.handleVisibilityChange.bind(this)); // 在元素更新之后触发
this.context.graph.on(GraphEvent.AFTER_ELEMENT_UPDATE, this.handleUpdateCanvas.bind(this)); // 在元素更新之后触发
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFTER_ELEMENT_UPDATE 是针对单个元素的,这里建议监听一下事件:

  • GraphEvent.AFTER_SIZE_CHANGE 画布尺寸变化
  • GraphEvent.AFTER_DRAW 绘制完成(不包含布局)
  • GraphEvent.AFTER_RENDER 渲染完成(包含布局)

建议将 drawCanvasupdateCanvas 合并成一个(例如 handleChange),这样 AFTER_DRAWAFTER_RENDER 统一走这个事件回调就行了。不太建议监听元素事件,因为批量触发时会很频繁,还需要做防抖处理

};

public destroy(): void {
super.destroy();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要解除事件监听

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants