Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
terrychenzw committed Jan 20, 2025
1 parent c2bd1ab commit b343ed1
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 56 deletions.
4 changes: 3 additions & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ interface ZKNavigationSettings {
nodeColor: string;
datetimeFormat: string;
graphType: string;
nodeClose: boolean;
}

//Default value for setting field
Expand Down Expand Up @@ -171,7 +172,8 @@ const DEFAULT_SETTINGS: ZKNavigationSettings = {
playControllerToggle: true,
nodeColor: "#FFFFAA",
datetimeFormat: "yyyy-MM-DD HH:mm",
graphType: "structure"
graphType: "structure",
nodeClose: false,
}

export default class ZKNavigationPlugin extends Plugin {
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "zettelkasten-navigation",
"name": "zettelkasten navigation",
"version": "1.0.8",
"version": "1.0.9",
"minAppVersion": "1.5.7",
"description": "Visualize a Luhmann-style zettelkasten.",
"author": "terrychenzw",
Expand Down
4 changes: 3 additions & 1 deletion src/lang/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export default {
"play_des": "open the play controller",
"Set color for nodes": "Set color for branch's nodes",
"Set datetime format": "Set datetime format",
"Shorten the distance between adjacent nodes": "Shorten the distance between adjacent nodes",

// indexView.ts
"Display from : ": "From : ",
Expand Down Expand Up @@ -151,10 +152,11 @@ export default {
"Index folder not set!": "❌Setting error: Index folder not set!",
"No index can be found by path": "No index can be found by path",

//tableView.ts
//tableModal.ts
"note's ID": "note's ID",
"note's title": "note's title",
"Time of creation": "Time of creation",
"Copy markdown table": "Copy markdown table",

//addCommandModal.ts, chooseCutomNameModal.ts, chooseIconModal.ts
"choose a command to add": "choose a command to add",
Expand Down
4 changes: 3 additions & 1 deletion src/lang/locale/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export default {
"play_des": "打开底部居中的播放控制器",
"Set color for nodes": "设置分支节点颜色",
"Set datetime format": "设置日期时间格式",
"Shorten the distance between adjacent nodes": "缩短邻近节点的距离",

// indexView.ts
"Display from : ": "起点:",
Expand Down Expand Up @@ -149,10 +150,11 @@ export default {
"Index folder not set!": "❌设置错误: 关键词文件夹没有设置!",
"No index can be found by path": "指定文件夹找不到任何关键词:",

//tableView.ts
//tableModal.ts
"note's ID": "笔记编号(ID)",
"note's title": "笔记标题",
"Time of creation": "创建时间",
"Copy markdown table": "复制 markdown 表格",

//addCommandModal.ts
"choose a command to add": "选择一个命令并添加",
Expand Down
74 changes: 45 additions & 29 deletions src/modal/tableModal.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import ZKNavigationPlugin from "main";
import { App, MarkdownRenderer, Modal, moment, TFile } from "obsidian";
import { App, ExtraButtonComponent, MarkdownRenderer, Modal, moment, Notice, TFile } from "obsidian";
import { t } from "src/lang/helper";
import { ZKNode, ZK_NAVIGATION } from "src/view/indexView";

export class tableModal extends Modal {

plugin: ZKNavigationPlugin;
data:string = `|${t("note's ID")}|${t("note's title")}|${t("inlinks")}|${t("outlinks")}|${t("Time of creation")}|\n| --- | --- | --- | --- | --- |\n`;
headerStr:string = `|${t("note's ID")}|${t("note's title")}|${t("inlinks")}|${t("outlinks")}|${t("Time of creation")}|\n| --- | --- | --- | --- | --- |\n`;
tableStr:string = "";
tableArr:ZKNode[];

constructor(app: App, plugin:ZKNavigationPlugin, tableArr:ZKNode[]) {
Expand All @@ -18,13 +19,47 @@ export class tableModal extends Modal {
onOpen() {
let { contentEl } = this;
this.modalEl.addClass("zk-table-container");

this.createToolBar(contentEl)
this.createTable(contentEl)

}

createToolBar(contentEl:HTMLElement){

const toolbarDiv = contentEl.createDiv("zk-table-toolbar");
toolbarDiv.empty();
const copyTableIcon = new ExtraButtonComponent(toolbarDiv);
copyTableIcon.setIcon("copy").setTooltip(t("Copy markdown table"));
copyTableIcon.onClick(async ()=>{
await this.copyTableStr();
})


}
createTable(contentEl:HTMLElement){
const contentDiv = contentEl.createDiv("zk-table-view");
contentDiv.id = "zk-table-view";
this.appendTableLine();
MarkdownRenderer.render(this.app, this.data, contentDiv, '', this.plugin);
MarkdownRenderer.render(this.app, this.tableStr, contentDiv, '', this.plugin);
this.addLinkAndPreview();

}

async copyTableStr(){

this.appendTableLine();

this.tableStr = this.tableStr.replace(/<ul><li>/g,"").replace(/<\/li><\/ul>/g,"").replace(/<\/li><li>/g,"<br>");

await navigator.clipboard.writeText(this.tableStr);

new Notice(t("Copy markdown table"));

}

appendTableLine(){
this.tableStr = this.headerStr;
for(let node of this.tableArr){
let inlinksStr:string = "";
for(let inlink of this.getInlinks(node.file)){
Expand All @@ -36,15 +71,18 @@ export class tableModal extends Modal {

let outlinkStr:string = "";

for(let outlink of this.getOutlinks(node.file)){
outlinkStr = outlinkStr + `<li> [[${outlink.basename}]]</li>`;
}
let outlinks = this.app.metadataCache.getFileCache(node.file)?.links

if(outlinks){
for(let outlink of outlinks){
outlinkStr = outlinkStr + `<li> ${outlink.original.replace(`|`,`\\|`)}</li>`;
}
}
if(outlinkStr !== ""){
outlinkStr = `<ul>${outlinkStr}</ul>`;
}

this.data = this.data + `|[[${node.ID}]]|${node.title}|${inlinksStr}|${outlinkStr}|${moment(node.ctime).format(this.plugin.settings.datetimeFormat)}|\n`
this.tableStr = this.tableStr + `|[[${node.ID}]]|${node.title}|${inlinksStr}|${outlinkStr}|${moment(node.ctime).format(this.plugin.settings.datetimeFormat)}|\n`
}
}

Expand All @@ -68,28 +106,6 @@ getInlinks(currentFile: TFile) {
return inlinkArr;
}

getOutlinks(currentFile: TFile) {


let outlinkArr: TFile[] = [];
const resolvedLinks = this.app.metadataCache.resolvedLinks;

let outlinks: string[] = Object.keys(resolvedLinks[currentFile.path]);

if(this.plugin.settings.FileExtension == "md"){
outlinks = outlinks.filter(link=>link.endsWith(".md"))
}

for (let outlink of outlinks) {
let outlinkFile = this.app.vault.getFileByPath(outlink);
if (outlinkFile !== null) {
outlinkArr.push(outlinkFile);
}
}
return outlinkArr;

}

addLinkAndPreview(){

let tableDiv = document.getElementById("zk-table-view");
Expand Down
34 changes: 24 additions & 10 deletions src/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,21 +294,35 @@ export class ZKNavigationSettngTab extends PluginSettingTab {
.onChange((value) => {
this.plugin.settings.graphType = value;
this.plugin.RefreshIndexViewFlag = true;
branchSectionDiv.addClass("zk-hidden");
structureSettingDiv.addClass("zk-hidden");
roadmapSettingDiv.addClass("zk-hidden");
})
)
.addExtraButton((cb)=>{
cb.setIcon("settings")
.onClick(()=>{
if(this.plugin.settings.graphType === "structure"){
this.hideDiv(branchSectionDiv);
this.hideDiv(structureSettingDiv);
}else if(this.plugin.settings.graphType === "roadmap"){
this.hideDiv(roadmapSettingDiv);
}
})
})

const branchSectionDiv = indexGraphView.createDiv("zk-local-section zk-hidden")
const roadmapSettingDiv = indexGraphView.createDiv("zk-local-section zk-hidden")

new Setting(roadmapSettingDiv)
.setName(t("Shorten the distance between adjacent nodes"))
.addToggle(toggle => toggle.setValue(this.plugin.settings.nodeClose)
.onChange((value) => {
this.plugin.settings.nodeClose = value;
this.plugin.RefreshIndexViewFlag = true;
})
);

const structureSettingDiv = indexGraphView.createDiv("zk-local-section zk-hidden")

new Setting(branchSectionDiv)
new Setting(structureSettingDiv)
.setName(t("direction of graph"))
.addDropdown(options => options
.addOption("LR", t('"LR": feft to right'))
Expand All @@ -322,7 +336,7 @@ export class ZKNavigationSettngTab extends PluginSettingTab {
})
);

new Setting(branchSectionDiv)
new Setting(structureSettingDiv)
.setName(t("siblings order"))
.setDesc(t("siblings order description"))
.addDropdown(options => options
Expand All @@ -335,7 +349,7 @@ export class ZKNavigationSettngTab extends PluginSettingTab {
})
);

new Setting(branchSectionDiv)
new Setting(structureSettingDiv)
.setName(t("same width for siblings"))
.addToggle(toggle => toggle.setValue(this.plugin.settings.siblingLenToggle)
.onChange((value) => {
Expand All @@ -344,7 +358,7 @@ export class ZKNavigationSettngTab extends PluginSettingTab {
})
);

new Setting(branchSectionDiv)
new Setting(structureSettingDiv)
.setName(t("Set red dash line for nodes with ID ends with letter"))
.setDesc(t("In order to distinguish nodes which ID ends with letter and number"))
.addToggle(toggle => toggle.setValue(this.plugin.settings.RedDashLine)
Expand All @@ -354,7 +368,7 @@ export class ZKNavigationSettngTab extends PluginSettingTab {
})
);

new Setting(branchSectionDiv)
new Setting(structureSettingDiv)
.setName(t("display created time"))
.setDesc(t("Set datetime format"))
.addText((cb)=>{
Expand All @@ -376,7 +390,7 @@ export class ZKNavigationSettngTab extends PluginSettingTab {
})
);

new Setting(branchSectionDiv)
new Setting(structureSettingDiv)
.setName(t("Fold node toggle"))
.setDesc(t("Open the fold icon(🟡🟢)"))
.addToggle(toggle => toggle.setValue(this.plugin.settings.FoldToggle)
Expand All @@ -385,7 +399,7 @@ export class ZKNavigationSettngTab extends PluginSettingTab {
this.plugin.RefreshIndexViewFlag = true;
})
);
new Setting(branchSectionDiv)
new Setting(structureSettingDiv)
.setName(t("Set color for nodes"))
.addColorPicker(color => color.setValue(this.plugin.settings.nodeColor)
.onChange((value)=>{
Expand Down
62 changes: 49 additions & 13 deletions src/view/indexView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,7 @@ export class ZKIndexView extends ItemView {
}
}

let mermaidStr: string = `%%{init: { 'logLevel': 'debug', 'theme': 'base', 'gitGraph': {'showBranches': false, 'parallelCommits': true, 'rotateCommitLabel': true}} }%%
let mermaidStr: string = `%%{init: { 'logLevel': 'debug', 'theme': 'base', 'gitGraph': {'showBranches': false, 'parallelCommits': ${this.plugin.settings.nodeClose}, 'rotateCommitLabel': true}} }%%
gitGraph
${gitStr}
`;
Expand Down Expand Up @@ -1449,10 +1449,44 @@ export class ZKIndexView extends ItemView {
if(typeof nodes === 'undefined') return;
nodes.sort((a, b) => a.IDStr.localeCompare(b.IDStr));

const cardWidth = this.plugin.settings.cardWidth;
const cardHeight = this.plugin.settings.cardHeight;
const intervalX = cardWidth/2;
const intervalY = cardHeight/8;
let cardWidth = this.plugin.settings.cardWidth;
let cardHeight = this.plugin.settings.cardHeight;
let intervalX = cardWidth/2;
let intervalY = cardHeight/8;
let fromSide = "right";
let toSide = "left";
let direction = this.plugin.settings.DirectionOfBranchGraph;


switch(direction){
case "RL":
cardWidth = -cardWidth;
cardHeight = cardHeight;
intervalX = cardWidth/2;
intervalY = cardHeight/8;
fromSide = "left";
toSide = "right";
break;
case "TB":
cardWidth = cardWidth;
cardHeight = cardHeight;
intervalX = cardHeight/8;
intervalY = cardWidth/2;
fromSide = "bottom";
toSide = "top";
break;
case "BT":
cardWidth = -cardWidth;
cardHeight = cardHeight;
intervalX = -cardHeight/8;
intervalY = -cardWidth/2;
fromSide = "top";
toSide = "bottom";
break;
default:

break;
}

const maxLength = Math.max(...nodes.map(n=>n.IDArr.length));
const minLength = Math.min(...nodes.map(n=>n.IDArr.length));
Expand Down Expand Up @@ -1503,25 +1537,30 @@ export class ZKIndexView extends ItemView {
}
}

this.tightCards(nodes);
this.tightCards(nodes, intervalY, cardHeight);

let canvasNodeStr:string = "";
let canvasEdgeStr:string = "";
for(let i=0;i<nodes.length;i++){

let positionX:number = (nodes[i].IDArr.length - nodes[0].IDArr.length)*(cardWidth + intervalX);
let positionY:number = nodes[i].height;
canvasNodeStr = canvasNodeStr + `
{"id":"${nodes[i].randomId}","x":${positionX},"y":${positionY},"width":${Math.abs(cardWidth)},"height":${Math.abs(cardHeight)},"type":"file","file":"${nodes[i].file.path}"},`
if(direction === "LR" || direction === "RL"){
canvasNodeStr = canvasNodeStr + `
{"id":"${nodes[i].randomId}","x":${positionX},"y":${positionY},"width":${Math.abs(cardWidth)},"height":${Math.abs(cardHeight)},"type":"file","file":"${nodes[i].file.path}"},`
}else{
canvasNodeStr = canvasNodeStr + `
{"id":"${nodes[i].randomId}","x":${positionY},"y":${positionX},"width":${Math.abs(cardWidth)},"height":${Math.abs(cardHeight)},"type":"file","file":"${nodes[i].file.path}"},`

}
let IDStr = nodes[i].IDStr;
let IDArr = nodes[i].IDArr;

let sonNodes = nodes.filter(n=>n.IDStr.startsWith(IDStr) && n.IDArr.length == IDArr.length+1);

for(let son of sonNodes){
canvasEdgeStr = canvasEdgeStr + `
{"id":"${random(16)}","fromNode":"${nodes[i].randomId}","fromSide":"right","toNode":"${son.randomId}","toSide":"left"},`
{"id":"${random(16)}","fromNode":"${nodes[i].randomId}","fromSide":"${fromSide}","toNode":"${son.randomId}","toSide":"${toSide}"},`
}

}
Expand All @@ -1540,13 +1579,10 @@ export class ZKIndexView extends ItemView {
}`;
}

tightCards(nodes:ZKNode[]){
const cardHeight = this.plugin.settings.cardHeight;
const intervalY = cardHeight/8;
tightCards(nodes:ZKNode[], intervalY:number, cardHeight:number){

const maxLength = Math.max(...nodes.map(n=>n.IDArr.length));
const minLength = Math.min(...nodes.map(n=>n.IDArr.length));


for(let i=maxLength-1;i>=minLength;i--){
let layerNodes = nodes.filter(n=>n.IDArr.length === i);
Expand Down

0 comments on commit b343ed1

Please sign in to comment.