Skip to content

Commit

Permalink
Renamed ViewportRootElement
Browse files Browse the repository at this point in the history
  • Loading branch information
spoenemann committed Sep 29, 2023
1 parent 08dc794 commit 36d742c
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 23 deletions.
10 changes: 10 additions & 0 deletions packages/sprotty-protocol/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ export interface Alignable {
export interface Viewport extends Scrollable, Zoomable {
}

/**
* Usually the root of a model is also a viewport.
*/
export interface ViewportRootElement extends SModelRoot {
scroll?: Point
zoom?: number
position?: Point
size?: Dimension
}

/**
* A scrollable element has a scroll position, which indicates the top left corner of the
* visible area.
Expand Down
2 changes: 1 addition & 1 deletion packages/sprotty/src/base/commands/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export interface CommandExecutionContext {
/** The current Sprotty model (i.e. the main model that is visible to the user) */
root: SModelRootImpl

/** Used to turn sprotty schema elements (e.g. from the action) into model elements */
/** Used to turn sprotty external model elements (e.g. from the action) into internal model elements */
modelFactory: IModelFactory

/** Allows to give some feedback to the console */
Expand Down
14 changes: 7 additions & 7 deletions packages/sprotty/src/features/projection/views.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { VNode, VNodeStyle, h } from 'snabbdom';
import { Bounds } from 'sprotty-protocol/lib/utils/geometry';
import { IView, IViewArgs, RenderingContext } from '../../base/views/view';
import { setAttr, setClass } from '../../base/views/vnode-utils';
import { ViewportRootElement } from '../viewport/viewport-root';
import { ViewportRootElementImpl } from '../viewport/viewport-root';
import { getModelBounds, getProjections, ViewProjection } from './model';

/**
Expand All @@ -31,7 +31,7 @@ import { getModelBounds, getProjections, ViewProjection } from './model';
@injectable()
export class ProjectedViewportView implements IView {

render(model: Readonly<ViewportRootElement>, context: RenderingContext, args?: IViewArgs): VNode {
render(model: Readonly<ViewportRootElementImpl>, context: RenderingContext, args?: IViewArgs): VNode {
const rootNode: VNode = <div class-sprotty-root={true}>
{this.renderSvg(model, context, args)}
{this.renderProjections(model, context, args)}
Expand All @@ -40,13 +40,13 @@ export class ProjectedViewportView implements IView {
return rootNode;
}

protected renderSvg(model: Readonly<ViewportRootElement>, context: RenderingContext, args?: IViewArgs): VNode {
protected renderSvg(model: Readonly<ViewportRootElementImpl>, context: RenderingContext, args?: IViewArgs): VNode {
const transform = `scale(${model.zoom}) translate(${-model.scroll.x},${-model.scroll.y})`;
const ns = 'http://www.w3.org/2000/svg';
return h('svg', { ns }, h('g', { ns, attrs: { transform } }, context.renderChildren(model)));
}

protected renderProjections(model: Readonly<ViewportRootElement>, context: RenderingContext, args?: IViewArgs): VNode[] {
protected renderProjections(model: Readonly<ViewportRootElementImpl>, context: RenderingContext, args?: IViewArgs): VNode[] {
if (model.zoom <= 0) {
return [];
}
Expand All @@ -61,7 +61,7 @@ export class ProjectedViewportView implements IView {
];
}

protected renderProjectionBar(projections: ViewProjection[], model: Readonly<ViewportRootElement>, modelBounds: Bounds, orientation: 'horizontal' | 'vertical'): VNode {
protected renderProjectionBar(projections: ViewProjection[], model: Readonly<ViewportRootElementImpl>, modelBounds: Bounds, orientation: 'horizontal' | 'vertical'): VNode {
const params: ProjectionParams = { modelBounds, orientation } as ProjectionParams;
// NOTE: Here we assume that the projection bars have the same size as the diagram canvas, i.e. they are drawn as overlay above the canvas.
params.factor = orientation === 'horizontal' ? model.canvasBounds.width / modelBounds.width : model.canvasBounds.height / modelBounds.height;
Expand All @@ -75,7 +75,7 @@ export class ProjectedViewportView implements IView {
</div>;
}

protected renderViewport(model: Readonly<ViewportRootElement>, params: ProjectionParams): VNode {
protected renderViewport(model: Readonly<ViewportRootElementImpl>, params: ProjectionParams): VNode {
let canvasSize, viewportPos: number;
if (params.orientation === 'horizontal') {
canvasSize = model.canvasBounds.width;
Expand Down Expand Up @@ -106,7 +106,7 @@ export class ProjectedViewportView implements IView {
return <div class-sprotty-viewport={true} style={style} />;
}

protected renderProjection(projection: ViewProjection, model: Readonly<ViewportRootElement>, params: ProjectionParams): VNode {
protected renderProjection(projection: ViewProjection, model: Readonly<ViewportRootElementImpl>, params: ProjectionParams): VNode {
let canvasSize, projPos, projSize: number;
if (params.orientation === 'horizontal') {
canvasSize = model.canvasBounds.width;
Expand Down
4 changes: 2 additions & 2 deletions packages/sprotty/src/features/update/update-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { MoveAnimation, ResolvedElementMove, MorphEdgesAnimation } from '../move
import { Fadeable, isFadeable } from '../fade/model';
import { isLocateable } from '../move/model';
import { isSizeable } from '../bounds/model';
import { ViewportRootElement } from '../viewport/viewport-root';
import { ViewportRootElementImpl } from '../viewport/viewport-root';
import { isSelectable } from '../select/model';
import { MatchResult, ModelMatcher, Match, forEachMatch } from './model-matching';
import { ResolvedElementResize, ResizeAnimation } from '../bounds/resize';
Expand Down Expand Up @@ -241,7 +241,7 @@ export class UpdateModelCommand extends Command {
if (left instanceof SModelRootImpl && right instanceof SModelRootImpl) {
right.canvasBounds = left.canvasBounds;
}
if (left instanceof ViewportRootElement && right instanceof ViewportRootElement) {
if (left instanceof ViewportRootElementImpl && right instanceof ViewportRootElementImpl) {
right.scroll = left.scroll;
right.zoom = left.zoom;
}
Expand Down
11 changes: 2 additions & 9 deletions packages/sprotty/src/features/viewport/viewport-root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,18 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { SModelRoot, Viewport } from 'sprotty-protocol/lib/model';
import { Viewport } from 'sprotty-protocol/lib/model';
import { Bounds, Dimension, isBounds, Point } from 'sprotty-protocol/lib/utils/geometry';
import { SModelRootImpl, ModelIndexImpl } from '../../base/model/smodel';
import { viewportFeature } from "./model";
import { exportFeature } from "../export/model";
import { BoundsAware } from "../bounds/model";

export interface ViewportRootElementSchema extends SModelRoot {
scroll?: Point
zoom?: number
position?: Point
size?: Dimension
}

/**
* Model root element that defines a viewport, so it transforms the coordinate system with
* a `scroll` translation and a `zoom` scaling.
*/
export class ViewportRootElement extends SModelRootImpl implements Viewport, BoundsAware {
export class ViewportRootElementImpl extends SModelRootImpl implements Viewport, BoundsAware {
static readonly DEFAULT_FEATURES = [viewportFeature, exportFeature];

scroll: Point = { x: 0, y: 0 };
Expand Down
4 changes: 2 additions & 2 deletions packages/sprotty/src/graph/sgraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ import { Hoverable, hoverFeedbackFeature, popupFeature } from '../features/hover
import { moveFeature } from '../features/move/model';
import { connectableFeature, SConnectableElementImpl, SRoutableElementImpl } from '../features/routing/model';
import { Selectable, selectFeature } from '../features/select/model';
import { ViewportRootElement } from '../features/viewport/viewport-root';
import { ViewportRootElementImpl } from '../features/viewport/viewport-root';
import { FluentIterable, FluentIterableImpl } from '../utils/iterable';

/**
* Root element for graph-like models.
*/
export class SGraphImpl extends ViewportRootElement {
export class SGraphImpl extends ViewportRootElementImpl {
layoutOptions?: ModelLayoutOptions;

constructor(index = new SGraphIndex()) {
Expand Down
4 changes: 2 additions & 2 deletions packages/sprotty/src/lib/svg-views.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { VNode } from "snabbdom";
import { Point } from 'sprotty-protocol/lib/utils/geometry';
import { IView, IViewArgs, RenderingContext } from "../base/views/view";
import { SNodeImpl, SPortImpl } from "../graph/sgraph";
import { ViewportRootElement } from "../features/viewport/viewport-root";
import { ViewportRootElementImpl } from "../features/viewport/viewport-root";
import { SShapeElementImpl } from '../features/bounds/model';
import { ShapeView } from '../features/bounds/views';
import { Hoverable } from '../features/hover/model';
Expand All @@ -32,7 +32,7 @@ import { injectable } from 'inversify';

@injectable()
export class SvgViewportView implements IView {
render(model: Readonly<ViewportRootElement>, context: RenderingContext, args?: IViewArgs): VNode {
render(model: Readonly<ViewportRootElementImpl>, context: RenderingContext, args?: IViewArgs): VNode {
const transform = `scale(${model.zoom}) translate(${-model.scroll.x},${-model.scroll.y})`;
return <svg>
<g transform={transform}>
Expand Down

0 comments on commit 36d742c

Please sign in to comment.