From 7d9868bb7a52f199b27f693ff5b811afbe922cda Mon Sep 17 00:00:00 2001 From: Jonah Iden Date: Thu, 2 Nov 2023 10:17:38 +0100 Subject: [PATCH] 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; } }