Implements Grid extractors/visualizer and sorting demo.
This commit is contained in:
@@ -8,7 +8,8 @@ export type CommonDataType =
|
||||
| CommonDataTypes.Tree
|
||||
| CommonDataTypes.Ast
|
||||
| CommonDataTypes.Graph
|
||||
| CommonDataTypes.Plotly;
|
||||
| CommonDataTypes.Plotly
|
||||
| CommonDataTypes.Grid;
|
||||
|
||||
export function isCommonDataType<T>(
|
||||
data: ExtractedData,
|
||||
@@ -55,6 +56,30 @@ export module CommonDataTypes {
|
||||
root: TreeNode<TData>;
|
||||
}
|
||||
|
||||
export interface Grid {
|
||||
kind: { array: true };
|
||||
columnLabels?: { label?: string }[];
|
||||
rows: {
|
||||
label?: string;
|
||||
columns: {
|
||||
content?: string;
|
||||
tag?: string;
|
||||
color?: string;
|
||||
}[];
|
||||
}[];
|
||||
markers?: {
|
||||
id: string;
|
||||
|
||||
row: number;
|
||||
column: number;
|
||||
rows?: number;
|
||||
columns?: number;
|
||||
|
||||
label?: string;
|
||||
color?: string;
|
||||
}[];
|
||||
}
|
||||
|
||||
export interface Ast
|
||||
extends Tree<{
|
||||
position: number;
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import { ExtractedData } from "../../../DataExtractionResult";
|
||||
import {
|
||||
DataExtractor,
|
||||
ExtractionCollector,
|
||||
DataExtractorContext,
|
||||
} from "../..";
|
||||
import { CommonDataTypes } from "../../../CommonDataTypes";
|
||||
|
||||
export class GridExtractor implements DataExtractor<ExtractedData> {
|
||||
readonly id = "grid";
|
||||
getExtractions(
|
||||
data: unknown,
|
||||
extractionCollector: ExtractionCollector<ExtractedData>,
|
||||
context: DataExtractorContext
|
||||
): void {
|
||||
if (!Array.isArray(data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
extractionCollector.addExtraction({
|
||||
id: this.id,
|
||||
name: "Array As Grid",
|
||||
priority: 500,
|
||||
extractData(): CommonDataTypes.Grid {
|
||||
return {
|
||||
kind: { array: true },
|
||||
rows: [{ columns: data.map(d => ({ tag: d })) }],
|
||||
};
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import { ToStringDataExtractor } from "./ToStringExtractor";
|
||||
import { PlotDataExtractor } from "./PlotlyDataExtractor";
|
||||
import { ObjectGraphExtractor } from "./ObjectGraphExtractor";
|
||||
import { getDataExtractorApi } from "../injection";
|
||||
import { GridExtractor } from "./GridExtractor";
|
||||
|
||||
/**
|
||||
* The default data extractors should be registered by VS Code automatically.
|
||||
@@ -21,6 +22,7 @@ export function registerDefaultExtractors(
|
||||
new ToStringDataExtractor(),
|
||||
new PlotDataExtractor(),
|
||||
new ObjectGraphExtractor(),
|
||||
new GridExtractor(),
|
||||
]) {
|
||||
api.registerExtractor(item);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from "./createGraph";
|
||||
export * from "./createGraphFromPointers";
|
||||
export * from "./tryEval";
|
||||
export * from "./markedGrid";
|
||||
|
||||
16
data-extraction/src/js/helpers/markedGrid.ts
Normal file
16
data-extraction/src/js/helpers/markedGrid.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { CommonDataTypes } from "../../CommonDataTypes";
|
||||
|
||||
export function markedGrid(
|
||||
arr: any[],
|
||||
marked: Record<string, number>
|
||||
): CommonDataTypes.Grid {
|
||||
return {
|
||||
kind: { array: true },
|
||||
rows: [{ columns: arr.map(d => ({ tag: d })) }],
|
||||
markers: Object.entries(marked).map(([key, val]) => ({
|
||||
id: key,
|
||||
row: 0,
|
||||
column: val,
|
||||
})),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user