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

Add Force Mark #4258

Closed
pepper-nice opened this issue Nov 9, 2022 · 2 comments
Closed

Add Force Mark #4258

pepper-nice opened this issue Nov 9, 2022 · 2 comments

Comments

@pepper-nice
Copy link
Contributor

pepper-nice commented Nov 9, 2022

API 设计

import { json } from 'd3-fetch';
import { G2Spec } from '../../../src';
export async function miserableForceCustom(): Promise<G2Spec> {
  const data = await json('data/miserable.json');
  return {
    type: 'force',
    data: {
      value: data,
    },
    layout: {
      // 节点散开/聚合
      disjoint: true,
      // 模拟 node 间的引力
      nodeStrength: (d) => 10,
      // 模拟 link 间的引力
      linkStrength: (d) => 1,
    },
    encode: {
      source: 'source',
      target: 'target',
      // 映射连接线的宽度
      value: 'value',
      // 映射 node 半径
      nodeRadius: (d) => d.radius,
      nodeKey: 'id',
      nodeColor: 'group',
      linkColor: (d) => d.source,
    },
    scale: {},
    style: {},
  };
}

实现思路

力导向图连接线使用 Link Mark 绘制,节点使用 Point Mark 绘制。

const DEFAULT_LINK_OPTIONS = {
  type: 'link',
  encode: {
    x: 'x',
    y: 'y',
    shape: 'link',
  },
};
const DEFAULT_NODE_OPTIONS = {
  type: 'point',
  encode: {
    x: 'x',
    y: 'y',
    shape: 'point',
  },
};
@pearmini
Copy link
Member

pearmini commented Nov 9, 2022

nodeId,改成 nodeKey,在 encode 里面声明,参考 Sankey 的实现。

const options = {
  encode: {
    nodeKey: d => d.key
  }
}

@hustcc
Copy link
Member

hustcc commented Dec 1, 2022

这个是否已经完成了?完成就关闭了哈,然后后续设计讨论放到 discussion~

@hustcc hustcc closed this as completed Dec 1, 2022
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

3 participants