serialize child items with parent start offset subtracted

for compactness
This commit is contained in:
Bruno Windels 2021-02-24 10:37:20 +01:00
parent 23b8ba7e54
commit ee8886f7c2
2 changed files with 7 additions and 6 deletions

View File

@ -147,7 +147,7 @@ async function loadFile() {
logs.items.sort((a, b) => itemStart(a) - itemStart(b));
rootItem = {c: logs.items};
itemByRef = new Map();
preprocessRecursively(rootItem, itemByRef, []);
preprocessRecursively(rootItem, null, itemByRef, []);
const fragment = logs.items.reduce((fragment, item, i, items) => {
const prevItem = i === 0 ? null : items[i - 1];
@ -160,7 +160,8 @@ async function loadFile() {
main.replaceChildren(fragment);
}
function preprocessRecursively(item, refsMap, path) {
function preprocessRecursively(item, parentElement, refsMap, path) {
item.s = (parentElement?.s || 0) + item.s;
if (itemRefSource(item)) {
refsMap.set(itemRefSource(item), item);
}
@ -170,7 +171,7 @@ function preprocessRecursively(item, refsMap, path) {
const child = itemChildren(item)[i];
const childPath = path.concat(i);
child.id = childPath.join("/");
preprocessRecursively(child, refsMap, childPath);
preprocessRecursively(child, item, refsMap, childPath);
}
}
}

View File

@ -100,7 +100,7 @@ export class LogItem {
}
}
serialize(filter) {
serialize(filter, parentStartTime = null) {
if (this._filterCreator) {
try {
filter = this._filterCreator(new LogFilter(filter), this);
@ -111,7 +111,7 @@ export class LogItem {
let children;
if (this._children !== null) {
children = this._children.reduce((array, c) => {
const s = c.serialize(filter);
const s = c.serialize(filter, this._start);
if (s) {
if (array === null) {
array = [];
@ -127,7 +127,7 @@ export class LogItem {
// in (v)alues, (l)abel and (t)ype are also reserved.
const item = {
// (s)tart
s: this._start,
s: parentStartTime === null ? this._start : this._start - parentStartTime,
// (d)uration
d: this.duration,
// (v)alues