-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 a data transform for mapping node size #6347
Conversation
yvonneyx
commented
Sep 18, 2024
- 新增基于节点重要性动态调整节点大小的能力
- 内置五种方式来衡量节点的重要性:度中心性、中介中心性、接近中心性、特征向量中心性、pagerank 中心性
- 拿到节点重要性后通过用户自定义节点大小与插值函数来进行映射,内置了线性、对数、幂律和平方根
也就是说,下个版本可以根据 label 内容的长度自动计算 node 的宽度了吗 |
“根据 label 内容的长度自动计算 node 的宽度” 能力 G6 目前不考虑内置,实现起来也比较简单,可以参考: const measureTextWidth = memoize(
(text: string, font: any = {}): TextMetrics => {
const { fontSize, fontFamily = 'sans-serif', fontWeight, fontStyle, fontVariant } = font;
const ctx = getCanvasContext();
// @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/font
ctx.font = [fontStyle, fontWeight, fontVariant, `${fontSize}px`, fontFamily].join(' ');
return ctx.measureText(isString(text) ? text : '').width;
},
(text: string, font = {}) => [text, ...values(font)].join(''),
);
const graph = new G6.Graph({
node: {
style: { size: d => [measureTextWidth(d.label, {...}) , xxx] },
}
}) |
明白了,感谢。 |
@@ -87,11 +88,11 @@ | |||
"limit-size": [ | |||
{ | |||
"gzip": true, | |||
"limit": "300 Kb", | |||
"limit": "310 Kb", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个得关注下具体是哪部分增长了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
多导出了 MapNodeSize 和 MapNodeSizeOptions
5b6d941
to
680ef04
Compare