conversions to typescript and type fixes

development
mcyph 2021-06-27 17:23:33 +10:00
parent ff309ee781
commit 288ba10cf0
9 changed files with 135 additions and 112 deletions

View File

@ -19,7 +19,7 @@ import {
TOOLTIP_VERTICAL_OFFSET, TOOLTIP_VERTICAL_OFFSET,
VALID_COLOR, VALID_COLOR,
} from '../../util/Constants'; } from '../../util/Constants';
import utils from '../../util/Utils'; import utils, { convertPoint, getOffset, getRotatedPoint, getValue, toRadians } from '../../util/Utils';
import InternalMouseEvent from '../event/InternalMouseEvent'; import InternalMouseEvent from '../event/InternalMouseEvent';
import ImageShape from '../geometry/shape/node/ImageShape'; import ImageShape from '../geometry/shape/node/ImageShape';
import CellMarker from '../cell/CellMarker'; import CellMarker from '../cell/CellMarker';
@ -39,6 +39,8 @@ import graph from '../Graph';
import Image from '../image/Image'; import Image from '../image/Image';
import CellState from '../cell/datatypes/CellState'; import CellState from '../cell/datatypes/CellState';
import Graph from '../Graph'; import Graph from '../Graph';
import ConnectionConstraint from './ConnectionConstraint';
import Shape from '../geometry/shape/Shape';
type FactoryMethod = (source: Cell, target: Cell, style?: string) => Cell; type FactoryMethod = (source: Cell, target: Cell, style?: string) => Cell;
@ -199,7 +201,8 @@ type FactoryMethod = (source: Cell, target: Cell, style?: string) => Cell;
* the <mxCell> that represents the new edge. * the <mxCell> that represents the new edge.
*/ */
class ConnectionHandler extends EventSource { class ConnectionHandler extends EventSource {
constructor(graph: Graph, factoryMethod: FactoryMethod | null = null) { constructor(graph: Graph,
factoryMethod: FactoryMethod | null = null) {
super(); super();
this.graph = graph; this.graph = graph;
@ -214,6 +217,20 @@ class ConnectionHandler extends EventSource {
this.graph.addListener(InternalEvent.ESCAPE, this.escapeHandler); this.graph.addListener(InternalEvent.ESCAPE, this.escapeHandler);
} }
// TODO: Document me!
previous: CellState | null = null;
iconState: CellState | null = null;
icons: ImageShape[] | null = null;
cell: Cell | null = null;
currentPoint: Point | null = null;
sourceConstraint: ConnectionConstraint | null = null;
shape: Shape | null = null;
icon: ImageShape | null = null;
originalPoint: Point | null = null;
currentState: CellState | null = null;
selectedIcon: ImageShape | null = null;
waypoints: Point[] | null = null;
/** /**
* Variable: graph * Variable: graph
* *
@ -297,7 +314,8 @@ class ConnectionHandler extends EventSource {
* *
* Holds the <mxTerminalMarker> used for finding source and target cells. * Holds the <mxTerminalMarker> used for finding source and target cells.
*/ */
marker?: CellMarker; // @ts-ignore
marker: CellMarker;
/** /**
* Variable: constraintHandler * Variable: constraintHandler
@ -410,7 +428,7 @@ class ConnectionHandler extends EventSource {
* *
* Specifies the cursor to be used while the handler is active. Default is null. * Specifies the cursor to be used while the handler is active. Default is null.
*/ */
cursor: string = null; cursor: string | null = null;
/** /**
* Variable: insertBeforeSource * Variable: insertBeforeSource
@ -585,7 +603,7 @@ class ConnectionHandler extends EventSource {
// Overrides to return cell at location only if valid (so that // Overrides to return cell at location only if valid (so that
// there is no highlight for invalid cells) // there is no highlight for invalid cells)
getCell = (me) => { getCell(me: InternalMouseEvent) {
let cell = super.getCell(me); let cell = super.getCell(me);
self.error = null; self.error = null;
@ -604,9 +622,9 @@ class ConnectionHandler extends EventSource {
} }
if ( if (
(self.graph.isSwimlane(cell) && (self.graph.swimlane.isSwimlane(cell) &&
self.currentPoint != null && self.currentPoint != null &&
self.graph.hitsSwimlaneContent( self.graph.swimlane.hitsSwimlaneContent(
cell, cell,
self.currentPoint.x, self.currentPoint.x,
self.currentPoint.y self.currentPoint.y
@ -645,29 +663,29 @@ class ConnectionHandler extends EventSource {
}; };
// Sets the highlight color according to validateConnection // Sets the highlight color according to validateConnection
isValidState = (state) => { isValidState(state: CellState) {
if (self.isConnecting()) { if (self.isConnecting()) {
return self.error == null; return self.error == null;
} }
return super.isValidState(state); return super.isValidState(state);
}; }
// Overrides to use marker color only in highlight mode or for // Overrides to use marker color only in highlight mode or for
// target selection // target selection
getMarkerColor = (evt, state, isValid) => { getMarkerColor(evt: Event, state: CellState, isValid: boolean): string | null {
return self.connectImage == null || self.isConnecting() return self.connectImage == null || self.isConnecting()
? super.getMarkerColor(evt, state, isValid) ? super.getMarkerColor(evt, state, isValid)
: null; : null;
}; }
// Overrides to use hotspot only for source selection otherwise // Overrides to use hotspot only for source selection otherwise
// intersects always returns true when over a cell // intersects always returns true when over a cell
intersects = (state, evt) => { intersects(state: CellState, evt: InternalMouseEvent) {
if (self.connectImage != null || self.isConnecting()) { if (self.connectImage != null || self.isConnecting()) {
return true; return true;
} }
return super.intersects(state, evt); return super.intersects(state, evt);
}; }
} }
return <CellMarker>new MyCellMarker(this.graph); return <CellMarker>new MyCellMarker(this.graph);
@ -747,7 +765,8 @@ class ConnectionHandler extends EventSource {
* source - <mxCell> that represents the source terminal. * source - <mxCell> that represents the source terminal.
* target - <mxCell> that represents the target terminal. * target - <mxCell> that represents the target terminal.
*/ */
validateConnection(source: Cell, target: Cell): string { validateConnection(source: Cell,
target: Cell): string {
if (!this.isValidTarget(target)) { if (!this.isValidTarget(target)) {
return ''; return '';
} }
@ -764,7 +783,7 @@ class ConnectionHandler extends EventSource {
* *
* state - <mxCellState> whose connect image should be returned. * state - <mxCellState> whose connect image should be returned.
*/ */
getConnectImage(state: CellState): Image { getConnectImage(state: CellState): Image | null {
return this.connectImage; return this.connectImage;
} }
@ -798,8 +817,7 @@ class ConnectionHandler extends EventSource {
* *
* state - <mxCellState> whose connect icons should be returned. * state - <mxCellState> whose connect icons should be returned.
*/ */
// createIcons(state: mxCellState): mxImageShape[]; createIcons(state: CellState): ImageShape[] | null {
createIcons(state) {
const image = this.getConnectImage(state); const image = this.getConnectImage(state);
if (image != null && state != null) { if (image != null && state != null) {
@ -868,7 +886,8 @@ class ConnectionHandler extends EventSource {
* *
* icons - Optional array of <mxImageShapes> to be redrawn. * icons - Optional array of <mxImageShapes> to be redrawn.
*/ */
redrawIcons(icons?: ImageShape[], state?: CellState): void { redrawIcons(icons?: ImageShape[] | null,
state?: CellState): void {
if (icons != null && icons[0] != null && state != null) { if (icons != null && icons[0] != null && state != null) {
const pos = this.getIconPosition(icons[0], state); const pos = this.getIconPosition(icons[0], state);
icons[0].bounds.x = pos.x; icons[0].bounds.x = pos.x;
@ -877,16 +896,9 @@ class ConnectionHandler extends EventSource {
} }
} }
/** // TODO: Document me! ===========================================================================================================
* Function: redrawIcons getIconPosition(icon: ImageShape,
* state: CellState): Point {
* Redraws the given array of <mxImageShapes>.
*
* Parameters:
*
* icons - Optional array of <mxImageShapes> to be redrawn.
*/
getIconPosition(icon?: ImageShape[], state?: CellState): Point {
const { scale } = this.graph.getView(); const { scale } = this.graph.getView();
let cx = state.getCenterX(); let cx = state.getCenterX();
let cy = state.getCenterY(); let cy = state.getCenterY();
@ -897,15 +909,15 @@ class ConnectionHandler extends EventSource {
cx = size.width !== 0 ? state.x + (size.width * scale) / 2 : cx; cx = size.width !== 0 ? state.x + (size.width * scale) / 2 : cx;
cy = size.height !== 0 ? state.y + (size.height * scale) / 2 : cy; cy = size.height !== 0 ? state.y + (size.height * scale) / 2 : cy;
const alpha = utils.toRadians( const alpha = toRadians(
utils.getValue(state.style, 'rotation') || 0 getValue(state.style, 'rotation') || 0
); );
if (alpha !== 0) { if (alpha !== 0) {
const cos = Math.cos(alpha); const cos = Math.cos(alpha);
const sin = Math.sin(alpha); const sin = Math.sin(alpha);
const ct = new Point(state.getCenterX(), state.getCenterY()); const ct = new Point(state.getCenterX(), state.getCenterY());
const pt = utils.getRotatedPoint(new Point(cx, cy), cos, sin, ct); const pt = getRotatedPoint(new Point(cx, cy), cos, sin, ct);
cx = pt.x; cx = pt.x;
cy = pt.y; cy = pt.y;
} }
@ -1012,8 +1024,7 @@ class ConnectionHandler extends EventSource {
* connecting. This implementation returns true if the state is not movable * connecting. This implementation returns true if the state is not movable
* in the graph. * in the graph.
*/ */
// isImmediateConnectSource(state: mxCellState): boolean; isImmediateConnectSource(state: CellState): boolean {
isImmediateConnectSource(state) {
return !this.graph.isCellMovable(state.cell); return !this.graph.isCellMovable(state.cell);
} }
@ -1034,8 +1045,7 @@ class ConnectionHandler extends EventSource {
* }; * };
* (end) * (end)
*/ */
// createEdgeState(me: mxMouseEvent): mxCellState; createEdgeState(me: InternalMouseEvent): CellState | null {
createEdgeState(me) {
return null; return null;
} }
@ -1045,9 +1055,8 @@ class ConnectionHandler extends EventSource {
* Returns true if <outlineConnect> is true and the source of the event is the outline shape * Returns true if <outlineConnect> is true and the source of the event is the outline shape
* or shift is pressed. * or shift is pressed.
*/ */
// isOutlineConnectEvent(me: mxMouseEvent): boolean; isOutlineConnectEvent(me: InternalMouseEvent): boolean {
isOutlineConnectEvent(me) { const offset = getOffset(this.graph.container);
const offset = utils.getOffset(this.graph.container);
const evt = me.getEvent(); const evt = me.getEvent();
const clientX = getClientX(evt); const clientX = getClientX(evt);
@ -1080,8 +1089,8 @@ class ConnectionHandler extends EventSource {
* Updates the current state for a given mouse move event by using * Updates the current state for a given mouse move event by using
* the <marker>. * the <marker>.
*/ */
// updateCurrentState(me: mxMouseEvent, point: mxPoint): void; updateCurrentState(me: InternalMouseEvent,
updateCurrentState(me, point) { point: Point): void {
this.constraintHandler.update( this.constraintHandler.update(
me, me,
this.first == null, this.first == null,
@ -1214,8 +1223,7 @@ class ConnectionHandler extends EventSource {
* *
* Returns true if the given cell does not allow new connections to be created. * Returns true if the given cell does not allow new connections to be created.
*/ */
// isCellEnabled(cell: mxCell): boolean; isCellEnabled(cell: Cell): boolean {
isCellEnabled(cell) {
return true; return true;
} }
@ -1224,8 +1232,7 @@ class ConnectionHandler extends EventSource {
* *
* Converts the given point from screen coordinates to model coordinates. * Converts the given point from screen coordinates to model coordinates.
*/ */
// convertWaypoint(point: mxPoint): void; convertWaypoint(point: Point): void {
convertWaypoint(point) {
const scale = this.graph.getView().getScale(); const scale = this.graph.getView().getScale();
const tr = this.graph.getView().getTranslate(); const tr = this.graph.getView().getTranslate();
@ -1239,8 +1246,8 @@ class ConnectionHandler extends EventSource {
* Called to snap the given point to the current preview. This snaps to the * Called to snap the given point to the current preview. This snaps to the
* first point of the preview if alt is not pressed. * first point of the preview if alt is not pressed.
*/ */
// snapToPreview(me: mxMouseEvent, point: mxPoint): void; snapToPreview(me: MouseEvent,
snapToPreview(me, point) { point: Point): void {
if (!isAltDown(me.getEvent()) && this.previous != null) { if (!isAltDown(me.getEvent()) && this.previous != null) {
const tol = (this.graph.gridSize * this.graph.view.scale) / 2; const tol = (this.graph.gridSize * this.graph.view.scale) / 2;
const tmp = const tmp =
@ -1264,8 +1271,8 @@ class ConnectionHandler extends EventSource {
* Handles the event by updating the preview edge or by highlighting * Handles the event by updating the preview edge or by highlighting
* a possible source or target terminal. * a possible source or target terminal.
*/ */
// mouseMove(sender: mxMouseEvent, me: mxMouseEvent): void; mouseMove(sender: MouseEvent,
mouseMove(sender, me) { me: InternalMouseEvent): void {
if ( if (
!me.isConsumed() && !me.isConsumed() &&
(this.ignoreMouseDown || this.first != null || !this.graph.isMouseDown) (this.ignoreMouseDown || this.first != null || !this.graph.isMouseDown)
@ -1282,10 +1289,10 @@ class ConnectionHandler extends EventSource {
let point = new Point(me.getGraphX(), me.getGraphY()); let point = new Point(me.getGraphX(), me.getGraphY());
this.error = null; this.error = null;
if (this.graph.isGridEnabledEvent(me.getEvent())) { if (this.graph.grid.isGridEnabledEvent(me.getEvent())) {
point = new point( point = new point(
(this.graph.snap(point.x / scale - tr.x) + tr.x) * scale, (this.graph.grid.snap(point.x / scale - tr.x) + tr.x) * scale,
(this.graph.snap(point.y / scale - tr.y) + tr.y) * scale (this.graph.grid.snap(point.y / scale - tr.y) + tr.y) * scale
); );
} }
@ -1528,8 +1535,8 @@ class ConnectionHandler extends EventSource {
* *
* Updates <edgeState>. * Updates <edgeState>.
*/ */
// updateEdgeState(current: mxCellState, constraint: mxCellState): void; updateEdgeState(current: CellState,
updateEdgeState(current, constraint) { constraint: CellState): void {
// TODO: Use generic method for writing constraint to style // TODO: Use generic method for writing constraint to style
if (this.sourceConstraint != null && this.sourceConstraint.point != null) { if (this.sourceConstraint != null && this.sourceConstraint.point != null) {
this.edgeState.style.exitX = this.sourceConstraint.point.x; this.edgeState.style.exitX = this.sourceConstraint.point.x;
@ -1609,8 +1616,8 @@ class ConnectionHandler extends EventSource {
* state - <mxCellState> that represents the target cell state. * state - <mxCellState> that represents the target cell state.
* me - <mxMouseEvent> that represents the mouse move. * me - <mxMouseEvent> that represents the mouse move.
*/ */
// getTargetPerimeterPoint(state: mxCellState, me: mxMouseEvent): mxPoint; getTargetPerimeterPoint(state: CellState,
getTargetPerimeterPoint(state, me) { me: MouseEvent): Point {
let result = null; let result = null;
const { view } = state; const { view } = state;
const targetPerimeter = view.getPerimeterFunction(state); const targetPerimeter = view.getPerimeterFunction(state);
@ -1649,19 +1656,20 @@ class ConnectionHandler extends EventSource {
* next - <mxPoint> that represents the next point along the previewed edge. * next - <mxPoint> that represents the next point along the previewed edge.
* me - <mxMouseEvent> that represents the mouse move. * me - <mxMouseEvent> that represents the mouse move.
*/ */
// getSourcePerimeterPoint(state: mxCellState, next: mxPoint, me: mxMouseEvent): mxPoint; getSourcePerimeterPoint(state: CellState,
getSourcePerimeterPoint(state, next, me) { next: Point,
me: MouseEvent): Point {
let result = null; let result = null;
const { view } = state; const { view } = state;
const sourcePerimeter = view.getPerimeterFunction(state); const sourcePerimeter = view.getPerimeterFunction(state);
const c = new Point(state.getCenterX(), state.getCenterY()); const c = new Point(state.getCenterX(), state.getCenterY());
if (sourcePerimeter != null) { if (sourcePerimeter != null) {
const theta = utils.getValue(state.style, 'rotation', 0); const theta = getValue(state.style, 'rotation', 0);
const rad = -theta * (Math.PI / 180); const rad = -theta * (Math.PI / 180);
if (theta !== 0) { if (theta !== 0) {
next = utils.getRotatedPoint( next = getRotatedPoint(
new Point(next.x, next.y), new Point(next.x, next.y),
Math.cos(rad), Math.cos(rad),
Math.sin(rad), Math.sin(rad),
@ -1678,7 +1686,7 @@ class ConnectionHandler extends EventSource {
if (tmp != null) { if (tmp != null) {
if (theta !== 0) { if (theta !== 0) {
tmp = utils.getRotatedPoint( tmp = getRotatedPoint(
new Point(tmp.x, tmp.y), new Point(tmp.x, tmp.y),
Math.cos(-rad), Math.cos(-rad),
Math.sin(-rad), Math.sin(-rad),
@ -1707,8 +1715,9 @@ class ConnectionHandler extends EventSource {
* icons - Array of currently displayed icons. * icons - Array of currently displayed icons.
* me - <mxMouseEvent> that contains the mouse event. * me - <mxMouseEvent> that contains the mouse event.
*/ */
// updateIcons(state: mxCellState, icons: string[], me: mxMouseEvent): void; updateIcons(state: CellState,
updateIcons(state, icons, me) { icons: string[],
me: InternalMouseEvent): void {
// empty // empty
} }
@ -1720,8 +1729,7 @@ class ConnectionHandler extends EventSource {
* called if <waypointsEnabled> is true. This implemtation returns true * called if <waypointsEnabled> is true. This implemtation returns true
* if there is a cell state in the given event. * if there is a cell state in the given event.
*/ */
// isStopEvent(me: mxMouseEvent): void; isStopEvent(me: InternalMouseEvent): boolean {
isStopEvent(me) {
return me.getState() != null; return me.getState() != null;
} }
@ -1730,9 +1738,8 @@ class ConnectionHandler extends EventSource {
* *
* Adds the waypoint for the given event to <waypoints>. * Adds the waypoint for the given event to <waypoints>.
*/ */
// addWaypointForEvent(me: mxMouseEvent): void; addWaypointForEvent(me: InternalMouseEvent): void {
addWaypointForEvent(me) { let point = convertPoint(
let point = utils.convertPoint(
this.graph.container, this.graph.container,
me.getX(), me.getX(),
me.getY() me.getY()
@ -1783,8 +1790,8 @@ class ConnectionHandler extends EventSource {
* *
* Handles the event by inserting the new connection. * Handles the event by inserting the new connection.
*/ */
// mouseUp(sender: mxMouseEvent, me: mxMouseEvent): void; mouseUp(sender: InternalMouseEvent,
mouseUp(sender, me) { me: InternalMouseEvent): void {
if (!me.isConsumed() && this.isConnecting()) { if (!me.isConsumed() && this.isConnecting()) {
if (this.waypointsEnabled && !this.isStopEvent(me)) { if (this.waypointsEnabled && !this.isStopEvent(me)) {
this.addWaypointForEvent(me); this.addWaypointForEvent(me);
@ -1851,8 +1858,7 @@ class ConnectionHandler extends EventSource {
* *
* Resets the state of this handler. * Resets the state of this handler.
*/ */
// reset(): void; reset(): void {
reset() {
if (this.shape != null) { if (this.shape != null) {
this.shape.destroy(); this.shape.destroy();
this.shape = null; this.shape = null;
@ -1884,8 +1890,7 @@ class ConnectionHandler extends EventSource {
* Redraws the preview edge using the color and width returned by * Redraws the preview edge using the color and width returned by
* <getEdgeColor> and <getEdgeWidth>. * <getEdgeColor> and <getEdgeWidth>.
*/ */
// drawPreview(): void; drawPreview(): void {
drawPreview() {
this.updatePreview(this.error == null); this.updatePreview(this.error == null);
this.shape.redraw(); this.shape.redraw();
} }
@ -1901,8 +1906,7 @@ class ConnectionHandler extends EventSource {
* valid - Boolean indicating if the color for a valid edge should be * valid - Boolean indicating if the color for a valid edge should be
* returned. * returned.
*/ */
// updatePreview(valid: boolean): void; updatePreview(valid: boolean): void {
updatePreview(valid) {
this.shape.strokewidth = this.getEdgeWidth(valid); this.shape.strokewidth = this.getEdgeWidth(valid);
this.shape.stroke = this.getEdgeColor(valid); this.shape.stroke = this.getEdgeColor(valid);
} }
@ -1918,8 +1922,7 @@ class ConnectionHandler extends EventSource {
* valid - Boolean indicating if the color for a valid edge should be * valid - Boolean indicating if the color for a valid edge should be
* returned. * returned.
*/ */
// getEdgeColor(valid: boolean): string; getEdgeColor(valid: boolean): string {
getEdgeColor(valid) {
return valid ? VALID_COLOR : INVALID_COLOR; return valid ? VALID_COLOR : INVALID_COLOR;
} }
@ -1934,8 +1937,7 @@ class ConnectionHandler extends EventSource {
* valid - Boolean indicating if the width for a valid edge should be * valid - Boolean indicating if the width for a valid edge should be
* returned. * returned.
*/ */
// getEdgeWidth(valid: boolean): number; getEdgeWidth(valid: boolean): number {
getEdgeWidth(valid) {
return valid ? 3 : 1; return valid ? 3 : 1;
} }
@ -1953,8 +1955,10 @@ class ConnectionHandler extends EventSource {
* dropTarget - <mxCell> that represents the cell under the mouse when it was * dropTarget - <mxCell> that represents the cell under the mouse when it was
* released. * released.
*/ */
// connect(source: mxCell, target: mxCell, evt: MouseEvent, dropTarget: mxCell): void; connect(source: Cell,
connect(source, target, evt, dropTarget) { target: Cell,
evt: MouseEvent,
dropTarget: Cell): void {
if ( if (
target != null || target != null ||
this.isCreateTarget(evt) || this.isCreateTarget(evt) ||
@ -2150,8 +2154,8 @@ class ConnectionHandler extends EventSource {
* Selects the given edge after adding a new connection. The target argument * Selects the given edge after adding a new connection. The target argument
* contains the target vertex if one has been inserted. * contains the target vertex if one has been inserted.
*/ */
// selectCells(edge: mxCell, target: mxCell): void; selectCells(edge: Cell,
selectCells(edge, target) { target: Cell): void {
this.graph.setSelectionCell(edge); this.graph.setSelectionCell(edge);
} }
@ -2162,8 +2166,13 @@ class ConnectionHandler extends EventSource {
* implementation does only use <createEdge> if <factoryMethod> is defined, * implementation does only use <createEdge> if <factoryMethod> is defined,
* otherwise <mxGraph.insertEdge> will be used. * otherwise <mxGraph.insertEdge> will be used.
*/ */
// insertEdge(parent: mxCell, id: string, value: any, source: mxCell, target: mxCell, style: string): mxCell; insertEdge(parent: Cell,
insertEdge(parent, id, value, source, target, style) { id: string,
value: any,
source: Cell,
target: Cell,
style: string): Cell {
if (this.factoryMethod == null) { if (this.factoryMethod == null) {
return this.graph.insertEdge(parent, id, value, source, target, style); return this.graph.insertEdge(parent, id, value, source, target, style);
} }
@ -2185,8 +2194,8 @@ class ConnectionHandler extends EventSource {
* evt - Mousedown event of the connect gesture. * evt - Mousedown event of the connect gesture.
* source - <mxCell> that represents the source terminal. * source - <mxCell> that represents the source terminal.
*/ */
// createTargetVertex(evt: MouseEvent, source: mxCell): mxCell; createTargetVertex(evt: MouseEvent,
createTargetVertex(evt, source) { source: Cell): Cell {
// Uses the first non-relative source // Uses the first non-relative source
let geo = source.getGeometry(); let geo = source.getGeometry();
@ -2237,11 +2246,10 @@ class ConnectionHandler extends EventSource {
* *
* Returns the tolerance for aligning new targets to sources. This returns the grid size / 2. * Returns the tolerance for aligning new targets to sources. This returns the grid size / 2.
*/ */
// getAlignmentTolerance(evt: MouseEvent): number; getAlignmentTolerance(evt: MouseEvent): number {
getAlignmentTolerance(evt) { return this.graph.grid.isGridEnabled()
return this.graph.isGridEnabled() ? this.graph.grid.gridSize / 2
? this.graph.gridSize / 2 : this.graph.grid.tolerance;
: this.graph.tolerance;
} }
/** /**
@ -2259,8 +2267,10 @@ class ConnectionHandler extends EventSource {
* target - <mxCell> that represents the target terminal. * target - <mxCell> that represents the target terminal.
* style - Optional style from the preview edge. * style - Optional style from the preview edge.
*/ */
// createEdge(value?: any, source?: mxCell, target?: mxCell, style?: string): mxCell; createEdge(value?: any,
createEdge(value, source, target, style) { source?: Cell,
target?: Cell,
style?: string): Cell {
let edge = null; let edge = null;
// Creates a new edge using the factoryMethod // Creates a new edge using the factoryMethod
@ -2288,8 +2298,7 @@ class ConnectionHandler extends EventSource {
* called on all instances. It is called automatically for the built-in * called on all instances. It is called automatically for the built-in
* instance created for each <mxGraph>. * instance created for each <mxGraph>.
*/ */
// destroy(): void; destroy(): void {
destroy() {
this.graph.removeMouseListener(this); this.graph.removeMouseListener(this);
if (this.shape != null) { if (this.shape != null) {

View File

@ -151,7 +151,7 @@ class EventSource {
fireEvent(evt: EventObject, sender: any = null): void { fireEvent(evt: EventObject, sender: any = null): void {
if (this.eventListeners != null && this.isEventsEnabled()) { if (this.eventListeners != null && this.isEventsEnabled()) {
if (evt == null) { if (evt == null) {
evt = new EventObject(); evt = new EventObject('');
} }
if (sender == null) { if (sender == null) {

View File

@ -887,7 +887,7 @@ class Model extends EventSource {
* the new cell style. * the new cell style.
*/ */
styleForCellChanged(cell: Cell, styleForCellChanged(cell: Cell,
style: string): string | null { style: string | null): string | null {
const previous = cell.getStyle(); const previous = cell.getStyle();
cell.setStyle(style); cell.setStyle(style);

View File

@ -1,7 +1,16 @@
import Point from "../geometry/Point"; import Point from "../geometry/Point";
import Rectangle from "../geometry/Rectangle"; import Rectangle from "../geometry/Rectangle";
import Graph from '../Graph';
class GraphSnap { class GraphSnap {
constructor(graph: Graph) {
this.graph = graph;
}
// TODO: Document me!
tolerance: number | null = null;
graph: Graph;
/** /**
* Specifies the grid size. * Specifies the grid size.
* @default 10 * @default 10
@ -42,8 +51,8 @@ class GraphSnap {
ignoreHorizontal: boolean = false, ignoreHorizontal: boolean = false,
ignoreVertical: boolean = false ignoreVertical: boolean = false
): Point { ): Point {
const t = this.view.translate; const t = this.graph.view.translate;
const s = this.view.scale; const s = this.graph.view.scale;
if (!ignoreGrid && this.gridEnabled) { if (!ignoreGrid && this.gridEnabled) {
const tol = this.gridSize * s * 0.5; const tol = this.gridSize * s * 0.5;
@ -131,7 +140,7 @@ class GraphSnap {
/** /**
* Returns {@link tolerance}. * Returns {@link tolerance}.
*/ */
getTolerance(): number { getTolerance(): number | null {
return this.tolerance; return this.tolerance;
} }

View File

@ -5,7 +5,7 @@
* Type definitions from the typed-mxgraph project * Type definitions from the typed-mxgraph project
*/ */
import utils from '../../util/Utils'; import utils, { intersection } from '../../util/Utils';
import Point from '../geometry/Point'; import Point from '../geometry/Point';
import { import {
DIRECTION_EAST, DIRECTION_EAST,
@ -15,6 +15,7 @@ import {
} from '../../util/Constants'; } from '../../util/Constants';
import Rectangle from '../geometry/Rectangle'; import Rectangle from '../geometry/Rectangle';
import CellState from '../cell/datatypes/CellState'; import CellState from '../cell/datatypes/CellState';
import { CellStateStyles } from '../../types';
/** /**
* @class Perimeter * @class Perimeter
@ -292,14 +293,14 @@ class Perimeter {
// set the slope and offset of the border line accordingly // set the slope and offset of the border line accordingly
if (px < cx) { if (px < cx) {
if (py < cy) { if (py < cy) {
return utils.intersection(px, py, tx, ty, cx, y, x, cy); return intersection(px, py, tx, ty, cx, y, x, cy);
} }
return utils.intersection(px, py, tx, ty, cx, y + h, x, cy); return intersection(px, py, tx, ty, cx, y + h, x, cy);
} }
if (py < cy) { if (py < cy) {
return utils.intersection(px, py, tx, ty, cx, y, x + w, cy); return intersection(px, py, tx, ty, cx, y, x + w, cy);
} }
return utils.intersection(px, py, tx, ty, cx, y + h, x + w, cy); return intersection(px, py, tx, ty, cx, y + h, x + w, cy);
} }
/** /**
@ -402,7 +403,7 @@ class Perimeter {
(vertical && next.x <= x + w / 2) || (vertical && next.x <= x + w / 2) ||
(!vertical && next.y <= y + h / 2) (!vertical && next.y <= y + h / 2)
) { ) {
result = utils.intersection( result = intersection(
next.x, next.x,
next.y, next.y,
cx, cx,
@ -413,7 +414,7 @@ class Perimeter {
corner.y corner.y
); );
} else { } else {
result = utils.intersection( result = intersection(
next.x, next.x,
next.y, next.y,
cx, cx,
@ -462,7 +463,7 @@ class Perimeter {
const direction = const direction =
vertex != null vertex != null
? utils.getValue(vertex.style, 'direction', DIRECTION_EAST) ? Perimeter.getValue(vertex.style, 'direction', DIRECTION_EAST)
: DIRECTION_EAST; : DIRECTION_EAST;
const vertical = const vertical =
direction === DIRECTION_NORTH || direction === DIRECTION_SOUTH; direction === DIRECTION_NORTH || direction === DIRECTION_SOUTH;
@ -639,7 +640,7 @@ class Perimeter {
} }
} }
result = utils.intersection(tx, ty, next.x, next.y, a.x, a.y, b.x, b.y); result = intersection(tx, ty, next.x, next.y, a.x, a.y, b.x, b.y);
} else { } else {
if (vertical) { if (vertical) {
const beta = Math.atan2(h / 4, w / 2); const beta = Math.atan2(h / 4, w / 2);
@ -730,7 +731,7 @@ class Perimeter {
} }
} }
result = utils.intersection(cx, cy, next.x, next.y, a.x, a.y, b.x, b.y); result = intersection(cx, cy, next.x, next.y, a.x, a.y, b.x, b.y);
} }
if (result == null) { if (result == null) {
@ -738,6 +739,10 @@ class Perimeter {
} }
return result; return result;
} }
private static getValue(style: CellStateStyles, direction: string, DIRECTION_EAST: string) {
return '';
}
} }
export default Perimeter; export default Perimeter;

View File

@ -29,7 +29,7 @@ import Perimeter from './Perimeter';
* in a style. This is currently only used to perimeters and edge styles. * in a style. This is currently only used to perimeters and edge styles.
*/ */
class StyleRegistry { class StyleRegistry {
/* /**
* Variable: values * Variable: values
* *
* Maps from strings to objects. * Maps from strings to objects.