Bläddra i källkod

Update view.js

Lutz Roeder 2 år sedan
förälder
incheckning
e03d63730c
4 ändrade filer med 60 tillägg och 68 borttagningar
  1. 1 1
      source/index.html
  2. 44 48
      source/view.js
  3. 1 1
      test/models.json
  4. 14 18
      test/worker.js

+ 1 - 1
source/index.html

@@ -193,7 +193,7 @@ button { font-family: -apple-system, BlinkMacSystemFont, "Segoe WPC", "Segoe UI"
 .sidebar-item-value code { font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace; overflow: auto; white-space: pre-wrap; word-wrap: break-word; }
 .sidebar-item-value pre { font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace; margin: 0; overflow: auto; white-space: pre; word-wrap: normal; display: block; }
 .sidebar-item-value-line { padding: 4px 6px 4px 6px; }
-.sidebar-item-value-line-link { padding: 4px 6px 4px 6px; cursor: default; overflow-x: auto; }
+.sidebar-item-value-line-link { padding: 4px 6px 4px 6px; cursor: default; overflow-x: auto; white-space: nowrap; }
 .sidebar-item-value-line-link:hover { text-decoration: underline; }
 .sidebar-item-value-line-border { padding: 4px 6px 4px 6px; border-top: 1px solid rgba(27, 31, 35, 0.05); }
 .sidebar-item-value-line-content { white-space: pre; word-wrap: normal; overflow: auto; display: block; }

+ 44 - 48
source/view.js

@@ -1837,8 +1837,11 @@ view.Node = class extends grapher.Node {
             }
             throw error;
         }
-        const content = options.names && (node.name || node.location) ? (node.name || node.location) : type.name.split('.').pop();
+        let content = options.names && (node.name || node.location) ? (node.name || node.location) : type.name.split('.').pop();
         const tooltip = options.names && (node.name || node.location) ? type.name : (node.name || node.location);
