Skip to content

Commit a54e4b4

Browse files
authored
Merge pull request #3015 from finos/d3fc-style-2
Fix `perspective-viewer-datagrid` draw error when `group_by`+`split_by`+`filter` are empty
2 parents c4e2805 + 20d4a66 commit a54e4b4

13 files changed

Lines changed: 69 additions & 62 deletions

File tree

packages/perspective-viewer-d3fc/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
"@finos/perspective-viewer": "workspace:^",
5252
"chroma-js": "^1.3.4",
5353
"d3fc": "^15.2.4",
54+
"@d3fc/d3fc-chart": "^5.1.9",
55+
"@d3fc/d3fc-element": "^6.2.0",
5456
"d3-selection": "^3.0.0",
5557
"d3-array": "^3.2.1",
5658
"d3-svg-legend": "^2.25.6",

packages/perspective-viewer-d3fc/src/ts/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
1212

1313
import type { IPerspectiveViewerPlugin } from "@finos/perspective-viewer";
14-
import { init } from "./plugin/d3fc_global_styles";
14+
import { register } from "./plugin/plugin";
1515

16-
await init();
16+
await register();
1717

1818
declare global {
1919
interface CustomElementRegistry {

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

Lines changed: 0 additions & 33 deletions
This file was deleted.

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import * as d3 from "d3";
2121

2222
import { Chart, Settings, Type } from "../types";
2323

24+
import * as d3fc_style_1 from "@d3fc/d3fc-chart/src/css.js";
25+
import * as d3fc_style_2 from "@d3fc/d3fc-element/src/css.js";
26+
2427
const DEFAULT_PLUGIN_SETTINGS = {
2528
initial: {
2629
type: "number",
@@ -30,7 +33,13 @@ const DEFAULT_PLUGIN_SETTINGS = {
3033
selectMode: "select",
3134
};
3235

33-
const D3FC_GLOBAL_STYLES = [];
36+
const D3FC_GLOBAL_STYLES = [d3fc_style_1.css, d3fc_style_2.css, style].map(
37+
(x) => {
38+
const sheet = new CSSStyleSheet();
39+
sheet.replaceSync(x);
40+
return sheet;
41+
}
42+
);
3443

3544
const EXCLUDED_SETTINGS = [
3645
"crossValues",
@@ -53,18 +62,6 @@ async function register_element(plugin_name: string) {
5362
await perspectiveViewerClass.registerPlugin(plugin_name);
5463
}
5564

56-
export function createStyleSheets(sheets) {
57-
for (const style of sheets) {
58-
const sheet = new CSSStyleSheet();
59-
sheet.replaceSync(style.textContent);
60-
D3FC_GLOBAL_STYLES.push(sheet);
61-
}
62-
63-
const sheet = new CSSStyleSheet();
64-
sheet.replaceSync(style);
65-
D3FC_GLOBAL_STYLES.push(sheet);
66-
}
67-
6865
export function register(...plugin_names: string[]) {
6966
const plugins = new Set(
7067
plugin_names.length > 0

packages/perspective-viewer-datagrid/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"@finos/perspective": "workspace:^",
3636
"@finos/perspective-viewer": "workspace:^",
3737
"chroma-js": "^1.3.4",
38-
"regular-table": "=0.6.7"
38+
"regular-table": "=0.6.8"
3939
},
4040
"devDependencies": {
4141
"@prospective.co/procss": "^0.1.16",

packages/perspective-viewer-datagrid/src/js/data_listener/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ export function createDataListener(viewer) {
128128
}
129129

130130
return {
131+
num_column_headers: column_headers[0]?.length || 1,
132+
num_row_headers: this._config.group_by.length + 1,
131133
num_rows: this._num_rows,
132134
num_columns: this._column_paths.length,
133135
row_headers: Array.from(

packages/perspective-viewer-datagrid/src/js/model/create.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,6 @@ export async function createModel(regular, table, view, extend = {}) {
143143
this.parentElement.getEditPort(),
144144
]);
145145

146-
// Due to conflation, this plugin may be called on a `View` that has yet
147-
// to be populated with data by a `poll()`.
148-
if (Object.keys(schema).length === 0) {
149-
return undefined;
150-
}
151-
152146
const _plugin_background = chroma(
153147
get_rule(regular, "--plugin--background", "#FFFFFF")
154148
).rgb();
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- viewer settings
2+
- Viewer/engine Settings
3+
- Stats
4+
* Debug Columns .. _ Style _ Attributes Plugins .. - Plugin Settings

packages/perspective-viewer-datagrid/src/js/style_handlers/column_header.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,14 @@ export function column_header_style_listener(regularTable, viewer) {
9595
1
9696
);
9797

98-
style_column_header_row.call(this, regularTable, col_headers, false);
98+
if (col_headers) {
99+
style_column_header_row.call(
100+
this,
101+
regularTable,
102+
col_headers,
103+
false
104+
);
105+
}
99106

100107
let [style_menu_headers] = group_header_trs.splice(
101108
this._config.split_by.length,
@@ -116,7 +123,7 @@ export function column_header_style_listener(regularTable, viewer) {
116123
function style_column_header_row(regularTable, col_headers, is_menu_row) {
117124
// regular header styling
118125
const header_depth = regularTable._view_cache.config.row_pivots.length - 1;
119-
for (const td of col_headers?.children) {
126+
for (const td of col_headers.children) {
120127
const metadata = regularTable.getMeta(td);
121128
const column_name =
122129
metadata.column_header?.[this._config.split_by.length];

packages/perspective-viewer-datagrid/test/js/superstore.spec.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,32 @@ test.describe("Datagrid with superstore data set", () => {
9494
"column-headers-are-printed-correctly-split-by-a-date-column.txt"
9595
);
9696
});
97+
98+
test("A filtered-to-empty dataset with group_by and split_by does not error internally", async ({
99+
page,
100+
}) => {
101+
await page.goto("/tools/perspective-test/src/html/basic-test.html");
102+
await page.evaluate(async () => {
103+
while (!window["__TEST_PERSPECTIVE_READY__"]) {
104+
await new Promise((x) => setTimeout(x, 10));
105+
}
106+
});
107+
108+
await page.evaluate(async () => {
109+
await document.querySelector("perspective-viewer").restore({
110+
plugin: "Datagrid",
111+
columns: ["Sales", "Profit"],
112+
group_by: ["State"],
113+
split_by: ["Ship Mode"],
114+
filter: [["State", "==", "Schmexas"]],
115+
});
116+
});
117+
118+
compareContentsToSnapshot(
119+
await getDatagridContents(page),
120+
"a-filtered-to-empty-dataset-with-group-by-and-split-by-does-not-error-internally.txt"
121+
);
122+
});
97123
});
98124

99125
test.describe("Datagrid with superstore arrow data set", () => {

0 commit comments

Comments
 (0)