Skip to content

Commit

Permalink
feat(impliedRelations): ✨ Multiple new implied relationship types, ea…
Browse files Browse the repository at this point in the history
…ch with their own toggle
  • Loading branch information
SkepticMystic committed Jan 19, 2022
1 parent 3602261 commit 43260b3
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 166 deletions.
209 changes: 77 additions & 132 deletions main.js

Large diffs are not rendered by default.

46 changes: 32 additions & 14 deletions src/BreadcrumbsSettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,47 +73,65 @@ export class BCSettingTab extends PluginSettingTab {
});

const relationDetails = details("Relationships");
// const mermtest = relationDetails.createDiv({ text: "test" });

// MarkdownRenderer.renderMarkdown(
// "```mermaid\nflowchart BT\nMe -->|up| Dad\nDad -->|same| Aunt\nMe -->|up| Aunt\n```",
// mermtest,
// containerEl,
// "",
// null
// );

relationDetails.createEl("p", {text: 'Here you can toggle on/off different ypes of implied relationships. All of your explicit (real) relationships will still show, but you can choose which implied ones get filled in.\nAll implied relationships are given a CSS class of the type of implied relaiton, so you can style the differently. For example `.BC-Aunt`.'})

new Setting(relationDetails)
.setName("Aunt/Uncle")
.setDesc("Treat your parent's siblings as your parents (aunts/uncles)")
.setName("Same Parent is Siblings")
.setDesc(
"If one note shares a parent with another, treat them as siblings"
)
.addToggle((tg) =>
tg
.setValue(settings.impliedRelations.parentsSiblingsIsParents)
.setValue(settings.impliedRelations.sameParentIsSibling)
.onChange(async (val) => {
settings.impliedRelations.parentsSiblingsIsParents = val;
settings.impliedRelations.sameParentIsSibling = val;
await plugin.saveSettings();
await refreshIndex(plugin);
})
);
new Setting(relationDetails)
.setName("Cousins")
.setDesc("Treat your cousins as siblings")
.setName("Siblings' Siblings")
.setDesc("Treat your siblings' siblings as your siblings")
.addToggle((tg) =>
tg
.setValue(settings.impliedRelations.cousinsIsSibling)
.setValue(settings.impliedRelations.siblingsSiblingIsSibling)
.onChange(async (val) => {
settings.impliedRelations.cousinsIsSibling = val;
settings.impliedRelations.siblingsSiblingIsSibling = val;
await plugin.saveSettings();
await refreshIndex(plugin);
})
);

