// SET // /** * FUNCTION: set( i, j, value ) * Sets a matrix element based on the provided row and column indices. * * @param {Number} i - row index * @param {Number} j - column index * @param {Number} value - value to set * @returns {Matrix} Matrix instance */ function set( i, j, v ) { /* jshint validthis: true */ if ( !isNonNegativeInteger( i ) || !isNonNegativeInteger( j ) ) { throw new TypeError( 'invalid input argument. Row and column indices must be nonnegative integers. Values: `[' + i + ',' + j + ']`.' ); } if ( !isNumber( v ) && !isnan( v ) ) { throw new TypeError( 'invalid input argument. An input value must be a number primitive. Value: `' + v + '`.' ); } i = this.offset + i*this.strides[0] + j*this.strides[1]; if ( i >= 0 ) { this.data[ i ] = v; } return this; } // end FUNCTION set()
// DELETE // /** * FUNCTION: del( id, options, clbk ) * Deletes a token. * * @param {Number} id - token id * @param {Object} options - function options * @param {String} options.username - Github username * @param {String} options.password - Github password * @param {String} [options.otp] - Github one-time password * @param {String} [options.useragent] - user agent string * @param {Function} clbk - callback to invoke upon query completion * @returns {Function} function for deleting a token */ function del( id, options, clbk ) { var opts; var err; if ( !isNonNegativeInteger( id ) ) { throw new TypeError( 'invalid input argument. Token id must be a nonnegative integer. Value: `' + id + '`.' ); } if ( !isFunction( clbk ) ) { throw new TypeError( 'invalid input argument. Callback argument must be a function. Value: `' + clbk + '`.' ); } opts = copy( defaults ); err = validate( opts, options ); if ( err ) { throw err; } query( id, opts, done ); /** * FUNCTION: done( error, info ) * Callback invoked after receiving an API response. * * @private * @param {Error|Null} error - error object * @param {Object} info - response info * @returns {Void} */ function done( error, info ) { error = error || null; info = info || null; clbk( error, info ); } // end FUNCTION done() } // end FUNCTION del()
// VALIDATE // /** * FUNCTION: validate( opts, options ) * Validates function options. * * @param {Object} opts - destination object * @param {Object} options - options to validate * @param {String} [options.protocol] - request protocol * @param {String} [options.hostname] - endpoint hostname * @param {Number} [options.port] - endpoint port * @param {String} [options.pathname] - resource pathname * @param {String} [options.query=""] - params portion of a query string * @param {String} [options.token] - Travis CI access token * @param {String} [options.accept] - media type * @param {String} [options.useragent] - user agent string * @returns {Error|Null} error or null */ function validate( opts, options ) { if ( !isObject( options ) ) { return new TypeError( 'invalid input argument. Options argument must be an object. Value: `' + options + '`.' ); } if ( options.hasOwnProperty( 'protocol' ) ) { opts.protocol = options.protocol; if ( !isString( opts.protocol ) ) { return new TypeError( 'invalid option. `protocol` option must be a string primitive. Option: `' + opts.protocol + '`.' ); } if ( opts.protocol !== 'http' && opts.protocol !== 'https' ) { return new Error( 'invalid option. Protocol must be either `http` or `https`. Option: `' + opts.protocol + '`.' ); } } if ( options.hasOwnProperty( 'hostname' ) ) { opts.hostname = options.hostname; if ( !isString( opts.hostname ) ) { return new TypeError( 'invalid option. `hostname` option must be a string primitive. Option: `' + opts.hostname + '`.' ); } } if ( options.hasOwnProperty( 'port' ) ) { opts.port = options.port; if ( !isNonNegativeInteger( opts.port ) ) { return new TypeError( 'invalid option. `port` option must be a nonnegative integer. Option: `' + opts.port + '`.' ); } } if ( options.hasOwnProperty( 'pathname' ) ) { opts.pathname = options.pathname; if ( !isString( opts.pathname ) ) { return new TypeError( 'invalid option. `pathname` option must be a string primitive. Option: `' + opts.pathname + '`.' ); } } if ( options.hasOwnProperty( 'query' ) ) { opts.query = options.query; if ( !isString( opts.query ) ) { return new TypeError( 'invalid option. `query` option must be a string primitive. Option: `' + opts.query + '`.' ); } } if ( options.hasOwnProperty( 'token' ) ) { opts.token = options.token; if ( !isString( opts.token ) ) { return new TypeError( 'invalid option. `token` option must be a string primitive. Option: `' + opts.token + '`.' ); } } if ( options.hasOwnProperty( 'accept' ) ) { opts.accept = options.accept; if ( !isString( opts.accept ) ) { return new TypeError( 'invalid option. `accept` option must be a string primitive. Option: `' + opts.accept + '`.' ); } } if ( options.hasOwnProperty( 'useragent' ) ) { opts.useragent = options.useragent; if ( !isString( opts.useragent ) ) { return new TypeError( 'invalid option. `useragent` option must be a string primitive. Option: `' + opts.useragent + '`.' ); } } return null; } // end FUNCTION validate()
// OBSERVER // /** * FUNCTION: paddingTopChanged( newVal, oldVal ) * Event handler invoked when the `paddingTop` property changes. * * @param {Number} newVal - new value * @param {Number} oldVal - old value */ function paddingTopChanged( newVal, oldVal ) { /* jshint validthis:true */ var height, range, err; if ( oldVal === void 0 ) { return; } if ( !isNonNegativeInteger( newVal ) ) { err = new TypeError( 'paddingTop::invalid assignment. Must be a nonnegative integer. Value: `' + newVal + '.' ); this.fire( 'err', err ); this.paddingTop = oldVal; return; } height = this.height - newVal - this.paddingBottom; // [0] Update the yScale: range = [ height, 0 ]; this._yScale.range( range ); if ( this.autoUpdate ) { // [1] Update the background: this.$.bkgd.attr( 'height', height ); // [2] Update the clipPath: this.$.clipPath.attr( 'height', height ); // [3] Update the graph: this.$.graph.attr( 'transform', 'translate(' + this.paddingLeft + ',' + newVal + ')' ); // [4] Update the x-axis: this.$.xAxis.attr( 'transform', 'translate(0,' + height + ')' ); // [5] Update the y-axis: this.$.yAxis.call( this._yAxis ); // [6] Update the y-label position: this.$.yLabel.attr( 'x', -height / 2 ); // [7] Update the paths: this.$.paths.attr( 'd', this._line ); // [8] Update the annotations: this.$.annotationMarkers.attr( 'd', this._triangle ); this.$.annotationLines.attr( 'd', this._vline ); } this.fire( 'change', { 'attr': 'paddingTop', 'prev': oldVal, 'curr': newVal }); } // end FUNCTION paddingTopChanged()
// OBSERVER // /** * FUNCTION: yNumTicksChanged( newVal, oldVal ) * Event handler invoked when the `yNumTicks` property changes. * * @param {Number|Null} newVal - new value * @param {Number|Null} oldVal - old value */ function yNumTicksChanged( newVal, oldVal ) { /* jshint validthis:true */ var err; if ( oldVal === void 0 ) { return; } if ( newVal !== null && !isNonNegativeInteger( newVal ) ) { err = new TypeError( 'yNumTicks::invalid assignment. Must be a nonnegative integer or null. Value: `' + newVal + '`.' ); this.fire( 'err', err ); this.yNumTicks = oldVal; return; } this._yAxis.ticks( newVal ); if ( this.autoUpdate ) { this.$.yAxis.call( this._yAxis ); } this.fire( 'change', { 'attr': 'yNumTicks', 'prev': oldVal, 'curr': newVal }); } // end FUNCTION yNumTicksChanged()