Skip to content

Commit

Permalink
feat(impliedRelations): ✨ New optional impliedRelation: Siblings' par…
Browse files Browse the repository at this point in the history
…ent is your parent (#301)
  • Loading branch information
SkepticMystic committed Feb 5, 2022
1 parent 73f90b1 commit 2a92f6d
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 5 deletions.
48 changes: 44 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3251,7 +3251,14 @@ const blankRealNImplied = () => {
prev: { reals: [], implieds: [] },
};
};
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"];
const [BC_I_AUNT, BC_I_COUSIN, BC_I_SIBLING_1, BC_I_SIBLING_2, BC_I_REFLEXIVE, BC_I_PARENT,] = [
"BC-Aunt",
"BC-Cousin",
"BC-Sibling-1",
"BC-Sibling-2",
"BC-Reflexive",
"BC-Parent",
];
const [BC_FOLDER_NOTE, BC_FOLDER_NOTE_SUBFOLDERS, BC_FOLDER_NOTE_RECURSIVE, BC_TAG_NOTE, BC_TAG_NOTE_FIELD, BC_TAG_NOTE_EXACT, BC_LINK_NOTE, BC_TRAVERSE_NOTE, BC_REGEX_NOTE, BC_REGEX_NOTE_FIELD, BC_DV_NOTE, BC_DV_NOTE_FIELD, BC_IGNORE_DENDRON, BC_HIDE_TRAIL, BC_ORDER,] = [
"BC-folder-note",
"BC-folder-note-subfolders",
Expand Down Expand Up @@ -3483,6 +3490,7 @@ const DEFAULT_SETTINGS = {
siblingIdentity: false,
sameParentIsSibling: true,
siblingsSiblingIsSibling: false,
siblingsParentIsParent: false,
parentsSiblingsIsParents: false,
parentsParentsIsParent: false,
cousinsIsSibling: false,
Expand Down Expand Up @@ -35467,6 +35475,26 @@ function addSiblingsFromSameParent(g, settings) {
});
});
}
function addSiblingsParentIsParent(g) {
g.forEachNode((currN, a) => {
// Find siblings of current node
g.forEachOutEdge(currN, (k, currNAttr, s, sibling) => {
if (currNAttr.dir !== "same")
return;
// Find the parents of those siblings
g.forEachOutEdge(sibling, (k, a, s, parent) => {
const { dir, field } = a;
if (dir !== "up")
return;
addEdgeIfNot(g, currN, parent, {
dir: "up",
field,
implied: BC_I_PARENT,
});
});
});
});
}
function addAuntsUncles(g) {
g.forEachNode((currN, a) => {
// Find parents of current node
Expand Down Expand Up @@ -35533,10 +35561,12 @@ function addStructuralEquivalenceSiblings(g) {
}
function buildClosedG(plugin) {
const { mainG, settings } = plugin;
const { userHiers, impliedRelations: { sameParentIsSibling, parentsSiblingsIsParents, cousinsIsSibling, siblingsSiblingIsSibling, }, } = settings;
const { userHiers, impliedRelations: { sameParentIsSibling, parentsSiblingsIsParents, cousinsIsSibling, siblingsSiblingIsSibling, siblingsParentIsParent, }, } = settings;
let closedG = getReflexiveClosure(mainG, userHiers);
if (sameParentIsSibling)
addSiblingsFromSameParent(closedG, settings);
if (siblingsParentIsParent)
addSiblingsParentIsParent(closedG);
if (parentsSiblingsIsParents)
addAuntsUncles(closedG);
if (cousinsIsSibling)
Expand Down Expand Up @@ -39315,7 +39345,7 @@ function addRelationSettings(plugin, containerEl) {
// null
// );
relationDetails.createEl("p", {
text: "Here you can toggle on/off different types 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`.",
text: "Here you can toggle on/off different types 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 relation, so you can style them differently. For example `.BC-Aunt`.",
});
new obsidian.Setting(relationDetails)
.setName("Same Parent is Siblings")
Expand All @@ -39337,6 +39367,16 @@ function addRelationSettings(plugin, containerEl) {
await plugin.saveSettings();
await refreshIndex(plugin);
}));
new obsidian.Setting(relationDetails)
.setName("Siblings' Parent is Parent")
.setDesc("Your siblings' parents are your parents")
.addToggle((tg) => tg
.setValue(settings.impliedRelations.siblingsParentIsParent)
.onChange(async (val) => {
settings.impliedRelations.siblingsParentIsParent = val;
await plugin.saveSettings();
await refreshIndex(plugin);
}));
new obsidian.Setting(relationDetails)
.setName("Aunt/Uncle")
.setDesc("Treat your parent's siblings as your parents (aunts/uncles)")
Expand Down Expand Up @@ -39672,7 +39712,7 @@ function addVisModalSettings(plugin, viewDetails) {
const visModalDetails = subDetails("Visualisation Modal", viewDetails);
new obsidian.Setting(visModalDetails)
.setName("Default Visualisation Type")
.setDesc("Which visualisation to show by defualt")
.setDesc("Which visualisation to show by default")
.addDropdown((cb) => {
VISTYPES.forEach((option) => {
cb.addOption(option, option);
Expand Down
13 changes: 13 additions & 0 deletions src/Settings/RelationSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ export function addRelationSettings(
})
);

new Setting(relationDetails)
.setName("Siblings' Parent is Parent")
.setDesc("Your siblings' parents are your parents")
.addToggle((tg) =>
tg
.setValue(settings.impliedRelations.siblingsParentIsParent)
.onChange(async (val) => {
settings.impliedRelations.siblingsParentIsParent = val;
await plugin.saveSettings();
await refreshIndex(plugin);
})
);

new Setting(relationDetails)
.setName("Aunt/Uncle")
.setDesc("Treat your parent's siblings as your parents (aunts/uncles)")
Expand Down
11 changes: 10 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,15 @@ export const [
BC_I_SIBLING_1,
BC_I_SIBLING_2,
BC_I_REFLEXIVE,
] = ["BC-Aunt", "BC-Cousin", "BC-Sibling-1", "BC-Sibling-2", "BC-Reflexive"];
BC_I_PARENT,
] = [
"BC-Aunt",
"BC-Cousin",
"BC-Sibling-1",
"BC-Sibling-2",
"BC-Reflexive",
"BC-Parent",
];

export const [
BC_FOLDER_NOTE,
Expand Down Expand Up @@ -388,6 +396,7 @@ export const DEFAULT_SETTINGS: BCSettings = {
siblingIdentity: false,
sameParentIsSibling: true,
siblingsSiblingIsSibling: false,
siblingsParentIsParent: false,
parentsSiblingsIsParents: false,
parentsParentsIsParent: false,
cousinsIsSibling: false,
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export interface BCSettings {
sameParentIsSibling: boolean;
/** Traverse siblings horizontally to make all siblings siblings of each other */
siblingsSiblingIsSibling: boolean;
/** Your siblings' parents are your parents */
siblingsParentIsParent: boolean;
/** Aunt and Uncle */
parentsSiblingsIsParents: boolean;
/** Grandparents */
Expand Down
23 changes: 23 additions & 0 deletions src/refreshIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
BC_FOLDER_NOTE,
BC_I_AUNT,
BC_I_COUSIN,
BC_I_PARENT,
BC_I_SIBLING_1,
BC_I_SIBLING_2,
BC_LINK_NOTE,
Expand Down Expand Up @@ -330,6 +331,26 @@ function addSiblingsFromSameParent(g: MultiGraph, settings: BCSettings) {
});
}

function addSiblingsParentIsParent(g: MultiGraph) {
g.forEachNode((currN, a) => {
// Find siblings of current node
g.forEachOutEdge(currN, (k, currNAttr, s, sibling) => {
if (currNAttr.dir !== "same") return;
// Find the parents of those siblings
g.forEachOutEdge(sibling, (k, a, s, parent) => {
const { dir, field } = a;
if (dir !== "up") return;

addEdgeIfNot(g, currN, parent, {
dir: "up",
field,
implied: BC_I_PARENT,
});
});
});
});
}

// Transitive closure of siblings
function addSiblingsFromSiblings(g: MultiGraph) {}

Expand Down Expand Up @@ -404,11 +425,13 @@ export function buildClosedG(plugin: BCPlugin) {
parentsSiblingsIsParents,
cousinsIsSibling,
siblingsSiblingIsSibling,
siblingsParentIsParent,
},
} = settings;
let closedG = getReflexiveClosure(mainG, userHiers);

if (sameParentIsSibling) addSiblingsFromSameParent(closedG, settings);
if (siblingsParentIsParent) addSiblingsParentIsParent(closedG);
if (parentsSiblingsIsParents) addAuntsUncles(closedG);
if (cousinsIsSibling) addCousins(closedG);
if (siblingsSiblingIsSibling) addStructuralEquivalenceSiblings(closedG);
Expand Down

0 comments on commit 2a92f6d

Please sign in to comment.