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: dynamically toggle label visibility based on density to ensure adaptive display #6398

Merged
merged 9 commits into from
Oct 12, 2024

Conversation

yvonneyx
Copy link
Contributor

@yvonneyx yvonneyx commented Oct 11, 2024

  • 根据信息密度动态调整标签的显隐,以确保标签仅在有足够可用空间的情况下显示。这一策略旨在避免标签之间的重叠,减少视觉混乱

Oct-11-2024 19-13-38

interface ToggleLabelVisibilityOptions extends BaseBehaviorOptions {
  /**
   * <zh/> 是否启用
   *
   * <en/> Whether to enable
   * @defaultValue `true`
   */
  enable?: boolean | ((event: IViewportEvent) => boolean);
  /**
   * <zh/> 根据元素的重要性从高到低排序,重要性越高的元素其标签显示优先级越高。一般情况下 combo > node > edge
   *
   * <en/> Sort elements by their importance in descending order; elements with higher importance have higher label display priority; usually combo > node > edge
   */
  sorter?: (this: Graph, labelElementsInViewport: Element[]) => Element[];
  /**
   * <zh/> 根据节点的重要性从高到低排序,重要性越高的节点其标签显示优先级越高。内置几种中心性算法,也可以自定义排序函数。需要注意,如果设置了 `sorter`,则 `nodeSorter` 不会生效
   *
   * <en/> Sort nodes by importance in descending order; nodes with higher importance have higher label display priority. Several centrality algorithms are built in, and custom sorting functions can also be defined. It should be noted that if `sorter` is set, `nodeSorter` will not take effect
   * @defaultValue { type: 'degree' }
   */
  nodeSorter?: NodeCentralityOptions | ((this: Graph, labeledNodesInViewport: Node[]) => Node[]);
  /**
   * <zh/> 根据边的重要性从高到低排序,重要性越高的边其标签显示优先级越高。默认按照数据先后进行排序。需要注意,如果设置了 `sorter`,则 `edgeSorter` 不会生效
   *
   * <en/> Sort edges by importance in descending order; edges with higher importance have higher label display priority. By default, they are sorted according to the data. It should be noted that if `sorter` is set, `edgeSorter` will not take effect
   */
  edgeSorter?: (this: Graph, labeledEdgesInViewport: Edge[]) => Edge[];
  /**
   * <zh/> 根据群组的重要性从高到低排序,重要性越高的群组其标签显示优先级越高。默认按照数据先后进行排序。需要注意,如果设置了 `sorter`,则 `comboSorter` 不会生效
   *
   * <en/> Sort combos by importance in descending order; combos with higher importance have higher label display priority. By default, they are sorted according to the data. It should be noted that if `sorter` is set, `comboSorter` will not take effect
   */
  comboSorter?: (this: Graph, labeledCombosInViewport: Combo[]) => Combo[];
  /**
   * <zh/> 设置标签的内边距,用于判断标签是否重叠,以避免标签显示过于密集
   *
   * <en/> Set the padding of the label to determine whether the label overlaps to avoid the label being displayed too densely
   * @defaultValue 10
   */
  padding?: Padding;
  /**
   * <zh/> 节流时间
   *
   * <en/> Throttle time
   * @defaultValue 32
   */
  throttle?: number;
}

@yvonneyx yvonneyx changed the title feat: toggle label visibility feat: dynamically toggle label visibility based on density to ensure adaptive display Oct 11, 2024
@yvonneyx yvonneyx merged commit 2bacd5d into v5 Oct 12, 2024
5 checks passed
@yvonneyx yvonneyx deleted the behavior/label-visibility branch October 12, 2024 06:52
@rmd1710714107
Copy link

这个用法在官方文档哪里,我没找到,希望可以告知,谢谢

@yvonneyx
Copy link
Contributor Author

yvonneyx commented Nov 4, 2024

这个用法在官方文档哪里,我没找到,希望可以告知,谢谢

示例:https://g6.antv.antgroup.com/examples/feature/default/#unicorns-investors

配置项可以先查看此处:https://github.com/antvis/G6/blob/v5/packages/g6/src/behaviors/auto-adapt-label.ts,这两天也会同步到官网~

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.

3 participants