Skip to content

Commit bb30c4d

Browse files
committed
UI support
Signed-off-by: Andrew Stein <steinlink@gmail.com>
1 parent c2ea98c commit bb30c4d

File tree

25 files changed

+585
-73
lines changed

25 files changed

+585
-73
lines changed

packages/viewer-d3fc/src/ts/plugin/plugin.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ class HTMLPerspectiveViewerD3fcPluginElement extends HTMLElement {
136136
return this._chart.plugin.selectMode || "select";
137137
}
138138

139+
get group_rollups(): string[] {
140+
return ["flat"];
141+
}
142+
139143
get min_config_columns() {
140144
return (
141145
this._chart.plugin.initial?.count ||

packages/viewer-datagrid/src/less/regular_table.less

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ perspective-viewer {
128128
border-color: var(--selected-row--background-color, #ea7319) !important;
129129
}
130130

131-
.psp-row-selected.psp-tree-label:not(:hover):before {
131+
regular-table:not(.flat-group-rollup-mode)
132+
.psp-row-selected.psp-tree-label:not(:hover):before {
132133
color: white;
133134
}
134135

@@ -254,29 +255,36 @@ tbody th:empty {
254255
max-width: 20px;
255256
pointer-events: none;
256257
}
257-
.psp-tree-label {
258-
max-width: 0px;
259-
min-width: 0px;
260-
}
261-
.psp-tree-label:before {
262-
color: var(--icon--color);
263-
font-family: var(--button--font-family, inherit);
264-
padding-right: 11px;
265-
}
266-
.psp-tree-label-expand:before {
267-
content: var(--tree-label-expand--content, "+");
268-
}
269-
.psp-tree-label-collapse:before {
270-
content: var(--tree-label-collapse--content, "-");
271-
}
272-
.psp-tree-label-expand,
273-
.psp-tree-label-collapse {
274-
cursor: pointer;
275-
}
276258

277-
.psp-tree-label:hover:before {
278-
color: var(--active--color);
279-
text-shadow: 0px 0px 5px var(--active--color);
259+
regular-table:not(.flat-group-rollup-mode) {
260+
.psp-tree-label {
261+
max-width: 0px;
262+
min-width: 0px;
263+
}
264+
265+
.psp-tree-label:before {
266+
color: var(--icon--color);
267+
font-family: var(--button--font-family, inherit);
268+
padding-right: 11px;
269+
}
270+
271+
.psp-tree-label-expand:before {
272+
content: var(--tree-label-expand--content, "+");
273+
}
274+
275+
.psp-tree-label-collapse:before {
276+
content: var(--tree-label-collapse--content, "-");
277+
}
278+
279+
.psp-tree-label-expand,
280+
.psp-tree-label-collapse {
281+
cursor: pointer;
282+
}
283+
284+
.psp-tree-label:hover:before {
285+
color: var(--active--color);
286+
text-shadow: 0px 0px 5px var(--active--color);
287+
}
280288
}
281289

282290
.psp-tree-leaf {

packages/viewer-datagrid/src/ts/custom_elements/datagrid.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ export class HTMLPerspectiveViewerDatagridPluginElement
133133
return ["Columns"];
134134
}
135135

136+
get group_rollups(): string[] {
137+
return ["rollup", "flat"];
138+
}
139+
136140
/**
137141
* Give the Datagrid a higher priority so it is loaded
138142
* over the default charts by default.
@@ -179,6 +183,7 @@ export class HTMLPerspectiveViewerDatagridPluginElement
179183
viewport?.start_row !== null
180184
? viewport.end_row - viewport.start_row
181185
: await view.num_rows();
186+
182187
let out = "";
183188
for (let ridx = 0; ridx < nrows; ridx++) {
184189
for (const col_name of cols) {

packages/viewer-datagrid/src/ts/data_listener/format_tree_header.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,22 @@ export function* format_tree_header_row_path(
5252
}
5353
}
5454

55+
export function* format_flat_header_row_path(
56+
this: DatagridModel,
57+
paths: unknown[][] = [],
58+
row_headers: string[],
59+
regularTable: RegularTable,
60+
): Generator<RowHeaderCell[]> {
61+
const plugins: ColumnsConfig =
62+
(regularTable as any)[PRIVATE_PLUGIN_SYMBOL] || {};
63+
64+
for (let path of paths) {
65+
yield path.map((part, i) =>
66+
format_cell.call(this, row_headers[i], part, plugins, true),
67+
) as RowHeaderCell[];
68+
}
69+
}
70+
5571
/**
5672
* Format a single cell of the `group_by` tree header.
5773
*/

packages/viewer-datagrid/src/ts/data_listener/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import { PRIVATE_PLUGIN_SYMBOL } from "../types.js";
1414
import { format_cell } from "./format_cell.js";
1515
import {
16+
format_flat_header_row_path,
1617
format_tree_header,
1718
format_tree_header_row_path,
1819
} from "./format_tree_header.js";
@@ -207,9 +208,12 @@ export function createDataListener(
207208
}
208209

209210
const is_row_path = columns.__ROW_PATH__ !== undefined;
211+
const is_flat = this._config.group_rollup_mode === "flat";
210212
const row_headers = Array.from(
211213
(is_row_path
212-
? format_tree_header_row_path
214+
? is_flat
215+
? format_flat_header_row_path
216+
: format_tree_header_row_path
213217
: format_tree_header
214218
).call(
215219
this,

packages/viewer-datagrid/src/ts/model/create.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ export async function createModel(
122122
}
123123
}
124124

125+
const group_rollup_mode_changed =
126+
old.group_rollup_mode !== config.group_rollup_mode;
127+
125128
this._reset_scroll_top = group_by_changed;
126129
this._reset_scroll_left = split_by_changed;
127130
this._reset_select =
@@ -132,6 +135,7 @@ export async function createModel(
132135
columns_changed;
133136

134137
this._reset_column_size =
138+
group_rollup_mode_changed ||
135139
split_by_changed ||
136140
group_by_changed ||
137141
columns_changed ||

packages/viewer-datagrid/src/ts/plugin/draw.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export async function draw(
3737
const drawPromise = this.regular_table.draw({
3838
invalid_columns: true,
3939
} as any);
40+
4041
if (this._reset_scroll_top) {
4142
this.regular_table.scrollTop = 0;
4243
this._reset_scroll_top = false;

packages/viewer-datagrid/src/ts/style_handlers/body.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ export function applyBodyCellStyles(
4949
const hasSelected = selectedRowsMap.has(regularTable);
5050
const selected = selectedRowsMap.get(regularTable);
5151

52+
regularTable.classList.toggle(
53+
"flat-group-rollup-mode",
54+
this._config.group_rollup_mode === "flat",
55+
);
56+
5257
for (const { element: td, metadata, isHeader } of cells) {
5358
const column_name =
5459
metadata.column_header?.[this._config.split_by.length];

pnpm-workspace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ catalog:
3939
"pro_self_extracting_wasm": "0.0.9"
4040
"react-dom": ">17 <20"
4141
"react": ">17 <20"
42-
"regular-table": "=0.8.1"
42+
"regular-table": "=0.8.2"
4343
"stoppable": "=1.1.0"
4444
"ws": "^8.17.0"
4545

rust/perspective-client/perspective.proto

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ message ViewConfig {
519519
map<string, AggList> aggregates = 7;
520520
FilterReducer filter_op = 8;
521521
optional uint32 group_by_depth = 9;
522-
optional bool leaves_only = 10;
522+
optional GroupRollupMode group_rollup_mode = 10;
523523

524524
message AggList {
525525
repeated string aggregations = 1;
@@ -540,6 +540,12 @@ message ViewConfig {
540540
AND = 0;
541541
OR = 1;
542542
}
543+
544+
enum GroupRollupMode {
545+
ROLLUP = 0;
546+
FLAT = 1;
547+
// TOTAL = 2;
548+
}
543549
}
544550

545551
message ColumnsUpdate {

0 commit comments

Comments
 (0)