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
|
import mxGraphFactory from 'mxgraph'
const {
mxClient,
mxUtils,
mxEvent,
mxDivResizer,
mxWindow,
mxEffects,
mxCodec
} = new mxGraphFactory()
// Added to handle ordering for a few blocks.
window.inBitMap = '0'
window.outBitMap = '0'
export function showModalWindow (graph, title, content, width, height) {
const background = document.createElement('div')
background.style.position = 'absolute'
background.style.left = '0px'
background.style.top = '0px'
background.style.right = '0px'
background.style.bottom = '0px'
background.style.background = 'black'
mxUtils.setOpacity(background, 50)
document.body.appendChild(background)
if (mxClient.IS_IE) {
new mxDivResizer(background)
}
const x = Math.max(0, document.body.scrollWidth / 2 - width / 2)
const y = Math.max(10, (document.body.scrollHeight || document.documentElement.scrollHeight) / 2 - height * 2 / 3)
const wind = new mxWindow(title, content, x, y, width, height, false, true)
wind.setClosable(true)
// Fades the background out after after the window has been closed
wind.addListener(mxEvent.DESTROY, function () {
graph.setEnabled(true)
mxEffects.fadeOut(background, 50, true, 10, 30, true)
})
graph.setEnabled(false)
graph.tooltipHandler.hide()
wind.setVisible(true)
return wind
}
export function updateDetails (graph, cell, details, detailsInstance, styleName, geometryCell, create = false) {
const enc = new mxCodec(mxUtils.createXmlDocument())
const node = enc.encode(details)
const fullStyleName = styleName
if (styleName != null) {
const idx = styleName.indexOf(';')
if (styleName.startsWith('SELF_SWITCH')) {
const stateOpen = detailsInstance.stateOpen
styleName = stateOpen ? 'SELF_SWITCH_OFF' : 'SELF_SWITCH_ON'
} else {
if (idx !== -1) {
styleName = styleName.substring(0, idx)
}
}
}
const stylesheet = graph.getStylesheet()
const style = stylesheet.styles[styleName]
const dimensionForBlock = detailsInstance.getDimensionForDisplay()
let height = dimensionForBlock.height
let width = dimensionForBlock.width
if (geometryCell.height != null && geometryCell.height > 1) {
height = geometryCell.height
}
if (geometryCell.width != null && geometryCell.width > 1) {
width = geometryCell.width
}
/*
* When a particular block is loaded for the first time, the image in the
* style of the block will be a path to the image. Set the label in the
* style property of the block has a html image, and set the image in the
* style property as null
*
* NOTE: Since the image of any block need not be changed for every
* movement of that block, the image must be set only once.
*/
if (style != null && style.image != null) {
// Make label as a image html element
const label = '<img src="' + style.image + '" height="' + (height * 0.9) + '" width="' + (width * 0.9) + '">'
// Set label
style.label = label
style.imagePath = style.image
// Set image as null
style.image = null
// Add the label as a part of node
node.setAttribute('label', label)
}
/*
* If a particular block with image tag in its style property has been
* invoked already, the image tag would be null for any successive
* instances of the same block. Hence, set the label from the label tag in
* style which was set when that blockModel was invoked on the first time.
*/
if (style != null && style.label != null) {
// Set label from the label field in the style property
node.setAttribute('label', style.label)
}
const parent = graph.getDefaultParent()
node.setAttribute('parent', parent.id)
if (create) {
return graph.insertVertex(parent, null, node, geometryCell.x, geometryCell.y, width, height, fullStyleName)
}
cell.setValue(node)
}
// To convert graph points to array which have been converted
// to objects because of dragging the points
export function objToArrayList (graphPoints) {
const tempPoints = []
for (let i = 0; i < graphPoints.length; i++) {
if (graphPoints[i].x) {
tempPoints.push([graphPoints[i].x, graphPoints[i].y])
} else {
tempPoints.push(graphPoints[i])
}
}
return tempPoints
}
// For Sigbuilder block
export function getmethod (mtd) {
let METHOD = ''
switch (mtd) {
case 0: METHOD = 'zero order'; break
case 1: METHOD = 'linear'; break
case 2: METHOD = 'order 2'; break
case 3: METHOD = 'not_a_knot'; break
case 4: METHOD = 'periodic'; break
case 5: METHOD = 'monotone'; break
case 6: METHOD = 'fast'; break
case 7: METHOD = 'clamped'; break
default: METHOD = 'zero order'; break
}
return METHOD
}
|