In the ASP.NET Core Timesheet tutorial, the histogram displayed in the first (frozen) row is calculated using the following logic (in onBeforeCellRender):
onBeforeCellRender: args => {
if (args.cell.resource === "histogram") {
const max = timesheet.rows.all().filter(r => r.data.frozen !== "top" && r.children().length === 0).length;
const cStartTime = args.cell.start.getTimePart();
const cEndTime = args.cell.end.getTimePart();
const allEventParts = timesheet.rows.all().flatMap(row => row.events.all());
const inUse = allEventParts.filter(e => {
const eStartTime = e.part.start.getTimePart();
const eEndTime = e.part.end === e.part.start.addDays(1) ? DayPilot.Duration.ofDays(1).totalMilliseconds() :e.part.end.getTimePart();
return DayPilot.Util.overlaps(cStartTime, cEndTime, eStartTime, eEndTime);
}).length;
const percentage = inUse / max;
args.cell.properties.backColor = "#ffffff";
if (inUse > 0) {
const cellHeight = timesheet.eventHeight - 1;
const barHeight = Math.min(percentage, 1) * cellHeight;
args.cell.properties.areas = [
{
bottom: 1,
height: barHeight,
left: 3,
right: 3,
backColor: "#dd7e6b",
style: "box-sizing: border-box; border: 1px solid #cc4125;",
}
];
}
}
}
This seems to work fine.
To make sure that the histogram gets updated after drag and drop changes, the histogram row needs to be marked for automatic updates (cellsAutoUpdated
):
resources: [
{name: "Histogram", id: "histogram", frozen: "top", cellsAutoUpdated: true, ... },
// ...
],