Skip to content

Commit

Permalink
Update node
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasdeluna committed Aug 7, 2024
1 parent f3201d1 commit 54ef928
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@typescript-eslint/parser": "^5.61.0",
"babel-loader": "^9.1.2",
"cross-env": "^7.0.3",
"eslint": "^8.43.0",
"eslint": "^8.43.0",
"eslint-plugin-import": "^2.27.5",
"expose-loader": "^4.1.0",
"prettier": "^2.8.8",
Expand Down
27 changes: 24 additions & 3 deletions src/Components/Derived/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import Text from "../Text";

export type NodeOptions = CircleOptions & {
label?: string;
color?: number;
};

const defaultNodeOptions: NodeOptions = {
...defaultShapeOptions,
label: "",
color: 0xfaa307,
};

type Edge = {
Expand All @@ -19,6 +21,18 @@ type Edge = {
weight?: number;
};

type ConnectOptions = {
directed: boolean;
value: number | undefined;
color: number;
};

const defaultConnectOptions: ConnectOptions = {
directed: false,
value: undefined,
color: 0x080007,
};

class Node extends Circle {
adjacencyList: Edge[];
label?: Text;
Expand Down Expand Up @@ -75,7 +89,9 @@ class Node extends Circle {
* @param directed - Booleean for whether the edge is directed (directed edges will also have curve)
* @param value - Number for eeight/value of the edge
*/
connectTo(other: Node, directed = false, value?: number): void {
connectTo(other: Node, options?: ConnectOptions): void {
const { directed, value, color } = { ...defaultConnectOptions, ...options };

if (!this.isAdjacentTo(other) && !(!directed && other.isAdjacentTo(this))) {
const dx = other.position.x - this.position.x;
const dy = other.position.y - this.position.y;
Expand All @@ -95,7 +111,8 @@ class Node extends Circle {
{
arrowhead: directed,
curve: directed ? 2 : 0,
label: value !== undefined ? value.toString() : "",
label: value?.toString() ?? "",
color: color,
}
);
this.adjacencyList.push({ node: other, line: line, weight: value });
Expand Down Expand Up @@ -154,7 +171,11 @@ class Node extends Circle {
}

if (!directed) {
other.connectTo(this, false);
other.connectTo(this, {
directed: false,
value: undefined,
color: 0x080007,
});
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/Components/LegendText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ type LegendTextOptions = {
};

const defaultLegendTextOptions = {

shape: "circle",
color: "#faa307",
useStates: false,
Expand Down
13 changes: 1 addition & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* export { default as Core } from "./Core";
export { default as Core } from "./Core";
export { default as Arc } from "./Components/Arc";
export { default as Bracket } from "./Components/Bracket";
export { default as Button } from "./Components/Button";
Expand All @@ -24,14 +24,3 @@ export { default as Node } from "./Components/Derived/Node";
export { default as OperationButtonPanel } from "./Components/Derived/OperationButtonPanel";
export { default as BarDiagram } from "./Components/Derived/BarDiagram";
export * as three from "three";
*/

import Grid from "./Components/Grid";
import Core from "./Core";

const a = new Core({disableZoom: true, disablePan: true});
const g = new Grid();

a.add(g)

a.run()

0 comments on commit 54ef928

Please sign in to comment.