Skip to content

Commit fb11915

Browse files
authored
Merge pull request #2753 from wakek/missing-tooltip-data
Missing tooltip data
2 parents e6e6eae + 99c6dcc commit fb11915

2 files changed

Lines changed: 167 additions & 1 deletion

File tree

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ export function getDataValues(data, settings) {
7070
}
7171
return settings.mainValues.map((main) => ({
7272
name: main.name,
73-
value: toValue(main.type, data.row[main.name]),
73+
value: toValue(
74+
main.type,
75+
data.row[getDataRowKey(data.key, main, settings.realValues)]
76+
),
7477
}));
7578
}
7679
return [
@@ -86,3 +89,33 @@ export function getDataValues(data, settings) {
8689
},
8790
];
8891
}
92+
93+
function getDataRowKey(key, main, realValues) {
94+
if (!key) {
95+
return main.name;
96+
}
97+
98+
if (key.includes("|")) {
99+
const splitKey = key.split("|");
100+
const keyIncludesValidValueName =
101+
splitKey[splitKey.length - 1] === main.name;
102+
103+
if (keyIncludesValidValueName) {
104+
return key;
105+
}
106+
107+
const keyIncludesInvalidValueName = realValues.includes(
108+
splitKey[splitKey.length - 1]
109+
);
110+
111+
const validKeyPrefix = keyIncludesInvalidValueName
112+
? splitKey.slice(0, splitKey.length - 1).join("|")
113+
: key;
114+
115+
return `${validKeyPrefix}|${main.name}`;
116+
}
117+
118+
const keyIsRealValue = realValues.includes(key);
119+
120+
return keyIsRealValue ? main.name : `${key}|${main.name}`;
121+
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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 { expect, test } from "@finos/perspective-test";
14+
15+
test.describe("Tooltip data values with various 'Split By' configurations", () => {
16+
test("Show valid tooltip data with no 'Split By' configuration", async ({
17+
page,
18+
}) => {
19+
await page.goto("/tools/perspective-test/src/html/basic-test.html");
20+
await page.evaluate(async () => {
21+
while (!window["__TEST_PERSPECTIVE_READY__"]) {
22+
await new Promise((x) => setTimeout(x, 10));
23+
}
24+
});
25+
26+
await page.evaluate(async () => {
27+
await document.querySelector("perspective-viewer")!.restore({
28+
plugin: "X/Y Line",
29+
settings: true,
30+
columns: ["Row ID", "Postal Code", null],
31+
group_by: [],
32+
split_by: [],
33+
});
34+
});
35+
36+
await page.hover(
37+
"#container > d3fc-group > d3fc-svg.svg-plot-area.plot-area > svg > g:nth-child(2) > g > g:nth-child(1) > g > path",
38+
{
39+
force: true,
40+
}
41+
);
42+
await page.waitForSelector("#tooltip-values > li:nth-child(1)");
43+
44+
let tooltip_row_id_value = await page.evaluate(async () => {
45+
return document
46+
.querySelector("perspective-viewer-d3fc-xyline")
47+
?.shadowRoot?.querySelector(
48+
"#tooltip-values > li:nth-child(2) > b"
49+
)?.textContent;
50+
});
51+
52+
expect(tooltip_row_id_value).toBeTruthy();
53+
expect(tooltip_row_id_value).toMatch(/^(?!NaN$|-$).+$/);
54+
});
55+
test("Show valid tooltip data with one 'Split By' configuration", async ({
56+
page,
57+
}) => {
58+
await page.goto("/tools/perspective-test/src/html/basic-test.html");
59+
await page.evaluate(async () => {
60+
while (!window["__TEST_PERSPECTIVE_READY__"]) {
61+
await new Promise((x) => setTimeout(x, 10));
62+
}
63+
});
64+
65+
await page.evaluate(async () => {
66+
await document.querySelector("perspective-viewer")!.restore({
67+
plugin: "X/Y Line",
68+
settings: true,
69+
columns: ["Row ID", "Postal Code", null],
70+
group_by: [],
71+
split_by: ["Sub-Category"],
72+
});
73+
});
74+
75+
await page.hover(
76+
"#container > d3fc-group > d3fc-svg.svg-plot-area.plot-area > svg > g:nth-child(2) > g > g:nth-child(1) > g > path",
77+
{
78+
force: true,
79+
}
80+
);
81+
await page.waitForSelector("#tooltip-values > li:nth-child(2)");
82+
83+
let tooltip_row_id_value = await page.evaluate(async () => {
84+
return document
85+
.querySelector("perspective-viewer-d3fc-xyline")
86+
?.shadowRoot?.querySelector(
87+
"#tooltip-values > li:nth-child(2) > b"
88+
)?.textContent;
89+
});
90+
91+
expect(tooltip_row_id_value).toBeTruthy();
92+
expect(tooltip_row_id_value).toMatch(/^(?!NaN$|-$).+$/);
93+
});
94+
test("Show valid tooltip data with multiple 'Split By' configuration", async ({
95+
page,
96+
}) => {
97+
await page.goto("/tools/perspective-test/src/html/basic-test.html");
98+
await page.evaluate(async () => {
99+
while (!window["__TEST_PERSPECTIVE_READY__"]) {
100+
await new Promise((x) => setTimeout(x, 10));
101+
}
102+
});
103+
104+
await page.evaluate(async () => {
105+
await document.querySelector("perspective-viewer")!.restore({
106+
plugin: "X/Y Line",
107+
settings: true,
108+
columns: ["Row ID", "Postal Code", null],
109+
group_by: [],
110+
split_by: ["Sub-Category", "Segment"],
111+
});
112+
});
113+
114+
await page.hover(
115+
"#container > d3fc-group > d3fc-svg.svg-plot-area.plot-area > svg > g:nth-child(2) > g > g:nth-child(1) > g > path",
116+
{
117+
force: true,
118+
}
119+
);
120+
await page.waitForSelector("#tooltip-values > li:nth-child(3)");
121+
122+
let tooltip_row_id_value = await page.evaluate(async () => {
123+
return document
124+
.querySelector("perspective-viewer-d3fc-xyline")
125+
?.shadowRoot?.querySelector(
126+
"#tooltip-values > li:nth-child(2) > b"
127+
)?.textContent;
128+
});
129+
130+
expect(tooltip_row_id_value).toBeTruthy();
131+
expect(tooltip_row_id_value).toMatch(/^(?!NaN$|-$).+$/);
132+
});
133+
});

0 commit comments

Comments
 (0)