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 2 commits
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
3 changes: 0 additions & 3 deletions src/components/NestedEdgeList.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
<script lang="ts">
import type { EdgeAttribute } from "src/graph/MyMultiGraph";
import type { EdgeTree } from "src/graph/traverse";
import { type EdgeSorter } from "src/graph/utils";
import type { ShowNodeOptions } from "src/interfaces/settings";
import type BreadcrumbsPlugin from "src/main";
import { untyped_pick } from "src/utils/objects";
import { url_search_params } from "src/utils/url";
import EdgeLink from "./EdgeLink.svelte";
import ChevronOpener from "./button/ChevronOpener.svelte";
import TreeItemFlair from "./obsidian/TreeItemFlair.svelte";
Expand Down
17 changes: 8 additions & 9 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
@@ -1,20 +1,16 @@
<script lang="ts">
import type { ICodeblock } from "src/codeblocks/schema";
import { ListIndex } from "src/commands/list_index";
import { Traverse, type EdgeTree } from "src/graph/traverse";
import {
get_edge_sorter,
has_edge_attrs,
type EdgeAttrFilters,
} from "src/graph/utils";
import type { BreadcrumbsError } from "src/interfaces/graph";
import type BreadcrumbsPlugin from "src/main";
import { active_file_store } from "src/stores/active_file";
import { onMount } from "svelte";
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";
import { TraversalOptions, type RecTraversalData } from "wasm/pkg/breadcrumbs_graph_wasm";

export let plugin: BreadcrumbsPlugin;
export let options: ICodeblock["Options"];
Expand All @@ -31,10 +27,13 @@

export const update = () => {
tree = plugin.graph.rec_traverse(
file_path,
options.fields ?? [],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question here. Previously the fallback was []. Does your traversal treat an empty fields list as all fields allowed? Cause mine needed you to explicitly pass in the full list of fields, if that's what you wanted

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined is all fields, [] is none

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok call, I'll update my change to use undefined when necessary

options.depth[1] ?? 100,
);
new TraversalOptions(
[file_path],
options.fields,
options.depth[1] ?? 100,
!options["merge-fields"],
)
).data;
};

