* Updates Dependencies
* Uses webpack to bundle runtime library into a single file * Inject the entire file into the Debugee * Register runtime helpers (hediet_dbgVis)
This commit is contained in:
45
data-extraction/src/js/helpers/createGraphFromPointers.ts
Normal file
45
data-extraction/src/js/helpers/createGraphFromPointers.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { EdgeGraphData, NodeGraphData, CommonDataTypes } from "../..";
|
||||
import { createGraph } from ".";
|
||||
|
||||
/**
|
||||
* Given a labeled list of roots, it creates a graph by following their edges recursively.
|
||||
* Tracks cycles.
|
||||
*/
|
||||
export function createGraphFromPointers<T>(
|
||||
roots: Record<string, T | undefined | null>,
|
||||
infoSelector: (
|
||||
item: T
|
||||
) => {
|
||||
id?: string | number;
|
||||
edges: ({ to: T } & Omit<EdgeGraphData, "from" | "to">)[];
|
||||
} & Omit<NodeGraphData, "id">
|
||||
): CommonDataTypes.Graph {
|
||||
const marker = {};
|
||||
|
||||
interface Pointer {
|
||||
marker: {};
|
||||
name: string;
|
||||
value: T | null | undefined;
|
||||
}
|
||||
|
||||
const items = Object.entries(roots).map<Pointer>(([name, value]) => ({
|
||||
marker,
|
||||
name,
|
||||
value,
|
||||
}));
|
||||
|
||||
return createGraph<T | Pointer>(items, item => {
|
||||
if ("marker" in item && item["marker"] === marker) {
|
||||
return {
|
||||
id: "label____" + item.name,
|
||||
color: "orange",
|
||||
label: item.name,
|
||||
edges: [{ to: item.value!, color: "orange", label: "" }].filter(
|
||||
t => !!t.to
|
||||
),
|
||||
};
|
||||
} else {
|
||||
return infoSelector(item as T);
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user