Skip to content

Commit

Permalink
#3195: Plate Viewer: WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
skalkin committed Dec 17, 2024
1 parent 8c13266 commit c1530ee
Show file tree
Hide file tree
Showing 16 changed files with 1,583 additions and 1,425 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 15 additions & 21 deletions js-api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions js-api/src/api/grok_api.g.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,8 @@ export interface IDartApi {
grok_GridColumnList_SetVisible(columns: any, columnNames: any): any;
grok_GridColumnList_Get_Length(columns: any): any;
grok_GridColumnList_Add(columns: any, cellType: String, gridColumnName: String): any;
grok_GridColumnList_RemoveAt(columns: any, index: Num): any;
grok_GridColumnList_Clear(columns: any): any;
grok_Grid_Create(table: any): any;
grok_Grid_Sort(grid: any, columns: any, orders: any): any;
grok_Grid_Get_Canvas(grid: any): any;
Expand Down
18 changes: 17 additions & 1 deletion js-api/src/dataframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ export class Row {
return true;
},
get(target: any, name) {
if (name == 'cells' || name == 'get' || name == 'toDart' || target.hasOwnProperty(name))
if (name == 'cells' || name == 'get' || name == 'toDart' || name == 'toMap' || target.hasOwnProperty(name))
return target[<any>name];
return target.table.get(name, target.idx);
}
Expand All @@ -583,6 +583,14 @@ export class Row {

get cells(): Iterable<Cell> { return _toIterable(api.grok_Row_Get_Cells(this.table.dart, this.idx)); }

/** Returns a JS object with column names as keys and values as values. */
toMap(): {[index: string]: any} {
const res: {[index: string]: any} = {};
for (const column of this.table.columns)
res[column.name] = column.get(this.idx);
return res;
}

/** Returns this row's value for the specified column
* @param {string} columnName
* @returns {Object} */
Expand Down Expand Up @@ -1237,6 +1245,14 @@ export class ColumnList {
return _toIterable(api.grok_ColumnList_ByTags(this.dart, tags));
}

/** Returns the first column that satisfies the specified criteria. */
firstWhere(predicate: (col: Column) => boolean): Column | undefined {
for (const col of this)
if (predicate(col))
return col;
}


/** Finds categorical columns.
* Sample: {@link https://public.datagrok.ai/js/samples/data-frame/find-columns} */
get categorical(): Iterable<Column> {
Expand Down
12 changes: 12 additions & 0 deletions js-api/src/grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {SemType} from './const';
import {Property} from './entities';
import {IFormSettings, IGridSettings} from "./interfaces/d4";
import {IDartApi} from "./api/grok_api.g";
import * as DG from "./dataframe";


const api: IDartApi = <any>window;
Expand Down Expand Up @@ -783,6 +784,12 @@ export class GridColumnList {
add(options: {gridColumnName?: string, cellType: string, index?: number}): GridColumn {
return api.grok_GridColumnList_Add(this.dart, options.cellType, options.gridColumnName);
}

/** Removes a grid column at the specified position. */
removeAt(index: number) { api.grok_GridColumnList_RemoveAt(this.dart, index); }

/** Removes all columns. */
clear() { api.grok_GridColumnList_Clear(this.dart); }
}

/** DataFrame-bound viewer that contains {@link Form} */
Expand Down Expand Up @@ -1058,6 +1065,11 @@ export class Grid extends Viewer<IGridSettings> {
autoSize(maxWidth: number, maxHeight: number, minWidth?: number, minHeight?: number, autoSizeOnDataChange?: boolean): void {
api.grok_Grid_AutoSize(this.dart, maxWidth, maxHeight, minWidth, minHeight, autoSizeOnDataChange);
}

/** Renders the content of this grid to the specified canvas and bounds. */
render(g: CanvasRenderingContext2D, bounds: Rect) {
api.grok_Grid_Render(this.dart, g, bounds.toDart());
}
}


Expand Down
2 changes: 1 addition & 1 deletion js-api/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ export namespace input {

export interface IColumnInputInitOptions<T> extends IInputInitOptions<T> {
table?: DataFrame;
filter?: Function;
filter?: (col: Column) => boolean;
}

export interface IColumnsInputInitOptions<T> extends IColumnInputInitOptions<T> {
Expand Down
Loading

0 comments on commit c1530ee

Please sign in to comment.