Skip to content

Commit

Permalink
Merge pull request #468 from xBimTeam/feature/heatmaps
Browse files Browse the repository at this point in the history
Fixed issue about reading stringfied heatmap sources values
  • Loading branch information
Ibrahim5aad authored Sep 11, 2024
2 parents 5a35389 + 5f1549c commit 788bc81
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
4 changes: 2 additions & 2 deletions examples/data-visualization/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ viewer.on('loaded', args => {

setInterval(function(){
if(selectedChannel.channelId === tempChannelId){
temperatureSource.value = getRandomInt(40);
temperatureSource.value = getRandomInt(40).toString(); // will work for stringified
heatmap.renderSource(temperatureSource.id);
sourceIcon.description = `Room ${selectedChannel.name}: ${temperatureSource.value}${selectedChannel.unit}`;
}
else{
humiditySource.value = getRandomInt(100);
humiditySource.value = getRandomInt(100).toString();
heatmap.renderSource(humiditySource.id);
sourceIcon.description = `Room ${selectedChannel.name}: ${humiditySource.value}${selectedChannel.unit}`;
}
Expand Down
27 changes: 14 additions & 13 deletions src/plugins/DataVisualization/Heatmap/heatmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ export class Heatmap implements IPlugin {
});
const values = Object.keys(channel.values);
(sources ?? this._sources).filter(s => s.channelId == channel.channelId).forEach(source => {
// Normalize source value to [0, 1.0]
const stringVal = source.value.toString();
if(values.includes(stringVal)){
const colorHex = channel.values[source.value];
Expand All @@ -146,16 +145,15 @@ export class Heatmap implements IPlugin {
});

(sources ?? this._sources).filter(s => s.channelId == channel.channelId).forEach(source => {
// Normalize source value to [0, 1.0]
if(typeof source.value === 'number')
{
const value = source.value as number;
for (let i = 0; i < channel.valueRanges.length; i++) {
const range = channel.valueRanges[i];
if(value >= range.min && value <= range.max){
this._viewer.setStyle(this._colorStylesMap[range.color], [source.productId], source.modelId);
break;
}
const value = Number(source.value);
if(isNaN(value))
return;

for (let i = 0; i < channel.valueRanges.length; i++) {
const range = channel.valueRanges[i];
if(value >= range.min && value <= range.max){
this._viewer.setStyle(this._colorStylesMap[range.color], [source.productId], source.modelId);
break;
}
}
});
Expand All @@ -173,8 +171,11 @@ export class Heatmap implements IPlugin {
this._nextStyleId++;
});
(sources ?? this._sources).filter(s => s.channelId == channel.channelId).forEach(source => {
// Normalize source value to [0, 1.0]
var value = this.clamp((source.value - channel.min) / (channel.max - channel.min), channel.min, channel.max);
const srcValue = Number(source.value);
if(isNaN(srcValue))
return;

var value = this.clamp((srcValue - channel.min) / (channel.max - channel.min), channel.min, channel.max);
if(this._valueStylesMap[value]){
var style = this._valueStylesMap[value];
this._viewer.setStyle(style, [source.productId], source.modelId);
Expand Down

0 comments on commit 788bc81

Please sign in to comment.