Skip to content

Commit

Permalink
fix(List/Matrix View): 🐛 Remove duplicate implied siblings
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Oct 4, 2021
1 parent 6e87f17 commit 0d0a187
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 120 deletions.
112 changes: 57 additions & 55 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -26415,41 +26415,8 @@ class MatrixView extends obsidian.ItemView {
});
return index;
}
async draw() {
this.contentEl.empty();
const settings = this.plugin.settings;
debugGroupStart(settings, "debugMode", "Draw Matrix/List View");
const hierGs = this.plugin.currGraphs;
const { userHierarchies } = this.plugin.settings;
const currFile = this.app.workspace.getActiveFile();
const viewToggleButton = this.contentEl.createEl("button", {
text: this.matrixQ ? "List" : "Matrix",
});
viewToggleButton.addEventListener("click", async () => {
this.matrixQ = !this.matrixQ;
viewToggleButton.innerText = this.matrixQ ? "List" : "Matrix";
await this.draw();
});
const refreshIndexButton = this.contentEl.createEl("button", {
text: "Refresh Index",
});
refreshIndexButton.addEventListener("click", async () => {
await this.plugin.refreshIndex();
});
const data = hierGs.hierGs.map((hier) => {
const hierData = {
up: undefined,
same: undefined,
down: undefined,
};
DIRECTIONS.forEach((dir) => {
// This is merging all graphs in Dir **In a particular hierarchy**, not accross all hierarchies like mergeGs(getAllGsInDir()) does
hierData[dir] = mergeGs(...Object.values(hier[dir]));
});
return hierData;
});
debug(settings, { data });
const hierSquares = userHierarchies.map((hier, i) => {
getHierSquares(userHierarchies, data, currFile, settings) {
return userHierarchies.map((hier, i) => {
var _a;
const [currUpG, currSameG, currDownG] = [
data[i].up,
Expand Down Expand Up @@ -26516,6 +26483,13 @@ class MatrixView extends obsidian.ItemView {
iUp = this.removeDuplicateImplied(rUp, iUp);
iSameArr = this.removeDuplicateImplied(rSame, iSameArr);
iDown = this.removeDuplicateImplied(rDown, iDown);
const iSameNoDup = [];
iSameArr.forEach(impSib => {
if (iSameNoDup.every(noDup => noDup.to !== impSib.to)) {
iSameNoDup.push(impSib);
}
});
iSameArr = iSameNoDup;
debug(settings, {
rUp,
iUp,
Expand Down Expand Up @@ -26547,31 +26521,59 @@ class MatrixView extends obsidian.ItemView {
};
return [upSquare, sameSquare, downSquare];
});
}
async draw() {
this.contentEl.empty();
const { settings } = this.plugin;
debugGroupStart(settings, "debugMode", "Draw Matrix/List View");
const hierGs = this.plugin.currGraphs;
const { userHierarchies } = settings;
const currFile = this.app.workspace.getActiveFile();
const viewToggleButton = this.contentEl.createEl("button", {
text: this.matrixQ ? "List" : "Matrix",
});
viewToggleButton.addEventListener("click", async () => {
this.matrixQ = !this.matrixQ;
viewToggleButton.innerText = this.matrixQ ? "List" : "Matrix";
await this.draw();
});
const refreshIndexButton = this.contentEl.createEl("button", {
text: "Refresh Index",
});
refreshIndexButton.addEventListener("click", async () => {
await this.plugin.refreshIndex();
});
const data = hierGs.hierGs.map((hier) => {
const hierData = {
up: undefined,
same: undefined,
down: undefined,
};
DIRECTIONS.forEach((dir) => {
// This is merging all graphs in Dir **In a particular hierarchy**, not accross all hierarchies like mergeGs(getAllGsInDir()) does
hierData[dir] = mergeGs(...Object.values(hier[dir]));
});
return hierData;
});
debug(settings, { data });
const hierSquares = this.getHierSquares(userHierarchies, data, currFile, settings);
debug(settings, { hierSquares });
const filteredSquaresArr = hierSquares.filter((squareArr) => squareArr.some((square) => square.realItems.length + square.impliedItems.length > 0));
const compInput = {
target: this.contentEl,
props: {
filteredSquaresArr,
currFile,
settings,
matrixView: this,
app: this.app,
},
};
if (this.matrixQ) {
this.view = new Matrix({
target: this.contentEl,
props: {
filteredSquaresArr,
currFile,
settings: settings,
matrixView: this,
app: this.app,
},
});
this.view = new Matrix(compInput);
}
else {
this.view = new Lists({
target: this.contentEl,
props: {
filteredSquaresArr,
currFile,
settings: settings,
matrixView: this,
app: this.app,
},
});
this.view = new Lists(compInput);
}
debugGroupEnd(settings, "debugMode");
}
Expand Down
135 changes: 70 additions & 65 deletions src/MatrixView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@ import { ItemView, TFile, WorkspaceLeaf } from "obsidian";
import {
DIRECTIONS,
TRAIL_ICON,
VIEW_TYPE_BREADCRUMBS_MATRIX,
VIEW_TYPE_BREADCRUMBS_MATRIX
} from "src/constants";
import type {
BreadcrumbsSettings,
Directions,
internalLinkObj,
SquareProps,
userHierarchy
} from "src/interfaces";
import type BreadcrumbsPlugin from "src/main";
import {
copy,
debug,
debugGroupEnd,
debugGroupStart,
mergeGs,
mergeGs
} from "src/sharedFunctions";
import Lists from "./Components/Lists.svelte";
import Matrix from "./Components/Matrix.svelte";
Expand Down Expand Up @@ -261,49 +262,8 @@ export default class MatrixView extends ItemView {
return index;
}

async draw(): Promise<void> {
this.contentEl.empty();

const settings = this.plugin.settings;

debugGroupStart(settings, "debugMode", "Draw Matrix/List View");

const hierGs = this.plugin.currGraphs;
const { userHierarchies } = this.plugin.settings;

const currFile = this.app.workspace.getActiveFile();

const viewToggleButton = this.contentEl.createEl("button", {
text: this.matrixQ ? "List" : "Matrix",
});
viewToggleButton.addEventListener("click", async () => {
this.matrixQ = !this.matrixQ;
viewToggleButton.innerText = this.matrixQ ? "List" : "Matrix";
await this.draw();
});

const refreshIndexButton = this.contentEl.createEl("button", {
text: "Refresh Index",
});
refreshIndexButton.addEventListener("click", async () => {
await this.plugin.refreshIndex();
});

const data = hierGs.hierGs.map((hier) => {
const hierData: { [dir in Directions]: Graph } = {
up: undefined,
same: undefined,
down: undefined,
};
DIRECTIONS.forEach((dir) => {
// This is merging all graphs in Dir **In a particular hierarchy**, not accross all hierarchies like mergeGs(getAllGsInDir()) does
hierData[dir] = mergeGs(...Object.values(hier[dir]));
});
return hierData;
});
debug(settings, { data });

const hierSquares = userHierarchies.map((hier, i) => {
getHierSquares(userHierarchies: userHierarchy[], data: { [dir in Directions]: Graph }[], currFile: TFile, settings: BreadcrumbsSettings) {
return userHierarchies.map((hier, i) => {
const [currUpG, currSameG, currDownG] = [
data[i].up,
data[i].same,
Expand Down Expand Up @@ -376,6 +336,14 @@ export default class MatrixView extends ItemView {
iSameArr = this.removeDuplicateImplied(rSame, iSameArr);
iDown = this.removeDuplicateImplied(rDown, iDown);

const iSameNoDup: internalLinkObj[] = []
iSameArr.forEach(impSib => {
if (iSameNoDup.every(noDup => noDup.to !== impSib.to)) {
iSameNoDup.push(impSib)
}
})
iSameArr = iSameNoDup

debug(settings, {
rUp,
iUp,
Expand Down Expand Up @@ -414,36 +382,73 @@ export default class MatrixView extends ItemView {

return [upSquare, sameSquare, downSquare];
});
}

async draw(): Promise<void> {
this.contentEl.empty();

const { settings } = this.plugin;

debugGroupStart(settings, "debugMode", "Draw Matrix/List View");

const hierGs = this.plugin.currGraphs;
const { userHierarchies } = settings;
const currFile = this.app.workspace.getActiveFile();

const viewToggleButton = this.contentEl.createEl("button", {
text: this.matrixQ ? "List" : "Matrix",
});
viewToggleButton.addEventListener("click", async () => {
this.matrixQ = !this.matrixQ;
viewToggleButton.innerText = this.matrixQ ? "List" : "Matrix";
await this.draw();
});

const refreshIndexButton = this.contentEl.createEl("button", {
text: "Refresh Index",
});
refreshIndexButton.addEventListener("click", async () => {
await this.plugin.refreshIndex();
});

const data = hierGs.hierGs.map((hier) => {
const hierData: { [dir in Directions]: Graph } = {
up: undefined,
same: undefined,
down: undefined,
};
DIRECTIONS.forEach((dir) => {
// This is merging all graphs in Dir **In a particular hierarchy**, not accross all hierarchies like mergeGs(getAllGsInDir()) does
hierData[dir] = mergeGs(...Object.values(hier[dir]));
});
return hierData;
});
debug(settings, { data });

const hierSquares = this.getHierSquares(userHierarchies, data, currFile, settings)
debug(settings, { hierSquares });

const filteredSquaresArr = hierSquares.filter((squareArr) =>
squareArr.some(
(square) => square.realItems.length + square.impliedItems.length > 0
)
);

const compInput = {
target: this.contentEl,
props: {
filteredSquaresArr,
currFile,
settings,
matrixView: this,
app: this.app,
},
}

if (this.matrixQ) {
this.view = new Matrix({
target: this.contentEl,
props: {
filteredSquaresArr,
currFile,
settings: settings,
matrixView: this,
app: this.app,
},
});
this.view = new Matrix(compInput);
} else {
this.view = new Lists({
target: this.contentEl,
props: {
filteredSquaresArr,
currFile,
settings: settings,
matrixView: this,
app: this.app,
},
});
this.view = new Lists(compInput);
}
debugGroupEnd(settings, "debugMode");
}
Expand Down

0 comments on commit 0d0a187

Please sign in to comment.