aframe-babia-components 1.2.0 → 1.2.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.
Files changed (127) hide show
  1. package/components/filters/babia-selector.js +256 -79
  2. package/components/filters/babia-treebuilder.js +4 -5
  3. package/components/geometries/babia-cyl.js +180 -0
  4. package/components/others/assets/tooltip.png +0 -0
  5. package/components/others/babia-camera.js +195 -0
  6. package/components/others/babia-controls.js +62 -37
  7. package/components/others/babia-navigator.js +55 -49
  8. package/components/others/babia-range-selector.js +208 -0
  9. package/components/others/babia-slider.js +36 -8
  10. package/components/others/babia-ui.js +246 -73
  11. package/components/others/common.js +60 -73
  12. package/components/queriers/babia-querycsv.js +96 -0
  13. package/components/queriers/babia-queryes.js +203 -132
  14. package/components/visualizers/babia-bars.js +4 -35
  15. package/components/visualizers/babia-barsmap.js +2 -30
  16. package/components/visualizers/babia-boats.js +291 -279
  17. package/components/visualizers/babia-bubbles.js +9 -26
  18. package/components/visualizers/babia-city.js +19 -9
  19. package/components/visualizers/babia-cyls.js +197 -201
  20. package/components/visualizers/babia-cylsmap.js +171 -241
  21. package/components/visualizers/babia-doughnut.js +2 -28
  22. package/components/visualizers/babia-network.js +191 -124
  23. package/components/visualizers/babia-pie.js +2 -30
  24. package/dist/aframe-babia-components.js +6785 -5626
  25. package/dist/aframe-babia-components.min.js +7 -1
  26. package/dist/aframe-babia-components.min.js.map +1 -0
  27. package/docs/APIs/CHARTS.md +11 -4
  28. package/docs/APIs/DATAMANAGEMENT.md +7 -0
  29. package/docs/APIs/OTHERS.md +27 -0
  30. package/docs/APIs/QUERIERS.md +16 -0
  31. package/docs/RELEASE_NOTES.md +44 -23
  32. package/docs/Tutorials/multiuser.md +47 -2
  33. package/docs/Tutorials/temporal_evol_with_boats.md +4 -4
  34. package/examples/assets/door/New Bitmap Image.jpg +0 -0
  35. package/examples/assets/door/door.mtl +26 -0
  36. package/examples/assets/door/door.obj +6927 -0
  37. package/examples/assets/popups/0.png +0 -0
  38. package/examples/assets/popups/1.png +0 -0
  39. package/examples/assets/popups/10.png +0 -0
  40. package/examples/assets/popups/2.png +0 -0
  41. package/examples/assets/popups/3.png +0 -0
  42. package/examples/assets/popups/4.png +0 -0
  43. package/examples/assets/popups/5.png +0 -0
  44. package/examples/assets/popups/6.png +0 -0
  45. package/examples/assets/popups/7.png +0 -0
  46. package/examples/assets/popups/8.png +0 -0
  47. package/examples/assets/popups/9.png +0 -0
  48. package/examples/assets/popups/close.jpg +0 -0
  49. package/examples/assets/popups/info.jpg +0 -0
  50. package/examples/assets/textures/brownwall.png +0 -0
  51. package/examples/assets/textures/concrete.png +0 -0
  52. package/examples/assets/textures/white-wall-texture.jpg +0 -0
  53. package/examples/boats/boats_new_element/data1.json +18 -18
  54. package/examples/boats/boats_new_element/data2.json +19 -19
  55. package/examples/boats/boats_new_element/index.html +1 -1
  56. package/examples/charts/cyls/index.html +13 -4
  57. package/examples/charts/cyls/primitive.html +76 -0
  58. package/examples/charts/cylsmap/index.html +14 -5
  59. package/examples/charts_querier/bars_querier/data.csv +10 -0
  60. package/examples/charts_querier/bars_querier/index_csv.html +80 -0
  61. package/examples/dashboard/chaoss-dashboards.html +259 -0
  62. package/examples/dashboard/chaoss-issues.html +248 -0
  63. package/examples/dashboard/chaoss-pr.html +248 -0
  64. package/examples/dashboard/index.html +247 -0
  65. package/examples/dashboard/issues_queries/80-percent-open-time.json +123 -0
  66. package/examples/dashboard/issues_queries/issues-by-organization.json +107 -0
  67. package/examples/dashboard/issues_queries/issues.json +117 -0
  68. package/examples/dashboard/issues_queries/median-open-time.json +123 -0
  69. package/examples/dashboard/issues_queries/organizations.json +130 -0
  70. package/examples/dashboard/issues_queries/projects.json +130 -0
  71. package/examples/dashboard/issues_queries/repositories.json +130 -0
  72. package/examples/dashboard/issues_queries/status.json +107 -0
  73. package/examples/dashboard/issues_queries/submitter.json +125 -0
  74. package/examples/dashboard/issues_queries/submitters.json +113 -0
  75. package/examples/dashboard/pullrequests_queries/80-percent-open-time.json +123 -0
  76. package/examples/dashboard/pullrequests_queries/median-open-time.json +123 -0
  77. package/examples/dashboard/pullrequests_queries/organizations.json +130 -0
  78. package/examples/dashboard/pullrequests_queries/projects.json +130 -0
  79. package/examples/dashboard/pullrequests_queries/pull-requests-by-organization.json +107 -0
  80. package/examples/dashboard/pullrequests_queries/pull-requests.json +117 -0
  81. package/examples/dashboard/pullrequests_queries/repositories.json +130 -0
  82. package/examples/dashboard/pullrequests_queries/status.json +107 -0
  83. package/examples/dashboard/pullrequests_queries/submitter.json +125 -0
  84. package/examples/dashboard/pullrequests_queries/submitters.json +113 -0
  85. package/examples/dashboard/range.html +88 -0
  86. package/examples/dashboard/template.html +136 -0
  87. package/examples/demos/1.0.11/index_multiuser_ui.html +1 -1
  88. package/examples/multi_bars/data.json +14 -0
  89. package/examples/multi_bars/data2.json +15 -0
  90. package/examples/multi_bars/data3.json +23 -0
  91. package/examples/multi_bars/easyrtc.js +11984 -0
  92. package/examples/multi_bars/index.html +97 -0
  93. package/examples/multi_bars/index1.html +111 -0
  94. package/examples/multi_bars/index2.html +102 -0
  95. package/examples/multi_bars/index3.html +104 -0
  96. package/examples/multi_boats/data3.json +174 -0
  97. package/examples/multi_boats/data4.json +192 -0
  98. package/examples/multi_boats/easyrtc.js +11984 -0
  99. package/examples/multi_boats/index_multi_boats.html +223 -0
  100. package/examples/multi_boats/jetuml.html +256 -0
  101. package/examples/multi_boats/jetuml_code_data.json +1 -0
  102. package/examples/multi_boats/jetuml_evolution_experiment.html +419 -0
  103. package/examples/multi_boats/only_queryjson.html +132 -0
  104. package/examples/multi_boats/only_queryjson2.html +167 -0
  105. package/examples/multi_boats/only_queryjson3.html +165 -0
  106. package/examples/multi_boats/queryjson_treebuilder.html +132 -0
  107. package/examples/multi_boats/with_selector.html +255 -0
  108. package/examples/multiuser/choose_avatar/index.html +18 -8
  109. package/examples/selector_boats/jetuml.html +74 -0
  110. package/examples/selector_boats/jetuml_evol_data.json +1 -0
  111. package/examples/selector_boats/jetuml_from_3_2_to_1_0.json +62382 -0
  112. package/examples/selector_boats/jetumltest.html +80 -0
  113. package/examples/ui/link/index.html +12 -11
  114. package/examples/ui/network/data.json +123 -0
  115. package/examples/ui/network/links.json +13 -0
  116. package/examples/ui/network/network.html +75 -0
  117. package/examples/ui/network/network_nodes_links.html +82 -0
  118. package/examples/ui/network/nodes.json +12 -0
  119. package/index.html +73 -2
  120. package/index.js +12 -1
  121. package/package.json +6 -3
  122. package/tests/screenshots/other_snapshots.js/chaoss-issues.png +0 -0
  123. package/tests/screenshots/other_snapshots.js/chaoss-pr.png +0 -0
  124. package/tests/screenshots/other_snapshots.js/template.png +0 -0
  125. package/tests/ui.js +7 -0
  126. package/webpack.common.js +10 -1
  127. package/webpack.devnossl.js +16 -0
