Implements Grid extractors/visualizer and sorting demo.

This commit is contained in:
Henning Dieterichs
2020-02-22 13:41:50 +01:00
parent 9f3c0ead67
commit e3808e5009
8 changed files with 535 additions and 2 deletions

View File

@@ -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;

View File

@@ -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 })) }],
};
},
});
}
}

View File

@@ -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);
}

View File

@@ -1,3 +1,4 @@
export * from "./createGraph";
export * from "./createGraphFromPointers";
export * from "./tryEval";
export * from "./markedGrid";

View 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,
})),
};
}