onMount(() => {
Expand Down
70 changes: 44 additions & 26 deletions src/components/page_views/TrailView.svelte
Original file line number Diff line number Diff line change
@@ -1,35 +1,45 @@
<script lang="ts">
import { Traverse } from "src/graph/traverse";
import { has_edge_attrs, type EdgeAttrFilters } from "src/graph/utils";
import type BreadcrumbsPlugin from "src/main";
import { remove_duplicates_by } from "src/utils/arrays";
import { remove_duplicates_by_equals } from "src/utils/arrays";
import { resolve_field_group_labels } from "src/utils/edge_fields";
import MergeFieldsButton from "../button/MergeFieldsButton.svelte";
import TrailViewGrid from "./TrailViewGrid.svelte";
import TrailViewPath from "./TrailViewPath.svelte";
import { TraversalOptions } from "wasm/pkg/breadcrumbs_graph_wasm";

export let plugin: BreadcrumbsPlugin;
export let file_path: string;

// TODO: I've copped-out here, building the view from edge_tree seems crazy hard.
// So I just use all_paths
const base_traversal = (attr: EdgeAttrFilters) =>
Traverse.tree_to_all_paths(
Traverse.build_tree(plugin.graph, file_path, {}, (e) =>
has_edge_attrs(e, attr),
),
);
// const base_traversal = (attr: EdgeAttrFilters) =>
// Traverse.tree_to_all_paths(
// Traverse.build_tree(plugin.graph, file_path, {}, (e) =>
// has_edge_attrs(e, attr),
// ),
// );

$: edge_field_labels = resolve_field_group_labels(
plugin.settings.edge_field_groups,
plugin.settings.views.page.trail.field_group_labels,
);

$: all_paths = plugin.graph.hasNode(file_path)
? plugin.settings.views.page.trail.merge_fields
? base_traversal({ $or_fields: edge_field_labels })
: edge_field_labels.flatMap((field) => base_traversal({ field }))
: [];
$: traversal_data = plugin.graph.rec_traverse(
new TraversalOptions(
[file_path],
edge_field_labels,
100,
!plugin.settings.views.page.trail.merge_fields,
),
);

$: all_paths = traversal_data.to_paths();

// $: all_paths = plugin.graph.hasNode(file_path)
// ? plugin.settings.views.page.trail.merge_fields
// ? base_traversal({ $or_fields: edge_field_labels })
// : edge_field_labels.flatMap((field) => base_traversal({ field }))
// : [];

$: selected_paths =
plugin.settings.views.page.trail.selection === "all"
Expand All @@ -38,41 +48,49 @@
? all_paths.slice(-1)
: plugin.settings.views.page.trail.selection === "longest"
? all_paths.slice(0, 1)
: [[]];
: [];
mProjectsCode marked this conversation as resolved.
Show resolved Hide resolved

$: MAX_DEPTH = Math.max(0, ...selected_paths.map((p) => p.length));
$: MAX_DEPTH = Math.max(0, ...selected_paths.map((p) => p.length()));
$: depth = Math.min(
MAX_DEPTH,
plugin.settings.views.page.trail.default_depth,
);

// Slice the paths to the chosen max depth.
$: sliced_paths = selected_paths.map((path) => path.slice(0, depth));
$: selected_paths.forEach((path) => path.truncate(depth));

// Remove duplicates by the target_ids of the path.
$: deduped_paths =
// There are no duplicates if the depth is the max depth.
// The traversal wouldn't add them in the first place.
depth === MAX_DEPTH
? sliced_paths
: remove_duplicates_by(sliced_paths, (path) =>
path.map((p) => p.target_id).join("/"),
);
? selected_paths
: remove_duplicates_by_equals(selected_paths, (a, b) => a.equals(b));

// NOTE: Only sort after slicing, so that the depth is taken into account.
$: sorted_paths = deduped_paths.sort((a, b) => {
const len_diff = b.length - a.length;
const len_diff = b.length() - a.length();

// Focus on run-length first
if (len_diff !== 0) return len_diff;
if (len_diff !== 0) {
return len_diff;
}
// Then focus on the alphabetical order of the target_ids
else return a[0].target_id.localeCompare(b[0].target_id);
else {
const a_target = a.get_first_target();
const b_target = b.get_first_target();

if (a_target === undefined && b_target === undefined) return 0;
if (a_target === undefined) return -1;
if (b_target === undefined) return 1;
else return a_target.localeCompare(b_target);
}
});
</script>

<div>
{#key sorted_paths}
{#if sorted_paths.length}
{#key traversal_data}
{#if !traversal_data.is_empty()}
<div
class="mb-1 flex flex-wrap justify-between gap-3"
class:hidden={!plugin.settings.views.page.trail.show_controls}
Expand Down
8 changes: 4 additions & 4 deletions src/components/page_views/TrailViewGrid.svelte
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<script lang="ts">
import type { BCEdge } from "src/graph/MyMultiGraph";
import type BreadcrumbsPlugin from "src/main";
import {
ensure_square_array,
gather_by_runs,
transpose,
} from "src/utils/arrays";
import EdgeLink from "../EdgeLink.svelte";
import type { Path } from "wasm/pkg/breadcrumbs_graph_wasm";

export let plugin: BreadcrumbsPlugin;
export let all_paths: BCEdge[][];
export let all_paths: Path[];

const reversed = all_paths.map((path) => [...path].reverse());
const reversed = all_paths.map((path) => path.reverse_edges);

const square = ensure_square_array(reversed, null, true);

const col_runs = transpose(square).map((col) =>
gather_by_runs(col, (e) => (e ? e.target_id : null)),
gather_by_runs(col, (e) => (e ? e.target.path : null)),
);
</script>

Expand Down
20 changes: 8 additions & 12 deletions src/components/page_views/TrailViewPath.svelte
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<script lang="ts">
import type { BCEdge } from "src/graph/MyMultiGraph";
import type BreadcrumbsPlugin from "src/main";
import EdgeLink from "../EdgeLink.svelte";
import { url_search_params } from "src/utils/url";
import { untyped_pick } from "src/utils/objects";
import type { Path } from "wasm/pkg/breadcrumbs_graph_wasm";

export let plugin: BreadcrumbsPlugin;
export let all_paths: BCEdge[][];
export let all_paths: Path[];

const reversed = all_paths.map((path) => [...path].reverse());
const reversed = all_paths.map((path) => path.reverse_edges);
</script>

<div class="BC-trail-view flex flex-col gap-1 p-1">
Expand All @@ -19,13 +17,11 @@
{#if j !== 0}
<span
class="BC-trail-view-item-separator"
aria-label={url_search_params(
untyped_pick(edge.attr, [
"source",
"implied_kind",
"round",
]),
)}
aria-label={edge.get_attribute_label([
"source",
"implied_kind",
"round",
])}
></span>
{/if}

Expand Down
41 changes: 31 additions & 10 deletions src/components/side_views/Matrix.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { get_edge_sorter, has_edge_attrs } from "src/graph/utils";
import { get_edge_sorter } from "src/graph/utils";
import type BreadcrumbsPlugin from "src/main";
import { active_file_store } from "src/stores/active_file";
import { group_by } from "src/utils/arrays";
Expand All @@ -15,6 +15,7 @@
let { edge_sort_id, field_group_labels, show_attributes } =
plugin.settings.views.side.matrix;


$: edge_field_labels = resolve_field_group_labels(
plugin.settings.edge_field_groups,
field_group_labels,
Expand All @@ -24,20 +25,40 @@
$active_file_store &&
// Even tho we ensure the graph is built before the views are registered,
// Existing views still try render before the graph is built.
plugin.graph.hasNode($active_file_store.path)
plugin.graph.has_node($active_file_store.path)
? group_by(
plugin.graph
.get_out_edges($active_file_store.path)
.filter((e) =>
has_edge_attrs(e, {
$or_fields: edge_field_labels,
}),
),
(e) => e.attr.field,
.get_outgoing_edges($active_file_store.path)
.filter((e) => e.matches_edge_filter(edge_field_labels)),
(e) => e.edge_type,
)
: null;

$: sort = get_edge_sorter(edge_sort_id, plugin.graph);
$: sort = get_edge_sorter(edge_sort_id);

// $: edge_field_labels = resolve_field_group_labels(
// plugin.settings.edge_field_groups,
// field_group_labels,
// );

// $: grouped_out_edges =
// $active_file_store &&
// // Even tho we ensure the graph is built before the views are registered,
// // Existing views still try render before the graph is built.
// plugin.graph.hasNode($active_file_store.path)
// ? group_by(
// plugin.graph
// .get_out_edges($active_file_store.path)
// .filter((e) =>
// has_edge_attrs(e, {
// $or_fields: edge_field_labels,
// }),
// ),
// (e) => e.attr.field,
// )
// : null;

// $: sort = get_edge_sorter(edge_sort_id, plugin.graph);
mProjectsCode marked this conversation as resolved.
Show resolved Hide resolved
</script>

<div class="markdown-rendered BC-matrix-view">
Expand Down
14 changes: 5 additions & 9 deletions src/components/side_views/MatrixEdgeField.svelte
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<script lang="ts">
import type { BCEdge, EdgeAttribute } from "src/graph/MyMultiGraph";
import type { EdgeAttribute } from "src/graph/MyMultiGraph";
import type { EdgeSorter } from "src/graph/utils";
import type { EdgeField } from "src/interfaces/settings";
import type BreadcrumbsPlugin from "src/main";
import { untyped_pick } from "src/utils/objects";
import { url_search_params } from "src/utils/url";
import EdgeLink from "../EdgeLink.svelte";
import ChevronOpener from "../button/ChevronOpener.svelte";
import TreeItemFlair from "../obsidian/TreeItemFlair.svelte";
import type { EdgeStruct } from "wasm/pkg/breadcrumbs_graph_wasm";

export let edges: BCEdge[];
export let edges: EdgeStruct[];
export let field: EdgeField;
export let plugin: BreadcrumbsPlugin;
// NOTE: These are available on settings, but they're modified in the parent component,
Expand Down Expand Up @@ -63,11 +62,8 @@

<TreeItemFlair
cls="font-mono"
label={edge.attr.explicit ? "x" : "i"}
aria_label={url_search_params(
untyped_pick(edge.attr, show_attributes),
{ trim_lone_param: true },
)}
label={edge.implied ? "i" : "x"}
aria_label={edge.get_attribute_label(show_attributes)}
/>
</div>
</div>
Expand Down
Loading