Skip to content

Commit

Permalink
Merge pull request #785 from finos/release-fixes
Browse files Browse the repository at this point in the history
Hypergrid paintloop removal
  • Loading branch information
texodus authored Oct 30, 2019
2 parents c1a6ff1 + e0be2ef commit 968393b
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 61 deletions.
3 changes: 1 addition & 2 deletions examples/phosphor/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import perspective from "@finos/perspective";
import {PerspectiveWorkspace, PerspectiveWidget} from "@finos/perspective-phosphor";
import {Widget} from "@phosphor/widgets";
import "@finos/perspective-phosphor/src/theme/vaporwave/index.less";
import "@finos/perspective-phosphor/src/theme/material/index.less";

import "@finos/perspective-viewer-hypergrid";
import "@finos/perspective-viewer-d3fc";
Expand Down Expand Up @@ -58,5 +58,4 @@ window.addEventListener("load", async () => {
};

window.workspace = workspace;

});
2 changes: 1 addition & 1 deletion packages/perspective-viewer-hypergrid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@finos/perspective-viewer": "^0.4.0-rc.1",
"core-js": "^2.6.9",
"datasaur-local": "3.0.0",
"faux-hypergrid": "3.2.1",
"faux-hypergrid": "3.2.2",
"fin-hypergrid-grouped-header-plugin": "^1.2.4",
"lodash": "^4.17.4",
"rectangular": "1.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ function find_row(rows, index) {
return -1;
}

const _wrapper = function(f) {
return async function(_, resolve) {
try {
const is_error = await f.call(this);
resolve(is_error);
} catch (e) {
resolve(e);
}
};
};

