Skip to content

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
wants to merge 38 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
ec04cbd
feat: add `@stdlib/plot/table/unicode`
Snehil-Shah Jun 19, 2024
ee7dec3
Merge branch 'stdlib-js:develop' into table
Snehil-Shah Jul 20, 2024
8ab53e7
refactor: update table from code review
Snehil-Shah Jul 20, 2024
2c7c604
docs: update jsdoc
Snehil-Shah Jul 20, 2024
8d36829
docs: add events to README
Snehil-Shah Jul 27, 2024
f4502df
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into pr…
kgryte Feb 10, 2025
9ea8bad
refactor: update implementation and clean-up
kgryte Feb 11, 2025
2fe6d53
chore: update copyright years
stdlib-bot Feb 11, 2025
68986f4
chore: update copyright years
stdlib-bot Feb 11, 2025
4a4b5ec
refactor: implement a FIFO array and refactor `push` logic
kgryte Feb 13, 2025
2738a64
Merge branch 'table' of https://github.com/Snehil-Shah/stdlib into pr…
kgryte Feb 13, 2025
db9d55b
docs: update example
kgryte Feb 13, 2025
478b462
docs: add streaming example
kgryte Feb 13, 2025
d1b8126
docs: add complex number example
kgryte Feb 13, 2025
b11a2c9
feat: add support for getting and setting individual data elements
kgryte Feb 13, 2025
c045e40
docs: document methods
kgryte Feb 13, 2025
274f158
feat: add support for specifying a format string
kgryte Feb 13, 2025
3509f9d
docs: update example
kgryte Feb 13, 2025
7e1b3a0
style: disable lint rule
kgryte Feb 13, 2025
a130400
feat!: rename property/option and support separate header alignment
kgryte Feb 14, 2025
38bbb32
feat: add support for specifying fixed column width(s)
kgryte Feb 14, 2025
d2d519c
refactor: compute columns rather than number of graphemes due to term…
kgryte Feb 14, 2025
de57031
refactor: rename internal properties and add initial ANSI escape support
kgryte Feb 17, 2025
a2510d5
fix: add specialized logic for joining strings
kgryte Feb 17, 2025
2d0eb37
docs: update comment
kgryte Feb 17, 2025
2dc3f6f
refactor: move normalization of cell data to separate module
kgryte Feb 17, 2025
2c1654a
refactor: support ANSI escape sequences in table characters
kgryte Feb 17, 2025
e13e98e
docs: add example demonstrating value-dependent styling
kgryte Feb 17, 2025
dcdab1e
docs: add example demonstrating value-dependent styling
kgryte Feb 17, 2025
c06b4c4
Merge branch 'table' of https://github.com/Snehil-Shah/stdlib into pr…
kgryte Feb 17, 2025
558b87e
refactor: remove character length restriction
kgryte Feb 18, 2025
0b7b7ff
docs: add note
kgryte Feb 18, 2025
1138b9c
refactor: restrict corners and joints to one grapheme cluster
kgryte Feb 19, 2025
26caefa
fix: support grapheme clusters for joints, corners, and borders
kgryte Feb 19, 2025
cbbe6ec
docs: update example
kgryte Feb 19, 2025
ae6a4cd
refactor: add internal width "units" property
kgryte Feb 19, 2025
e378881
docs: add comments
kgryte Feb 19, 2025
03b8157
refactor: ensure normalization uses consistent units
kgryte Feb 19, 2025
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
609 changes: 609 additions & 0 deletions lib/node_modules/@stdlib/plot/table/unicode/README.md

Large diffs are not rendered by default.

809 changes: 809 additions & 0 deletions lib/node_modules/@stdlib/plot/table/unicode/benchmark/benchmark.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/**
* @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 {UnicodeTable} table - table instance
* @returns {Function} benchmark function
*/
function createBenchmark( rows, columns, table ) {
var headers;
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 ]
});
headers = [];
for ( i = 0; i < columns; i++ ) {
headers.push( randu() );
}
table.data = data;
table.headers = headers;
return benchmark;

