Ben Lin
2024-06-18 9dfa701454d6a94690bad39dbb0e38f2a0b31489
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
33
34
35
36
37
38
39
40
/*
 * @Description: file content
 * @Author: your name
 * @version: 
 * @Date: 2024-04-30 14:35:47
 * @LastEditors: your name
 * @LastEditTime: 2024-06-15 18:15:59
 */
import { RectNode, RectNodeModel } from '@logicflow/core';
 
class CustomRectNode extends RectNode {}
 
class CustomRectModel extends RectNodeModel {
  override setAttributes() {
    this.width = 120;
    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,
};