Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 | 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 189x 189x 189x 189x 189x 189x 189x 2x 2x 187x 189x 9x 9x 178x 178x 178x 178x 178x 189x 534x 534x 534x 178x 189x 1x 1x 177x 189x 1565x 1565x 1325x 1325x 240x 240x 240x 1565x 79x 79x 79x 79x 79x 1565x 98x 189x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 3x 13x 13x 13x 13x 13x 13x | /**
* @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 no-restricted-syntax, no-invalid-this */
'use strict';
// MODULES //
var EventEmitter = require( 'events' ).EventEmitter;
var logger = require( 'debug' );
var isObject = require( '@stdlib/assert/is-object' );
var setNonEnumerableReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
var setNonEnumerableReadOnlyAccessor = require( '@stdlib/utils/define-nonenumerable-read-only-accessor' ); // eslint-disable-line id-length
var setReadWriteAccessor = require( '@stdlib/utils/define-read-write-accessor' );
var hasProp = require( '@stdlib/assert/has-property' );
var inherit = require( '@stdlib/utils/inherit' );
var objectKeys = require( '@stdlib/utils/keys' );
var transformErrorMessage = require( '@stdlib/plot/vega/base/transform-validation-message' );
var instance2json = require( '@stdlib/plot/vega/base/to-json' );
var format = require( '@stdlib/string/format' );
var properties = require( './properties.json' );
var defaults = require( './defaults.js' );
// Note: keep the following in alphabetical order according to the `require` path...
var getDomain = require( './domain/get.js' );
var setDomain = require( './domain/set.js' );
var getDomainMax = require( './domain-max/get.js' );
var setDomainMax = require( './domain-max/set.js' );
var getDomainMid = require( './domain-mid/get.js' );
var setDomainMid = require( './domain-mid/set.js' );
var getDomainMin = require( './domain-min/get.js' );
var setDomainMin = require( './domain-min/set.js' );
var getDomainRaw = require( './domain-raw/get.js' );
var setDomainRaw = require( './domain-raw/set.js' );
var getInterpolate = require( './interpolate/get.js' );
var setInterpolate = require( './interpolate/set.js' );
var getName = require( './name/get.js' );
var setName = require( './name/set.js' );
var getProperties = require( './properties/get.js' );
var getRange = require( './range/get.js' );
var setRange = require( './range/set.js' );
var getReverse = require( './reverse/get.js' );
var setReverse = require( './reverse/set.js' );
var getRound = require( './round/get.js' );
var setRound = require( './round/set.js' );
var getType = require( './type/get.js' );
var setType = require( './type/set.js' );
// VARIABLES //
var debug = logger( 'vega:scale:main' );
// MAIN //
/**
* Scale constructor.
*
* @constructor
* @param {Options} options - constructor options
* @param {string} options.name - scale name
* @param {(Collection|Object|Signal)} [options.domain] - domain of associated data values
* @param {number} [options.domainMax] - maximum value in the scale domain (overrides the `domain` option)
* @param {number} [options.domainMin] - minimum value in the scale domain (overrides the `domain` option)
* @param {number} [options.domainMid] - single mid-point value inserted into a two-element domain
* @param {Collection} [options.domainRaw] - array of raw domain values which overrides the `domain` property
* @param {(string|Object)} [options.interpolate] - scale range interpolation method
* @param {(Collection|Object|Signal|string)} [options.range] - scale range
* @param {boolean} [options.reverse=false] - boolean indicating whether to reverse the order of the scale range
* @param {boolean} [options.round=false] - boolean indicating whether to round numeric output values to integers
* @param {string} [options.type='linear'] - scale type
* @throws {TypeError} options argument must be an object
* @throws {Error} must provide valid options
* @returns {Scale} scale instance
*
* @example
* var scale = new Scale({
* 'name': 'xScale'
* });
* // returns <Scale>
*/
function Scale( options ) {
var opts;
var keys;
var v;
var k;
var i;
if ( !( this instanceof Scale ) ) {
return new Scale( options );
}
EventEmitter.call( this );
if ( !isObject( options ) ) {
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
}
// Resolve the default configuration:
opts = defaults();
// Set internal properties according to the default configuration...
keys = objectKeys( opts );
for ( i = 0; i < keys.length; i++ ) {
k = keys[ i ];
this[ '_'+k ] = opts[ k ];
}
// Check for required properties...
if ( !hasProp( options, 'name' ) ) {
throw new TypeError( 'invalid argument. Options argument must specify the scale name.' );
}
// Validate provided options by attempting to assign option values to corresponding fields...
for ( i = 0; i < properties.length; i++ ) {
k = properties[ i ];
if ( !hasProp( options, k ) ) {
continue;
}
v = options[ k ];
try {
this[ k ] = v;
} catch ( err ) {
debug( 'Encountered an error. Error: %s', err.message );
// FIXME: retain thrown error type
throw new Error( transformErrorMessage( err.message ) );
}
}
return this;
}
/*
* Inherit from the `EventEmitter` prototype.
*/
inherit( Scale, EventEmitter );
/**
* Constructor name.
*
* @private
* @name name
* @memberof Scale
* @readonly
* @type {string}
*/
setNonEnumerableReadOnly( Scale, 'name', 'Scale' );
/**
* Scale domain.
*
* @name domain
* @memberof Scale.prototype
* @type {(Array|Object|Signal|void)}
*
* @example
* var scale = new Scale({
* 'name': 'xScale',
* 'domain': [ 0, 100 ]
* });
*
* var v = scale.domain;
* // returns [ 0, 100 ]
*/
setReadWriteAccessor( Scale.prototype, 'domain', getDomain, setDomain );
/**
* Explicit scale domain maximum value.
*
* @name domainMax
* @memberof Scale.prototype
* @type {(number|void)}
*
* @example
* var scale = new Scale({
* 'name': 'xScale',
* 'domainMax': 100
* });
*
* var v = scale.domainMax;
* // returns 100
*/
setReadWriteAccessor( Scale.prototype, 'domainMax', getDomainMax, setDomainMax );
/**
* Mid-point inserted into a two-element scale domain.
*
* @name domainMid
* @memberof Scale.prototype
* @type {(number|void)}
*
* @example
* var scale = new Scale({
* 'name': 'xScale',
* 'domainMid': 50
* });
*
* var v = scale.domainMid;
* // returns 50
*/
setReadWriteAccessor( Scale.prototype, 'domainMid', getDomainMid, setDomainMid );
/**
* Explicit scale domain minimum value.
*
* @name domainMin
* @memberof Scale.prototype
* @type {(number|void)}
*
* @example
* var scale = new Scale({
* 'name': 'xScale',
* 'domainMin': 0
* });
*
* var v = scale.domainMin;
* // returns 0
*/
setReadWriteAccessor( Scale.prototype, 'domainMin', getDomainMin, setDomainMin );
/**
* Raw scale domain values.
*
* @name domainRaw
* @memberof Scale.prototype
* @type {(Array|void)}
*
* @example
* var scale = new Scale({
* 'name': 'xScale',
* 'domainRaw': [ 0, 1, 2, 3, 4, 5 ]
* });
*
* var v = scale.domainRaw;
* // returns [ 0, 1, 2, 3, 4, 5 ]
*/
setReadWriteAccessor( Scale.prototype, 'domainRaw', getDomainRaw, setDomainRaw );
/**
* Scale range interpolation method.
*
* @name interpolate
* @memberof Scale.prototype
* @type {(string|Object|void)}
*
* @example
* var scale = new Scale({
* 'name': 'xScale',
* 'interpolate': 'rgb'
* });
*
* var v = scale.interpolate;
* // returns 'rgb'
*/
setReadWriteAccessor( Scale.prototype, 'interpolate', getInterpolate, setInterpolate );
/**
* Scale name.
*
* @name name
* @memberof Scale.prototype
* @type {string}
*
* @example
* var scale = new Scale({
* 'name': 'xScale'
* });
*
* var v = scale.name;
* // returns 'xScale'
*/
setReadWriteAccessor( Scale.prototype, 'name', getName, setName );
/**
* Scale properties.
*
* @name properties
* @memberof Scale.prototype
* @type {Array<string>}
*
* @example
* var scale = new Scale({
* 'name': 'xScale'
* });
*
* var v = scale.properties;
* // returns [...]
*/
setNonEnumerableReadOnlyAccessor( Scale.prototype, 'properties', getProperties );
/**
* Scale range.
*
* @name range
* @memberof Scale.prototype
* @type {(Array|Object|Signal|string|void)}
*
* @example
* var scale = new Scale({
* 'name': 'xScale',
* 'range': [ 0, 100 ]
* });
*
* var v = scale.range;
* // returns [ 0, 100 ]
*/
setReadWriteAccessor( Scale.prototype, 'range', getRange, setRange );
/**
* Boolean indicating whether to reverse the order of the scale range.
*
* @name reverse
* @memberof Scale.prototype
* @type {boolean}
* @default false
*
* @example
* var scale = new Scale({
* 'name': 'xScale',
* 'reverse': true
* });
*
* var v = scale.reverse;
* // returns true
*/
setReadWriteAccessor( Scale.prototype, 'reverse', getReverse, setReverse );
/**
* Boolean indicating whether to round numeric output value to integers.
*
* @name round
* @memberof Scale.prototype
* @type {boolean}
* @default false
*
* @example
* var scale = new Scale({
* 'name': 'xScale',
* 'round': true
* });
*
* var v = scale.round;
* // returns true
*/
setReadWriteAccessor( Scale.prototype, 'round', getRound, setRound );
/**
* Scale type.
*
* @name type
* @memberof Scale.prototype
* @type {string}
* @default 'linear'
*
* @example
* var scale = new Scale({
* 'name': 'xScale',
* 'type': 'log'
* });
*
* var v = scale.type;
* // returns 'log'
*/
setReadWriteAccessor( Scale.prototype, 'type', getType, setType );
/**
* Serializes an instance to a JSON object.
*
* ## Notes
*
* - This method is implicitly invoked by `JSON.stringify`.
*
* @name toJSON
* @memberof Scale.prototype
* @type {Function}
* @returns {Object} JSON object
*
* @example
* var scale = new Scale({
* 'name': 'xScale'
* });
*
* var v = scale.toJSON();
* // returns {...}
*/
setNonEnumerableReadOnly( Scale.prototype, 'toJSON', function toJSON() {
return instance2json( this, properties );
});
// EXPORTS //
module.exports = Scale;
|