-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathTopology.razor.js
More file actions
172 lines (150 loc) · 4.36 KB
/
Topology.razor.js
File metadata and controls
172 lines (150 loc) · 4.36 KB
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
import '../../meta2d.js'
import Data from '../../../BootstrapBlazor/modules/data.js'
export function init(id, options) {
const el = document.getElementById(id)
if (el === null) { return }
const { invoker, data, callback, isFitView, isCenterView } = options;
const initCanvas = () => {
const option = { isFitView, isCenterView }
const meta2d = createMeta2d(id, data, option)
Data.set(id, {
el,
meta2d,
option
})
invoker.invokeMethodAsync(callback);
if (options.isDisableHover) {
meta2d.setOptions({ hoverColor: '', hoverCursor: '', activeColor: '' });
}
if (options.isDisableAnchor) {
meta2d.disableAnchor();
}
}
// make sure el has height
if (el.offsetHeight > 0 && el.offsetWidth > 0) {
initCanvas()
}
else {
const handler = setInterval(() => {
if (el.offsetHeight > 0 && el.offsetWidth > 0) {
clearInterval(handler)
initCanvas()
}
}, 200)
}
}
export function update(id, data) {
const meta = Data.get(id)
if (meta) {
meta.meta2d.doSocket(JSON.stringify(data))
}
}
export function scale(id, rate, options) {
const meta = Data.get(id)
if (meta) {
meta.meta2d.scale(rate)
reset(id, options);
}
}
export function reset(id, options) {
const meta = Data.get(id)
if (meta) {
const meta2d = meta.meta2d;
options = { isFitView: false, isCenterView: false, ...options };
meta.option.isFitView = options.isFitView;
meta.option.isCenterView = options.isCenterView;
if (meta.option.isCenterView) {
meta2d.centerView()
}
if (meta.option.isFitView) {
meta2d.fitView()
}
}
}
export function resize(id, width, height) {
const meta = Data.get(id)
if (meta) {
const meta2d = meta.meta2d
const el = meta.el
const option = meta.option
if (el.offsetHeight > 0 && el.offsetWidth > 0) {
meta2d.canvas.dirty = true
if (width && height) {
meta2d.resize(width, height)
}
else {
meta2d.resize()
}
if (option.isCenterView) {
meta2d.centerView()
}
if (option.isFitView) {
meta2d.fitView()
}
}
}
}
export function dispose(id) {
const meta = Data.get(id)
Data.remove(id)
if (meta) {
meta.meta2d.destroy()
delete meta.meta2d
}
}
const createMeta2d = (id, data, option) => {
const el = document.getElementById(id);
const meta2d = hackMeta2d(el)
meta2d.open(JSON.parse(data))
meta2d.lock(1)
if (option.isFitView) {
meta2d.fitView()
}
if (option.isCenterView) {
meta2d.centerView()
}
el.observer = new ResizeObserver(() => {
resize(id)
})
el.observer.observe(el)
return meta2d
}
const hackMeta2d = el => {
if (Meta2d.isHack === void 0) {
Meta2d.isHack = true
Meta2d.prototype.lock = function (status) {
this.store.data.locked = status
this.finishDrawLine(!0)
this.canvas.drawingLineName = ""
this.stopPencil()
}
Meta2d.prototype.connectSocket = function () {
}
Meta2d.prototype.doSocket = function (data) {
this.socketCallback(data, { type: 'http', url: '' });
}
Meta2d.prototype.disableAnchor = function () {
const pensMap = this.store.pens
Object.keys(pensMap).forEach(key => {
let pen = pensMap[key]
if (pen.type == 1) {
this.setValue({
id: key,
anchors: pen.anchors.map(anchor => ({ ...anchor, radius: 0.0001 }))
}, { render: false })
}
});
this.render()
}
}
const meta2d = new Meta2d(el)
const originalCanvasResize = meta2d.canvas.resize
meta2d.canvas.resize = function () {
const width = this.parentElement.clientWidth
const height = this.parentElement.clientHeight
if (width > 0 && height > 0) {
originalCanvasResize.call(this)
}
}
return meta2d;
}