Skip to content

Commit

Permalink
Complete all existing implied relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Feb 3, 2024
1 parent a28eca9 commit 3d31ae5
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 6 deletions.
37 changes: 37 additions & 0 deletions src/graph/builders/implied/cousin_is_sibling.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { ImpliedEdgeBuilder } from "src/interfaces/graph";

export const _add_implied_edges_cousin_is_sibling: ImpliedEdgeBuilder = (
graph,
plugin,
) => {
plugin.settings.hierarchies.forEach((hierarchy, hierarchy_i) => {
if (!hierarchy.implied_relationships.cousin_is_sibling) {
return;
}

graph.forEachNode((source_id) => {
graph
.get_dir_chains_path(
source_id,
["up", "same", "down"],
(edge) =>
edge.attr.hierarchy_i === hierarchy_i &&
edge.attr.explicit &&
// Don't include the current source_id in the path
edge.target_id !== source_id,
)
.forEach((path) => {
console.log("path", path);
graph.addDirectedEdge(source_id, path.last()!.target_id, {
dir: "same",
hierarchy_i,
explicit: false,
implied_kind: "cousin_is_sibling",
field: hierarchy.dirs["same"].at(0) ?? null,
});
});
});
});

return {};
};
5 changes: 4 additions & 1 deletion src/graph/builders/implied/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { _add_implied_edges_parents_sibling_is_parent } from "./parents_sibling_
import { _add_implied_edges_same_parent_is_sibling } from "./same_parent_is_sibling";
import { _add_implied_edges_same_sibling_is_sibling } from "./same_sibling_is_sibling";
import { _add_implied_edges_self_is_sibling } from "./self_is_sibling";
import { _add_implied_edges_cousin_is_sibling } from "./cousin_is_sibling";
import { _add_implied_edges_siblings_parent_is_parent } from "./siblings_parent_is_parent";

// TODO: Flesh out
//@ts-expect-error
export const add_implied_edges: Record<
keyof Hierarchy["implied_relationships"],
ImpliedEdgeBuilder
Expand All @@ -17,4 +18,6 @@ export const add_implied_edges: Record<
same_parent_is_sibling: _add_implied_edges_same_parent_is_sibling,
parents_sibling_is_parent: _add_implied_edges_parents_sibling_is_parent,
same_sibling_is_sibling: _add_implied_edges_same_sibling_is_sibling,
cousin_is_sibling: _add_implied_edges_cousin_is_sibling,
siblings_parent_is_parent: _add_implied_edges_siblings_parent_is_parent,
};
39 changes: 39 additions & 0 deletions src/graph/builders/implied/siblings_parent_is_parent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import type { ImpliedEdgeBuilder } from "src/interfaces/graph";

export const _add_implied_edges_siblings_parent_is_parent: ImpliedEdgeBuilder =
(graph, plugin) => {
plugin.settings.hierarchies.forEach((hierarchy, hierarchy_i) => {
if (!hierarchy.implied_relationships.siblings_parent_is_parent) {
return;
}

graph.forEachNode((source_id) => {
graph
.get_dir_chains_path(
source_id,
["same", "up"],
(edge) =>
edge.attr.hierarchy_i === hierarchy_i &&
edge.attr.explicit &&
// Don't include the current source_id in the path
edge.target_id !== source_id,
)
.forEach((path) => {
console.log("path", path);
graph.addDirectedEdge(
source_id,
path.last()!.target_id,
{
dir: "up",
hierarchy_i,
explicit: false,
implied_kind: "siblings_parent_is_parent",
field: hierarchy.dirs["up"].at(0) ?? null,
},
);
});
});
});

return {};
};
2 changes: 1 addition & 1 deletion src/interfaces/hierarchies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export type Hierarchy = {
implied_relationships: {
self_is_sibling: boolean;
opposite_direction: boolean;
cousing_is_sibling: boolean;
cousin_is_sibling: boolean;
same_parent_is_sibling: boolean;
same_sibling_is_sibling: boolean;
siblings_parent_is_parent: boolean;
Expand Down
4 changes: 2 additions & 2 deletions src/modals/ImpliedRelationshipsSettingsModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ export class ImpliedRelationshipsSettingsModal extends Modal {
name: "Cousins",
desc: "Parents' siblings' children are siblings (cousins)",
toggle: {
value: implied_relationships.cousing_is_sibling,
value: implied_relationships.cousin_is_sibling,
cb: async (val) => {
implied_relationships.cousing_is_sibling = val;
implied_relationships.cousin_is_sibling = val;
await save();
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/settings/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const migrate_old_settings = async (plugin: BreadcrumbsPlugin) => {
...blank_hierarchy().implied_relationships,

self_is_sibling: settings.impliedRelations.siblingIdentity,
cousing_is_sibling: settings.impliedRelations.cousinsIsSibling,
cousin_is_sibling: settings.impliedRelations.cousinsIsSibling,
same_parent_is_sibling:
settings.impliedRelations.sameParentIsSibling,
same_sibling_is_sibling:
Expand Down
2 changes: 1 addition & 1 deletion src/utils/hierarchies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const blank_hierarchy = (): Hierarchy => ({
opposite_direction: true,
self_is_sibling: false,
parents_sibling_is_parent: false,
cousing_is_sibling: false,
cousin_is_sibling: false,
same_parent_is_sibling: false,
same_sibling_is_sibling: false,
siblings_parent_is_parent: false,
Expand Down
2 changes: 2 additions & 0 deletions src/utils/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import type { App } from "obsidian";
import path from "path";
import type { LinkKind } from "src/interfaces/links";

// TODO: Something seems wrong here... a new note was created in the root of the vault,
// even though it used a full path in the link content
/** Given an unresolved link path, return the absolute path of where it _would_ get created,
* given the file it would be created in
*/
Expand Down

0 comments on commit 3d31ae5

Please sign in to comment.