Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable pan and zoom individually #90

Merged
merged 3 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kateter-platform/graphica",
"version": "1.0.87",
"version": "1.0.88",
"source": "./src/index.ts",
"description": "A tool for advanced graphing and visualization",
"repository": {
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
9 changes: 8 additions & 1 deletion src/Core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const ORBIT_CONTROL_OPTIONS = {
type GraphicaOptions = {
root: HTMLElement;
disableControls: boolean;
disableZoom: boolean;
disablePan: boolean;
defaultZoom: number;
defaultPosition: InputPosition;
minZoom: number;
Expand All @@ -38,6 +40,8 @@ type GraphicaOptions = {
const defaultGraphicaOptions: GraphicaOptions = {
root: document.body,
disableControls: false,
disableZoom: false,
disablePan: false,
defaultZoom: 50,
defaultPosition: [0, 0],
minZoom: 1,
Expand Down Expand Up @@ -68,6 +72,8 @@ class Core {
const {
root,
disableControls,
disableZoom,
disablePan,
defaultZoom,
minZoom,
maxZoom,
Expand Down Expand Up @@ -111,7 +117,8 @@ class Core {

const controls = new OrbitControls(this.camera, this.renderer.domElement);
controls.enableRotate = false;
controls.enablePan = true;
controls.enablePan = !disablePan;
controls.enableZoom = !disableZoom;
controls.mouseButtons = ORBIT_CONTROL_OPTIONS;
controls.minZoom = minZoom;
controls.maxZoom = maxZoom;
Expand Down
Loading