Various visualizer improvements, uses registerDebugAdapterTrackerFactory now.
This commit is contained in:
@@ -4,7 +4,7 @@ export type DataExtractionResult = {
|
||||
availableExtractors: DataExtractorInfo[];
|
||||
};
|
||||
|
||||
// is json
|
||||
// Instances must be valid json values.
|
||||
export type ExtractedData = {
|
||||
kind: Record<string, true>;
|
||||
};
|
||||
|
||||
@@ -8,23 +8,27 @@ export class AsIsDataExtractor implements DataExtractor<ExtractedData> {
|
||||
extractionCollector: ExtractionCollector<ExtractedData>,
|
||||
evalFn: <TEval>(expression: string) => TEval
|
||||
): void {
|
||||
if (typeof data === "object" && data && "kind" in data) {
|
||||
const obj = data as any;
|
||||
if (typeof obj.kind === "object" && obj.kind) {
|
||||
const areAllTrue = Object.values(obj.kind).every(
|
||||
val => val === true
|
||||
);
|
||||
if (areAllTrue) {
|
||||
extractionCollector.addExtraction({
|
||||
id: this.id,
|
||||
name: "As Is",
|
||||
priority: 500,
|
||||
extractData() {
|
||||
return obj;
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
if (typeof data !== "object" || !data || !("kind" in data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const obj = data as any;
|
||||
if (typeof obj.kind !== "object" || !obj.kind) {
|
||||
return;
|
||||
}
|
||||
|
||||
const areAllTrue = Object.values(obj.kind).every(val => val === true);
|
||||
if (!areAllTrue) {
|
||||
return;
|
||||
}
|
||||
|
||||
extractionCollector.addExtraction({
|
||||
id: this.id,
|
||||
name: "As Is",
|
||||
priority: 500,
|
||||
extractData() {
|
||||
return obj;
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,18 +10,20 @@ export class GetDebugVisualizationDataExtractor
|
||||
evalFn: <TEval>(expression: string) => TEval
|
||||
): void {
|
||||
if (
|
||||
typeof data === "object" &&
|
||||
data &&
|
||||
"getDebugVisualization" in data
|
||||
typeof data !== "object" ||
|
||||
!data ||
|
||||
!("getDebugVisualization" in data)
|
||||
) {
|
||||
extractionCollector.addExtraction({
|
||||
id: this.id,
|
||||
name: "getDebugVisualization",
|
||||
priority: 500,
|
||||
extractData() {
|
||||
return (data as any).getDebugVisualization();
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
extractionCollector.addExtraction({
|
||||
id: this.id,
|
||||
name: "Use Method 'getDebugVisualization'",
|
||||
priority: 500,
|
||||
extractData() {
|
||||
return (data as any).getDebugVisualization();
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
80
data-extraction/src/js/getClosure.ts
Normal file
80
data-extraction/src/js/getClosure.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
import { CommonDataTypes } from "../CommonDataTypes";
|
||||
|
||||
export function getClosureObj<T>(
|
||||
roots: Record<string, T | undefined | null>,
|
||||
edgeSelector: (item: T) => { item: T; edgeLabel: string }[],
|
||||
labelSelector: (item: T) => string,
|
||||
idSelector?: (item: T) => string | number
|
||||
): CommonDataTypes.GraphData {
|
||||
const items = Object.entries(roots).map(([k, v]) => v);
|
||||
return getClosure<T>(
|
||||
items.filter(i => !!i) as T[],
|
||||
edgeSelector,
|
||||
item => {
|
||||
const names = new Array<string>();
|
||||
for (const [key, val] of Object.entries(roots)) {
|
||||
if (val === item) {
|
||||
names.push(key);
|
||||
}
|
||||
}
|
||||
const base = labelSelector(item);
|
||||
return names.length === 0 ? base : `${names.join(", ")}: ${base}`;
|
||||
},
|
||||
idSelector
|
||||
);
|
||||
}
|
||||
|
||||
export function getClosure<T>(
|
||||
roots: T[],
|
||||
edgeSelector: (item: T) => { item: T; edgeLabel: string }[],
|
||||
labelSelector: (item: T) => string,
|
||||
idSelector?: (item: T) => string | number
|
||||
): CommonDataTypes.GraphData {
|
||||
const r: CommonDataTypes.GraphData = {
|
||||
kind: {
|
||||
graph: true,
|
||||
},
|
||||
nodes: [],
|
||||
edges: [],
|
||||
};
|
||||
let idCounter = 1;
|
||||
const ids = new Map<T, string>();
|
||||
function getId(item: T): string {
|
||||
if (idSelector) {
|
||||
return "" + idSelector(item);
|
||||
}
|
||||
|
||||
let id = ids.get(item);
|
||||
if (!id) {
|
||||
id = (idCounter++).toString();
|
||||
ids.set(item, id);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
const queue = new Array<T>(...roots);
|
||||
const processed = new Set<T>();
|
||||
|
||||
while (queue.length > 0) {
|
||||
const item = queue.shift()!;
|
||||
if (processed.has(item)) {
|
||||
continue;
|
||||
}
|
||||
processed.add(item);
|
||||
const edges = edgeSelector(item);
|
||||
const fromId = getId(item);
|
||||
r.nodes.push({ id: fromId, label: labelSelector(item) });
|
||||
for (const e of edges) {
|
||||
const toId = getId(e.item);
|
||||
r.edges.push({
|
||||
from: fromId,
|
||||
to: toId,
|
||||
label: e.edgeLabel,
|
||||
});
|
||||
if (!processed.has(e.item)) {
|
||||
queue.push(e.item);
|
||||
}
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from "./Extractors";
|
||||
export * from "./DataExtractor";
|
||||
export * from "./DataExtractorApi";
|
||||
export * from "./getClosure";
|
||||
|
||||
Reference in New Issue
Block a user