Skip to content

Commit beff159

Browse files
committed
Update view.js (#1240) (#1418)
1 parent a17af05 commit beff159

File tree

1 file changed

+43
-49
lines changed

1 file changed

+43
-49
lines changed

source/view.js

Lines changed: 43 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2735,6 +2735,12 @@ view.ObjectSidebar = class extends view.Control {
27352735
this.element = this.createElement('div', 'sidebar-object');
27362736
}
27372737

2738+
addSection(title) {
2739+
const element = this.createElement('div', 'sidebar-section');
2740+
element.innerText = title;
2741+
this.element.appendChild(element);
2742+
}
2743+
27382744
addEntry(name, item) {
27392745
const entry = new view.NameValueView(this._view, name, item);
27402746
const element = entry.render();
@@ -2747,16 +2753,21 @@ view.ObjectSidebar = class extends view.Control {
27472753
return item;
27482754
}
27492755

2750-
addHeader(title) {
2751-
const element = this.createElement('h1', 'sidebar-header');
2752-
element.innerText = title;
2753-
this.element.appendChild(element);
2754-
}
2755-
2756-
addSection(title) {
2757-
const element = this.createElement('div', 'sidebar-section');
2758-
element.innerText = title;
2759-
this.element.appendChild(element);
2756+
addArgument(name, argument, source) {
2757+
const value = new view.ArgumentView(this._view, argument, source);
2758+
value.on('focus', (sender, value) => {
2759+
this.emit('focus', value);
2760+
this._focused = this._focused || new Set();
2761+
this._focused.add(value);
2762+
});
2763+
value.on('blur', (sender, value) => {
2764+
this.emit('blur', value);
2765+
this._focused = this._focused || new Set();
2766+
this._focused.delete(value);
2767+
});
2768+
value.on('select', (sender, value) => this.emit('select', value));
2769+
value.on('activate', (sender, value) => this.emit('activate', value));
2770+
this.addEntry(name, value);
27602771
}
27612772

27622773
error(error, fatal) {
@@ -2844,36 +2855,19 @@ view.NodeSidebar = class extends view.ObjectSidebar {
28442855
const metadata = node.metadata;
28452856
if (Array.isArray(metadata) && metadata.length > 0) {
28462857
this.addSection('Metadata');
2847-
for (const entry of metadata) {
2848-
this.addArgument(entry.name, entry, 'attribute');
2858+
for (const argument of metadata) {
2859+
this.addArgument(argument.name, argument);
28492860
}
28502861
}
28512862
const metrics = this._view.metrics.node(node);
28522863
if (Array.isArray(metrics) && metrics.length > 0) {
28532864
this.addSection('Metrics');
2854-
for (const metric of metrics) {
2855-
this.addArgument(metric.name, metric);
2865+
for (const argument of metrics) {
2866+
this.addArgument(argument.name, argument);
28562867
}
28572868
}
28582869
}
28592870

2860-
addArgument(name, argument, source) {
2861-
const value = new view.ArgumentView(this._view, argument, source);
2862-
value.on('focus', (sender, value) => {
2863-
this.emit('focus', value);
2864-
this._focused = this._focused || new Set();
2865-
this._focused.add(value);
2866-
});
2867-
value.on('blur', (sender, value) => {
2868-
this.emit('blur', value);
2869-
this._focused = this._focused || new Set();
2870-
this._focused.delete(value);
2871-
});
2872-
value.on('select', (sender, value) => this.emit('select', value));
2873-
value.on('activate', (sender, value) => this.emit('activate', value));
2874-
this.addEntry(name, value);
2875-
}
2876-
28772871
activate() {
28782872
this.emit('select', this._node);
28792873
}
@@ -3517,15 +3511,15 @@ view.ConnectionSidebar = class extends view.ObjectSidebar {
35173511
}
35183512
if (Array.isArray(value.metadata) && value.metadata.length > 0) {
35193513
this.addSection('Metadata');
3520-
for (const metadata of value.metadata) {
3521-
this.addProperty(metadata.name, metadata.value);
3514+
for (const argument of value.metadata) {
3515+
this.addArgument(argument.name, argument);
35223516
}
35233517
}
35243518
const metrics = this._view.metrics.value(value);
35253519
if (Array.isArray(metrics) && metrics.length > 0) {
35263520
this.addSection('Metrics');
35273521
for (const argument of metrics) {
3528-
this.addProperty(argument.name, argument.value);
3522+
this.addArgument(argument.name, argument);
35293523
}
35303524
}
35313525
}
@@ -3618,7 +3612,7 @@ view.TensorSidebar = class extends view.ObjectSidebar {
36183612
if (Array.isArray(metadata) && metadata.length > 0) {
36193613
this.addSection('Metadata');
36203614
for (const argument of tensor.metadata) {
3621-
this.addProperty(argument.name, argument.value);
3615+
this.addArgument(argument.name, argument);
36223616
}
36233617
}
36243618
}
@@ -3698,14 +3692,14 @@ view.ModelSidebar = class extends view.ObjectSidebar {
36983692
if (Array.isArray(metadata) && metadata.length > 0) {
36993693
this.addSection('Metadata');
37003694
for (const argument of metadata) {
3701-
this.addProperty(argument.name, argument.value);
3695+
this.addArgument(argument.name, argument);
37023696
}
37033697
}
37043698
const metrics = this._view.metrics.model(model);
37053699
if (Array.isArray(metrics) && metrics.length > 0) {
37063700
this.addSection('Metrics');
37073701
for (const argument of metrics) {
3708-
this.addProperty(argument.name, argument.value);
3702+
this.addArgument(argument.name, argument);
37093703
}
37103704
}
37113705
}
@@ -3764,14 +3758,14 @@ view.TargetSidebar = class extends view.ObjectSidebar {
37643758
if (Array.isArray(metadata) && metadata.length > 0) {
37653759
this.addSection('Metadata');
37663760
for (const argument of metadata) {
3767-
this.addProperty(argument.name, argument.value);
3761+
this.addArgument(argument.name, argument);
37683762
}
37693763
}
37703764
const metrics = this._view.metrics.graph(target);
37713765
if (Array.isArray(metrics) && metrics.length > 0) {
37723766
this.addSection('Metrics');
37733767
for (const argument of metrics) {
3774-
this.addProperty(argument.name, argument.value);
3768+
this.addArgument(argument.name, argument);
37753769
}
37763770
}
37773771
}
@@ -5341,8 +5335,8 @@ metrics.Metrics = class {
53415335
if (data && data.signature === 'metrics' && Array.isArray(data.metrics)) {
53425336
this._metrics.clear();
53435337
for (const metric of data.metrics) {
5344-
if (metric.kind && 'target' in metric) {
5345-
const key = `${metric.kind}::${metric.target}`;
5338+
if (metric.kind && ('target' in metric || 'identifier' in metric)) {
5339+
const key = 'target' in metric ? `${metric.kind}::${metric.target}` : `${metric.kind}[${metric.identifier}]`;
53465340
if (!this._metrics.has(key)) {
53475341
this._metrics.set(key, new Map());
53485342
}
@@ -5356,9 +5350,10 @@ metrics.Metrics = class {
53565350
return false;
53575351
}
53585352

5359-
metrics(entries, type, name) {
5353+
metrics(entries, kind, value) {
53605354
const result = new Map(entries.map((metric) => [metric.name, metric]));
5361-
const key = `${type}::${name}`;
5355+
const name = value.identifier === undefined ? `::${(value.name || '').split('\n').shift()}` : `[${value.identifier}]`;
5356+
const key = `${kind}${name}`;
53625357
if (this._metrics.has(key)) {
53635358
for (const [name, metric] of this._metrics.get(key)) {
53645359
result.set(name, new metrics.Argument(name, metric.value, metric.type || 'attribute'));
@@ -5372,20 +5367,19 @@ metrics.Metrics = class {
53725367
}
53735368

53745369
graph(value) {
5375-
return this.metrics(value.metrics || [], 'graph', value.name || '');
5370+
return this.metrics(value.metrics || [], 'graph', value);
53765371
}
53775372

53785373
node(value) {
5379-
return this.metrics(value.metrics || [], 'node', value.name);
5374+
return this.metrics(value.metrics || [], 'node', value);
53805375
}
53815376

53825377
value(value) {
5383-
const name = (value.name || '').split('\n').shift();
5384-
return this.metrics(value.metrics || [], 'value', name);
5378+
return this.metrics(value.metrics || [], 'value', value);
53855379
}
53865380

53875381
tensor(value) {
5388-
return this.metrics(value.metrics || [], 'tensor', value.name);
5382+
return this.metrics(value.metrics || [], 'tensor', value);
53895383
}
53905384
};
53915385

@@ -6598,7 +6592,7 @@ view.ModelFactoryService = class {
65986592
async import() {
65996593
if (this._host.type === 'Browser' || this._host.type === 'Python') {
66006594
const files = [
6601-
'./server', './onnx', './pytorch', './tflite', './mlnet',
6595+
'./message', './onnx', './pytorch', './tflite', './mlnet',
66026596
'./onnx-proto', './onnx-schema', './tflite-schema',
66036597
'onnx-metadata.json', 'pytorch-metadata.json', 'tflite-metadata.json'
66046598
];

0 commit comments

Comments
 (0)