Ben Lin
2024-06-07 aa0bc81d06736cc1a1bd210dde61f57736585d43
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { RectNode, RectNodeModel } from '@logicflow/core';
 
class CustomRectNode extends RectNode {}
 
class CustomRectModel extends RectNodeModel {
  override setAttributes() {
    this.width = 80;
    this.height = 40;
    this.radius = 20;
  }
  override getTextStyle(): LogicFlow.TextNodeTheme {
    const { refX = 0, refY = 0 } = this.properties as CustomProperties;
    const style = super.getTextStyle();
 
    // 通过 transform 重新设置 text 的位置
    return {
      ...style,
      transform: `matrix(1 0 0 1 ${refX} ${refY + 2})`,
    };
  }
  override getNodeStyle() {
    const style = super.getNodeStyle();
    style.stroke = 'blue';
    return style;
  }
}
 
export default {
  type: 'custom-rect',
  view: CustomRectNode,
  model: CustomRectModel,
};