Skip to content

Commit

Permalink
stopped missing view messages from overlapping;
Browse files Browse the repository at this point in the history
messages now containing more relevant information;
added warning to console

Signed-off-by: Jonah Iden <[email protected]>
  • Loading branch information
jonah-iden committed Nov 2, 2023
1 parent 3625d2d commit 7d9868b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
16 changes: 8 additions & 8 deletions examples/classdiagram/src/di.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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, {
Expand Down
17 changes: 15 additions & 2 deletions packages/sprotty/src/base/views/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export class ViewRegistry extends InstanceRegistry<IView> {
}

override missing(key: string): IView {
console.warn(`no registered view for type '${key}', please configure a view in the ContainerModule`);
return new MissingView();
}
}
Expand Down Expand Up @@ -155,8 +156,20 @@ export class EmptyView implements IView {
*/
@injectable()
export class MissingView implements IView {
private static positionMap = new Map<string, Point>();

render(model: Readonly<SModelElementImpl>, context: RenderingContext): VNode {
const position: Point = (model as any).position || Point.ORIGIN;
return <text class-sprotty-missing={true} x={position.x} y={position.y}>?{model.id}?</text>;
const position: Point = (model as any).position || this.getPostion(model.type);
return <text class-sprotty-missing={true} x={position.x} y={position.y}>missing "{model.type}" view</text>;
}

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;
}
}

0 comments on commit 7d9868b

Please sign in to comment.