Skip to content

Commit

Permalink
refactor(nextPrev): ♻️ Dedicated function for nextNPrev
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Jan 21, 2022
1 parent 5e17d3f commit fdc4228
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 12 deletions.
28 changes: 27 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) => {
Expand Down
51 changes: 40 additions & 11 deletions src/Views/TrailView.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<void> {
try {
const { settings, db, app } = plugin;
Expand Down Expand Up @@ -134,7 +164,7 @@ export async function drawTrail(plugin: BCPlugin): Promise<void> {
const {
next: { reals: rNext, implieds: iNext },
prev: { reals: rPrev, implieds: iPrev },
} = getRealnImplied(plugin, basename, "next");
} = getNextNPrev(plugin, basename);

// Remove duplicate implied
const next = [...rNext];
Expand Down Expand Up @@ -163,9 +193,9 @@ export async function drawTrail(plugin: BCPlugin): Promise<void> {
: "";

const elForMaxWidth =
selectorForMaxWidth !== ""
? document.querySelector(selectorForMaxWidth)
: null;
selectorForMaxWidth !== ""
? document.querySelector(selectorForMaxWidth)
: null;
const max_width = elForMaxWidth
? getComputedStyle(elForMaxWidth).getPropertyValue("max-width")
: "100%";
Expand All @@ -178,9 +208,8 @@ export async function drawTrail(plugin: BCPlugin): Promise<void> {
}`,
attr: {
style:
(mode !== "preview" ? `max-width: ${max_width};` : "") +
"margin: 0 auto;",

(mode !== "preview" ? `max-width: ${max_width};` : "") +
"margin: 0 auto;",
},
});

Expand Down
6 changes: 6 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,9 @@ export interface NodePath {
node: string;
path: string[];
}

export interface EdgeAttr {
dir: Directions;
field: string;
implied?: string;
}

0 comments on commit fdc4228

Please sign in to comment.