Skip to content

Commit

Permalink
release: 1.1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
HananoshikaYomaru committed Dec 22, 2023
1 parent 26be173 commit 9d42732
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 8 deletions.
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "3d-graph-new",
"name": "3D Graph New",
"version": "1.1.8",
"version": "1.1.9",
"description": "A 3D Graph for Obsidian",
"author": "Hananoshika Yomaru",
"authorUrl": "https://github.com/HananoshikaYomaru",
Expand All @@ -10,4 +10,4 @@
"Github Sponsor": "https://github.com/sponsors/HananoshikaYomaru"
},
"isDesktopOnly": true
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "3d-graph-new",
"version": "1.1.8",
"version": "1.1.9",
"description": "A 3D graph for Obsidian",
"main": "main.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/SettingManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,5 +247,6 @@ export const DEFAULT_SETTING: Setting = {
pluginSetting: {
maxNodeNumber: 1000,
searchEngine: SearchEngineType.default,
rightClickToPan: false,
},
};
1 change: 1 addition & 0 deletions src/SettingsSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,6 @@ export const SettingSchema = z.object({
pluginSetting: z.object({
maxNodeNumber: z.number(),
searchEngine: z.nativeEnum(SearchEngineType),
rightClickToPan: z.boolean().default(false),
}),
});
17 changes: 17 additions & 0 deletions src/views/SettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,22 @@ export class SettingTab extends PluginSettingTab {
this.plugin.activeGraphViews.forEach((view) => view.settingManager.resetSettings());
});
});

new Setting(containerEl)
.setName("Right click to pan")
.setDesc(
"If true, right click will pan the graph. Otherwise, Cmd + left click will pan the graph."
)
.addToggle((toggle) => {
toggle.setValue(pluginSetting.rightClickToPan).onChange(async (value) => {
// update the json
this.plugin.settingManager.updateSettings((setting) => {
setting.value.pluginSetting.rightClickToPan = value;
});

// force all the graph view to reset their settings
this.plugin.activeGraphViews.forEach((view) => view.refreshGraph());
});
});
}
}
24 changes: 19 additions & 5 deletions src/views/graph/ForceGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import { Graph3dView } from "@/views/graph/Graph3dView";
import { FOCAL_FROM_CAMERA, ForceGraphEngine } from "@/views/graph/ForceGraphEngine";
import { DeepPartial } from "ts-essentials";
import { Node } from "@/graph/Node";
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls";

import { rgba } from "polished";
import { createNotice } from "@/util/createNotice";
import { DagOrientation, GraphType } from "@/SettingsSchemas";
import { LocalGraph3dView } from "@/views/graph/LocalGraph3dView";
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls";

/**
* the origin vectorss
Expand Down Expand Up @@ -56,6 +56,8 @@ export class ForceGraph {
this.view = view;
this.interactionManager = new ForceGraphEngine(this);

const pluginSetting = this.view.plugin.settingManager.getSettings().pluginSetting;

// get the content element of the item view
const rootHtmlElement = view.contentEl as HTMLDivElement;

Expand All @@ -69,7 +71,7 @@ export class ForceGraph {
// create the instance
// these config will not changed by user
this.instance = ForceGraph3D({
controlType: "orbit",
controlType: pluginSetting.rightClickToPan ? undefined : "orbit",
extraRenderers: [
// @ts-ignore https://github.com/vasturiano/3d-force-graph/blob/522d19a831e92015ff77fb18574c6b79acfc89ba/example/html-nodes/index.html#L27C9-L29
new CSS2DRenderer({
Expand All @@ -91,6 +93,9 @@ export class ForceGraph {
: 1)
);
})
.onBackgroundRightClick(() => {
this.interactionManager.removeSelection();
})
.nodeOpacity(0.9)
.linkOpacity(0.3)
.onNodeHover(this.interactionManager.onNodeHover)
Expand Down Expand Up @@ -162,13 +167,22 @@ export class ForceGraph {
// init other setting
this.updateConfig(this.view.settingManager.getCurrentSetting());

const controls = this.instance.controls() as OrbitControls;
controls.mouseButtons.RIGHT = undefined;
// this disable the right click to pan
if (!pluginSetting.rightClickToPan) {
const controls = this.instance.controls() as OrbitControls;
controls.mouseButtons.RIGHT = undefined;
// also if right click to pan cmd + left pan should be disabled
// to disable it, we just need to remove the orbit controls
}

// change the nav info text
this.view.contentEl
.querySelector(".scene-nav-info")
?.setText("Left-click: rotate, Mouse-wheel/middle-click: zoom, Cmd + left-click: pan");
?.setText(
`Left-click: rotate, Mouse-wheel/middle-click: zoom, ${
pluginSetting.rightClickToPan ? "Right click" : "Cmd + left click"
}: pan`
);
}

private createNodeLabel() {
Expand Down

0 comments on commit 9d42732

Please sign in to comment.