2020-12-07 08:44:54 +00:00
|
|
|
// Copyright 2020 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-05-25 08:49:11 +00:00
|
|
|
import {App} from '../index.mjs'
|
2020-12-07 08:44:54 +00:00
|
|
|
|
2021-05-04 09:36:04 +00:00
|
|
|
import {FocusEvent, ToolTipEvent} from './events.mjs';
|
2020-12-07 08:44:54 +00:00
|
|
|
import {groupBy, LazyTable} from './helper.mjs';
|
2021-05-03 12:50:10 +00:00
|
|
|
import {CollapsableElement, DOM} from './helper.mjs';
|
2020-12-07 08:44:54 +00:00
|
|
|
|
|
|
|
DOM.defineCustomElement('view/list-panel',
|
|
|
|
(templateText) =>
|
2021-05-03 12:50:10 +00:00
|
|
|
class ListPanel extends CollapsableElement {
|
2020-12-21 09:47:32 +00:00
|
|
|
_selectedLogEntries = [];
|
|
|
|
_displayedLogEntries = [];
|
2020-12-07 08:44:54 +00:00
|
|
|
_timeline;
|
|
|
|
|
|
|
|
_detailsClickHandler = this._handleDetailsClick.bind(this);
|
2020-12-14 09:41:32 +00:00
|
|
|
_logEntryClickHandler = this._handleLogEntryClick.bind(this);
|
2021-05-04 09:36:04 +00:00
|
|
|
_logEntryMouseOverHandler = this._logEntryMouseOverHandler.bind(this);
|
2020-12-07 08:44:54 +00:00
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super(templateText);
|
2021-05-03 12:50:10 +00:00
|
|
|
this.groupKey.addEventListener('change', e => this.requestUpdate());
|
2020-12-21 09:47:32 +00:00
|
|
|
this.showAllRadio.onclick = _ => this._showEntries(this._timeline);
|
|
|
|
this.showTimerangeRadio.onclick = _ =>
|
|
|
|
this._showEntries(this._timeline.selectionOrSelf);
|
|
|
|
this.showSelectionRadio.onclick = _ =>
|
|
|
|
this._showEntries(this._selectedLogEntries);
|
2020-12-07 08:44:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static get observedAttributes() {
|
|
|
|
return ['title'];
|
|
|
|
}
|
|
|
|
|
|
|
|
attributeChangedCallback(name, oldValue, newValue) {
|
|
|
|
if (name == 'title') {
|
|
|
|
this.$('#title').innerHTML = newValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-13 19:33:07 +00:00
|
|
|
set timeline(timeline) {
|
|
|
|
console.assert(timeline !== undefined, 'timeline undefined!');
|
|
|
|
this._timeline = timeline;
|
|
|
|
this.$('.panel').style.display = timeline.isEmpty() ? 'none' : 'inherit';
|
|
|
|
this._initGroupKeySelect();
|
2020-12-07 08:44:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set selectedLogEntries(entries) {
|
2020-12-21 09:47:32 +00:00
|
|
|
if (entries === this._timeline) {
|
2020-12-13 19:33:07 +00:00
|
|
|
this.showAllRadio.click();
|
2020-12-21 09:47:32 +00:00
|
|
|
} else if (entries === this._timeline.selection) {
|
|
|
|
this.showTimerangeRadio.click();
|
2020-12-13 19:33:07 +00:00
|
|
|
} else {
|
|
|
|
this._selectedLogEntries = entries;
|
|
|
|
this.showSelectionRadio.click();
|
|
|
|
}
|
2020-12-07 08:44:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get entryClass() {
|
|
|
|
return this._timeline.at(0)?.constructor;
|
|
|
|
}
|
|
|
|
|
|
|
|
get groupKey() {
|
|
|
|
return this.$('#group-key');
|
|
|
|
}
|
|
|
|
|
|
|
|
get table() {
|
|
|
|
return this.$('#table');
|
|
|
|
}
|
|
|
|
|
2020-12-13 19:33:07 +00:00
|
|
|
get showAllRadio() {
|
|
|
|
return this.$('#show-all');
|
|
|
|
}
|
2021-05-03 12:50:10 +00:00
|
|
|
|
2020-12-13 19:33:07 +00:00
|
|
|
get showTimerangeRadio() {
|
|
|
|
return this.$('#show-timerange');
|
|
|
|
}
|
2021-05-03 12:50:10 +00:00
|
|
|
|
2020-12-13 19:33:07 +00:00
|
|
|
get showSelectionRadio() {
|
|
|
|
return this.$('#show-selection');
|
2020-12-07 08:44:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get _propertyNames() {
|
|
|
|
return this.entryClass?.propertyNames ?? [];
|
|
|
|
}
|
|
|
|
|
2020-12-13 19:33:07 +00:00
|
|
|
_initGroupKeySelect() {
|
|
|
|
const select = this.groupKey;
|
|
|
|
select.options.length = 0;
|
|
|
|
for (const propertyName of this._propertyNames) {
|
|
|
|
const option = DOM.element('option');
|
|
|
|
option.text = propertyName;
|
|
|
|
select.add(option);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-21 09:47:32 +00:00
|
|
|
_showEntries(entries) {
|
2020-12-13 19:33:07 +00:00
|
|
|
this._displayedLogEntries = entries;
|
2021-05-03 12:50:10 +00:00
|
|
|
this.requestUpdate();
|
2020-12-13 19:33:07 +00:00
|
|
|
}
|
|
|
|
|
2020-12-07 08:44:54 +00:00
|
|
|
_update() {
|
2020-12-13 19:33:07 +00:00
|
|
|
if (this._timeline.isEmpty()) return;
|
2020-12-07 08:44:54 +00:00
|
|
|
DOM.removeAllChildren(this.table);
|
2020-12-13 19:33:07 +00:00
|
|
|
if (this._displayedLogEntries.length == 0) return;
|
2020-12-07 08:44:54 +00:00
|
|
|
const propertyName = this.groupKey.selectedOptions[0].text;
|
|
|
|
const groups =
|
2020-12-13 19:33:07 +00:00
|
|
|
groupBy(this._displayedLogEntries, each => each[propertyName], true);
|
2020-12-07 08:44:54 +00:00
|
|
|
this._render(groups, this.table);
|
|
|
|
}
|
|
|
|
|
|
|
|
createSubgroups(group) {
|
|
|
|
const map = new Map();
|
2021-11-18 09:53:32 +00:00
|
|
|
const tempGroups = [];
|
2020-12-07 08:44:54 +00:00
|
|
|
for (let propertyName of this._propertyNames) {
|
|
|
|
map.set(
|
|
|
|
propertyName,
|
|
|
|
groupBy(group.entries, each => each[propertyName], true));
|
|
|
|
}
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
2020-12-14 09:41:32 +00:00
|
|
|
_handleLogEntryClick(e) {
|
2020-12-07 08:44:54 +00:00
|
|
|
const group = e.currentTarget.group;
|
2020-12-14 09:41:32 +00:00
|
|
|
this.dispatchEvent(new FocusEvent(group.key));
|
2020-12-07 08:44:54 +00:00
|
|
|
}
|
|
|
|
|
2021-05-04 09:36:04 +00:00
|
|
|
_logEntryMouseOverHandler(e) {
|
|
|
|
const group = e.currentTarget.group;
|
2021-05-25 08:49:11 +00:00
|
|
|
this.dispatchEvent(new ToolTipEvent(group.key, e.currentTarget));
|
2021-05-04 09:36:04 +00:00
|
|
|
}
|
|
|
|
|
2020-12-07 08:44:54 +00:00
|
|
|
_handleDetailsClick(event) {
|
|
|
|
event.stopPropagation();
|
|
|
|
const tr = event.target.parentNode;
|
|
|
|
const group = tr.group;
|
|
|
|
// Create subgroup in-place if the don't exist yet.
|
|
|
|
if (tr.groups === undefined) {
|
|
|
|
const groups = tr.groups = this.createSubgroups(group);
|
|
|
|
this.renderDrilldown(groups, tr);
|
|
|
|
}
|
|
|
|
const detailsTr = tr.nextSibling;
|
|
|
|
if (tr.classList.contains('open')) {
|
|
|
|
tr.classList.remove('open');
|
|
|
|
detailsTr.style.display = 'none';
|
|
|
|
} else {
|
|
|
|
tr.classList.add('open');
|
|
|
|
detailsTr.style.display = 'table-row';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
renderDrilldown(groups, previousSibling) {
|
|
|
|
const tr = DOM.tr('entry-details');
|
|
|
|
tr.style.display = 'none';
|
|
|
|
// indent by one td.
|
|
|
|
tr.appendChild(DOM.td());
|
|
|
|
const td = DOM.td();
|
|
|
|
td.colSpan = 3;
|
|
|
|
groups.forEach((group, key) => {
|
|
|
|
this.renderDrilldownGroup(td, group, key);
|
|
|
|
});
|
|
|
|
tr.appendChild(td);
|
|
|
|
// Append the new TR after previousSibling.
|
|
|
|
previousSibling.parentNode.insertBefore(tr, previousSibling.nextSibling);
|
|
|
|
}
|
|
|
|
|
2020-12-09 08:01:26 +00:00
|
|
|
renderDrilldownGroup(td, groups, key) {
|
2020-12-07 08:44:54 +00:00
|
|
|
const div = DOM.div('drilldown-group-title');
|
2020-12-09 08:01:26 +00:00
|
|
|
div.textContent = `Grouped by ${key}: ${groups[0]?.parentTotal ?? 0}#`;
|
2020-12-07 08:44:54 +00:00
|
|
|
td.appendChild(div);
|
|
|
|
const table = DOM.table();
|
2020-12-09 08:01:26 +00:00
|
|
|
this._render(groups, table, false)
|
2020-12-07 08:44:54 +00:00
|
|
|
td.appendChild(table);
|
|
|
|
}
|
|
|
|
|
2020-12-09 08:01:26 +00:00
|
|
|
_render(groups, table) {
|
|
|
|
let last;
|
|
|
|
new LazyTable(table, groups, group => {
|
|
|
|
last = group;
|
|
|
|
const tr = DOM.tr();
|
|
|
|
tr.group = group;
|
|
|
|
const details = tr.appendChild(DOM.td('', 'toggle'));
|
|
|
|
details.onclick = this._detailsClickHandler;
|
|
|
|
tr.appendChild(DOM.td(`${group.percent.toFixed(2)}%`, 'percentage'));
|
2021-07-05 08:01:09 +00:00
|
|
|
tr.appendChild(DOM.td(group.length, 'count'));
|
2021-06-15 21:27:47 +00:00
|
|
|
const valueTd = tr.appendChild(DOM.td(group.key?.toString(), 'key'));
|
2021-05-25 08:49:11 +00:00
|
|
|
if (App.isClickable(group.key)) {
|
2020-12-14 09:41:32 +00:00
|
|
|
tr.onclick = this._logEntryClickHandler;
|
2021-05-04 09:36:04 +00:00
|
|
|
tr.onmouseover = this._logEntryMouseOverHandler;
|
2020-12-09 08:01:26 +00:00
|
|
|
valueTd.classList.add('clickable');
|
|
|
|
}
|
|
|
|
return tr;
|
|
|
|
}, 10);
|
|
|
|
}
|
2020-12-07 08:44:54 +00:00
|
|
|
});
|