Skip to content

Commit

Permalink
Merge pull request #185 from jpmorganchase/schema-fix
Browse files Browse the repository at this point in the history
Schema fix
  • Loading branch information
texodus authored Aug 9, 2018
2 parents b1d8360 + 0038f53 commit b075f0a
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 41 deletions.
4 changes: 1 addition & 3 deletions packages/perspective-viewer-highcharts/test/js/bar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ utils.with_server({}, () => {
const tooltip_selector = '.highcharts-label.highcharts-tooltip';
const text = tooltip_selector + ' > text';

test.run('tooltip shows on hover.', async page => {
test.capture('tooltip shows on hover.', async page => {
await utils.invoke_tooltip(bar, page);
return await page.$eval(
tooltip_selector, element => element.getAttribute('opacity') === '1');
});

test.run('tooltip shows column label.', async page => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ utils.with_server({}, () => {

describe('tooltip tests', () => {
const text = '.highcharts-label.highcharts-tooltip > text';
const point = '.highcharts-point';

test.capture('tooltip shows on hover.', async page => {
await utils.invoke_tooltip(point, page);
});

test.run("tooltip shows a value.", async page => {
await utils.invoke_tooltip('.highcharts-point', page);
await utils.invoke_tooltip(point, page);
return await page.$eval(
text, element => element.textContent !== "");
});
Expand Down
6 changes: 1 addition & 5 deletions packages/perspective-viewer-highcharts/test/js/line.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,12 @@ utils.with_server({}, () => {
const tooltip_selector = '.highcharts-label.highcharts-tooltip';
const text = tooltip_selector + ' > text';

test.run('tooltip shows on hover.', async page => {
test.capture('tooltip shows on hover.', async page => {
await page.click('#config_button');
await page.$('perspective-viewer');
await utils.invoke_tooltip(series, page);
return await page.$eval(
tooltip_selector,
element => element.getAttribute('opacity') === '1');
});


test.run('tooltip shows proper column labels.', async page => {
await page.click('#config_button');
await page.$('perspective-viewer');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,12 @@ utils.with_server({}, () => {
const tooltip_selector = '.highcharts-label.highcharts-tooltip';
const text = tooltip_selector + ' > text';

test.run("tooltip shows on hover.", async page => {
test.capture('tooltip shows on hover.', async page => {
await page.click('#config_button');
await page.$("perspective-viewer");

await utils.invoke_tooltip(point, page);
return await page.$eval(tooltip_selector,
element => element.getAttribute('opacity') === '1');
});


test.run("tooltip shows proper column labels.", async page => {
await page.click('#config_button');
await page.$("perspective-viewer");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ utils.with_server({}, () => {

describe('tooltip tests', () => {

test.run("tooltip shows on hover.", async page => {
test.capture('tooltip shows on hover.', async page => {
await page.click('#config_button');
const viewer = await page.$("perspective-viewer");

Expand All @@ -31,8 +31,6 @@ utils.with_server({}, () => {
await page.waitForSelector('perspective-viewer:not([updating])');

await utils.invoke_tooltip('.highcharts-point', page);
return await page.$eval('.highcharts-tooltip',
element => element.getAttribute('opacity') === '1');
});
});

Expand Down
35 changes: 20 additions & 15 deletions packages/perspective-viewer-highcharts/test/results/results.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,28 @@
"superstore.html/sorts by a numeric column.": "375062fbd50e09afa7b6df7e6b4a3a5f",
"superstore.html/sorts by an alpha column.": "2643e0b5787b6e8e85f122b1713d01cd",
"superstore.html/displays visible columns.": "1da296527f149393be8f3f99e34b3e4a",
"scatter.html/shows a grid without any settings applied.": "347af5199ea79a910371040b8d522e1a",
"scatter.html/pivots by a row.": "cc93f57242048601487b0249ac3425b7",
"scatter.html/pivots by two rows.": "f633ceb2d8cb4d2eb48665137a311d2a",
"scatter.html/pivots by a row and a column.": "3f0f6fc873944f49b8b4c30a96f5597a",
"scatter.html/pivots by two rows and two columns.": "d949d347caf76b387bce9bfab5923898",
"scatter.html/sorts by a numeric column.": "416502fb7a86db10d77f2bd38f882bce",
"scatter.html/sorts by an alpha column.": "59ec9b3c81e64a9ef48127d0b6fd7439",
"scatter.html/displays visible columns.": "d73ac37284066261219c64e626451ad2",
"bar.html/shows a grid without any settings applied.": "a12733749a41c34bc7664c5271b659a5",
"bar.html/pivots by a row.": "93b8a823c927a02641a3aa394a5a3ef0",
"bar.html/pivots by two rows.": "3e75a8f255d9d111c54fa1e835315fd0",
"bar.html/pivots by a row and a column.": "6a707a6fe1a125a80bbf5b0bdf3c28a1",
"bar.html/pivots by two rows and two columns.": "57a496db707dceecd82dff30cd6389a9",
"bar.html/sorts by a numeric column.": "59616b02a997af70f1b9399898ed65dc",
"bar.html/filters by a numeric column.": "3588e6e5ff1171a0b8a55ac834583f82",
"bar.html/sorts by an alpha column.": "9f5ecb239cbef2729692cf16ad25ec54",
"bar.html/sorts by a hidden column.": "f0bc729adf33735b90511132bfa96734",
"bar.html/displays visible columns.": "256c396aed2c8223101c3e212f92fc1d",
"bar.html/tooltip shows on hover.": "f051aacf0b647fc41c664604a61062ca",
"line.html/shows a grid without any settings applied.": "36efa1d28a7737d520ab014568a2759e",
"line.html/pivots by a row.": "f93cab70af19db3ade6684360ddcd206",
"line.html/pivots by two rows.": "f3bf3c0f30ff01bcb201a9b753fa7226",
"line.html/pivots by a row and a column.": "d0ee7ec2db5418ffdcf920a219830789",
"line.html/pivots by two rows and two columns.": "8ae9a7702c77c7888f4bc74d157798d7",
"line.html/sorts by a numeric column.": "fa07a1bb87370f982ca772db098da599",
"line.html/sorts by an alpha column.": "47ff12237bc6c0a0493cec852915882d",
"line.html/displays visible columns.": "0114f63b6166bcc313e9a8fcd04b91f5",
"bar.html/displays visible columns.": "256c396aed2c8223101c3e212f92fc1d",
"scatter.html/sorts by a hidden column.": "685ae3c16b4bf6ee72687368b5bbf996",
"line.html/sorts by a hidden column.": "e31e6309a8f90761a191f552999cf23b",
"bar.html/sorts by a hidden column.": "f0bc729adf33735b90511132bfa96734",
"scatter.html/filters by a numeric column.": "2afc34dd68ac113e0fb15bd12cb122fd",
"line.html/filters by a numeric column.": "a14b081c18a15871f009fcb9264af2dd",
"bar.html/filters by a numeric column.": "3588e6e5ff1171a0b8a55ac834583f82",
"line.html/displays visible columns.": "0114f63b6166bcc313e9a8fcd04b91f5",
"line.html/tooltip shows on hover.": "ae22ee115b4bcd86e3226332828eeebc",
"heatmap.html/shows a grid without any settings applied.": "098bdc3c3041404117876d7da1602ac8",
"heatmap.html/pivots by a row.": "9bacc36695164e236fae2a885be1f7f4",
"heatmap.html/pivots by two rows.": "75ab2607aed4b67e448c9c8d830ba24b",
Expand All @@ -47,6 +39,18 @@
"heatmap.html/filters by a numeric column.": "88c49b785eb0b24117fdb3f3a9a51d6b",
"heatmap.html/sorts by an alpha column.": "7aaea8713a032a5cf92eb23a601cf655",
"heatmap.html/displays visible columns.": "519d0b4b7c23ac9be8b031bb311c63a6",
"heatmap.html/tooltip shows on hover.": "25caa0ddd3880ff2c2f16f4891bc3dd9",
"scatter.html/shows a grid without any settings applied.": "347af5199ea79a910371040b8d522e1a",
"scatter.html/pivots by a row.": "cc93f57242048601487b0249ac3425b7",
"scatter.html/pivots by two rows.": "f633ceb2d8cb4d2eb48665137a311d2a",
"scatter.html/pivots by a row and a column.": "3f0f6fc873944f49b8b4c30a96f5597a",
"scatter.html/pivots by two rows and two columns.": "d949d347caf76b387bce9bfab5923898",
"scatter.html/sorts by a hidden column.": "685ae3c16b4bf6ee72687368b5bbf996",
"scatter.html/sorts by a numeric column.": "416502fb7a86db10d77f2bd38f882bce",
"scatter.html/filters by a numeric column.": "2afc34dd68ac113e0fb15bd12cb122fd",
"scatter.html/sorts by an alpha column.": "59ec9b3c81e64a9ef48127d0b6fd7439",
"scatter.html/displays visible columns.": "d73ac37284066261219c64e626451ad2",
"scatter.html/tooltip shows on hover.": "64714096c8a360dc816d3dd67eb0322f",
"treemap.html/shows a grid without any settings applied.": "1453de0677c0f278c4fa69f4c27fb400",
"treemap.html/pivots by a row.": "e2f57f9ffbff639d731fc46e9891261c",
"treemap.html/pivots by two rows.": "172ebd217611662244baa45ca9ae3354",
Expand All @@ -56,5 +60,6 @@
"treemap.html/sorts by a numeric column.": "53b5d4d89c358ae4ac59d9fa496f4ee3",
"treemap.html/filters by a numeric column.": "e79978195df664206e4d8e233a408b6f",
"treemap.html/sorts by an alpha column.": "cf3c51e9b18fddade098bd7203ed4832",
"treemap.html/displays visible columns.": "7f8e4756e554bc34920ea32eaf0373ae"
"treemap.html/displays visible columns.": "7f8e4756e554bc34920ea32eaf0373ae",
"treemap.html/tooltip shows on hover.": "d82160988637350390ed0f1c13794762"
}
27 changes: 18 additions & 9 deletions packages/perspective/src/js/perspective.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,19 +482,28 @@ view.prototype.schema = async function() {
} else if (types[col_name] === 12) {
new_schema[col_name] = "date";
}
if (this.sides() > 0) {
for (let agg in this.config.aggregate) {
agg = this.config.aggregate[agg];
if (agg.column.join(',') === col_name) {
if (["distinct count", "distinctcount", "distinct", "count"].indexOf(agg.op) > -1) {
new_schema[col_name] = "integer";
}
if (this.sides() > 0 && this.config.row_pivot.length > 0) {
new_schema[col_name] = map_aggregate_types(col_name, new_schema[col_name], this.config.aggregate);
}
}
return new_schema;
}

}
const map_aggregate_types = function(col_name, orig_type, aggregate) {
const INTEGER_AGGS = ["distinct count", "distinctcount", "distinct", "count"];
const FLOAT_AGGS = ["avg", "mean", "mean by count", "weighted_mean", "pct sum parent", "pct sum grand total"];

for (let agg in aggregate) {
let found_agg = aggregate[agg];
if (found_agg.column.join(',') === col_name) {
if (INTEGER_AGGS.includes(found_agg.op)) {
return "integer";
} else if (FLOAT_AGGS.includes(found_agg.op)) {
return "float";
}
}
}
return new_schema;
return orig_type;
}

const to_format = async function (options, formatter) {
Expand Down
30 changes: 30 additions & 0 deletions packages/perspective/test/js/pivots.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,36 @@ module.exports = (perspective) => {
expect(result2).toEqual(meta);
});

it("['x'] translates type `string` to `integer` when pivoted by row", async function () {
var table = perspective.table(data);
var view = table.view({
row_pivot: ['x'],
aggregate: [{column: 'y', op: 'distinct count'}]
});
let result2 = await view.schema();
expect(result2).toEqual({y: 'integer'});
});

it("['x'] translates type `integer` to `float` when pivoted by row", async function () {
var table = perspective.table(data);
var view = table.view({
row_pivot: ['y'],
aggregate: [{column: 'x', op: 'avg'}]
});
let result2 = await view.schema();
expect(result2).toEqual({x: 'float'});
});

it("['x'] does not translate type when only pivoted by column", async function () {
var table = perspective.table(data);
var view = table.view({
col_pivot: ['y'],
aggregate: [{column: 'x', op: 'avg'}]
});
let result2 = await view.schema();
expect(result2).toEqual({x: 'integer'});
});

it("['x'] has the correct # of rows", async function () {
var table = perspective.table(data);
var view = table.view({
Expand Down

0 comments on commit b075f0a

Please sign in to comment.