From 4d25172bc39699cd693d7c25ad89065ae8fd37af Mon Sep 17 00:00:00 2001 From: Zsolt Viczian Date: Thu, 11 Aug 2022 22:32:16 +0200 Subject: [PATCH] 0.1.6 --- manifest.json | 2 +- src/Scene.ts | 29 +++++++++++++++++++++++++-- src/graph/Layout.ts | 46 ++++++++++++++++++++++++++++--------------- src/utils/dataview.ts | 2 +- versions.json | 2 +- 5 files changed, 60 insertions(+), 21 deletions(-) diff --git a/manifest.json b/manifest.json index f017dae..c5819b9 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "excalibrain", "name": "ExcaliBrain", - "version": "0.1.5", + "version": "0.1.6", "minAppVersion": "0.15.5", "description": "A clean, intuitive and editable graph view for Obsidian", "author": "Zsolt Viczian", diff --git a/src/Scene.ts b/src/Scene.ts index ac684cd..d3182d9 100644 --- a/src/Scene.ts +++ b/src/Scene.ts @@ -378,6 +378,31 @@ export class Scene { const singleParent = parents.length <= 1 const baseStyle = this.plugin.settings.baseNodeStyle; + //----------------------------------- + //----------------------------------- + //WIP: even columns + enum multitude { + one = 1, + few = 2, + more = 3, + many = 4 + } + + const count = (len:number):number => { + if(len <= 1) return multitude.one; + if(len <= 4) return multitude.few; + if(len < 10) return multitude.more; + return multitude.many; + } + + const mChildren = count(children.length); + const mParent = count(parents.length); + const mSiblings = count(siblings.length); + + //----------------------------------- + //----------------------------------- + + const lCenter = new Layout({ origoX: 0, origoY: 0, @@ -388,7 +413,7 @@ export class Scene { rowHeight: this.nodeHeight }); this.layouts.push(lCenter); - + const lChildren = new Layout({ origoX: 0, origoY: 2.5 * this.nodeHeight, @@ -661,7 +686,7 @@ export class Scene { this.render(); } } - + if(this.removeTimer) { this.removeTimer(); this.removeTimer = undefined; diff --git a/src/graph/Layout.ts b/src/graph/Layout.ts index d44639d..ef01981 100644 --- a/src/graph/Layout.ts +++ b/src/graph/Layout.ts @@ -11,7 +11,7 @@ export class Layout { } layout(columns = this.spec.columns) { - const generateLayoutVector = (pattern:number[]) => { + const generateOddLayoutVector = (pattern:number[]) => { const res:number[] = []; let cur = 1; let state = true; @@ -21,23 +21,37 @@ export class Layout { for(let i=0;i { + const res:number[] = []; + let i = 0; + for(i=columns/2;i>pattern[0];i--) res.push(null); + for(i=0;i items%2 - ? generateLayoutVector([(columns-items)/2,items,(columns-items)/2]) //odd - : generateLayoutVector([(columns-items)/2,items/2,1,items/2,(columns-items)/2]); //even + const getRowLayout = (items: number) => columns%2 + ? (items%2 //even columns + ? generateEvenLayoutVector([(items+1)/2,(items-1)/2]) //odd + : generateEvenLayoutVector([items/2,items/2])) //even + : (items%2 //odd columns + ? generateOddLayoutVector([(columns-items)/2,items,(columns-items)/2]) //odd + : generateOddLayoutVector([(columns-items)/2,items/2,1,items/2,(columns-items)/2])); //even - const sortedNodes = this.nodes.sort((a,b) => a.title.toLowerCase() < b.title.toLowerCase() ? -1 : 1) - const itemCount = sortedNodes.length; - if(itemCount === 0) { - return; - } - const rowCount = Math.ceil(itemCount / columns); - this.renderedNodes = Array(rowCount).fill(null).map((_,i) => - (i+1 < rowCount) || (itemCount % columns === 0) - ? Array(columns).fill(null).map((_,j) => sortedNodes[i*columns+j]) //full row - : getRowLayout(itemCount % columns).map(idx => idx ? sortedNodes[i*columns+idx-1]:null)); + const sortedNodes = this.nodes.sort((a,b) => a.title.toLowerCase() < b.title.toLowerCase() ? -1 : 1) + const itemCount = sortedNodes.length; + if(itemCount === 0) { + return; + } + const rowCount = Math.ceil(itemCount / columns); + + this.renderedNodes = Array(rowCount).fill(null).map((_,i) => + (i+1 < rowCount) || (itemCount % columns === 0) + ? Array(columns).fill(null).map((_,j) => sortedNodes[i*columns+j]) //full row + : getRowLayout(itemCount % columns).map(idx => idx ? sortedNodes[i*columns+idx-1]:null)); } render() { diff --git a/src/utils/dataview.ts b/src/utils/dataview.ts index 27e430a..9e6a17f 100644 --- a/src/utils/dataview.ts +++ b/src/utils/dataview.ts @@ -41,7 +41,7 @@ const readDVField = (app: App, field: any, file:TFile):string[] => { const values = Array.from(field.values()) //List of links values - .filter((l:any)=>l?.type && (l.type === "file" || l.type === "header")) + .filter((l:any)=>l?.type && (l.type === "file" || l.type === "header" || l.type=="block")) .forEach((l:any)=>{ const path = getPathOrSelf(app, l.path,file.path); if(path) { diff --git a/versions.json b/versions.json index 7f3db7d..31e9dc2 100644 --- a/versions.json +++ b/versions.json @@ -1,5 +1,5 @@ { - "0.1.4": "0.15.5", + "0.1.6": "0.15.5", "0.1.3": "0.15.3", "0.1.0": "0.15.2", "0.0.22": "0.14.0"