/**
* Generates a row of table data.
*
* @private
* @returns {Array<number>} table data
*/
function row() {
var data;
var i;

data = [];
for ( i = 0; i < columns; i++ ) {
data.push( 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.push( row() ).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();
table.bufferSize = rows;
f = createBenchmark( rows, columns, table );
bench( pkg+':render:rows='+rows+',columns='+columns, f );
}
}
}

main();
160 changes: 160 additions & 0 deletions lib/node_modules/@stdlib/plot/table/unicode/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@

{{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: Array<string>|string (optional)
Datum's cell alignment(s). Default: 'right'.

options.autoRender: boolean (optional)
Boolean indicating whether to re-render on a 'change' event. Default:
false.

options.borders: Array<string> (optional)
Border characters. Default: [ '─', '│', '─', '│' ].

options.bufferSize: integer|null (optional)
Data buffer size. If provided, data is kept in a first-in first-out
(FIFO) buffer which cannot exceed the buffer size. Default: +infinity.

options.cellPaddingLeft: Array<NonNegativeInteger>|NonNegativeInteger
(optional)
Cell's left padding(s). Default: 1.

options.cellPaddingRight: Array<NonNegativeInteger>|NonNegativeInteger
(optional)
Cell's right padding(s). Default: 1.

options.columnSeparator: string (optional)
Column separator character(s). Default: '│'.

options.corners: Array<string> (optional)
Corner characters. Default: [ '┌', '┐', '┘', '└' ].

options.headerSeparator: string (optional)
Header separator character(s). Default: '─'.

options.horizontalSeparatorMode: string (optional)
Horizontal line separator mode. The following modes are supported:

- resume: resume line sequence after a joint.
- interpolate: skip line character at a joint.
- repeat: repeat line sequence after a joint.

Default: `resume`.

options.joints: Array<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: Array<NonNegativeInteger>|NonNegativeInteger|null
(optional)
Maximum cell width(s). Default: +infinity.

options.maxOutputWidth: NonNegativeInteger|null (optional)
Maximum output width. Default: +infinity.

options.rowSeparator: string (optional)
Row separator character(s). Default: ''.

options.verticalSeparatorMode: string (optional)
Vertical line separator mode. The following modes are supported:

- resume: resume line sequence after a joint.
- interpolate: skip line character at a joint.
- repeat: repeat line sequence after a joint.

Default: `resume`.

Returns
-------
table.alignment
Datum's cell alignment(s).

table.autoRender
Rendering mode. If `true`, an instance renders on each 'change' event;
otherwise, rendering must be triggered manually.

table.borders
Border characters.

table.bufferSize
Data buffer size.

table.cellPaddingLeft
Cell's left Padding.

table.cellPaddingRight
Cell's right Padding.

table.columnSeparator
Column separator character(s).

table.corners
Corner characters.

table.data
Table data.

table.headers
Table headers.

table.headerSeparator
Header separator character(s).

table.horizontalSeparatorMode
Horizontal line separator mode.

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.push( row )
Appends a row to table data.

table.render()
Renders a table.

table.rowSeparator
Row separator character(s).

table.verticalSeparatorMode
Vertical line separator mode.

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
--------

45 changes: 45 additions & 0 deletions lib/node_modules/@stdlib/plot/table/unicode/examples/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* @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 uniform = require( '@stdlib/random/array/uniform' );
var array = require( '@stdlib/ndarray/array' );
var ctor = require( './../lib' );

var headers;
var table;
var data;
var str;

// Generate some random data...
data = uniform( 50, 1, 100 );
data = array( data, {
'shape': [ 10, 5 ]
});

// Generate headers...
headers = [ 'A', 'B', 'C', 'D', 'E' ];

// Create a table:
table = ctor( data, headers );

// Render the table:
str = table.render();
console.log( str );
// => '...'
Loading
Loading