new Setting(relationDetails)
.setName("Siblings' Siblings")
.setDesc("Treat your siblings' siblings as your siblings")
.setName("Aunt/Uncle")
.setDesc("Treat your parent's siblings as your parents (aunts/uncles)")
.addToggle((tg) =>
tg
.setValue(settings.impliedRelations.siblingsSiblingIsSibling)
.setValue(settings.impliedRelations.parentsSiblingsIsParents)
.onChange(async (val) => {
settings.impliedRelations.siblingsSiblingIsSibling = val;
settings.impliedRelations.parentsSiblingsIsParents = val;
await plugin.saveSettings();
await refreshIndex(plugin);
})
);
new Setting(relationDetails)
.setName("Cousins")
.setDesc(
"Treat the cousins of a note as siblings (parents' siblings' children are cousins)"
)
.addToggle((tg) =>
tg
.setValue(settings.impliedRelations.cousinsIsSibling)
.onChange(async (val) => {
settings.impliedRelations.cousinsIsSibling = val;
await plugin.saveSettings();
await refreshIndex(plugin);
})
Expand Down
8 changes: 4 additions & 4 deletions src/Components/Lists.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@

<ol>
{#each square.realItems as realItem}
<li class={realItem.implied ?? ""}>
<li>
<div
class={realItem.cls}
class="{realItem.cls} {realItem.implied ?? ''}"
on:click={async (e) => openOrSwitch(app, realItem.to, e)}
on:mouseover={(e) =>
hoverPreview(e, matrixView, realItem.to)}
Expand All @@ -66,10 +66,10 @@
class="BC-Implied {treatCurrNodeAsImpliedSibling &&
impliedItem.to === currFile.basename
? 'BC-active-note'
: ''} {impliedItem.implied ?? ''}"
: ''}"
>
<div
class={impliedItem.cls}
class="{impliedItem.cls} {impliedItem.implied ?? ''}"
on:click={async (e) =>
openOrSwitch(app, impliedItem.to, e)}
on:mouseover={(e) =>
Expand Down
8 changes: 4 additions & 4 deletions src/Components/Matrix.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
{#if square.realItems.length}
<ol>
{#each square.realItems as realItem}
<li class={realItem.implied ?? ""}>
<li>
<div
class={realItem.cls}
class="{realItem.cls} {realItem.implied ?? ''}"
on:click={async (e) => openOrSwitch(app, realItem.to, e)}
on:mouseover={(event) =>
hoverPreview(event, matrixView, realItem.to)}
Expand All @@ -70,10 +70,10 @@
class="BC-Implied {treatCurrNodeAsImpliedSibling &&
impliedItem.to === currFile.basename
? 'BC-active-note'
: ''} {impliedItem.implied ?? ''}"
: ''}"
>
<div
class={impliedItem.cls}
class="{impliedItem.cls} {impliedItem.implied ?? ''}"
on:click={async (e) =>
openOrSwitch(app, impliedItem.to, e)}
on:mouseover={(e) =>
Expand Down
10 changes: 8 additions & 2 deletions src/Views/MatrixView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ import type {
} from "../interfaces";
import type BCPlugin from "../main";
import { refreshIndex } from "../refreshIndex";
import { getRealnImplied, linkClass, splitAndTrim } from "../sharedFunctions";
import {
getMatrixNeighbours,
getRealnImplied,
linkClass,
splitAndTrim,
} from "../sharedFunctions";

export default class MatrixView extends ItemView {
private plugin: BCPlugin;
Expand Down Expand Up @@ -124,7 +129,8 @@ export default class MatrixView extends ItemView {
if (!mainG) return [];

const { basename } = currFile;
const realsnImplieds = getRealnImplied(plugin, basename);
// const realsnImplieds = getRealnImplied(plugin, basename);
const realsnImplieds = getMatrixNeighbours(plugin, basename);

return userHiers.map((hier) => {
const filteredRealNImplied: {
Expand Down
13 changes: 7 additions & 6 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,13 @@ export const blankRealNImplied = () => {
};
};

export const [BC_I_AUNT, BC_I_COUSIN, BC_I_SIBLING_1, BC_I_SIBLING_2] = [
"BC-Aunt",
"BC-Cousin",
"BC-Sibling-1",
"BC-Sibling-2",
];
export const [
BC_I_AUNT,
BC_I_COUSIN,
BC_I_SIBLING_1,
BC_I_SIBLING_2,
BC_I_REFLEXIVE,
] = ["BC-Aunt", "BC-Cousin", "BC-Sibling-1", "BC-Sibling-2", "BC-Reflexive"];

export const [
BC_FOLDER_NOTE,
Expand Down
4 changes: 2 additions & 2 deletions src/graphUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { dfsFromNode } from "graphology-traversal";
import type { Attributes } from "graphology-types";
import { info } from "loglevel";
import type { App } from "obsidian";
import { BC_ORDER } from "./constants";
import { BC_I_REFLEXIVE, BC_ORDER } from "./constants";
// import { DIRECTIONS } from "./constants";
import type {
BCSettings,
Expand Down Expand Up @@ -101,7 +101,7 @@ export function getReflexiveClosure(
//@ts-ignore
dir: closeAsOpposite ? oppDir : dir,
field: closeAsOpposite ? oppField : field,
implied: true,
implied: BC_I_REFLEXIVE,
});
});
return copy;
Expand Down
4 changes: 2 additions & 2 deletions src/refreshIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ function addAuntsUncles(g: MultiGraph) {

addEdgeIfNot(g, currN, uncle, {
dir: "up",
// Use the starting nodes parent field
// Use the starting node's parent field
field: currEAttr.field,
implied: BC_I_AUNT,
});
Expand All @@ -385,7 +385,7 @@ function addCousins(g: MultiGraph) {
if (parentSiblingAttr.dir !== "same") return;

g.forEachOutEdge(uncle, (k, a, s, cousin) => {
if (a.dir !== "down") return;
if (a.dir !== "down" || currN === cousin) return;

addEdgeIfNot(g, currN, cousin, {
dir: "same",
Expand Down
28 changes: 28 additions & 0 deletions src/sharedFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,34 @@ export function getRealnImplied(
return realsnImplieds;
}

export function getMatrixNeighbours(plugin: BCPlugin, currNode: string) {
const { closedG } = plugin;
const { userHiers } = plugin.settings;
const neighbours = blankRealNImplied();
if (!closedG) return neighbours;

closedG.forEachEdge(currNode, (k, a, s, t) => {
const { field, dir, implied } = a as {
field: string;
dir: Directions;
implied?: string;
};

if (s === currNode) {
neighbours[dir].reals.push({ to: t, field, implied });
} else {
neighbours[getOppDir(dir)].implieds.push({
to: s,
field:
getOppFields(userHiers, field)[0] ?? fallbackOppField(field, dir),
implied,
});
}
});

return neighbours;
}

export function iterateHiers(
userHiers: UserHier[],
fn: (hier: UserHier, dir: Directions, field: string) => void
Expand Down

0 comments on commit 43260b3

Please sign in to comment.