Skip to content

Commit

Permalink
fix the thickness handle not responsible issue
Browse files Browse the repository at this point in the history
  • Loading branch information
HananoshikaYomaru committed Dec 23, 2023
1 parent 8cfd419 commit 4c5d42f
Show file tree
Hide file tree
Showing 24 changed files with 283 additions and 188 deletions.
Binary file modified bun.lockb
Binary file not shown.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"version": "bun version-bump.mjs && git add manifest.json versions.json",
"release": "bash ./release.sh",
"prepare": "husky install",
"typecheck": "tsc -noEmit -skipLibCheck",
"typecheck": "tsc -noEmit -skipLibCheck && bunx dpdm -T --exit-code circular:1 --warning false --tree false src/main.ts",
"lint": "eslint . --ext .ts --fix"
},
"keywords": [
Expand All @@ -32,9 +32,11 @@
"@typescript-eslint/parser": "^6.7.0",
"builtin-modules": "3.3.0",
"bun-types": "^1.0.5",
"dpdm": "^3.14.0",
"esbuild": "0.17.3",
"eslint": "^8.51.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-unused-imports": "^2.0.0",
"husky": "^8.0.3",
Expand Down
97 changes: 2 additions & 95 deletions src/SettingManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,14 @@ import {
GraphType,
SearchEngineType,
SavedSettingSchema,
DagOrientation,
CommandClickNodeAction,
defaultLocalGraphSetting,
defaultGlobalGraphSetting,
} from "@/SettingsSchemas";
import { createNotice } from "@/util/createNotice";
import { State } from "@/util/State";
import { Plugin } from "obsidian";

export const nodeSize = {
min: 1,
max: 10,
step: 0.1,
default: 3, // 3
};

export const linkThickness = {
min: 1,
max: 3,
step: 0.1,
default: 2, // 3
};

export const linkDistance = {
min: 10,
max: 200,
step: 1,
default: 100, // 50
};

export const nodeRepulsion = {
min: 2500,
max: 3000,
step: 100,
default: 2800, // 28
};

export const distanceFromFocal = {
min: 100,
max: 500,
step: 10,
default: 300,
};

export type BaseFilterSettings = Prettify<z.TypeOf<typeof BaseFilterSettingsSchema>>;

export type LocalFilterSetting = Prettify<z.TypeOf<typeof LocalFilterSettingSchema>>;
Expand All @@ -78,64 +44,6 @@ export type GraphSetting = Exclude<SavedSetting["setting"], undefined>;
const corruptedMessage =
"The setting is corrupted. You will not be able to save the setting. Please backup your data.json, remove it and reload the plugin. Then migrate your old setting back.";

export const defaultGlobalGraphSetting = {
filter: {
searchQuery: "",
showOrphans: true,
showAttachments: false,
},
groups: [],
display: {
nodeSize: nodeSize.default,
linkThickness: linkThickness.default,
linkDistance: linkDistance.default,
nodeRepulsion: nodeRepulsion.default,
distanceFromFocal: 300,
// node hover color is red
nodeHoverColor: "#ff0000",
// node hover neighbour color is green
nodeHoverNeighbourColor: "#00ff00",
// link hover color is blue
linkHoverColor: "#0000ff",
showExtension: false,
showFullPath: false,
showCenterCoordinates: true,
showLinkArrow: true,
dontMoveWhenDrag: false,
dagOrientation: DagOrientation.null,
},
};

export const defaultLocalGraphSetting = {
filter: {
searchQuery: "",
showOrphans: true,
showAttachments: false,
depth: 1,
linkType: "both",
},
groups: [],
display: {
nodeSize: nodeSize.default,
linkThickness: linkThickness.default,
linkDistance: linkDistance.default,
nodeRepulsion: nodeRepulsion.default,
distanceFromFocal: 300,
// node hover color is red
nodeHoverColor: "#ff0000",
// node hover neighbour color is green
nodeHoverNeighbourColor: "#00ff00",
// link hover color is blue
linkHoverColor: "#0000ff",
showExtension: false,
showFullPath: false,
showCenterCoordinates: true,
showLinkArrow: true,
dontMoveWhenDrag: false,
dagOrientation: DagOrientation.null,
},
};

/**
* @remarks the setting will not keep the temporary setting. It will only keep the saved settings.
*/
Expand Down Expand Up @@ -231,7 +139,6 @@ export class MySettingManager implements ISettingManager<Setting> {

static getNewSetting<T extends GraphType>(type: T) {
if (type === GraphType.global) {
// @ts-ignore
return defaultGlobalGraphSetting as GlobalGraphSettings;
} else {
return defaultLocalGraphSetting as LocalGraphSettings;
Expand Down
95 changes: 94 additions & 1 deletion src/SettingsSchemas.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,40 @@
import { defaultGlobalGraphSetting } from "@/SettingManager";
import { z } from "zod";

export const nodeSize = {
min: 1,
max: 10,
step: 0.1,
default: 3, // 3
};

export const linkThickness = {
min: 1,
max: 3,
step: 0.1,
default: 2, // 3
};

export const linkDistance = {
min: 10,
max: 200,
step: 1,
default: 100, // 50
};

export const nodeRepulsion = {
min: 2500,
max: 3000,
step: 100,
default: 2800, // 28
};

export const distanceFromFocal = {
min: 100,
max: 500,
step: 10,
default: 300,
};

export enum GraphType {
/**
* the global graph
Expand All @@ -10,6 +44,7 @@ export enum GraphType {
* the local graph
*/
local = "local",
postProcessor = "postProcessor",
}

export enum SearchEngineType {
Expand All @@ -35,6 +70,64 @@ export enum CommandClickNodeAction {
focusNode = "focusNode",
}

export const defaultGlobalGraphSetting = {
filter: {
searchQuery: "",
showOrphans: true,
showAttachments: false,
},
groups: [],
display: {
nodeSize: nodeSize.default,
linkThickness: linkThickness.default,
linkDistance: linkDistance.default,
nodeRepulsion: nodeRepulsion.default,
distanceFromFocal: 300,
// node hover color is red
nodeHoverColor: "#ff0000",
// node hover neighbour color is green
nodeHoverNeighbourColor: "#00ff00",
// link hover color is blue
linkHoverColor: "#0000ff",
showExtension: false,
showFullPath: false,
showCenterCoordinates: true,
showLinkArrow: true,
dontMoveWhenDrag: false,
dagOrientation: DagOrientation.null,
},
};

export const defaultLocalGraphSetting = {
filter: {
searchQuery: "",
showOrphans: true,
showAttachments: false,
depth: 1,
linkType: "both",
},
groups: [],
display: {
nodeSize: nodeSize.default,
linkThickness: linkThickness.default,
linkDistance: linkDistance.default,
nodeRepulsion: nodeRepulsion.default,
distanceFromFocal: 300,
// node hover color is red
nodeHoverColor: "#ff0000",
// node hover neighbour color is green
nodeHoverNeighbourColor: "#00ff00",
// link hover color is blue
linkHoverColor: "#0000ff",
showExtension: false,
showFullPath: false,
showCenterCoordinates: true,
showLinkArrow: true,
dontMoveWhenDrag: false,
dagOrientation: DagOrientation.null,
},
};

export const BaseDisplaySettingsSchema = z.object({
nodeSize: z.number().default(defaultGlobalGraphSetting.display.nodeSize),
linkThickness: z.number().default(defaultGlobalGraphSetting.display.linkThickness),
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const commands: Command[] = [
title: "Test Command",
function: (view, nodes) => {
for (const node of nodes) {
const file = view.app.vault.getAbstractFileByPath(node.path);
const file = view.plugin.app.vault.getAbstractFileByPath(node.path);
if (file) createNotice(`run on ${file.name}`);
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/commands/CommandModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class CommandModal extends FuzzySuggestModal<Command> {
private view: Graph3dView;

constructor(view: Graph3dView, selectedNodes: Set<Node>) {
super(view.app);
super(view.plugin.app);
this.nodes = selectedNodes;
this.view = view;
}
Expand Down
5 changes: 3 additions & 2 deletions src/commands/deleteNote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { Graph3dView } from "@/views/graph/Graph3dView";
import { Node } from "@/graph/Node";

export const deleteNote = (view: Graph3dView, nodes: Set<Node>) => {
const vault = view.plugin.app.vault;
for (const node of nodes) {
const file = view.app.vault.getAbstractFileByPath(node.path);
const file = vault.getAbstractFileByPath(node.path);
if (file) {
view.app.vault.trash(file, view.app.vault.config.trashOption === "system");
vault.trash(file, vault.config.trashOption === "system");
}
}
};
2 changes: 1 addition & 1 deletion src/graph/Link.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Node } from "@/graph/Node";
import { type Node } from "@/graph/Node";

export type ResolvedLinkCache = Record<string, Record<string, number>>;

Expand Down
2 changes: 1 addition & 1 deletion src/graph/Node.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Link } from "@/graph/Link";
import { type Link } from "@/graph/Link";
import { TAbstractFile } from "obsidian";

export class Node {
Expand Down
26 changes: 14 additions & 12 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { config } from "@/config";
import { MyFileManager } from "@/FileManager";
import { MySettingManager } from "@/SettingManager";
import { GraphType } from "@/SettingsSchemas";
import { GlobalGraph3dView } from "@/views/graph/GlobalGraph3dView";
import { Graph3dView } from "@/views/graph/Graph3dView";
import { LocalGraph3dView } from "@/views/graph/LocalGraph3dView";
import { GlobalGraphItemView } from "@/views/graph/GlobalGraphItemView";
import { LocalGraphItemView } from "@/views/graph/LocalGraphItemView";

export default class Graph3dPlugin extends Plugin {
_resolvedCache: ResolvedLinkCache;
Expand Down Expand Up @@ -72,12 +72,18 @@ export default class Graph3dPlugin extends Plugin {

// register global view
this.registerView(config.viewType.global, (leaf) => {
return new GlobalGraph3dView(this, leaf);
return new GlobalGraphItemView(leaf, this);
});

// register local view
this.registerView(config.viewType.local, (leaf) => {
return new LocalGraph3dView(this, leaf);
return new LocalGraphItemView(leaf, this);
});

// register markdown code block processor
this.registerMarkdownCodeBlockProcessor("3d-graph", (source, el, ctx) => {
// create the local graph on el
// new GraphPostProcessor(source, el, ctx, this);
});
}

Expand Down Expand Up @@ -158,21 +164,17 @@ export default class Graph3dPlugin extends Plugin {
* Opens a local graph view in a new leaf
*/
private openLocalGraph = () => {
const localGraphView =
this.app.workspace.getActiveViewOfType(LocalGraph3dView) ??
this.activeGraphViews.find((view) => view.graphType === GraphType.local);
if (localGraphView) {
this.app.workspace.setActiveLeaf(localGraphView.leaf);
const localGraphItemView = this.app.workspace.getActiveViewOfType(LocalGraphItemView);
if (localGraphItemView) {
this.app.workspace.setActiveLeaf(localGraphItemView.leaf);
} else this.openGraph(GraphType.local);
};

/**
* Opens a global graph view in the current leaf
*/
private openGlobalGraph = () => {
const globalGraphView =
this.app.workspace.getActiveViewOfType(GlobalGraph3dView) ??
this.activeGraphViews.find((view) => view.graphType === GraphType.global);
const globalGraphView = this.app.workspace.getActiveViewOfType(GlobalGraphItemView);
if (globalGraphView) {
this.app.workspace.setActiveLeaf(globalGraphView.leaf);
} else this.openGraph(GraphType.global);
Expand Down
2 changes: 1 addition & 1 deletion src/views/atomics/addSearchInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const addSearchInput = async (
};

// this make search that the search result container el is alaways visible
view.containerEl.appendChild(searchResultContainerEl);
if (view.itemView) view.itemView.containerEl.appendChild(searchResultContainerEl);

// if it is a passive engine, we need to enable mutation observer

Expand Down
3 changes: 2 additions & 1 deletion src/views/graph/CenterCoordinates.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as THREE from "three";
import { origin } from "@/views/graph/ForceGraph";

const origin = new THREE.Vector3(0, 0, 0);

export class CenterCoordinates {
public readonly arrowsGroup = new THREE.Group();
Expand Down

0 comments on commit 4c5d42f

Please sign in to comment.