Skip to content

Commit

Permalink
fix: fire config-update evnt on d3fc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jkusa committed Mar 7, 2022
1 parent 8cd9fa5 commit 9e69fd6
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const splitterLabels = (settings) => {
.style("color", (d) =>
coloured ? withoutOpacity(color(d.name)) : undefined
)
.on("click", (_event, d) => {
.on("click", (event, d) => {
if (disabled) return;

if (alt) {
Expand All @@ -45,6 +45,11 @@ export const splitterLabels = (settings) => {
);
}

event.target
.getRootNode()
.host.closest("perspective-viewer")
?.dispatchEvent(new Event("perspective-config-update"));

redrawChart(selection);
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function draggableComponent() {

const draggable = (element) => {
const node = element.node();
const viewer = node.getRootNode().host.closest("perspective-viewer");
node.style.cursor = "move";
if (settings.legend) {
node.style.left = settings.legend.left;
Expand All @@ -39,12 +40,11 @@ export function draggableComponent() {
};
settings.legend = {...settings.legend, ...position};

if (isNodeInTopRight(node)) {
pinned = pinNodeToTopRight(node);
return;
}
pinned = isNodeInTopRight(node)
? pinNodeToTopRight(node)
: unpinNodeFromTopRight(node, pinned);

pinned = unpinNodeFromTopRight(node, pinned);
viewer?.dispatchEvent(new Event("perspective-config-update"));
});

element.call(drag);
Expand Down
144 changes: 144 additions & 0 deletions packages/perspective-viewer-d3fc/test/js/integration/events.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/******************************************************************************
*
* Copyright (c) 2022, the Perspective Authors.
*
* This file is part of the Perspective library, distributed under the terms of
* the Apache License 2.0. The full license can be found in the LICENSE file.
*
*/

const path = require("path");

const utils = require("@finos/perspective-test");
const simple_tests = require("@finos/perspective-viewer/test/js/simple_tests.js");

const {withTemplate} = require("./simple-template");
withTemplate("events", "Y Line");

async function get_contents(page) {
return await page.evaluate(async () => {
const viewer = document
.querySelector(`perspective-viewer perspective-viewer-d3fc-yline`)
.shadowRoot.querySelector("svg");
return viewer.outerHTML || "MISSING";
});
}

utils.with_server({}, () => {
describe.page(
"events.html",
() => {
test.capture(
"perspective-config-update event is fired when series axis is changed",
async (page) => {
// Await the viewer element to exist on the page
const viewer = await page.$("perspective-viewer");
await page.evaluate(async (viewer) => {
// Await the table load
await viewer.getTable();

viewer.restore({
plugin: "Y Line",
columns: ["Sales", "Profit"],
});

// Register a listener for `perspective-config-update` event
window.__series_events__ = [];
viewer.addEventListener(
"perspective-config-update",
(evt) => {
window.__series_events__.push(evt);
}
);
}, viewer);
const axisLabel = (
await page.waitForFunction(() =>
document
.querySelector("perspective-viewer-d3fc-yline")
.shadowRoot.querySelector(".y-label")
)
).asElement();
await axisLabel.click(axisLabel);

const count = await page.evaluate(async (viewer) => {
// Await the plugin rendering
await viewer.flush();

// Count the events;
return window.__series_events__.length;
}, viewer);

// Expect 1 event
expect(count).toEqual(1);

// Return the chart contents
return get_contents(page);
}
);

test.capture(
"perspective-config-update event is fired when legend position is changed",
async (page) => {
// Await the viewer element to exist on the page
const viewer = await page.$("perspective-viewer");
await page.evaluate(async (viewer) => {
// Await the table load
await viewer.getTable();

viewer.restore({
plugin: "Y Line",
columns: ["Sales", "Profit"],
});

// Register a listener for `perspective-config-update` event
window.__legend_events__ = [];
viewer.addEventListener(
"perspective-config-update",
(evt) => {
window.__legend_events__.push(evt);
}
);
}, viewer);

const legend = (
await page.waitForFunction(() =>
document
.querySelector("perspective-viewer-d3fc-yline")
.shadowRoot.querySelector(".legend-container")
)
).asElement();

const boundingBox = await legend.boundingBox();

const start = {
x: boundingBox.x + boundingBox.width / 2,
y: boundingBox.y + boundingBox.height / 2,
};

const target = {
x: start.x - 300,
y: start.y,
};

await page.mouse.move(start.x, start.y);
await page.mouse.down();
await page.mouse.move(target.x, target.y);

const count = await page.evaluate(async (viewer) => {
// Await the plugin rendering
await viewer.flush();

// Count the events;
return window.__legend_events__.length;
}, viewer);

expect(count).toBeGreaterThan(0);

// Return the chart contents
return get_contents(page);
}
);
},
{reload_page: false, root: path.join(__dirname, "..", "..", "..")}
);
});
36 changes: 19 additions & 17 deletions packages/perspective-viewer-d3fc/test/results/results.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"__GIT_COMMIT__": "d776202ff728f808f1d07060e5ce73bb392402f1",
"__GIT_COMMIT__": "6715e8d349a9d8978f2e2a03346027d14cc9255b",
"area_shows_a_grid_without_any_settings_applied": "3852532b8ee6abba3373a10d41bb4df2",
"area_displays_visible_columns_": "919cc6f6c2a2f2ec13b90dfb60e1b7ef",
"area_pivot_by_a_row": "7495976cfed69cfe9db2b3fdc6ef4707",
Expand Down Expand Up @@ -93,17 +93,17 @@
"heatmap_filters_filters_with__in__comparator": "b9e271668af3836baf5a5d51226910a3",
"scatter_shows_a_grid_without_any_settings_applied": "9cbb9843a44b830cf4a324706a7bd713",
"scatter_displays_visible_columns_": "0519cc65006ebd80de93362817a7ce4f",
"scatter_pivot_by_a_row": "9cbb9843a44b830cf4a324706a7bd713",
"scatter_pivot_by_two_rows": "9cbb9843a44b830cf4a324706a7bd713",
"scatter_pivot_by_a_column": "9cbb9843a44b830cf4a324706a7bd713",
"scatter_pivot_by_a_row_and_a_column": "9cbb9843a44b830cf4a324706a7bd713",
"scatter_pivot_by_two_rows_and_two_columns": "9cbb9843a44b830cf4a324706a7bd713",
"scatter_sort_by_a_hidden_column": "9cbb9843a44b830cf4a324706a7bd713",
"scatter_sort_by_a_numeric_column": "9cbb9843a44b830cf4a324706a7bd713",
"scatter_sort_by_an_alpha_column": "01fa363fa5ef2e1aa66a77ed87e9225f",
"scatter_filters_filters_by_a_numeric_column": "37fd54838ea9dead5dc441bf1e62fbb9",
"scatter_filters_filters_by_an_alpha_column": "2b3728cca2c7518bb10382dd7ef0d4fd",
"scatter_filters_filters_with__in__comparator": "f44f7f144f9ee4827783a9b516f2a4e3",
"scatter_pivot_by_a_row": "afb75b167c5ea6be21c7b2121901a17f",
"scatter_pivot_by_two_rows": "afb75b167c5ea6be21c7b2121901a17f",
"scatter_pivot_by_a_column": "afb75b167c5ea6be21c7b2121901a17f",
"scatter_pivot_by_a_row_and_a_column": "afb75b167c5ea6be21c7b2121901a17f",
"scatter_pivot_by_two_rows_and_two_columns": "afb75b167c5ea6be21c7b2121901a17f",
"scatter_sort_by_a_hidden_column": "afb75b167c5ea6be21c7b2121901a17f",
"scatter_sort_by_a_numeric_column": "afb75b167c5ea6be21c7b2121901a17f",
"scatter_sort_by_an_alpha_column": "3a0440b79d5a068fc3e2c48b3d15a01e",
"scatter_filters_filters_by_a_numeric_column": "adbc354df9b4f69db72160fcad7bde74",
"scatter_filters_filters_by_an_alpha_column": "cf64a7ffdc6f150d1f535cf08679f052",
"scatter_filters_filters_with__in__comparator": "16fbc02857ffd2df180274a19c51c4f2",
"yscatter_shows_a_grid_without_any_settings_applied": "006aa96e87e006a01a0349f0c20ea27a",
"yscatter_displays_visible_columns_": "0bff95a36d9f0a0029599bb7adcc6af8",
"yscatter_pivot_by_a_row": "fb6504a26b1b859619a180b27d35f73b",
Expand All @@ -121,10 +121,10 @@
"sunburst_pivot_by_two_rows": "38fe70a8f88a3e0df185f8775c88317d",
"sunburst_pivot_by_a_row_and_a_column": "fa789a00c03e04567bd45a8451e7a00a",
"sunburst_pivot_by_two_rows_and_two_columns": "e03658ff241f45837b9d61227bf023a4",
"treemap_pivot_by_a_row": "7322fa73924e688662d36558a33ddb99",
"treemap_pivot_by_two_rows": "ce30c9196e830d54d4960d4f9a53ad32",
"treemap_pivot_by_a_row_and_a_column": "a9ee5c25d23fff12e57b7755ca310cb5",
"treemap_pivot_by_two_rows_and_two_columns": "fe5616df5b45c5b0b2f86489f7a1dc22",
"treemap_pivot_by_a_row": "d9e965d744906a2320148b73dc1fcb29",
"treemap_pivot_by_two_rows": "28390c90695be1b38bd2a05a984dd242",
"treemap_pivot_by_a_row_and_a_column": "a36877ce32fed64d1ae16807de27e9de",
"treemap_pivot_by_two_rows_and_two_columns": "92203a8d4778c041836361b56ff39174",
"treemap_shows_a_grid_without_any_settings_applied": "10d1208b485425756fcc932229386b02",
"treemap_displays_visible_columns_": "10d1208b485425756fcc932229386b02",
"treemap_pivot_by_a_column": "10d1208b485425756fcc932229386b02",
Expand All @@ -143,5 +143,7 @@
"sunburst_filters_filters_by_a_numeric_column": "10d1208b485425756fcc932229386b02",
"sunburst_filters_filters_by_an_alpha_column": "10d1208b485425756fcc932229386b02",
"sunburst_filters_filters_with__in__comparator": "10d1208b485425756fcc932229386b02",
"bar_rendering_bugs_correctly_render_when_a_bar_chart_has_non_equidistant_times_on_a_datetime_axis": "9e7617a454d83e328aaa3d25c8145a0e"
"bar_rendering_bugs_correctly_render_when_a_bar_chart_has_non_equidistant_times_on_a_datetime_axis": "9e7617a454d83e328aaa3d25c8145a0e",
"events_perspective-config-update_event_is_fired_when_series_axis_is_changed": "c07cb12b00fe628aba8751721f8f5498",
"events_perspective-config-update_event_is_fired_when_legend_position_is_changed": "c07cb12b00fe628aba8751721f8f5498"
}

0 comments on commit 9e69fd6

Please sign in to comment.