-
-
Notifications
You must be signed in to change notification settings - Fork 844
feat: add plot/table/unicode
#2407
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
Draft
Snehil-Shah
wants to merge
38
commits into
stdlib-js:develop
Choose a base branch
from
Snehil-Shah:table
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+15,628
−0
Draft
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
ec04cbd
feat: add `@stdlib/plot/table/unicode`
Snehil-Shah ee7dec3
Merge branch 'stdlib-js:develop' into table
Snehil-Shah 8ab53e7
refactor: update table from code review
Snehil-Shah 2c7c604
docs: update jsdoc
Snehil-Shah 8d36829
docs: add events to README
Snehil-Shah f4502df
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into pr…
kgryte 9ea8bad
refactor: update implementation and clean-up
kgryte 2fe6d53
chore: update copyright years
stdlib-bot 68986f4
chore: update copyright years
stdlib-bot 4a4b5ec
refactor: implement a FIFO array and refactor `push` logic
kgryte 2738a64
Merge branch 'table' of https://github.com/Snehil-Shah/stdlib into pr…
kgryte db9d55b
docs: update example
kgryte 478b462
docs: add streaming example
kgryte d1b8126
docs: add complex number example
kgryte b11a2c9
feat: add support for getting and setting individual data elements
kgryte c045e40
docs: document methods
kgryte 274f158
feat: add support for specifying a format string
kgryte 3509f9d
docs: update example
kgryte 7e1b3a0
style: disable lint rule
kgryte a130400
feat!: rename property/option and support separate header alignment
kgryte 38bbb32
feat: add support for specifying fixed column width(s)
kgryte d2d519c
refactor: compute columns rather than number of graphemes due to term…
kgryte de57031
refactor: rename internal properties and add initial ANSI escape support
kgryte a2510d5
fix: add specialized logic for joining strings
kgryte 2d0eb37
docs: update comment
kgryte 2dc3f6f
refactor: move normalization of cell data to separate module
kgryte 2c1654a
refactor: support ANSI escape sequences in table characters
kgryte e13e98e
docs: add example demonstrating value-dependent styling
kgryte dcdab1e
docs: add example demonstrating value-dependent styling
kgryte c06b4c4
Merge branch 'table' of https://github.com/Snehil-Shah/stdlib into pr…
kgryte 558b87e
refactor: remove character length restriction
kgryte 0b7b7ff
docs: add note
kgryte 1138b9c
refactor: restrict corners and joints to one grapheme cluster
kgryte 26caefa
fix: support grapheme clusters for joints, corners, and borders
kgryte cbbe6ec
docs: update example
kgryte ae6a4cd
refactor: add internal width "units" property
kgryte e378881
docs: add comments
kgryte 03b8157
refactor: ensure normalization uses consistent units
kgryte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
495 changes: 495 additions & 0 deletions
495
lib/node_modules/@stdlib/plot/table/unicode/benchmark/benchmark.js
Large diffs are not rendered by default.
Oops, something went wrong.
142 changes: 142 additions & 0 deletions
142
lib/node_modules/@stdlib/plot/table/unicode/benchmark/benchmark.render.js
This file contains hidden or 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,142 @@ | ||
/** | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2024 The Stdlib Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// MODULES // | ||
|
||
var bench = require( '@stdlib/bench' ); | ||
var randu = require( '@stdlib/random/base/randu' ); | ||
var pow = require( '@stdlib/math/base/special/pow' ); | ||
var Float64Array = require( '@stdlib/array/float64' ); | ||
var array = require( '@stdlib/ndarray/array' ); | ||
var pkg = require( './../package.json' ).name; | ||
var UnicodeTable = require( './../lib' ); | ||
|
||
|
||
// FUNCTIONS // | ||
|
||
/** | ||
* Creates a benchmark function. | ||
* | ||
* @private | ||
* @param {PositiveInteger} rows - number of rows | ||
* @param {PositiveInteger} columns - number of columns | ||
* @param {UnicodeSparkline} table - table instance | ||
* @returns {Function} benchmark function | ||
*/ | ||
function createBenchmark( rows, columns, table ) { | ||
return benchmark; | ||
|
||
/** | ||
* Generates table data. | ||
* | ||
* @private | ||
* @returns {ndarray} table data | ||
*/ | ||
function data() { | ||
var data; | ||
var i; | ||
|
||
data = new Float64Array( rows * columns ); | ||
for ( i = 0; i < data.length; i++ ) { | ||
data[ i ] = randu(); | ||
} | ||
data = array( data, { | ||
'shape': [ rows, columns ] | ||
}); | ||
return data; | ||
} | ||
|
||
/** | ||
* Generates table headers. | ||
* | ||
* @private | ||
* @returns {Float64Array} table data | ||
*/ | ||
function headers() { | ||
var data; | ||
var i; | ||
|
||
data = new Float64Array( columns ); | ||
for ( i = 0; i < data.length; i++ ) { | ||
data[ i ] = randu(); | ||
} | ||
return data; | ||
} | ||
|
||
/** | ||
* Benchmark function. | ||
* | ||
* @private | ||
* @param {Benchmark} b - benchmark instance | ||
*/ | ||
function benchmark( b ) { | ||
var str; | ||
var i; | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
str = table.setData( data(), headers() ).render(); | ||
if ( typeof str !== 'string' ) { | ||
b.fail( 'should return a string' ); | ||
} | ||
} | ||
b.toc(); | ||
if ( typeof str !== 'string' ) { | ||
b.fail( 'should return a string' ); | ||
} | ||
b.pass( 'benchmark finished' ); | ||
b.end(); | ||
} | ||
} | ||
|
||
|
||
// MAIN // | ||
|
||
/** | ||
* Main execution sequence. | ||
* | ||
* @private | ||
*/ | ||
function main() { | ||
var columns; | ||
var table; | ||
var rows; | ||
var min; | ||
var max; | ||
var f; | ||
var i; | ||
var j; | ||
|
||
min = 1; // 5^min | ||
max = 3; // 5^max | ||
|
||
for ( i = min; i <= max; i++ ) { | ||
for ( j = min; j <= max; j++ ) { | ||
rows = pow( 5, i ); | ||
columns = pow( 5, j ); | ||
|
||
table = new UnicodeTable(); | ||
f = createBenchmark( rows, columns, table ); | ||
bench( pkg+':render:rows='+rows+',columns='+columns, f ); | ||
} | ||
} | ||
} | ||
|
||
main(); |
112 changes: 112 additions & 0 deletions
112
lib/node_modules/@stdlib/plot/table/unicode/docs/repl.txt
This file contains hidden or 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,112 @@ | ||
|
||
{{alias}}( [data,] [headers,] [options] ) | ||
Returns a Unicode table instance. | ||
|
||
Parameters | ||
---------- | ||
data: Object|Array<Object>|Array<Array>|MatrixLike (optional) | ||
Table data. | ||
|
||
headers: Collection (optional) | ||
Table headers. | ||
|
||
options: Object (optional) | ||
Table options. | ||
|
||
options.alignment: string (optional) | ||
Datum's cell alignment. Default: 'right'. | ||
|
||
options.borders: string (optional) | ||
Border characters. Default: '─ │ ─ │'. | ||
|
||
options.cellPadding: NonNegativeInteger (optional) | ||
Cell padding. Default: 1. | ||
|
||
options.columnSeparator: string (optional) | ||
Column separator character. Default: '│'. | ||
|
||
options.corners: string (optional) | ||
Corner characters. Default: '┌ ┐ ┘ └'. | ||
|
||
options.headerSeparator: string (optional) | ||
Header separator character. Default: '─'. | ||
|
||
options.joints: string (optional) | ||
Joint characters. Default: '┼ ┬ ┤ ┴ ├'. | ||
|
||
options.marginX: NonNegativeInteger (optional) | ||
Horizontal output margin. Default: 0. | ||
|
||
options.marginY: NonNegativeInteger (optional) | ||
Vertical output margin. Default: 0. | ||
|
||
options.maxCellWidth: NonNegativeInteger (optional) | ||
Maximum cell width (excluding padding). Default: FLOAT64_MAX. | ||
|
||
options.maxOutputWidth: NonNegativeInteger (optional) | ||
Maximum output width (including margin). Default: FLOAT64_MAX. | ||
|
||
options.rowSeparator: string (optional) | ||
Row separator character. Default: 'None'. | ||
|
||
Returns | ||
------- | ||
table.addRow( row ) | ||
Adds a row to table data. | ||
|
||
table.alignment | ||
Datum's cell alignment. | ||
|
||
table.borders | ||
Border characters. | ||
|
||
table.cellPadding | ||
Cell Padding. | ||
|
||
table.columnSeparator | ||
Column separator character. | ||
|
||
table.corners | ||
Corner characters. | ||
|
||
table.getData() | ||
Gets table data and headers. | ||
|
||
table.headerSeparator | ||
Header separator character. | ||
|
||
table.joints | ||
Joint characters. | ||
|
||
table.marginX | ||
Horizontal output margin. | ||
|
||
table.marginY | ||
Vertical output margin. | ||
|
||
table.maxCellWidth | ||
Maximum cell width. | ||
|
||
table.maxOutputWidth | ||
Maximum output width. | ||
|
||
table.render() | ||
Renders a table. | ||
|
||
table.rowSeparator | ||
Row separator character. | ||
|
||
table.setData( data, [headers] ) | ||
Sets table data and headers | ||
|
||
Examples | ||
-------- | ||
> var data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; | ||
> var headers = [ 'col1', 'col2', 'col3' ]; | ||
> var table = new {{alias}}( data, headers ); | ||
> table.render() | ||
'...' | ||
|
||
See Also | ||
-------- | ||
|
53 changes: 53 additions & 0 deletions
53
lib/node_modules/@stdlib/plot/table/unicode/examples/index.js
This file contains hidden or 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,53 @@ | ||
/** | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2024 The Stdlib Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var randu = require( '@stdlib/random/base/randu' ); | ||
var Float64Array = require( '@stdlib/array/float64' ); | ||
var array = require( '@stdlib/ndarray/array' ); | ||
var ctor = require( './../lib' ); | ||
|
||
var headers; | ||
var table; | ||
var data; | ||
var str; | ||
var i; | ||
|
||
// Generate some random data... | ||
data = new Float64Array( 50 ); | ||
for ( i = 0; i < data.length; i++ ) { | ||
data[ i ] = randu() * 100.0; | ||
} | ||
data = array( data, { | ||
'shape': [ 10, 5 ] | ||
}); | ||
|
||
// Generate headers... | ||
headers = new Float64Array( 5 ); | ||
for ( i = 0; i < headers.length; i++ ) { | ||
headers[ i ] = randu() * 100.0; | ||
} | ||
|
||
// Create a table: | ||
table = ctor( data, headers ); | ||
|
||
// Render the table: | ||
str = table.render(); | ||
console.log( str ); | ||
// => '...' |
This file contains hidden or 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,63 @@ | ||
/** | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2024 The Stdlib Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// MODULES // | ||
|
||
var format = require( '@stdlib/string/format' ); | ||
var isCollection = require( '@stdlib/assert/is-collection' ); | ||
var parse2dArray = require( './parser/parse_2d_array.js' ); | ||
|
||
|
||
// MAIN // | ||
|
||
/** | ||
* Adds a row to table data. | ||
* | ||
* @private | ||
* @param {Collection} row - row to add | ||
* @throws {TypeError} must provide a collection with equal number of columns to existing data | ||
* @returns {UnicodeTable} class instance | ||
*/ | ||
function addRow( row ) { | ||
/* eslint-disable no-invalid-this */ | ||
var parsed; | ||
|
||
if ( !isCollection ) { | ||
throw new TypeError( format( 'invalid argument. Must provide a collection. Value: `%s`.', row ) ); | ||
} | ||
// If data doesn't already exist, parse row as new data... | ||
if ( !this._data || !this._data.length ) { | ||
parsed = parse2dArray( [ row ], this._headers ); | ||
this._data = parsed.data; | ||
this._headers = parsed.headers; | ||
this._columnWidths = parsed.columnWidths; | ||
return this; | ||
} | ||
if ( this._data[ 0 ].length !== row.length ) { | ||
throw new TypeError( format( 'invalid argument. Must provide a collection with equal number of columns to existing data. Value: `%s`.', row ) ); | ||
} | ||
this._data.push( row ); | ||
return this; | ||
} | ||
|
||
|
||
// EXPORTS // | ||
|
||
module.exports = addRow; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.