Skip to content

Commit 794dce5

Browse files
authored
Merge pull request #2452 from finos/safari-theme
Fix `perspective-click` event for `"Treemap"` plugin
2 parents e1069c0 + ee479e7 commit 794dce5

16 files changed

Lines changed: 258 additions & 80 deletions

File tree

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,13 @@ export function register(...plugins) {
533533
if (settings) {
534534
delete settings["colorStyles"];
535535
delete settings["textStyles"];
536-
initialiseStyles(this._container, this._settings);
537-
this.resize(...args);
536+
if (this.isConnected) {
537+
initialiseStyles(
538+
this._container,
539+
this._settings
540+
);
541+
this.resize(...args);
542+
}
538543
}
539544
}
540545

packages/perspective-viewer-d3fc/src/js/tooltip/selectionData.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export function getGroupValues(data, settings) {
3535
if (data.crossValue.length === 0) return [];
3636
const groupValues = (data.crossValue.split
3737
? data.crossValue.split("|")
38+
: Array.isArray(data.crossValue)
39+
? data.crossValue
3840
: [data.crossValue]) || [data.key];
3941
return groupValues.map((cross, i) => ({
4042
name: settings.crossValues[i].name,
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
2+
// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
3+
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
4+
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
5+
// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
6+
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
7+
// ┃ Copyright (c) 2017, the Perspective Authors. ┃
8+
// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
9+
// ┃ This file is part of the Perspective library, distributed under the terms ┃
10+
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
11+
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
12+
13+
import { test, expect } from "@playwright/test";
14+
import {
15+
compareLightDOMContents,
16+
compareShadowDOMContents,
17+
} from "@finos/perspective-test";
18+
19+
test.beforeEach(async ({ page }) => {
20+
await page.goto("/tools/perspective-test/src/html/workspace-test.html");
21+
await page.evaluate(async () => {
22+
while (!window["__TEST_PERSPECTIVE_READY__"]) {
23+
await new Promise((x) => setTimeout(x, 10));
24+
}
25+
});
26+
});
27+
28+
function tests(context, compare) {
29+
test("treemap filters work", async ({ page }) => {
30+
const config = {
31+
viewers: {
32+
One: {
33+
table: "superstore",
34+
name: "Test",
35+
group_by: ["State"],
36+
columns: ["Sales"],
37+
plugin: "Treemap",
38+
},
39+
Two: { table: "superstore", name: "One" },
40+
},
41+
master: {
42+
widgets: ["One"],
43+
},
44+
detail: {
45+
main: {
46+
currentIndex: 0,
47+
type: "tab-area",
48+
widgets: ["Two"],
49+
},
50+
},
51+
};
52+
53+
const cfg = await page.evaluate(async (config) => {
54+
const workspace = document.getElementById("workspace");
55+
await workspace.restore(config);
56+
await workspace.flush();
57+
document
58+
.querySelector("perspective-viewer-d3fc-treemap")
59+
.shadowRoot.querySelector("g.treemap > g")
60+
.dispatchEvent(new Event("click"));
61+
await workspace.flush();
62+
return await workspace.save();
63+
}, config);
64+
65+
expect(cfg.viewers.Two.filter).toEqual([["State", "==", "Alabama"]]);
66+
return compare(page, `${context}-treemap-filters-work.txt`);
67+
});
68+
}
69+
70+
test.describe("Workspace global filters", () => {
71+
test.describe("Light DOM", () => {
72+
tests("light-dom", compareLightDOMContents);
73+
});
74+
75+
test.describe("Shadow DOM", () => {
76+
tests("shadow-dom", compareShadowDOMContents);
77+
});
78+
});

python/perspective/bench/runtime/bench.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,71 @@
3838
"benchmark-python.arrow",
3939
)
4040

41+
BASELINE = {
42+
"name": [
43+
"arrow",
44+
"csv",
45+
"one",
46+
"one_1_pivot",
47+
"one_2_pivot",
48+
"to_arrow",
49+
"to_arrow_r1",
50+
"to_arrow_r1_c1",
51+
"to_arrow_r2",
52+
"to_arrow_r2_c2",
53+
"to_columns",
54+
"to_columns_r1",
55+
"to_columns_r1_c1",
56+
"to_columns_r2",
57+
"to_columns_r2_c2",
58+
"to_csv",
59+
"to_csv_r1",
60+
"to_csv_r1_c1",
61+
"to_csv_r2",
62+
"to_csv_r2_c2",
63+
"to_records",
64+
"to_records_r1",
65+
"to_records_r1_c1",
66+
"to_records_r2",
67+
"to_records_r2_c2",
68+
"two",
69+
"two_1x1_pivot",
70+
"two_2x2_pivot",
71+
"zero",
72+
],
73+
"time": [
74+
0.007100801400002865,
75+
0.2905632236999963,
76+
0.31363245369999504,
77+
0.5827624402000027,
78+
0.5723526209999988,
79+
0.3929776023999921,
80+
0.00021701669998037688,
81+
0.005837792799991348,
82+
0.0012358780999875308,
83+
0.06712399980000328,
84+
1.5685727534000022,
85+
0.00040022939999744266,
86+
0.007451989500009404,
87+
0.0027319223000063174,
88+
0.08117095989999826,
89+
0.5763108057000068,
90+
0.0003611342000112927,
91+
0.008143171199992593,
92+
0.0019054690000075425,
93+
0.07623720379999668,
94+
2.040859387900002,
95+
0.00047493509999867455,
96+
0.008475803500004986,
97+
0.0036788466000075458,
98+
0.09640174390000311,
99+
1.1455542396000056,
100+
1.9211396786000023,
101+
1.9244194315999947,
102+
0.10238117819999956,
103+
],
104+
}
105+
41106

42107
class VirtualEnvHandler(object):
43108
"""Creates and manages a virtualenv for benchmarking, which allows for
@@ -248,6 +313,7 @@ def run_method(self, func, *args, **kwargs):
248313

249314
result = timeit(func, number=Runner.ITERATIONS) / Runner.ITERATIONS
250315
overall_result["__TIME__"] = result
316+
overall_result["baseline"] = BASELINE["time"][BASELINE["name"].index(overall_result["name"])]
251317
return overall_result
252318

253319
def print_result(self, result):

python/perspective/bench/runtime/run_perspective_benchmark.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
"""Benchmark the `perspective-python` runtime locally."""
2020
VERSIONS = [
2121
"master",
22+
"2.7.0",
23+
"2.6.0",
24+
"2.5.0",
2225
"2.4.0",
2326
"2.3.2",
2427
"2.3.1",

rust/perspective-viewer/src/less/column-settings-panel.less

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,17 @@
4242
outline-color: var(--inactive--color);
4343
background-color: var(--plugin--background);
4444
border: none;
45-
border-radius: 2px;
4645
margin-bottom: 0.5em;
4746
font-family: inherit;
4847
font-size: 12px;
49-
min-height: 24px;
50-
5148
&:disabled {
5249
background-color: var(--inactive--color);
5350
}
5451
}
52+
53+
&[type="search"] {
54+
min-height: 24px;
55+
border-radius: 2px;
56+
}
5557
}
5658
}

rust/perspective-viewer/src/rust/presentation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ fn fill_sheet_theme_names(
237237

238238
if let Ok(rules) = sheet.css_rules() {
239239
for rule in iter_index!(&rules) {
240-
fill_rule_theme_names(themes, &rule, elem)?;
240+
fill_rule_theme_names(themes, &rule, elem).unwrap_or_default();
241241
}
242242
}
243243

rust/perspective-viewer/src/rust/utils/console_logger.rs

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
1212

1313
use std::fmt::{Debug, Write};
14+
use std::sync::OnceLock;
1415

1516
use tracing::field::{Field, Visit};
1617
use tracing::Subscriber;
@@ -65,6 +66,16 @@ impl tracing::Level {
6566
}
6667
}
6768

69+
fn web_logger_1(&self) -> fn(&JsValue) {
70+
match *self {
71+
tracing::Level::TRACE => web_sys::console::trace_1,
72+
tracing::Level::DEBUG => web_sys::console::debug_1,
73+
tracing::Level::INFO => web_sys::console::info_1,
74+
tracing::Level::WARN => web_sys::console::warn_1,
75+
tracing::Level::ERROR => web_sys::console::error_1,
76+
}
77+
}
78+
6879
/// Return a pretty color theme for a `tracing::Level`.
6980
fn web_log_color(&self) -> &'static str {
7081
match *self {
@@ -77,6 +88,12 @@ impl tracing::Level {
7788
}
7889
}
7990

91+
static IS_CHROME: OnceLock<bool> = OnceLock::new();
92+
93+
fn detect_chrome() -> bool {
94+
web_sys::window().unwrap().get("chrome").is_some()
95+
}
96+
8097
#[extend::ext]
8198
impl<'a> tracing::Metadata<'a> {
8299
/// Log a message in the style of `WasmLogger`.
@@ -87,12 +104,16 @@ impl<'a> tracing::Metadata<'a> {
87104
.and_then(|file| self.line().map(|ln| format!("{}:{}", &file[11..], ln)))
88105
.unwrap_or_default();
89106

90-
level.web_logger_4()(
91-
&format!("%c {} %c {}%c {} ", level, origin, msg).into(),
92-
&level.web_log_color().into(),
93-
&"color: gray; font-style: italic".into(),
94-
&"color: inherit".into(),
95-
);
107+
if *IS_CHROME.get_or_init(detect_chrome) {
108+
level.web_logger_4()(
109+
&format!("%c {} %c {}%c {} ", level, origin, msg).into(),
110+
&level.web_log_color().into(),
111+
&"color: gray; font-style: italic".into(),
112+
&"color: inherit".into(),
113+
);
114+
} else {
115+
level.web_logger_1()(&format!("{} {}", origin, msg).into());
116+
}
96117
}
97118
}
98119

@@ -185,16 +206,7 @@ impl<S: Subscriber + for<'a> LookupSpan<'a>> Layer<S> for WasmLogger {
185206
/// `tracing::Subscriber`, so it should not be called when `perspective` is used
186207
/// as a library from a larger app; in this case the app itself should configure
187208
/// `tracing` explicitly.
188-
///
189-
/// Why is this stubbed out for `--release` builds, you may ask? While `tracing`
190-
/// has support for [compile-time log ellision](https://docs.rs/tracing/latest/tracing/level_filters/index.html)
191-
/// (which is enabled), even at `"max_level_off"` there is a 80k binary
192-
/// payload generated from `set_global_logging()` in wasm. As this module does
193-
/// not currently use even `"error"` level logging in `--release` builds,
194-
/// we stub this library out entirely to save bytes.
195-
#[cfg(debug_assertions)]
196209
pub fn set_global_logging() {
197-
use std::sync::OnceLock;
198210
static INIT_LOGGING: OnceLock<()> = OnceLock::new();
199211
INIT_LOGGING.get_or_init(|| {
200212
use tracing_subscriber::layer::SubscriberExt;
@@ -210,6 +222,3 @@ pub fn set_global_logging() {
210222
tracing::subscriber::set_global_default(subscriber).unwrap();
211223
});
212224
}
213-
214-
#[cfg(not(debug_assertions))]
215-
pub fn set_global_logging() {}

rust/perspective-viewer/src/themes/dracula.less

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,23 @@ perspective-viewer[theme="Dracula"] {
2020
}
2121

2222
perspective-viewer[theme="Dracula"] {
23+
@include perspective-viewer-pro-dark;
24+
@include perspective-viewer-dracula--colors;
25+
@include perspective-viewer-dracula--animation;
26+
@include perspective-viewer-dracula--fonts;
27+
@include perspective-viewer-dracula--datagrid;
28+
@include perspective-viewer-dracula--d3fc;
29+
}
30+
31+
perspective-copy-menu[theme="Dracula"],
32+
perspective-export-menu[theme="Dracula"],
33+
perspective-dropdown[theme="Dracula"] {
34+
@include perspective-modal-pro-dark;
35+
@include perspective-viewer-dracula--colors;
36+
background-color: var(--theme-bg0);
37+
}
38+
39+
@mixin perspective-viewer-dracula--colors {
2340
--theme-bg0: #191a22;
2441
--theme-bg1: #282a36;
2542
--theme-bg2: #44475a;
@@ -38,23 +55,6 @@ perspective-viewer[theme="Dracula"] {
3855
--theme-orange: #ffb86c;
3956
--theme-pink: #ff79c6;
4057

41-
@include perspective-viewer-pro-dark;
42-
@include perspective-viewer-dracula--colors;
43-
@include perspective-viewer-dracula--animation;
44-
@include perspective-viewer-dracula--fonts;
45-
@include perspective-viewer-dracula--datagrid;
46-
@include perspective-viewer-dracula--d3fc;
47-
}
48-
49-
perspective-copy-menu[theme="Dracula"],
50-
perspective-export-menu[theme="Dracula"],
51-
perspective-dropdown[theme="Dracula"] {
52-
@include perspective-modal-pro-dark;
53-
@include perspective-viewer-dracula--colors;
54-
background-color: var(--theme-bg0);
55-
}
56-
57-
@mixin perspective-viewer-dracula--colors {
5858
color: var(--theme-fg0);
5959
background-color: var(--theme-bg0);
6060
--icon--color: var(--theme-fg1);

0 commit comments

Comments
 (0)