+        if (content.length > 24) {
+            content = `${content.substring(0, 12)}\u2026${content.substring(content.length - 12, content.length)}`;
+        }
         const title = header.add(null, styles, content, tooltip);
         title.on('click', () => {
             this.context.activate(node);
@@ -2340,14 +2343,15 @@ view.NodeSidebar = class extends view.ObjectSidebar {
             const status = node.type.status;
             if (module || version || status) {
                 const list = [ module, version ? `v${version}` : '', status ];
-                this.addProperty('module', list.filter((value) => value).join(' '));
+                const value = list.filter((value) => value).join(' ');
+                this.addProperty('module', value, 'nowrap');
             }
         }
         if (node.name) {
-            this.addProperty('name', node.name);
+            this.addProperty('name', node.name, 'nowrap');
         }
         if (node.location) {
-            this.addProperty('location', node.location);
+            this.addProperty('location', node.location, 'nowrap');
         }
         if (node.description) {
             this.addProperty('description', node.description);
@@ -2521,6 +2525,10 @@ view.ValueTextView = class extends view.Control {
                     case 'bold':
                         line.innerHTML = `<b>${item}<b>`;
                         break;
+                    case 'nowrap':
+                        line.innerText = item;
+                        line.style.whiteSpace = style;
+                        break;
                     default:
                         line.innerText = item;
                         break;
@@ -5576,54 +5584,46 @@ view.ModelFactoryService = class {
         unknown();
     }
 
+    async _require(id) {
+        const module = await this._host.require(id);
+        if (!module || !module.ModelFactory) {
+            throw new view.Error(`Failed to load module '${id}'.`);
+        }
+        return new module.ModelFactory();
+    }
+
     async _openContext(context) {
         const modules = this._filter(context).filter((module) => module && module.length > 0);
         const errors = [];
-        let success = false;
-        const next = async () => {
-            if (modules.length > 0) {
-                let module = null;
+        for (const module of modules) {
+            /* eslint-disable no-await-in-loop */
+            const modelFactory = await this._require(module);
+            /* eslint-enable no-await-in-loop */
+            const target = modelFactory.match(context);
+            if (target) {
                 try {
-                    const id = modules.shift();
-                    module = await this._host.require(id);
-                    if (!module.ModelFactory) {
-                        throw new view.Error(`Failed to load module '${id}'.`);
+                    /* eslint-disable no-await-in-loop */
+                    const model = await modelFactory.open(context, target);
+                    /* eslint-enable no-await-in-loop */
+                    if (!model.identifier) {
+                        model.identifier = context.identifier;
                     }
+                    return model;
                 } catch (error) {
-                    success = true;
-                    modules.splice(0, modules.length);
-                    errors.push(error);
-                }
-                if (module) {
-                    try {
-                        const modelFactory = new module.ModelFactory();
-                        const target = modelFactory.match(context);
-                        if (target) {
-                            success = true;
-                            const model = await modelFactory.open(context, target);
-                            if (!model.identifier) {
-                                model.identifier = context.identifier;
-                            }
-                            return model;
-                        }
-                    } catch (error) {
-                        if (context.stream && context.stream.position !== 0) {
-                            context.stream.seek(0);
-                        }
-                        errors.push(error);
+                    if (context.stream && context.stream.position !== 0) {
+                        context.stream.seek(0);
                     }
+                    errors.push(error);
                 }
-                return await next();
             }
-            if (success) {
-                if (errors.length === 1) {
-                    throw errors[0];
-                }
-                throw new view.Error(errors.map((err) => err.message).join('\n'));
+        }
+        if (errors.length > 0) {
+            if (errors.length === 1) {
+                throw errors[0];
             }
-            return null;
-        };
-        return await next();
+            throw new view.Error(errors.map((err) => err.message).join('\n'));
+        }
+        return null;
     }
 
     async _openEntries(entries) {
@@ -5662,14 +5662,10 @@ view.ModelFactoryService = class {
                     const identifier = entry.name.substring(folder.length);
                     const context = new view.Context(entryContext, identifier, entry.stream);
                     const modules = this._filter(context);
-                    for (const id of modules) {
+                    for (const module of modules) {
                         /* eslint-disable no-await-in-loop */
-                        const module = await this._host.require(id);
+                        const modelFactory = await this._require(module);
                         /* eslint-enable no-await-in-loop */
-                        if (!module.ModelFactory) {
-                            throw new view.ArchiveError(`Failed to load module '${id}'.`, null);
-                        }
-                        const modelFactory = new module.ModelFactory();
                         if (modelFactory.match(context)) {
                             matches.push(context);
                             break;

+ 1 - 1
test/models.json

@@ -4559,7 +4559,7 @@
     "target":   "dill_custom_class.pkl",
     "source":   "https://github.com/lutzroeder/netron/files/13035743/dill_custom_class.pkl.zip[dill_custom_class.pkl]",
     "format":   "Pickle",
-    "error":    "Unknown type name '__builtin__.__main__'.\n'dill._dill._create_type' not implemented.",
+    "error":    "'dill._dill._create_type' not implemented.\nUnknown type name '__builtin__.__main__'.",
     "link":     "https://github.com/lutzroeder/netron/issues/901"
   },
   {

+ 14 - 18
test/worker.js

@@ -47,19 +47,12 @@ const host = {};
 host.TestHost = class {
 
     constructor(window) {
-        this._window = window;
-        this._document = window.document;
+        this.errors = [];
+        this.window = window;
+        this.document = window.document;
         host.TestHost.source = host.TestHost.source || dirname('..', 'source');
     }
 
-    get window() {
-        return this._window;
-    }
-
-    get document() {
-        return this._document;
-    }
-
     async view(/* view */) {
     }
 
@@ -98,8 +91,8 @@ host.TestHost = class {
     event(/* name, params */) {
     }
 
-    exception(err /*, fatal */) {
-        throw err;
+    exception(error /*, fatal */) {
+        this.errors.push(error);
     }
 };
 
@@ -349,6 +342,7 @@ export class Target {
             }
         };
         this.status({ name: 'name', target: this.name });
+        const errors = [];
         try {
             await time(this.download);
             await time(this.load);
@@ -356,13 +350,15 @@ export class Target {
             if (!this.tags.has('skip-render')) {
                 await time(this.render);
             }
-            if (this.error) {
-                throw new Error('Expected error.');
-            }
         } catch (error) {
-            if (!this.error || error.message !== this.error) {
-                throw error;
-            }
+            errors.push(error);
+        }
+        errors.push(...this.host.errors);
+        if (errors.length === 0 && this.error) {
+            throw new Error('Expected error.');
+        }
+        if (errors.length > 0 && (!this.error || errors.map((error) => error.message).join('\n') !== this.error)) {
+            throw errors[0];
         }
     }