-
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Datagrid: Add a public API to get the current viewport (#695)
* Datagrid: Add a public API to get the current viewport * Review * Add docstring * Generate API * Add spec * Add model * Proper test * Fix typo Co-authored-by: Michał Krassowski <[email protected]> --------- Co-authored-by: Michał Krassowski <[email protected]>
- Loading branch information
1 parent
f9b76e2
commit f85aad4
Showing
4 changed files
with
141 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (c) Jupyter Development Team. | ||
// Distributed under the terms of the Modified BSD License. | ||
import { expect } from 'chai'; | ||
|
||
import { DataGrid, DataModel } from '@lumino/datagrid'; | ||
|
||
class LargeDataModel extends DataModel { | ||
rowCount(region: DataModel.RowRegion): number { | ||
return region === 'body' ? 1_000_000_000_000 : 2; | ||
} | ||
|
||
columnCount(region: DataModel.ColumnRegion): number { | ||
return region === 'body' ? 1_000_000_000_000 : 3; | ||
} | ||
|
||
data(region: DataModel.CellRegion, row: number, column: number): any { | ||
if (region === 'row-header') { | ||
return `R: ${row}, ${column}`; | ||
} | ||
if (region === 'column-header') { | ||
return `C: ${row}, ${column}`; | ||
} | ||
if (region === 'corner-header') { | ||
return `N: ${row}, ${column}`; | ||
} | ||
return `(${row}, ${column})`; | ||
} | ||
} | ||
|
||
describe('@lumino/datagrid', () => { | ||
let datagrid: DataGrid; | ||
let model: LargeDataModel; | ||
|
||
beforeEach(() => { | ||
datagrid = new DataGrid(); | ||
model = new LargeDataModel(); | ||
datagrid.dataModel = model; | ||
datagrid.viewport.node.style.height = '500px'; | ||
datagrid.viewport.node.style.width = '500px'; | ||
document.children[0].appendChild(datagrid.node); | ||
}); | ||
|
||
describe('DataGrid', () => { | ||
describe('currentViewport()', () => { | ||
it('should return the viewport', () => { | ||
const viewport = datagrid.currentViewport; | ||
|
||
if (viewport === undefined) { | ||
throw new Error('viewport is undefined'); | ||
} | ||
|
||
expect(viewport.firstRow).to.be.eq(0); | ||
expect(viewport.firstColumn).to.be.eq(0); | ||
expect(viewport.lastRow).to.be.eq(22); | ||
expect(viewport.lastColumn).to.be.eq(4); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
|
||
import './textrenderer.spec'; | ||
import './imagerenderer.spec'; | ||
import './datagrid.spec'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters