@ejfdelgado/ejflab-common 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +2 -0
- package/package.json +29 -0
- package/src/CollisionsEngine.js +252 -0
- package/src/CsvFormatter.js +54 -0
- package/src/CsvFormatter.test.js +119 -0
- package/src/CsvFormatterFilters.js +79 -0
- package/src/CsvParser.js +51 -0
- package/src/CsvParser.test.js +41 -0
- package/src/CsvWithFilters.js +114 -0
- package/src/FaceEncoder.js +64 -0
- package/src/FlowChartDiagram.js +503 -0
- package/src/IdGen.js +211 -0
- package/src/ModuloDatoSeguro.js +142 -0
- package/src/ModuloDatoSeguro.test.js +29 -0
- package/src/ModuloDatoSeguro.test.mjs +45 -0
- package/src/ModuloDatoSeguroBack.mjs +55 -0
- package/src/ModuloDatoSeguroFront.js +73 -0
- package/src/ModuloSonido.js +83 -0
- package/src/ModuloVideos.js +51 -0
- package/src/MyColor.js +136 -0
- package/src/MyColor.test.js +37 -0
- package/src/MyConstants.js +147 -0
- package/src/MyCookies.js +34 -0
- package/src/MyDates.js +412 -0
- package/src/MyDates.test.js +26 -0
- package/src/MyDatesBack.mjs +21 -0
- package/src/MyDatesFront.js +41 -0
- package/src/MyJsPdf.js +52 -0
- package/src/MyRoutes.js +29 -0
- package/src/MyTemplate.js +272 -0
- package/src/MyTemplate.test.js +90 -0
- package/src/MyTensorflow.js +248 -0
- package/src/MyTensorflow.test.js +19 -0
- package/src/MyTensorflowBack.mjs +33 -0
- package/src/MyThrottle.js +80 -0
- package/src/MyTuples.js +445 -0
- package/src/MyTuples.test.js +330 -0
- package/src/MyUtilities.js +137 -0
- package/src/SimpleObj.js +153 -0
- package/src/SimpleObj.test.js +58 -0
- package/src/TriangulacionGeometric.js +335 -0
- package/src/changePath.js +38 -0
- package/src/data/case0.csv +3 -0
- package/src/data/case0.json +24 -0
- package/src/data/case1.csv +2 -0
- package/src/data/case1.json +24 -0
- package/src/data/case2.csv +3 -0
- package/src/data/case2.json +24 -0
- package/src/data/case3.csv +3 -0
- package/src/data/case3.json +24 -0
- package/src/data/format0.json +0 -0
- package/src/data/format0.txt +1 -0
- package/src/data/tensordata.csv +10 -0
- package/src/data/tensordata.json +37 -0
- package/src/data/tensordata.test.csv +10 -0
- package/src/data/tensormodel.json +113 -0
- package/src/fft.js +224 -0
- package/src/flowchart/FlowChartExec.js +763 -0
- package/src/flowchart/steps/CommandBasic.js +32 -0
- package/src/flowchart/steps/CommandInc.js +19 -0
- package/src/flowchart/steps/CommandMilvus.js +47 -0
- package/src/flowchart/steps/CommandMinio.js +28 -0
- package/src/flowchart/steps/CommandMongo.js +59 -0
- package/src/flowchart/steps/CommandPrint.js +12 -0
- package/src/flowchart/steps/CommandSet.js +14 -0
- package/src/flowchart/steps/CommandTimeline.js +21 -0
- package/src/flowchart/steps/CommandTimelineNext.js +28 -0
- package/src/flowchart/steps/StepBasic.js +184 -0
- package/src/flowchart/steps/StepCheckProcessor.js +26 -0
- package/src/flowchart/steps/StepCheckSrc.js +42 -0
- package/src/flowchart/steps/StepIsTrue.js +12 -0
- package/src/flowchart/steps/StepOneTime.js +21 -0
- package/src/flowchart/steps/StepProcess.js +163 -0
- package/src/flowchart/steps/StepReadSrc.js +66 -0
- package/src/flowchart/steps/StepSleep.js +22 -0
- package/src/flowchart/steps/StepTimeLineEnds.js +21 -0
- package/src/flowchart/steps/StepTimeLineHasMore.js +16 -0
- package/src/gif/index.d.ts +20 -0
- package/src/gif/index.mjs +85 -0
- package/src/gif/utils/checkTypes.d.ts +2 -0
- package/src/gif/utils/checkTypes.mjs +11 -0
- package/src/js-colormaps.js +19484 -0
- package/src/sortify.js +75 -0
- package/src/sqlmodelparser/SqlModelParser.js +22 -0
- package/src/test/csv/test_1000_20230429204538700.csv +1001 -0
- package/src/test/csv/test_5_20230429204525930.csv +6 -0
- package/src/test/svg/test.html +5 -0
|
@@ -0,0 +1,503 @@
|
|
|
1
|
+
const { XMLParser } = require("fast-xml-parser");
|
|
2
|
+
|
|
3
|
+
// For nodes
|
|
4
|
+
const DEFAULT_FONT_COLOR = "#ffffff";
|
|
5
|
+
const DEFAULT_FILL_COLOR = "#555555";
|
|
6
|
+
const DEFAULT_STROKE_COLOR = "#000000";
|
|
7
|
+
const DEFAULT_STROKE_WIDTH = "1";
|
|
8
|
+
const CURRENT_NODE_FILL = "#990000";
|
|
9
|
+
|
|
10
|
+
// For lines
|
|
11
|
+
const PENDING_BORDER_COLOR = "rgb(0,0,0)";
|
|
12
|
+
const PENDING_BORDER_WIDTH = "1";
|
|
13
|
+
|
|
14
|
+
// For nodes and lines
|
|
15
|
+
const DONE_BORDER_COLOR = "rgb(255,0,0)";
|
|
16
|
+
const DONE_BORDER_WIDTH = "3";
|
|
17
|
+
|
|
18
|
+
const computeStyle = function (incomming, done = false, current = false) {
|
|
19
|
+
const base = {
|
|
20
|
+
fillColor: DEFAULT_FILL_COLOR,
|
|
21
|
+
strokeColor: DEFAULT_STROKE_COLOR,
|
|
22
|
+
strokeWidth: DEFAULT_STROKE_WIDTH,
|
|
23
|
+
// for text
|
|
24
|
+
fontColor: DEFAULT_FONT_COLOR,
|
|
25
|
+
};
|
|
26
|
+
Object.assign(base, incomming);
|
|
27
|
+
if (done) {
|
|
28
|
+
//border red
|
|
29
|
+
base.strokeColor = DONE_BORDER_COLOR;
|
|
30
|
+
base.strokeWidth = DONE_BORDER_WIDTH;
|
|
31
|
+
};
|
|
32
|
+
if (current) {
|
|
33
|
+
//border red
|
|
34
|
+
base.strokeColor = DONE_BORDER_COLOR;
|
|
35
|
+
//strokeWidth
|
|
36
|
+
base.strokeWidth = DONE_BORDER_WIDTH;
|
|
37
|
+
base.fillColor = CURRENT_NODE_FILL;
|
|
38
|
+
base.fontColor = DEFAULT_FONT_COLOR;
|
|
39
|
+
}
|
|
40
|
+
const translateShape = {
|
|
41
|
+
"fillColor": "fill",
|
|
42
|
+
"strokeColor": "stroke",
|
|
43
|
+
"strokeWidth": "stroke-width"
|
|
44
|
+
};
|
|
45
|
+
const translateText = {
|
|
46
|
+
fontColor: "fill",
|
|
47
|
+
};
|
|
48
|
+
const computedStyle = {
|
|
49
|
+
shape: [],
|
|
50
|
+
shapeText: '',
|
|
51
|
+
text: {}
|
|
52
|
+
};
|
|
53
|
+
const shapeKeys = Object.keys(translateShape);
|
|
54
|
+
for (let i = 0; i < shapeKeys.length; i++) {
|
|
55
|
+
const shapeKey = shapeKeys[i];
|
|
56
|
+
const shapeTranslated = translateShape[shapeKey];
|
|
57
|
+
computedStyle.shape.push(`${shapeTranslated}:${base[shapeKey]}`);
|
|
58
|
+
}
|
|
59
|
+
computedStyle.shapeText = computedStyle.shape.join(";");
|
|
60
|
+
|
|
61
|
+
// Compute text style
|
|
62
|
+
const textKeys = Object.keys(translateText);
|
|
63
|
+
for (let i = 0; i < textKeys.length; i++) {
|
|
64
|
+
const textKey = textKeys[i];
|
|
65
|
+
const textTranslated = translateText[textKey];
|
|
66
|
+
computedStyle.text[textTranslated] = base[textKey];
|
|
67
|
+
}
|
|
68
|
+
return computedStyle;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
class FlowChartDiagram {
|
|
72
|
+
static searchClosest(srcList, tarList) {
|
|
73
|
+
let closestDistance = null;
|
|
74
|
+
let srcPos = null;
|
|
75
|
+
let tarPos = null;
|
|
76
|
+
for (let i = 0; i < srcList.length; i++) {
|
|
77
|
+
for (let j = 0; j < tarList.length; j++) {
|
|
78
|
+
const srcTmp = srcList[i];
|
|
79
|
+
const tarTmp = tarList[j];
|
|
80
|
+
const distance = Math.sqrt(
|
|
81
|
+
Math.pow(srcTmp.x - tarTmp.x, 2) + Math.pow(srcTmp.y - tarTmp.y, 2)
|
|
82
|
+
);
|
|
83
|
+
if (closestDistance == null || distance < closestDistance) {
|
|
84
|
+
closestDistance = distance;
|
|
85
|
+
srcPos = srcTmp;
|
|
86
|
+
tarPos = tarTmp;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
src: srcPos,
|
|
92
|
+
tar: tarPos,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
// FlowChartDiagram.drawLine(src, tar)
|
|
96
|
+
static drawLine(src, tar, isDone = false) {
|
|
97
|
+
let color = PENDING_BORDER_COLOR;
|
|
98
|
+
let width = PENDING_BORDER_WIDTH;
|
|
99
|
+
if (isDone) {
|
|
100
|
+
color = DONE_BORDER_COLOR;
|
|
101
|
+
width = DONE_BORDER_WIDTH;
|
|
102
|
+
}
|
|
103
|
+
return `<line x1="${src.x}" x2="${tar.x}" y1="${src.y}" y2="${tar.y}" stroke="${color}" stroke-width="${width}" stroke-linecap="round"/>`;
|
|
104
|
+
}
|
|
105
|
+
static isIdInHistory(nodeId, history) {
|
|
106
|
+
if (history instanceof Array) {
|
|
107
|
+
for (let i = 0; i < history.length; i++) {
|
|
108
|
+
const oneHistory = history[i];
|
|
109
|
+
if (oneHistory.id == nodeId) {
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return false;
|
|
115
|
+
};
|
|
116
|
+
static computeGraph(grafo, currentNodes = [], history = []) {
|
|
117
|
+
const lineHeight = 15;
|
|
118
|
+
let svgContent = ' <defs>\
|
|
119
|
+
<filter x="0" y="0" width="1" height="1" id="solid">\
|
|
120
|
+
<feFlood flood-color="white" flood-opacity="0.8" result="bg" />\
|
|
121
|
+
<feMerge>\
|
|
122
|
+
<feMergeNode in="bg"/>\
|
|
123
|
+
<feMergeNode in="SourceGraphic"/>\
|
|
124
|
+
</feMerge>\
|
|
125
|
+
</filter>\
|
|
126
|
+
</defs>';
|
|
127
|
+
const styleTar = 'fill:rgb(0,0,0);stroke-width:1;stroke:rgb(0,0,0)';
|
|
128
|
+
|
|
129
|
+
if (grafo) {
|
|
130
|
+
const shapes = grafo.shapes;
|
|
131
|
+
const arrows = grafo.arrows;
|
|
132
|
+
const centers = {};
|
|
133
|
+
if (shapes instanceof Array) {
|
|
134
|
+
for (let i = 0; i < shapes.length; i++) {
|
|
135
|
+
const shape = shapes[i];
|
|
136
|
+
const id = shape.id;
|
|
137
|
+
const pos = shape.pos;
|
|
138
|
+
centers[id] = [
|
|
139
|
+
{
|
|
140
|
+
x: parseInt(pos.x),
|
|
141
|
+
y: parseInt(pos.y + pos.height * 0.5),
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
x: parseInt(pos.x + pos.width * 0.5),
|
|
145
|
+
y: parseInt(pos.y),
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
x: parseInt(pos.x + pos.width),
|
|
149
|
+
y: parseInt(pos.y + pos.height * 0.5),
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
x: parseInt(pos.x + pos.width * 0.5),
|
|
153
|
+
y: parseInt(pos.y + pos.height),
|
|
154
|
+
},
|
|
155
|
+
];
|
|
156
|
+
}
|
|
157
|
+
// Acá van las líneas
|
|
158
|
+
if (arrows instanceof Array) {
|
|
159
|
+
for (let i = 0; i < arrows.length; i++) {
|
|
160
|
+
const arrow = arrows[i];
|
|
161
|
+
const isDone = FlowChartDiagram.isIdInHistory(arrow.id, history);
|
|
162
|
+
const points = [];
|
|
163
|
+
const srcList = centers[arrow.src];
|
|
164
|
+
const tarList = centers[arrow.tar];
|
|
165
|
+
// Debo buscar la combinación más corta
|
|
166
|
+
let tar;
|
|
167
|
+
let statistics = null;
|
|
168
|
+
if (arrow.points instanceof Array) {
|
|
169
|
+
for (let j = 0; j < arrow.points.length; j++) {
|
|
170
|
+
const punto = arrow.points[j];
|
|
171
|
+
points.push(punto);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const points1 = FlowChartDiagram.searchClosest(srcList, [points[0]]);
|
|
175
|
+
const points2 = FlowChartDiagram.searchClosest([points[points.length - 1]], tarList);
|
|
176
|
+
points.unshift(points1.src);// Al inicio
|
|
177
|
+
points.push(points2.tar);//Al final
|
|
178
|
+
tar = points2.tar;
|
|
179
|
+
} else {
|
|
180
|
+
const points0 = FlowChartDiagram.searchClosest(srcList, tarList);
|
|
181
|
+
points.push(points0.src);
|
|
182
|
+
points.push(points0.tar);
|
|
183
|
+
tar = points0.tar;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// draw all lines...
|
|
187
|
+
for (let j = 0; j < points.length - 1; j++) {
|
|
188
|
+
svgContent += FlowChartDiagram.drawLine(points[j], points[j + 1], isDone);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
//compute position of text
|
|
192
|
+
points.forEach((point) => {
|
|
193
|
+
if (statistics == null) {
|
|
194
|
+
statistics = {
|
|
195
|
+
xmin: point.x,
|
|
196
|
+
ymin: point.y,
|
|
197
|
+
xmax: point.x,
|
|
198
|
+
ymax: point.y,
|
|
199
|
+
};
|
|
200
|
+
} else {
|
|
201
|
+
if (point.x < statistics.xmin) {
|
|
202
|
+
statistics.xmin = point.x;
|
|
203
|
+
}
|
|
204
|
+
if (point.y < statistics.ymin) {
|
|
205
|
+
statistics.ymin = point.y;
|
|
206
|
+
}
|
|
207
|
+
if (point.x > statistics.xmax) {
|
|
208
|
+
statistics.xmax = point.x;
|
|
209
|
+
}
|
|
210
|
+
if (point.y > statistics.ymax) {
|
|
211
|
+
statistics.ymax = point.y;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
//draw end point
|
|
217
|
+
svgContent += `<ellipse cx="${tar.x}" cy="${tar.y}" rx="5" ry="5" style="${styleTar}"></ellipse>`;
|
|
218
|
+
|
|
219
|
+
// Se escribe el texto de la línea
|
|
220
|
+
if (typeof arrow.txt == "string") {
|
|
221
|
+
const lines = arrow.txt.split(/\n/g);
|
|
222
|
+
const pos = {
|
|
223
|
+
x: statistics.xmin,
|
|
224
|
+
y: statistics.ymin,
|
|
225
|
+
width: Math.abs(statistics.xmax - statistics.xmin),
|
|
226
|
+
height: Math.abs(statistics.ymax - statistics.ymin),
|
|
227
|
+
};
|
|
228
|
+
for (let j = 0; j < lines.length; j++) {
|
|
229
|
+
const line = lines[j];
|
|
230
|
+
let xPos, yPos;
|
|
231
|
+
if (points.length <= 2) {
|
|
232
|
+
xPos = pos.x + pos.width * 0.5;
|
|
233
|
+
yPos = pos.y +
|
|
234
|
+
pos.height * 0.5 +
|
|
235
|
+
j * lineHeight -
|
|
236
|
+
(lines.length - 1) * lineHeight * 0.5 +
|
|
237
|
+
lineHeight * 0.25;
|
|
238
|
+
} else {
|
|
239
|
+
// take intermediate point
|
|
240
|
+
const median = Math.floor(points.length * 0.5);
|
|
241
|
+
xPos = parseInt(points[median].x);
|
|
242
|
+
yPos = parseInt(points[median].y) + j * lineHeight -
|
|
243
|
+
(lines.length - 1) * lineHeight * 0.5 +
|
|
244
|
+
lineHeight * 0.25;
|
|
245
|
+
//yPos = points[median].y;
|
|
246
|
+
}
|
|
247
|
+
svgContent += `<text filter="url(#solid)" font-family="Helvetica" font-size="14px" text-anchor="middle" x="${xPos}" y="${yPos}" fill="black">${line}</text>`;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
// Acá van los nodos
|
|
253
|
+
let error = null;
|
|
254
|
+
for (let i = 0; i < shapes.length; i++) {
|
|
255
|
+
const shape = shapes[i];
|
|
256
|
+
const id = shape.id;
|
|
257
|
+
const isDone = FlowChartDiagram.isIdInHistory(id, history);
|
|
258
|
+
const isHiglighted = currentNodes.indexOf(id) >= 0;
|
|
259
|
+
const pos = shape.pos;
|
|
260
|
+
//console.log(this.computeStyle);
|
|
261
|
+
const styledResponse = computeStyle(shape.style, isDone, isHiglighted);
|
|
262
|
+
//console.log(JSON.stringify(styledResponse));
|
|
263
|
+
// Se debe reemplazar el color de fondo y de texto
|
|
264
|
+
|
|
265
|
+
const isRectCorrect = [pos.x, pos.y, pos.width, pos.height].reduce((acum, current) => { return acum && (typeof current == "number"); }, true);
|
|
266
|
+
if (shape.type == 'box') {
|
|
267
|
+
if (isRectCorrect) {
|
|
268
|
+
const tempRect = `<rect rx="5" x="${pos.x}" y="${pos.y}" width="${pos.width}" height="${pos.height}" style="${styledResponse.shapeText}"></rect>`;
|
|
269
|
+
svgContent += tempRect;
|
|
270
|
+
} else {
|
|
271
|
+
error = `${shape.type} with id ${id} is malformed ${JSON.stringify(shape)}`;
|
|
272
|
+
}
|
|
273
|
+
} else if (shape.type == 'ellipse') {
|
|
274
|
+
if (isRectCorrect) {
|
|
275
|
+
svgContent += `<ellipse cx="${pos.x + pos.width * 0.5}" cy="${pos.y + pos.height * 0.5
|
|
276
|
+
}" rx="${pos.width * 0.5}" ry="${pos.height * 0.5
|
|
277
|
+
}" style="${styledResponse.shapeText}"></ellipse>`;
|
|
278
|
+
} else {
|
|
279
|
+
error = `${shape.type} with id ${id} is malformed ${JSON.stringify(shape)}`;
|
|
280
|
+
}
|
|
281
|
+
} else if (shape.type == 'rhombus') {
|
|
282
|
+
if (isRectCorrect) {
|
|
283
|
+
svgContent += `<polygon points="`;
|
|
284
|
+
svgContent += `${pos.x.toFixed(0)},${pos.y + pos.height * 0.5} `;
|
|
285
|
+
svgContent += `${pos.x + pos.width * 0.5},${pos.y.toFixed(0)} `;
|
|
286
|
+
svgContent += `${(pos.x + pos.width).toFixed(0)},${pos.y + pos.height * 0.5
|
|
287
|
+
} `;
|
|
288
|
+
svgContent += `${pos.x + pos.width * 0.5},${(
|
|
289
|
+
pos.y + pos.height
|
|
290
|
+
).toFixed(0)}" `;
|
|
291
|
+
svgContent += `style="${styledResponse.shapeText}"/>`;
|
|
292
|
+
} else {
|
|
293
|
+
error = `${shape.type} with id ${id} is malformed ${JSON.stringify(shape)}`;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
if (typeof shape.txt == 'string') {
|
|
297
|
+
const lines = shape.txt.split(/\n/g);
|
|
298
|
+
for (let j = 0; j < lines.length; j++) {
|
|
299
|
+
const line = lines[j];
|
|
300
|
+
svgContent += `<text font-family="Helvetica" font-size="14px" text-anchor="middle" x="${pos.x + pos.width * 0.5
|
|
301
|
+
}" y="${pos.y +
|
|
302
|
+
pos.height * 0.5 +
|
|
303
|
+
j * lineHeight -
|
|
304
|
+
(lines.length - 1) * lineHeight * 0.5 +
|
|
305
|
+
lineHeight * 0.25
|
|
306
|
+
}" fill="${styledResponse.text.fill}">${line}</text>`;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
if (error != null) {
|
|
311
|
+
alert(error);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return svgContent;
|
|
316
|
+
}
|
|
317
|
+
static parseHTML(text) {
|
|
318
|
+
try {
|
|
319
|
+
let innerText = "";
|
|
320
|
+
const options = {
|
|
321
|
+
ignoreAttributes: true,
|
|
322
|
+
tagValueProcessor: (tagName, value) => {
|
|
323
|
+
//console.log(`tagName = ${tagName} with ${value}`);
|
|
324
|
+
innerText += value;
|
|
325
|
+
if (["span"].indexOf(tagName) >= 0) {
|
|
326
|
+
innerText += "\n";
|
|
327
|
+
} else {
|
|
328
|
+
innerText += " ";
|
|
329
|
+
}
|
|
330
|
+
return "";
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
const parser = new XMLParser(options);
|
|
334
|
+
parser.parse(text);
|
|
335
|
+
if (innerText.trim().length == 0) {
|
|
336
|
+
return text;
|
|
337
|
+
} else {
|
|
338
|
+
// If it really gets some content...
|
|
339
|
+
//
|
|
340
|
+
return innerText.replace(/\n$/g, "");
|
|
341
|
+
}
|
|
342
|
+
} catch (err) {
|
|
343
|
+
return text;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
static computeStyle(style) {
|
|
347
|
+
const response = {
|
|
348
|
+
fontColor: DEFAULT_FONT_COLOR,
|
|
349
|
+
fillColor: DEFAULT_FILL_COLOR,
|
|
350
|
+
strokeColor: DEFAULT_STROKE_COLOR,
|
|
351
|
+
};
|
|
352
|
+
if (typeof style == "string") {
|
|
353
|
+
const tokens = style.split(";");
|
|
354
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
355
|
+
const token = tokens[i];
|
|
356
|
+
const partes = token.split("=");
|
|
357
|
+
if (partes.length >= 2) {
|
|
358
|
+
response[partes[0]] = partes[1];
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
//console.log(`style ${style} to ${JSON.stringify(response)}`);
|
|
363
|
+
return response;
|
|
364
|
+
}
|
|
365
|
+
static processFlowChart(nodos, he = null, prefix = "") {
|
|
366
|
+
const simple = {
|
|
367
|
+
shapes: [],
|
|
368
|
+
arrows: [],
|
|
369
|
+
};
|
|
370
|
+
if (nodos instanceof Array) {
|
|
371
|
+
// Se renombran los ids si es necesario
|
|
372
|
+
if (prefix != "") {
|
|
373
|
+
for (let i = 0; i < nodos.length; i++) {
|
|
374
|
+
const nodo = nodos[i];
|
|
375
|
+
if (nodo['@_id']) {
|
|
376
|
+
nodo['@_id'] = prefix + nodo['@_id'];
|
|
377
|
+
}
|
|
378
|
+
if (nodo['@_source']) {
|
|
379
|
+
nodo['@_source'] = prefix + nodo['@_source'];
|
|
380
|
+
}
|
|
381
|
+
if (nodo['@_target']) {
|
|
382
|
+
nodo['@_target'] = prefix + nodo['@_target'];
|
|
383
|
+
}
|
|
384
|
+
if (nodo['@_parent']) {
|
|
385
|
+
nodo['@_parent'] = prefix + nodo['@_parent'];
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
// Se preprocesan las flechas
|
|
390
|
+
const mapaFlechas = {};
|
|
391
|
+
for (let i = 0; i < nodos.length; i++) {
|
|
392
|
+
const nodo = nodos[i];
|
|
393
|
+
const id = nodo['@_id'];
|
|
394
|
+
const source = nodo['@_source'];
|
|
395
|
+
const target = nodo['@_target'];
|
|
396
|
+
if (source && target) {
|
|
397
|
+
mapaFlechas[id] = { original: nodo };
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
// Se procesan los nodos y flechas
|
|
401
|
+
for (let i = 0; i < nodos.length; i++) {
|
|
402
|
+
const nodo = nodos[i];
|
|
403
|
+
const id = nodo['@_id'];
|
|
404
|
+
const source = nodo['@_source'];
|
|
405
|
+
const parentId = nodo['@_parent'];
|
|
406
|
+
const parentArrow = mapaFlechas[parentId];
|
|
407
|
+
const target = nodo['@_target'];
|
|
408
|
+
const txt = nodo["@_value"];
|
|
409
|
+
let texto = '';
|
|
410
|
+
if (typeof txt == "string") {
|
|
411
|
+
texto = this.parseHTML(txt);
|
|
412
|
+
if (he != null) {
|
|
413
|
+
texto = he.decode(texto);
|
|
414
|
+
}
|
|
415
|
+
//texto = texto.replace(/ /g, " ");
|
|
416
|
+
texto = texto.replace(/<\/?br\/?>/ig, '\n');
|
|
417
|
+
}
|
|
418
|
+
const style = nodo['@_style'];
|
|
419
|
+
const computedStyle = this.computeStyle(style);
|
|
420
|
+
const details = nodo['mxGeometry'];
|
|
421
|
+
if (source && target) {
|
|
422
|
+
// Es una flecha
|
|
423
|
+
const nuevaFlecha = {
|
|
424
|
+
src: source,
|
|
425
|
+
tar: target,
|
|
426
|
+
txt: texto,
|
|
427
|
+
id,
|
|
428
|
+
prefix,
|
|
429
|
+
};
|
|
430
|
+
// Se valida si tiene puntos intermedios
|
|
431
|
+
if (details?.Array?.mxPoint instanceof Array) {
|
|
432
|
+
nuevaFlecha.points = details?.Array?.mxPoint.map((point) => {
|
|
433
|
+
return {
|
|
434
|
+
x: point["@_x"],
|
|
435
|
+
y: point["@_y"],
|
|
436
|
+
};
|
|
437
|
+
});
|
|
438
|
+
} else if (details?.Array?.mxPoint) {
|
|
439
|
+
const mxPoint = details?.Array?.mxPoint;
|
|
440
|
+
nuevaFlecha.points = [{
|
|
441
|
+
x: mxPoint["@_x"],
|
|
442
|
+
y: mxPoint["@_y"],
|
|
443
|
+
}];
|
|
444
|
+
}
|
|
445
|
+
mapaFlechas[id].ref = nuevaFlecha;
|
|
446
|
+
simple.arrows.push(nuevaFlecha);
|
|
447
|
+
} else {
|
|
448
|
+
if (parentArrow) {
|
|
449
|
+
// Save text in the parent
|
|
450
|
+
parentArrow.txt = texto;
|
|
451
|
+
continue;
|
|
452
|
+
}
|
|
453
|
+
let shapeType = 'box';
|
|
454
|
+
if (style) {
|
|
455
|
+
if (style.startsWith('ellipse')) {
|
|
456
|
+
shapeType = 'ellipse';
|
|
457
|
+
} else if (style.startsWith('rhombus')) {
|
|
458
|
+
shapeType = 'rhombus';
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
// read coordinates
|
|
462
|
+
if (details) {
|
|
463
|
+
const pos = {
|
|
464
|
+
width: parseInt(details['@_width']),
|
|
465
|
+
height: parseInt(details['@_height']),
|
|
466
|
+
x: parseInt(details['@_x']),
|
|
467
|
+
y: parseInt(details['@_y']),
|
|
468
|
+
};
|
|
469
|
+
simple.shapes.push({
|
|
470
|
+
id,
|
|
471
|
+
pos,
|
|
472
|
+
txt: texto,
|
|
473
|
+
type: shapeType,
|
|
474
|
+
style: computedStyle,
|
|
475
|
+
prefix
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
// Se escriben los textos que quedaron faltando
|
|
481
|
+
const llavesFlechas = Object.keys(mapaFlechas);
|
|
482
|
+
for (let i = 0; i < llavesFlechas.length; i++) {
|
|
483
|
+
const llave = llavesFlechas[i];
|
|
484
|
+
const flecha = mapaFlechas[llave];
|
|
485
|
+
if (flecha.ref.txt == "") {
|
|
486
|
+
let temp = flecha.txt;
|
|
487
|
+
if (typeof temp == "string") {
|
|
488
|
+
if (he != null) {
|
|
489
|
+
temp = he.decode(temp);
|
|
490
|
+
}
|
|
491
|
+
temp = temp.replace(/<\/?br\/?>/ig, '\n');
|
|
492
|
+
}
|
|
493
|
+
flecha.ref.txt = temp;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
return simple;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
module.exports = {
|
|
502
|
+
FlowChartDiagram
|
|
503
|
+
};
|