import { Subject } from 'rxjs'; import { DiagramContextMenu } from '../diagram/canvas/diagram-context-menu'; import { DiagramUserHighlight } from '../diagram/canvas/diagram-user-highlight'; import { DiagramUserSelection } from '../diagram/canvas/diagram-user-selection'; import { CollabEngine } from '../diagram/collab/collab-engine'; import { BackgroundConfig, GridConfig } from '../diagram/config/diagram-canvas-config'; import { UserActionConfig } from '../diagram/config/diagram-config'; import { ActionStack, DiagramAction, DiagramActionMethod, DiagramActions } from '../diagram/diagram-action'; import { DiagramEvent } from '../diagram/diagram-event'; import { DiagramConnectionType } from '../diagram/model/diagram-connection'; import { DiagramModel } from '../diagram/model/diagram-model'; import { DiagramNode } from '../diagram/model/diagram-node'; import { DiagramValidator } from '../errors/diagram-validator'; import { Point } from '../util/canvas-util'; import { DiagramEditor } from './diagram-editor'; /** * Represents a specific replica or view of the model. * Provides the functionality for the visual representation of the elements of a model. * @public */ export interface Canvas { /** * Parent component of the diagram. * @private */ readonly parentComponent: DiagramEditor; /** * Object that contains the data of the elements of the diagram. * @public */ readonly model: DiagramModel; /** * Object that contains the functionality related to the user selection. * @public */ readonly userSelection: DiagramUserSelection; /** * Object that contains the functionality related to the user highlight. * @public */ readonly userHighlight: DiagramUserHighlight; /** * Object that contains the functionality related to the context menu. * @public */ readonly contextMenu: DiagramContextMenu; /** * The stack of actions performed by the user used to keep track of what actions can be undone or redone. * @private */ readonly actionStack: ActionStack; /** * Engine that implements collaborative actions. * @private */ readonly collabEngine: CollabEngine; /** * Background config of the diagram. * @public */ backgroundConfig: BackgroundConfig; /** * Grid config of the diagram. * @public */ gridConfig: GridConfig; /** * The factor by which the zoom level increases or decreases when the user users buttons or keys to zoom in or out. Should be above 1. * @public */ zoomFactor: number; /** * The rate by which the view of the canvas moves when the user users buttons or keys to pan at a default zoom level in diagram units. Should be above 1. * @public */ panRate: number; /** * If true, new connections should have the type that makes most sense even if it's not the currently chosen type. * @public */ inferConnectionType: boolean; /** * When a new connection is made, it should have this type. * @public */ connectionType?: DiagramConnectionType; /** * Whether the start and end ports should automatically change to try to minimize the distance between them. * @public */ autoTightenConnections: boolean; /** * Whether a connection can be tightened to use ports of a different type. * @public */ tightenConnectionsAcrossPortTypes: boolean; /** * Whether a connection can use the same port as start and end. * @public */ allowConnectionLoops: boolean; /** * Whether the same port can be used by two different connections. * @public */ allowSharingPorts: boolean; /** * Whether two connections can use the same ports. * @public */ allowSharingBothPorts: boolean; /** * Within what radius the closest port may be highlighted when drawing a new connection as a guide to the user. * @public */ portHighlightRadius: number; /** * If true, the next drag action will create a multiple selection rectangle. */ multipleSelectionOn: boolean; /** * Identifier of the current layout format used by the diagram. * @public */ layoutFormat?: string; /** * The list of validators used to check for errors in this canvas. * @private */ validators: DiagramValidator[]; /** * Mapping of what actions the user is allowed to perform. Absent values are assumed to be allowed. * @public */ userActions: UserActionConfig; /** * Subject for tracking when validators are added to or removed from the canvas. * @public */ readonly validatorChange$: Subject; /** * Subject for tracking changes in the diagram which affect the diagram's model. * Used to detect if there have been changes over a period of time. * Values are sent when the user performs changes on the diagram, but not when the changes are performed programmatically. * @public */ readonly diagramChange$: Subject<{ action: DiagramAction; method: DiagramActionMethod; }>; /** * Subject for tracking user events in the diagram which do not affect the diagram's model. * @public */ readonly diagramEvent$: Subject; /** * Subject for tracking changes in the property editor. * @public */ readonly propertyEditorChanges$: Subject; /** * Initializes the view of the diagram. * @private */ initView(appendTo: HTMLElement): void; /** * Gets the current zoom level. * @public */ getZoomLevel(): number; /** * Increases the zoom level by the given factor. * @public * @param factor A factor of zoom. */ zoomBy(factor: number): void; /** * Changes the zoom level to a given level. * @public * @param level A level of zoom. */ zoomTo(level: number): void; /** * Gets the current coordinates of the center of view. * Ensures that calling `translateTo()` with the result causes no changes. * @public */ getViewCoordinates(): Point; /** * Translates the view by the given amount. * @public * @param x A distance along the x axis. * @param y A distance along the y axis. */ translateBy(x: number, y: number): void; /** * Translates the center of the view to the given point. * @public * @param x A coordinate along the x axis. * @param y A coordinate along the y axis. */ translateTo(x: number, y: number): void; /** * Translates the center of the view to the given point and the given zoom level over the given duration of time. * The duration may be set to `0` or `undefined` to make the move instant without animation. * @public * @param x A coordinate along the x axis. * @param y A coordinate along the y axis. * @param z A level of zoom. * @param duration A duration for the animation in milliseconds. May be set to `0` or `undefined` to make it instant without animation. */ zoomAndPanTo(x: number, y: number, z: number, duration?: number): void; /** * Centers by zooming and translating the view such that every element fits in the view. * @public * @param nodeIds A list of node ids to center the view on. If `undefined`, it encompasses all nodes. * @param maxZoomLevel The maximum zoom level that can be used when zooming into the elements. Can be used to prevent zooming in past a given level. `1` by default. * @param duration A duration for the animation in milliseconds. May be set to `0` or `undefined` to make it instant without animation. */ center(nodeIds?: string[], maxZoomLevel?: number, duration?: number): void; /** * Get the closest grid point to the given point. * @public * @param point A point. */ getClosestGridPoint(point: Point): Point; /** * Get the coordinates in the diagram of the points of the screen at the top left and the bottom right of the diagram view. * @public */ getCoordinatesOnScreen(): [Point, Point]; /** * Get the location of the pointer in the given event relative to the canvas. * @private * @param event A MouseEvent. */ getPointerLocationRelativeToCanvas(event: MouseEvent | d3.D3DragEvent): Point; /** * Get the location of the pointer in the given event relative to the svg element. * @private * @param event A MouseEvent. */ getPointerLocationRelativeToRoot(event: MouseEvent | d3.D3DragEvent): Point; /** * Get the location of the pointer in the given event relative to the body. * @private * @param event A MouseEvent. */ getPointerLocationRelativeToBody(event: MouseEvent | d3.D3DragEvent): Point; /** * Get the location of the pointer in the given event relative to the screen. * @private * @param event A MouseEvent. */ getPointerLocationRelativeToScreen(event: MouseEvent | d3.D3DragEvent): Point; /** * Adds a validator to the list of validators of the diagram. * @public */ addValidator(validator: DiagramValidator): void; /** * Removes a validator from the list of validators of the diagram. * @public */ removeValidator(validator: DiagramValidator): void; /** * Get the possible priority thresholds of the diagram. * @public */ getPriorityThresholdOptions(): number[] | undefined; /** * Get the current priority threshold of the diagram. * @public */ getPriorityThreshold(): number | undefined; /** * Changes the current priority threshold of the diagram. * @public * @param priority A priority threshold. */ setPriorityThreshold(priority: number): void; /** * Update the view of the canvas to show the current state of the model. * @public */ updateModelInView(): void; /** * Update the view of the canvas to show the current state of the nodes. * @public */ updateNodesInView(...ids: string[]): void; /** * Update the view of the canvas to show the current state of the sections. * @public */ updateSectionsInView(...ids: string[]): void; /** * Update the view of the canvas to show the current state of the ports. * @public */ updatePortsInView(...ids: string[]): void; /** * Update the view of the canvas to show the current state of the connections. * @public */ updateConnectionsInView(...ids: string[]): void; /** * Update the view of the canvas to show the current state of the fields. * @public */ updateFieldsInView(...ids: string[]): void; /** * Update the view of the canvas to show the current state of the objects. * @public */ updateObjectsInView(...ids: string[]): void; /** * Update the view of the canvas to show the current state of the decorators. * @public */ updateDecoratorsInView(...ids: string[]): void; /** * Update the z coordinate of a node to be higher than any node that overlaps with it. * @public */ bringToFront(node: DiagramNode): void; /** * Update the z coordinate of a node to be lower than any node that overlaps with it. * @public */ sendToBack(node: DiagramNode): void; /** * Checks whether the root of a diagram field encompasses the totality of the field. * @param id The id of a diagram field * @returns `true` if the root of a diagram field encompasses the totality of the field, `false` otherwise. */ fieldRootFitsInView(id: string): boolean; /** * Fit the root of a diagram field to encompass the totality of the field. * @param id The id of a diagram field * @param shrink Whether the root of the diagram field should shrink if there is excess space; `true` by default */ fitFieldRootInView(id: string, shrink?: boolean): void; /** * Fit a node to encompass the totality of its sections. * @param id The id of a node * @param shrink Whether the node should shrink if there is excess space; `true` by default */ fitNodeInView(id: string, shrink?: boolean): void; /** * Open a text input for a field. * @param id The id of a field. */ openTextInput(id: string): void; /** * Get the d3 Selection containing the root html div element of the canvas. * @private */ selectRoot(): d3.Selection; /** * Get the d3 Selection containing the svg element of the canvas. * @private */ selectSVGElement(): d3.Selection; /** * Get the d3 Selection containing the view of all the elements in the canvas. * @private */ selectCanvasView(): d3.Selection; /** * Stops all unfinished user actions to ensure there are no unfinished actions before performing a different action. * @public */ cancelAllUserActions(): void; /** * Checks whether the user can perform the given action. * @public */ canUserPerformAction(action: DiagramActions): boolean; }