diff --git a/rust/perspective-viewer/src/less/column-style.less b/rust/perspective-viewer/src/less/column-style.less index abc53ae551..94fc0ce961 100644 --- a/rust/perspective-viewer/src/less/column-style.less +++ b/rust/perspective-viewer/src/less/column-style.less @@ -194,7 +194,6 @@ border-radius: 0 6px 6px 0; margin: 0 0 0 1px; } - } ::-webkit-color-swatch-wrapper { diff --git a/rust/perspective-viewer/src/less/dom/scrollbar.less b/rust/perspective-viewer/src/less/dom/scrollbar.less index b4c99e291b..0d57dd1cba 100644 --- a/rust/perspective-viewer/src/less/dom/scrollbar.less +++ b/rust/perspective-viewer/src/less/dom/scrollbar.less @@ -1,3 +1,15 @@ +// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃ +// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃ +// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃ +// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃ +// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ +// ┃ Copyright (c) 2017, the Perspective Authors. ┃ +// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃ +// ┃ This file is part of the Perspective library, distributed under the terms ┃ +// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃ +// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + @mixin scrollbar { &::-webkit-scrollbar-thumb { border: 0 solid var(--icon--color); diff --git a/rust/perspective-viewer/src/rust/components/style_controls/number_string_format.rs b/rust/perspective-viewer/src/rust/components/style_controls/number_string_format.rs index 2e9610b3e7..27c622aade 100644 --- a/rust/perspective-viewer/src/rust/components/style_controls/number_string_format.rs +++ b/rust/perspective-viewer/src/rust/components/style_controls/number_string_format.rs @@ -68,16 +68,23 @@ pub struct CustomNumberFormat { impl CustomNumberFormat { fn initialize(ctx: &yew::prelude::Context) -> Self { let config = ctx.props().restored_config.clone(); + let show_frac = config + .minimum_fraction_digits + .or(config.maximum_fraction_digits) + .or(config.rounding_increment) + .is_some(); + let show_sig = config + .minimum_significant_digits + .or(config.maximum_significant_digits) + .is_some(); + let disable_rounding_increment = show_sig + || show_frac + || !matches!( + config.rounding_priority, + Some(RoundingPriority::Auto) | None + ); + let disable_rounding_priority = !(show_frac && show_sig); Self { - show_frac: config - .minimum_fraction_digits - .or(config.maximum_fraction_digits) - .or(config.rounding_increment) - .is_some(), - show_sig: config - .minimum_significant_digits - .or(config.maximum_significant_digits) - .is_some(), style: config ._style .as_ref() @@ -89,7 +96,11 @@ impl CustomNumberFormat { }) .unwrap_or_default(), config, - ..Default::default() + show_frac, + show_sig, + disable_rounding_increment, + disable_rounding_priority, + notation: None, } } } @@ -245,7 +256,7 @@ impl Component for CustomNumberFormat { self.config.rounding_priority, Some(RoundingPriority::Auto) | None ); - self.disable_rounding_priority = self.show_sig || self.show_frac; + self.disable_rounding_priority = !(self.show_frac && self.show_sig); let filtered_config = self.config.clone().filter_default( self.show_sig, diff --git a/rust/perspective-viewer/src/rust/components/style_controls/number_string_format/digits_section.rs b/rust/perspective-viewer/src/rust/components/style_controls/number_string_format/digits_section.rs index bb75cf63f3..543d2affa4 100644 --- a/rust/perspective-viewer/src/rust/components/style_controls/number_string_format/digits_section.rs +++ b/rust/perspective-viewer/src/rust/components/style_controls/number_string_format/digits_section.rs @@ -148,7 +148,7 @@ impl CustomNumberFormat { { self.rounding_increment(ctx) } label="Rounding Priority" - disabled={!(self.show_frac && self.show_sig)} + disabled={self.disable_rounding_priority} current_value={self.config.rounding_priority} on_change={ctx.link().callback(CustomNumberFormatMsg::RoundingPriority)} /> diff --git a/rust/perspective-viewer/test/js/column_settings/number_string_format.spec.ts b/rust/perspective-viewer/test/js/column_settings/number_string_format.spec.ts new file mode 100644 index 0000000000..1b18d06102 --- /dev/null +++ b/rust/perspective-viewer/test/js/column_settings/number_string_format.spec.ts @@ -0,0 +1,210 @@ +// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃ +// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃ +// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃ +// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃ +// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ +// ┃ Copyright (c) 2017, the Perspective Authors. ┃ +// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃ +// ┃ This file is part of the Perspective library, distributed under the terms ┃ +// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃ +// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + +import { Type } from "@finos/perspective"; +import { + DEFAULT_CONFIG, + PageView, + compareContentsToSnapshot, +} from "@finos/perspective-test"; +import { ColumnSelector } from "@finos/perspective-test/src/js/models/settings_panel"; +import { test, expect } from "@finos/perspective-test"; +import { DataGridPlugin } from "@finos/perspective-test/src/js/models/plugins"; +import { DataGrid } from "@finos/perspective-test/src/js/models/plugins/datagrid"; + +test.beforeEach(async ({ page }) => { + await page.goto("/tools/perspective-test/src/html/basic-test.html"); + await page.evaluate(async () => { + while (!window["__TEST_PERSPECTIVE_READY__"]) { + await new Promise((x) => setTimeout(x, 10)); + } + }); +}); + +test("Integer/float styles", async ({ page }) => { + const view = new PageView(page); + await view.restore({ + settings: true, + plugin: "Datagrid", + columns: ["Profit", "Row ID"], + }); + const profit = await view.settingsPanel.activeColumns.getColumnByName( + "Profit" + ); + await profit.editBtn.click(); + const styleContainer = view.columnSettingsSidebar.styleTab.container; + await styleContainer.getByText("Fractional Digits").waitFor(); + const rowId = await view.settingsPanel.activeColumns.getColumnByName( + "Row ID" + ); + await rowId.editBtn.click(); + await styleContainer + .getByText("Fractional Digits") + .waitFor({ state: "detached" }); +}); +for (const name of ["Significant Digits", "Fractional Digits"]) { + test(`Rounding Increment doesn't send when ${name} is open`, async ({ + page, + }) => { + let view = new PageView(page); + await view.restore({ + settings: true, + plugin: "Datagrid", + columns: ["Profit"], + }); + const profit = await view.settingsPanel.activeColumns.getColumnByName( + "Profit" + ); + await profit.editBtn.click(); + const styleContainer = view.columnSettingsSidebar.styleTab.container; + await styleContainer + .locator("#Rounding-Increment-checkbox ~ div > select") + .selectOption("20"); + await styleContainer.getByText(name).click(); + await expect( + styleContainer.locator("#Rounding-Increment-checkbox") + ).toBeDisabled(); + let config = await view.save(); + expect(config).toMatchObject({ + column_config: {}, + }); + await styleContainer.getByText(name).click(); + config = await view.save(); + expect(config).toMatchObject({ + column_config: { + Profit: { + number_string_format: { + maximumFractionDigits: 0, + roundingIncrement: 20, + }, + }, + }, + }); + }); +} +test("Rounding Priority doesn't send unless Fractional and Significant Digits are open", async ({ + page, +}) => { + const view = new PageView(page); + await view.restore({ + settings: true, + plugin: "Datagrid", + columns: ["Profit"], + }); + const col = await view.settingsPanel.activeColumns.getColumnByName( + "Profit" + ); + await col.editBtn.click(); + const styleContainer = view.columnSettingsSidebar.styleTab.container; + await expect( + styleContainer.locator("#Rounding-Priority-checkbox") + ).toBeDisabled(); + await styleContainer.getByText("Fractional Digits").click(); + await styleContainer.getByText("Significant Digits").click(); + await expect( + styleContainer.locator("#Rounding-Priority-checkbox") + ).toBeEnabled(); + const select = styleContainer.locator( + "#Rounding-Priority-checkbox ~ div > select" + ); + await select.scrollIntoViewIfNeeded(); + await select.selectOption("MorePrecision"); + const config = await view.save(); + expect(config).toMatchObject({ + column_config: { + Profit: { + number_string_format: { + roundingPriority: "morePrecision", + }, + }, + }, + }); + await styleContainer.getByText("Fractional Digits").click(); + const config2 = await view.save(); + expect(config2).toMatchObject({ + column_config: {}, + }); +}); + +test("Datagrid integration", async ({ page }) => { + const view = new PageView(page); + const datagrid = new DataGrid(page); + await view.restore({ + plugin: "Datagrid", + columns: ["Profit"], + column_config: { + Profit: { + number_string_format: { + minimumIntegerDigits: 3, + maximumFractionDigits: 0, + roundingIncrement: 50, + roundingMode: "ceil", + notation: "compact", + compactDisplay: "short", + signDisplay: "always", + }, + }, + }, + }); + const decimal = await datagrid.regularTable.table.innerHTML(); + await compareContentsToSnapshot(decimal, [ + "datagrid-integration-decimal.html", + ]); + await view.restore({ + plugin: "Datagrid", + columns: ["Profit"], + column_config: { + Profit: { + number_string_format: { + style: "currency", + currency: "USD", + currencySign: "accounting", + }, + }, + }, + }); + const currency = await datagrid.regularTable.table.innerHTML(); + await compareContentsToSnapshot(currency, [ + "datagrid-integration-currency.html", + ]); + + await view.restore({ + plugin: "Datagrid", + columns: ["Profit"], + column_config: { + Profit: { + number_string_format: { + style: "unit", + unit: "byte", + }, + }, + }, + }); + const unit = await datagrid.regularTable.table.innerHTML(); + await compareContentsToSnapshot(unit, ["datagrid-integration-unit.html"]); + + await view.restore({ + plugin: "Datagrid", + columns: ["Profit"], + column_config: { + Profit: { + number_string_format: { + style: "percent", + }, + }, + }, + }); + const data = await datagrid.regularTable.table.innerHTML(); + await compareContentsToSnapshot(data, [ + "datagrid-integration-percent.html", + ]); +}); diff --git a/tools/perspective-test/results.tar.gz b/tools/perspective-test/results.tar.gz index 1ab2bcc626..f920856250 100644 Binary files a/tools/perspective-test/results.tar.gz and b/tools/perspective-test/results.tar.gz differ