From 2a92f6da3ee2b51d104aae327396be6ff2511743 Mon Sep 17 00:00:00 2001 From: Ross Keenan Date: Sat, 5 Feb 2022 10:20:19 +0200 Subject: [PATCH] feat(impliedRelations): :sparkles: New optional impliedRelation: Siblings' parent is your parent (#301) --- main.js | 48 +++++++++++++++++++++++++++++--- src/Settings/RelationSettings.ts | 13 +++++++++ src/constants.ts | 11 +++++++- src/interfaces.ts | 2 ++ src/refreshIndex.ts | 23 +++++++++++++++ 5 files changed, 92 insertions(+), 5 deletions(-) diff --git a/main.js b/main.js index 789c0b0e..24a6d67d 100644 --- a/main.js +++ b/main.js @@ -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", @@ -3483,6 +3490,7 @@ const DEFAULT_SETTINGS = { siblingIdentity: false, sameParentIsSibling: true, siblingsSiblingIsSibling: false, + siblingsParentIsParent: false, parentsSiblingsIsParents: false, parentsParentsIsParent: false, cousinsIsSibling: false, @@ -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 @@ -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) @@ -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") @@ -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)") @@ -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); diff --git a/src/Settings/RelationSettings.ts b/src/Settings/RelationSettings.ts index 89d7a432..510321f3 100644 --- a/src/Settings/RelationSettings.ts +++ b/src/Settings/RelationSettings.ts @@ -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)") diff --git a/src/constants.ts b/src/constants.ts index 5d8ffa56..05fe0a75 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -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, @@ -388,6 +396,7 @@ export const DEFAULT_SETTINGS: BCSettings = { siblingIdentity: false, sameParentIsSibling: true, siblingsSiblingIsSibling: false, + siblingsParentIsParent: false, parentsSiblingsIsParents: false, parentsParentsIsParent: false, cousinsIsSibling: false, diff --git a/src/interfaces.ts b/src/interfaces.ts index 56ee9c95..095857cf 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -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 */ diff --git a/src/refreshIndex.ts b/src/refreshIndex.ts index 313fc231..8fceea76 100644 --- a/src/refreshIndex.ts +++ b/src/refreshIndex.ts @@ -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, @@ -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) {} @@ -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);