Skip to content

Commit f0ce4e3

Browse files
add tabular.data.pageSize default config option support (#67)
and reorganize table view and tabulator table config vars in tableView.js
1 parent b866fce commit f0ce4e3

File tree

4 files changed

+48
-23
lines changed

4 files changed

+48
-23
lines changed

package.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,19 @@
163163
}
164164
]
165165
}
166-
]
166+
],
167+
"configuration": {
168+
"title": "Tabular Data Viewer",
169+
"type": "object",
170+
"properties": {
171+
"tabular.data.pageSize": {
172+
"type": "integer",
173+
"enum": [1000, 10000, 100000],
174+
"default": "100000",
175+
"description": "Default data page size to use for loading and displaying large datasets."
176+
}
177+
}
178+
}
167179
},
168180
"scripts": {
169181
"vscode:prepublish": "npm run package",

src/configuration/settings.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* Tabular data view configuraiton settings.
3+
*/
4+
export enum Settings {
5+
dataPageSize = 'pageSize'
6+
}

src/views/tableView.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@ import {
1515

1616
import * as fs from 'fs';
1717
import * as path from 'path';
18+
import { Stream } from 'stream';
19+
20+
import * as config from '../configuration/configuration';
1821
import * as fileUtils from '../utils/fileUtils';
1922

2023
import { FileInfo } from './fileInfo';
2124
import { FileTypes } from './fileTypes';
2225
import { ViewTypes } from './viewTypes';
2326
import { statusBar } from './statusBar';
2427

25-
import { Stream } from 'stream';
2628
import { ViewCommands } from '../commands/viewCommands';
29+
import { Settings } from '../configuration/Settings';
2730

2831
// eslint-disable-next-line @typescript-eslint/naming-convention
2932
const {Table} = require('tableschema');
@@ -55,9 +58,6 @@ export class TableView {
5558

5659

5760
// TODO: move the settings below to tabular data viewer config options later
58-
// default page data size for incremental data loading into table view
59-
private readonly _pageDataSize: number = 100000;
60-
6161
// infer table schema rows sample size limit
6262
private readonly _inferDataSize = 100;
6363

@@ -279,14 +279,14 @@ export class TableView {
279279
dataStream.on('data', (row: any) => {
280280
tableRows.push(row);
281281
rowCount++;
282-
if ((rowCount % (this._pageDataSize * 10)) === 0) {
282+
if ((rowCount % (this.dataPageSize * 10)) === 0) {
283283
console.log(`tabular.data.view:refresh(): parsing rows ${rowCount.toLocaleString()}+ ...`);
284284
if (this.visible) {
285285
statusBar.showMessage(`Parsing rows ${rowCount.toLocaleString()}+`);
286286
}
287287
}
288288

289-
if (rowCount === this._pageDataSize) {
289+
if (rowCount === this.dataPageSize) {
290290
// send initial set of data rows to table view for display
291291
this.loadData(tableRows);
292292
// TODO: add pause/resume stream later
@@ -309,13 +309,13 @@ export class TableView {
309309
statusBar.totalRows = tableRows.length;
310310
}
311311

312-
if (tableRows.length < this._pageDataSize) {
312+
if (tableRows.length < this.dataPageSize) {
313313
// load first page of data
314314
this.loadData(tableRows);
315315
// clear data loading status bar message
316316
statusBar.showMessage('');
317317
}
318-
else if (tableRows.length > this._pageDataSize) {
318+
else if (tableRows.length > this.dataPageSize) {
319319
// load remaining table rows
320320
const dataPageIndex: number = 1;
321321
this.addData(dataPageIndex);
@@ -344,7 +344,7 @@ export class TableView {
344344
}
345345

346346
// send initial set of data rows to table view for display
347-
const nextRows: number = Math.min(this._pageDataSize, this._totalRows);
347+
const nextRows: number = Math.min(this.dataPageSize, this._totalRows);
348348
const initialDataRows: Array<any> = tableRows.slice(0, nextRows);
349349
this.webviewPanel.webview.postMessage({
350350
command: 'refresh',
@@ -353,7 +353,8 @@ export class TableView {
353353
tableConfig: this._tableConfig,
354354
tableSchema: this._tableSchema,
355355
totalRows: this._totalRows,
356-
tableData: initialDataRows
356+
tableData: initialDataRows,
357+
dataPageSize: this.dataPageSize
357358
});
358359
}
359360

@@ -363,7 +364,7 @@ export class TableView {
363364
* @param dataPage Requested data page index for loading the next set of data rows.
364365
*/
365366
public async addData(dataPage: number): Promise<void> {
366-
let nextRows: number = dataPage * this._pageDataSize;
367+
let nextRows: number = dataPage * this.dataPageSize;
367368
if (this._loadedDataPage <= dataPage && nextRows < this._totalRows) {
368369
// console.log(`tabular.data.view:addData(): loading rows ${nextRows.toLocaleString()}+ ...`);
369370
if (this.visible) {
@@ -372,7 +373,7 @@ export class TableView {
372373

373374
// get the next set of data rows to load in table view
374375
const dataRows: Array<any> =
375-
this._tableData.slice(nextRows, Math.min(nextRows + this._pageDataSize, this._totalRows));
376+
this._tableData.slice(nextRows, Math.min(nextRows + this.dataPageSize, this._totalRows));
376377

377378
// increment next rows for data loading status update
378379
nextRows += dataRows.length;
@@ -563,6 +564,13 @@ export class TableView {
563564
return delimiter;
564565
}
565566

567+
/**
568+
* Gets data page size configuration setting.
569+
*/
570+
get dataPageSize(): number {
571+
return <number>config.get(Settings.dataPageSize);
572+
}
573+
566574
/**
567575
* Creates webview html content for the webview panel display.
568576
*

web/scripts/tableView.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ let saveDataFileName = '';
1010

1111
// table view elements
1212
let tableContainer, table, progressRing, saveFileTypeSelector, tablePageSelector;
13+
const toolbarHeight = 40; // table view toolbar height offset
1314

1415
// table view vars
1516
let tableConfig = {};
@@ -19,27 +20,24 @@ let tableData = [];
1920
let loadedRows = 0;
2021
let totalRows = 0;
2122
let loadedDataPage = 0;
23+
let dataPageSize = 100000;
2224
let viewState = {
2325
tableConfig: tableConfig
2426
};
2527

26-
// table view settings
27-
const toolbarHeight = 40; // table view toolbar height offset
28-
const autoResize = true;
28+
// tabulator table settings
2929
let autoColumns = true;
30+
const autoResize = true;
3031
const enableClipboard = true; // enable clipboard copy and paste
3132
const clipboardPasteAction = 'replace';
3233
const movableColumns = true;
3334
const movableRows = true;
3435
const selectableRows = true;
35-
3636
const pagination = false;
3737
const paginationSize = 1000;
38-
const pageDataSize = 100000;
3938
const pageSizes = [100, 1000, 10000, 100000];
40-
41-
const reactiveData = false;
4239
const renderVerticalBuffer = 300; // virtual view buffer height in px for redraw on scroll
40+
const reactiveData = false;
4341

4442
// tabulator debug options
4543
const debugInvalidOptions = true; // tabulator warnings
@@ -176,6 +174,7 @@ function updateViewState(tableInfo) {
176174
tableSchema = tableInfo.tableSchema;
177175
tableData = tableInfo.tableData;
178176
totalRows = tableInfo.totalRows;
177+
dataPageSize = tableInfo.dataPageSize;
179178

180179
if (tableInfo.tableConfig.columns) {
181180
// update table config
@@ -410,7 +409,7 @@ function onTableBuilt () {
410409
*/
411410
function getNextDataPage() {
412411
const nextDataPage = loadedDataPage + 1;
413-
if (loadedRows < totalRows && (nextDataPage * pageDataSize) < totalRows) {
412+
if (loadedRows < totalRows && (nextDataPage * dataPageSize) < totalRows) {
414413
progressRing.style.visibility = 'visible';
415414
vscode.postMessage({
416415
command: 'addData',
@@ -460,8 +459,8 @@ function addData(table, dataRows, dataPageIndex) {
460459
function showDataPage() {
461460
let dataPageIndex = Number(tablePageSelector.value);
462461
// console.log('tableView.showDataPage(): loading data page:', dataPageIndex);
463-
const pageStart = (dataPageIndex * pageDataSize);
464-
const pageData = tableData.slice(pageStart, Math.min(pageStart + pageDataSize, totalRows));
462+
const pageStart = (dataPageIndex * dataPageSize);
463+
const pageData = tableData.slice(pageStart, Math.min(pageStart + dataPageSize, totalRows));
465464
table.clearData();
466465
table.replaceData(pageData);
467466
}

0 commit comments

Comments
 (0)