Skip to content

Commit

Permalink
Fixed empty hypergrid loading error #264
Browse files Browse the repository at this point in the history
  • Loading branch information
texodus committed Oct 25, 2018
1 parent c31c955 commit 82a8ec1
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/perspective-viewer-hypergrid/src/js/hypergrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ async function grid_create(div, view, task) {
perspectiveHypergridElement.set_data(json, hidden, schema, tschema, rowPivots);
this.hypergrid.canvas.paintNow();
let running = true;
while (running) {
while (nrows > 0 && running) {
running = await new Promise(resolve => dataModel.fetchData(undefined, resolve));
if (running) {
await new Promise(resolve => setTimeout(resolve, 10));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ function filter_hidden(hidden, json) {

function psp2hypergrid(data, hidden, schema, tschema, row_pivots) {
data = filter_hidden(hidden, data);
const firstcol = Object.keys(data)[0];
if (data[firstcol].length === 0) {
const colnames = Object.keys(data);
const firstcol = colnames.length > 0 ? colnames[0] : undefined;
if (colnames.length === 0 || data[firstcol].length === 0) {
let columns = Object.keys(schema);
return {
rows: [],
Expand Down
34 changes: 34 additions & 0 deletions packages/perspective-viewer-hypergrid/test/html/empty.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!--
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.
-->

<!DOCTYPE html>
<html>
<head>

<script src="perspective.view.js"></script>
<script src="hypergrid.plugin.js"></script>

<link rel='stylesheet' href="demo.css">

</head>
<body>

<perspective-viewer>

</perspective-viewer>

<script>

var viewer = document.getElementsByTagName('perspective-viewer')[0];
viewer.load({x: "integer"});

</script>

</body>
</html>
10 changes: 10 additions & 0 deletions packages/perspective-viewer-hypergrid/test/js/regressions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ async function capture_update(page, viewer, body) {
}

utils.with_server({}, () => {
describe.page("empty.html", () => {
test.capture("empty grids do not explode", async page => {
const viewer = await page.$("perspective-viewer");
await page.evaluate(element => element.shadowRoot.querySelector("#config_button").click(), viewer);
await page.waitFor("perspective-viewer:not([updating])");
await capture_update(page, viewer, () => page.evaluate(element => element.update([{x: 3}]), viewer));
await page.waitFor("perspective-viewer:not([updating])");
});
});

describe.page("regressions.html", () => {
describe("Updates", () => {
test.capture("regular updates", async page => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
"superstore.html/filters by a numeric column.": "f2bbde9e67461a6607e2630771aed363",
"superstore.html/pivots by a column.": "fb5e1247513754c9bbf206f002c3b0a3",
"superstore.html/collapses to depth smaller than viewport": "bdd25c1c40781478bd040d5816b887a6",
"regressions.html/saving a computed column does not interrupt update rendering": "6f6bfce96b1120c67bf6145b00225c9e"
"regressions.html/saving a computed column does not interrupt update rendering": "6f6bfce96b1120c67bf6145b00225c9e",
"empty.html/empty grids do not explode": "77797cda77c9ab250d4c84e7ca44188a"
}

0 comments on commit 82a8ec1

Please sign in to comment.