aframe-babia-components 1.4.0 → 1.5.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/common/city-history.js +53 -0
- package/components/visualizers/babia-boats.js +229 -2060
- package/components/visualizers/babia-city-evocells.js +189 -0
- package/components/visualizers/babia-city-evostreets.js +163 -0
- package/components/visualizers/babia-city-gospermap.js +190 -0
- package/components/visualizers/babia-city-hexgrid.js +6 -0
- package/components/visualizers/babia-city-hilbert.js +5 -0
- package/components/visualizers/babia-city-history-resistant.js +5 -0
- package/components/visualizers/babia-city-morton.js +5 -0
- package/components/visualizers/babia-city-voronoi.js +3 -211
- package/components/visualizers/boats/interactions.js +194 -0
- package/components/visualizers/boats/layout.js +148 -0
- package/components/visualizers/boats/legend.js +135 -0
- package/components/visualizers/evocells/history.js +69 -0
- package/components/visualizers/evocells/layout.js +170 -0
- package/components/visualizers/evocells/rectangles.js +183 -0
- package/components/visualizers/evostreets/layout.js +171 -0
- package/components/visualizers/gospermap/curve.js +91 -0
- package/components/visualizers/gospermap/layout.js +221 -0
- package/components/visualizers/gospermap/prisms.js +152 -0
- package/components/visualizers/gospermap/regions.js +99 -0
- package/components/visualizers/gospermap/selection.js +65 -0
- package/components/visualizers/hexgrid/grid.js +70 -0
- package/components/visualizers/hexgrid/layout.js +90 -0
- package/components/visualizers/hexgrid/prisms.js +71 -0
- package/components/visualizers/hilbert/layout.js +131 -0
- package/components/visualizers/history-resistant/layout.js +128 -0
- package/components/visualizers/morton/layout.js +79 -0
- package/components/visualizers/peak-lot-plan.js +72 -0
- package/components/visualizers/prism-city.js +226 -0
- package/components/visualizers/voronoi/history.js +35 -0
- package/components/visualizers/voronoi/hover-legend.js +6 -1
- package/components/visualizers/voronoi/layout.js +58 -23
- package/dist/aframe-babia-components.js +5872 -3118
- package/dist/aframe-babia-components.min.js +1 -1
- package/dist/aframe-babia-components.min.js.map +1 -1
- package/index.js +7 -0
- package/package.json +1 -1
|
@@ -1,2034 +1,279 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
1
|
+
/* global AFRAME */
|
|
2
|
+
const {colors, findProdComponent, parseJson} = require('../others/common');
|
|
3
|
+
const {NotiBuffer} = require('../../common/noti-buffer');
|
|
4
|
+
const {collectMetadata, makeFigures, buildingHeight} = require('./boats/layout');
|
|
5
|
+
const {BoatInteractions} = require('./boats/interactions');
|
|
6
|
+
const {DEFAULT_TEXT} = require('./boats/legend');
|
|
5
7
|
require('./boats/windows');
|
|
6
8
|
|
|
7
|
-
const
|
|
9
|
+
const THREE = AFRAME.THREE;
|
|
10
|
+
const origin = {x: 0, y: 0, z: 0};
|
|
11
|
+
const labelOptions = new Set(['legend_text', 'legend_scale', 'legend_lookat', 'legendsAsChildren', 'legendsAsChildrenHeight',
|
|
12
|
+
'height_building_legend', 'height_quarter_legend_title', 'height_quarter_legend_box', 'hideQuarterBoxLegend']);
|
|
8
13
|
|
|
9
|
-
/* global AFRAME */
|
|
10
|
-
if (typeof AFRAME === 'undefined') {
|
|
11
|
-
throw new Error('Component attempted to register before AFRAME was available.');
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* A-Charts component for A-Frame.
|
|
16
|
-
*/
|
|
17
14
|
AFRAME.registerComponent('babia-boats', {
|
|
18
15
|
schema: {
|
|
19
|
-
data: {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
zone_elevation: { type: 'number', default: 0.01 },
|
|
38
|
-
separation: { type: 'number', default: 0.1 },
|
|
39
|
-
extra: { type: 'number', default: 1.0 },
|
|
40
|
-
levels: { type: 'number' },
|
|
41
|
-
building_color: { type: 'string', default: "#E6B9A1" },
|
|
42
|
-
buildingAlpha: { type: 'number', default: 1 },
|
|
43
|
-
gradientBaseColor: { type: 'boolean', default: false },
|
|
44
|
-
base_color: { type: 'color', default: '#98e690' },
|
|
45
|
-
baseAlpha: { type: 'number', default: 1 },
|
|
46
|
-
// To add into the doc
|
|
47
|
-
height_quarter_legend_box: { type: 'number', default: 11 },
|
|
48
|
-
height_quarter_legend_title: { type: 'number', default: 12 },
|
|
49
|
-
height_building_legend: { type: 'number', default: 0 },
|
|
50
|
-
legend_scale: { type: 'number', default: 1 },
|
|
51
|
-
legend_lookat: { type: 'string', default: "[camera]" },
|
|
52
|
-
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}' },
|
|
53
|
-
legendsAsChildren: { type: 'boolean', default: false },
|
|
54
|
-
legendsAsChildrenHeight: { type: 'number', default: 3 },
|
|
55
|
-
metricsInfoId: { type: 'string', default: "" },
|
|
56
|
-
highlightQuarter: { type: 'boolean', default: false },
|
|
57
|
-
hideQuarterBoxLegend: { type: 'boolean', default: false },
|
|
58
|
-
highlightQuarterByClick: { type: 'boolean', default: false },
|
|
59
|
-
field: { type: 'string', default: 'uid' },
|
|
60
|
-
|
|
61
|
-
// Numeric color legend entity to hide/show
|
|
62
|
-
numericColorLegendId: { type: 'string' },
|
|
63
|
-
|
|
64
|
-
// Highlight building by field
|
|
65
|
-
highlightBuildingByField: { type: 'string' },
|
|
66
|
-
highlightBuildingByFieldColor: { type: 'string', default: 'white' },
|
|
67
|
-
|
|
68
|
-
// Wireframe & Transparency by repeated IDs
|
|
69
|
-
wireframeByRepeatedField: { type: 'string' },
|
|
70
|
-
transparent80ByRepeatedField: { type: 'string' },
|
|
71
|
-
transparent20ByRepeatedField: { type: 'string' },
|
|
72
|
-
|
|
73
|
-
// Autoscale when animating or starting
|
|
74
|
-
autoscale: { type: 'boolean', default: false },
|
|
75
|
-
autoscaleSizeX: { type: 'number', default: 3 },
|
|
76
|
-
autoscaleSizeZ: { type: 'number', default: 3 },
|
|
77
|
-
//autoscaleSizeY: { type: 'number', default: 2 }
|
|
78
|
-
|
|
79
|
-
// New layout
|
|
80
|
-
treeLayout: { type: 'boolean', default: false },
|
|
81
|
-
treeQuartersLevelHeight: { type: 'number', default: 0.2 },
|
|
82
|
-
treeFixQuarterHeight: { type: 'boolean', default: false },
|
|
83
|
-
treeHideOneSonQuarters: { type: 'boolean', default: false }
|
|
84
|
-
},
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Entities with legend activated
|
|
88
|
-
*/
|
|
89
|
-
entitiesWithLegend: [],
|
|
90
|
-
legendsActive: [],
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Querier component target
|
|
94
|
-
*/
|
|
95
|
-
dataComponent: undefined,
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Where the data is gonna be stored
|
|
99
|
-
*/
|
|
100
|
-
newData: undefined,
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Where the metaddata is gonna be stored
|
|
104
|
-
*/
|
|
105
|
-
babiaMetadata: {
|
|
106
|
-
id: 0
|
|
16
|
+
data: {type: 'asset'}, from: {type: 'string'}, field: {default: 'uid'},
|
|
17
|
+
width: {default: 'width'}, depth: {default: 'depth'}, height: {default: 'height'},
|
|
18
|
+
area: {type: 'string'}, color: {type: 'string'}, windows: {type: 'string'}, glow: {type: 'string'},
|
|
19
|
+
border: {default: 0.5}, separation: {default: 0.1}, extra: {default: 1}, levels: {type: 'number'},
|
|
20
|
+
maxBuildingHeight: {default: 2}, minBuildingHeight: {default: 0.03}, diffBuildingHeight: {default: false},
|
|
21
|
+
zone_elevation: {default: 0.01}, building_color: {default: '#E6B9A1'}, buildingAlpha: {default: 1},
|
|
22
|
+
gradientBaseColor: {default: false}, base_color: {type: 'color', default: '#98e690'}, baseAlpha: {default: 1},
|
|
23
|
+
height_quarter_legend_box: {default: 11}, height_quarter_legend_title: {default: 12},
|
|
24
|
+
height_building_legend: {default: 0}, legend_scale: {default: 1}, legend_lookat: {default: '[camera]'},
|
|
25
|
+
legend_text: {default: DEFAULT_TEXT}, legendsAsChildren: {default: false}, legendsAsChildrenHeight: {default: 3},
|
|
26
|
+
metricsInfoId: {type: 'string'}, numericColorLegendId: {type: 'string'},
|
|
27
|
+
highlightQuarter: {default: false}, hideQuarterBoxLegend: {default: false}, highlightQuarterByClick: {default: false},
|
|
28
|
+
highlightBuildingByField: {type: 'string'}, highlightBuildingByFieldColor: {default: 'white'},
|
|
29
|
+
wireframeByRepeatedField: {type: 'string'}, transparent80ByRepeatedField: {type: 'string'},
|
|
30
|
+
transparent20ByRepeatedField: {type: 'string'},
|
|
31
|
+
autoscale: {default: false}, autoscaleSizeX: {default: 3}, autoscaleSizeZ: {default: 3},
|
|
32
|
+
treeLayout: {default: false}, treeQuartersLevelHeight: {default: 0.2},
|
|
33
|
+
treeFixQuarterHeight: {default: false}, treeHideOneSonQuarters: {default: false}
|
|
107
34
|
},
|
|
108
35
|
|
|
109
|
-
/**
|
|
110
|
-
* List of visualization properties
|
|
111
|
-
*/
|
|
112
36
|
visProperties: ['height', 'area', 'width', 'depth', 'color', 'windows', 'glow'],
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Set if component needs multiple instancing.
|
|
116
|
-
*/
|
|
117
|
-
multiple: false,
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
*
|
|
121
|
-
*/
|
|
122
37
|
duration: 2000,
|
|
123
|
-
|
|
124
|
-
figures_in: [],
|
|
125
|
-
animation: false,
|
|
126
|
-
/**
|
|
127
|
-
* Called once when component is attached. Generally for initial setup.
|
|
128
|
-
*/
|
|
38
|
+
|
|
129
39
|
init: function () {
|
|
130
40
|
this.notiBuffer = new NotiBuffer();
|
|
41
|
+
this.babiaMetadata = {id: 0};
|
|
42
|
+
this.boxes = new Map();
|
|
43
|
+
this.entitiesWithLegend = [];
|
|
44
|
+
this.legendsActive = [];
|
|
45
|
+
this.interactions = new BoatInteractions(this);
|
|
46
|
+
this.tracks = [];
|
|
47
|
+
this.inserted = [];
|
|
48
|
+
this.lines = [];
|
|
49
|
+
this.figures = [];
|
|
131
50
|
},
|
|
132
|
-
/**
|
|
133
|
-
* Called when component is attached and when component data changes.
|
|
134
|
-
* Generally modifies the entity based on the data.
|
|
135
|
-
*/
|
|
136
51
|
|
|
137
52
|
update: function (oldData) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
if (!currentScale) {
|
|
155
|
-
currentScale = { x: 1, y: 1, z: 1 }
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
this.el.setAttribute("scale", { x: eval(this.data.autoscaleSizeX / finalSizeX) * currentScale.x, y: currentScale.y, z: eval(this.data.autoscaleSizeZ / finalSizeZ) * currentScale.z })
|
|
159
|
-
},
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Called on each scene tick.
|
|
163
|
-
*/
|
|
164
|
-
tick: function (t, delta) {
|
|
165
|
-
let self = this;
|
|
166
|
-
|
|
167
|
-
// First time to autoscale
|
|
168
|
-
if (this.data.autoscale && !this.alreadyAutoscaled) {
|
|
169
|
-
let bbox = new THREE.Box3().setFromObject(this.el.object3D)
|
|
170
|
-
if (bbox.min.x !== Infinity) {
|
|
171
|
-
this.autoscaleBoats()
|
|
172
|
-
this.alreadyAutoscaled = true
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (this.animation) {
|
|
177
|
-
let t = { x: 0, y: 0, z: 0 };
|
|
178
|
-
if ((Date.now() - this.start_time) > this.duration) {
|
|
179
|
-
this.animation = false;
|
|
180
|
-
this.setFigures(this.figures, t);
|
|
181
|
-
|
|
182
|
-
// Animation finished, set autoscale if activated
|
|
183
|
-
if (this.data.autoscale) {
|
|
184
|
-
this.autoscaleBoats()
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
//Reactivate legends, check PERFORMANCE
|
|
188
|
-
self.entitiesWithLegend = self.entitiesWithLegend.filter(item => document.getElementById(item.entity.id))
|
|
189
|
-
self.entitiesWithLegend.forEach(item => {
|
|
190
|
-
let entity = item.entity
|
|
191
|
-
let figure = item.figure
|
|
192
|
-
|
|
193
|
-
if (figure.children) {
|
|
194
|
-
// Quarter
|
|
195
|
-
entity.legend = generateLegend(entity.babiaRawData || {}, {
|
|
196
|
-
name: figure.name,
|
|
197
|
-
scale: self.data.legend_scale,
|
|
198
|
-
lookat: self.data.legend_lookat,
|
|
199
|
-
template: self.data.legend_text || '{name}',
|
|
200
|
-
colorPlane: 'black',
|
|
201
|
-
colorText: 'white',
|
|
202
|
-
isQuarter: true,
|
|
203
|
-
fields: {}
|
|
204
|
-
});
|
|
205
|
-
let worldPos = new THREE.Vector3();
|
|
206
|
-
let coordinates = worldPos.setFromMatrixPosition(entity.object3D.matrixWorld);
|
|
207
|
-
let coordinatesFinal = {
|
|
208
|
-
x: coordinates.x,
|
|
209
|
-
y: self.data.height_quarter_legend_title,
|
|
210
|
-
z: coordinates.z
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// If legend is a child of the building/quarter
|
|
214
|
-
if (self.data.legendsAsChildren) {
|
|
215
|
-
entity.legend.setAttribute('position', { x: 0, y: self.data.legendsAsChildrenHeight, z: 0 })
|
|
216
|
-
entity.legend.setAttribute('visible', true);
|
|
217
|
-
entity.appendChild(entity.legend)
|
|
218
|
-
} else {
|
|
219
|
-
entity.legend.setAttribute('position', coordinatesFinal)
|
|
220
|
-
entity.legend.setAttribute('visible', true);
|
|
221
|
-
self.el.parentElement.appendChild(entity.legend)
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
self.legendsActive.push(entity.legend)
|
|
226
|
-
entity.alreadyActive = true
|
|
227
|
-
} else {
|
|
228
|
-
// Building
|
|
229
|
-
entity.legend = entity.legend = generateLegend(entity.babiaRawData, {
|
|
230
|
-
name: figure.name,
|
|
231
|
-
scale: self.data.legend_scale,
|
|
232
|
-
lookat: self.data.legend_lookat,
|
|
233
|
-
template: self.data.legend_text,
|
|
234
|
-
colorPlane: 'white',
|
|
235
|
-
colorText: 'black',
|
|
236
|
-
isQuarter: false,
|
|
237
|
-
fields: {
|
|
238
|
-
height: self.data.height,
|
|
239
|
-
area: self.data.area,
|
|
240
|
-
width: self.data.width,
|
|
241
|
-
depth: self.data.depth,
|
|
242
|
-
color: self.data.color,
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
let worldPos = new THREE.Vector3();
|
|
246
|
-
let coordinates = worldPos.setFromMatrixPosition(entity.object3D.matrixWorld);
|
|
247
|
-
let height_real = new THREE.Box3().setFromObject(entity.object3D)
|
|
248
|
-
let coordinatesFinal = {
|
|
249
|
-
x: coordinates.x,
|
|
250
|
-
y: height_real.max.y + 1 + self.data.height_building_legend,
|
|
251
|
-
z: coordinates.z
|
|
252
|
-
}
|
|
253
|
-
entity.legend.setAttribute('position', coordinatesFinal)
|
|
254
|
-
entity.legend.setAttribute('visible', true);
|
|
255
|
-
self.el.parentElement.appendChild(entity.legend);
|
|
256
|
-
|
|
257
|
-
self.legendsActive.push(entity.legend)
|
|
258
|
-
entity.alreadyActive = true
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
} else {
|
|
262
|
-
this.Animation(this.el, this.figures, this.figures_old, delta, t, t);
|
|
53
|
+
const {data, from} = this.data;
|
|
54
|
+
if (data !== oldData.data || (!data && from !== oldData.from)) {
|
|
55
|
+
this.unsubscribe();
|
|
56
|
+
if (data) return this.processData(parseJson(data));
|
|
57
|
+
const prod = (!from || document.getElementById(from)) && findProdComponent(this.data, this.el);
|
|
58
|
+
if (prod?.notiBuffer) {
|
|
59
|
+
this.prodComponent = prod;
|
|
60
|
+
if (prod.notiBuffer.data === undefined && this.boxes.size) this.processData([]);
|
|
61
|
+
this.notiBufferId = prod.notiBuffer.register(snapshot => this.processData(snapshot));
|
|
62
|
+
} else this.processData([]);
|
|
63
|
+
} else if (this.newData) {
|
|
64
|
+
const needsLayout = Object.keys(this.data).some(key => this.data[key] !== oldData[key] && !labelOptions.has(key));
|
|
65
|
+
if (needsLayout) this.processData(this.newData);
|
|
66
|
+
else {
|
|
67
|
+
for (const label of this.interactions.labels.values()) label.configure(this);
|
|
68
|
+
this.interactions.update();
|
|
263
69
|
}
|
|
264
70
|
}
|
|
265
71
|
},
|
|
266
72
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
this.
|
|
271
|
-
this.
|
|
272
|
-
this.
|
|
273
|
-
|
|
274
|
-
// when animation not finished, delete figures and opa 1 to inserted
|
|
275
|
-
if (this.animation) {
|
|
276
|
-
this.figures_del.forEach(figure => {
|
|
277
|
-
let entity = document.getElementById(figure.id);
|
|
278
|
-
if (entity) {
|
|
279
|
-
entity.remove();
|
|
280
|
-
}
|
|
281
|
-
})
|
|
282
|
-
this.figures_in.forEach(figure => {
|
|
283
|
-
let entity = document.getElementById(figure.id);
|
|
284
|
-
if (entity) {
|
|
285
|
-
setOpacity(entity, 1.0);
|
|
286
|
-
}
|
|
287
|
-
})
|
|
288
|
-
this.setFigures(this.figures, t);
|
|
289
|
-
this.animation = false;
|
|
290
|
-
this.figures_del = [];
|
|
291
|
-
this.figures_in = [];
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
this.figures_old = this.figures;
|
|
295
|
-
this.figures = [];
|
|
296
|
-
|
|
297
|
-
let el = this.el;
|
|
298
|
-
let elements = items
|
|
299
|
-
|
|
300
|
-
// Calculate Increment
|
|
301
|
-
let increment;
|
|
302
|
-
if (this.data.levels) {
|
|
303
|
-
increment = this.data.border * this.data.extra * this.data.levels;
|
|
304
|
-
} else {
|
|
305
|
-
// Find last level
|
|
306
|
-
let levels = getLevels(elements, 0);
|
|
307
|
-
//console.log("Levels:" + levels);
|
|
308
|
-
increment = this.data.border * this.data.extra * (levels + 1);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
// Register all figures before drawing
|
|
312
|
-
[x, y, t, this.figures] = this.generateElements(elements, this.figures, t, increment);
|
|
313
|
-
|
|
314
|
-
// Draw figures
|
|
315
|
-
t.x = 0;
|
|
316
|
-
t.z = 0;
|
|
317
|
-
if (this.figures_old.length == 0) {
|
|
318
|
-
// First, delete all elements of the component
|
|
319
|
-
while (this.el.firstChild)
|
|
320
|
-
this.el.firstChild.remove();
|
|
321
|
-
this.drawElements(el, this.figures, t);
|
|
322
|
-
} else {
|
|
323
|
-
if (this.figures_old !== this.figures) {
|
|
324
|
-
this.animation = true;
|
|
325
|
-
this.start_time = Date.now();
|
|
326
|
-
}
|
|
327
|
-
}
|
|
73
|
+
processData: function (items) {
|
|
74
|
+
this.newData = items;
|
|
75
|
+
this.babiaMetadata = collectMetadata(items, this.data, this.babiaMetadata.id + 1);
|
|
76
|
+
this.categoricColorMaps = Object.create(null);
|
|
77
|
+
this.updateChart(items);
|
|
78
|
+
this.updateMetricInfo();
|
|
79
|
+
this.notiBuffer.set(items);
|
|
328
80
|
},
|
|
329
81
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
* Each figure includes all data needed to visualize it (which will be done
|
|
348
|
-
* later, in another function).
|
|
349
|
-
*
|
|
350
|
-
* @param {*} elements Array of elements
|
|
351
|
-
* @param {*} figures Array of figures
|
|
352
|
-
* @param {*} translate Translation from the center
|
|
353
|
-
* @param {*} inc Increment
|
|
354
|
-
* @returns [width, depth, translate, figures]
|
|
355
|
-
*/
|
|
356
|
-
generateElements: function (elements, figures, translate, inc) {
|
|
357
|
-
const self = this;
|
|
358
|
-
const data = this.data;
|
|
359
|
-
|
|
360
|
-
var increment = inc;
|
|
361
|
-
|
|
362
|
-
// Vertical limits (of all figures up to now)
|
|
363
|
-
var limit_up = 0;
|
|
364
|
-
var limit_down = 0;
|
|
365
|
-
// Horizontal limits (of all figures up to now)
|
|
366
|
-
var limit_right = 0;
|
|
367
|
-
var limit_left = 0;
|
|
368
|
-
|
|
369
|
-
//Position of the center of current figure
|
|
370
|
-
var posX = 0;
|
|
371
|
-
var posY = 0;
|
|
372
|
-
|
|
373
|
-
// Aux variables to update limits
|
|
374
|
-
// Save max limits to update limits in the next step
|
|
375
|
-
var max_right = 0;
|
|
376
|
-
var max_left = 0;
|
|
377
|
-
var max_down = 0;
|
|
378
|
-
var max_up = 0;
|
|
379
|
-
|
|
380
|
-
// Control points
|
|
381
|
-
var current_vertical = 0;
|
|
382
|
-
var current_horizontal = 0;
|
|
383
|
-
|
|
384
|
-
// Controllers
|
|
385
|
-
var up = false;
|
|
386
|
-
var down = false;
|
|
387
|
-
var left = false;
|
|
388
|
-
var right = true;
|
|
389
|
-
|
|
390
|
-
/**
|
|
391
|
-
* Get each element and set its position respectly
|
|
392
|
-
* Then save all data in figures array
|
|
393
|
-
*/
|
|
394
|
-
for (let i = 0; i < elements.length; i++) {
|
|
395
|
-
// To do not overwrite newData
|
|
396
|
-
let element = {}
|
|
397
|
-
if (data.width) {
|
|
398
|
-
element.width = elements[i][data.width] || 0.5
|
|
399
|
-
};
|
|
400
|
-
if (data.depth) {
|
|
401
|
-
element.depth = elements[i][data.depth] || 0.5
|
|
402
|
-
};
|
|
403
|
-
if (data.height) {
|
|
404
|
-
let height_min = 0;
|
|
405
|
-
if (data.diffBuildingHeight) {
|
|
406
|
-
height_min = self.babiaMetadata['heightMin'];
|
|
407
|
-
};
|
|
408
|
-
element.height = self.normalizeValues(height_min,
|
|
409
|
-
self.babiaMetadata['heightMax'],
|
|
410
|
-
self.data.minBuildingHeight,
|
|
411
|
-
self.data.maxBuildingHeight,
|
|
412
|
-
elements[i][data.height]) || data.minBuildingHeight
|
|
413
|
-
};
|
|
414
|
-
if (data.area) {
|
|
415
|
-
element.area = elements[i][data.area] || 0.5;
|
|
416
|
-
element.width = element.depth = Math.sqrt(element.area);
|
|
417
|
-
}
|
|
418
|
-
if (elements[i].children) {
|
|
419
|
-
// There are elements hanging from this element
|
|
420
|
-
// so, it is a quarter. Let's run this function recursively
|
|
421
|
-
element.children = elements[i].children
|
|
422
|
-
var children = [];
|
|
423
|
-
var translate_matrix;
|
|
424
|
-
// Save Zone's parameters
|
|
425
|
-
// Check scale because it should be abosulte, not relative
|
|
426
|
-
let scale = self.el.getAttribute("scale")
|
|
427
|
-
if (!scale) {
|
|
428
|
-
scale = { x: 1, y: 1, z: 1 }
|
|
429
|
-
}
|
|
430
|
-
element.height = data.zone_elevation / scale.y;
|
|
431
|
-
increment -= data.border * data.extra;
|
|
432
|
-
|
|
433
|
-
// Tree layout
|
|
434
|
-
if (data.treeLayout) {
|
|
435
|
-
element.children.forEach(el => {
|
|
436
|
-
if (!el.children) {
|
|
437
|
-
element.treeMetaphorHeight = el[data.height]
|
|
438
|
-
return
|
|
439
|
-
}
|
|
440
|
-
});
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
[element.width, element.depth, translate_matrix, children]
|
|
444
|
-
= this.generateElements(element.children, children,
|
|
445
|
-
translate_matrix, increment);
|
|
446
|
-
translate_matrix.y = element.height;
|
|
447
|
-
increment = inc;
|
|
448
|
-
};
|
|
449
|
-
if (i == 0) {
|
|
450
|
-
// This is the first element to place
|
|
451
|
-
if (data.area && !elements[i].children) {
|
|
452
|
-
limit_up += Math.sqrt(element.area) / 2;
|
|
453
|
-
limit_down -= Math.sqrt(element.area) / 2;
|
|
454
|
-
limit_right += Math.sqrt(element.area) / 2;
|
|
455
|
-
limit_left -= Math.sqrt(element.area) / 2;
|
|
456
|
-
} else {
|
|
457
|
-
limit_up += element.depth / 2;
|
|
458
|
-
limit_down -= element.depth / 2;
|
|
459
|
-
limit_right += element.width / 2;
|
|
460
|
-
limit_left -= element.width / 2;
|
|
461
|
-
}
|
|
462
|
-
//console.log("==== RIGHT SIDE ====");
|
|
463
|
-
current_horizontal = limit_up
|
|
464
|
-
} else if (element.height > 0) {
|
|
465
|
-
console.log("Element: ", i);
|
|
466
|
-
console.log("Directions (up, right, down, left):",
|
|
467
|
-
up, right, down, left);
|
|
468
|
-
console.log("Current (vertical, horizontal):",
|
|
469
|
-
current_vertical, current_horizontal);
|
|
470
|
-
console.log("Limits (up, right, down, left):",
|
|
471
|
-
limit_up, limit_right, limit_down, limit_left);
|
|
472
|
-
console.log("Max (up, right, down, left):",
|
|
473
|
-
max_up, max_right, max_down, max_left);
|
|
474
|
-
console.log("Position (x, y):", posX, posY);
|
|
475
|
-
if (up) {
|
|
476
|
-
[current_vertical, posX, posY, max_up] =
|
|
477
|
-
this.UpSide(element, limit_up, current_vertical, max_up);
|
|
478
|
-
if (current_vertical > limit_right) {
|
|
479
|
-
max_right = current_vertical;
|
|
480
|
-
up = false;
|
|
481
|
-
right = true;
|
|
482
|
-
if (max_left < limit_left) {
|
|
483
|
-
limit_left = max_left;
|
|
484
|
-
}
|
|
485
|
-
current_horizontal = limit_up;
|
|
486
|
-
}
|
|
487
|
-
} else if (right) {
|
|
488
|
-
[current_horizontal, posX, posY, max_right] =
|
|
489
|
-
this.RightSide(element, limit_right, current_horizontal, max_right);
|
|
490
|
-
console.log("RIGHT", current_horizontal, posX, posY, max_right);
|
|
491
|
-
if (current_horizontal < limit_down) {
|
|
492
|
-
max_down = current_horizontal;
|
|
493
|
-
right = false;
|
|
494
|
-
down = true;
|
|
495
|
-
if (max_up > limit_up) {
|
|
496
|
-
limit_up = max_up;
|
|
497
|
-
}
|
|
498
|
-
current_vertical = limit_right;
|
|
499
|
-
}
|
|
500
|
-
console.log("RIGHT2",
|
|
501
|
-
current_horizontal, current_vertical, posX, posY, max_right);
|
|
502
|
-
} else if (down) {
|
|
503
|
-
console.log("DOWN1 (element, limit_down, current_vertical, max_down):",
|
|
504
|
-
element, limit_down, current_vertical, max_down);
|
|
505
|
-
[current_vertical, posX, posY, max_down] = this.DownSide(element, limit_down, current_vertical, max_down);
|
|
506
|
-
console.log("DOWN2", current_vertical, posX, posY, max_down);
|
|
507
|
-
if (current_vertical < limit_left) {
|
|
508
|
-
max_left = current_vertical;
|
|
509
|
-
down = false;
|
|
510
|
-
left = true;
|
|
511
|
-
if (max_right > limit_right) {
|
|
512
|
-
limit_right = max_right;
|
|
513
|
-
}
|
|
514
|
-
current_horizontal = limit_down;
|
|
515
|
-
}
|
|
516
|
-
} else if (left) {
|
|
517
|
-
[current_horizontal, posX, posY, max_left] = this.LeftSide(element, limit_left, current_horizontal, max_left);
|
|
518
|
-
if (current_horizontal > limit_up) {
|
|
519
|
-
max_up = current_horizontal;
|
|
520
|
-
left = false;
|
|
521
|
-
up = true;
|
|
522
|
-
if (max_down < limit_down) {
|
|
523
|
-
limit_down = max_down;
|
|
524
|
-
}
|
|
525
|
-
current_vertical = limit_left;
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
// Save information about the figure
|
|
531
|
-
// First, fill in common properties, then add those specific for
|
|
532
|
-
// bases or buildings
|
|
533
|
-
let figure = {
|
|
534
|
-
id: "boat-" + elements[i][data.field],
|
|
535
|
-
posX: posX,
|
|
536
|
-
posY: posY,
|
|
537
|
-
height: element.height,
|
|
538
|
-
translate_matrix: translate_matrix
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
if (elements[i].children) {
|
|
542
|
-
// This is the base for a quarter
|
|
543
|
-
figure.name = elements[i][this.data.field] || '',
|
|
544
|
-
figure.width = element.width - this.data.separation,
|
|
545
|
-
figure.depth = element.depth - this.data.separation,
|
|
546
|
-
figure.children = children,
|
|
547
|
-
figure.alpha = self.data.baseAlpha,
|
|
548
|
-
figure.translate_matrix = translate_matrix
|
|
549
|
-
// Tree layout
|
|
550
|
-
if (data.treeLayout) {
|
|
551
|
-
figure.treeMetaphorHeight = element.treeMetaphorHeight;
|
|
552
|
-
}
|
|
553
|
-
// Hierarchy level
|
|
554
|
-
let hierarchyLevel = figure.name.split("/").length - 1;
|
|
555
|
-
figure.hierarchyLevel = hierarchyLevel;
|
|
556
|
-
figure.renderOrder = hierarchyLevel;
|
|
557
|
-
// Gradient color
|
|
558
|
-
figure.color = self.getColorBase(hierarchyLevel);
|
|
559
|
-
} else {
|
|
560
|
-
// This is a building
|
|
561
|
-
figure.name = (elements[i].name) ? elements[i].name : elements[i][this.data.field],
|
|
562
|
-
figure.alpha = self.data.buildingAlpha
|
|
563
|
-
figure.width = element.width - data.separation;
|
|
564
|
-
figure.depth = element.depth - data.separation;
|
|
565
|
-
|
|
566
|
-
figure.color = this.getColor(elements[i], data.color) || data.building_color;
|
|
567
|
-
if (data.windows) {
|
|
568
|
-
// Largest consecutive integer exactly representable by a shader float.
|
|
569
|
-
figure.windows = Math.min(2 ** 24, Math.floor(positiveMetric(elements[i][data.windows])));
|
|
570
|
-
}
|
|
571
|
-
if (data.glow) figure.glow = positiveMetric(elements[i][data.glow]);
|
|
572
|
-
|
|
573
|
-
}
|
|
574
|
-
figure.rawData = elements[i]
|
|
575
|
-
|
|
576
|
-
// Set transparency and wireframe, if appropriate
|
|
577
|
-
self.setTransparency(figure);
|
|
578
|
-
figure.wireframe = this.getWireframe(figure, data.wireframeByRepeatedField);
|
|
579
|
-
|
|
580
|
-
figures.push(figure);
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
// Check and update last limits
|
|
584
|
-
if (max_down < limit_down) {
|
|
585
|
-
limit_down = max_down;
|
|
586
|
-
}
|
|
587
|
-
if (max_left < limit_left) {
|
|
588
|
-
limit_left = max_left;
|
|
589
|
-
}
|
|
590
|
-
if (max_up > limit_up) {
|
|
591
|
-
limit_up = max_up;
|
|
592
|
-
}
|
|
593
|
-
if (max_right > limit_right) {
|
|
594
|
-
limit_right = max_right;
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
// Calculate translation of the center, width and depth of the zone
|
|
598
|
-
var width = Math.abs(limit_left) + Math.abs(limit_right);
|
|
599
|
-
var depth = Math.abs(limit_down) + Math.abs(limit_up);
|
|
600
|
-
|
|
601
|
-
width += 2 * increment;
|
|
602
|
-
depth += 2 * increment;
|
|
603
|
-
|
|
604
|
-
var translate_x = limit_left + width / 2 - increment;
|
|
605
|
-
var translate_z = limit_down + depth / 2 - increment;
|
|
606
|
-
translate = {
|
|
607
|
-
x: translate_x,
|
|
608
|
-
y: 0,
|
|
609
|
-
z: translate_z,
|
|
610
|
-
};
|
|
611
|
-
|
|
612
|
-
return [width, depth, translate, figures];
|
|
82
|
+
updateChart: function (items) {
|
|
83
|
+
const animate = this.boxes.size > 0;
|
|
84
|
+
this.tracks.length = this.inserted.length = 0;
|
|
85
|
+
this.removeTreeLines();
|
|
86
|
+
this.figures = makeFigures(items, this.data, this.babiaMetadata, this.el.object3D.scale.y || 1,
|
|
87
|
+
this.categoricColorMaps, colors.palettes.categoric);
|
|
88
|
+
const seen = new Set();
|
|
89
|
+
this.drawElements(this.el, this.figures, origin, seen, animate);
|
|
90
|
+
for (const [id, entity] of this.boxes) if (!seen.has(id)) this.removeLot(entity);
|
|
91
|
+
for (const entity of this.interactions.labels.keys()) {
|
|
92
|
+
this.interactions.highlightGroup(entity);
|
|
93
|
+
this.interactions.highlightQuarter(entity);
|
|
94
|
+
}
|
|
95
|
+
this.interactions.update();
|
|
96
|
+
this.animation = !!(this.tracks.length || this.inserted.length);
|
|
97
|
+
this.start_time = Date.now();
|
|
98
|
+
if (!this.animation) this.alreadyAutoscaled = false;
|
|
613
99
|
},
|
|
614
100
|
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
for (let i in figures) {
|
|
624
|
-
|
|
625
|
-
let height = figures[i].height;
|
|
626
|
-
let x = figures[i].posX;
|
|
627
|
-
let y = figures[i].posY;
|
|
628
|
-
let position = {
|
|
629
|
-
x: x - translate.x,
|
|
630
|
-
y: (height / 2 + translate.y / 2),
|
|
631
|
-
z: -y + translate.z
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
// Tree layout
|
|
635
|
-
if (self.data.treeLayout) {
|
|
636
|
-
// Hide quarters with no children
|
|
637
|
-
if (self.data.treeHideOneSonQuarters && (figures[i].children && figures[i].children.length === 1)) {
|
|
638
|
-
figures[i].alphaTest = 1
|
|
639
|
-
figures[i].dontAddEvents = true
|
|
640
|
-
figures[i].children[0].dontAddLine = true
|
|
101
|
+
drawElements: function (parent, figures, translate, seen, animate) {
|
|
102
|
+
const d = this.data;
|
|
103
|
+
for (const f of figures) {
|
|
104
|
+
const position = new THREE.Vector3(f.posX - translate.x, (f.height + translate.y) / 2, -f.posY + translate.z);
|
|
105
|
+
if (d.treeLayout) {
|
|
106
|
+
if (d.treeHideOneSonQuarters && f.children?.length === 1) {
|
|
107
|
+
f.dontAddEvents = true;
|
|
108
|
+
f.children[0].dontAddLine = true;
|
|
641
109
|
}
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
if (figures[i].height < self.data.treeQuartersLevelHeight) {
|
|
652
|
-
// If flag to hide activated and the parent has only one son, not needed to draw the line
|
|
653
|
-
if (!(self.data.treeHideOneSonQuarters && figures[i].dontAddLine)) {
|
|
654
|
-
// First get top
|
|
655
|
-
let topBuildingY = position.y
|
|
656
|
-
// Get where the quarter is
|
|
657
|
-
let quarterPosY = position.y + (self.data.treeQuartersLevelHeight - (height / 2))
|
|
658
|
-
// Draw the line in the space
|
|
659
|
-
let line = document.createElement('a-entity')
|
|
660
|
-
line.setAttribute('class', 'babiaboatstreelines')
|
|
661
|
-
line.setAttribute('line', {
|
|
662
|
-
start: { x: position.x, y: topBuildingY, z: position.z },
|
|
663
|
-
end: { x: position.x, y: quarterPosY, z: position.z },
|
|
664
|
-
color: 'yellow'
|
|
665
|
-
})
|
|
666
|
-
element.appendChild(line)
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
}
|
|
110
|
+
if (d.treeFixQuarterHeight) {
|
|
111
|
+
position.y += f.treeMetaphorHeight !== undefined ? d.treeQuartersLevelHeight : -d.treeQuartersLevelHeight - d.zone_elevation;
|
|
112
|
+
if (f.treeMetaphorHeight === undefined && f.height < d.treeQuartersLevelHeight && !f.dontAddLine) {
|
|
113
|
+
const line = document.createElement('a-entity');
|
|
114
|
+
line.classList.add('babiaboatstreelines');
|
|
115
|
+
line.setAttribute('line', {start: position, end: {x: position.x,
|
|
116
|
+
y: position.y + d.treeQuartersLevelHeight - f.height / 2, z: position.z}, color: 'yellow'});
|
|
117
|
+
parent.appendChild(line);
|
|
118
|
+
this.lines.push(line);
|
|
670
119
|
}
|
|
671
|
-
} else
|
|
672
|
-
|
|
673
|
-
if (figures[i].treeMetaphorHeight !== undefined) {
|
|
674
|
-
let height_min = 0;
|
|
675
|
-
if (self.data.diffBuildingHeight) {
|
|
676
|
-
height_min = self.babiaMetadata['heightMin'];
|
|
677
|
-
};
|
|
678
|
-
position.y = (self.normalizeValues(height_min,
|
|
679
|
-
self.babiaMetadata['heightMax'],
|
|
680
|
-
self.data.minBuildingHeight,
|
|
681
|
-
self.data.maxBuildingHeight,
|
|
682
|
-
figures[i].treeMetaphorHeight))
|
|
683
|
-
} else {
|
|
684
|
-
position.y = ((height / 2 + translate.y / 2)) - height - 0.001
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
let entity = this.createElement(figures[i], position);
|
|
691
|
-
this.addEvents(entity, figures[i]);
|
|
692
|
-
|
|
693
|
-
element.appendChild(entity);
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
},
|
|
697
|
-
|
|
698
|
-
RightSide: function (element, limit_right, current_horizontal, max_right) {
|
|
699
|
-
const data = this.data;
|
|
700
|
-
|
|
701
|
-
let width, depth;
|
|
702
|
-
if (data.area && !element.children) {
|
|
703
|
-
width = Math.sqrt(element.area);
|
|
704
|
-
depth = Math.sqrt(element.area);
|
|
705
|
-
} else {
|
|
706
|
-
width = parseFloat(element.width);
|
|
707
|
-
depth = parseFloat(element.depth);
|
|
708
|
-
}
|
|
709
|
-
// Calculate position
|
|
710
|
-
let posX = limit_right + (width / 2);
|
|
711
|
-
let posY = current_horizontal - (depth / 2);
|
|
712
|
-
|
|
713
|
-
// Calculate states
|
|
714
|
-
current_horizontal -= depth;
|
|
715
|
-
let total_x = limit_right + width;
|
|
716
|
-
if (total_x > max_right) {
|
|
717
|
-
max_right = total_x;
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
return [current_horizontal, posX, posY, max_right];
|
|
721
|
-
},
|
|
722
|
-
|
|
723
|
-
DownSide: function (element, limit_down, current_vertical, max_down) {
|
|
724
|
-
const data = this.data;
|
|
725
|
-
|
|
726
|
-
let width, depth;
|
|
727
|
-
if (data.area && !element.children) {
|
|
728
|
-
width = Math.sqrt(element.area);
|
|
729
|
-
depth = Math.sqrt(element.area);
|
|
730
|
-
} else {
|
|
731
|
-
width = parseFloat(element.width);
|
|
732
|
-
depth = parseFloat(element.depth);
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
let posX = current_vertical - (width / 2);
|
|
736
|
-
let posY = limit_down - (depth / 2);
|
|
737
|
-
|
|
738
|
-
current_vertical -= width;
|
|
739
|
-
|
|
740
|
-
let total_y = limit_down - depth;
|
|
741
|
-
if (total_y < max_down) {
|
|
742
|
-
max_down = total_y;
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
return [current_vertical, posX, posY, max_down];
|
|
746
|
-
},
|
|
747
|
-
|
|
748
|
-
LeftSide: function (element, limit_left, current_horizontal, max_left) {
|
|
749
|
-
const data = this.data;
|
|
750
|
-
|
|
751
|
-
let width, depth;
|
|
752
|
-
if (data.area && !element.children) {
|
|
753
|
-
width = Math.sqrt(element.area);
|
|
754
|
-
depth = Math.sqrt(element.area);
|
|
755
|
-
} else {
|
|
756
|
-
width = parseFloat(element.width);
|
|
757
|
-
depth = parseFloat(element.depth);
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
let posX = limit_left - (width / 2);
|
|
761
|
-
let posY = current_horizontal + (depth / 2);
|
|
762
|
-
|
|
763
|
-
current_horizontal += depth;
|
|
764
|
-
|
|
765
|
-
let total_x = limit_left - width;
|
|
766
|
-
if (total_x < max_left) {
|
|
767
|
-
max_left = total_x;
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
return [current_horizontal, posX, posY, max_left];
|
|
771
|
-
},
|
|
772
|
-
|
|
773
|
-
UpSide: function (element, limit_up, current_vertical, max_up) {
|
|
774
|
-
const data = this.data;
|
|
775
|
-
|
|
776
|
-
let width, depth;
|
|
777
|
-
if (data.area && !element.children) {
|
|
778
|
-
width = Math.sqrt(element.area);
|
|
779
|
-
depth = Math.sqrt(element.area);
|
|
780
|
-
} else {
|
|
781
|
-
width = parseFloat(element.width);
|
|
782
|
-
depth = parseFloat(element.depth);
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
let posX = current_vertical + (width / 2);
|
|
786
|
-
let posY = limit_up + (depth / 2);
|
|
787
|
-
|
|
788
|
-
current_vertical += width;
|
|
789
|
-
|
|
790
|
-
let total_y = limit_up + depth;
|
|
791
|
-
if (total_y > max_up) {
|
|
792
|
-
max_up = total_y;
|
|
793
|
-
}
|
|
794
|
-
|
|
795
|
-
return [current_vertical, posX, posY, max_up];
|
|
796
|
-
},
|
|
797
|
-
|
|
798
|
-
/**
|
|
799
|
-
* getColor
|
|
800
|
-
*
|
|
801
|
-
* Calculate the color of the element based on its value in color_field.
|
|
802
|
-
* If the value is a number, it will calculate the color based on the
|
|
803
|
-
* heat map from color_min to color_max.
|
|
804
|
-
* If the value is a string, it will assign a color from colorsArray in
|
|
805
|
-
* order of appearence.
|
|
806
|
-
*
|
|
807
|
-
* @param {Object} element - The element to calculate the color for
|
|
808
|
-
* @param {String} color_field - The field in the element to calculate the color from
|
|
809
|
-
*
|
|
810
|
-
* @return {String} - The color for the element
|
|
811
|
-
*/
|
|
812
|
-
getColor: function (element, color_field) {
|
|
813
|
-
const self = this;
|
|
814
|
-
let color_value = element[color_field];
|
|
815
|
-
let color;
|
|
816
|
-
if (typeof color_value === 'number') {
|
|
817
|
-
color = heatMapColorforValue(color_value,
|
|
818
|
-
self.babiaMetadata['color_max'], self.babiaMetadata['color_min']);
|
|
819
|
-
} else if (typeof color_value === 'string') {
|
|
820
|
-
// Categoric color
|
|
821
|
-
if (color_value in self.categoricColorMaps) {
|
|
822
|
-
color = self.categoricColorMaps[color_value];
|
|
823
|
-
} else {
|
|
824
|
-
self.categoricColorMaps[color_value]
|
|
825
|
-
= colorsArray[self.categoricColorIndex]
|
|
826
|
-
color = colorsArray[self.categoricColorIndex]
|
|
827
|
-
|
|
828
|
-
self.categoricColorIndex = self.categoricColorIndex + 1
|
|
829
|
-
if (self.categoricColorIndex >= colorsArray.length) {
|
|
830
|
-
self.categoricColorIndex = 0
|
|
831
|
-
}
|
|
120
|
+
} else if (f.treeMetaphorHeight !== undefined) position.y = buildingHeight(f.treeMetaphorHeight, d, this.babiaMetadata);
|
|
121
|
+
else position.y -= f.height + 0.001;
|
|
832
122
|
}
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
/**
|
|
838
|
-
* getColorBase
|
|
839
|
-
*
|
|
840
|
-
* Determines the color for the base in a given level, depending on whether
|
|
841
|
-
* gradientBaseColor is enabled. If enabled, it calculates a color
|
|
842
|
-
* using the greenColorsurface function based on normalized level
|
|
843
|
-
* values. If not enabled, it uses the default base color.
|
|
844
|
-
*
|
|
845
|
-
* @param {number} level - The level for which to determine the color.
|
|
846
|
-
*
|
|
847
|
-
* @return {string} - The calculated base color.
|
|
848
|
-
*/
|
|
849
|
-
getColorBase: function (level) {
|
|
850
|
-
let color;
|
|
851
|
-
const self = this;
|
|
852
|
-
|
|
853
|
-
if (self.data.gradientBaseColor) {
|
|
854
|
-
let max_levels = self.babiaMetadata['maxLevels'];
|
|
855
|
-
color = greenColorsurface(Math.round(
|
|
856
|
-
self.normalizeValues(1, max_levels, 15, 100, level)
|
|
857
|
-
));
|
|
858
|
-
} else {
|
|
859
|
-
color = self.data.base_color;
|
|
860
|
-
};
|
|
861
|
-
return color;
|
|
862
|
-
},
|
|
863
|
-
|
|
864
|
-
/**
|
|
865
|
-
* setTransparency
|
|
866
|
-
*
|
|
867
|
-
* If "transparency by a field" on buildings is selected
|
|
868
|
-
* set transparency to 80% or 20% to those buildings that share
|
|
869
|
-
* same value for the selected field.
|
|
870
|
-
* @param {Object} figure - The figure to set transparency
|
|
871
|
-
*/
|
|
872
|
-
setTransparency: function (figure) {
|
|
873
|
-
const self = this;
|
|
874
|
-
const data = this.data;
|
|
875
|
-
|
|
876
|
-
// If transparency by a field on buildings
|
|
877
|
-
// Put transparent 80% to those buildings that share same value for a field selected
|
|
878
|
-
const t80_field = data.transparent80ByRepeatedField;
|
|
879
|
-
const t20_field = data.transparent20ByRepeatedField;
|
|
880
|
-
if (t80_field && (!figure.children &&
|
|
881
|
-
self.idsToNotRepeat80Transparent.includes(figure.rawData[t80_field]))) {
|
|
882
|
-
figure.alpha = 0.8
|
|
883
|
-
figure.renderOrder = 2000
|
|
884
|
-
} else {
|
|
885
|
-
self.idsToNotRepeat80Transparent.push(figure.rawData[t80_field])
|
|
886
|
-
}
|
|
887
|
-
|
|
888
|
-
// Put transparent 20% to those buildings that share same value for a field selected
|
|
889
|
-
if (t20_field && (!figure.children &&
|
|
890
|
-
self.idsToNotRepeat20Transparent.includes(figure.rawData[t20_field]))) {
|
|
891
|
-
figure.alpha = 0.45
|
|
892
|
-
figure.renderOrder = 2000
|
|
893
|
-
} else {
|
|
894
|
-
self.idsToNotRepeat20Transparent.push(figure.rawData[t20_field])
|
|
123
|
+
const entity = this.syncBox(parent, f, position, animate);
|
|
124
|
+
seen.add(f.id);
|
|
125
|
+
if (f.children) this.drawElements(entity, f.children, f.translate_matrix, seen, animate);
|
|
895
126
|
}
|
|
896
127
|
},
|
|
897
128
|
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
self.idsToNotRepeatWireframe.includes(figure.rawData[wireframe_field]))) {
|
|
915
|
-
wireframe = true;
|
|
129
|
+
// Keep public boat-<id> IDs, but resolve them in this instance. Two boats
|
|
130
|
+
// visualizers can show the same project without borrowing each other's lots.
|
|
131
|
+
syncBox: function (parent, figure, position, animate) {
|
|
132
|
+
let entity = this.boxes.get(figure.id);
|
|
133
|
+
if (entity && !!entity.babiaFigure.children !== !!figure.children) {
|
|
134
|
+
this.removeLot(entity);
|
|
135
|
+
entity = null;
|
|
136
|
+
}
|
|
137
|
+
const isNew = !entity;
|
|
138
|
+
if (isNew) {
|
|
139
|
+
entity = document.createElement('a-box');
|
|
140
|
+
entity.id = figure.id;
|
|
141
|
+
this.boxes.set(figure.id, entity);
|
|
142
|
+
for (const dim of ['width', 'height', 'depth']) entity.setAttribute(dim, figure[dim]);
|
|
143
|
+
entity.setAttribute('position', position);
|
|
144
|
+
if (animate) this.inserted.push(entity);
|
|
916
145
|
} else {
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
//Increment opacity
|
|
944
|
-
// let opa_inc = delta / this.duration;
|
|
945
|
-
// let opacity = parseFloat(entity.getAttribute('material').opacity);
|
|
946
|
-
// if (opacity + opa_inc < 1) {
|
|
947
|
-
// opacity += opa_inc;
|
|
948
|
-
// } else {
|
|
949
|
-
// opacity = 1.0;
|
|
950
|
-
// figures[i].inserted = false;
|
|
951
|
-
// }
|
|
952
|
-
//setOpacity(entity, opacity);
|
|
953
|
-
|
|
954
|
-
// If animation stops before finish
|
|
955
|
-
let cond = 'id=' + figures[i].id
|
|
956
|
-
if (findIndex(self.figures_in, cond) < 0) {
|
|
957
|
-
self.figures_in.push(figures[i])
|
|
958
|
-
}
|
|
959
|
-
|
|
960
|
-
} else {
|
|
961
|
-
// find index in old_figures
|
|
962
|
-
let cond = 'id=' + figures[i].id
|
|
963
|
-
let index = findIndex(figures_old, cond)
|
|
964
|
-
|
|
965
|
-
// Update rawData
|
|
966
|
-
entity.babiaRawData = figures[i].rawData
|
|
967
|
-
if (index < 0) {
|
|
968
|
-
// encontrar el elemento que no esta en la escena con id y darle opacidad
|
|
969
|
-
// y cambiar sus propiedades a la nueva si es necesario
|
|
970
|
-
figures[i].inserted = true;
|
|
971
|
-
if (entity.getAttribute('width') != figures[i].width) {
|
|
972
|
-
entity.setAttribute('width', figures[i].width);
|
|
973
|
-
}
|
|
974
|
-
if (entity.getAttribute('height') != figures[i].height) {
|
|
975
|
-
entity.setAttribute('height', figures[i].height);
|
|
976
|
-
}
|
|
977
|
-
if (entity.getAttribute('depth') != figures[i].depth) {
|
|
978
|
-
entity.setAttribute('depth', figures[i].depth);
|
|
979
|
-
}
|
|
980
|
-
if (entity.getAttribute('color') != figures[i].color) {
|
|
981
|
-
entity.setAttribute('color', figures[i].color);
|
|
982
|
-
}
|
|
983
|
-
if (entity.getAttribute('material').wireframe != figures[i].wireframe) {
|
|
984
|
-
entity.setAttribute('material', 'wireframe', figures[i].wireframe);
|
|
985
|
-
entity.setAttribute('material', 'wireframeLinewidth', 0.1);
|
|
986
|
-
}
|
|
987
|
-
|
|
988
|
-
} else {
|
|
989
|
-
// RESIZE
|
|
990
|
-
this.resize(entity, new_time, delta, figures[i], figures_old[index]);
|
|
991
|
-
// TRASLATE
|
|
992
|
-
this.traslate(entity, new_time, delta, figures[i], figures_old[index], translate, translate_old);
|
|
993
|
-
// COLOR
|
|
994
|
-
if (entity.getAttribute('color') != figures[i].color && !self.inEntitiesWithLegend(entity)) {
|
|
995
|
-
entity.setAttribute('color', figures[i].color);
|
|
996
|
-
}
|
|
997
|
-
if (entity.getAttribute('material').wireframe != figures[i].wireframe) {
|
|
998
|
-
entity.setAttribute('material', 'wireframe', figures[i].wireframe);
|
|
999
|
-
entity.setAttribute('material', 'wireframeLinewidth', 0.1);
|
|
1000
|
-
}
|
|
1001
|
-
if (entity.getAttribute('material').opacity != figures[i].alpha) {
|
|
1002
|
-
entity.setAttribute('material', 'opacity', figures[i].alpha);
|
|
1003
|
-
entity.object3D.renderOrder = figures[i].renderOrder
|
|
1004
|
-
}
|
|
1005
|
-
|
|
1006
|
-
if (figures[i].children) {
|
|
1007
|
-
this.Animation(entity, figures[i].children, figures_old[index].children, delta, figures[i].translate_matrix, figures_old[index].translate_matrix);
|
|
1008
|
-
} else {
|
|
1009
|
-
// Building color if changed, force to the new one
|
|
1010
|
-
if (figures[i].rawData[self.data.color] !== figures_old[index].rawData[self.data.color]) {
|
|
1011
|
-
// Color numeric or categoric
|
|
1012
|
-
let color
|
|
1013
|
-
if (typeof figures[i].rawData[self.data.color] === 'number') {
|
|
1014
|
-
color = heatMapColorforValue(figures[i].rawData[self.data.color], self.babiaMetadata['color_max'], self.babiaMetadata['color_min'])
|
|
1015
|
-
} else if (typeof figures[i].rawData[self.data.color] === 'string') {
|
|
1016
|
-
// Categoric color
|
|
1017
|
-
if (figures[i].rawData[self.data.color] in self.categoricColorMaps) {
|
|
1018
|
-
color = self.categoricColorMaps[figures[i].rawData[self.data.color]]
|
|
1019
|
-
} else {
|
|
1020
|
-
self.categoricColorMaps[figures[i].rawData[self.data.color]] = colorsArray[self.categoricColorIndex]
|
|
1021
|
-
color = colorsArray[self.categoricColorIndex]
|
|
1022
|
-
|
|
1023
|
-
self.categoricColorIndex = self.categoricColorIndex + 1
|
|
1024
|
-
if (self.categoricColorIndex >= colorsArray.length) {
|
|
1025
|
-
self.categoricColorIndex = 0
|
|
1026
|
-
}
|
|
1027
|
-
}
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
let oldColor = entity.getAttribute('color')
|
|
1032
|
-
if (color !== oldColor) {
|
|
1033
|
-
entity.setAttribute('color', color)
|
|
1034
|
-
}
|
|
1035
|
-
}
|
|
1036
|
-
}
|
|
1037
|
-
}
|
|
1038
|
-
}
|
|
1039
|
-
} else {
|
|
1040
|
-
|
|
1041
|
-
// CREATE NEW
|
|
1042
|
-
position = {
|
|
1043
|
-
x: figures[i].posX - translate.x,
|
|
1044
|
-
y: (figures[i].height / 2 + translate.y / 2),
|
|
1045
|
-
z: -figures[i].posY + translate.z
|
|
1046
|
-
}
|
|
1047
|
-
|
|
1048
|
-
let new_entity = this.createElement(figures[i], position);
|
|
1049
|
-
this.addEvents(new_entity, figures[i]);
|
|
1050
|
-
|
|
1051
|
-
//TODO: bad perfomance when Opacity 0 at the beginning
|
|
1052
|
-
//setOpacity(new_entity, 0);
|
|
1053
|
-
|
|
1054
|
-
// New building and quarter, it appears with 0.5 opacity
|
|
1055
|
-
setOpacity(new_entity, 0.5);
|
|
1056
|
-
|
|
1057
|
-
element.appendChild(new_entity);
|
|
1058
|
-
figures[i].inserted = true;
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
|
|
1062
|
-
// Delete figures
|
|
1063
|
-
let opa_dec = delta / this.duration;
|
|
1064
|
-
for (let i in figures_old) {
|
|
1065
|
-
let deleted = false;
|
|
1066
|
-
let cond = 'id=' + figures_old[i].id
|
|
1067
|
-
let index = findIndex(figures, cond)
|
|
1068
|
-
if (index < 0) {
|
|
1069
|
-
if (findIndex(self.figures_del, cond) < 0) {
|
|
1070
|
-
self.figures_del.push(figures_old[i])
|
|
1071
|
-
}
|
|
1072
|
-
let entity_del = document.getElementById(figures_old[i].id);
|
|
1073
|
-
if (entity_del) {
|
|
1074
|
-
|
|
1075
|
-
//TODO: Bad perfomance issue when changing dinamically the opacity, better to just make it non vissible
|
|
1076
|
-
entity_del.object3D.visible = false
|
|
1077
|
-
entity_del.remove();
|
|
1078
|
-
|
|
1079
|
-
// let opacity = parseFloat(entity_del.components.material.opacity);
|
|
1080
|
-
// if (opacity - opa_dec > 0) {
|
|
1081
|
-
// opacity -= opa_dec;
|
|
1082
|
-
// } else {
|
|
1083
|
-
// opacity = 0.0;
|
|
1084
|
-
// deleted = true;
|
|
1085
|
-
// self.figures_del.pop(figures_old[i]);
|
|
1086
|
-
// }
|
|
1087
|
-
// setOpacity(entity_del, opacity);
|
|
1088
|
-
// if (deleted) {
|
|
1089
|
-
// entity_del.remove();
|
|
1090
|
-
// }
|
|
1091
|
-
}
|
|
1092
|
-
}
|
|
1093
|
-
}
|
|
1094
|
-
},
|
|
1095
|
-
|
|
1096
|
-
inEntitiesWithLegend(obj) {
|
|
1097
|
-
let i;
|
|
1098
|
-
for (i = 0; i < this.entitiesWithLegend.length; i++) {
|
|
1099
|
-
if (this.entitiesWithLegend[i].entity === obj) {
|
|
1100
|
-
return true;
|
|
1101
|
-
}
|
|
146
|
+
// Start an interrupted animation at its displayed size and position.
|
|
147
|
+
const start = entity.object3D.position.clone();
|
|
148
|
+
start.y -= entity.boatLift || 0;
|
|
149
|
+
const geometry = entity.getAttribute('geometry') || entity.babiaFigure;
|
|
150
|
+
const dims = ['width', 'height', 'depth'].filter(key => geometry[key] !== figure[key]);
|
|
151
|
+
if (dims.length || !start.equals(position)) this.tracks.push({entity, start, end: position,
|
|
152
|
+
geometry: {}, sizes: dims.map(key => ({key, from: geometry[key], to: figure[key]}))});
|
|
153
|
+
}
|
|
154
|
+
if (figure.dontAddEvents && entity.legend) this.interactions.drop(entity);
|
|
155
|
+
entity.babiaFigure = figure;
|
|
156
|
+
entity.babiaRawData = figure.rawData;
|
|
157
|
+
entity.classList.toggle('babiaxraycasterclass', !figure.dontAddEvents);
|
|
158
|
+
entity.setAttribute('color', figure.color);
|
|
159
|
+
entity.setAttribute('babiaxrFirstColor', figure.color);
|
|
160
|
+
entity.highlightbuildingbyfieldactive = false;
|
|
161
|
+
const field = this.data.highlightBuildingByField;
|
|
162
|
+
if (field) entity.setAttribute('babia-highlightbuildingbyfield', String(figure.rawData[field]).replace('/', '').replace('@', ''));
|
|
163
|
+
else entity.removeAttribute('babia-highlightbuildingbyfield');
|
|
164
|
+
entity.object3D.renderOrder = figure.renderOrder || 0;
|
|
165
|
+
entity.setAttribute('material', {opacity: isNew && animate ? 0.5 : figure.alpha,
|
|
166
|
+
alphaTest: figure.dontAddEvents ? 1 : 0, wireframe: figure.wireframe, wireframeLinewidth: 0.1});
|
|
167
|
+
applyBuildingMetrics(entity, figure);
|
|
168
|
+
if (entity.parentElement !== parent) {
|
|
169
|
+
const previousParent = entity.parentElement;
|
|
170
|
+
parent.appendChild(entity);
|
|
171
|
+
if (previousParent?.babiaFigure && entity.alreadyActive) this.interactions.highlightQuarter(previousParent);
|
|
1102
172
|
}
|
|
1103
|
-
|
|
1104
|
-
return false;
|
|
1105
|
-
},
|
|
1106
|
-
|
|
1107
|
-
setFigures: function (figures, translate) {
|
|
1108
|
-
const self = this
|
|
1109
|
-
figures.forEach(figure => {
|
|
1110
|
-
let entity = document.getElementById(figure.id);
|
|
1111
|
-
if (entity) {
|
|
1112
|
-
applyBuildingMetrics(entity, figure);
|
|
1113
|
-
// Keep picking and legends current even if no intermediate animation tick ran.
|
|
1114
|
-
entity.babiaRawData = figure.rawData;
|
|
1115
|
-
if (entity.getAttribute('width') != figure.width) {
|
|
1116
|
-
entity.setAttribute('width', figure.width);
|
|
1117
|
-
}
|
|
1118
|
-
if (entity.getAttribute('height') != figure.height) {
|
|
1119
|
-
entity.setAttribute('height', figure.height);
|
|
1120
|
-
}
|
|
1121
|
-
if (entity.getAttribute('depth') != figure.depth) {
|
|
1122
|
-
entity.setAttribute('depth', figure.depth);
|
|
1123
|
-
}
|
|
1124
|
-
// If legend active, don't force change color, put it as the color before
|
|
1125
|
-
if (self.inEntitiesWithLegend(entity)) {
|
|
1126
|
-
entity.setAttribute('babiaxrFirstColor', figure.color)
|
|
1127
|
-
} else {
|
|
1128
|
-
if (entity.getAttribute('color') != figure.color) {
|
|
1129
|
-
entity.setAttribute('color', figure.color);
|
|
1130
|
-
}
|
|
1131
|
-
}
|
|
1132
|
-
|
|
1133
|
-
//TODO: Full opacity because it was in 0.5 if new building/quarter
|
|
1134
|
-
if (entity.components.material.data.opacity < 1) {
|
|
1135
|
-
setOpacity(entity, 1)
|
|
1136
|
-
}
|
|
1137
|
-
|
|
1138
|
-
// Quarters to alpha if tree fix position
|
|
1139
|
-
if (entity.getAttribute('material').opacity != figure.alpha) {
|
|
1140
|
-
entity.setAttribute('material', 'opacity', figure.alpha);
|
|
1141
|
-
}
|
|
1142
|
-
|
|
1143
|
-
// TEST TREE
|
|
1144
|
-
if (self.data.treeLayout) {
|
|
1145
|
-
// Hide quarters that has not children
|
|
1146
|
-
if (self.data.treeHideOneSonQuarters && (figure.children && figure.children.length === 1)) {
|
|
1147
|
-
figure.alphaTest = 1
|
|
1148
|
-
figure.dontAddEvents = true
|
|
1149
|
-
figure.children[0].dontAddLine = true
|
|
1150
|
-
}
|
|
1151
|
-
|
|
1152
|
-
if (self.data.treeFixQuarterHeight) {
|
|
1153
|
-
// Fix position y for quarters
|
|
1154
|
-
if (figure.treeMetaphorHeight !== undefined) {
|
|
1155
|
-
entity.object3D.position.set(
|
|
1156
|
-
figure.posX - translate.x,
|
|
1157
|
-
(figure.height / 2 + translate.y / 2) + self.data.treeQuartersLevelHeight,
|
|
1158
|
-
(- figure.posY + translate.z),
|
|
1159
|
-
)
|
|
1160
|
-
} else {
|
|
1161
|
-
let positionYFixed = ((figure.height / 2 + translate.y / 2)) - self.data.treeQuartersLevelHeight - self.data.zone_elevation
|
|
1162
|
-
let positionX = figure.posX - translate.x
|
|
1163
|
-
let positionZ = (- figure.posY + translate.z)
|
|
1164
|
-
entity.object3D.position.set(
|
|
1165
|
-
positionX,
|
|
1166
|
-
positionYFixed,
|
|
1167
|
-
positionZ,
|
|
1168
|
-
)
|
|
1169
|
-
// DRAW LINE WHEN DOES NOT ACHIEVE THE QUARTER (TOO LOW)
|
|
1170
|
-
if (figure.height < self.data.treeQuartersLevelHeight) {
|
|
1171
|
-
// If flag to hide activated and the parent has only one son, not needed to draw the line
|
|
1172
|
-
if (!(self.data.treeHideOneSonQuarters && figure.dontAddLine)) {
|
|
1173
|
-
// First get top
|
|
1174
|
-
let topBuildingY = positionYFixed
|
|
1175
|
-
// Get where the quarter is
|
|
1176
|
-
let quarterPosY = positionYFixed + (self.treeQuartersLevelHeight - figure.height / 2)
|
|
1177
|
-
// Draw the line in the space
|
|
1178
|
-
let line = document.createElement('a-entity')
|
|
1179
|
-
line.setAttribute('class', 'babiaboatstreelines')
|
|
1180
|
-
line.setAttribute('line', {
|
|
1181
|
-
start: { x: positionX, y: topBuildingY, z: positionZ },
|
|
1182
|
-
end: { x: positionX, y: quarterPosY, z: positionZ },
|
|
1183
|
-
color: 'yellow'
|
|
1184
|
-
})
|
|
1185
|
-
entity.parentElement.appendChild(line)
|
|
1186
|
-
}
|
|
1187
|
-
}
|
|
1188
|
-
}
|
|
1189
|
-
} else {
|
|
1190
|
-
if (figure.treeMetaphorHeight !== undefined) {
|
|
1191
|
-
let height_min = 0;
|
|
1192
|
-
if (self.data.diffBuildingHeight) {
|
|
1193
|
-
height_min = self.babiaMetadata['heightMin'];
|
|
1194
|
-
};
|
|
1195
|
-
entity.object3D.position.set(
|
|
1196
|
-
figure.posX - translate.x,
|
|
1197
|
-
self.normalizeValues(height_min,
|
|
1198
|
-
self.babiaMetadata['heightMax'],
|
|
1199
|
-
self.data.minBuildingHeight,
|
|
1200
|
-
self.data.maxBuildingHeight,
|
|
1201
|
-
figure.treeMetaphorHeight),
|
|
1202
|
-
- figure.posY + translate.z,
|
|
1203
|
-
)
|
|
1204
|
-
} else {
|
|
1205
|
-
entity.object3D.position.set(
|
|
1206
|
-
figure.posX - translate.x,
|
|
1207
|
-
((figure.height / 2 + translate.y / 2)) - figure.height - 0.001,
|
|
1208
|
-
(- figure.posY + translate.z),
|
|
1209
|
-
)
|
|
1210
|
-
}
|
|
1211
|
-
}
|
|
1212
|
-
} else {
|
|
1213
|
-
// Lo de no tree, lo que estaba antes
|
|
1214
|
-
entity.object3D.position.set(
|
|
1215
|
-
figure.posX - translate.x,
|
|
1216
|
-
((parseFloat(figure.height) + translate.y) / 2),
|
|
1217
|
-
(- figure.posY + translate.z),
|
|
1218
|
-
)
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
|
-
if (figure.children) {
|
|
1222
|
-
this.setFigures(figure.children, figure.translate_matrix);
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
});
|
|
173
|
+
return entity;
|
|
1226
174
|
},
|
|
1227
175
|
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
(
|
|
1232
|
-
(
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
let inc_width = (delta * diff_width) / this.duration;
|
|
1241
|
-
let inc_height = (delta * diff_height) / this.duration;
|
|
1242
|
-
let inc_depth = (delta * diff_depth) / this.duration;
|
|
1243
|
-
|
|
1244
|
-
let last_width = parseFloat(entity.getAttribute('width'));
|
|
1245
|
-
let last_height = parseFloat(entity.getAttribute('height'));
|
|
1246
|
-
let last_depth = parseFloat(entity.getAttribute('depth'));
|
|
1247
|
-
|
|
1248
|
-
let new_width;
|
|
1249
|
-
if (figure.width - figure_old.width < 0) {
|
|
1250
|
-
new_width = last_width - inc_width;
|
|
1251
|
-
} else {
|
|
1252
|
-
new_width = last_width + inc_width;
|
|
1253
|
-
}
|
|
1254
|
-
|
|
1255
|
-
let new_height;
|
|
1256
|
-
if (figure.height - figure_old.height < 0) {
|
|
1257
|
-
new_height = last_height - inc_height;
|
|
1258
|
-
} else {
|
|
1259
|
-
new_height = last_height + inc_height;
|
|
1260
|
-
}
|
|
1261
|
-
|
|
1262
|
-
let new_depth;
|
|
1263
|
-
if (figure.depth - figure_old.depth < 0) {
|
|
1264
|
-
new_depth = last_depth - inc_depth;
|
|
1265
|
-
} else {
|
|
1266
|
-
new_depth = last_depth + inc_depth;
|
|
1267
|
-
}
|
|
1268
|
-
|
|
1269
|
-
// Update size
|
|
1270
|
-
entity.setAttribute('width', new_width);
|
|
1271
|
-
entity.setAttribute('height', new_height);
|
|
1272
|
-
entity.setAttribute('depth', new_depth);
|
|
1273
|
-
|
|
1274
|
-
//Check if has transparent box as a quarter
|
|
1275
|
-
if (entity.classList.contains('babiaquarterboxactivated')) {
|
|
1276
|
-
entity.childNodes.forEach(child => {
|
|
1277
|
-
if (child.classList.contains('babiaquarterlegendbox')) {
|
|
1278
|
-
child.setAttribute('geometry', 'width', new_width);
|
|
1279
|
-
child.setAttribute('geometry', 'depth', new_depth);
|
|
1280
|
-
child.setAttribute('material', 'opacity', 0.4);
|
|
1281
|
-
}
|
|
1282
|
-
});
|
|
176
|
+
tick: function () {
|
|
177
|
+
if (this.animation) {
|
|
178
|
+
const progress = this.duration > 0 ? Math.min(1, (Date.now() - this.start_time) / this.duration) : 1;
|
|
179
|
+
for (const {entity, start, end, geometry, sizes} of this.tracks) {
|
|
180
|
+
entity.object3D.position.lerpVectors(start, end, progress);
|
|
181
|
+
entity.object3D.position.y += entity.boatLift || 0;
|
|
182
|
+
if (!sizes.length) continue;
|
|
183
|
+
for (const {key, from, to} of sizes) geometry[key] = progress === 1 ? to : from + (to - from) * progress;
|
|
184
|
+
entity.setAttribute('geometry', geometry);
|
|
185
|
+
// Keep a-box's public primitive attributes in sync at the endpoint.
|
|
186
|
+
if (progress === 1) for (const {key, to} of sizes) entity.setAttribute(key, to);
|
|
187
|
+
if (entity.legend && !entity.babiaFigure.children) this.interactions.sizeHighlight(entity, true);
|
|
1283
188
|
}
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
(figure.depth != figure_old.depth))) {
|
|
1290
|
-
|
|
1291
|
-
entity.setAttribute('width', figure.width);
|
|
1292
|
-
entity.setAttribute('height', figure.height);
|
|
1293
|
-
entity.setAttribute('depth', figure.depth);
|
|
1294
|
-
|
|
1295
|
-
//Check if has transparent box as a quarter
|
|
1296
|
-
if (entity.classList.contains('babiaquarterboxactivated')) {
|
|
1297
|
-
entity.childNodes.forEach(child => {
|
|
1298
|
-
if (child.classList.contains('babiaquarterlegendbox')) {
|
|
1299
|
-
child.setAttribute('geometry', 'width', new_width);
|
|
1300
|
-
child.setAttribute('geometry', 'depth', new_depth);
|
|
1301
|
-
child.setAttribute('material', 'opacity', 0.4);
|
|
1302
|
-
}
|
|
1303
|
-
});
|
|
189
|
+
if (progress === 1) {
|
|
190
|
+
for (const el of this.inserted) el.setAttribute('material', 'opacity', el.babiaFigure.alpha);
|
|
191
|
+
this.animation = false;
|
|
192
|
+
this.tracks.length = this.inserted.length = 0;
|
|
193
|
+
this.alreadyAutoscaled = false;
|
|
1304
194
|
}
|
|
1305
195
|
}
|
|
196
|
+
if (this.data.autoscale && !this.alreadyAutoscaled && this.boxes.size) this.autoscaleBoats();
|
|
197
|
+
this.interactions.update();
|
|
1306
198
|
},
|
|
1307
199
|
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
if (
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
let new_x = last_x - inc_x;
|
|
1325
|
-
let new_y = last_y + inc_y;
|
|
1326
|
-
let new_z = last_z + inc_z;
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
// Update entity
|
|
1330
|
-
entity.object3D.position.set(
|
|
1331
|
-
new_x,
|
|
1332
|
-
new_y,
|
|
1333
|
-
new_z
|
|
1334
|
-
)
|
|
1335
|
-
|
|
1336
|
-
} else if ((new_time - this.start_time) > this.duration) {
|
|
1337
|
-
entity.object3D.position.set(
|
|
1338
|
-
(figure.posX - translate.x),
|
|
1339
|
-
((parseFloat(figure.height) + translate.y) / 2),
|
|
1340
|
-
(- figure.posY + translate.z),
|
|
1341
|
-
)
|
|
1342
|
-
}
|
|
1343
|
-
}
|
|
200
|
+
autoscaleBoats: function () {
|
|
201
|
+
// Fit lots, not child labels or a quarter's selection box.
|
|
202
|
+
const bounds = new THREE.Box3(), box = new THREE.Box3();
|
|
203
|
+
this.el.object3D.updateWorldMatrix(true, true);
|
|
204
|
+
for (const el of this.boxes.values()) {
|
|
205
|
+
const mesh = el.getObject3D('mesh');
|
|
206
|
+
if (!mesh) continue;
|
|
207
|
+
if (!mesh.geometry.boundingBox) mesh.geometry.computeBoundingBox();
|
|
208
|
+
bounds.union(box.copy(mesh.geometry.boundingBox).applyMatrix4(el.object3D.matrixWorld));
|
|
209
|
+
}
|
|
210
|
+
const size = bounds.getSize(new THREE.Vector3());
|
|
211
|
+
if (!(size.x > 0 && size.z > 0)) return;
|
|
212
|
+
const scale = this.el.object3D.scale;
|
|
213
|
+
this.el.setAttribute('scale', {x: scale.x * this.data.autoscaleSizeX / size.x, y: scale.y,
|
|
214
|
+
z: scale.z * this.data.autoscaleSizeZ / size.z});
|
|
215
|
+
this.alreadyAutoscaled = true;
|
|
1344
216
|
},
|
|
1345
217
|
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
}
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
entity.setAttribute("babia-highlightbuildingbyfield", String(figure.rawData[self.data.highlightBuildingByField]).replace("/", "").replace("@", ""))
|
|
1377
|
-
}
|
|
1378
|
-
|
|
1379
|
-
// add into scene
|
|
1380
|
-
entity.setAttribute('position', {
|
|
1381
|
-
x: position.x,
|
|
1382
|
-
y: position.y,
|
|
1383
|
-
z: position.z
|
|
1384
|
-
});
|
|
1385
|
-
|
|
1386
|
-
// add opacity
|
|
1387
|
-
entity.setAttribute('material', 'opacity', figure.alpha);
|
|
1388
|
-
|
|
1389
|
-
// add opacity
|
|
1390
|
-
entity.setAttribute('material', 'wireframe', figure.wireframe);
|
|
1391
|
-
entity.setAttribute('material', 'wireframeLinewidth', 0.1);
|
|
1392
|
-
|
|
1393
|
-
// transparent if alphaTest
|
|
1394
|
-
if (figure.alphaTest) {
|
|
1395
|
-
entity.setAttribute('material', 'alphaTest', figure.alphaTest);
|
|
1396
|
-
entity.removeAttribute('class');
|
|
1397
|
-
}
|
|
1398
|
-
|
|
1399
|
-
applyBuildingMetrics(entity, figure);
|
|
1400
|
-
return entity;
|
|
218
|
+
updateMetricInfo: function () {
|
|
219
|
+
const d = this.data, meta = this.babiaMetadata;
|
|
220
|
+
this.entityCatColorLegend?.remove();
|
|
221
|
+
this.entityCatColorLegend = null;
|
|
222
|
+
const info = document.getElementById(d.metricsInfoId);
|
|
223
|
+
if (!info) return;
|
|
224
|
+
const lines = ['Metrics information', 'METRIC (FIELD): MIN - MAX - AVG', ''];
|
|
225
|
+
for (const key of ['height', ...(d.area ? ['area'] : ['width', 'depth'])]) {
|
|
226
|
+
lines.push(`${key[0].toUpperCase() + key.slice(1)} (${d[key]}) - ${meta[key + 'Min']} - ${meta[key + 'Max']} - ${meta[key + 'Avg']}`);
|
|
227
|
+
}
|
|
228
|
+
const numeric = typeof meta.color_max === 'number';
|
|
229
|
+
if (numeric) lines.push(`Color (${d.color}) - ${meta.color_min} - ${meta.color_max} - ${meta.colorAvg}`);
|
|
230
|
+
document.getElementById(d.numericColorLegendId)?.setAttribute('visible', numeric);
|
|
231
|
+
info.setAttribute('text', {value: lines.join('\n'), align: 'center', width: 3, color: 'black'});
|
|
232
|
+
if (!d.color || numeric) return;
|
|
233
|
+
const panel = document.createElement('a-plane');
|
|
234
|
+
panel.setAttribute('position', '-3 0 0');
|
|
235
|
+
panel.setAttribute('width', 2.8);
|
|
236
|
+
panel.setAttribute('height', 5);
|
|
237
|
+
panel.setAttribute('color', '#B7B7B7');
|
|
238
|
+
const row = (value, color, y) => {
|
|
239
|
+
const el = document.createElement('a-entity');
|
|
240
|
+
el.setAttribute('text', {value, align: 'center', width: 3, color});
|
|
241
|
+
el.setAttribute('position', {x: 0, y, z: 0});
|
|
242
|
+
panel.appendChild(el);
|
|
243
|
+
};
|
|
244
|
+
row(`COLOR LEGEND (${d.color})`, 'black', 2.2);
|
|
245
|
+
Object.entries(this.categoricColorMaps).forEach(([key, color], i) => row(`${key}: ${color}`, color, 2 - i * 0.15));
|
|
246
|
+
info.appendChild(panel);
|
|
247
|
+
this.entityCatColorLegend = panel;
|
|
1401
248
|
},
|
|
1402
249
|
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
//console.log("processData", _data);
|
|
1409
|
-
let data = this.data;
|
|
1410
|
-
this.newData = _data;
|
|
1411
|
-
this.babiaMetadata = { id: this.babiaMetadata.id++ };
|
|
1412
|
-
this.categoricColorMaps = {}
|
|
1413
|
-
this.categoricColorIndex = 0
|
|
1414
|
-
|
|
1415
|
-
// If color metric activated, save in the metadata the max and min value for mapping
|
|
1416
|
-
if (data.color) {
|
|
1417
|
-
let [color_max, color_min, color_values] = getMaxMinValues(this.newData, data.color, [])
|
|
1418
|
-
this.babiaMetadata['color_max'] = color_max
|
|
1419
|
-
this.babiaMetadata['color_min'] = color_min
|
|
1420
|
-
let colorAvg = Math.round(color_values.reduce((a, b) => a + b, 0) / color_values.length)
|
|
1421
|
-
this.babiaMetadata['colorAvg'] = colorAvg
|
|
1422
|
-
}
|
|
1423
|
-
// Get important data for normalize metrics
|
|
1424
|
-
let [heightMax, heightMin, height_values] = getMaxMinValues(this.newData, data.height, [])
|
|
1425
|
-
this.babiaMetadata['heightMax'] = heightMax
|
|
1426
|
-
this.babiaMetadata['heightMin'] = heightMin
|
|
1427
|
-
let heightAvg = Math.round(height_values.reduce((a, b) => a + b, 0) / height_values.length)
|
|
1428
|
-
this.babiaMetadata['heightAvg'] = heightAvg
|
|
1429
|
-
this.babiaMetadata['maxLevels'] = getLevels(this.newData, 0)
|
|
1430
|
-
|
|
1431
|
-
if (data.area) {
|
|
1432
|
-
let [areaMax, areaMin, area_values] = getMaxMinValues(this.newData, data.area, [])
|
|
1433
|
-
this.babiaMetadata['areaMax'] = areaMax
|
|
1434
|
-
this.babiaMetadata['areaMin'] = areaMin
|
|
1435
|
-
this.babiaMetadata['areaAvg'] = Math.round(area_values.reduce((a, b) => a + b, 0) / area_values.length)
|
|
1436
|
-
} else {
|
|
1437
|
-
let [widthMax, widthMin, width_values] = getMaxMinValues(this.newData, data.width, [])
|
|
1438
|
-
this.babiaMetadata['widthMax'] = widthMax
|
|
1439
|
-
this.babiaMetadata['widthMin'] = widthMin
|
|
1440
|
-
this.babiaMetadata['widthAvg'] = Math.round(width_values.reduce((a, b) => a + b, 0) / width_values.length)
|
|
1441
|
-
|
|
1442
|
-
let [depthMax, depthMin, depth_values] = getMaxMinValues(this.newData, data.depth, [])
|
|
1443
|
-
this.babiaMetadata['depthMax'] = depthMax
|
|
1444
|
-
this.babiaMetadata['depthMin'] = depthMin
|
|
1445
|
-
this.babiaMetadata['depthAvg'] = Math.round(depth_values.reduce((a, b) => a + b, 0) / depth_values.length)
|
|
1446
|
-
}
|
|
1447
|
-
|
|
1448
|
-
// Update place where metric info if activated
|
|
1449
|
-
if (this.data.metricsInfoId) {
|
|
1450
|
-
let text = `Metrics information\nMETRIC (FIELD): MIN - MAX - AVG\n\nHeight (${data.height}) - ${heightMin} - ${heightMax} - ${heightAvg}`
|
|
1451
|
-
if (this.data.area) {
|
|
1452
|
-
text += `\nArea (${data.area}) - ${this.babiaMetadata['areaMin']} - ${this.babiaMetadata['areaMax']} - ${this.babiaMetadata['areaAvg']}`
|
|
1453
|
-
} else {
|
|
1454
|
-
text += `\nWidth (${data.width}) - ${this.babiaMetadata['widthMin']} - ${this.babiaMetadata['widthMax']} - ${this.babiaMetadata['widthAvg']}`
|
|
1455
|
-
text += `\nDepth (${data.depth}) - ${this.babiaMetadata['depthMin']} - ${this.babiaMetadata['depthMax']} - ${this.babiaMetadata['depthAvg']}`
|
|
1456
|
-
}
|
|
1457
|
-
|
|
1458
|
-
if (this.data.color && typeof this.babiaMetadata['color_max'] !== 'string') {
|
|
1459
|
-
document.getElementById(this.data.numericColorLegendId).setAttribute("visible", true)
|
|
1460
|
-
text += `\nColor (${data.color}) - ${this.babiaMetadata['color_min']} - ${this.babiaMetadata['color_max']} - ${this.babiaMetadata['colorAvg']}`
|
|
1461
|
-
}
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
let placeToInsertInfo = document.getElementById(this.data.metricsInfoId)
|
|
1465
|
-
placeToInsertInfo.setAttribute('text', {
|
|
1466
|
-
'value': text,
|
|
1467
|
-
'align': 'center',
|
|
1468
|
-
'width': 3,
|
|
1469
|
-
'color': 'black',
|
|
1470
|
-
'alphaTest': 6,
|
|
1471
|
-
'opacity': 6,
|
|
1472
|
-
'transparent': false
|
|
1473
|
-
})
|
|
1474
|
-
}
|
|
1475
|
-
|
|
1476
|
-
this.notiBuffer.set(this.newData)
|
|
1477
|
-
|
|
1478
|
-
// Remove lines if activated the fixed position
|
|
1479
|
-
if (this.data.treeLayout && this.data.treeFixQuarterHeight) {
|
|
1480
|
-
this.removeTreeLines()
|
|
1481
|
-
}
|
|
1482
|
-
|
|
1483
|
-
// Create city
|
|
1484
|
-
console.log("About to update chart...", this.newData)
|
|
1485
|
-
this.updateChart(this.newData)
|
|
1486
|
-
|
|
1487
|
-
// Categoric color legend
|
|
1488
|
-
if (this.data.metricsInfoId && typeof (this.babiaMetadata['color_max']) !== "number") {
|
|
1489
|
-
// Hide numericlegend
|
|
1490
|
-
document.getElementById(self.data.numericColorLegendId).setAttribute("visible", false)
|
|
1491
|
-
|
|
1492
|
-
// If already exists, just show
|
|
1493
|
-
if (self.entityCatColorLegend) {
|
|
1494
|
-
self.entityCatColorLegend.remove()
|
|
1495
|
-
self.entityCatColorLegend = undefined
|
|
1496
|
-
}
|
|
1497
|
-
let placeToInsertInfo = document.getElementById(this.data.metricsInfoId)
|
|
1498
|
-
self.entityCatColorLegend = document.createElement("a-plane")
|
|
1499
|
-
self.entityCatColorLegend.setAttribute("position", '-3 0 0')
|
|
1500
|
-
self.entityCatColorLegend.setAttribute("width", 2.8)
|
|
1501
|
-
self.entityCatColorLegend.setAttribute("height", 5)
|
|
1502
|
-
self.entityCatColorLegend.setAttribute("position", '-3 0 0')
|
|
1503
|
-
self.entityCatColorLegend.setAttribute("material", 'color', "#B7B7B7")
|
|
1504
|
-
let posY = 2.2
|
|
1505
|
-
let text = `COLOR LEGEND (${this.data.color})`
|
|
1506
|
-
let entity = document.createElement("a-entity")
|
|
1507
|
-
entity.setAttribute('text', {
|
|
1508
|
-
'value': text,
|
|
1509
|
-
'align': 'center',
|
|
1510
|
-
'width': 3,
|
|
1511
|
-
'color': 'black',
|
|
1512
|
-
})
|
|
1513
|
-
entity.setAttribute("position", { x: 0, y: posY, z: 0 })
|
|
1514
|
-
posY = posY - 0.2
|
|
1515
|
-
self.entityCatColorLegend.appendChild(entity)
|
|
1516
|
-
for (const [key, value] of Object.entries(this.categoricColorMaps)) {
|
|
1517
|
-
let text = `${key}: ${value}`;
|
|
1518
|
-
let entity = document.createElement("a-entity")
|
|
1519
|
-
entity.setAttribute('text', {
|
|
1520
|
-
'value': text,
|
|
1521
|
-
'align': 'center',
|
|
1522
|
-
'width': 3,
|
|
1523
|
-
'color': value,
|
|
1524
|
-
})
|
|
1525
|
-
entity.setAttribute("position", { x: 0, y: posY, z: 0 })
|
|
1526
|
-
posY = posY - 0.15
|
|
1527
|
-
self.entityCatColorLegend.appendChild(entity)
|
|
1528
|
-
|
|
1529
|
-
}
|
|
1530
|
-
placeToInsertInfo.appendChild(self.entityCatColorLegend)
|
|
1531
|
-
} else if (this.data.metricsInfoId && typeof (this.babiaMetadata['color_max']) === "number") {
|
|
1532
|
-
if (self.entityCatColorLegend) {
|
|
1533
|
-
self.entityCatColorLegend.remove()
|
|
1534
|
-
self.entityCatColorLegend = undefined
|
|
1535
|
-
}
|
|
1536
|
-
}
|
|
250
|
+
removeLot: function (entity) {
|
|
251
|
+
for (const child of Array.from(entity.children)) if (this.boxes.get(child.id) === child) this.removeLot(child);
|
|
252
|
+
this.interactions.drop(entity);
|
|
253
|
+
this.boxes.delete(entity.id);
|
|
254
|
+
entity.remove();
|
|
1537
255
|
},
|
|
1538
256
|
|
|
1539
257
|
removeTreeLines: function () {
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
line.remove()
|
|
1543
|
-
}
|
|
258
|
+
for (const line of this.lines) line.remove();
|
|
259
|
+
this.lines.length = 0;
|
|
1544
260
|
},
|
|
1545
261
|
|
|
1546
|
-
|
|
1547
|
-
|
|
262
|
+
play: function () { this.interactions.play(); },
|
|
263
|
+
pause: function () { this.interactions.pause(); },
|
|
264
|
+
unsubscribe: function () {
|
|
265
|
+
if (this.prodComponent) this.prodComponent.notiBuffer.unregister(this.notiBufferId);
|
|
266
|
+
this.prodComponent = null;
|
|
1548
267
|
},
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
entity.addEventListener('click', function (e) {
|
|
1559
|
-
// Just launch the event on the child
|
|
1560
|
-
if (e.target !== this)
|
|
1561
|
-
return;
|
|
1562
|
-
|
|
1563
|
-
if (entity.legend) {
|
|
1564
|
-
// Only if it not activated
|
|
1565
|
-
if (!self.data.hideQuarterBoxLegend) {
|
|
1566
|
-
self.el.parentElement.removeChild(transparentBox)
|
|
1567
|
-
}
|
|
1568
|
-
|
|
1569
|
-
// Only if highlighted activated
|
|
1570
|
-
if (self.data.highlightQuarterByClick) {
|
|
1571
|
-
entity.setAttribute('material', 'color', entity.getAttribute('babiaxrFirstColor'))
|
|
1572
|
-
entity.setAttribute('babiaxrHightlightedByClick', false)
|
|
1573
|
-
}
|
|
1574
|
-
|
|
1575
|
-
entity.classList.remove("babiaquarterboxactivated");
|
|
1576
|
-
|
|
1577
|
-
// If legend is a child of the building/quarter
|
|
1578
|
-
if (self.data.legendsAsChildren) {
|
|
1579
|
-
entity.removeChild(entity.legend)
|
|
1580
|
-
} else {
|
|
1581
|
-
self.el.parentElement.removeChild(entity.legend)
|
|
1582
|
-
}
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
// Remove from the array that has the entity activated and the legend
|
|
1586
|
-
const index = self.entitiesWithLegend.findIndex(item => item.entity === entity);
|
|
1587
|
-
if (index > -1) {
|
|
1588
|
-
self.entitiesWithLegend.splice(index, 1);
|
|
1589
|
-
}
|
|
1590
|
-
const indexLegend = self.legendsActive.indexOf(entity.legend);
|
|
1591
|
-
if (index > -1) {
|
|
1592
|
-
self.legendsActive.splice(indexLegend, 1);
|
|
1593
|
-
}
|
|
1594
|
-
|
|
1595
|
-
entity.legend = undefined
|
|
1596
|
-
transparentBox = undefined
|
|
1597
|
-
|
|
1598
|
-
} else {
|
|
1599
|
-
// Global coordinates
|
|
1600
|
-
let worldPos = new THREE.Vector3();
|
|
1601
|
-
let coordinates = worldPos.setFromMatrixPosition(entity.object3D.matrixWorld);
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
if (!self.data.hideQuarterBoxLegend) {
|
|
1605
|
-
transparentBox = document.createElement('a-entity');
|
|
1606
|
-
transparentBox.setAttribute('class', 'babiaquarterlegendbox')
|
|
1607
|
-
entity.classList.add("babiaquarterboxactivated");
|
|
1608
|
-
let oldGeometry = entity.getAttribute('geometry')
|
|
1609
|
-
let scale = self.el.getAttribute("scale") || { x: 1, y: 1, z: 1 }
|
|
1610
|
-
let tsBoxHeight = (oldGeometry.height * scale.y) + self.data.height_quarter_legend_box
|
|
1611
|
-
transparentBox.setAttribute('geometry', {
|
|
1612
|
-
height: tsBoxHeight,
|
|
1613
|
-
depth: oldGeometry.depth * scale.z,
|
|
1614
|
-
width: oldGeometry.width * scale.x
|
|
1615
|
-
});
|
|
1616
|
-
transparentBox.setAttribute('material', {
|
|
1617
|
-
'visible': true,
|
|
1618
|
-
'opacity': 0.4
|
|
1619
|
-
});
|
|
1620
|
-
// This is because the webGL render order does not work well with the transparencies
|
|
1621
|
-
transparentBox.object3D.renderOrder = 1000000000
|
|
1622
|
-
|
|
1623
|
-
transparentBox.setAttribute('position', coordinates)
|
|
1624
|
-
self.el.parentElement.appendChild(transparentBox)
|
|
1625
|
-
}
|
|
1626
|
-
|
|
1627
|
-
// If quarter is highlighted using the click
|
|
1628
|
-
if (self.data.highlightQuarterByClick) {
|
|
1629
|
-
//entity.setAttribute('babiaxrFirstColor', entity.getAttribute("material")["color"])
|
|
1630
|
-
entity.setAttribute('material', 'color', '#bfbfbf')
|
|
1631
|
-
}
|
|
1632
|
-
|
|
1633
|
-
let coordinatesFinal = {
|
|
1634
|
-
x: coordinates.x,
|
|
1635
|
-
y: self.data.height_quarter_legend_title,
|
|
1636
|
-
z: coordinates.z
|
|
1637
|
-
}
|
|
1638
|
-
entity.legend = generateLegend(entity.babiaRawData || {}, {
|
|
1639
|
-
name: figure.name,
|
|
1640
|
-
scale: self.data.legend_scale,
|
|
1641
|
-
lookat: self.data.legend_lookat,
|
|
1642
|
-
template: self.data.legend_text || '{name}',
|
|
1643
|
-
colorPlane: 'black',
|
|
1644
|
-
colorText: 'white',
|
|
1645
|
-
isQuarter: true,
|
|
1646
|
-
fields: {}
|
|
1647
|
-
});
|
|
1648
|
-
|
|
1649
|
-
// If legend is a child of the building/quarter
|
|
1650
|
-
if (self.data.legendsAsChildren) {
|
|
1651
|
-
entity.legend.setAttribute('position', { x: 0, y: self.data.legendsAsChildrenHeight, z: 0 })
|
|
1652
|
-
entity.legend.setAttribute('visible', true);
|
|
1653
|
-
entity.appendChild(entity.legend)
|
|
1654
|
-
} else {
|
|
1655
|
-
entity.legend.setAttribute('position', coordinatesFinal)
|
|
1656
|
-
entity.legend.setAttribute('visible', true);
|
|
1657
|
-
self.el.parentElement.appendChild(entity.legend)
|
|
1658
|
-
}
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
// Add to the elements that has the legend activated
|
|
1662
|
-
self.entitiesWithLegend.push({ 'figure': figure, 'entity': entity })
|
|
1663
|
-
self.legendsActive.push(entity.legend)
|
|
1664
|
-
}
|
|
1665
|
-
})
|
|
1666
|
-
}
|
|
1667
|
-
|
|
1668
|
-
this.drawElements(entity, figure.children, figure.translate_matrix);
|
|
1669
|
-
} else {
|
|
1670
|
-
// Building
|
|
1671
|
-
let entityGeometry;
|
|
1672
|
-
entity.alreadyActive = false;
|
|
1673
|
-
|
|
1674
|
-
entity.addEventListener('click', function (e) {
|
|
1675
|
-
if (e.target !== this)
|
|
1676
|
-
return;
|
|
1677
|
-
|
|
1678
|
-
if (entity.alreadyActive) {
|
|
1679
|
-
// Remove Higlight quarter
|
|
1680
|
-
if (self.data.highlightQuarter) {
|
|
1681
|
-
if (parseInt(entity.parentElement.getAttribute('babiaxrHightlighted')) == 1) {
|
|
1682
|
-
let oldPosition = entity.parentElement.getAttribute('position')
|
|
1683
|
-
entity.parentElement.setAttribute("position", { x: oldPosition.x, y: entity.parentElement.getAttribute('babiaxrFirstYPosition'), z: oldPosition.z })
|
|
1684
|
-
entity.parentElement.setAttribute('material', {
|
|
1685
|
-
'color': entity.parentElement.getAttribute('babiaxrFirstColor')
|
|
1686
|
-
});
|
|
1687
|
-
entity.parentElement.setAttribute('babiaxrHightlighted', 0)
|
|
1688
|
-
} else {
|
|
1689
|
-
let currentActives = parseInt(entity.parentElement.getAttribute('babiaxrHightlighted'))
|
|
1690
|
-
entity.parentElement.setAttribute('babiaxrHightlighted', currentActives - 1)
|
|
1691
|
-
}
|
|
1692
|
-
}
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
entity.legend.setAttribute('visible', false);
|
|
1696
|
-
entity.setAttribute('geometry', {
|
|
1697
|
-
height: entityGeometry.height - 0.1,
|
|
1698
|
-
depth: entityGeometry.depth - 0.1,
|
|
1699
|
-
width: entityGeometry.width - 0.1
|
|
1700
|
-
});
|
|
1701
|
-
entity.setAttribute('material', {
|
|
1702
|
-
'color': entity.getAttribute('babiaxrFirstColor')
|
|
1703
|
-
});
|
|
1704
|
-
|
|
1705
|
-
// If legend is a child of the building/quarter
|
|
1706
|
-
if (self.data.legendsAsChildren) {
|
|
1707
|
-
entity.removeChild(entity.legend)
|
|
1708
|
-
} else {
|
|
1709
|
-
self.el.parentElement.removeChild(entity.legend)
|
|
1710
|
-
}
|
|
1711
|
-
|
|
1712
|
-
// Remove from the array that has the entity activated
|
|
1713
|
-
const index = self.entitiesWithLegend.findIndex(item => item.entity === entity);
|
|
1714
|
-
if (index > -1) {
|
|
1715
|
-
self.entitiesWithLegend.splice(index, 1);
|
|
1716
|
-
}
|
|
1717
|
-
const indexLegend = self.legendsActive.indexOf(entity.legend);
|
|
1718
|
-
if (index > -1) {
|
|
1719
|
-
self.legendsActive.splice(indexLegend, 1);
|
|
1720
|
-
}
|
|
1721
|
-
|
|
1722
|
-
// Remove Hihglight by field
|
|
1723
|
-
if (self.data.highlightBuildingByField) {
|
|
1724
|
-
let fieldValue = entity.getAttribute("babia-highlightbuildingbyfield")
|
|
1725
|
-
let toRemoveHighlight = document.querySelectorAll(`[babia-highlightbuildingbyfield=${fieldValue}]`)
|
|
1726
|
-
toRemoveHighlight.forEach(element => {
|
|
1727
|
-
if (entity !== element) {
|
|
1728
|
-
if (element.highlightbuildingbyfieldactive && !element.alreadyActive) {
|
|
1729
|
-
let oldColor = element.getAttribute('babiaxrBeforeBuildingHighlight')
|
|
1730
|
-
element.setAttribute("material", "color", oldColor)
|
|
1731
|
-
element.highlightbuildingbyfieldactive = false
|
|
1732
|
-
}
|
|
1733
|
-
}
|
|
1734
|
-
});
|
|
1735
|
-
}
|
|
1736
|
-
|
|
1737
|
-
entity.legend = undefined
|
|
1738
|
-
entity.alreadyActive = false
|
|
1739
|
-
} else {
|
|
1740
|
-
// Avoid to click if higlighted by building field
|
|
1741
|
-
if (entity.highlightbuildingbyfieldactive) {
|
|
1742
|
-
return
|
|
1743
|
-
}
|
|
1744
|
-
|
|
1745
|
-
entity.alreadyActive = true
|
|
1746
|
-
|
|
1747
|
-
// If clicked again but not mouseover
|
|
1748
|
-
if (!entity.legend) {
|
|
1749
|
-
// COPY FROM 626
|
|
1750
|
-
entityGeometry = entity.getAttribute('geometry')
|
|
1751
|
-
let boxPosition = entity.getAttribute('position')
|
|
1752
|
-
entity.setAttribute('position', boxPosition)
|
|
1753
|
-
entity.setAttribute('babiaxrFirstColor', entity.getAttribute("material")["color"])
|
|
1754
|
-
entity.setAttribute('material', {
|
|
1755
|
-
'color': 'white'
|
|
1756
|
-
});
|
|
1757
|
-
entity.setAttribute('geometry', {
|
|
1758
|
-
height: entityGeometry.height + 0.1,
|
|
1759
|
-
depth: entityGeometry.depth + 0.1,
|
|
1760
|
-
width: entityGeometry.width + 0.1
|
|
1761
|
-
});
|
|
1762
|
-
entity.legend = generateLegend(entity.babiaRawData, {
|
|
1763
|
-
name: figure.name,
|
|
1764
|
-
scale: self.data.legend_scale,
|
|
1765
|
-
lookat: self.data.legend_lookat,
|
|
1766
|
-
template: self.data.legend_text,
|
|
1767
|
-
colorPlane: 'white',
|
|
1768
|
-
colorText: 'black',
|
|
1769
|
-
isQuarter: false,
|
|
1770
|
-
fields: {
|
|
1771
|
-
height: self.data.height,
|
|
1772
|
-
area: self.data.area,
|
|
1773
|
-
width: self.data.width,
|
|
1774
|
-
depth: self.data.depth,
|
|
1775
|
-
color: self.data.color,
|
|
1776
|
-
}
|
|
1777
|
-
});
|
|
1778
|
-
let worldPos = new THREE.Vector3();
|
|
1779
|
-
let coordinates = worldPos.setFromMatrixPosition(entity.object3D.matrixWorld);
|
|
1780
|
-
let height_real = new THREE.Box3().setFromObject(entity.object3D)
|
|
1781
|
-
let coordinatesFinal = {
|
|
1782
|
-
x: coordinates.x,
|
|
1783
|
-
y: height_real.max.y + 1 + self.data.height_building_legend,
|
|
1784
|
-
z: coordinates.z
|
|
1785
|
-
}
|
|
1786
|
-
|
|
1787
|
-
// If legend is a child of the building/quarter
|
|
1788
|
-
if (self.data.legendsAsChildren) {
|
|
1789
|
-
entity.legend.setAttribute('position', { x: 0, y: self.data.legendsAsChildrenHeight, z: 0 })
|
|
1790
|
-
entity.legend.setAttribute('visible', true);
|
|
1791
|
-
entity.appendChild(entity.legend)
|
|
1792
|
-
} else {
|
|
1793
|
-
entity.legend.setAttribute('position', coordinatesFinal)
|
|
1794
|
-
entity.legend.setAttribute('visible', true);
|
|
1795
|
-
self.el.parentElement.appendChild(entity.legend);
|
|
1796
|
-
}
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
}
|
|
1800
|
-
|
|
1801
|
-
// Higlight quarter
|
|
1802
|
-
if (self.data.highlightQuarter) {
|
|
1803
|
-
if (!entity.parentElement.getAttribute('babiaxrHightlighted') || parseInt(entity.parentElement.getAttribute('babiaxrHightlighted')) == 0) {
|
|
1804
|
-
let oldPosition = entity.parentElement.getAttribute("position")
|
|
1805
|
-
entity.parentElement.setAttribute('babiaxrFirstYPosition', oldPosition.y)
|
|
1806
|
-
entity.parentElement.setAttribute("position", { x: oldPosition.x, y: oldPosition.y + 0.2, z: oldPosition.z })
|
|
1807
|
-
entity.parentElement.setAttribute('material', 'color', '#bfbfbf')
|
|
1808
|
-
entity.parentElement.setAttribute('babiaxrHightlighted', 1)
|
|
1809
|
-
} else {
|
|
1810
|
-
let currentActives = parseInt(entity.parentElement.getAttribute('babiaxrHightlighted'))
|
|
1811
|
-
entity.parentElement.setAttribute('babiaxrHightlighted', currentActives + 1)
|
|
1812
|
-
}
|
|
1813
|
-
}
|
|
1814
|
-
|
|
1815
|
-
// Hihglight by field
|
|
1816
|
-
if (self.data.highlightBuildingByField) {
|
|
1817
|
-
let fieldValue = entity.getAttribute("babia-highlightbuildingbyfield")
|
|
1818
|
-
let toHighlight = document.querySelectorAll(`[babia-highlightbuildingbyfield=${fieldValue}]`)
|
|
1819
|
-
toHighlight.forEach(element => {
|
|
1820
|
-
if (entity !== element && !element.highlightbuildingbyfieldactive && !element.alreadyActive) {
|
|
1821
|
-
element.highlightbuildingbyfieldactive = true
|
|
1822
|
-
element.setAttribute('babiaxrBeforeBuildingHighlight', element.getAttribute("material")["color"])
|
|
1823
|
-
element.setAttribute("material", "color", self.data.highlightBuildingByFieldColor)
|
|
1824
|
-
}
|
|
1825
|
-
});
|
|
1826
|
-
}
|
|
1827
|
-
|
|
1828
|
-
// Add to the elements that has the legend activated
|
|
1829
|
-
self.entitiesWithLegend.push({ 'figure': figure, 'entity': entity })
|
|
1830
|
-
self.legendsActive.push(entity.legend)
|
|
1831
|
-
}
|
|
1832
|
-
|
|
1833
|
-
})
|
|
1834
|
-
|
|
1835
|
-
entity.addEventListener('mouseenter', function () {
|
|
1836
|
-
if (!entity.alreadyActive) {
|
|
1837
|
-
entityGeometry = entity.getAttribute('geometry')
|
|
1838
|
-
let boxPosition = entity.getAttribute('position')
|
|
1839
|
-
entity.setAttribute('position', boxPosition)
|
|
1840
|
-
// If the color is not a field, it is stored at "color"
|
|
1841
|
-
let firstColor = entity.getAttribute("material")["color"] !== "undefined" ? entity.getAttribute("material")["color"] : self.data.building_color;
|
|
1842
|
-
entity.setAttribute('babiaxrFirstColor', firstColor)
|
|
1843
|
-
entity.setAttribute('material', {
|
|
1844
|
-
'color': 'white'
|
|
1845
|
-
});
|
|
1846
|
-
entity.setAttribute('geometry', {
|
|
1847
|
-
height: entityGeometry.height + 0.1,
|
|
1848
|
-
depth: entityGeometry.depth + 0.1,
|
|
1849
|
-
width: entityGeometry.width + 0.1
|
|
1850
|
-
});
|
|
1851
|
-
entity.legend = generateLegend(entity.babiaRawData, {
|
|
1852
|
-
name: figure.name,
|
|
1853
|
-
scale: self.data.legend_scale,
|
|
1854
|
-
lookat: self.data.legend_lookat,
|
|
1855
|
-
template: self.data.legend_text,
|
|
1856
|
-
colorPlane: 'white',
|
|
1857
|
-
colorText: 'black',
|
|
1858
|
-
isQuarter: false,
|
|
1859
|
-
fields: {
|
|
1860
|
-
height: self.data.height,
|
|
1861
|
-
area: self.data.area,
|
|
1862
|
-
width: self.data.width,
|
|
1863
|
-
depth: self.data.depth,
|
|
1864
|
-
color: self.data.color,
|
|
1865
|
-
}
|
|
1866
|
-
});
|
|
1867
|
-
let worldPos = new THREE.Vector3();
|
|
1868
|
-
let coordinates = worldPos.setFromMatrixPosition(entity.object3D.matrixWorld);
|
|
1869
|
-
let height_real = new THREE.Box3().setFromObject(entity.object3D)
|
|
1870
|
-
let coordinatesFinal = {
|
|
1871
|
-
x: coordinates.x,
|
|
1872
|
-
y: height_real.max.y + 1 + self.data.height_building_legend,
|
|
1873
|
-
z: coordinates.z
|
|
1874
|
-
}
|
|
1875
|
-
|
|
1876
|
-
// If legend is a child of the building/quarter
|
|
1877
|
-
if (self.data.legendsAsChildren) {
|
|
1878
|
-
entity.legend.setAttribute('position', { x: 0, y: self.data.legendsAsChildrenHeight, z: 0 })
|
|
1879
|
-
entity.legend.setAttribute('visible', true);
|
|
1880
|
-
entity.appendChild(entity.legend)
|
|
1881
|
-
} else {
|
|
1882
|
-
entity.legend.setAttribute('position', coordinatesFinal)
|
|
1883
|
-
entity.legend.setAttribute('visible', true);
|
|
1884
|
-
self.el.parentElement.appendChild(entity.legend);
|
|
1885
|
-
}
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
// Hihglight by field
|
|
1889
|
-
if (self.data.highlightBuildingByField) {
|
|
1890
|
-
let fieldValue = entity.getAttribute("babia-highlightbuildingbyfield")
|
|
1891
|
-
let toHighlight = document.querySelectorAll(`[babia-highlightbuildingbyfield=${fieldValue}]`)
|
|
1892
|
-
toHighlight.forEach(element => {
|
|
1893
|
-
if (entity !== element && !element.highlightbuildingbyfieldactive && !element.alreadyActive) {
|
|
1894
|
-
element.highlightbuildingbyfieldactive = true
|
|
1895
|
-
element.setAttribute('babiaxrBeforeBuildingHighlight', element.getAttribute("material")["color"])
|
|
1896
|
-
element.setAttribute("material", "color", self.data.highlightBuildingByFieldColor)
|
|
1897
|
-
}
|
|
1898
|
-
});
|
|
1899
|
-
}
|
|
1900
|
-
}
|
|
1901
|
-
|
|
1902
|
-
});
|
|
1903
|
-
entity.addEventListener('mouseleave', function () {
|
|
1904
|
-
if (!entity.alreadyActive && entity.legend) {
|
|
1905
|
-
entity.legend.setAttribute('visible', false);
|
|
1906
|
-
entity.setAttribute('geometry', {
|
|
1907
|
-
height: entityGeometry.height - 0.1,
|
|
1908
|
-
depth: entityGeometry.depth - 0.1,
|
|
1909
|
-
width: entityGeometry.width - 0.1
|
|
1910
|
-
});
|
|
1911
|
-
entity.setAttribute('material', {
|
|
1912
|
-
'color': entity.getAttribute('babiaxrFirstColor')
|
|
1913
|
-
});
|
|
1914
|
-
// If legend is a child of the building/quarter
|
|
1915
|
-
if (self.data.legendsAsChildren) {
|
|
1916
|
-
entity.removeChild(entity.legend)
|
|
1917
|
-
} else {
|
|
1918
|
-
self.el.parentElement.removeChild(entity.legend)
|
|
1919
|
-
}
|
|
1920
|
-
entity.legend = undefined
|
|
1921
|
-
}
|
|
1922
|
-
|
|
1923
|
-
// Remove Hihglight by field
|
|
1924
|
-
if (self.data.highlightBuildingByField) {
|
|
1925
|
-
if (!entity.alreadyActive && !entity.highlightbuildingbyfieldactive) {
|
|
1926
|
-
let fieldValue = entity.getAttribute("babia-highlightbuildingbyfield")
|
|
1927
|
-
let toRemoveHighlight = document.querySelectorAll(`[babia-highlightbuildingbyfield=${fieldValue}]`)
|
|
1928
|
-
toRemoveHighlight.forEach(element => {
|
|
1929
|
-
if (entity !== element) {
|
|
1930
|
-
if (element.highlightbuildingbyfieldactive && !element.alreadyActive) {
|
|
1931
|
-
let oldColor = element.getAttribute('babiaxrBeforeBuildingHighlight')
|
|
1932
|
-
element.setAttribute("material", "color", oldColor)
|
|
1933
|
-
element.highlightbuildingbyfieldactive = false
|
|
1934
|
-
}
|
|
1935
|
-
}
|
|
1936
|
-
});
|
|
1937
|
-
}
|
|
1938
|
-
}
|
|
1939
|
-
});
|
|
1940
|
-
}
|
|
1941
|
-
},
|
|
1942
|
-
})
|
|
1943
|
-
|
|
1944
|
-
/**
|
|
1945
|
-
* This function generate a plane at the top of the building with the desired text
|
|
1946
|
-
*/
|
|
1947
|
-
let generateLegend = (data, {
|
|
1948
|
-
name,
|
|
1949
|
-
scale,
|
|
1950
|
-
lookat,
|
|
1951
|
-
template = '{name}',
|
|
1952
|
-
colorPlane = 'white',
|
|
1953
|
-
colorText = 'black',
|
|
1954
|
-
isQuarter = false,
|
|
1955
|
-
fields = {}
|
|
1956
|
-
}) => {
|
|
1957
|
-
const safe = (val, fallback = '') => (typeof val !== 'undefined' ? val : fallback);
|
|
1958
|
-
const round = v => (typeof v === 'number' ? Math.round(v * 100) / 100 : v);
|
|
1959
|
-
|
|
1960
|
-
// Campos usados
|
|
1961
|
-
const fheight = fields.height || '';
|
|
1962
|
-
const farea = fields.area || '';
|
|
1963
|
-
const fwidth = fields.width || '';
|
|
1964
|
-
const fdepth = fields.depth || '';
|
|
1965
|
-
const fcolor = fields.color || '';
|
|
1966
|
-
|
|
1967
|
-
// Datos correspondientes
|
|
1968
|
-
const vheight = round(safe(data?.[fheight]));
|
|
1969
|
-
const varea = round(safe(data?.[farea]));
|
|
1970
|
-
const vwidth = round(safe(data?.[fwidth]));
|
|
1971
|
-
const vdepth = round(safe(data?.[fdepth]));
|
|
1972
|
-
const vcolor = safe(data?.[fcolor]);
|
|
1973
|
-
|
|
1974
|
-
// Texto final
|
|
1975
|
-
let processedTemplate = isQuarter ? '{name}' : template;
|
|
1976
|
-
|
|
1977
|
-
processedTemplate = processedTemplate
|
|
1978
|
-
.replaceAll('{name}', name)
|
|
1979
|
-
.replaceAll('{height}', vheight)
|
|
1980
|
-
.replaceAll('{area}', varea)
|
|
1981
|
-
.replaceAll('{width}', vwidth)
|
|
1982
|
-
.replaceAll('{depth}', vdepth)
|
|
1983
|
-
.replaceAll('{color}', vcolor)
|
|
1984
|
-
.replaceAll('{fheight}', fheight)
|
|
1985
|
-
.replaceAll('{farea}', farea)
|
|
1986
|
-
.replaceAll('{fwidth}', fwidth)
|
|
1987
|
-
.replaceAll('{fdepth}', fdepth)
|
|
1988
|
-
.replaceAll('{fcolor}', fcolor);
|
|
1989
|
-
|
|
1990
|
-
const knownPlaceholders = new Set([
|
|
1991
|
-
'name', 'height', 'area', 'width', 'depth', 'color',
|
|
1992
|
-
'fheight', 'farea', 'fwidth', 'fdepth', 'fcolor'
|
|
1993
|
-
]);
|
|
1994
|
-
|
|
1995
|
-
const finalText = processedTemplate.replace(/\{(\w+)\}/g, (match, variable) => {
|
|
1996
|
-
if (knownPlaceholders.has(variable)) return match; // ya procesado
|
|
1997
|
-
return safe(data?.[variable], match); // si existe en rawData, lo usamos
|
|
1998
|
-
});
|
|
1999
|
-
|
|
2000
|
-
const lines = finalText.split('\n');
|
|
2001
|
-
const width = Math.max(...lines.map(line => line.length)) / 5;
|
|
2002
|
-
const height = lines.length * 0.3 + 0.3;
|
|
2003
|
-
|
|
2004
|
-
const entity = document.createElement('a-plane');
|
|
2005
|
-
entity.setAttribute('babia-lookat', lookat);
|
|
2006
|
-
entity.setAttribute('rotation', { x: 0, y: 0, z: 0 });
|
|
2007
|
-
entity.setAttribute('height', height);
|
|
2008
|
-
entity.setAttribute('width', width);
|
|
2009
|
-
entity.setAttribute('color', colorPlane);
|
|
2010
|
-
entity.setAttribute('material', { side: 'double' });
|
|
2011
|
-
|
|
2012
|
-
entity.setAttribute('text', {
|
|
2013
|
-
value: finalText,
|
|
2014
|
-
align: 'center',
|
|
2015
|
-
width: 6,
|
|
2016
|
-
color: colorText,
|
|
2017
|
-
alphaTest: 6,
|
|
2018
|
-
opacity: 6,
|
|
2019
|
-
transparent: false
|
|
2020
|
-
});
|
|
2021
|
-
|
|
2022
|
-
entity.setAttribute('visible', false);
|
|
2023
|
-
entity.setAttribute('class', 'babialegend');
|
|
2024
|
-
entity.setAttribute('scale', { x: scale, y: scale, z: scale });
|
|
2025
|
-
|
|
2026
|
-
return entity;
|
|
2027
|
-
};
|
|
2028
|
-
|
|
2029
|
-
function positiveMetric(value) {
|
|
2030
|
-
return Number.isFinite(value) && value > 0 ? value : 0;
|
|
2031
|
-
}
|
|
268
|
+
remove: function () {
|
|
269
|
+
this.interactions.dispose();
|
|
270
|
+
this.unsubscribe();
|
|
271
|
+
for (const entity of this.boxes.values()) this.removeLot(entity);
|
|
272
|
+
this.removeTreeLines();
|
|
273
|
+
this.entityCatColorLegend?.remove();
|
|
274
|
+
this.tracks.length = this.inserted.length = 0;
|
|
275
|
+
}
|
|
276
|
+
});
|
|
2032
277
|
|
|
2033
278
|
function applyBuildingMetrics(entity, figure) {
|
|
2034
279
|
const previous = entity.babiaAppearance;
|
|
@@ -2045,79 +290,3 @@ function applyBuildingMetrics(entity, figure) {
|
|
|
2045
290
|
}
|
|
2046
291
|
entity.babiaAppearance = figure;
|
|
2047
292
|
}
|
|
2048
|
-
|
|
2049
|
-
function setOpacity(entity, opacity) {
|
|
2050
|
-
entity.setAttribute('material', 'opacity', opacity);
|
|
2051
|
-
if (entity.childNodes) {
|
|
2052
|
-
for (let i = 0; i < entity.childNodes.length; i++) {
|
|
2053
|
-
setOpacity(entity.childNodes[i], opacity);
|
|
2054
|
-
}
|
|
2055
|
-
}
|
|
2056
|
-
}
|
|
2057
|
-
|
|
2058
|
-
let getLevels = (elements, levels) => {
|
|
2059
|
-
let level = levels
|
|
2060
|
-
let max_level = levels
|
|
2061
|
-
for (let i in elements) {
|
|
2062
|
-
if (elements[i].children) {
|
|
2063
|
-
level++
|
|
2064
|
-
levels = getLevels(elements[i].children, level)
|
|
2065
|
-
if (max_level < levels) {
|
|
2066
|
-
max_level = levels
|
|
2067
|
-
}
|
|
2068
|
-
level--
|
|
2069
|
-
}
|
|
2070
|
-
}
|
|
2071
|
-
return max_level;
|
|
2072
|
-
}
|
|
2073
|
-
|
|
2074
|
-
let getMaxMinValues = (data, field, valuesToAvg, max, min) => {
|
|
2075
|
-
for (let i = 0; i < data.length; i++) {
|
|
2076
|
-
if (data[i].children) {
|
|
2077
|
-
[max, min] = getMaxMinValues(data[i].children, field, valuesToAvg, max, min)
|
|
2078
|
-
} else {
|
|
2079
|
-
if (data[i][field] !== "null" && !max || data[i][field] > max) {
|
|
2080
|
-
max = data[i][field]
|
|
2081
|
-
}
|
|
2082
|
-
if (data[i][field] !== "null" && !(min !== undefined) || data[i][field] < min) {
|
|
2083
|
-
min = data[i][field]
|
|
2084
|
-
}
|
|
2085
|
-
valuesToAvg.push(data[i][field])
|
|
2086
|
-
}
|
|
2087
|
-
}
|
|
2088
|
-
return [max, min, valuesToAvg]
|
|
2089
|
-
}
|
|
2090
|
-
|
|
2091
|
-
function heatMapColorforValue(val, max, min) {
|
|
2092
|
-
|
|
2093
|
-
//Blue to red
|
|
2094
|
-
let color2 = [19, 82, 138]
|
|
2095
|
-
let color1 = [255, 94, 83]
|
|
2096
|
-
|
|
2097
|
-
let value = ((val || 0) - min) / (max - min)
|
|
2098
|
-
|
|
2099
|
-
var p = value;
|
|
2100
|
-
var w = p * 2 - 1;
|
|
2101
|
-
var w1 = (w / 1 + 1) / 2;
|
|
2102
|
-
var w2 = 1 - w1;
|
|
2103
|
-
var rgb = [Math.round(color1[0] * w1 + color2[0] * w2),
|
|
2104
|
-
Math.round(color1[1] * w1 + color2[1] * w2),
|
|
2105
|
-
Math.round(color1[2] * w1 + color2[2] * w2)];
|
|
2106
|
-
return "rgb(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + ")";
|
|
2107
|
-
|
|
2108
|
-
}
|
|
2109
|
-
|
|
2110
|
-
let findIndex = (list, condicion) => {
|
|
2111
|
-
condicion = condicion.split('=')
|
|
2112
|
-
//console.log(condicion)
|
|
2113
|
-
for (i = 0; i < list.length; i++) {
|
|
2114
|
-
if (list[i][condicion[0]] === condicion[1]) {
|
|
2115
|
-
return i
|
|
2116
|
-
}
|
|
2117
|
-
}
|
|
2118
|
-
return -1
|
|
2119
|
-
}
|
|
2120
|
-
|
|
2121
|
-
let greenColorsurface = (perc) => {
|
|
2122
|
-
return "hsl(140, 100%," + perc + "%)"
|
|
2123
|
-
}
|