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: add snapline plugin #6188

Merged
merged 4 commits into from
Aug 16, 2024
Merged

feat: add snapline plugin #6188

merged 4 commits into from
Aug 16, 2024

Conversation

yvonneyx
Copy link
Contributor

@yvonneyx yvonneyx commented Aug 15, 2024

  • add snapline plugin
  • tests

Kapture 2024-08-15 at 21 00 50

interface SnaplineOptions extends BasePluginOptions {
  /**
   * <zh/> 对齐精度,即移动节点时与目标位置的距离小于 tolerance 时触发显示对齐线
   *
   * <en/> The alignment accuracy, that is, when the distance between the moved node and the target position is less than tolerance, the alignment line is displayed
   * @defaultValue 5
   */
  tolerance?: number;
  /**
   * <zh/> 对齐线头尾的延伸距离。取值范围:[0, Infinity]
   *
   * <en/> The extension distance of the snapline. The value range is [0, Infinity]
   * @defaultValue 20
   */
  offset?: number;
  /**
   * <zh/> 是否启用自动吸附
   *
   * <en/> Whether to enable automatic adsorption
   * @defaultValue true
   */
  auto?: boolean;
  /**
   * <zh/> 指定元素上的哪个图形作为参照图形
   *
   * <en/> Specifies which shape on the element to use as the reference shape
   * @defaultValue `'key'`
   * @remarks
   * <zh/>
   * - 'key' 使用元素的主图形作为参照图形
   * - 也可以传入一个函数,接收元素对象,返回一个图形
   *
   * <en/>
   * - `'key'` uses the key shape of the element as the reference shape
   * - You can also pass in a function that receives the element and returns a shape
   */
  shape?: string | ((node: Node) => DisplayObject);
  /**
   * <zh/> 垂直对齐线样式
   *
   * <en/> Vertical snapline style
   * @defaultValue `{ stroke: '#1783FF' }`
   */
  verticalLineStyle?: BaseStyleProps;
  /**
   * <zh/> 水平对齐线样式
   *
   * <en/> Horizontal snapline style
   * @defaultValue `{ stroke: '#1783FF' }`
   */
  horizontalLineStyle?: BaseStyleProps;
  /**
   * <zh/> 过滤器,用于过滤不需要作为参考的节点
   *
   * <en/> Filter, used to filter nodes that do not need to be used as references
   * @defaultValue `() => true`
   */
  filter?: (nodeId: string) => boolean;
}

packages/g6/src/plugins/snapline/index.ts Show resolved Hide resolved
packages/g6/src/plugins/snapline/index.ts Outdated Show resolved Hide resolved
packages/g6/src/plugins/snapline/index.ts Outdated Show resolved Hide resolved
@yvonneyx yvonneyx merged commit ab97b6a into v5 Aug 16, 2024
3 of 5 checks passed
@yvonneyx yvonneyx deleted the plugin-snapline branch August 16, 2024 10:34
@hustcc
Copy link
Member

hustcc commented Aug 28, 2024

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