Skip to content

Commit

Permalink
Merge pull request #666 from finos/computed-column-fix
Browse files Browse the repository at this point in the history
Fixes user defined aggregates for computed columns
  • Loading branch information
texodus authored Jul 25, 2019
2 parents 1bebf98 + d21e5b6 commit d6c3ce6
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/perspective-viewer-d3fc/test/results/results.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,5 @@
"sunburst.html/highlights invalid filter.": "e48566c24b1655a202d1d227424f71c5",
"sunburst.html/sorts by an alpha column.": "dca6a09d9b0c4b4a3fd6cdb91fa1eb1a",
"sunburst.html/displays visible columns.": "92769650f8ccaf823d070f3bd12aa73b",
"__GIT_COMMIT__": "b35932f5217f9847c9684a980b6a50f675c9a8d2"
"__GIT_COMMIT__": "e821170c1e341e1b54d83a7d76a54009aa5a35ab"
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,5 @@
"bar.html/perspective dispatches perspective-click event with one filter.": "32d64db28af46dfe77fad5cc1ca8af9c",
"bar.html/perspective dispatches perspective-click event with filters.": "c18f49270244dfe4a6b32270ec30d99d",
"bar.html/dates on the x-axis display correctly.": "591a1c8e9493451b6885b9651917ffff",
"__GIT_COMMIT__": "b35932f5217f9847c9684a980b6a50f675c9a8d2"
"__GIT_COMMIT__": "e821170c1e341e1b54d83a7d76a54009aa5a35ab"
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
"superstore.html/shows a sort indicator": "bea0d6800110d9e7289c3d6fa1a42f33",
"superstore.html/shows multiple sort indicators": "d61716d5e6ee368ed51f6ac1f3759195",
"superstore.html/shows a sort indicator on column split": "21cc1a4820cccebf53df2dee77e9ab0f",
"__GIT_COMMIT__": "b35932f5217f9847c9684a980b6a50f675c9a8d2",
"__GIT_COMMIT__": "e821170c1e341e1b54d83a7d76a54009aa5a35ab",
"superstore.html/should reinterpret metadata when only row pivots are changed": "998f6962e318ce6fe2d38a79b316e8fa"
}
14 changes: 9 additions & 5 deletions packages/perspective-viewer/src/js/viewer/perspective_element.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,17 @@ export class PerspectiveElement extends StateElement {
cols.sort(column_sorter(schema));

// Update aggregates
const computed_aggregates = Object.entries(computed_schema).map(([column, op]) => ({
column,
op
}));
const aggregate_attribute = this.get_aggregate_attribute();

Object.entries(computed_schema).forEach(([column, op]) => {
const already_configured = aggregate_attribute.find(agg => agg.column === column);
if (!already_configured) {
aggregate_attribute.push({column, op});
}
});

const all_cols = cols.concat(Object.keys(computed_schema));
const aggregates = get_aggregates_with_defaults(this.get_aggregate_attribute().concat(computed_aggregates), schema, all_cols);
const aggregates = get_aggregates_with_defaults(aggregate_attribute, schema, all_cols);

let shown = JSON.parse(this.getAttribute("columns")).filter(x => all_cols.indexOf(x) > -1);
if (shown.length === 0) {
Expand Down
14 changes: 14 additions & 0 deletions packages/perspective-viewer/test/js/computed_columns.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,20 @@ utils.with_server({}, () => {
await page.evaluate(element => element.setAttribute("columns", '["Row ID", "Quantity"]'), viewer);
await page.evaluate(element => element.setAttribute("columns", '["Row ID", "Quantity", "new_cc"]'), viewer);
});

test.capture("user defined aggregates maintained on computed columns", async page => {
const viewer = await page.$("perspective-viewer");
await page.shadow_click("perspective-viewer", "#config_button");

await page.evaluate(element => {
element.restore({
aggregates: {Computed: "mean"},
"computed-columns": [{name: "Computed", inputs: ["Sales", "Profit"], func: "add"}],
columns: ["Computed", "Quantity"],
"row-pivots": ["Category"]
});
}, viewer);
});
},
{
root: path.join(__dirname, "..", "..")
Expand Down
5 changes: 3 additions & 2 deletions packages/perspective-viewer/test/results/results.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"superstore.html/saving a duplicate column should fail with error message.": "d9618357228698c5fbe9978b3ed1f668",
"superstore.html/highlights invalid filter.": "b31284a7b2a401d232ed077ec097a653",
"superstore.html/replaces all rows.": "7a7265b18d5c94f8f90abcad4f3f7781",
"__GIT_COMMIT__": "b35932f5217f9847c9684a980b6a50f675c9a8d2",
"__GIT_COMMIT__": "e821170c1e341e1b54d83a7d76a54009aa5a35ab",
"superstore.html/shows horizontal columns on small vertical viewports.": "05d7c917b5eb9e05387d52e3a6372c67",
"superstore.html/shows horizontal columns on small vertical and horizontal viewports.": "4cde889ccdbecba750e76f287707626f"
"superstore.html/shows horizontal columns on small vertical and horizontal viewports.": "4cde889ccdbecba750e76f287707626f",
"superstore.html/user defined aggregates maintained on computed columns": "4047d2fd3b973a0492f805da9f604dbc"
}

0 comments on commit d6c3ce6

Please sign in to comment.