aframe-babia-components 1.3.0 → 1.3.3
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/components/visualizers/babia-boats.js +375 -212
- package/dist/aframe-babia-components.js +6585 -6200
- package/dist/aframe-babia-components.min.js +1 -1
- package/dist/aframe-babia-components.min.js.LICENSE.txt +1 -1
- package/dist/aframe-babia-components.min.js.map +1 -1
- package/docs/APIs/CHARTS.md +3 -1
- package/docs/RELEASE_NOTES.md +12 -0
- package/docs/Tutorials/HOW_TO_USE_BABIA_MAP.md +1 -1
- package/examples/boats/boats2/data_simple.json +377 -0
- package/examples/boats/boats2/index.html +2 -2
- package/examples/boats/boats_city/index.html +1 -1
- package/examples/boats/boats_city_plan_view/index.html +1 -1
- package/examples/boats/boats_dependency/experiment.html +2 -2
- package/examples/boats/boats_dependency/index.html +2 -2
- package/examples/boats/boats_dependency/index_gradient.html +1 -1
- package/examples/boats/boats_dependency/index_normalcity.html +1 -1
- package/examples/boats/boats_dependency/index_quarter_levels_01.html +1 -1
- package/examples/boats/boats_dependency/index_quarter_levels_02.html +1 -1
- package/examples/boats/boats_dependency/index_quarter_levels_03.html +1 -1
- package/examples/boats/boats_dependency/index_quarter_levels_querystring.html +2 -2
- package/examples/boats/boats_dependency/index_tree.html +1 -1
- package/examples/boats/boats_dependency/index_tree_gradient.html +1 -1
- package/examples/boats/boats_dependency/index_tree_wireframe.html +2 -2
- package/examples/boats/boats_diagonal/diagonal.json +5 -0
- package/examples/boats/boats_diagonal/index.html +53 -0
- package/examples/boats/boats_quarter_resize2/index.html +1 -1
- package/examples/boats/jetuml_evol/index.html +34 -34
- package/examples/publications/elevated/index.html +2 -6
- package/examples/ui/boats_treegenerator/index.html +1 -1
- package/examples/ui/ui_treegenerator/index.html +1 -1
- package/package.json +1 -1
- package/webpack.dev.js +2 -1
- package/webpack.devall.js +3 -0
- package/webpack.devnossl.js +3 -0
|
@@ -31,7 +31,7 @@ AFRAME.registerComponent('babia-boats', {
|
|
|
31
31
|
// highest and lowest value)
|
|
32
32
|
diffBuildingHeight: { type: 'boolean', default: false },
|
|
33
33
|
zone_elevation: { type: 'number', default: 0.01 },
|
|
34
|
-
|
|
34
|
+
separation: { type: 'number', default: 0.1 },
|
|
35
35
|
extra: { type: 'number', default: 1.0 },
|
|
36
36
|
levels: { type: 'number' },
|
|
37
37
|
building_color: { type: 'string', default: "#E6B9A1" },
|
|
@@ -45,6 +45,7 @@ AFRAME.registerComponent('babia-boats', {
|
|
|
45
45
|
height_building_legend: { type: 'number', default: 0 },
|
|
46
46
|
legend_scale: { type: 'number', default: 1 },
|
|
47
47
|
legend_lookat: { type: 'string', default: "[camera]" },
|
|
48
|
+
legend_text: { type: 'string', default: '{name}\n{fheight} (height): {height}\n{farea} (area): {area}\n{fwidth} (width): {width}\n{fdepth} (depth): {depth}\n{fcolor} (color): {color}' },
|
|
48
49
|
legendsAsChildren: { type: 'boolean', default: false },
|
|
49
50
|
legendsAsChildrenHeight: { type: 'number', default: 3 },
|
|
50
51
|
metricsInfoId: { type: 'string', default: "" },
|
|
@@ -187,7 +188,16 @@ AFRAME.registerComponent('babia-boats', {
|
|
|
187
188
|
|
|
188
189
|
if (figure.children) {
|
|
189
190
|
// Quarter
|
|
190
|
-
entity.legend = generateLegend(
|
|
191
|
+
entity.legend = generateLegend(entity.babiaRawData || {}, {
|
|
192
|
+
name: figure.name,
|
|
193
|
+
scale: self.data.legend_scale,
|
|
194
|
+
lookat: self.data.legend_lookat,
|
|
195
|
+
template: self.data.legend_text || '{name}',
|
|
196
|
+
colorPlane: 'black',
|
|
197
|
+
colorText: 'white',
|
|
198
|
+
isQuarter: true,
|
|
199
|
+
fields: {}
|
|
200
|
+
});
|
|
191
201
|
let worldPos = new THREE.Vector3();
|
|
192
202
|
let coordinates = worldPos.setFromMatrixPosition(entity.object3D.matrixWorld);
|
|
193
203
|
let coordinatesFinal = {
|
|
@@ -212,7 +222,22 @@ AFRAME.registerComponent('babia-boats', {
|
|
|
212
222
|
entity.alreadyActive = true
|
|
213
223
|
} else {
|
|
214
224
|
// Building
|
|
215
|
-
entity.legend =
|
|
225
|
+
entity.legend = entity.legend = generateLegend(entity.babiaRawData, {
|
|
226
|
+
name: figure.name,
|
|
227
|
+
scale: self.data.legend_scale,
|
|
228
|
+
lookat: self.data.legend_lookat,
|
|
229
|
+
template: self.data.legend_text,
|
|
230
|
+
colorPlane: 'white',
|
|
231
|
+
colorText: 'black',
|
|
232
|
+
isQuarter: false,
|
|
233
|
+
fields: {
|
|
234
|
+
height: self.data.height,
|
|
235
|
+
area: self.data.area,
|
|
236
|
+
width: self.data.width,
|
|
237
|
+
depth: self.data.depth,
|
|
238
|
+
color: self.data.color,
|
|
239
|
+
}
|
|
240
|
+
});
|
|
216
241
|
let worldPos = new THREE.Vector3();
|
|
217
242
|
let coordinates = worldPos.setFromMatrixPosition(entity.object3D.matrixWorld);
|
|
218
243
|
let height_real = new THREE.Box3().setFromObject(entity.object3D)
|
|
@@ -326,27 +351,29 @@ AFRAME.registerComponent('babia-boats', {
|
|
|
326
351
|
*/
|
|
327
352
|
generateElements: function (elements, figures, translate, inc) {
|
|
328
353
|
const self = this;
|
|
354
|
+
const data = this.data;
|
|
355
|
+
|
|
329
356
|
var increment = inc;
|
|
330
357
|
|
|
331
|
-
// Vertical
|
|
358
|
+
// Vertical limits (of all figures up to now)
|
|
332
359
|
var limit_up = 0;
|
|
333
360
|
var limit_down = 0;
|
|
334
|
-
// Horizontal
|
|
361
|
+
// Horizontal limits (of all figures up to now)
|
|
335
362
|
var limit_right = 0;
|
|
336
363
|
var limit_left = 0;
|
|
337
364
|
|
|
338
|
-
//Position
|
|
365
|
+
//Position of the center of current figure
|
|
339
366
|
var posX = 0;
|
|
340
367
|
var posY = 0;
|
|
341
368
|
|
|
342
|
-
// Aux to update
|
|
343
|
-
// Save max
|
|
369
|
+
// Aux variables to update limits
|
|
370
|
+
// Save max limits to update limits in the next step
|
|
344
371
|
var max_right = 0;
|
|
345
372
|
var max_left = 0;
|
|
346
373
|
var max_down = 0;
|
|
347
374
|
var max_up = 0;
|
|
348
375
|
|
|
349
|
-
//
|
|
376
|
+
// Control points
|
|
350
377
|
var current_vertical = 0;
|
|
351
378
|
var current_horizontal = 0;
|
|
352
379
|
|
|
@@ -363,31 +390,31 @@ AFRAME.registerComponent('babia-boats', {
|
|
|
363
390
|
for (let i = 0; i < elements.length; i++) {
|
|
364
391
|
// To do not overwrite newData
|
|
365
392
|
let element = {}
|
|
366
|
-
if (
|
|
367
|
-
element.width = elements[i][
|
|
368
|
-
}
|
|
369
|
-
if (
|
|
393
|
+
if (data.width) {
|
|
394
|
+
element.width = elements[i][data.width] || 0.5
|
|
395
|
+
};
|
|
396
|
+
if (data.depth) {
|
|
397
|
+
element.depth = elements[i][data.depth] || 0.5
|
|
398
|
+
};
|
|
399
|
+
if (data.height) {
|
|
370
400
|
let height_min = 0;
|
|
371
|
-
if (
|
|
401
|
+
if (data.diffBuildingHeight) {
|
|
372
402
|
height_min = self.babiaMetadata['heightMin'];
|
|
373
403
|
};
|
|
374
404
|
element.height = self.normalizeValues(height_min,
|
|
375
405
|
self.babiaMetadata['heightMax'],
|
|
376
406
|
self.data.minBuildingHeight,
|
|
377
407
|
self.data.maxBuildingHeight,
|
|
378
|
-
elements[i][
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
element.
|
|
383
|
-
}
|
|
384
|
-
if (this.data.area) {
|
|
385
|
-
element.area = elements[i][this.data.area] || 0.5
|
|
408
|
+
elements[i][data.height]) || data.minBuildingHeight
|
|
409
|
+
};
|
|
410
|
+
if (data.area) {
|
|
411
|
+
element.area = elements[i][data.area] || 0.5;
|
|
412
|
+
element.width = element.depth = Math.sqrt(element.area);
|
|
386
413
|
}
|
|
387
414
|
if (elements[i].children) {
|
|
388
415
|
// There are elements hanging from this element
|
|
416
|
+
// so, it is a quarter. Let's run this function recursively
|
|
389
417
|
element.children = elements[i].children
|
|
390
|
-
this.quarter = true;
|
|
391
418
|
var children = [];
|
|
392
419
|
var translate_matrix;
|
|
393
420
|
// Save Zone's parameters
|
|
@@ -396,27 +423,28 @@ AFRAME.registerComponent('babia-boats', {
|
|
|
396
423
|
if (!scale) {
|
|
397
424
|
scale = { x: 1, y: 1, z: 1 }
|
|
398
425
|
}
|
|
399
|
-
element.height =
|
|
400
|
-
increment -=
|
|
426
|
+
element.height = data.zone_elevation / scale.y;
|
|
427
|
+
increment -= data.border * data.extra;
|
|
401
428
|
|
|
402
|
-
//
|
|
403
|
-
if (
|
|
429
|
+
// Tree layout
|
|
430
|
+
if (data.treeLayout) {
|
|
404
431
|
element.children.forEach(el => {
|
|
405
432
|
if (!el.children) {
|
|
406
|
-
element.treeMetaphorHeight = el[
|
|
433
|
+
element.treeMetaphorHeight = el[data.height]
|
|
407
434
|
return
|
|
408
435
|
}
|
|
409
436
|
});
|
|
410
437
|
}
|
|
411
438
|
|
|
412
439
|
[element.width, element.depth, translate_matrix, children]
|
|
413
|
-
= this.generateElements(element.children, children,
|
|
440
|
+
= this.generateElements(element.children, children,
|
|
441
|
+
translate_matrix, increment);
|
|
414
442
|
translate_matrix.y = element.height;
|
|
415
443
|
increment = inc;
|
|
416
|
-
}
|
|
444
|
+
};
|
|
417
445
|
if (i == 0) {
|
|
418
446
|
// This is the first element to place
|
|
419
|
-
if (
|
|
447
|
+
if (data.area && !elements[i].children) {
|
|
420
448
|
limit_up += Math.sqrt(element.area) / 2;
|
|
421
449
|
limit_down -= Math.sqrt(element.area) / 2;
|
|
422
450
|
limit_right += Math.sqrt(element.area) / 2;
|
|
@@ -428,55 +456,69 @@ AFRAME.registerComponent('babia-boats', {
|
|
|
428
456
|
limit_left -= element.width / 2;
|
|
429
457
|
}
|
|
430
458
|
//console.log("==== RIGHT SIDE ====");
|
|
431
|
-
current_horizontal = limit_up
|
|
459
|
+
current_horizontal = limit_up
|
|
432
460
|
} else if (element.height > 0) {
|
|
461
|
+
console.log("Element: ", i);
|
|
462
|
+
console.log("Directions (up, right, down, left):",
|
|
463
|
+
up, right, down, left);
|
|
464
|
+
console.log("Current (vertical, horizontal):",
|
|
465
|
+
current_vertical, current_horizontal);
|
|
466
|
+
console.log("Limits (up, right, down, left):",
|
|
467
|
+
limit_up, limit_right, limit_down, limit_left);
|
|
468
|
+
console.log("Max (up, right, down, left):",
|
|
469
|
+
max_up, max_right, max_down, max_left);
|
|
470
|
+
console.log("Position (x, y):", posX, posY);
|
|
433
471
|
if (up) {
|
|
434
|
-
[current_vertical, posX, posY, max_up] =
|
|
472
|
+
[current_vertical, posX, posY, max_up] =
|
|
473
|
+
this.UpSide(element, limit_up, current_vertical, max_up);
|
|
435
474
|
if (current_vertical > limit_right) {
|
|
436
|
-
current_vertical += this.data.building_separation / 2;
|
|
437
475
|
max_right = current_vertical;
|
|
438
476
|
up = false;
|
|
439
477
|
right = true;
|
|
440
478
|
if (max_left < limit_left) {
|
|
441
479
|
limit_left = max_left;
|
|
442
480
|
}
|
|
443
|
-
current_horizontal = limit_up
|
|
481
|
+
current_horizontal = limit_up;
|
|
444
482
|
}
|
|
445
483
|
} else if (right) {
|
|
446
|
-
[current_horizontal, posX, posY, max_right] =
|
|
484
|
+
[current_horizontal, posX, posY, max_right] =
|
|
485
|
+
this.RightSide(element, limit_right, current_horizontal, max_right);
|
|
486
|
+
console.log("RIGHT", current_horizontal, posX, posY, max_right);
|
|
447
487
|
if (current_horizontal < limit_down) {
|
|
448
|
-
current_horizontal += this.data.building_separation / 2;
|
|
449
488
|
max_down = current_horizontal;
|
|
450
489
|
right = false;
|
|
451
490
|
down = true;
|
|
452
491
|
if (max_up > limit_up) {
|
|
453
492
|
limit_up = max_up;
|
|
454
493
|
}
|
|
455
|
-
current_vertical = limit_right
|
|
494
|
+
current_vertical = limit_right;
|
|
456
495
|
}
|
|
496
|
+
console.log("RIGHT2",
|
|
497
|
+
current_horizontal, current_vertical, posX, posY, max_right);
|
|
457
498
|
} else if (down) {
|
|
499
|
+
console.log("DOWN1 (element, limit_down, current_vertical, max_down):",
|
|
500
|
+
element, limit_down, current_vertical, max_down);
|
|
458
501
|
[current_vertical, posX, posY, max_down] = this.DownSide(element, limit_down, current_vertical, max_down);
|
|
502
|
+
console.log("DOWN2", current_vertical, posX, posY, max_down);
|
|
459
503
|
if (current_vertical < limit_left) {
|
|
460
|
-
current_vertical -= this.data.building_separation / 2;
|
|
461
504
|
max_left = current_vertical;
|
|
462
505
|
down = false;
|
|
463
506
|
left = true;
|
|
464
507
|
if (max_right > limit_right) {
|
|
465
508
|
limit_right = max_right;
|
|
466
509
|
}
|
|
467
|
-
current_horizontal = limit_down
|
|
510
|
+
current_horizontal = limit_down;
|
|
468
511
|
}
|
|
469
512
|
} else if (left) {
|
|
470
513
|
[current_horizontal, posX, posY, max_left] = this.LeftSide(element, limit_left, current_horizontal, max_left);
|
|
471
514
|
if (current_horizontal > limit_up) {
|
|
472
|
-
current_horizontal -= this.data.building_separation / 2;
|
|
473
515
|
max_up = current_horizontal;
|
|
474
516
|
left = false;
|
|
475
517
|
up = true;
|
|
476
518
|
if (max_down < limit_down) {
|
|
477
519
|
limit_down = max_down;
|
|
478
520
|
}
|
|
479
|
-
current_vertical = limit_left
|
|
521
|
+
current_vertical = limit_left;
|
|
480
522
|
}
|
|
481
523
|
}
|
|
482
524
|
}
|
|
@@ -485,7 +527,7 @@ AFRAME.registerComponent('babia-boats', {
|
|
|
485
527
|
// First, fill in common properties, then add those specific for
|
|
486
528
|
// bases or buildings
|
|
487
529
|
let figure = {
|
|
488
|
-
id: "boat-" + elements[i][
|
|
530
|
+
id: "boat-" + elements[i][data.field],
|
|
489
531
|
posX: posX,
|
|
490
532
|
posY: posY,
|
|
491
533
|
height: element.height,
|
|
@@ -495,49 +537,37 @@ AFRAME.registerComponent('babia-boats', {
|
|
|
495
537
|
if (elements[i].children) {
|
|
496
538
|
// This is the base for a quarter
|
|
497
539
|
figure.name = elements[i][this.data.field] || '',
|
|
498
|
-
figure.width = element.width,
|
|
499
|
-
figure.depth = element.depth,
|
|
540
|
+
figure.width = element.width - this.data.separation,
|
|
541
|
+
figure.depth = element.depth - this.data.separation,
|
|
500
542
|
figure.children = children,
|
|
501
543
|
figure.alpha = self.data.baseAlpha,
|
|
502
544
|
figure.translate_matrix = translate_matrix
|
|
503
|
-
//
|
|
504
|
-
if (
|
|
505
|
-
figure.treeMetaphorHeight = element.treeMetaphorHeight
|
|
545
|
+
// Tree layout
|
|
546
|
+
if (data.treeLayout) {
|
|
547
|
+
figure.treeMetaphorHeight = element.treeMetaphorHeight;
|
|
506
548
|
}
|
|
549
|
+
// Hierarchy level
|
|
550
|
+
let hierarchyLevel = figure.name.split("/").length - 1;
|
|
551
|
+
figure.hierarchyLevel = hierarchyLevel;
|
|
552
|
+
figure.renderOrder = hierarchyLevel;
|
|
507
553
|
// Gradient color
|
|
508
|
-
|
|
509
|
-
figure.hierarchyLevel = hierarchyLevel
|
|
510
|
-
figure.renderOrder = hierarchyLevel
|
|
511
|
-
if (self.data.gradientBaseColor) {
|
|
512
|
-
figure.color = greenColorsurface(Math.round(
|
|
513
|
-
self.normalizeValues(1,
|
|
514
|
-
self.babiaMetadata['maxLevels'],
|
|
515
|
-
15,
|
|
516
|
-
100,
|
|
517
|
-
hierarchyLevel)
|
|
518
|
-
));
|
|
519
|
-
} else {
|
|
520
|
-
figure.color = self.data.base_color;
|
|
521
|
-
}
|
|
554
|
+
figure.color = self.getColorBase(hierarchyLevel);
|
|
522
555
|
} else {
|
|
523
556
|
// This is a building
|
|
524
557
|
figure.name = (elements[i].name) ? elements[i].name : elements[i][this.data.field],
|
|
525
558
|
figure.alpha = self.data.buildingAlpha
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
figure.
|
|
531
|
-
|
|
532
|
-
}
|
|
533
|
-
if (typeof elements[i][self.data.color] === 'number') {
|
|
534
|
-
figure.color = heatMapColorforValue(elements[i][self.data.color], self.babiaMetadata['color_max'], self.babiaMetadata['color_min'])
|
|
535
|
-
} else if (typeof elements[i][self.data.color] === 'string') {
|
|
559
|
+
figure.width = element.width - data.separation;
|
|
560
|
+
figure.depth = element.depth - data.separation;
|
|
561
|
+
|
|
562
|
+
if (typeof elements[i][data.color] === 'number') {
|
|
563
|
+
figure.color = heatMapColorforValue(elements[i][data.color],
|
|
564
|
+
self.babiaMetadata['color_max'], self.babiaMetadata['color_min'])
|
|
565
|
+
} else if (typeof elements[i][data.color] === 'string') {
|
|
536
566
|
// Categoric color
|
|
537
|
-
if (elements[i][
|
|
538
|
-
figure.color = self.categoricColorMaps[elements[i][
|
|
567
|
+
if (elements[i][data.color] in self.categoricColorMaps) {
|
|
568
|
+
figure.color = self.categoricColorMaps[elements[i][data.color]]
|
|
539
569
|
} else {
|
|
540
|
-
self.categoricColorMaps[elements[i][
|
|
570
|
+
self.categoricColorMaps[elements[i][data.color]] = colorsArray[self.categoricColorIndex]
|
|
541
571
|
figure.color = colorsArray[self.categoricColorIndex]
|
|
542
572
|
|
|
543
573
|
self.categoricColorIndex = self.categoricColorIndex + 1
|
|
@@ -547,37 +577,12 @@ AFRAME.registerComponent('babia-boats', {
|
|
|
547
577
|
}
|
|
548
578
|
}
|
|
549
579
|
|
|
550
|
-
|
|
551
|
-
|
|
552
580
|
}
|
|
553
581
|
figure.rawData = elements[i]
|
|
554
582
|
|
|
555
|
-
//
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
figure.alpha = 0.8
|
|
559
|
-
figure.renderOrder = 2000
|
|
560
|
-
} else {
|
|
561
|
-
self.idsToNotRepeat80Transparent.push(figure.rawData[self.data.transparent80ByRepeatedField])
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
// Put transparent 20% to those buildings that share same value for a field selected
|
|
565
|
-
if (self.data.transparent20ByRepeatedField && (!figure.children && self.idsToNotRepeat20Transparent.includes(figure.rawData[self.data.transparent20ByRepeatedField]))) {
|
|
566
|
-
figure.alpha = 0.45
|
|
567
|
-
figure.renderOrder = 2000
|
|
568
|
-
} else {
|
|
569
|
-
self.idsToNotRepeat20Transparent.push(figure.rawData[self.data.transparent20ByRepeatedField])
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
// Put wireframe to those buildings that share same value for a field selected
|
|
573
|
-
if (self.data.wireframeByRepeatedField && (!figure.children && self.idsToNotRepeatWireframe.includes(figure.rawData[self.data.wireframeByRepeatedField]))) {
|
|
574
|
-
figure.wireframe = true
|
|
575
|
-
} else {
|
|
576
|
-
figure.wireframe = false
|
|
577
|
-
self.idsToNotRepeatWireframe.push(figure.rawData[self.data.wireframeByRepeatedField])
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
|
|
583
|
+
// Set transparency and wireframe, if appropriate
|
|
584
|
+
self.setTransparency(figure);
|
|
585
|
+
figure.wireframe = this.getWireframe(figure, data.wireframeByRepeatedField);
|
|
581
586
|
|
|
582
587
|
figures.push(figure);
|
|
583
588
|
}
|
|
@@ -596,20 +601,7 @@ AFRAME.registerComponent('babia-boats', {
|
|
|
596
601
|
limit_right = max_right;
|
|
597
602
|
}
|
|
598
603
|
|
|
599
|
-
|
|
600
|
-
limit_left = current_vertical + this.data.building_separation / 2;
|
|
601
|
-
}
|
|
602
|
-
if (current_vertical > limit_right) {
|
|
603
|
-
limit_right = current_vertical - this.data.building_separation / 2;;
|
|
604
|
-
}
|
|
605
|
-
if (current_horizontal > limit_up) {
|
|
606
|
-
limit_up = current_horizontal - this.data.building_separation / 2;;
|
|
607
|
-
}
|
|
608
|
-
if (current_horizontal < limit_down) {
|
|
609
|
-
limit_down = current_horizontal + this.data.building_separation / 2;;
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
// Calculate translate of the center, width and depth of the zone
|
|
604
|
+
// Calculate translation of the center, width and depth of the zone
|
|
613
605
|
var width = Math.abs(limit_left) + Math.abs(limit_right);
|
|
614
606
|
var depth = Math.abs(limit_down) + Math.abs(limit_up);
|
|
615
607
|
|
|
@@ -646,9 +638,9 @@ AFRAME.registerComponent('babia-boats', {
|
|
|
646
638
|
z: -y + translate.z
|
|
647
639
|
}
|
|
648
640
|
|
|
649
|
-
//
|
|
641
|
+
// Tree layout
|
|
650
642
|
if (self.data.treeLayout) {
|
|
651
|
-
//
|
|
643
|
+
// Hide quarters with no children
|
|
652
644
|
if (self.data.treeHideOneSonQuarters && (figures[i].children && figures[i].children.length === 1)) {
|
|
653
645
|
figures[i].alphaTest = 1
|
|
654
646
|
figures[i].dontAddEvents = true
|
|
@@ -705,31 +697,29 @@ AFRAME.registerComponent('babia-boats', {
|
|
|
705
697
|
let entity = this.createElement(figures[i], position);
|
|
706
698
|
this.addEvents(entity, figures[i]);
|
|
707
699
|
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
700
|
element.appendChild(entity);
|
|
712
701
|
}
|
|
713
702
|
|
|
714
703
|
},
|
|
715
704
|
|
|
716
705
|
RightSide: function (element, limit_right, current_horizontal, max_right) {
|
|
717
|
-
|
|
706
|
+
const data = this.data;
|
|
707
|
+
|
|
718
708
|
let width, depth;
|
|
719
|
-
if (
|
|
709
|
+
if (data.area && !element.children) {
|
|
720
710
|
width = Math.sqrt(element.area);
|
|
721
|
-
depth = Math.sqrt(element.area)
|
|
711
|
+
depth = Math.sqrt(element.area);
|
|
722
712
|
} else {
|
|
723
713
|
width = parseFloat(element.width);
|
|
724
|
-
depth = parseFloat(element.depth)
|
|
714
|
+
depth = parseFloat(element.depth);
|
|
725
715
|
}
|
|
726
716
|
// Calculate position
|
|
727
|
-
let posX = limit_right + (width / 2)
|
|
717
|
+
let posX = limit_right + (width / 2);
|
|
728
718
|
let posY = current_horizontal - (depth / 2);
|
|
729
719
|
|
|
730
720
|
// Calculate states
|
|
731
721
|
current_horizontal -= depth;
|
|
732
|
-
let total_x = limit_right + width
|
|
722
|
+
let total_x = limit_right + width;
|
|
733
723
|
if (total_x > max_right) {
|
|
734
724
|
max_right = total_x;
|
|
735
725
|
}
|
|
@@ -738,22 +728,23 @@ AFRAME.registerComponent('babia-boats', {
|
|
|
738
728
|
},
|
|
739
729
|
|
|
740
730
|
DownSide: function (element, limit_down, current_vertical, max_down) {
|
|
741
|
-
|
|
731
|
+
const data = this.data;
|
|
732
|
+
|
|
742
733
|
let width, depth;
|
|
743
|
-
if (
|
|
744
|
-
width = Math.sqrt(element.area)
|
|
734
|
+
if (data.area && !element.children) {
|
|
735
|
+
width = Math.sqrt(element.area);
|
|
745
736
|
depth = Math.sqrt(element.area);
|
|
746
737
|
} else {
|
|
747
|
-
width = parseFloat(element.width)
|
|
738
|
+
width = parseFloat(element.width);
|
|
748
739
|
depth = parseFloat(element.depth);
|
|
749
740
|
}
|
|
750
|
-
|
|
741
|
+
|
|
751
742
|
let posX = current_vertical - (width / 2);
|
|
752
|
-
let posY = limit_down - (depth / 2)
|
|
743
|
+
let posY = limit_down - (depth / 2);
|
|
753
744
|
|
|
754
|
-
// Calculate state
|
|
755
745
|
current_vertical -= width;
|
|
756
|
-
|
|
746
|
+
|
|
747
|
+
let total_y = limit_down - depth;
|
|
757
748
|
if (total_y < max_down) {
|
|
758
749
|
max_down = total_y;
|
|
759
750
|
}
|
|
@@ -762,22 +753,23 @@ AFRAME.registerComponent('babia-boats', {
|
|
|
762
753
|
},
|
|
763
754
|
|
|
764
755
|
LeftSide: function (element, limit_left, current_horizontal, max_left) {
|
|
765
|
-
|
|
756
|
+
const data = this.data;
|
|
757
|
+
|
|
766
758
|
let width, depth;
|
|
767
|
-
if (
|
|
759
|
+
if (data.area && !element.children) {
|
|
768
760
|
width = Math.sqrt(element.area);
|
|
769
|
-
depth = Math.sqrt(element.area)
|
|
761
|
+
depth = Math.sqrt(element.area);
|
|
770
762
|
} else {
|
|
771
763
|
width = parseFloat(element.width);
|
|
772
|
-
depth = parseFloat(element.depth)
|
|
764
|
+
depth = parseFloat(element.depth);
|
|
773
765
|
}
|
|
774
|
-
|
|
775
|
-
let posX = limit_left - (width / 2)
|
|
766
|
+
|
|
767
|
+
let posX = limit_left - (width / 2);
|
|
776
768
|
let posY = current_horizontal + (depth / 2);
|
|
777
769
|
|
|
778
|
-
// Calculate state
|
|
779
770
|
current_horizontal += depth;
|
|
780
|
-
|
|
771
|
+
|
|
772
|
+
let total_x = limit_left - width;
|
|
781
773
|
if (total_x < max_left) {
|
|
782
774
|
max_left = total_x;
|
|
783
775
|
}
|
|
@@ -786,22 +778,23 @@ AFRAME.registerComponent('babia-boats', {
|
|
|
786
778
|
},
|
|
787
779
|
|
|
788
780
|
UpSide: function (element, limit_up, current_vertical, max_up) {
|
|
789
|
-
|
|
781
|
+
const data = this.data;
|
|
782
|
+
|
|
790
783
|
let width, depth;
|
|
791
|
-
if (
|
|
792
|
-
width = Math.sqrt(element.area)
|
|
784
|
+
if (data.area && !element.children) {
|
|
785
|
+
width = Math.sqrt(element.area);
|
|
793
786
|
depth = Math.sqrt(element.area);
|
|
794
787
|
} else {
|
|
795
|
-
width = parseFloat(element.width)
|
|
788
|
+
width = parseFloat(element.width);
|
|
796
789
|
depth = parseFloat(element.depth);
|
|
797
790
|
}
|
|
798
|
-
|
|
791
|
+
|
|
799
792
|
let posX = current_vertical + (width / 2);
|
|
800
|
-
let posY = limit_up + (depth / 2)
|
|
793
|
+
let posY = limit_up + (depth / 2);
|
|
801
794
|
|
|
802
|
-
// Calculate state
|
|
803
795
|
current_vertical += width;
|
|
804
|
-
|
|
796
|
+
|
|
797
|
+
let total_y = limit_up + depth;
|
|
805
798
|
if (total_y > max_up) {
|
|
806
799
|
max_up = total_y;
|
|
807
800
|
}
|
|
@@ -809,6 +802,131 @@ AFRAME.registerComponent('babia-boats', {
|
|
|
809
802
|
return [current_vertical, posX, posY, max_up];
|
|
810
803
|
},
|
|
811
804
|
|
|
805
|
+
/**
|
|
806
|
+
* getColor
|
|
807
|
+
*
|
|
808
|
+
* Calculate the color of the element based on its value in color_field.
|
|
809
|
+
* If the value is a number, it will calculate the color based on the
|
|
810
|
+
* heat map from color_min to color_max.
|
|
811
|
+
* If the value is a string, it will assign a color from colorsArray in
|
|
812
|
+
* order of appearence.
|
|
813
|
+
*
|
|
814
|
+
* @param {Object} element - The element to calculate the color for
|
|
815
|
+
* @param {String} color_field - The field in the element to calculate the color from
|
|
816
|
+
*
|
|
817
|
+
* @return {String} - The color for the element
|
|
818
|
+
*/
|
|
819
|
+
getColor: function (element, color_field) {
|
|
820
|
+
const self = this;
|
|
821
|
+
let color_value = element[color_field];
|
|
822
|
+
let color;
|
|
823
|
+
if (typeof color_value === 'number') {
|
|
824
|
+
color = heatMapColorforValue(color_value,
|
|
825
|
+
self.babiaMetadata['color_max'], self.babiaMetadata['color_min']);
|
|
826
|
+
} else if (typeof color_value === 'string') {
|
|
827
|
+
// Categoric color
|
|
828
|
+
if (color_value in self.categoricColorMaps) {
|
|
829
|
+
color = self.categoricColorMaps[color_value];
|
|
830
|
+
} else {
|
|
831
|
+
self.categoricColorMaps[color_value]
|
|
832
|
+
= colorsArray[self.categoricColorIndex]
|
|
833
|
+
color = colorsArray[self.categoricColorIndex]
|
|
834
|
+
|
|
835
|
+
self.categoricColorIndex = self.categoricColorIndex + 1
|
|
836
|
+
if (self.categoricColorIndex >= colorsArray.length) {
|
|
837
|
+
self.categoricColorIndex = 0
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
return color;
|
|
842
|
+
},
|
|
843
|
+
|
|
844
|
+
/**
|
|
845
|
+
* getColorBase
|
|
846
|
+
*
|
|
847
|
+
* Determines the color for the base in a given level, depending on whether
|
|
848
|
+
* gradientBaseColor is enabled. If enabled, it calculates a color
|
|
849
|
+
* using the greenColorsurface function based on normalized level
|
|
850
|
+
* values. If not enabled, it uses the default base color.
|
|
851
|
+
*
|
|
852
|
+
* @param {number} level - The level for which to determine the color.
|
|
853
|
+
*
|
|
854
|
+
* @return {string} - The calculated base color.
|
|
855
|
+
*/
|
|
856
|
+
getColorBase: function (level) {
|
|
857
|
+
let color;
|
|
858
|
+
const self = this;
|
|
859
|
+
|
|
860
|
+
if (self.data.gradientBaseColor) {
|
|
861
|
+
let max_levels = self.babiaMetadata['maxLevels'];
|
|
862
|
+
color = greenColorsurface(Math.round(
|
|
863
|
+
self.normalizeValues(1, max_levels, 15, 100, level)
|
|
864
|
+
));
|
|
865
|
+
} else {
|
|
866
|
+
color = self.data.base_color;
|
|
867
|
+
};
|
|
868
|
+
return color;
|
|
869
|
+
},
|
|
870
|
+
|
|
871
|
+
/**
|
|
872
|
+
* setTransparency
|
|
873
|
+
*
|
|
874
|
+
* If "transparency by a field" on buildings is selected
|
|
875
|
+
* set transparency to 80% or 20% to those buildings that share
|
|
876
|
+
* same value for the selected field.
|
|
877
|
+
* @param {Object} figure - The figure to set transparency
|
|
878
|
+
*/
|
|
879
|
+
setTransparency: function (figure) {
|
|
880
|
+
const self = this;
|
|
881
|
+
const data = this.data;
|
|
882
|
+
|
|
883
|
+
// If transparency by a field on buildings
|
|
884
|
+
// Put transparent 80% to those buildings that share same value for a field selected
|
|
885
|
+
const t80_field = data.transparent80ByRepeatedField;
|
|
886
|
+
const t20_field = data.transparent20ByRepeatedField;
|
|
887
|
+
if (t80_field && (!figure.children &&
|
|
888
|
+
self.idsToNotRepeat80Transparent.includes(figure.rawData[t80_field]))) {
|
|
889
|
+
figure.alpha = 0.8
|
|
890
|
+
figure.renderOrder = 2000
|
|
891
|
+
} else {
|
|
892
|
+
self.idsToNotRepeat80Transparent.push(figure.rawData[t80_field])
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
// Put transparent 20% to those buildings that share same value for a field selected
|
|
896
|
+
if (t20_field && (!figure.children &&
|
|
897
|
+
self.idsToNotRepeat20Transparent.includes(figure.rawData[t20_field]))) {
|
|
898
|
+
figure.alpha = 0.45
|
|
899
|
+
figure.renderOrder = 2000
|
|
900
|
+
} else {
|
|
901
|
+
self.idsToNotRepeat20Transparent.push(figure.rawData[t20_field])
|
|
902
|
+
}
|
|
903
|
+
},
|
|
904
|
+
|
|
905
|
+
/**
|
|
906
|
+
* getWireframe
|
|
907
|
+
*
|
|
908
|
+
* Get boolean to decide if wireframe will be put to the elements
|
|
909
|
+
* that share the same value of the selected field.
|
|
910
|
+
* @param {Object} figure - The figure to set wireframe
|
|
911
|
+
* @param {String} wireframe_field - The field in the element to decide the wireframe
|
|
912
|
+
*
|
|
913
|
+
* @return {Boolean} - True if the element will be visualized as wireframe
|
|
914
|
+
*/
|
|
915
|
+
getWireframe: function (figure, wireframe_field) {
|
|
916
|
+
const self = this;
|
|
917
|
+
let wireframe;
|
|
918
|
+
|
|
919
|
+
// Put wireframe to those buildings that share same value for a field selected
|
|
920
|
+
if (wireframe_field && (!figure.children &&
|
|
921
|
+
self.idsToNotRepeatWireframe.includes(figure.rawData[wireframe_field]))) {
|
|
922
|
+
wireframe = true;
|
|
923
|
+
} else {
|
|
924
|
+
wireframe = false;
|
|
925
|
+
self.idsToNotRepeatWireframe.push(figure.rawData[wireframe_field]);
|
|
926
|
+
}
|
|
927
|
+
return wireframe;
|
|
928
|
+
},
|
|
929
|
+
|
|
812
930
|
Animation: function (element, figures, figures_old, delta, translate, translate_old) {
|
|
813
931
|
let self = this
|
|
814
932
|
let new_time = Date.now();
|
|
@@ -1399,6 +1517,7 @@ AFRAME.registerComponent('babia-boats', {
|
|
|
1399
1517
|
}
|
|
1400
1518
|
|
|
1401
1519
|
// Create city
|
|
1520
|
+
console.log("About to update chart...", this.newData)
|
|
1402
1521
|
this.updateChart(this.newData)
|
|
1403
1522
|
|
|
1404
1523
|
// Categoric color legend
|
|
@@ -1552,7 +1671,16 @@ AFRAME.registerComponent('babia-boats', {
|
|
|
1552
1671
|
y: self.data.height_quarter_legend_title,
|
|
1553
1672
|
z: coordinates.z
|
|
1554
1673
|
}
|
|
1555
|
-
entity.legend = generateLegend(
|
|
1674
|
+
entity.legend = generateLegend(entity.babiaRawData || {}, {
|
|
1675
|
+
name: figure.name,
|
|
1676
|
+
scale: self.data.legend_scale,
|
|
1677
|
+
lookat: self.data.legend_lookat,
|
|
1678
|
+
template: self.data.legend_text || '{name}',
|
|
1679
|
+
colorPlane: 'black',
|
|
1680
|
+
colorText: 'white',
|
|
1681
|
+
isQuarter: true,
|
|
1682
|
+
fields: {}
|
|
1683
|
+
});
|
|
1556
1684
|
|
|
1557
1685
|
// If legend is a child of the building/quarter
|
|
1558
1686
|
if (self.data.legendsAsChildren) {
|
|
@@ -1667,7 +1795,22 @@ AFRAME.registerComponent('babia-boats', {
|
|
|
1667
1795
|
depth: entityGeometry.depth + 0.1,
|
|
1668
1796
|
width: entityGeometry.width + 0.1
|
|
1669
1797
|
});
|
|
1670
|
-
entity.legend = generateLegend(
|
|
1798
|
+
entity.legend = generateLegend(entity.babiaRawData, {
|
|
1799
|
+
name: figure.name,
|
|
1800
|
+
scale: self.data.legend_scale,
|
|
1801
|
+
lookat: self.data.legend_lookat,
|
|
1802
|
+
template: self.data.legend_text,
|
|
1803
|
+
colorPlane: 'white',
|
|
1804
|
+
colorText: 'black',
|
|
1805
|
+
isQuarter: false,
|
|
1806
|
+
fields: {
|
|
1807
|
+
height: self.data.height,
|
|
1808
|
+
area: self.data.area,
|
|
1809
|
+
width: self.data.width,
|
|
1810
|
+
depth: self.data.depth,
|
|
1811
|
+
color: self.data.color,
|
|
1812
|
+
}
|
|
1813
|
+
});
|
|
1671
1814
|
let worldPos = new THREE.Vector3();
|
|
1672
1815
|
let coordinates = worldPos.setFromMatrixPosition(entity.object3D.matrixWorld);
|
|
1673
1816
|
let height_real = new THREE.Box3().setFromObject(entity.object3D)
|
|
@@ -1741,7 +1884,22 @@ AFRAME.registerComponent('babia-boats', {
|
|
|
1741
1884
|
depth: entityGeometry.depth + 0.1,
|
|
1742
1885
|
width: entityGeometry.width + 0.1
|
|
1743
1886
|
});
|
|
1744
|
-
entity.legend = generateLegend(
|
|
1887
|
+
entity.legend = generateLegend(entity.babiaRawData, {
|
|
1888
|
+
name: figure.name,
|
|
1889
|
+
scale: self.data.legend_scale,
|
|
1890
|
+
lookat: self.data.legend_lookat,
|
|
1891
|
+
template: self.data.legend_text,
|
|
1892
|
+
colorPlane: 'white',
|
|
1893
|
+
colorText: 'black',
|
|
1894
|
+
isQuarter: false,
|
|
1895
|
+
fields: {
|
|
1896
|
+
height: self.data.height,
|
|
1897
|
+
area: self.data.area,
|
|
1898
|
+
width: self.data.width,
|
|
1899
|
+
depth: self.data.depth,
|
|
1900
|
+
color: self.data.color,
|
|
1901
|
+
}
|
|
1902
|
+
});
|
|
1745
1903
|
let worldPos = new THREE.Vector3();
|
|
1746
1904
|
let coordinates = worldPos.setFromMatrixPosition(entity.object3D.matrixWorld);
|
|
1747
1905
|
let height_real = new THREE.Box3().setFromObject(entity.object3D)
|
|
@@ -1822,74 +1980,79 @@ AFRAME.registerComponent('babia-boats', {
|
|
|
1822
1980
|
/**
|
|
1823
1981
|
* This function generate a plane at the top of the building with the desired text
|
|
1824
1982
|
*/
|
|
1825
|
-
let generateLegend = (
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
}
|
|
1861
|
-
|
|
1862
|
-
}
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1983
|
+
let generateLegend = (data, {
|
|
1984
|
+
name,
|
|
1985
|
+
scale,
|
|
1986
|
+
lookat,
|
|
1987
|
+
template = '{name}',
|
|
1988
|
+
colorPlane = 'white',
|
|
1989
|
+
colorText = 'black',
|
|
1990
|
+
isQuarter = false,
|
|
1991
|
+
fields = {}
|
|
1992
|
+
}) => {
|
|
1993
|
+
const safe = (val, fallback = '') => (typeof val !== 'undefined' ? val : fallback);
|
|
1994
|
+
const round = v => (typeof v === 'number' ? Math.round(v * 100) / 100 : v);
|
|
1995
|
+
|
|
1996
|
+
// Campos usados
|
|
1997
|
+
const fheight = fields.height || '';
|
|
1998
|
+
const farea = fields.area || '';
|
|
1999
|
+
const fwidth = fields.width || '';
|
|
2000
|
+
const fdepth = fields.depth || '';
|
|
2001
|
+
const fcolor = fields.color || '';
|
|
2002
|
+
|
|
2003
|
+
// Datos correspondientes
|
|
2004
|
+
const vheight = round(safe(data?.[fheight]));
|
|
2005
|
+
const varea = round(safe(data?.[farea]));
|
|
2006
|
+
const vwidth = round(safe(data?.[fwidth]));
|
|
2007
|
+
const vdepth = round(safe(data?.[fdepth]));
|
|
2008
|
+
const vcolor = safe(data?.[fcolor]);
|
|
2009
|
+
|
|
2010
|
+
// Texto final
|
|
2011
|
+
const finalText = isQuarter
|
|
2012
|
+
? name
|
|
2013
|
+
: template
|
|
2014
|
+
.replaceAll('{name}', name)
|
|
2015
|
+
// nombres de los campos
|
|
2016
|
+
.replaceAll('{fheight}', fheight)
|
|
2017
|
+
.replaceAll('{farea}', farea)
|
|
2018
|
+
.replaceAll('{fwidth}', fwidth)
|
|
2019
|
+
.replaceAll('{fdepth}', fdepth)
|
|
2020
|
+
.replaceAll('{fcolor}', fcolor)
|
|
2021
|
+
// valores
|
|
2022
|
+
.replaceAll('{height}', vheight)
|
|
2023
|
+
.replaceAll('{area}', varea)
|
|
2024
|
+
.replaceAll('{width}', vwidth)
|
|
2025
|
+
.replaceAll('{depth}', vdepth)
|
|
2026
|
+
.replaceAll('{color}', vcolor);
|
|
2027
|
+
|
|
2028
|
+
const lines = finalText.split('\n');
|
|
2029
|
+
const width = Math.max(...lines.map(line => line.length)) / 5;
|
|
2030
|
+
const height = lines.length * 0.3 + 0.3;
|
|
2031
|
+
|
|
2032
|
+
const entity = document.createElement('a-plane');
|
|
1871
2033
|
entity.setAttribute('babia-lookat', lookat);
|
|
1872
|
-
|
|
1873
2034
|
entity.setAttribute('rotation', { x: 0, y: 0, z: 0 });
|
|
1874
2035
|
entity.setAttribute('height', height);
|
|
1875
2036
|
entity.setAttribute('width', width);
|
|
1876
2037
|
entity.setAttribute('color', colorPlane);
|
|
1877
|
-
entity.setAttribute('material', {
|
|
2038
|
+
entity.setAttribute('material', { side: 'double' });
|
|
2039
|
+
|
|
1878
2040
|
entity.setAttribute('text', {
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
2041
|
+
value: finalText,
|
|
2042
|
+
align: 'center',
|
|
2043
|
+
width: 6,
|
|
2044
|
+
color: colorText,
|
|
2045
|
+
alphaTest: 6,
|
|
2046
|
+
opacity: 6,
|
|
2047
|
+
transparent: false
|
|
1886
2048
|
});
|
|
2049
|
+
|
|
1887
2050
|
entity.setAttribute('visible', false);
|
|
1888
2051
|
entity.setAttribute('class', 'babialegend');
|
|
1889
|
-
entity.setAttribute('scale', { x:
|
|
2052
|
+
entity.setAttribute('scale', { x: scale, y: scale, z: scale });
|
|
1890
2053
|
|
|
1891
2054
|
return entity;
|
|
1892
|
-
}
|
|
2055
|
+
};
|
|
1893
2056
|
|
|
1894
2057
|
function setOpacity(entity, opacity) {
|
|
1895
2058
|
entity.setAttribute('material', 'opacity', opacity);
|