|
@@ -3,15 +3,18 @@ import { GraphCanvasComponent } from './graphCanvas';
|
|
|
import { Nullable } from 'babylonjs/types';
|
|
|
import { Observer } from 'babylonjs/Misc/observable';
|
|
|
import { NodeLink } from './nodeLink';
|
|
|
+import { Color3 } from 'babylonjs';
|
|
|
+import { IFrameData } from '../nodeLocationInfo';
|
|
|
|
|
|
export class GraphFrame {
|
|
|
private _name: string;
|
|
|
+ private _color: Color3;
|
|
|
private _x = 0;
|
|
|
private _y = 0;
|
|
|
private _gridAlignedX = 0;
|
|
|
private _gridAlignedY = 0;
|
|
|
- public width: number;
|
|
|
- public height: number;
|
|
|
+ private _width: number;
|
|
|
+ private _height: number;
|
|
|
public element: HTMLDivElement;
|
|
|
private _headerElement: HTMLDivElement;
|
|
|
private _nodes: GraphNode[] = [];
|
|
@@ -24,14 +27,6 @@ export class GraphFrame {
|
|
|
return this._nodes;
|
|
|
}
|
|
|
|
|
|
- public get gridAlignedX() {
|
|
|
- return this._gridAlignedX;
|
|
|
- }
|
|
|
-
|
|
|
- public get gridAlignedY() {
|
|
|
- return this._gridAlignedY;
|
|
|
- }
|
|
|
-
|
|
|
public get name() {
|
|
|
return this._name;
|
|
|
}
|
|
@@ -41,6 +36,17 @@ export class GraphFrame {
|
|
|
this._headerElement.innerHTML = value;
|
|
|
}
|
|
|
|
|
|
+ public get color() {
|
|
|
+ return this._color;
|
|
|
+ }
|
|
|
+
|
|
|
+ public set color(value: Color3) {
|
|
|
+ this._color = value;
|
|
|
+ this._headerElement.style.background = `rgba(${value.r * 255}, ${value.g * 255}, ${value.b * 255}, 1)`;
|
|
|
+ this._headerElement.style.borderColor = `rgba(${value.r * 255}, ${value.g * 255}, ${value.b * 255}, 1)`;
|
|
|
+ this.element.style.background = `rgba(${value.r * 255}, ${value.g * 255}, ${value.b * 255}, 0.7)`;
|
|
|
+ }
|
|
|
+
|
|
|
public get x() {
|
|
|
return this._x;
|
|
|
}
|
|
@@ -68,9 +74,39 @@ export class GraphFrame {
|
|
|
|
|
|
this._gridAlignedY = this._ownerCanvas.getGridPosition(value);
|
|
|
this.element.style.top = `${this._gridAlignedY}px`;
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ public get width() {
|
|
|
+ return this._width;
|
|
|
+ }
|
|
|
+
|
|
|
+ public set width(value: number) {
|
|
|
+ if (this._width === value) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this._width = value;
|
|
|
+
|
|
|
+ var gridAlignedRight = this._ownerCanvas.getGridPositionCeil(value + this._gridAlignedX);
|
|
|
+
|
|
|
+ this.element.style.width = `${gridAlignedRight - this._gridAlignedX}px`;
|
|
|
+ }
|
|
|
+
|
|
|
+ public get height() {
|
|
|
+ return this._height;
|
|
|
+ }
|
|
|
+
|
|
|
+ public set height(value: number) {
|
|
|
+ if (this._height === value) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this._height = value;
|
|
|
+
|
|
|
+ var gridAlignedBottom = this._ownerCanvas.getGridPositionCeil(value + this._gridAlignedY);
|
|
|
|
|
|
- public constructor(candidate: HTMLDivElement, canvas: GraphCanvasComponent) {
|
|
|
+ this.element.style.height = `${gridAlignedBottom - this._gridAlignedY}px`;
|
|
|
+ }
|
|
|
+
|
|
|
+ public constructor(candidate: Nullable<HTMLDivElement>, canvas: GraphCanvasComponent) {
|
|
|
this._ownerCanvas = canvas;
|
|
|
const root = canvas.groupContainer;
|
|
|
this.element = root.ownerDocument!.createElement("div");
|
|
@@ -81,15 +117,17 @@ export class GraphFrame {
|
|
|
this._headerElement.classList.add("group-box-header");
|
|
|
this.element.appendChild(this._headerElement);
|
|
|
|
|
|
- this.x = parseFloat(candidate.style.left!.replace("px", ""));
|
|
|
- this.y = parseFloat(candidate.style.top!.replace("px", ""));
|
|
|
- this.width = parseFloat(candidate.style.width!.replace("px", ""));
|
|
|
- this.height = parseFloat(candidate.style.height!.replace("px", ""));
|
|
|
+ this.name = "Frame";
|
|
|
+ this.color = Color3.FromInts(72, 72, 72);
|
|
|
|
|
|
- this.cleanAccumulation();
|
|
|
+ if (candidate) {
|
|
|
+ this.x = parseFloat(candidate.style.left!.replace("px", ""));
|
|
|
+ this.y = parseFloat(candidate.style.top!.replace("px", ""));
|
|
|
+ this.width = parseFloat(candidate.style.width!.replace("px", ""));
|
|
|
+ this.height = parseFloat(candidate.style.height!.replace("px", ""));
|
|
|
|
|
|
- this.element.style.width = `${this.width}px`;
|
|
|
- this.element.style.height = `${this.height}px`;
|
|
|
+ this.cleanAccumulation();
|
|
|
+ }
|
|
|
|
|
|
this._headerElement.addEventListener("pointerdown", evt => this._onDown(evt));
|
|
|
this._headerElement.addEventListener("pointerup", evt => this._onUp(evt));
|
|
@@ -105,8 +143,8 @@ export class GraphFrame {
|
|
|
}
|
|
|
|
|
|
public cleanAccumulation() {
|
|
|
- this.x = this.gridAlignedX;
|
|
|
- this.y = this.gridAlignedY;
|
|
|
+ this.x = this._gridAlignedX;
|
|
|
+ this.y = this._gridAlignedY;
|
|
|
}
|
|
|
|
|
|
private _onDown(evt: PointerEvent) {
|
|
@@ -164,5 +202,32 @@ export class GraphFrame {
|
|
|
}
|
|
|
|
|
|
this.element.parentElement!.removeChild(this.element);
|
|
|
+
|
|
|
+
|
|
|
+ this._ownerCanvas.frames.splice(this._ownerCanvas.frames.indexOf(this), 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ public serialize(): IFrameData {
|
|
|
+ return {
|
|
|
+ x: this._x,
|
|
|
+ y: this._y,
|
|
|
+ width: this._width,
|
|
|
+ height: this._height,
|
|
|
+ color: this._color.asArray(),
|
|
|
+ name: this.name
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Parse(serializationData: IFrameData, canvas: GraphCanvasComponent) {
|
|
|
+ let newFrame = new GraphFrame(null, canvas);
|
|
|
+
|
|
|
+ newFrame.x = serializationData.x;
|
|
|
+ newFrame.y = serializationData.y;
|
|
|
+ newFrame.width = serializationData.width;
|
|
|
+ newFrame.height = serializationData.height;
|
|
|
+ newFrame.name = serializationData.name;
|
|
|
+ newFrame.color = Color3.FromArray(serializationData.color);
|
|
|
+
|
|
|
+ return newFrame;
|
|
|
}
|
|
|
}
|