Skip to content

Commit

Permalink
#9 latest changes to metaNodeModel api
Browse files Browse the repository at this point in the history
  • Loading branch information
ddelpiano committed Oct 28, 2022
1 parent 0afe203 commit 618d7ac
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export enum CallbackTypes {
OPTIONS_UPDATED = 'nodeUpdated',
POSITION_CHANGED = 'positionChanged',
SELECTION_CHANGED = 'selectionChanged',
CHILD_POSITION_CHANGED = 'childPositionChanged'
}

export enum EventTypes {
Expand Down
6 changes: 3 additions & 3 deletions src/models/BoundingBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ export class BoundingBox {
return this._top - this._bottom
}

containsPoint(points?: Point, x?: number, y?: number): boolean {
if (points) {
if (points.x >= this._left && points.x <= this._right && points.y >= this._top && points.x <= this._bottom) {
containsPoint(x: Point | number, y?: number): boolean {
if (x instanceof Point) {
if (x.x >= this._left && x.x <= this._right && x.y >= this._top && x.x <= this._bottom) {
return true;
}
} else if (x && y) {
Expand Down
20 changes: 14 additions & 6 deletions src/react-diagrams/MetaNodeModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { MetaPort } from '../models/MetaPort';
import { PortTypes, ReactDiagramMetaTypes, CallbackTypes } from '../constants';
import { DefaultPortModel, NodeModel } from '@projectstorm/react-diagrams';
import { BoundingBox } from "../models/BoundingBox";
import { Point } from "@projectstorm/geometry";

export class MetaNodeModel extends NodeModel {
private boundingBox: BoundingBox;
Expand All @@ -11,13 +12,10 @@ export class MetaNodeModel extends NodeModel {
...options,
type: ReactDiagramMetaTypes.META_NODE,
});

// @ts-ignore
if (options.width && options.height) {
// @ts-ignore
this.width = options.width;
// @ts-ignore
this.height = options.height;
this.updateDimensions({width: options.width, height: options.height});
}

this.boundingBox = new BoundingBox(
Expand Down Expand Up @@ -68,8 +66,8 @@ export class MetaNodeModel extends NodeModel {
return this.getOptions()[label]
}

flagUpdate(updateType: CallbackTypes) {
this.fireEvent({node: this, function: updateType}, updateType);
flagUpdate(updateType: CallbackTypes, extraCondition?: CallbackTypes) {
this.fireEvent({node: this, function: updateType, extraCondition: extraCondition}, updateType);
}

getId(): string[]{
Expand Down Expand Up @@ -116,4 +114,14 @@ export class MetaNodeModel extends NodeModel {
getNodeBoundingBox(): BoundingBox {
return this.boundingBox;
}

setChildPosition(x: number | Point, y?: number): void {
if (x instanceof Point) {
this.position = x;
} else {
// @ts-ignore
this.position = new Point(x, y);
}
this.flagUpdate(CallbackTypes.POSITION_CHANGED, CallbackTypes.CHILD_POSITION_CHANGED)
}
}

0 comments on commit 618d7ac

Please sign in to comment.