Skip to content

feat: add plot/unicode/base #6750

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

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2025 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 basePlot = require( './../lib' );
var str;
var opt = {
'plotAreaHeight': 12,
'plotAreaWidth': 102,
'axisTicsLabels': [ [1, 10], [ 1, 2 ], [ 2, 66, 666, 666 ], [ 9666, 55, 5 ] ],
'labelFormate': [ '%s', '%s', '%s', '%s' ],
'zAxis': false,
'wAxis': false,
'backgroundColor': 'Bwhite',
'foregroundColor': 'Fblack',
'xTicsLabelSpace': 2,
'yTicsLabelSpace': 1,
'zTicsLabelSpace': 3,
'wTicsLabelSpace': 4,
'ticsLabelsBckColor': 'Byellow',
'autoInitialization': true,
'xAxisPos': 40,
'yAxisPos': 5,
'zAxisPos': 101,
'xTicsSpacing': 9,
'yTicsSpacing': 9,
'zTicsSpacing': 9,
'wTicsSpacing': 9,
'wAxisPos': 11
};
var instance = basePlot( opt );
instance.initialize();
str = instance.render();
console.log( str );

// Adding string

// Note : as you can see 'hel' is on one side and remaining text is on other side this is because of the label space and we are adding the string as a safe area mode
instance.setString({
'row': 4,
'column': 37,
'value': 'hello Stdlib!',
'foregroundColor': 'Fwhite',
'backgroundColor': 'Bgray',
'safeArea': true
});

// Note : in Safe area mode we have to provide the coordinates in range of the plotAreaHeight and plotAreaWidth.
instance.setString({
'row': 5,
'column': 37,
'value': 'hello Stdlib!',
'foregroundColor': 'Fwhite',
'backgroundColor': 'Bgray',
'safeArea': true
});

// Now it is going to be Visible
instance.ticsLabelsBckColor = 'Bblue';

str = instance.render();
console.log( str );

// This line require to reinitialization ( autoInitialization is on )
instance.xTicsLabelSpace = 5;
str = instance.render();
console.log( str );

// Adding bar in safe area
instance.setBar({
'startPos': [ 0, 12 ],
'height': 7,
'width': 2,
'safeArea': true,
'overWrite': true,
'glyph': 'block',
'foregroundColor': 'Fred'
});

str = instance.render();
console.log( str );

// Adding bar without safe area mode
instance.setBar({
'startPos': [ 0, 16 ],
'height': 7,
'width': 2,
'overwrite': true,
'safeArea': false,
'glyph': 'block',
'foregroundColor': 'Fred'
});
str = instance.render();
console.log( str );
34 changes: 34 additions & 0 deletions lib/node_modules/@stdlib/plot/unicode/base/lib/ansi_regexp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2025 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';

// MAIN //

/**
* Regular expression to match ANSI escape sequences.
*
* @private
* @type {RegExp}
*/
var RE = /([\u001B\u009B][[\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\d\/#&.:=?%@~_]+)*|[a-zA-Z\d]+(?:;[-a-zA-Z\d\/#&.:=?%@~_]*)*)?(?:\u0007|\u001B\u005C|\u009C))|(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PR-TZcf-nq-uy=><~])))/g; // eslint-disable-line no-control-regex, no-useless-escape


// EXPORTS //

module.exports = RE;
62 changes: 62 additions & 0 deletions lib/node_modules/@stdlib/plot/unicode/base/lib/background-color.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2025 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.
*/

/* eslint-disable max-len */
/* eslint-disable no-invalid-this */

'use strict';

// MODULES //

var isValidBackgroundColor = require( './utils/is-valid-background-color.js' );
var isValidRowCol = require( './utils/is-valid-row-col.js' );

/**
* Method to add background color on specific row and col.
*
* @private
* @name setBackgroundColor
* @param {number} row - row number
* @param {number} col - col number
* @param {string} color - color name
* @param {boolean} overwrite - overwrite
* @param {boolean} safeArea - safeArea
* @returns {void}
*/
function setBackgroundColor( row, col, color, overwrite, safeArea ) {
var a;
var b;
var r;
var c;

r = row;
c = col;
if ( safeArea ) {
r = this.getSafeRow( row );
c = this.getSafeColumn( col );
}
a = ( isValidRowCol( r, c, this._height, this._width ) && isValidBackgroundColor( color ) );

// If color is already set to default we can change it
b = a && ( overwrite || this._backgroundColorMatrix[ r ][ c ] === this._backgroundColor );
if ( b ) {
this._backgroundColorMatrix[ r ][ c ] = color;
}
}

module.exports = setBackgroundColor;
Loading
Loading