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

【V5】如何在上层拿到所有的 elements #5217

Closed
BinghuiXie opened this issue Jun 21, 2023 · 1 comment
Closed

【V5】如何在上层拿到所有的 elements #5217

BinghuiXie opened this issue Jun 21, 2023 · 1 comment

Comments

@BinghuiXie
Copy link
Contributor

  • G2 Version:
  • Platform:
  • Mini Showcase(like screenshots):
  • CodePen Link:

V5 版本的 G2 底层采用 Selection 相关的 API 来选中节点,例如

selectAll(`.${ELEMENT_CLASS_NAME}`)

包括也实现了 selectG2Elements 方法用于获取所有的 Elements。
但目前在 index.ts 中,没有导出 Selection 或者 utils 里面的方法函数

// index.ts
import { runtime } from '@antv/g';

runtime.enableCSSParsing = false;

export {
  render,
  renderToMountedElement,
  MAIN_LAYER_CLASS_NAME,
  LABEL_LAYER_CLASS_NAME,
  ELEMENT_CLASS_NAME,
  VIEW_CLASS_NAME,
  PLOT_CLASS_NAME,
  COMPONENT_CLASS_NAME,
  LABEL_CLASS_NAME,
  AREA_CLASS_NAME,
} from './runtime';

export type { G2Context } from './runtime';

export { createLibrary } from './stdlib';

export { Chart, MarkNode, CompositionNode, register } from './api';

export { ChartEvent } from './utils/event';

export * from './spec';

所以如何在 G2 上层获取到所有的 Elements 呢
(目前想基于 G2 的 V5 版本做上层封装,但 V5 的很多工具方法没有暴露出来无法使用)

@BinghuiXie BinghuiXie changed the title 如何在上层拿到所有的 elements 【V5】如何在上层拿到所有的 elements Jun 21, 2023
@BinghuiXie
Copy link
Contributor Author

BinghuiXie commented Jun 22, 2023

const { canvas } = chart.getContext();

// 找到图形元素
const elements = canvas.document.getElementsByClassName(ELEMENT_CLASS_NAME);

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

No branches or pull requests

1 participant