export default require("datasaur-local").extend("PerspectiveDataModel", {
isTreeCol: function(x) {
return x === TREE_COLUMN_INDEX && this.isTree();
Expand Down Expand Up @@ -70,7 +81,6 @@ export default require("datasaur-local").extend("PerspectiveDataModel", {
}
this._dirty = true;
this._nrows = nrows;
this._grid.behaviorChanged();
},

// Called when clicking on a row group expand
Expand Down Expand Up @@ -136,50 +146,41 @@ export default require("datasaur-local").extend("PerspectiveDataModel", {
}
},

fetchData: async function(_, resolve) {
fetchData: _wrapper(async function() {
if (this._view === undefined) {
resolve(true);
return;
return true;
}

let rect = get_rect.call(this._grid.renderer);

if (!this._dirty && !uncachedRow.call(this._data_window, rect)) {
resolve(false);
if (!this._dirty && !is_cache_miss(rect, this._data_window)) {
return;
}

this._grid.renderer.needsComputeCellsBounds = true;

if (this._outstanding_rect && !uncachedRow.call(this._oustanding_rect, rect)) {
resolve(true);
return;
if (this._outstanding && !is_cache_miss(rect, this._outstanding.rect)) {
await this._outstanding.req;
this._grid.renderer.needsComputeCellsBounds = true;
return true;
}

this._outstanding_rect = rect;
this._dirty = false;
const req = this.pspFetch(rect);
this._outstanding = {rect, req};
this._update_select_index();

const action = this.pspFetch({
start_row: rect.origin.y,
end_row: rect.corner.y,
start_col: rect.origin.x,
end_col: rect.corner.x + 1
});
await req;

try {
this._update_select_index();
await action;
this._data_window = rect;
this._outstanding_rect = undefined;
const new_index = this._update_editor(rect);
this._update_selection(new_index);
rect = get_rect.call(this._grid.renderer);
this._grid.renderer.needsComputeCellsBounds = !!uncachedRow.call(this._data_window, rect);
resolve(this._grid.renderer.needsComputeCellsBounds);
} catch (e) {
resolve(e);
}
},
this._data_window = rect;
this._outstanding = undefined;
this._update_selection(this._update_editor(rect));

rect = get_rect.call(this._grid.renderer);
const ret = is_cache_miss(rect, this._data_window);
this._grid.renderer.needsComputeCellsBounds = ret;
return ret;
}),

getCellEditorAt: function(columnIndex, rowIndex, declaredEditorName, options) {
if (!declaredEditorName) {
Expand Down Expand Up @@ -221,8 +222,8 @@ export default require("datasaur-local").extend("PerspectiveDataModel", {
pspFetch: async function() {}
});

function uncachedRow(rect) {
return !this || this.top !== rect.top || this.height !== rect.height || this.left !== rect.left || this.width !== rect.width;
function is_cache_miss(req, cache) {
return !cache || req.top !== cache.top || req.top + req.height !== cache.top + cache.height || req.left !== cache.left || req.left + req.width !== cache.left + cache.width;
}

function cellStyle(gridCellConfig) {
Expand Down
50 changes: 35 additions & 15 deletions packages/perspective-viewer-hypergrid/src/js/hypergrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ bindTemplate(TEMPLATE, style)(
host.setAttribute("hidden", true);
this.grid = new Hypergrid(host, {DataModel: PerspectiveDataModel});
this.grid.canvas.stopResizeLoop();
this.grid.canvas.stopPaintLoop();
host.removeAttribute("hidden");
this.grid.get_styles = () => get_styles(this);

Expand Down Expand Up @@ -88,9 +89,10 @@ async function grid_update(div, view, task) {
return;
}
const dataModel = hypergrid.behavior.dataModel;
dataModel.setDirty(nrows);
dataModel._view = view;
dataModel._table = this._table;
dataModel.setDirty(nrows);
hypergrid.behaviorChanged();
hypergrid.canvas.paintNow();
}

Expand Down Expand Up @@ -140,12 +142,32 @@ async function getOrCreateHypergrid(div) {
return perspectiveHypergridElement;
}

function pad_data_window(rect, rowPivots = [], colPivots = [], settings = true) {
const range = {
start_row: rect.origin.y,
end_row: rect.corner.y,
start_col: rect.origin.x,
end_col: rect.corner.x + 1
};
range.end_row += settings ? 8 : 2;
range.end_col += rowPivots && rowPivots.length > 0 ? 1 : 0;
range.index = rowPivots.length === 0 && colPivots.length === 0;
return range;
}

function suppress_paint(hypergrid, f) {
const canvas = hypergrid.divCanvas;
hypergrid.divCanvas = undefined;
f();
hypergrid.divCanvas = canvas;
}

async function grid_create(div, view, task, max_rows, max_cols, force) {
let hypergrid = get_hypergrid.call(this);
if (hypergrid) {
hypergrid.behavior.dataModel._view = undefined;
hypergrid.behavior.dataModel._table = undefined;
hypergrid.allowEvents(false);
suppress_paint(hypergrid, () => hypergrid.allowEvents(false));
}

const config = await view.get_config();
Expand All @@ -156,13 +178,13 @@ async function grid_create(div, view, task, max_rows, max_cols, force) {

const colPivots = config.column_pivots;
const rowPivots = config.row_pivots;
const window = {
const data_window = {
start_row: 0,
end_row: Math.max(colPivots.length + 1, rowPivots.length + 1),
end_row: 1,
index: rowPivots.length === 0 && colPivots.length === 0
};

const [nrows, json, schema, tschema] = await Promise.all([view.num_rows(), view.to_columns(window), view.schema(), this._table.schema()]);
const [nrows, json, schema, tschema] = await Promise.all([view.num_rows(), view.to_columns(data_window), view.schema(), this._table.schema()]);

if (task.cancelled) {
return;
Expand All @@ -186,27 +208,25 @@ async function grid_create(div, view, task, max_rows, max_cols, force) {
dataModel._config = config;
dataModel._viewer = this;

dataModel.pspFetch = async range => {
range.end_row += this.hasAttribute("settings") ? 8 : 2;
range.end_col += rowPivots && rowPivots.length > 0 ? 1 : 0;
range.index = rowPivots.length === 0 && colPivots.length === 0;
dataModel.pspFetch = async rect => {
const range = pad_data_window(rect, rowPivots, colPivots, this.hasAttribute("settings"));
let next_page = await dataModel._view.to_columns(range);
if (columns.length === 0) {
columns = Object.keys(await view.to_columns(window));
columns = Object.keys(await view.to_columns(data_window));
}
dataModel.data = [];
const rows = page2hypergrid(next_page, rowPivots, columns);
const base = range.start_row;
const data = dataModel.data;
rows.forEach((row, offset) => (data[base + offset] = row));
};
hypergrid.renderer.needsComputeCellsBounds = true;
suppress_paint(hypergrid, () => perspectiveHypergridElement.set_data(json, schema, tschema, rowPivots, columns, force));
if (hypergrid.behavior.dataModel._outstanding) {
await hypergrid.behavior.dataModel._outstanding.req;
}

perspectiveHypergridElement.set_data(json, schema, tschema, rowPivots, columns, force);
hypergrid.allowEvents(false);
hypergrid.renderer.computeCellsBounds(true);
await hypergrid.canvas.resize(true);
hypergrid.renderer.computeCellsBounds(true);
hypergrid.canvas.paintNow();
hypergrid.allowEvents(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,6 @@ export const install = function(grid) {

this.bounds = new rectangular.Rectangle(0, 0, width, height);
this.component.setBounds(this.bounds);
this.resizeNotification();

let render = true;
if (height * ratio !== this.canvas.height || width * ratio !== this.canvas.width || force) {
Expand All @@ -499,6 +498,7 @@ export const install = function(grid) {

this.bounds = new rectangular.Rectangle(0, 0, width, height);
this.component.setBounds(this.bounds);
this.resizeNotification();

this.buffer.width = this.canvas.width = width * ratio;
this.buffer.height = this.canvas.height = height * ratio;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function page2hypergrid(data, row_pivots, columns) {
}

const is_tree = !!row_pivots.length;
const flat_columns = row_pivots.length ? columns.slice(1) : columns;
const flat_columns = row_pivots.length ? columns.filter(x => x !== "__ROW_PATH__") : columns;
const data_indices = data_columns.map(x => flat_columns.indexOf(x));
const rows = [];

Expand Down Expand Up @@ -71,7 +71,7 @@ function psp2hypergrid(data, schema, tschema, row_pivots, columns) {
};
}

const flat_columns = row_pivots.length ? columns.slice(1) : columns;
const flat_columns = row_pivots.length ? columns.filter(x => x !== "__ROW_PATH__") : columns;
const columnPaths = flat_columns.map(row => row.split(COLUMN_SEPARATOR_STRING));
const is_tree = !!row_pivots.length;
const rows = page2hypergrid(data, row_pivots, columns);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"superstore.html/highlights invalid filter.": "5fb11339a9c44a4bf5311b0f23bb033d",
"superstore.html/sorts by an alpha column.": "ec9d9bbcb6737e25dbbb47b52ac5cafc",
"superstore.html/displays visible columns.": "10ab4e128a672937669a44c921e34638",
"superstore.html/collapses to depth smaller than viewport": "7b1c805ec9d08fc3dba4d0f72c1230b6",
"superstore.html/collapses to depth smaller than viewport": "2f2ce2cb11ab4efe5207425960d1f7d6",
"superstore.html/resets viewable area when the logical size expands.": "e7916ebc0de23454e31216f92fe045b1",
"superstore.html/resets viewable area when the physical size expands.": "13d3164f406bf6a7d053c21dd506a0d5",
"superstore.html/replaces all rows.": "d36ca2fee2b3c06e36943e913e05bb43",
Expand All @@ -29,7 +29,7 @@
"superstore.html/shows a sort indicator": "5f4aae968d2dac96781c954e05d34303",
"superstore.html/shows multiple sort indicators": "b6f6bd22638f550ee07cadc46c1c37c0",
"superstore.html/shows a sort indicator on column split": "245820611945c0c5c563e93053505bd6",
"__GIT_COMMIT__": "85e51dae0d9fb6a4e799037d5816951f34425ab5",
"__GIT_COMMIT__": "11712699adb23aed276c2cdcbe052b6c908332d2",
"superstore.html/should reinterpret metadata when only row pivots are changed": "09b6aaf7708d4363546c005abf203a9c",
"empty.html/perspective-click is fired when an empty dataset is loaded first": "7e5b653226145e1ab9f82e2417d89d7b",
"superstore.html/should not edit an immutable viewer": "8d99c2bc8bf7450a5f2cc4f5b1ca7412",
Expand Down
12 changes: 12 additions & 0 deletions packages/perspective-viewer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Module for `<perspective-viewer>` custom element. There are no exports from thi
* [.plugin](#module_perspective-viewer..PerspectiveViewer+plugin) : <code>string</code>
* [.column-pivots](#module_perspective-viewer..PerspectiveViewer+column-pivots) : <code>Array.&lt;String&gt;</code>
* [.row-pivots](#module_perspective-viewer..PerspectiveViewer+row-pivots) : <code>array.&lt;string&gt;</code>
* [.editable](#module_perspective-viewer..PerspectiveViewer+editable) : <code>boolean</code>
* [.worker](#module_perspective-viewer..PerspectiveViewer+worker)
* [.table](#module_perspective-viewer..PerspectiveViewer+table)
* [.view](#module_perspective-viewer..PerspectiveViewer+view)
Expand Down Expand Up @@ -52,6 +53,7 @@ Module for `<perspective-viewer>` custom element. There are no exports from thi
* [.plugin](#module_perspective-viewer..PerspectiveViewer+plugin) : <code>string</code>
* [.column-pivots](#module_perspective-viewer..PerspectiveViewer+column-pivots) : <code>Array.&lt;String&gt;</code>
* [.row-pivots](#module_perspective-viewer..PerspectiveViewer+row-pivots) : <code>array.&lt;string&gt;</code>
* [.editable](#module_perspective-viewer..PerspectiveViewer+editable) : <code>boolean</code>
* [.worker](#module_perspective-viewer..PerspectiveViewer+worker)
* [.table](#module_perspective-viewer..PerspectiveViewer+table)
* [.view](#module_perspective-viewer..PerspectiveViewer+view)
Expand Down Expand Up @@ -226,6 +228,16 @@ Sets this `perspective.table.view`'s `row_pivots` property.
* * *
<a name="module_perspective-viewer..PerspectiveViewer+editable"></a>
#### perspectiveViewer.editable : <code>boolean</code>
Determines whether this viewer is editable or not (though it isultimately up to the plugin as to whether editing is implemented).
**Kind**: instance property of [<code>PerspectiveViewer</code>](#module_perspective-viewer..PerspectiveViewer)
**Emits**: <code>PerspectiveViewer#event:perspective-config-update</code>
* * *
<a name="module_perspective-viewer..PerspectiveViewer+worker"></a>
#### perspectiveViewer.worker
Expand Down
4 changes: 2 additions & 2 deletions packages/perspective/src/js/perspective.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,9 @@ export default function(Module) {

const viewport = this.config.viewport ? this.config.viewport : {};
const start_row = options.start_row || (viewport.top ? viewport.top : 0);
const end_row = Math.min(max_rows, options.end_row || (viewport.height ? start_row + viewport.height : max_rows));
const end_row = Math.min(max_rows, options.end_row !== undefined ? options.end_row : viewport.height ? start_row + viewport.height : max_rows);
const start_col = options.start_col || (viewport.left ? viewport.left : 0);
const end_col = Math.min(max_cols, (options.end_col || (viewport.width ? start_col + viewport.width : max_cols)) * (hidden + 1));
const end_col = Math.min(max_cols, (options.end_col !== undefined ? options.end_col : viewport.width ? start_col + viewport.width : max_cols) * (hidden + 1));
let date_format;
if (options.date_format) {
date_format = new Intl.DateTimeFormat(options.date_format);
Expand Down
2 changes: 1 addition & 1 deletion python/perspective/.bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0, 1, 11, 'final', 0
current_version = 0, 4, 0, 'rc', 1
commit = False
tag = False
parse = (?P<major>\d+)\,\ (?P<minor>\d+)\,\ (?P<patch>\d+)\,\ \'(?P<release>\S+)\'\,\ (?P<build>\d+)
Expand Down
6 changes: 3 additions & 3 deletions python/perspective/perspective/core/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
])

# DO NOT EDIT THIS DIRECTLY! It is managed by bumpversion
version_info = VersionInfo(0, 1, 11, 'final', 0)
version_info = VersionInfo(0, 4, 0, 'rc', 1)

_specifier_ = {'alpha': 'a', 'beta': 'b', 'candidate': 'rc', 'final': ''}
_specifier_ = {'alpha': 'alpha', 'beta': 'beta', 'rc': 'rc', 'final': ''}

__version__ = '{}.{}.{}{}'.format(
version_info.major,
version_info.minor,
version_info.micro,
(''
if version_info.releaselevel == 'final'
else _specifier_[version_info.releaselevel] + str(version_info.serial)))
else _specifier_[version_info.releaselevel] + "." + str(version_info.serial)))

0 comments on commit 968393b

Please sign in to comment.