From 88dd8ba799351f759120def4aa17f710844d95d3 Mon Sep 17 00:00:00 2001 From: Ira Andrushko Date: Fri, 28 Mar 2025 18:22:22 -0400 Subject: [PATCH] chore: fix JavaScript lint errors #6383 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/plot/base/ctor/lib/defaults.js | 3 + .../@stdlib/plot/base/ctor/lib/main.js | 41 +++++++++++- .../plot/base/ctor/lib/props/x-scale/get.js | 54 ++++++++++++++++ .../plot/base/ctor/lib/props/x-scale/set.js | 63 +++++++++++++++++++ 4 files changed, 158 insertions(+), 3 deletions(-) create mode 100644 lib/node_modules/@stdlib/plot/base/ctor/lib/props/x-scale/get.js create mode 100644 lib/node_modules/@stdlib/plot/base/ctor/lib/props/x-scale/set.js diff --git a/lib/node_modules/@stdlib/plot/base/ctor/lib/defaults.js b/lib/node_modules/@stdlib/plot/base/ctor/lib/defaults.js index 4d0e929a11c3..db52ed2a24f4 100644 --- a/lib/node_modules/@stdlib/plot/base/ctor/lib/defaults.js +++ b/lib/node_modules/@stdlib/plot/base/ctor/lib/defaults.js @@ -109,6 +109,9 @@ function defaults() { // Number of x-axis tick marks: o.xNumTicks = 5; + // x-axis scale: + o.xScale = 'linear'; + // x-axis tick format: o.xTickFormat = null; diff --git a/lib/node_modules/@stdlib/plot/base/ctor/lib/main.js b/lib/node_modules/@stdlib/plot/base/ctor/lib/main.js index d06d83cb323c..c992b16f9461 100644 --- a/lib/node_modules/@stdlib/plot/base/ctor/lib/main.js +++ b/lib/node_modules/@stdlib/plot/base/ctor/lib/main.js @@ -61,6 +61,8 @@ var setPaddingRight = require( './props/padding-right/set.js' ); var getPaddingRight = require( './props/padding-right/get.js' ); var setPaddingTop = require( './props/padding-top/set.js' ); var getPaddingTop = require( './props/padding-top/get.js' ); +var setXScale = require( './props/x-scale/set.js' ); +var getXScale = require( './props/x-scale/get.js' ); var render = require( './render' ); var stub = require( './render/stub.js' ); var setRenderFormat = require( './props/render-format/set.js' ); @@ -174,6 +176,7 @@ var merge = mergeFcn({ * @param {(Date|FiniteNumber|null)} [options.xMax=null] - maximum value of x-axis domain * @param {(Date|FiniteNumber|null)} [options.xMin=null] - minimum value of x-axis domain * @param {(NonNegativeInteger|null)} [options.xNumTicks=5] - number of x-axis tick marks +* @param {string} [options.xScale='time'] - x-axis scale * @param {(string|null)} [options.xTickFormat=null] - x-axis tick format * @param {string} [options.yAxisOrient='left'] - y-axis orientation * @param {string} [options.yLabel='y'] - y-axis label @@ -220,12 +223,17 @@ function Plot() { throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); } } else if ( nargs === 2 ) { - options = {}; + options = { + 'x': arguments[ 0 ], + 'y': arguments[ 1 ] + }; } else if ( nargs > 2 ) { - if ( !isObject( arguments[ 2 ] ) ) { + if ( !isObject( arguments[2] ) ) { throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', arguments[2] ) ); } - options = copy( arguments[ 2 ] ); // avoid mutation + options = copy( arguments[2] ); // avoid mutation + options.x = arguments[ 0 ]; + options.y = arguments[ 1 ]; } opts = merge( opts, options ); @@ -1023,6 +1031,33 @@ defineProperty( Plot.prototype, 'xRange', { 'get': getXRange }); +/** +* Scale function for mapping values to a coordinate along the x-axis. When retrieved, the returned value is a scale function. +* +* @name xScale +* @memberof Plot.prototype +* @type {string} +* @throws {TypeError} must be a string +* @default 'linear' +* +* @example +* var plot = new Plot(); +* plot.xScale = 'time'; +* +* @example +* var plot = new Plot({ +* 'xScale': 'time' +* }); +* var scale = plot.xScale; +* // returns +*/ +defineProperty( Plot.prototype, 'xScale', { + 'configurable': false, + 'enumerable': true, + 'set': setXScale, + 'get': getXScale +}); + /** * x-axis tick format. * diff --git a/lib/node_modules/@stdlib/plot/base/ctor/lib/props/x-scale/get.js b/lib/node_modules/@stdlib/plot/base/ctor/lib/props/x-scale/get.js new file mode 100644 index 000000000000..7da479347d9a --- /dev/null +++ b/lib/node_modules/@stdlib/plot/base/ctor/lib/props/x-scale/get.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 linear = require( 'd3-scale' ).scaleLinear; // TODO: remove +var time = require( 'd3-scale' ).scaleTime; // TODO: remove + + +// MAIN // + +/** +* Returns a scale function for mapping values to a coordinate along the x-axis. +* +* @private +* @returns {Function} scale function +*/ +function get() { + /* eslint-disable no-invalid-this */ + var scale; + if ( this._xScale === 'time' ) { + scale = time() + .domain( this.xDomain ) + .range( this.xRange ); + } else if ( this._xScale === 'linear' ) { + scale = linear() + .domain( this.xDomain ) + .range( this.xRange ); + } + // TODO: other scales + return scale; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/base/ctor/lib/props/x-scale/set.js b/lib/node_modules/@stdlib/plot/base/ctor/lib/props/x-scale/set.js new file mode 100644 index 000000000000..6178e1b7d8f7 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/base/ctor/lib/props/x-scale/set.js @@ -0,0 +1,63 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 logger = require( 'debug' ); +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var format = require( '@stdlib/string/format' ); + + +// VARIABLES // + +var debug = logger( 'plot:base:set:x-scale' ); + + +// MAIN // + +/** +* Sets the x-axis scale. +* +* @private +* @param {string} scale - axis scale +* @throws {TypeError} must be a string +* @returns {void} +*/ +function set( scale ) { + /* eslint-disable no-invalid-this */ + if ( !isString( scale ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string. Value: `%s`.', 'xScale', scale ) ); + } + // TODO: test for valid scale + + if ( scale !== this._xScale ) { + debug( 'Current value: %s.', this._xScale ); + + this._xScale = scale; + debug( 'New value: %s.', this._xScale ); + + this.emit( 'change' ); + } +} + + +// EXPORTS // + +module.exports = set;