Skip to content

Commit

Permalink
Update TimelineGraph.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
LPeter1997 committed Sep 21, 2023
1 parent 0cae77a commit 81eda4d
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/Draco.Trace.Visualizer/src/TimelineGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const TimelineGraph = (props: Props) => {
.attr('height', height);

const messageHierarchy = d3.hierarchy(toTimelineMessage(data.rootMessage), getTimelineChildren);
messageHierarchy.each(node => (node as any).value = getTimeSpan(node.data));
messageHierarchy.sum(node => node.children && node.children.length > 0 ? 0 : getTimeSpan(node));

const partitionLayout = d3
.partition<TimelineMessageModel>()
Expand Down Expand Up @@ -93,19 +93,23 @@ function toTimelineMessage(msg: MessageModel): TimelineMessageModel {
}

function getTimelineChildren(msg: MessageModel): TimelineMessageModel[] {
function makePlaceholder(startTime: number, endTime: number): TimelineMessageModel {
return {
name: '',
startTime,
endTime,
isPlaceholder: true,
};
}

if (!msg.children || msg.children.length === 0) return [];

const result = [];

// Check the gap between first child and parent
if (msg.startTime < msg.children[0].startTime) {
// Push placeholder
result.push({
name: '',
startTime: msg.startTime,
endTime: msg.children[0].startTime,
isPlaceholder: true,
});
result.push(makePlaceholder(msg.startTime, msg.children[0].startTime));
}

for (let i = 0; i < msg.children.length; ++i) {
Expand All @@ -128,6 +132,12 @@ function getTimelineChildren(msg: MessageModel): TimelineMessageModel[] {
}
}

// Check the gap between last child and parent
if (msg.children[msg.children.length - 1].endTime < msg.endTime) {
// Push placeholder
result.push(makePlaceholder(msg.children[msg.children.length - 1].endTime, msg.endTime));
}

return result;
}

Expand Down

0 comments on commit 81eda4d

Please sign in to comment.