Skip to content

Commit

Permalink
feat: Layout type selector for Juggl view
Browse files Browse the repository at this point in the history
  • Loading branch information
HEmile committed Jan 23, 2022
1 parent 736b685 commit 4f40700
Show file tree
Hide file tree
Showing 5 changed files with 553 additions and 940 deletions.
24 changes: 23 additions & 1 deletion src/Settings/TrailSettings.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Notice, Setting } from "obsidian";
import {DropdownComponent, Notice, Setting} from "obsidian";
import { isInVault } from "obsidian-community-lib/dist/utils";
import Checkboxes from "../Components/Checkboxes.svelte";
import type BCPlugin from "../main";
import { splitAndTrim } from "../Utils/generalUtils";
import { getFields } from "../Utils/HierUtils";
import { drawTrail } from "../Views/TrailView";
import { fragWithHTML, subDetails } from "./BreadcrumbsSettingTab";
import type {JugglLayouts} from "juggl-api";

export function addTrailViewSettings(
plugin: BCPlugin,
Expand Down Expand Up @@ -257,4 +258,25 @@ export function addTrailViewSettings(
await drawTrail(plugin);
})
);

new Setting(trailDetails)
.setName("Juggl view layout")
.setDesc(
"The layout type to use for the Juggl view. " +
"The hierarchy layout is most natural for Breadcrumbs, but for large graphs D3 Force is recommended."
)
.addDropdown((dc: DropdownComponent) => {
dc.addOption("hierarchy", "Hierarchy");
dc.addOption("d3-force", "D3 Force");
dc.addOption("cola", "Cola Force");
dc.addOption("grid", "Grid");
dc.addOption("concentric", "Concentric");

dc.setValue(settings.jugglLayout);
dc.onChange(async (value) => {
settings.jugglLayout = value as JugglLayouts;
await plugin.saveSettings();
await drawTrail(plugin);
});
});
}
70 changes: 47 additions & 23 deletions src/Visualisations/Juggl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,10 @@ export function createJugglTrail(
nodesS.add(source);
const nodes = Array.from(nodesS).map((s) => s + ".md");

const argsDown = Object.assign({}, args, {layout: {
const argsDown = Object.assign({}, args);
const layout = plugin.settings.jugglLayout;
if (layout === 'hierarchy') {
argsDown.layout = {
// @ts-ignore
name: 'dagre',
animate: false,
Expand All @@ -314,15 +317,23 @@ export function createJugglTrail(
const name = VizId.fromId(id).id;
if (name in depthMapDown) {
graph._nodes[id].rank = depthMapDown[name] + 1;
}
else {
} else {
graph._nodes[id].rank = 1;
}
});
}
}});
const isFdgd = argsDown.layout === 'force-directed' || argsDown.layout === 'cola' || argsDown.layout === 'd3-force';
if (!isFdgd) {
}
}
else {
argsDown.layout = layout;
}
const isFdgd = layout === 'cola' || layout === 'd3-force';
if (isFdgd) {
// @ts-ignore
argsDown.fdgdLayout = layout;
argsDown.layout = 'force-directed';
}
else {
argsDown.autoZoom = true;
argsDown.animateLayout = false;
}
Expand Down Expand Up @@ -380,24 +391,37 @@ export function createJugglTrail(
nodes.push(source);
nodes = nodes.map((s) => s + ".md");

const argsUp = Object.assign({}, args, {layout: {
// @ts-ignore
name: 'dagre',
animate: false,
ranker: (graph) => {
Object.keys(graph._nodes).forEach((id) => {
const name = VizId.fromId(id).id;
if (name in depthMapUp) {
graph._nodes[id].rank = (maxDepthUp - depthMapUp[name]) + 1;
}
else {
graph._nodes[id].rank = 1;
}
});
const argsUp: IJugglSettings = Object.assign({}, args);

const layout = plugin.settings.jugglLayout;
if (layout === 'hierarchy') {
argsUp.layout = {
// @ts-ignore
name: 'dagre',
animate: false,
ranker: (graph) => {
Object.keys(graph._nodes).forEach((id) => {
const name = VizId.fromId(id).id;
if (name in depthMapUp) {
graph._nodes[id].rank = (maxDepthUp - depthMapUp[name]) + 1;
} else {
graph._nodes[id].rank = 1;
}
});
}
}
}});
const isFdgd = argsUp.layout === 'force-directed' || argsUp.layout === 'cola' || argsUp.layout === 'd3-force';
if (!isFdgd) {
}
else {
argsUp.layout = layout;
}
const isFdgd = layout === 'cola' || layout === 'd3-force';
console.log({argsUp, isFdgd})
if (isFdgd) {
// @ts-ignore
argsUp.fdgdLayout = layout;
argsUp.layout = 'force-directed';
}
else {
argsUp.autoZoom = true;
argsUp.animateLayout = false;
}
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ export const DEFAULT_SETTINGS: BCSettings = {
enableAlphaSort: true,
fieldSuggestor: true,
filterImpliedSiblingsOfDifferentTypes: false,
jugglLayout: 'hierarchy',
limitWriteBCCheckboxes: [],
CHECKBOX_STATES_OVERWRITTEN: false,
gridDots: false,
Expand Down
4 changes: 3 additions & 1 deletion src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
import type DucksView from "./Views/DucksView";
import type MatrixView from "./Views/MatrixView";
import type StatsView from "./Views/StatsView";
import type { IJugglSettings } from "juggl-api";
import type {IJugglSettings, JugglLayouts} from "juggl-api";

export type DebugLevel = keyof LogLevel;
export interface BCSettings {
Expand Down Expand Up @@ -51,6 +51,8 @@ export interface BCSettings {
cousinsIsSibling: boolean;
};
indexNotes: string[];
// Default layout to use for Juggl view
jugglLayout: JugglLayouts;
/** An array of fields going _up_ which **will** be shown in the trail view */
limitTrailCheckboxes: string[];
/** An array of fields in all directions which **will** get written when running `Write implied BCs to file` */
Expand Down
Loading

0 comments on commit 4f40700

Please sign in to comment.