Skip to content

Commit d714c50

Browse files
committed
Update view.js (#1240) (#1418)
1 parent 7853dd9 commit d714c50

File tree

4 files changed

+124
-17
lines changed

4 files changed

+124
-17
lines changed

source/app.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ app.Application = class {
7373
this._dropPaths(event.sender, paths);
7474
event.returnValue = null;
7575
});
76+
electron.ipcMain.on('update-recents', (event, data) => {
77+
this._updateRecents(data.path);
78+
event.returnValue = null;
79+
});
7680
electron.ipcMain.on('show-save-dialog', async (event, options) => {
7781
const owner = event.sender.getOwnerBrowserWindow();
7882
const argument = {};
@@ -228,7 +232,6 @@ app.Application = class {
228232
for (const path of paths) {
229233
if (view) {
230234
view.open(path);
231-
this._updateRecents(path);
232235
view = null;
233236
} else {
234237
this._openPath(path);
@@ -285,7 +288,6 @@ app.Application = class {
285288
const view = this._views.activeView;
286289
if (view && view.path) {
287290
view.open(view.path);
288-
this._updateRecents(view.path);
289291
}
290292
}
291293

source/browser.js

+6
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,14 @@ host.BrowserHost = class {
486486
async _openContext(context) {
487487
this._telemetry.set('session_engaged', 1);
488488
try {
489+
const attachment = await this._view.attach(context);
490+
if (attachment) {
491+
this._view.show(null);
492+
return 'context-open-attachment';
493+
}
489494
const model = await this._view.open(context);
490495
if (model) {
496+
this._view.show(null);
491497
this.document.title = context.name || context.identifier;
492498
return '';
493499
}

source/electron.mjs

+15-9
Original file line numberDiff line numberDiff line change
@@ -462,17 +462,23 @@ host.ElectronHost = class {
462462
return;
463463
}
464464
try {
465-
const model = await this._view.open(context);
466-
this._view.show(null);
467-
const options = { ...this._view.options };
468-
if (model) {
469-
options.path = path;
470-
this._title(location.label);
465+
const attachment = await this._view.attach(context);
466+
if (attachment) {
467+
this._view.show(null);
471468
} else {
472-
options.path = path;
473-
this._title('');
469+
const model = await this._view.open(context);
470+
this._view.show(null);
471+
const options = { ...this._view.options };
472+
if (model) {
473+
options.path = path;
474+
this._title(location.label);
475+
} else {
476+
options.path = path;
477+
this._title('');
478+
}
479+
electron.ipcRenderer.send('update-recents', { path });
480+
this.update(options);
474481
}
475-
this.update(options);
476482
} catch (error) {
477483
const options = { ...this._view.options };
478484
if (error) {

source/view.js

+99-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ view.View = class {
1919
};
2020
this._options = { ...this._defaultOptions };
2121
this._model = null;
22+
this._metrics = new metrics.Metrics();
2223
this._stack = [];
2324
this._selection = [];
2425
this._sidebar = new view.Sidebar(this._host);
@@ -287,6 +288,10 @@ view.View = class {
287288
return this._model;
288289
}
289290

291+
get metrics() {
292+
return this._metrics;
293+
}
294+
290295
get options() {
291296
return this._options;
292297
}
@@ -715,6 +720,13 @@ view.View = class {
715720
}
716721
}
717722

723+
async attach(context) {
724+
if (this._model && await this._metrics.open(context)) {
725+
return true;
726+
}
727+
return false;
728+
}
729+
718730
async _updateActiveTarget(stack) {
719731
this._sidebar.close();
720732
if (this._model) {
@@ -2836,6 +2848,13 @@ view.NodeSidebar = class extends view.ObjectSidebar {
28362848
this.addArgument(entry.name, entry, 'attribute');
28372849
}
28382850
}
2851+
const metrics = this._view.metrics.node(node);
2852+
if (Array.isArray(metrics) && metrics.length > 0) {
2853+
this.addSection('Metrics');
2854+
for (const metric of metrics) {
2855+
this.addArgument(metric.name, metric);
2856+
}
2857+
}
28392858
}
28402859

28412860
addArgument(name, argument, source) {
@@ -3502,6 +3521,13 @@ view.ConnectionSidebar = class extends view.ObjectSidebar {
35023521
this.addProperty(metadata.name, metadata.value);
35033522
}
35043523
}
3524+
const metrics = this._view.metrics.value(value);
3525+
if (Array.isArray(metrics) && metrics.length > 0) {
3526+
this.addSection('Metrics');
3527+
for (const argument of metrics) {
3528+
this.addProperty(argument.name, argument.value);
3529+
}
3530+
}
35053531
}
35063532

35073533
addNodeList(name, list) {
@@ -3604,11 +3630,12 @@ view.TensorSidebar = class extends view.ObjectSidebar {
36043630
this._tensor = new base.Tensor(tensor);
36053631
if (!this._tensor.empty) {
36063632
if (!this._metrics) {
3607-
this._metrics = new metrics.Tensor(this._tensor);
3633+
const tensor = new metrics.Tensor(this._tensor);
3634+
this._metrics = this._view.metrics.tensor(tensor);
36083635
}
3609-
if (this._metrics.metrics.length > 0) {
3636+
if (this._metrics.length > 0) {
36103637
this.addSection('Metrics');
3611-
for (const metric of this._metrics.metrics) {
3638+
for (const metric of this._metrics) {
36123639
const value = metric.type === 'percentage' ? `${(metric.value * 100).toFixed(1)}%` : metric.value;
36133640
this.addProperty(metric.name, [value]);
36143641
}
@@ -3674,7 +3701,7 @@ view.ModelSidebar = class extends view.ObjectSidebar {
36743701
this.addProperty(argument.name, argument.value);
36753702
}
36763703
}
3677-
const metrics = model.metrics;
3704+
const metrics = this._view.metrics.model(model);
36783705
if (Array.isArray(metrics) && metrics.length > 0) {
36793706
this.addSection('Metrics');
36803707
for (const argument of metrics) {
@@ -3740,7 +3767,7 @@ view.TargetSidebar = class extends view.ObjectSidebar {
37403767
this.addProperty(argument.name, argument.value);
37413768
}
37423769
}
3743-
const metrics = target.metrics;
3770+
const metrics = this._view.metrics.graph(target);
37443771
if (Array.isArray(metrics) && metrics.length > 0) {
37453772
this.addSection('Metrics');
37463773
for (const argument of metrics) {
@@ -5301,6 +5328,67 @@ markdown.Generator = class {
53015328
}
53025329
};
53035330

5331+
metrics.Metrics = class {
5332+
5333+
constructor() {
5334+
this._metrics = new Map();
5335+
}
5336+
5337+
async open(context) {
5338+
const content = new view.Context(context);
5339+
if (content.identifier.toLowerCase().endsWith('.metrics.json')) {
5340+
const data = await content.peek('json');
5341+
if (data && data.signature === 'metrics' && Array.isArray(data.metrics)) {
5342+
this._metrics.clear();
5343+
for (const metric of data.metrics) {
5344+
if (metric.kind && 'target' in metric) {
5345+
const key = `${metric.kind}::${metric.target}`;
5346+
if (!this._metrics.has(key)) {
5347+
this._metrics.set(key, new Map());
5348+
}
5349+
const entries = this._metrics.get(key);
5350+
entries.set(metric.name, { value: metric.value, type: metric.type });
5351+
}
5352+
}
5353+
return true;
5354+
}
5355+
}
5356+
return false;
5357+
}
5358+
5359+
metrics(entries, type, name) {
5360+
const result = new Map(entries.map((metric) => [metric.name, metric]));
5361+
const key = `${type}::${name}`;
5362+
if (this._metrics.has(key)) {
5363+
for (const [name, metric] of this._metrics.get(key)) {
5364+
result.set(name, new metrics.Argument(name, metric.value, metric.type || 'attribute'));
5365+
}
5366+
}
5367+
return Array.from(result.values());
5368+
}
5369+
5370+
model(value) {
5371+
return this.metrics(value.metrics || [], 'model', '');
5372+
}
5373+
5374+
graph(value) {
5375+
return this.metrics(value.metrics || [], 'graph', value.name || '');
5376+
}
5377+
5378+
node(value) {
5379+
return this.metrics(value.metrics || [], 'node', value.name);
5380+
}
5381+
5382+
value(value) {
5383+
const name = (value.name || '').split('\n').shift();
5384+
return this.metrics(value.metrics || [], 'value', name);
5385+
}
5386+
5387+
tensor(value) {
5388+
return this.metrics(value.metrics || [], 'tensor', value.name);
5389+
}
5390+
};
5391+
53045392
metrics.Argument = class {
53055393

53065394
constructor(name, value, type) {
@@ -5317,6 +5405,10 @@ metrics.Tensor = class {
53175405
this._metrics = null;
53185406
}
53195407

5408+
get name() {
5409+
return this._tensor.name || '';
5410+
}
5411+
53205412
get metrics() {
53215413
if (this._metrics === null) {
53225414
this._metrics = [];
@@ -6026,6 +6118,7 @@ view.ModelFactoryService = class {
60266118
{ name: 'Netron metadata', tags: ['[].name', '[].category'] },
60276119
{ name: 'Netron test data', tags: ['[].type', '[].target', '[].source', '[].format', '[].link'] },
60286120
{ name: 'Netron configuration', tags: ['recents', 'consent'] },
6121+
{ name: 'Netron metrics data', tags: ['signature', 'metrics'] },
60296122
{ name: 'Darkflow metadata', tags: ['net', 'type', 'model'] },
60306123
{ name: 'keras-yolo2 configuration', tags: ['model', 'train', 'valid'] },
60316124
{ name: 'Vulkan SwiftShader ICD manifest', tags: ['file_format_version', 'ICD'] },
@@ -6063,7 +6156,7 @@ view.ModelFactoryService = class {
60636156
{ name: 'Jupyter Notebook data', tags: ['cells', 'nbformat'] },
60646157
{ name: 'Kaggle credentials', tags: ['username','key'] },
60656158
{ name: '.NET runtime configuration', tags: ['runtimeOptions.configProperties'] },
6066-
{ name: '.NET dependency manifest', tags: ['runtimeTarget', 'targets', 'libraries'] }
6159+
{ name: '.NET dependency manifest', tags: ['runtimeTarget', 'targets', 'libraries'] },
60676160
];
60686161
const match = (obj, tag) => {
60696162
if (tag.startsWith('[].')) {

0 commit comments

Comments
 (0)