You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
2.8 KiB

define(["core/chart_series","core/chart_axis"],function(a,b){function c(){this._series=[],this._labels=[],this._xaxes=[],this._yaxes=[],this._setDefaults()}return c.prototype._series=null,c.prototype._labels=null,c.prototype._title=null,c.prototype._xaxes=null,c.prototype._yaxes=null,c.prototype.COLORSET=["#f3c300","#875692","#f38400","#a1caf1","#be0032","#c2b280","#7f180d","#008856","#e68fac","#0067a5"],c.prototype._configColorSet=null,c.prototype.TYPE=null,c.prototype.addSeries=function(a){if(this._validateSeries(a),this._series.push(a),null===a.getColor()){var b=this.getConfigColorSet()||c.prototype.COLORSET;a.setColor(b[this._series.length%b.length])}},c.prototype.create=function(c,d){var e=new c;return e.setConfigColorSet(d.config_colorset),e.setLabels(d.labels),e.setTitle(d.title),d.series.forEach(function(b){e.addSeries(a.prototype.create(b))}),d.axes.x.forEach(function(a,c){e.setXAxis(b.prototype.create(a),c)}),d.axes.y.forEach(function(a,c){e.setYAxis(b.prototype.create(a),c)}),e},c.prototype.__getAxis=function(a,c,d){var e,f="x"===a?this._xaxes:this._yaxes,g=("x"===a?this.setXAxis:this.setYAxis).bind(this);if(c="undefined"==typeof c?0:c,d="undefined"!=typeof d&&d,e=f[c],"undefined"==typeof e){if(!d)throw new Error("Unknown axis.");e=new b,g(e,c)}return e},c.prototype.getConfigColorSet=function(){return this._configColorSet},c.prototype.getLabels=function(){return this._labels},c.prototype.getSeries=function(){return this._series},c.prototype.getTitle=function(){return this._title},c.prototype.getType=function(){if(!this.TYPE)throw new Error("The TYPE property has not been set.");return this.TYPE},c.prototype.getXAxes=function(){return this._xaxes},c.prototype.getXAxis=function(a,b){return this.__getAxis("x",a,b)},c.prototype.getYAxes=function(){return this._yaxes},c.prototype.getYAxis=function(a,b){return this.__getAxis("y",a,b)},c.prototype.setConfigColorSet=function(a){this._configColorSet=a},c.prototype._setDefaults=function(){},c.prototype.setLabels=function(a){if(a.length&&this._series.length&&this._series[0].length!=a.length)throw new Error("Series must match label values.");this._labels=a},c.prototype.setTitle=function(a){this._title=a},c.prototype.setXAxis=function(a,b){b="undefined"==typeof b?0:b,this._validateAxis("x",a,b),this._xaxes[b]=a},c.prototype.setYAxis=function(a,b){b="undefined"==typeof b?0:b,this._validateAxis("y",a,b),this._yaxes[b]=a},c.prototype._validateAxis=function(a,b,c){if(c="undefined"==typeof c?0:c,c>0){var d="x"==a?this._xaxes:this._yaxes;if("undefined"==typeof d[c-1])throw new Error("Missing "+a+" axis at index lower than "+c)}},c.prototype._validateSeries=function(a){if(this._series.length&&this._series[0].getCount()!=a.getCount())throw new Error("Series do not have an equal number of values.");if(this._labels.length&&this._labels.length!=a.getCount())throw new Error("Series must match label values.")},c});