@@ -1,4 +1,7 @@
1
1
  let findProdComponent = require('../others/common').findProdComponent;
2
+ let updateFunction = require('../others/common').updateFunction;
3
+
4
+ const NotiBuffer = require("../../common/noti-buffer").NotiBuffer;
2
5
 
3
6
  /* global AFRAME */
4
7
  if (typeof AFRAME === 'undefined') {
@@ -30,6 +33,8 @@ AFRAME.registerComponent('babia-boats', {
30
33
  height_quarter_legend_title: { type: 'number', default: 12 },
31
34
  height_building_legend: { type: 'number', default: 0 },
32
35
  legend_scale: { type: 'number', default: 1 },
36
+ legend_lookat: { type: 'string', default: "[camera]" },
37
+ field: { type: 'string', default: 'uid' },
33
38
  },
34
39
 
35
40
  /**
@@ -71,43 +76,21 @@ AFRAME.registerComponent('babia-boats', {
71
76
  figures_del: [],
72
77
  figures_in: [],
73
78
  animation: false,
74
-
79
+ /**
80
+ * Called once when component is attached. Generally for initial setup.
81
+ */
82
+ init: function () {
83
+ this.notiBuffer = new NotiBuffer();
84
+ },
75
85
  /**
76
86
  * Called when component is attached and when component data changes.
77
87
  * Generally modifies the entity based on the data.
78
88
  */
79
89
 
80
90
  update: function (oldData) {
81
- let data = this.data;
82
- let el = this.el;
83
- if (!this.figures){
84
- this.figures = [];
85
- }
86
-
87
- // Highest priority to data
88
- if (data.data && oldData.data !== data.data) {
89
- // Get from the json or embedded
90
- let _data = JSON.parse(data.data);
91
- this.processData(_data);
92
- } else if (data.from !== oldData.from) {
93
- // Unregister for old treegenerator
94
- if (this.prodComponent) {
95
- this.prodComponent.notiBuffer.unregister(this.notiBufferId)
96
- };
97
- // Register for the new one
98
- this.prodComponent = findProdComponent(data, el)
99
- if (this.prodComponent.notiBuffer){
100
- this.notiBufferId = this.prodComponent.notiBuffer
101
- .register(this.processData.bind(this))
102
- }
103
- }
104
- // If changed whatever, re-print with the current data
105
- else if (data !== oldData && this.newData) {
106
- console.log("Generating city...")
107
- this.processData(this.newData)
108
- }
91
+ updateFunction(this, oldData)
109
92
  },
110
-
93
+
111
94
  /**
112
95
  * Called on each scene tick.
113
96
  */
@@ -116,7 +99,6 @@ AFRAME.registerComponent('babia-boats', {
116
99
  let t = { x: 0, y: 0, z: 0 };
117
100
  if ((Date.now() - this.start_time) > this.duration) {
118
101
  this.animation = false;
119
- // Fix bugs when change instante quickly
120
102
  this.setFigures(this.figures, t);
121
103
  } else {
122
104
  this.Animation(this.el, this.figures, this.figures_old, delta, t, t);
@@ -129,14 +111,18 @@ AFRAME.registerComponent('babia-boats', {
129
111
  let t = { x: 0, y: 0, z: 0 };
130
112
 
131
113
  // when animation not finished, delete figures and opa 1 to inserted
132
- if (this.animation){
114
+ if (this.animation) {
133
115
  this.figures_del.forEach(figure => {
134
116
  let entity = document.getElementById(figure.id);
135
- setOpacity(entity, 0.0);
117
+ if (entity) {
118
+ entity.remove();
119
+ }
136
120
  })
137
121
  this.figures_in.forEach(figure => {
138
122
  let entity = document.getElementById(figure.id);
139
- setOpacity(entity, 1.0);
123
+ if (entity) {
124
+ setOpacity(entity, 1.0);
125
+ }
140
126
  })
141
127
  this.setFigures(this.figures, t);
142
128
  this.animation = false;
@@ -173,7 +159,7 @@ AFRAME.registerComponent('babia-boats', {
173
159
  this.el.firstChild.remove();
174
160
  this.drawElements(el, this.figures, t);
175
161
  } else {
176
- if (this.figures_old !== this.figures){
162
+ if (this.figures_old !== this.figures) {
177
163
  this.animation = true;
178
164
  this.start_time = Date.now();
179
165
  }
@@ -312,8 +298,8 @@ AFRAME.registerComponent('babia-boats', {
312
298
  let figure
313
299
  if (elements[i].children) {
314
300
  figure = {
315
- id: "boat-" + elements[i].uid,
316
- name: elements[i].uid,
301
+ id: id = "boat-" + elements[i][this.data.field],
302
+ name: elements[i][this.data.field],
317
303
  posX: posX,
318
304
  posY: posY,
319
305
  width: element.width,
@@ -325,8 +311,8 @@ AFRAME.registerComponent('babia-boats', {
325
311
  } else {
326
312
  if (this.data.area) {
327
313
  figure = {
328
- id: "boat-" + elements[i].uid,
329
- name: elements[i].uid,
314
+ id: "boat-" + elements[i][this.data.field],
315
+ name: (elements[i].name) ? elements[i].name : elements[i][this.data.field],
330
316
  posX: posX,
331
317
  posY: posY,
332
318
  width: Math.sqrt(element.area),
@@ -335,8 +321,8 @@ AFRAME.registerComponent('babia-boats', {
335
321
  }
336
322
  } else {
337
323
  figure = {
338
- id: "boat-" + elements[i].uid,
339
- name: elements[i].uid,
324
+ id: "boat-" + elements[i][this.data.field],
325
+ name: (elements[i].name) ? elements[i].name : elements[i][this.data.field],
340
326
  posX: posX,
341
327
  posY: posY,
342
328
  width: element.width,
@@ -395,7 +381,6 @@ AFRAME.registerComponent('babia-boats', {
395
381
  },
396
382
 
397
383
  drawElements: function (element, figures, translate) {
398
- let self = this
399
384
 
400
385
  for (let i in figures) {
401
386
 
@@ -409,177 +394,7 @@ AFRAME.registerComponent('babia-boats', {
409
394
  }
410
395
 
411
396
  let entity = this.createElement(figures[i], position);
412
-
413
- if (figures[i].children) {
414
- // Quarter
415
- let legend;
416
- let transparentBox;
417
- entity.addEventListener('click', function (e) {
418
- // Just launch the event on the child
419
- if (e.target !== this)
420
- return;
421
-
422
- if (legend) {
423
- entity.removeChild(transparentBox)
424
- self.el.parentElement.removeChild(legend)
425
- legend = undefined
426
- transparentBox = undefined
427
-
428
- // Remove from the array that has the entity activated
429
- const index = self.entitiesWithLegend.indexOf(entity);
430
- if (index > -1) {
431
- self.entitiesWithLegend.splice(index, 1);
432
- }
433
- } else {
434
- transparentBox = document.createElement('a-entity');
435
- transparentBox.setAttribute('class', 'babialegend')
436
- let oldGeometry = entity.getAttribute('geometry')
437
- let scale = self.el.getAttribute("scale")
438
- let tsBoxHeight = oldGeometry.height + self.data.height_quarter_legend_box
439
- if (scale) {
440
- tsBoxHeight = ((oldGeometry.height + self.data.height_quarter_legend_box) / scale.y)
441
- }
442
- transparentBox.setAttribute('geometry', {
443
- height: tsBoxHeight,
444
- depth: oldGeometry.depth,
445
- width: oldGeometry.width
446
- });
447
- transparentBox.setAttribute('material', {
448
- 'visible': true,
449
- 'opacity': 0.4
450
- });
451
- entity.appendChild(transparentBox)
452
-
453
- legend = generateLegend(figures[i].name, self.data.legend_scale, 'black', 'white');
454
- let worldPos = new THREE.Vector3();
455
- let coordinates = worldPos.setFromMatrixPosition(entity.object3D.matrixWorld);
456
- let coordinatesFinal = {
457
- x: coordinates.x,
458
- y: self.data.height_quarter_legend_title,
459
- z: coordinates.z
460
- }
461
- legend.setAttribute('position', coordinatesFinal)
462
- legend.setAttribute('visible', true);
463
- self.el.parentElement.appendChild(legend)
464
-
465
- // Add to the elements that has the legend activated
466
- self.entitiesWithLegend.push(entity)
467
- }
468
- })
469
-
470
- this.drawElements(entity, figures[i].children, figures[i].translate_matrix);
471
- } else {
472
- // Building
473
- let legend;
474
- let entityGeometry;
475
- let alreadyActive = false;
476
-
477
- entity.addEventListener('click', function (e) {
478
- if (e.target !== this)
479
- return;
480
-
481
- if (alreadyActive) {
482
- legend.setAttribute('visible', false);
483
- entity.setAttribute('geometry', {
484
- height: entityGeometry.height - 0.1,
485
- depth: entityGeometry.depth - 0.1,
486
- width: entityGeometry.width - 0.1
487
- });
488
- entity.setAttribute('material', {
489
- 'color': entity.getAttribute('babiaxrFirstColor')
490
- });
491
- self.el.parentElement.removeChild(legend)
492
- legend = undefined
493
- alreadyActive = false
494
-
495
- // Remove from the array that has the entity activated
496
- const index = self.entitiesWithLegend.indexOf(entity);
497
- if (index > -1) {
498
- self.entitiesWithLegend.splice(index, 1);
499
- }
500
- } else {
501
- alreadyActive = true
502
-
503
- // If clicked again but not mouseover
504
- if (!legend) {
505
- // COPY FROM 626
506
- entityGeometry = entity.getAttribute('geometry')
507
- let boxPosition = entity.getAttribute("position")
508
- entity.setAttribute('position', boxPosition)
509
- entity.setAttribute('babiaxrFirstColor', entity.getAttribute("material")["color"])
510
- entity.setAttribute('material', {
511
- 'color': 'white'
512
- });
513
- entity.setAttribute('geometry', {
514
- height: entityGeometry.height + 0.1,
515
- depth: entityGeometry.depth + 0.1,
516
- width: entityGeometry.width + 0.1
517
- });
518
- legend = generateLegend(figures[i].name, self.data.legend_scale, 'white', 'black', JSON.parse(entity.getAttribute('babiaRawData')), self.data.height, self.data.area, self.data.depth, self.data.width, self.data.color);
519
- let worldPos = new THREE.Vector3();
520
- let coordinates = worldPos.setFromMatrixPosition(entity.object3D.matrixWorld);
521
- let height_real = new THREE.Box3().setFromObject(entity.object3D)
522
- let coordinatesFinal = {
523
- x: coordinates.x,
524
- y: height_real.max.y + 1 + self.data.height_building_legend,
525
- z: coordinates.z
526
- }
527
- legend.setAttribute('position', coordinatesFinal)
528
- legend.setAttribute('visible', true);
529
- self.el.parentElement.appendChild(legend);
530
- }
531
-
532
- // Add to the elements that has the legend activated
533
- self.entitiesWithLegend.push(entity)
534
- }
535
-
536
- })
537
-
538
- entity.addEventListener('mouseenter', function () {
539
- if (!alreadyActive) {
540
- entityGeometry = entity.getAttribute('geometry')
541
- let boxPosition = entity.getAttribute("position")
542
- entity.setAttribute('position', boxPosition)
543
- entity.setAttribute('babiaxrFirstColor', entity.getAttribute("material")["color"])
544
- entity.setAttribute('material', {
545
- 'color': 'white'
546
- });
547
- entity.setAttribute('geometry', {
548
- height: entityGeometry.height + 0.1,
549
- depth: entityGeometry.depth + 0.1,
550
- width: entityGeometry.width + 0.1
551
- });
552
- legend = generateLegend(figures[i].name, self.data.legend_scale, 'white', 'black', JSON.parse(entity.getAttribute('babiaRawData')), self.data.height, self.data.area, self.data.depth, self.data.width, self.data.color);
553
- let worldPos = new THREE.Vector3();
554
- let coordinates = worldPos.setFromMatrixPosition(entity.object3D.matrixWorld);
555
- let height_real = new THREE.Box3().setFromObject(entity.object3D)
556
- let coordinatesFinal = {
557
- x: coordinates.x,
558
- y: height_real.max.y + 1 + self.data.height_building_legend,
559
- z: coordinates.z
560
- }
561
- legend.setAttribute('position', coordinatesFinal)
562
- legend.setAttribute('visible', true);
563
- self.el.parentElement.appendChild(legend);
564
- }
565
-
566
- });
567
- entity.addEventListener('mouseleave', function () {
568
- if (!alreadyActive && legend) {
569
- legend.setAttribute('visible', false);
570
- entity.setAttribute('geometry', {
571
- height: entityGeometry.height - 0.1,
572
- depth: entityGeometry.depth - 0.1,
573
- width: entityGeometry.width - 0.1
574
- });
575
- entity.setAttribute('material', {
576
- 'color': entity.getAttribute('babiaxrFirstColor')
577
- });
578
- self.el.parentElement.removeChild(legend)
579
- legend = undefined
580
- }
581
- });
582
- }
397
+ this.addEvents(entity, figures[i]);
583
398
 
584
399
  element.appendChild(entity);
585
400
  }
@@ -693,28 +508,30 @@ AFRAME.registerComponent('babia-boats', {
693
508
  entity = document.getElementById(figures[i].id);
694
509
  // Creating... (next ticks)
695
510
  if (figures[i].inserted) {
511
+
512
+ //TODO: This code increments the opacity in the animation part, but it adds several performance issues
696
513
  //Increment opacity
697
- let opa_inc = delta / this.duration;
698
- let opacity = parseFloat(entity.getAttribute('material').opacity);
699
- if (opacity + opa_inc < 1) {
700
- opacity += opa_inc;
701
- } else {
702
- opacity = 1.0;
703
- figures[i].inserted = false;
704
- }
705
- setOpacity(entity, opacity);
514
+ // let opa_inc = delta / this.duration;
515
+ // let opacity = parseFloat(entity.getAttribute('material').opacity);
516
+ // if (opacity + opa_inc < 1) {
517
+ // opacity += opa_inc;
518
+ // } else {
519
+ // opacity = 1.0;
520
+ // figures[i].inserted = false;
521
+ // }
522
+ //setOpacity(entity, opacity);
706
523
 
707
524
  // If animation stops before finish
708
525
  let cond = 'id=' + figures[i].id
709
- if (findIndex(self.figures_in, cond) < 0){
526
+ if (findIndex(self.figures_in, cond) < 0) {
710
527
  self.figures_in.push(figures[i])
711
528
  }
712
529
 
713
- } else {
530
+ } else {
714
531
  // find index in old_figures
715
532
  let cond = 'id=' + figures[i].id
716
533
  let index = findIndex(figures_old, cond)
717
- if (index < 0 ){
534
+ if (index < 0) {
718
535
  // encontrar el elemento que no esta en la escena con id y darle opacidad
719
536
  // y cambiar sus propiedades a la nueva si es necesario
720
537
  figures[i].inserted = true;
@@ -749,12 +566,13 @@ AFRAME.registerComponent('babia-boats', {
749
566
  }
750
567
 
751
568
  let new_entity = this.createElement(figures[i], position);
752
- if (figures[i].children) {
753
- this.drawElements(new_entity, figures[i].children, figures[i].translate_matrix);
754
- }
569
+ this.addEvents(new_entity, figures[i]);
755
570
 
756
- //Opacity 0
757
- setOpacity(new_entity, 0);
571
+ //TODO: bad perfomance when Opacity 0 at the beginning
572
+ //setOpacity(new_entity, 0);
573
+
574
+ // New building and quarter, it appears with 0.5 opacity
575
+ setOpacity(new_entity, 0.5);
758
576
 
759
577
  element.appendChild(new_entity);
760
578
  figures[i].inserted = true;
@@ -763,51 +581,70 @@ AFRAME.registerComponent('babia-boats', {
763
581
 
764
582
  // Delete figures
765
583
  let opa_dec = delta / this.duration;
766
- for (let i in figures_old){
584
+ for (let i in figures_old) {
585
+ let deleted = false;
767
586
  let cond = 'id=' + figures_old[i].id
768
587
  let index = findIndex(figures, cond)
769
- if (index < 0){
770
- if (findIndex(self.figures_del, cond) < 0){
588
+ if (index < 0) {
589
+ if (findIndex(self.figures_del, cond) < 0) {
771
590
  self.figures_del.push(figures_old[i])
772
591
  }
773
- let entity_del = document.getElementById(figures_old[i].id)
774
- let opacity = parseFloat(entity_del.getAttribute('material').opacity);
775
- if (opacity - opa_dec > 0) {
776
- opacity -= opa_dec;
777
- } else {
778
- opacity = 0.0;
592
+ let entity_del = document.getElementById(figures_old[i].id);
593
+ if (entity_del) {
594
+
595
+ //TODO: Bad perfomance issue when changing dinamically the opacity, better to just make it non vissible
596
+ entity_del.object3D.visible = false
597
+ entity_del.remove();
598
+
599
+ // let opacity = parseFloat(entity_del.components.material.opacity);
600
+ // if (opacity - opa_dec > 0) {
601
+ // opacity -= opa_dec;
602
+ // } else {
603
+ // opacity = 0.0;
604
+ // deleted = true;
605
+ // self.figures_del.pop(figures_old[i]);
606
+ // }
607
+ // setOpacity(entity_del, opacity);
608
+ // if (deleted) {
609
+ // entity_del.remove();
610
+ // }
779
611
  }
780
- setOpacity(entity_del, opacity);
781
612
  }
782
613
  }
783
614
  },
784
615
 
785
- setFigures: function (figures, translate){
616
+ setFigures: function (figures, translate) {
786
617
  figures.forEach(figure => {
787
618
  let entity = document.getElementById(figure.id);
788
- if (entity.getAttribute('width') != figure.width) {
789
- entity.setAttribute('width', figure.width);
790
- }
791
- if (entity.getAttribute('height') != figure.height) {
792
- entity.setAttribute('height', figure.height);
793
- }
794
- if (entity.getAttribute('depth') != figure.depth) {
795
- entity.setAttribute('depth', figure.depth);
796
- }
797
- entity.setAttribute('position', {
798
- x: figure.posX - translate.x,
799
- y: (parseFloat(figure.height) + translate.y) / 2,
800
- z: - figure.posY + translate.z
801
- });
619
+ if (entity) {
620
+ if (entity.getAttribute('width') != figure.width) {
621
+ entity.setAttribute('width', figure.width);
622
+ }
623
+ if (entity.getAttribute('height') != figure.height) {
624
+ entity.setAttribute('height', figure.height);
625
+ }
626
+ if (entity.getAttribute('depth') != figure.depth) {
627
+ entity.setAttribute('depth', figure.depth);
628
+ }
802
629
 
803
- if (figure.children){
804
- this.setFigures(figure.children, figure.translate_matrix);
630
+ //TODO: Full opacity because it was in 0.5 if new building/quarter
631
+ if(entity.components.material.data.opacity < 1){
632
+ setOpacity(entity, 1)
633
+ }
634
+
635
+ entity.object3D.position.set(
636
+ figure.posX - translate.x,
637
+ ((parseFloat(figure.height) + translate.y) / 2),
638
+ (- figure.posY + translate.z),
639
+ )
640
+ if (figure.children) {
641
+ this.setFigures(figure.children, figure.translate_matrix);
642
+ }
805
643
  }
806
644
  });
807
645
  },
808
646
 
809
647
  resize: function (entity, new_time, delta, figure, figure_old) {
810
- //console.log(entity.id)
811
648
  if (((new_time - this.start_time) < this.duration) &&
812
649
  ((figure.width != figure_old.width) ||
813
650
  (figure.height != figure_old.height) ||
@@ -851,6 +688,7 @@ AFRAME.registerComponent('babia-boats', {
851
688
  entity.setAttribute('width', new_width);
852
689
  entity.setAttribute('height', new_height);
853
690
  entity.setAttribute('depth', new_depth);
691
+ entity.babiaRawData = figure.rawData
854
692
 
855
693
  } else if (((new_time - this.start_time) > this.duration) &&
856
694
  ((figure.width != figure_old.width) ||
@@ -860,7 +698,7 @@ AFRAME.registerComponent('babia-boats', {
860
698
  entity.setAttribute('width', figure.width);
861
699
  entity.setAttribute('height', figure.height);
862
700
  entity.setAttribute('depth', figure.depth);
863
- entity.setAttribute('babiaRawData', JSON.stringify(figure.rawData))
701
+ entity.babiaRawData = figure.rawData
864
702
  }
865
703
  },
866
704
 
@@ -876,9 +714,9 @@ AFRAME.registerComponent('babia-boats', {
876
714
  let inc_y = (delta * dist_y) / (2 * this.duration);
877
715
  let inc_z = (delta * dist_z) / this.duration;
878
716
 
879
- let last_x = parseFloat(entity.getAttribute('position').x);
880
- let last_y = parseFloat(entity.getAttribute('position').y);
881
- let last_z = parseFloat(entity.getAttribute('position').z);
717
+ let last_x = parseFloat(entity.object3D.position.x);
718
+ let last_y = parseFloat(entity.object3D.position.y);
719
+ let last_z = parseFloat(entity.object3D.position.z);
882
720
 
883
721
  let new_x = last_x - inc_x;
884
722
  let new_y = last_y + inc_y;
@@ -886,18 +724,18 @@ AFRAME.registerComponent('babia-boats', {
886
724
 
887
725
 
888
726
  // Update entity
889
- entity.setAttribute('position', {
890
- x: new_x,
891
- y: new_y,
892
- z: new_z
893
- });
727
+ entity.object3D.position.set(
728
+ new_x,
729
+ new_y,
730
+ new_z
731
+ )
894
732
 
895
733
  } else if ((new_time - this.start_time) > this.duration) {
896
- entity.setAttribute('position', {
897
- x: figure.posX - translate.x,
898
- y: (parseFloat(figure.height) + translate.y) / 2,
899
- z: - figure.posY + translate.z
900
- });
734
+ entity.object3D.position.set(
735
+ (figure.posX - translate.x),
736
+ ((parseFloat(figure.height) + translate.y) / 2),
737
+ (- figure.posY + translate.z),
738
+ )
901
739
  }
902
740
  }
903
741
  },
@@ -933,7 +771,7 @@ AFRAME.registerComponent('babia-boats', {
933
771
  entity.setAttribute('depth', depth);
934
772
  // rawData building
935
773
  if (figure.rawData) {
936
- entity.setAttribute('babiaRawData', JSON.stringify(figure.rawData))
774
+ entity.babiaRawData = figure.rawData
937
775
  }
938
776
 
939
777
  // add into scene
@@ -954,23 +792,197 @@ AFRAME.registerComponent('babia-boats', {
954
792
  let data = this.data;
955
793
  this.newData = _data;
956
794
  this.babiaMetadata = { id: this.babiaMetadata.id++ };
957
-
795
+
958
796
  // If color metric activated, save in the metadata the max and min value for mapping
959
797
  if (data.color) {
960
798
  let [color_max, color_min] = getMaxMinColorValues(this.newData, data.color)
961
799
  this.babiaMetadata['color_max'] = color_max
962
800
  this.babiaMetadata['color_min'] = color_min
963
801
  }
964
-
802
+ this.notiBuffer.set(this.newData)
965
803
  // Create city
966
804
  this.updateChart(this.newData)
967
805
  },
806
+
807
+ addEvents: function (entity, figure) {
808
+ let self = this;
809
+ if (figure.children) {
810
+ // Quarter
811
+ let legend;
812
+ let transparentBox;
813
+ entity.addEventListener('click', function (e) {
814
+ // Just launch the event on the child
815
+ if (e.target !== this)
816
+ return;
817
+
818
+ if (legend) {
819
+ entity.removeChild(transparentBox)
820
+ self.el.parentElement.removeChild(legend)
821
+ legend = undefined
822
+ transparentBox = undefined
823
+
824
+ // Remove from the array that has the entity activated
825
+ const index = self.entitiesWithLegend.indexOf(entity);
826
+ if (index > -1) {
827
+ self.entitiesWithLegend.splice(index, 1);
828
+ }
829
+ } else {
830
+ transparentBox = document.createElement('a-entity');
831
+ transparentBox.setAttribute('class', 'babialegend')
832
+ let oldGeometry = entity.getAttribute('geometry')
833
+ let scale = self.el.getAttribute("scale")
834
+ let tsBoxHeight = oldGeometry.height + self.data.height_quarter_legend_box
835
+ if (scale) {
836
+ tsBoxHeight = ((oldGeometry.height + self.data.height_quarter_legend_box) / scale.y)
837
+ }
838
+ transparentBox.setAttribute('geometry', {
839
+ height: tsBoxHeight,
840
+ depth: oldGeometry.depth,
841
+ width: oldGeometry.width
842
+ });
843
+ transparentBox.setAttribute('material', {
844
+ 'visible': true,
845
+ 'opacity': 0.4
846
+ });
847
+ entity.appendChild(transparentBox)
848
+
849
+ legend = generateLegend(figure.name, self.data.legend_scale, self.data.legend_lookat, 'black', 'white');
850
+ let worldPos = new THREE.Vector3();
851
+ let coordinates = worldPos.setFromMatrixPosition(entity.object3D.matrixWorld);
852
+ let coordinatesFinal = {
853
+ x: coordinates.x,
854
+ y: self.data.height_quarter_legend_title,
855
+ z: coordinates.z
856
+ }
857
+ legend.setAttribute('position', coordinatesFinal)
858
+ legend.setAttribute('visible', true);
859
+ self.el.parentElement.appendChild(legend)
860
+
861
+ // Add to the elements that has the legend activated
862
+ self.entitiesWithLegend.push(entity)
863
+ }
864
+ })
865
+
866
+ this.drawElements(entity, figure.children, figure.translate_matrix);
867
+ } else {
868
+ // Building
869
+ let legend;
870
+ let entityGeometry;
871
+ let alreadyActive = false;
872
+
873
+ entity.addEventListener('click', function (e) {
874
+ if (e.target !== this)
875
+ return;
876
+
877
+ if (alreadyActive) {
878
+ legend.setAttribute('visible', false);
879
+ entity.setAttribute('geometry', {
880
+ height: entityGeometry.height - 0.1,
881
+ depth: entityGeometry.depth - 0.1,
882
+ width: entityGeometry.width - 0.1
883
+ });
884
+ entity.setAttribute('material', {
885
+ 'color': entity.getAttribute('babiaxrFirstColor')
886
+ });
887
+ self.el.parentElement.removeChild(legend)
888
+ legend = undefined
889
+ alreadyActive = false
890
+
891
+ // Remove from the array that has the entity activated
892
+ const index = self.entitiesWithLegend.indexOf(entity);
893
+ if (index > -1) {
894
+ self.entitiesWithLegend.splice(index, 1);
895
+ }
896
+ } else {
897
+ alreadyActive = true
898
+
899
+ // If clicked again but not mouseover
900
+ if (!legend) {
901
+ // COPY FROM 626
902
+ entityGeometry = entity.getAttribute('geometry')
903
+ let boxPosition = entity.getAttribute("position")
904
+ entity.setAttribute('position', boxPosition)
905
+ entity.setAttribute('babiaxrFirstColor', entity.getAttribute("material")["color"])
906
+ entity.setAttribute('material', {
907
+ 'color': 'white'
908
+ });
909
+ entity.setAttribute('geometry', {
910
+ height: entityGeometry.height + 0.1,
911
+ depth: entityGeometry.depth + 0.1,
912
+ width: entityGeometry.width + 0.1
913
+ });
914
+ legend = generateLegend(figure.name, self.data.legend_scale, self.data.legend_lookat, 'white', 'black', entity.babiaRawData, self.data.height, self.data.area, self.data.depth, self.data.width, self.data.color);
915
+ let worldPos = new THREE.Vector3();
916
+ let coordinates = worldPos.setFromMatrixPosition(entity.object3D.matrixWorld);
917
+ let height_real = new THREE.Box3().setFromObject(entity.object3D)
918
+ let coordinatesFinal = {
919
+ x: coordinates.x,
920
+ y: height_real.max.y + 1 + self.data.height_building_legend,
921
+ z: coordinates.z
922
+ }
923
+ legend.setAttribute('position', coordinatesFinal)
924
+ legend.setAttribute('visible', true);
925
+ self.el.parentElement.appendChild(legend);
926
+ }
927
+
928
+ // Add to the elements that has the legend activated
929
+ self.entitiesWithLegend.push(entity)
930
+ }
931
+
932
+ })
933
+
934
+ entity.addEventListener('mouseenter', function () {
935
+ if (!alreadyActive) {
936
+ entityGeometry = entity.getAttribute('geometry')
937
+ let boxPosition = entity.getAttribute("position")
938
+ entity.setAttribute('position', boxPosition)
939
+ entity.setAttribute('babiaxrFirstColor', entity.getAttribute("material")["color"])
940
+ entity.setAttribute('material', {
941
+ 'color': 'white'
942
+ });
943
+ entity.setAttribute('geometry', {
944
+ height: entityGeometry.height + 0.1,
945
+ depth: entityGeometry.depth + 0.1,
946
+ width: entityGeometry.width + 0.1
947
+ });
948
+ legend = generateLegend(figure.name, self.data.legend_scale, self.data.legend_lookat, 'white', 'black', entity.babiaRawData, self.data.height, self.data.area, self.data.depth, self.data.width, self.data.color);
949
+ let worldPos = new THREE.Vector3();
950
+ let coordinates = worldPos.setFromMatrixPosition(entity.object3D.matrixWorld);
951
+ let height_real = new THREE.Box3().setFromObject(entity.object3D)
952
+ let coordinatesFinal = {
953
+ x: coordinates.x,
954
+ y: height_real.max.y + 1 + self.data.height_building_legend,
955
+ z: coordinates.z
956
+ }
957
+ legend.setAttribute('position', coordinatesFinal)
958
+ legend.setAttribute('visible', true);
959
+ self.el.parentElement.appendChild(legend);
960
+ }
961
+
962
+ });
963
+ entity.addEventListener('mouseleave', function () {
964
+ if (!alreadyActive && legend) {
965
+ legend.setAttribute('visible', false);
966
+ entity.setAttribute('geometry', {
967
+ height: entityGeometry.height - 0.1,
968
+ depth: entityGeometry.depth - 0.1,
969
+ width: entityGeometry.width - 0.1
970
+ });
971
+ entity.setAttribute('material', {
972
+ 'color': entity.getAttribute('babiaxrFirstColor')
973
+ });
974
+ self.el.parentElement.removeChild(legend)
975
+ legend = undefined
976
+ }
977
+ });
978
+ }
979
+ },
968
980
  })
969
981
 
970
982
  /**
971
983
  * This function generate a plane at the top of the building with the desired text
972
984
  */
973
- let generateLegend = (name, legend_scale, colorPlane, colorText, data, fheight, farea, fdepth, fwidth, fcolor) => {
985
+ let generateLegend = (name, legend_scale, lookat, colorPlane, colorText, data, fheight, farea, fdepth, fwidth, fcolor) => {
974
986
  let width = 2;
975
987
  let height = 1;
976
988
  if (name.length > 16)
@@ -1011,7 +1023,7 @@ let generateLegend = (name, legend_scale, colorPlane, colorText, data, fheight,
1011
1023
  }
1012
1024
 
1013
1025
  let entity = document.createElement('a-plane');
1014
- entity.setAttribute('babia-lookat', "[camera]");
1026
+ entity.setAttribute('babia-lookat', lookat);
1015
1027
 
1016
1028
  entity.setAttribute('rotation', { x: 0, y: 0, z: 0 });
1017
1029
  entity.setAttribute('height', height);
@@ -1097,8 +1109,8 @@ function heatMapColorforValue(val, max, min) {
1097
1109
  let findIndex = (list, condicion) => {
1098
1110
  condicion = condicion.split('=')
1099
1111
  //console.log(condicion)
1100
- for (i = 0; i < list.length; i++){
1101
- if (list[i][condicion[0]] === condicion[1]){
1112
+ for (i = 0; i < list.length; i++) {
1113
+ if (list[i][condicion[0]] === condicion[1]) {
1102
1114
  return i
1103
1115
  }
1104
1116
  }