Skip to content

Commit

Permalink
Fix bar chart rendering bug #1561
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcolozzo authored and texodus committed Oct 16, 2021
1 parent ebced4c commit b07b2dd
Show file tree
Hide file tree
Showing 3 changed files with 229 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function barSeries(settings, color) {
return fc
.autoBandwidth(minBandwidth(series))
.crossValue((d) => d.crossValue)
.mainValue((d) => d.mainValue)
.mainValue((d) => (d.mainValue ? d.mainValue : 0))
.baseValue((d) => d.baseValue);
}

Expand Down
213 changes: 213 additions & 0 deletions packages/perspective-viewer-d3fc/test/js/integration/barWidth.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
/******************************************************************************
*
* Copyright (c) 2017, 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 render_warning_tests = require("@finos/perspective-viewer/test/js/render_warning_tests.js");

const {withTemplate} = require("./simple-template");

withTemplate("bar", "Y Bar");
withTemplate("bar-x", "X Bar");
withTemplate("bar-themed", "Y Bar", {template: "themed-template"});

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

utils.with_server({}, () => {
describe.page(
"bar.html",
() => {
describe("rendering bugs", () => {
test.capture(
"correctly render when a bar chart has non equidistant times on a datetime axis",
async (page) => {
const config = await page.evaluate(async () => {
const viewer =
document.querySelector("perspective-viewer");
await viewer.getTable();
await viewer.restore({
plugin: "Y Bar",
columns: ["Profit"],
row_pivots: ["Order Date"],
column_pivots: ["Profit"],
});
return await viewer.save();
});

expect(config).toEqual({
plugin: "Y Bar",
columns: ["Profit"],
row_pivots: ["Order Date"],
column_pivots: ["Profit"],
aggregates: {},
filter: [],
sort: [],
plugin_config: {},
settings: false,
expressions: [],
});

return await get_contents("ybar")(page);
}
);
});
},
{root: path.join(__dirname, "..", "..", "..")}
);
});

// async function get_contents(page) {
// return await page.evaluate(async () => {
// const viewer = document
// .querySelector("perspective-viewer")
// .shadowRoot.querySelector("#app_panel");
// return viewer ? viewer.innerHTML : "MISSING";
// });
// }

// utils.with_server({}, () => {
// describe.page(
// "superstore.html",
// () => {
// test.capture("save returns the current config", async (page) => {
// const config = await page.evaluate(async () => {
// const viewer = document.querySelector("perspective-viewer");
// await viewer.getTable();
// await viewer.restore({
// settings: true,
// row_pivots: ["State"],
// columns: ["Profit", "Sales"],
// });
// return await viewer.save();
// });

// expect(config).toEqual({
// aggregates: {},
// column_pivots: [],
// columns: ["Profit", "Sales"],
// expressions: [],
// filter: [],
// plugin: "Debug",
// plugin_config: {},
// row_pivots: ["State"],
// settings: true,
// sort: [],
// });

// return await get_contents(page);
// });

// test.capture(
// "restore restores a config from save",
// async (page) => {
// const config = await page.evaluate(async () => {
// const viewer =
// document.querySelector("perspective-viewer");
// await viewer.getTable();
// await viewer.restore({
// settings: true,
// row_pivots: ["State"],
// columns: ["Profit", "Sales"],
// });
// return await viewer.save();
// });

// expect(config).toEqual({
// aggregates: {},
// column_pivots: [],
// columns: ["Profit", "Sales"],
// expressions: [],
// filter: [],
// plugin: "Debug",
// plugin_config: {},
// row_pivots: ["State"],
// settings: true,
// sort: [],
// });

// const config2 = await page.evaluate(async () => {
// const viewer =
// document.querySelector("perspective-viewer");
// await viewer.reset();
// return await viewer.save();
// });

// expect(config2).toEqual({
// aggregates: {},
// column_pivots: [],
// columns: [
// "Row ID",
// "Order ID",
// "Order Date",
// "Ship Date",
// "Ship Mode",
// "Customer ID",
// "Segment",
// "Country",
// "City",
// "State",
// "Postal Code",
// "Region",
// "Product ID",
// "Category",
// "Sub-Category",
// "Sales",
// "Quantity",
// "Discount",
// "Profit",
// ],
// expressions: [],
// filter: [],
// plugin: "Debug",
// plugin_config: {},
// row_pivots: [],
// settings: true,
// sort: [],
// });

// const config3 = await page.evaluate(async (config) => {
// const viewer =
// document.querySelector("perspective-viewer");
// await viewer.restore(config);
// return await viewer.save();
// }, config);

// expect(config3).toEqual({
// aggregates: {},
// column_pivots: [],
// columns: ["Profit", "Sales"],
// expressions: [],
// filter: [],
// plugin: "Debug",
// plugin_config: {},
// row_pivots: ["State"],
// settings: true,
// sort: [],
// });

// return await get_contents(page);
// }
// );
// },
// {root: path.join(__dirname, "..", "..")}
// );
// });
29 changes: 15 additions & 14 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__": "e1fef0af227cbeb0b09f396349bb03b4a3845177",
"__GIT_COMMIT__": "c6555d41537d30f7b70ce28fbc594ab50ef013fc",
"area_shows_a_grid_without_any_settings_applied": "3852532b8ee6abba3373a10d41bb4df2",
"area_displays_visible_columns_": "919cc6f6c2a2f2ec13b90dfb60e1b7ef",
"area_pivot_by_a_row": "7495976cfed69cfe9db2b3fdc6ef4707",
Expand All @@ -14,38 +14,38 @@
"area_filters_filters_by_an_alpha_column": "a45bdbf8ed5240a2e3aa8beb74c43be5",
"area_filters_filters_with__in__comparator": "f4531a4d7a9a981e55391c347bed3e6c",
"bar_shows_a_grid_without_any_settings_applied": "67433692b144ca07b3171c0f74333afb",
"bar_displays_visible_columns_": "02feeb84263524f1acbaff015d369f55",
"bar_displays_visible_columns_": "eb3618e1cad5fa84e0edaebfbdc660de",
"bar_pivot_by_a_row": "0b35d45ec490bcc56a519afc9ed87d67",
"bar_pivot_by_two_rows": "642b4a4c45fef0cc5719a682b661a00d",
"bar_pivot_by_a_column": "a07dc459cf178d767fda55f45c87979b",
"bar_pivot_by_a_row_and_a_column": "8b419bde5e7e23a5902cd2961c198002",
"bar_pivot_by_two_rows_and_two_columns": "d318e63c94cf518665b25522a0ace02a",
"bar_pivot_by_a_column": "63494dd5721e58abbfb0ec7011f965f7",
"bar_pivot_by_a_row_and_a_column": "732fdb88830140d05c3a9cc13d82e1a6",
"bar_pivot_by_two_rows_and_two_columns": "623d1237084f92a0f86029ca9fde9116",
"bar_sort_by_a_hidden_column": "31d8cfb3e1243ad1b322ad0437b2271e",
"bar_sort_by_a_numeric_column": "cf348b1ab0de8f2aa51a7c7bf734ef9d",
"bar_sort_by_an_alpha_column": "827ad95a12fc1a4aea2256aaac308c98",
"bar_filters_filters_by_a_numeric_column": "3a0a6628e8ae24ae602b322ee007a3a8",
"bar_filters_filters_by_an_alpha_column": "742c4a14b33989a9d644445c253a7b60",
"bar_filters_filters_with__in__comparator": "a9b4dbeb4910b7f6cd8481ac0e1eb4a8",
"bar-x_shows_a_grid_without_any_settings_applied": "94aa945b63686cd82c3ef6313ddb4a19",
"bar-x_displays_visible_columns_": "67882a2c76ce9eaa83a7ba364d434974",
"bar-x_displays_visible_columns_": "22577f2c9ad0c7aaacb2cae440ba5b05",
"bar-x_pivot_by_a_row": "501875ed4e61cedfb49011b78b12b849",
"bar-x_pivot_by_two_rows": "a796f113b6cf7bc5ec10a60e7b0896f4",
"bar-x_pivot_by_a_column": "52a9b8211c6b263958460f4539401249",
"bar-x_pivot_by_a_row_and_a_column": "f4d5a2729da84676a68aef34fdaf0260",
"bar-x_pivot_by_two_rows_and_two_columns": "6ae8ee1cf77fc59333069f7c9a840c4a",
"bar-x_pivot_by_a_column": "a1d3896af9bbce1922d3bbaf03b9b895",
"bar-x_pivot_by_a_row_and_a_column": "6bda307025500dabebc174dfbf318bcc",
"bar-x_pivot_by_two_rows_and_two_columns": "204a2dc01e01bafcdb3a7c2f2be862d4",
"bar-x_sort_by_a_hidden_column": "ca8fe5a0d7513076028d0f8f590d0020",
"bar-x_sort_by_a_numeric_column": "b3a46f3536eb9d58e738f2825e370370",
"bar-x_sort_by_an_alpha_column": "e562dbae536932a00728f546f78238a5",
"bar-x_filters_filters_by_a_numeric_column": "4004fe31281d735cec230a82d51fec90",
"bar-x_filters_filters_by_an_alpha_column": "d59401b3bd9f84a147418805cdac94f4",
"bar-x_filters_filters_with__in__comparator": "20c666c449ed4353e0b3747d0df2e174",
"bar-themed_shows_a_grid_without_any_settings_applied": "67433692b144ca07b3171c0f74333afb",
"bar-themed_displays_visible_columns_": "02feeb84263524f1acbaff015d369f55",
"bar-themed_displays_visible_columns_": "eb3618e1cad5fa84e0edaebfbdc660de",
"bar-themed_pivot_by_a_row": "0b35d45ec490bcc56a519afc9ed87d67",
"bar-themed_pivot_by_two_rows": "642b4a4c45fef0cc5719a682b661a00d",
"bar-themed_pivot_by_a_column": "a07dc459cf178d767fda55f45c87979b",
"bar-themed_pivot_by_a_row_and_a_column": "8b419bde5e7e23a5902cd2961c198002",
"bar-themed_pivot_by_two_rows_and_two_columns": "d318e63c94cf518665b25522a0ace02a",
"bar-themed_pivot_by_a_column": "63494dd5721e58abbfb0ec7011f965f7",
"bar-themed_pivot_by_a_row_and_a_column": "732fdb88830140d05c3a9cc13d82e1a6",
"bar-themed_pivot_by_two_rows_and_two_columns": "623d1237084f92a0f86029ca9fde9116",
"bar-themed_sort_by_a_hidden_column": "31d8cfb3e1243ad1b322ad0437b2271e",
"bar-themed_sort_by_a_numeric_column": "cf348b1ab0de8f2aa51a7c7bf734ef9d",
"bar-themed_sort_by_an_alpha_column": "827ad95a12fc1a4aea2256aaac308c98",
Expand Down Expand Up @@ -142,5 +142,6 @@
"sunburst_sort_by_an_alpha_column": "10d1208b485425756fcc932229386b02",
"sunburst_filters_filters_by_a_numeric_column": "10d1208b485425756fcc932229386b02",
"sunburst_filters_filters_by_an_alpha_column": "10d1208b485425756fcc932229386b02",
"sunburst_filters_filters_with__in__comparator": "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"
}

0 comments on commit b07b2dd

Please sign in to comment.