Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remote performance #190

Merged
merged 5 commits into from
Aug 14, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Hypergrid ported to to_columns
  • Loading branch information
texodus committed Aug 14, 2018
commit a608c198bcc36ac3d1e6f2fd0910758d14e21b58
6 changes: 3 additions & 3 deletions packages/perspective-viewer-hypergrid/src/js/hypergrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const Range = require('./Range');
const perspectivePlugin = require('./perspective-plugin');
const PerspectiveDataModel = require('./PerspectiveDataModel');
const treeLineRendererPaint = require('./hypergrid-tree-cell-renderer').treeLineRendererPaint;
const psp2hypergrid = require('./psp-to-hypergrid');
const {psp2hypergrid} = require('./psp-to-hypergrid');

import {bindTemplate} from "@jpmorganchase/perspective-viewer/src/js/utils.js";

Expand Down Expand Up @@ -315,7 +315,7 @@ async function grid_create(div, view, task) {
const colPivots = JSON.parse(this.getAttribute('column-pivots'));
const [nrows, json, schema, tschema] = await Promise.all([
view.num_rows(),
view.to_json(Range.create(0, colPivots.length + 1)),
view.to_columns(Range.create(0, colPivots.length + 1)),
view.schema(),
this._table.schema()
]);
Expand All @@ -339,7 +339,7 @@ async function grid_create(div, view, task) {
dataModel._view = view;

dataModel.pspFetch = async function (range) {
let next_page = await view.to_json(range);
let next_page = await view.to_columns(range);
this.data = [];
const rows = psp2hypergrid(next_page, hidden, schema, tschema, rowPivots).rows;
const data = this.data
Expand Down
55 changes: 22 additions & 33 deletions packages/perspective-viewer-hypergrid/src/js/psp-to-hypergrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,19 @@
const TREE_COLUMN_INDEX = require('fin-hypergrid/src/behaviors/Behavior').prototype.treeColumnIndex;

function filter_hidden(hidden, json) {
if (hidden.length > 0) {
const first = json[0];
const to_delete = [];
for (let key in first) {
const split_key = key.split(',');
if (hidden.indexOf(split_key[split_key.length - 1].trim()) >= 0) {
to_delete.push(key);
}
}
for (let row of json) {
for (let h of to_delete) {
delete row[h];
}
for (let key of Object.keys(json)) {
const split_key = key.split(',');
if (hidden.indexOf(split_key[split_key.length - 1].trim()) >= 0) {
delete json[key];
}
}
return json;
}

module.exports = function psp2hypergrid(data, hidden, schema, tschema, row_pivots) {
function psp2hypergrid(data, hidden, schema, tschema, row_pivots) {
data = filter_hidden(hidden, data);
if (data.length === 0) {
const firstcol = Object.keys(data)[0];
if (data[firstcol].length === 0) {
let columns = Object.keys(schema);
return {
rows: [],
Expand All @@ -43,40 +35,35 @@ module.exports = function psp2hypergrid(data, hidden, schema, tschema, row_pivot

var is_tree = !!row_pivots.length;

var flat_columns = Object.keys(data[0]).filter(row => row !== '__ROW_PATH__');
var flat_columns = Object.keys(data).filter(row => row !== '__ROW_PATH__');
var columnPaths = flat_columns.map(row => row.split(','));

let rows = data.map(function (row, idx) {
// `dataRow` (element of `dataModel.data`) keys will be `index` here rather than
// `columnName` because pivoted data have obscure column names of little use to developer.
// This also allows us to override `dataModel.getValue` with a slightly more efficient version
// that doesn't require mapping the name through `dataModel.dataSource.schema` to get the index.
let rows = [];

for (let idx = 0; idx < data[firstcol].length; idx++) {

let dataRow = flat_columns.reduce(function (dataRow, columnName, index) {
dataRow[index] = row[columnName];
dataRow[index] = data[columnName][idx];
return dataRow;
}, {});
rows.push(dataRow);

if (is_tree) {
if (row.__ROW_PATH__ === undefined) {
row.__ROW_PATH__ = [];
if (data['__ROW_PATH__'][idx] === undefined) {
data['__ROW_PATH__'][idx] = [];
}

let name = row.__ROW_PATH__[row.__ROW_PATH__.length - 1];
let name = data['__ROW_PATH__'][idx][data['__ROW_PATH__'][idx].length - 1];
if (name === undefined && idx === 0) {
name = 'TOTAL';
}

// Following stores the tree column under [-1] rather than ['Tree'] so our `getValue`
// override can access it using the tree column index rather than the tree column name.
dataRow[TREE_COLUMN_INDEX] = {
rollup: name,
rowPath: ['ROOT'].concat(row.__ROW_PATH__),
isLeaf: row.__ROW_PATH__.length >= row_pivots.length
rowPath: ['ROOT'].concat(data['__ROW_PATH__'][idx]),
isLeaf: data['__ROW_PATH__'][idx].length >= row_pivots.length
};
}

return dataRow;
});
}

return {
rows: rows,
Expand All @@ -87,3 +74,5 @@ module.exports = function psp2hypergrid(data, hidden, schema, tschema, row_pivot
.concat(columnPaths.map(col => schema[col[col.length - 1]]))
};
};

module.exports = {psp2hypergrid}