Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

this code very faster #539

Draft
wants to merge 55 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
8b312ac
rusty breadcrumbs
mProjectsCode Apr 26, 2024
8d01fe0
working graph building; mermaid
mProjectsCode Apr 27, 2024
f822607
minor changes
mProjectsCode Apr 27, 2024
de02fb4
progress on tree view
mProjectsCode Apr 28, 2024
563bde6
edge sorting
mProjectsCode Apr 29, 2024
f18ee4f
fix list index
mProjectsCode Apr 29, 2024
583ff36
fix edge link class
mProjectsCode Apr 29, 2024
e12f0e1
Builders accumulate GraphConstructionData immediately, instead of int…
SkepticMystic Apr 29, 2024
f77c813
Merge branch 'master' into mProjectsCode/master
SkepticMystic Apr 29, 2024
4002de3
Merge pull request #1 from SkepticMystic/mProjectsCode/master
mProjectsCode Apr 29, 2024
6eb258e
first half of mermaid options
mProjectsCode Apr 29, 2024
c127789
Merge branch 'master' of https://github.com/mProjectsCode/breadcrumbs
mProjectsCode Apr 29, 2024
2233557
mermaid code block collapse edge option
mProjectsCode Apr 29, 2024
ad0aca8
split up rust code
mProjectsCode May 1, 2024
dac9130
traversal options
mProjectsCode May 1, 2024
e67b4ba
fix more views
mProjectsCode May 1, 2024
fcd533b
it kind of works
mProjectsCode May 2, 2024
dd6029a
fix traversal bug with trail view
mProjectsCode May 2, 2024
7d62722
fix more trail view things
mProjectsCode May 2, 2024
c47575f
fix more bugs
mProjectsCode May 2, 2024
f895f71
rust performance improvements due to vector based set
mProjectsCode May 2, 2024
062194d
fix lot's of clippy lint issues
mProjectsCode May 2, 2024
5ba7883
fixes; rust sorting; settings rule previews
mProjectsCode May 3, 2024
ea2e5f5
better sorting
mProjectsCode May 4, 2024
8452bf8
fix(command:threading): Reimplement
SkepticMystic May 7, 2024
6e764b1
Merge pull request #2 from mProjectsCode/mProjectsCode/master
SkepticMystic May 7, 2024
8a89247
fix(builders): Swap source and target when creating GraphConstruction…
SkepticMystic May 7, 2024
0262bcd
fix(builders): Rather push an error than show a notice if Dataview is…
SkepticMystic May 7, 2024
8dfd92c
test: Delete irrelevant TS tests
SkepticMystic May 7, 2024
7fbfb31
fix: Edge sort field is neighbour-field, not neighbour
SkepticMystic May 7, 2024
aa91e86
Reimplement trim_lone_param in get_attribute_label
SkepticMystic May 7, 2024
bbe3913
Merge pull request #3 from mProjectsCode/mProjectsCode/master
SkepticMystic May 7, 2024
ea00553
Merge branch 'master' into master
SkepticMystic May 7, 2024
a7f662f
Remove some old TODOs + Add (RUST) label to existing ones
SkepticMystic May 7, 2024
5568e84
fix: Resolve merge-conflict conflicts
SkepticMystic May 7, 2024
2f2179f
wasm logging; rust script in package json
mProjectsCode May 7, 2024
1e9ce56
Merge branch 'master' of https://github.com/mProjectsCode/breadcrumbs
mProjectsCode May 7, 2024
0596d96
adress some todos
mProjectsCode May 7, 2024
523793b
more minor fixes
mProjectsCode May 7, 2024
73eb309
refactor: TraversalOptions.fields being undefined is the same as allo…
SkepticMystic May 8, 2024
b1dc8bc
fix review comments
mProjectsCode May 8, 2024
33199aa
feat: Implement basic flatten rec_traversal_data func + switch to bre…
SkepticMystic May 9, 2024
b2b8526
Merge branch 'master' of https://github.com/mProjectsCode/breadcrumbs
SkepticMystic May 9, 2024
62678a7
Reimplement `flat` option on CodeblockTree
SkepticMystic May 9, 2024
25e118b
make clippy happy; work on todos
mProjectsCode May 10, 2024
134eda2
mermaid edge sorting
mProjectsCode May 10, 2024
8f3ec65
Update src/components/side_views/MatrixEdgeField.svelte
mProjectsCode May 13, 2024
1909ecb
Update wasm/src/graph_mermaid.rs
mProjectsCode May 13, 2024
52f6b2f
performance improvements to views
mProjectsCode May 15, 2024
aecbf93
some small improvements
mProjectsCode May 25, 2024
d668311
do node stringification in rust
mProjectsCode May 27, 2024
1932175
fix error, add debounce
mProjectsCode May 27, 2024
6ba43c5
update graph on vault events and code cleanup
mProjectsCode Dec 15, 2024
bcdcd55
change update flow
mProjectsCode Dec 20, 2024
62c2653
more cleanup; improve EdgeStruct perf
mProjectsCode Dec 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions src/commands/list_index/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { EdgeSortId } from "src/const/graph";
import type { BCGraph, EdgeAttribute } from "src/graph/MyMultiGraph";
import type { EdgeAttribute } from "src/graph/MyMultiGraph";
import { Traverse, type EdgeTree } from "src/graph/traverse";
import {
get_edge_sorter,
Expand All @@ -11,6 +11,7 @@ import type { ShowNodeOptions } from "src/interfaces/settings";
import { Links } from "src/utils/links";
import { untyped_pick } from "src/utils/objects";
import { url_search_params } from "src/utils/url";
import type { NoteGraph, RecTraversalData } from "wasm/pkg/breadcrumbs_graph_wasm";

export namespace ListIndex {
export type Options = {
Expand Down Expand Up @@ -44,7 +45,7 @@ export namespace ListIndex {
};

export const edge_tree_to_list_index = (
tree: EdgeTree[],
tree: RecTraversalData[],
options: Pick<
Options,
"link_kind" | "indent" | "show_node_options" | "show_attributes"
Expand All @@ -53,21 +54,23 @@ export namespace ListIndex {
let index = "";
const real_indent = options.indent.replace(/\\t/g, "\t");

tree.forEach(({ children, depth, edge }) => {
const display = stringify_node(edge.target_id, edge.target_attr, {
tree.forEach(({ children, depth, edge, node }) => {
mProjectsCode marked this conversation as resolved.
Show resolved Hide resolved
const display = stringify_node(node, {
show_node_options: options.show_node_options,
});

const link = Links.ify(edge.target_id, display, {
const link = Links.ify(node.path, display, {
link_kind: options.link_kind,
});

const attr = options.show_attributes.length
? ` (${url_search_params(
untyped_pick(edge.attr, options.show_attributes),
{ trim_lone_param: true },
)})`
: "";
// TODO: show_attributes
// const attr = options.show_attributes.length
// ? ` (${url_search_params(
// untyped_pick(edge.attr, options.show_attributes),
// { trim_lone_param: true },
// )})`
// : "";
const attr = "";

index += real_indent.repeat(depth) + `- ${link}${attr}\n`;

Expand All @@ -77,8 +80,9 @@ export namespace ListIndex {
return index;
};

// TODO
export const build = (
graph: BCGraph,
graph: NoteGraph,
start_node: string,
options: Options,
) =>
Expand Down
14 changes: 8 additions & 6 deletions src/components/EdgeLink.svelte
mProjectsCode marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
import { stringify_node } from "src/graph/utils";
import type { ShowNodeOptions } from "src/interfaces/settings";
import BreadcrumbsPlugin from "src/main";
import type { EdgeData, NodeData } from "wasm/pkg/breadcrumbs_graph_wasm";

export let edge: Pick<BCEdge, "attr" | "target_id" | "target_attr">;
export let edge: EdgeData;
export let target_node: NodeData;
export let plugin: BreadcrumbsPlugin;
export let show_node_options: ShowNodeOptions;
export let cls = "";

const { dendron_note } = plugin.settings.explicit_edge_sources;

const display = stringify_node(edge.target_id, edge.target_attr, {
const display = stringify_node(target_node, {
show_node_options,
trim_basename_delimiter:
dendron_note.enabled && dendron_note.display_trimmed
Expand All @@ -24,9 +26,9 @@
<ObsidianLink
{plugin}
{display}
path={edge.target_id}
resolved={edge.target_attr.resolved}
cls="{cls} BC-edge {edge.attr.explicit
path={target_node.path}
resolved={target_node.resolved}
cls="{cls} BC-edge {edge.implied
? 'BC-edge-explicit'
: `BC-edge-implied BC-edge-implied-${edge.attr.implied_kind}`}"
: `BC-edge-implied BC-edge-implied-${ 'transitive' /*edge.attr.implied_kind */}`}"
mProjectsCode marked this conversation as resolved.
Show resolved Hide resolved
/>
13 changes: 8 additions & 5 deletions src/components/NestedEdgeList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
import EdgeLink from "./EdgeLink.svelte";
import ChevronOpener from "./button/ChevronOpener.svelte";
import TreeItemFlair from "./obsidian/TreeItemFlair.svelte";
import type { RecTraversalData } from "wasm/pkg/breadcrumbs_graph_wasm";

export let plugin: BreadcrumbsPlugin;

export let tree: EdgeTree[];
export let tree: RecTraversalData[];

export let open_signal: boolean | null;
export let show_node_options: ShowNodeOptions;
Expand All @@ -30,8 +31,8 @@
open_signal = null;
}
</script>

{#each tree.sort((a, b) => sort(a.edge, b.edge)) as item, i}
<!-- TODO add sorting using the edge sorter -->
SkepticMystic marked this conversation as resolved.
Show resolved Hide resolved
{#each tree as item, i}
<details class="tree-item" bind:open={opens[i]}>
<summary class="tree-item-self is-clickable flex items-center">
{#if item.children.length}
Expand All @@ -44,19 +45,21 @@
<EdgeLink
{plugin}
edge={item.edge}
target_node={item.node}
{show_node_options}
cls="tree-item-inner-text"
/>
</div>

{#if show_attributes?.length}
<!-- TODO -->
<!-- {#if show_attributes?.length}
<TreeItemFlair
label={url_search_params(
untyped_pick(item.edge.attr, show_attributes),
{ trim_lone_param: true },
)}
/>
{/if}
{/if} -->
</summary>

{#if item.children.length}
Expand Down
6 changes: 4 additions & 2 deletions src/components/codeblocks/CodeblockMermaid.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
mermaid = plugin.graph.generate_mermaid_graph([file_path], options.fields ?? [], options.depth[1] ?? 100).mermaid;
};

update();

onMount(() => {
update();
});

// const sort = get_edge_sorter(
// // @ts-expect-error: ts(2345)
// options.sort,
Expand Down
107 changes: 60 additions & 47 deletions src/components/codeblocks/CodeblockTree.svelte
mProjectsCode marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import NestedEdgeList from "../NestedEdgeList.svelte";
import CopyToClipboardButton from "../button/CopyToClipboardButton.svelte";
import CodeblockErrors from "./CodeblockErrors.svelte";
import type { RecTraversalData } from "wasm/pkg/breadcrumbs_graph_wasm";

export let plugin: BreadcrumbsPlugin;
export let options: ICodeblock["Options"];
Expand All @@ -27,59 +28,71 @@
);
const { show_node_options } = plugin.settings.views.codeblocks;

let tree: EdgeTree[] = [];
let tree: RecTraversalData[] = [];

// if the file_path is an empty string, so the code block is not rendered inside note, we fall back to the active file store
$: source_path = file_path
? file_path
: $active_file_store
? $active_file_store.path
: "";

// this is an exposed function that we can call from the outside to update the codeblock
export const update = () => {
tree = get_tree();
tree = plugin.graph.rec_traverse(
file_path,
options.fields ?? [],
options.depth[1] ?? 100,
);
};

const base_traversal = (attr: EdgeAttrFilters) =>
Traverse.build_tree(
plugin.graph,
source_path,
{ max_depth: options.depth[1] },
(e) =>
has_edge_attrs(e, {
...attr,
$or_target_ids: options["dataview-from-paths"],
}),
);
onMount(() => {
update();
});

const edge_field_labels =
options.fields ?? plugin.settings.edge_fields.map((f) => f.label);

const get_tree = () => {
if (source_path && plugin.graph.hasNode(source_path)) {
const traversal = options["merge-fields"]
? base_traversal({ $or_fields: options.fields })
: edge_field_labels.flatMap((field) =>
base_traversal({ field }),
);

// NOTE: The flattening is done here so that:
// - We can use NestedEdgeList for both modes
// - ListIndex builds from an EdgeTree[] as well
return options.flat
? Traverse.flatten_tree(traversal).map((item) => ({
depth: 0,
children: [],
edge: item.edge,
}))
: traversal;
} else {
return [];
}
};
// // if the file_path is an empty string, so the code block is not rendered inside note, we fall back to the active file store
// $: source_path = file_path
// ? file_path
// : $active_file_store
// ? $active_file_store.path
// : "";

// // this is an exposed function that we can call from the outside to update the codeblock
// export const update = () => {
// tree = get_tree();
// };

// const base_traversal = (attr: EdgeAttrFilters) =>
// Traverse.build_tree(
// plugin.graph,
// source_path,
// { max_depth: options.depth[1] },
// (e) =>
// has_edge_attrs(e, {
// ...attr,
// $or_target_ids: options["dataview-from-paths"],
// }),
// );

// const edge_field_labels =
// options.fields ?? plugin.settings.edge_fields.map((f) => f.label);

// const get_tree = () => {
// if (source_path && plugin.graph.hasNode(source_path)) {
// const traversal = options["merge-fields"]
// ? base_traversal({ $or_fields: options.fields })
// : edge_field_labels.flatMap((field) =>
// base_traversal({ field }),
// );

// // NOTE: The flattening is done here so that:
// // - We can use NestedEdgeList for both modes
// // - ListIndex builds from an EdgeTree[] as well
// return options.flat
// ? Traverse.flatten_tree(traversal).map((item) => ({
// depth: 0,
// children: [],
// edge: item.edge,
// }))
// : traversal;
// } else {
// return [];
// }
// };

onMount(update);
// onMount(update);
</script>

<div class="BC-codeblock-tree">
Expand Down
15 changes: 8 additions & 7 deletions src/graph/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,34 @@ import { Paths } from "src/utils/paths";
import type {
BCEdge,
BCEdgeAttributes,
BCGraph,
BCNodeAttributes,
} from "./MyMultiGraph";
import type { NodeData } from "wasm/pkg/breadcrumbs_graph_wasm";

export const is_self_loop = (edge: Pick<BCEdge, "source_id" | "target_id">) =>
edge.source_id === edge.target_id;

export const stringify_node = (
node_id: string,
node_attr: BCNodeAttributes,
node: NodeData,
options?: {
show_node_options?: ShowNodeOptions;
trim_basename_delimiter?: string;
},
) => {
if (options?.show_node_options?.alias && node_attr.aliases?.length) {
return node_attr.aliases.at(0)!;
if (options?.show_node_options?.alias && node.aliases?.length) {
return node.aliases.at(0)!;
} else if (options?.trim_basename_delimiter) {
return Paths.drop_ext(node_id)
return Paths.drop_ext(node.path)
.split("/")
.pop()!
.split(options.trim_basename_delimiter)
.last()!;
} else {
return Paths.show(node_id, options?.show_node_options);
return Paths.show(node.path, options?.show_node_options);
}
};

// UNUSED
export const stringify_edge = (
edge: BCEdge,
options?: {
Expand Down
Loading