Skip to content

Commit

Permalink
feat: Flexibility in adjusting collections on which layout is enacted
Browse files Browse the repository at this point in the history
  • Loading branch information
HEmile committed Nov 5, 2023
1 parent b9cab84 commit d7f34de
Show file tree
Hide file tree
Showing 9 changed files with 2,205 additions and 5,300 deletions.
2,637 changes: 0 additions & 2,637 deletions docs/obsidian.css

This file was deleted.

4,761 changes: 2,127 additions & 2,634 deletions docs/publish.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export const DefaultJugglSettings: IJugglPluginSettings = {
autoZoom: false,
coreStore: OBSIDIAN_STORE_NAME,
expandInitial: true,
fdgdLayout: 'd3-force',
fdgdLayout: 'cola',
filter: '',
height: '100%',
hoverEdges: false,
Expand Down
30 changes: 29 additions & 1 deletion src/ui/toolbar/ToolbarLocal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,21 @@
export let filterInput;
export let filterValue;
export let workspace: Workspace;
export let onDepthChange;
let depth = 1;
const minDepth = 0;
const maxDepth = 10;
filterInput = debounce(filterInput, 500, true);
const increment = function(e) {
depth = Math.min(depth + 1, maxDepth);
onDepthChange(depth);
}
const decrement = function(e) {
depth = Math.max(depth - 1, minDepth);
onDepthChange(depth);
}
</script>

<div class="cy-toolbar-section">
Expand All @@ -29,6 +42,21 @@
<ToolbarButton icon={icons.ag_workspace} onClick={workspaceModeClick} title="Workspace mode"/>
</div>
<div class="cy-toolbar-section">
<div class="juggl-inline-group">
<div class="input-group-prepend">
<button class="btn-outline-secondary btn-minus" on:click={decrement}>
-
</button>
</div>
<input class="quantity form-control" id="depth" min="0" max="10" value={depth} type="number">
<div class="input-group-append">
<button class="btn-outline-secondary btn-plus" on:click={increment}>
+
</button>
</div>
</div>
<HelpButton {workspace}/>
</div>
<br /><label for="ag-filter">Filter: </label><input type="text" id="ag-filter" name="ag-filter" on:input={filterInput} value={filterValue}>


<br /><input type="text" id="ag-filter" name="ag-filter" on:input={filterInput} value={filterValue}>
26 changes: 13 additions & 13 deletions src/viz/layout-settings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {Layouts} from 'cytoscape';
import type {Collection, Layouts} from 'cytoscape';
import {
CLASS_ACTIVE_NODE, CLASS_EXPANDED,
DISCRETE_LAYOUT_ANIMATION_TIME,
Expand Down Expand Up @@ -34,8 +34,8 @@ export class ColaGlobalLayout implements LayoutSettings {
this.options = Object.assign({}, ColaGlobalLayout.DEFAULT, options, {animate: animate ? 'end' : false});
}

startLayout(view: IJuggl): Layouts {
return view.viz.layout(this.options).start();
startLayout(collection: Collection): Layouts {
return collection.layout(this.options).start();
}
}

Expand All @@ -44,8 +44,8 @@ export class D3GlobalLayout implements LayoutSettings {
constructor(options?: LayoutOptions, animate?: boolean) {
this.options = Object.assign({}, D3GlobalLayout.DEFAULT, options, {animate: animate ? 'end' : false});
}
startLayout(view: IJuggl): Layouts {
return view.viz.layout(Object.assign(this.options, {linkId: function id(d: any) {
startLayout(collection: Collection): Layouts {
return collection.layout(Object.assign(this.options, {linkId: function id(d: any) {
return d.id;
}, // sets the node id accessor to the specified function
})).start();
Expand Down Expand Up @@ -95,8 +95,8 @@ export class GridGlobalLayout implements LayoutSettings {
constructor(options?: LayoutOptions) {
this.options = Object.assign({}, GridGlobalLayout.DEFAULT, options);
}
startLayout(view: IJuggl): Layouts {
return view.viz.layout(this.options).start();
startLayout(collection: Collection): Layouts {
return collection.layout(this.options).start();
}

options: LayoutOptions;
Expand All @@ -118,8 +118,8 @@ export class DagreGlobalLayout implements LayoutSettings {
constructor(options?: LayoutOptions) {
this.options = Object.assign({}, DagreGlobalLayout.DEFAULT, options);
}
startLayout(view: IJuggl): Layouts {
return view.viz.layout(this.options).start();
startLayout(collection: Collection): Layouts {
return collection.layout(this.options).start();
}
options: cytoscape.LayoutOptions;
static DEFAULT = {
Expand All @@ -141,8 +141,8 @@ export class AVSDFGlobalLayout implements LayoutSettings {
constructor(options?: LayoutOptions) {
this.options = Object.assign({}, AVSDFGlobalLayout.DEFAULT, options);
}
startLayout(view: IJuggl): Layouts {
return view.viz.layout( this.options).start();
startLayout(collection: Collection): Layouts {
return collection.layout( this.options).start();
}
options: cytoscape.LayoutOptions;
static DEFAULT: LayoutOptions = {
Expand All @@ -164,8 +164,8 @@ export class ConcentricLayout implements LayoutSettings {
constructor(options?: LayoutOptions) {
this.options = Object.assign({}, ConcentricLayout.DEFAULT, options);
}
startLayout(view: IJuggl): Layouts {
return view.viz.layout(Object.assign(this.options, {concentric: (n: NodeSingular) =>{
startLayout(collection: Collection): Layouts {
return collection.layout(Object.assign(this.options, {concentric: (n: NodeSingular) =>{
// @ts-ignore
if (n.hasClass(CLASS_ACTIVE_NODE)) {
return 1000;
Expand Down
16 changes: 9 additions & 7 deletions src/viz/local-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export class LocalMode extends Component implements IAGMode {
events: EventRec[] = [];
windowEvent: any;
toolbar: SvelteComponent;
depth: number = 1;
maxDepthForCurrentFile: number = 1;

constructor(view: Juggl) {
super();
this.view = view;
Expand Down Expand Up @@ -86,6 +89,11 @@ export class LocalMode extends Component implements IAGMode {
this.viz.endBatch();
}

changeDepth(depth: number) {
console.log(`changing depth to ${depth}`);

}

registerCyEvent(name: EventNames, selector: string, callback: any) {
this.events.push({eventName: name, selector: selector, event: callback});
if (selector) {
Expand Down Expand Up @@ -132,14 +140,11 @@ export class LocalMode extends Component implements IAGMode {
this.view.searchFilter(handler.target.value);
this.view.restartLayout();
},
onDepthChange: this.changeDepth,
filterValue: this.view.settings.filter,
workspace: this.view.plugin.app.workspace,
},
});
// this.view.on('vizReady', (viz) => {
// tb.$set({viz: viz});
// tb.onSelect.bind(tb)();
// });
}

updateActiveFile(node: NodeCollection) {
Expand All @@ -153,8 +158,5 @@ export class LocalMode extends Component implements IAGMode {
.connectedNodes()
.addClass(CLASS_CONNECTED_ACTIVE_NODE)
.union(node);
// this.viz.one('tap', (e) => {
// e.cy.elements().removeClass(['connected-active-file', 'active-file', 'inactive-file']);
// });
}
}
14 changes: 8 additions & 6 deletions src/viz/visualization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Workspace,
} from 'obsidian';
import cytoscape, {
Collection,
Core,
EdgeDefinition,
EdgeSingular,
Expand Down Expand Up @@ -409,9 +410,9 @@ export class Juggl extends Component implements IJuggl {
return edges;
}

async expand(toExpand: NodeCollection, batch=true, triggerGraphChanged=true): Promise<IMergedToGraph> {
async expand(toExpand: NodeCollection, batch=true, triggerGraphChanged=true): Promise<IMergedToGraph | null> {
if (toExpand.length === 0) {
return null;
return Promise.resolve(null);
}
if (batch) {
this.viz.startBatch();
Expand Down Expand Up @@ -439,8 +440,8 @@ export class Juggl extends Component implements IJuggl {
async updateStylesheet(): Promise<void> {
const sheet = new GraphStyleSheet(this.plugin);
const sSheet = await sheet.getStylesheet(this);
this.trigger('stylesheet', sheet, sSheet);
this.viz.style(sSheet);
this.trigger('stylesheet', sheet, sSheet);
}

onunload(): void {
Expand Down Expand Up @@ -493,8 +494,9 @@ export class Juggl extends Component implements IJuggl {
}
const layoutSettings = parseLayoutSettings(this.settings);
try {
this.trigger("layout", layoutSettings);
this.activeLayout = layoutSettings.startLayout(this);
const triggerS = {'layout': layoutSettings, 'collection': this.viz.elements()};
this.trigger("layout", triggerS);
this.activeLayout = layoutSettings.startLayout(triggerS.collection);
} catch (e) {
console.log(e);
}
Expand Down Expand Up @@ -640,7 +642,7 @@ export class Juggl extends Component implements IJuggl {
trigger(name: 'selectChange'): void;
trigger(name: 'elementsChange'): void;
trigger(name: 'vizReady', viz: Core): void;
trigger(name: 'layout', layout: LayoutSettings): void;
trigger(name: 'layout', layout: {layout: LayoutSettings, collection: Collection}): void;
trigger(name: string, ...data: any[]): void {
this.events.trigger(name, ...data);
}
Expand Down
17 changes: 17 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,20 @@ button.juggl-icon-button {
width: 50px;
justify-content: center;
}

.juggl-inline-group {
max-width: 9rem;
display: flex;
align-items: center;
/*padding: .5rem;*/
}

.juggl-inline-group .form-control {
text-align: right;
}

.form-control[type="number"]::-webkit-inner-spin-button,
.form-control[type="number"]::-webkit-outer-spin-button {
-webkit-appearance: none;
margin: 0;
}

0 comments on commit d7f34de

Please sign in to comment.