'use strict';

// MODULES //

var isObject = require( '@stdlib/utils/is-object' ); // TODO: is-plain-object
var copy = require( '@stdlib/utils/copy' );
var Plot = require( './plot.js' );


// FACTORY //

/**
* Returns a reusable function for generating plots.
*
* @param {Options} [options] - factory options
* TODO
* @returns {Function} plot function
*
* @example
* var opts = {
*     'width': 600,
*     'height': 400
* };
* var plot = factory( opts );
* var h1 = plot( [[1,2,3]], [[1,0,1]] );
* var h2 = plot( [[4,5,6]], [[0,1,0]] );
*/
function factory( options ) {
	var opts;
	if ( arguments.length ) {
		if ( !isObject( options ) ) {
			throw new TypeError( 'invalid input argument. `options` argument must be a plain object. Value: `' + options + '`' );
		}
		opts = copy( options );
	} else {
		opts = {};
	}
	/**
	* Creates a plot.
	*
	* @private
	* @param {Array} [x] - x-values
	* @param {Array} [y] - y-values
	* @returns {Plot} plot instance
	*/
	return function plot( x, y ) {
		if ( arguments.length === 2 ) {
			return new Plot( x, y, opts );
		}
		return new Plot( opts );
	}; // end FUNCTION plot()
} // end FUNCTION factory()


// EXPORTS //

module.exports = factory;

'use strict';

// MODULES //

var isObject = require( '@stdlib/utils/is-object' ); // TODO: is-plain-object
var copy = require( '@stdlib/utils/copy' );
var Plot = require( './plot.js' );


// FACTORY //

/**
* Returns a reusable function for generating plots.
*
* @param {Options} [options] - factory options
* TODO
* @throws {TypeError} must provide an object
* @returns {Function} plot function
*
* @example
* var opts = {
*     'width': 600,
*     'height': 400
* };
* var plot = factory( opts );
* var h1 = plot( [[1,2,3]], [[1,0,1]] );
* var h2 = plot( [[4,5,6]], [[0,1,0]] );
*/
function factory( options ) {
	var opts;
	if ( arguments.length ) {
		if ( !isObject( options ) ) {
			throw new TypeError( 'invalid input argument. `options` argument must be a plain object. Value: `' + options + '`' );
		}
		opts = copy( options );
	} else {
		opts = {};
	}
	/**
	* Creates a plot.
	*
	* @private
	* @param {Array} [x] - x-values
	* @param {Array} [y] - y-values
	* @throws {TypeError} must provide valid options
	* @returns {Plot} plot instance
	*/
	return function plot( x, y ) {
		if ( arguments.length === 2 ) {
			return new Plot( x, y, opts );
		}
		return new Plot( opts );
	}; // end FUNCTION plot()
} // end FUNCTION factory()


// EXPORTS //

module.exports = factory;

Add JSDoc throws annotations