文本属性
属性
文本有以下可用的属性。
| 属性名 | 含义 | 备注 |
|---|---|---|
| fill | 设置用于填充绘画的颜色、渐变或模式 | 对应 canvas 属性 fillStyle |
| stroke | 设置用于笔触的颜色、渐变或模式 | 对应 canvas 属性 strokeStyle |
| shadowColor | 设置用于阴影的颜色 | |
| shadowBlur | 设置用于阴影的模糊级别 | 数值越大,越模糊 |
| shadowOffsetX | 设置阴影距形状的水平距离 | |
| shadowOffsetY | 设置阴影距形状的垂直距离 | |
| opacity | 设置绘图的当前 alpha 或透明值 | 对应 canvas 属性 globalAlpha |
| font | 设置文本内容的当前字体属性 | |
| textAlign | 设置文本内容的当前对齐方式 | 支持的属性:center |
| textBaseline | 设置在绘制文本时使用的当前文本基线 | 支持的属性:top |
| fontStyle | 字体样式 | 对应 font-style |
| fontVariant | 设置为小型大写字母字体 | 对应 font-variant |
| fontWeight | 字体粗细 | 对应 font-weight |
| fontSize | 字体大小 | 对应 font-size |
| fontFamily | 字体系列 | 对应 font-family |
| autoRotate | 是否自动旋转 |
案例
1. const data = {
2. nodes: [
3. {
4. id: 'node1',
5. x: 100,
6. y: 100,
7. shape: 'rect',
8. label: 'rect',
9. },
10. ],
11. };
13. const graph = new G6.Graph({
14. container: 'mountNode',
15. width: 500,
16. height: 500,
17. });
18. graph.data(data);
19. graph.render();
21. const node = graph.findById('node1');
22. graph.update(node, {
23. style: {
24. stroke: 'blue',
25. },
26. labelCfg: {
27. style: {
28. fill: 'red',
29. shadowOffsetX: 10,
30. shadowOffsetY: 10,
31. shadowColor: 'blue',
32. shadowBlur: 10,
33. },
34. },
35. });
通过以上代码修改node中文本的样式,效果如下图:

