From 7d9868bb7a52f199b27f693ff5b811afbe922cda Mon Sep 17 00:00:00 2001 From: Jonah Iden Date: Thu, 2 Nov 2023 10:17:38 +0100 Subject: [PATCH 1/4] stopped missing view messages from overlapping; messages now containing more relevant information; added warning to console Signed-off-by: Jonah Iden --- examples/classdiagram/src/di.config.ts | 16 ++++++++-------- packages/sprotty/src/base/views/view.tsx | 17 +++++++++++++++-- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/examples/classdiagram/src/di.config.ts b/examples/classdiagram/src/di.config.ts index d404d0bc..c423246e 100644 --- a/examples/classdiagram/src/di.config.ts +++ b/examples/classdiagram/src/di.config.ts @@ -18,10 +18,10 @@ import { Container, ContainerModule } from 'inversify'; import { TYPES, configureViewerOptions, SGraphView, SLabelView, SCompartmentView, JumpingPolylineEdgeView, ConsoleLogger, LogLevel, loadDefaultModules, HtmlRootView, PreRenderedView, ExpandButtonView, - SRoutingHandleView, PreRenderedElementImpl, HtmlRootImpl, SGraphImpl, configureModelElement, SLabelImpl, - SCompartmentImpl, SEdgeImpl, SButtonImpl, SRoutingHandleImpl, RevealNamedElementActionProvider, + PreRenderedElementImpl, HtmlRootImpl, SGraphImpl, configureModelElement, SLabelImpl, + SCompartmentImpl, SEdgeImpl, SButtonImpl, RevealNamedElementActionProvider, CenterGridSnapper, expandFeature, nameFeature, withEditLabelFeature, editLabelFeature, - RectangularNode, BezierCurveEdgeView, SBezierCreateHandleView, SBezierControlHandleView + RectangularNode, BezierCurveEdgeView } from 'sprotty'; import edgeIntersectionModule from 'sprotty/lib/features/edge-intersection/di.config'; import { BezierMouseListener } from 'sprotty/lib/features/routing/bezier-edge-router'; @@ -75,11 +75,11 @@ export default (containerId: string) => { configureModelElement(context, 'html', HtmlRootImpl, HtmlRootView); configureModelElement(context, 'pre-rendered', PreRenderedElementImpl, PreRenderedView); configureModelElement(context, 'button:expand', SButtonImpl, ExpandButtonView); - configureModelElement(context, 'routing-point', SRoutingHandleImpl, SRoutingHandleView); - configureModelElement(context, 'volatile-routing-point', SRoutingHandleImpl, SRoutingHandleView); - configureModelElement(context, 'bezier-create-routing-point', SRoutingHandleImpl, SBezierCreateHandleView); - configureModelElement(context, 'bezier-remove-routing-point', SRoutingHandleImpl, SBezierCreateHandleView); - configureModelElement(context, 'bezier-routing-point', SRoutingHandleImpl, SBezierControlHandleView); + // configureModelElement(context, 'routing-point', SRoutingHandleImpl, SRoutingHandleView); + // configureModelElement(context, 'volatile-routing-point', SRoutingHandleImpl, SRoutingHandleView); + // configureModelElement(context, 'bezier-create-routing-point', SRoutingHandleImpl, SBezierCreateHandleView); + // configureModelElement(context, 'bezier-remove-routing-point', SRoutingHandleImpl, SBezierCreateHandleView); + // configureModelElement(context, 'bezier-routing-point', SRoutingHandleImpl, SBezierControlHandleView); configureViewerOptions(context, { diff --git a/packages/sprotty/src/base/views/view.tsx b/packages/sprotty/src/base/views/view.tsx index 6643ae2a..1d9d881d 100644 --- a/packages/sprotty/src/base/views/view.tsx +++ b/packages/sprotty/src/base/views/view.tsx @@ -107,6 +107,7 @@ export class ViewRegistry extends InstanceRegistry { } override missing(key: string): IView { + console.warn(`no registered view for type '${key}', please configure a view in the ContainerModule`); return new MissingView(); } } @@ -155,8 +156,20 @@ export class EmptyView implements IView { */ @injectable() export class MissingView implements IView { + private static positionMap = new Map(); + render(model: Readonly, context: RenderingContext): VNode { - const position: Point = (model as any).position || Point.ORIGIN; - return ?{model.id}?; + const position: Point = (model as any).position || this.getPostion(model.type); + return missing "{model.type}" view; + } + + getPostion(type: string) { + let position = MissingView.positionMap.get(type); + if (!position) { + position = Point.ORIGIN; + MissingView.positionMap.forEach(value => position = value.y >= position!.y ? {x: 0, y: value.y + 20} : position); + MissingView.positionMap.set(type, position); + } + return position; } } From 9f90bcb820085f7f3853efe4ab88f631b928d976 Mon Sep 17 00:00:00 2001 From: Jonah Iden Date: Thu, 2 Nov 2023 10:36:55 +0100 Subject: [PATCH 2/4] removed testing changes from classdiagram di-config --- examples/classdiagram/src/di.config.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/classdiagram/src/di.config.ts b/examples/classdiagram/src/di.config.ts index c423246e..d404d0bc 100644 --- a/examples/classdiagram/src/di.config.ts +++ b/examples/classdiagram/src/di.config.ts @@ -18,10 +18,10 @@ import { Container, ContainerModule } from 'inversify'; import { TYPES, configureViewerOptions, SGraphView, SLabelView, SCompartmentView, JumpingPolylineEdgeView, ConsoleLogger, LogLevel, loadDefaultModules, HtmlRootView, PreRenderedView, ExpandButtonView, - PreRenderedElementImpl, HtmlRootImpl, SGraphImpl, configureModelElement, SLabelImpl, - SCompartmentImpl, SEdgeImpl, SButtonImpl, RevealNamedElementActionProvider, + SRoutingHandleView, PreRenderedElementImpl, HtmlRootImpl, SGraphImpl, configureModelElement, SLabelImpl, + SCompartmentImpl, SEdgeImpl, SButtonImpl, SRoutingHandleImpl, RevealNamedElementActionProvider, CenterGridSnapper, expandFeature, nameFeature, withEditLabelFeature, editLabelFeature, - RectangularNode, BezierCurveEdgeView + RectangularNode, BezierCurveEdgeView, SBezierCreateHandleView, SBezierControlHandleView } from 'sprotty'; import edgeIntersectionModule from 'sprotty/lib/features/edge-intersection/di.config'; import { BezierMouseListener } from 'sprotty/lib/features/routing/bezier-edge-router'; @@ -75,11 +75,11 @@ export default (containerId: string) => { configureModelElement(context, 'html', HtmlRootImpl, HtmlRootView); configureModelElement(context, 'pre-rendered', PreRenderedElementImpl, PreRenderedView); configureModelElement(context, 'button:expand', SButtonImpl, ExpandButtonView); - // configureModelElement(context, 'routing-point', SRoutingHandleImpl, SRoutingHandleView); - // configureModelElement(context, 'volatile-routing-point', SRoutingHandleImpl, SRoutingHandleView); - // configureModelElement(context, 'bezier-create-routing-point', SRoutingHandleImpl, SBezierCreateHandleView); - // configureModelElement(context, 'bezier-remove-routing-point', SRoutingHandleImpl, SBezierCreateHandleView); - // configureModelElement(context, 'bezier-routing-point', SRoutingHandleImpl, SBezierControlHandleView); + configureModelElement(context, 'routing-point', SRoutingHandleImpl, SRoutingHandleView); + configureModelElement(context, 'volatile-routing-point', SRoutingHandleImpl, SRoutingHandleView); + configureModelElement(context, 'bezier-create-routing-point', SRoutingHandleImpl, SBezierCreateHandleView); + configureModelElement(context, 'bezier-remove-routing-point', SRoutingHandleImpl, SBezierCreateHandleView); + configureModelElement(context, 'bezier-routing-point', SRoutingHandleImpl, SBezierControlHandleView); configureViewerOptions(context, { From ba1739961a0497f1d9a7d140f4128365d0fdd15b Mon Sep 17 00:00:00 2001 From: Jonah Iden Date: Thu, 2 Nov 2023 10:42:57 +0100 Subject: [PATCH 3/4] fixed test for new missing message Signed-off-by: Jonah Iden --- packages/sprotty/src/base/views/view.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/sprotty/src/base/views/view.spec.ts b/packages/sprotty/src/base/views/view.spec.ts index abca0da0..3d4be921 100644 --- a/packages/sprotty/src/base/views/view.spec.ts +++ b/packages/sprotty/src/base/views/view.spec.ts @@ -46,7 +46,7 @@ describe('base views', () => { it('missing view', () => { const vnode = missingView.render(emptyRoot, context); - expect(toHTML(vnode)).to.be.equal('?EMPTY?'); + expect(toHTML(vnode)).to.be.equal('missing "NONE" view'); const model = new SNodeImpl(); model.bounds = { x: 42, @@ -57,7 +57,7 @@ describe('base views', () => { model.id = 'foo'; model.type = 'type'; const vnode1 = missingView.render(model, context); - expect(toHTML(vnode1)).to.be.equal('?foo?'); + expect(toHTML(vnode1)).to.be.equal('missing "type" view'); }); }); From a4a515ef13c1fd6a4e93294f3f6a69b8ca9df3b8 Mon Sep 17 00:00:00 2001 From: Jonah Iden Date: Mon, 6 Nov 2023 13:08:06 +0100 Subject: [PATCH 4/4] review changes; using logger, moved sprotty-missing css class Signed-off-by: Jonah Iden --- examples/circlegraph/css/diagram.css | 9 --------- examples/classdiagram/css/diagram.css | 8 -------- examples/multicore/css/diagram.css | 8 -------- packages/sprotty/css/sprotty.css | 8 ++++++++ packages/sprotty/src/base/views/view.tsx | 8 ++++++-- 5 files changed, 14 insertions(+), 27 deletions(-) diff --git a/examples/circlegraph/css/diagram.css b/examples/circlegraph/css/diagram.css index 3918cb22..d5a88d44 100644 --- a/examples/circlegraph/css/diagram.css +++ b/examples/circlegraph/css/diagram.css @@ -38,13 +38,4 @@ .sprotty-node.selected { stroke: #dd8; stroke-width: 6; -} - -.sprotty-missing { - stroke-width: 1; - stroke: #f00; - fill: #f00; - font-family: SansSerif; - font-size: 14pt; - text-anchor: middle; } \ No newline at end of file diff --git a/examples/classdiagram/css/diagram.css b/examples/classdiagram/css/diagram.css index a04f3357..63b9e045 100644 --- a/examples/classdiagram/css/diagram.css +++ b/examples/classdiagram/css/diagram.css @@ -123,14 +123,6 @@ stroke-width: 1; } -.sprotty-missing { - stroke-width: 1; - stroke: #f00; - fill: #f00; - font-size: 14pt; - text-anchor: middle; -} - .sprotty-popup-title { font-weight: bold; margin-bottom: 10px; diff --git a/examples/multicore/css/diagram.css b/examples/multicore/css/diagram.css index 131bf15e..089924f3 100644 --- a/examples/multicore/css/diagram.css +++ b/examples/multicore/css/diagram.css @@ -62,14 +62,6 @@ text-align: start; } -.sprotty-missing { - stroke-width: 1; - stroke: #f00; - fill: #f00; - font-size: 14pt; - text-anchor: middle; -} - .sprotty-popup-title { font-weight: bold; margin-bottom: 10px; diff --git a/packages/sprotty/css/sprotty.css b/packages/sprotty/css/sprotty.css index 1a04b7fe..002795d9 100644 --- a/packages/sprotty/css/sprotty.css +++ b/packages/sprotty/css/sprotty.css @@ -93,3 +93,11 @@ .animation-spin { animation: spin 1.5s linear infinite; } + +.sprotty-missing { + stroke-width: 1; + stroke: #f00; + fill: #f00; + font-size: 14pt; + text-anchor: start; +} \ No newline at end of file diff --git a/packages/sprotty/src/base/views/view.tsx b/packages/sprotty/src/base/views/view.tsx index 1d9d881d..ac2ae94b 100644 --- a/packages/sprotty/src/base/views/view.tsx +++ b/packages/sprotty/src/base/views/view.tsx @@ -17,7 +17,7 @@ /** @jsx svg */ import { svg } from '../../lib/jsx'; -import { injectable, multiInject, optional, interfaces } from 'inversify'; +import { injectable, multiInject, optional, interfaces, inject } from 'inversify'; import { VNode } from 'snabbdom'; import { TYPES } from '../types'; import { InstanceRegistry } from '../../utils/registry'; @@ -26,6 +26,7 @@ import { SModelElementImpl, SModelRootImpl, SParentElementImpl } from '../model/ import { EMPTY_ROOT, CustomFeatures } from '../model/smodel-factory'; import { registerModelElement } from '../model/smodel-utils'; import { Point } from 'sprotty-protocol'; +import { ILogger } from '../../utils/logging'; /** * Arguments for `IView` rendering. @@ -94,6 +95,9 @@ export type ViewRegistrationFactory = () => ViewRegistration; */ @injectable() export class ViewRegistry extends InstanceRegistry { + + @inject(TYPES.ILogger) protected logger: ILogger; + constructor(@multiInject(TYPES.ViewRegistration) @optional() registrations: ViewRegistration[]) { super(); this.registerDefaults(); @@ -107,7 +111,7 @@ export class ViewRegistry extends InstanceRegistry { } override missing(key: string): IView { - console.warn(`no registered view for type '${key}', please configure a view in the ContainerModule`); + this.logger.warn(this, `no registered view for type '${key}', please configure a view in the ContainerModule`); return new MissingView(); } }