Skip to content

Commit

Permalink
0.1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
zsviczian committed Aug 11, 2022
1 parent f063d86 commit 4d25172
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 21 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
29 changes: 27 additions & 2 deletions src/Scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -661,7 +686,7 @@ export class Scene {
this.render();
}
}

if(this.removeTimer) {
this.removeTimer();
this.removeTimer = undefined;
Expand Down
46 changes: 30 additions & 16 deletions src/graph/Layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,23 +21,37 @@ export class Layout {
for(let i=0;i<cnt;i++) res.push(state ? null : cur++);
state = !state;
});
return res;
}
return res;
}

const generateEvenLayoutVector = (pattern: number[]) => {
const res:number[] = [];
let i = 0;
for(i=columns/2;i>pattern[0];i--) res.push(null);
for(i=0;i<pattern[0];i++) res.push(i+1);
for (i=0;i<columns/2;i++) res.push(i<pattern[1]?pattern[0]+i+1:null);
return res;
}

const getRowLayout = (items: number) => 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<Node>(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<Node>(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() {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/dataview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit 4d25172

Please sign in to comment.