diff --git a/main.js b/main.js index d7120801..205cad04 100644 --- a/main.js +++ b/main.js @@ -25121,6 +25121,32 @@ function getBreadcrumbs(settings, g, currFile) { .sort((a, b) => a.length - b.length); return sortedTrails; } +function getNextNPrev(plugin, currNode) { + const { mainG } = plugin; + const { userHiers } = plugin.settings; + if (!mainG) + return null; + const nextNPrev = blankRealNImplied(); + mainG.forEachEdge(currNode, (k, a, s, t) => { + var _a; + const { dir, field, implied } = a; + if (dir !== "next" && dir !== "prev") + return; + if (s === currNode) { + nextNPrev[dir].reals.push({ field, to: t, real: true, implied }); + } + else { + const oppField = (_a = getOppFields(userHiers, field)[0]) !== null && _a !== void 0 ? _a : fallbackOppField(field, dir); + nextNPrev[getOppDir(dir)].implieds.push({ + field: oppField, + to: s, + real: false, + implied, + }); + } + }); + return nextNPrev; +} async function drawTrail(plugin) { var _a, _b, _c, _d; try { @@ -25163,7 +25189,7 @@ async function drawTrail(plugin) { const sortedTrails = getBreadcrumbs(settings, closedUp, file); loglevel.info({ sortedTrails }); const { basename } = file; - const { next: { reals: rNext, implieds: iNext }, prev: { reals: rPrev, implieds: iPrev }, } = getRealnImplied(plugin, basename, "next"); + const { next: { reals: rNext, implieds: iNext }, prev: { reals: rPrev, implieds: iPrev }, } = getNextNPrev(plugin, basename); // Remove duplicate implied const next = [...rNext]; iNext.forEach((i) => { diff --git a/src/Views/TrailView.ts b/src/Views/TrailView.ts index 07109a15..041648e4 100644 --- a/src/Views/TrailView.ts +++ b/src/Views/TrailView.ts @@ -1,21 +1,26 @@ import type { MultiGraph } from "graphology"; import { error, info } from "loglevel"; import { MarkdownView, Notice, TFile } from "obsidian"; -import type { BCSettings } from "../interfaces"; import NextPrev from "../Components/NextPrev.svelte"; import TrailGrid from "../Components/TrailGrid.svelte"; import TrailPath from "../Components/TrailPath.svelte"; -import { BC_HIDE_TRAIL, JUGGL_TRAIL_DEFAULTS } from "../constants"; +import { + BC_HIDE_TRAIL, + blankRealNImplied, + JUGGL_TRAIL_DEFAULTS, +} from "../constants"; import { bfsAllPaths, + getOppDir, getOppFields, getReflexiveClosure, getSubForFields, getSubInDirs, } from "../graphUtils"; +import type { BCSettings, EdgeAttr, RealNImplied } from "../interfaces"; import type BCPlugin from "../main"; -import { getFields, getRealnImplied } from "../sharedFunctions"; -import {createJugglTrail} from "../Visualisations/Juggl"; +import { fallbackOppField, getFields } from "../sharedFunctions"; +import { createJugglTrail } from "../Visualisations/Juggl"; function getLimitedTrailSub(plugin: BCPlugin) { const { settings, mainG } = plugin; @@ -69,6 +74,31 @@ function getBreadcrumbs( return sortedTrails; } +function getNextNPrev(plugin: BCPlugin, currNode: string) { + const { mainG } = plugin; + const { userHiers } = plugin.settings; + if (!mainG) return null; + const nextNPrev: RealNImplied = blankRealNImplied(); + + mainG.forEachEdge(currNode, (k, a, s, t) => { + const { dir, field, implied } = a as EdgeAttr; + if (dir !== "next" && dir !== "prev") return; + if (s === currNode) { + nextNPrev[dir].reals.push({ field, to: t, real: true, implied }); + } else { + const oppField = + getOppFields(userHiers, field)[0] ?? fallbackOppField(field, dir); + nextNPrev[getOppDir(dir)].implieds.push({ + field: oppField, + to: s, + real: false, + implied, + }); + } + }); + return nextNPrev; +} + export async function drawTrail(plugin: BCPlugin): Promise { try { const { settings, db, app } = plugin; @@ -134,7 +164,7 @@ export async function drawTrail(plugin: BCPlugin): Promise { const { next: { reals: rNext, implieds: iNext }, prev: { reals: rPrev, implieds: iPrev }, - } = getRealnImplied(plugin, basename, "next"); + } = getNextNPrev(plugin, basename); // Remove duplicate implied const next = [...rNext]; @@ -163,9 +193,9 @@ export async function drawTrail(plugin: BCPlugin): Promise { : ""; const elForMaxWidth = - selectorForMaxWidth !== "" - ? document.querySelector(selectorForMaxWidth) - : null; + selectorForMaxWidth !== "" + ? document.querySelector(selectorForMaxWidth) + : null; const max_width = elForMaxWidth ? getComputedStyle(elForMaxWidth).getPropertyValue("max-width") : "100%"; @@ -178,9 +208,8 @@ export async function drawTrail(plugin: BCPlugin): Promise { }`, attr: { style: - (mode !== "preview" ? `max-width: ${max_width};` : "") + - "margin: 0 auto;", - + (mode !== "preview" ? `max-width: ${max_width};` : "") + + "margin: 0 auto;", }, }); diff --git a/src/interfaces.ts b/src/interfaces.ts index 9ae54a4c..88fd426e 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -322,3 +322,9 @@ export interface NodePath { node: string; path: string[]; } + +export interface EdgeAttr { + dir: Directions; + field: string; + implied?: string; +}