support
support copied to clipboard
Resource allocation is not aggregated correctly for the second (and higher) treeGroups in ResourceHistogram
Hi, When 2 or more groups are applied using treeGroup feature in ResourceHistogram resource allocation is not aggregated correctly by default so when hovering over second group level bars it throws this error because resource is undefined
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'name')
at ResourceHistogram.js:325:64
at Array.map (<anonymous>)
at ResourceHistogram.getGroupBarTip (ResourceHistogram.js:324:1)
at ResourceHistogram.barTooltipTemplate [as _barTooltipTemplate] (ResourceHistogram.js:752:1)
at ResourceHistogram.getTipHtml (TimelineHistogramBase.js:125:1)
And "Loading..." is shown in the tooltip.
It can be fixed by using the same approach as in ResourceUtilization aggregateAllocationEntry. Here's the final code:
aggregateAllocationEntry(acc, entry, _recordIndex, _entryIndex, aggregationContext) {
if (entry.resourceAllocation) {
acc.resourceAllocation = new Map([
...acc.resourceAllocation,
...entry.resourceAllocation,
]);
} else {
acc.resourceAllocation.set(entry.resource, entry);
}
acc.tick = entry.tick;
acc.isOverallocated = acc.isOverallocated || entry.isOverallocated;
acc.isUnderallocated = acc.isUnderallocated || entry.isUnderallocated;
acc.inEventTimeSpan = acc.inEventTimeSpan || entry.inEventTimeSpan;
if (entry.assignments) {
if (acc.assignments) {
entry.assignments.forEach(assignment => acc.assignments.add(assignment));
}
else {
acc.assignments = new Set(entry.assignments);
}
}
return acc;
}
Reproducible here https://bryntum.com/products/gantt/examples/resourcehistogram/ by replacing histogram features with this config:
features : {
scheduleTooltip : false,
tree: true,
treeGroup: { levels: ["name", "city"] },
},