/
common-accessor.ts
205 lines (174 loc) 路 4.49 KB
/
common-accessor.ts
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import { globals } from '../option'
import { Cell } from '../core/cell'
import { Rectangle, Point } from '../struct'
import { hook } from './decorator'
import { BaseGraph } from './base-graph'
export class CommonAccessor extends BaseGraph {
batchUpdate(update: () => void) {
this.model.batchUpdate(update)
return this
}
getCellGeometry(cell: Cell) {
return this.model.getGeometry(cell)
}
@hook()
getChildOffset(cell: Cell): Point | null {
return null
}
@hook()
getTranslateForCurrentRoot(currentRoot: Cell | null): Point | null {
return null
}
@hook()
isCellLocked(cell: Cell | null) {
if (this.isCellsLocked()) {
return true
}
const style = this.getStyle(cell)
if (style.locked) {
return true
}
const geometry = this.model.getGeometry(cell)
return geometry != null && this.model.isNode(cell) && geometry.relative
}
@hook()
isCellSelectable(cell: Cell) {
return this.isCellsSelectable()
}
@hook()
isCellRotatable(cell: Cell) {
const style = this.getStyle(cell)
return (
this.isCellsRotatable() &&
!this.isCellLocked(cell) &&
style.rotatable !== false
)
}
@hook()
isLabelMovable(cell: Cell | null) {
return (
!this.isCellLocked(cell) &&
((this.model.isEdge(cell) && this.edgeLabelsMovable) ||
(this.model.isNode(cell) && this.nodeLabelsMovable))
)
}
@hook()
isCellBendable(cell: Cell) {
const style = this.getStyle(cell)
return (
this.isCellsBendable() &&
!this.isCellLocked(cell) &&
style.bendable !== false
)
}
@hook()
isTerminalPointMovable(cell: Cell, isSource: boolean) {
return true
}
@hook()
isHtmlLabel(cell: Cell) {
const style = this.getStyle(cell)
if (style != null && style.htmlLabel != null) {
return style.htmlLabel
}
return this.isHtmlLabels()
}
@hook()
isWrapping(cell: Cell) {
const style = this.getStyle(cell)
return style != null ? style.whiteSpace === 'wrap' : false
}
@hook()
isLabelClipped(cell: Cell) {
const style = this.getStyle(cell)
return style != null ? style.overflow === 'hidden' : false
}
@hook()
getHtml(cell: Cell): HTMLElement | string | null {
let result = null
if (cell != null) {
result = cell.style.html
}
return result || null
}
@hook()
getLabel(cell: Cell): HTMLElement | string | null {
let result = null
if (this.labelsVisible && cell != null) {
const style = this.getStyle(cell)
if (style.label !== false && style.label != null) {
result = style.label
}
}
return result
}
@hook()
getCellLink(cell: Cell) {
return null
}
@hook()
getCellCursor(cell: Cell | null) {
return null
}
@hook()
getStartSize(swimlane: Cell | null) {
const result = new Rectangle()
const style = this.getStyle(swimlane)
if (style != null) {
const size = style.startSize || globals.defaultStartSize
if (style.horizontal !== false) {
result.height = size
} else {
result.width = size
}
}
return result
}
@hook()
getCellClassName(cell: Cell) {
const style = this.getStyle(cell)
return style.className || null
}
@hook()
getLabelClassName(cell: Cell) {
const style = this.getStyle(cell)
return style.labelClassName || null
}
/**
* Returns the cells which may be exported in the given array of cells.
*/
getExportableCells(cells: Cell[]) {
return this.model.filterCells(cells, cell => this.canExportCell(cell))
}
canExportCell(cell: Cell) {
return this.isCellsExportable()
}
getImportableCells(cells: Cell[]) {
return this.model.filterCells(cells, cell => this.canImportCell(cell))
}
/**
* Returns true if the given cell may be imported from the clipboard.
*
* Default is `true`.
*/
canImportCell(cell: Cell) {
return this.isCellsImportable()
}
/**
* Returns a decimal number representing the amount of the width and height
* of the given cell that is allowed to overlap its parent. A value of 0
* means all children must stay inside the parent, 1 means the child is
* allowed to be placed outside of the parent such that it touches one of
* the parents sides.
*/
getOverlap(cell: Cell) {
return this.isAllowOverlapParent(cell) ? this.defaultOverlap : 0
}
/**
* Returns true if the given cell is allowed to be placed outside of the
* parents area.
*/
isAllowOverlapParent(cell: Cell) {
return false
}
}