...
1 package d2target
2
3 import (
4 "fmt"
5 )
6
7 const (
8 PrefixPadding = 10
9 PrefixWidth = 20
10 CenterPadding = 50
11
12 VerticalPadding = 20
13 )
14
15 type Class struct {
16 Fields []ClassField `json:"fields"`
17 Methods []ClassMethod `json:"methods"`
18 }
19
20 type ClassField struct {
21 Name string `json:"name"`
22 Type string `json:"type"`
23 Visibility string `json:"visibility"`
24 }
25
26 func (cf ClassField) Text(fontSize int) *MText {
27 return &MText{
28 Text: fmt.Sprintf("%s%s", cf.Name, cf.Type),
29 FontSize: fontSize,
30 IsBold: false,
31 IsItalic: false,
32 Shape: "class",
33 }
34 }
35
36 func (cf ClassField) VisibilityToken() string {
37 switch cf.Visibility {
38 case "protected":
39 return "#"
40 case "private":
41 return "-"
42 default:
43 return "+"
44 }
45 }
46
47 type ClassMethod struct {
48 Name string `json:"name"`
49 Return string `json:"return"`
50 Visibility string `json:"visibility"`
51 }
52
53 func (cm ClassMethod) Text(fontSize int) *MText {
54 return &MText{
55 Text: fmt.Sprintf("%s%s", cm.Name, cm.Return),
56 FontSize: fontSize,
57 IsBold: false,
58 IsItalic: false,
59 Shape: "class",
60 }
61 }
62
63 func (cm ClassMethod) VisibilityToken() string {
64 switch cm.Visibility {
65 case "protected":
66 return "#"
67 case "private":
68 return "-"
69 default:
70 return "+"
71 }
72 }
73
View as plain text