mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
MDL-55030 core: Support setting defaults in charts
Part of MDL-54987 epic.
This commit is contained in:
parent
46de49dc9f
commit
a6c6faefb7
2
lib/amd/build/chart_base.min.js
vendored
2
lib/amd/build/chart_base.min.js
vendored
@ -1 +1 @@
|
||||
define(["core/chart_series","core/chart_axis"],function(a,b){function c(){this._series=[],this._labels=[],this._xaxes=[],this._yaxes=[]}return c.prototype._series=null,c.prototype._labels=null,c.prototype._title=null,c.prototype._xaxes=null,c.prototype._yaxes=null,c.prototype.COLORSET=["red","green","blue","yellow","pink","orange"],c.prototype.TYPE=null,c.prototype.addSeries=function(a){this._validateSerie(a),this._series.push(a),null===a.getColor()&&a.setColor(c.prototype.COLORSET[this._series.length%c.prototype.COLORSET.length])},c.prototype.create=function(c,d){var e=new c;return 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;if(c="undefined"==typeof c?0:c,d="undefined"==typeof d?!1:d,e=f[c],"undefined"==typeof e){if(!d)throw new Error("Unknown axis.");e=new b,f[c]=e}return e},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.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._xaxes[b]=a},c.prototype.setYAxis=function(a,b){b="undefined"==typeof b?0:b,this._yaxes[b]=a},c.prototype._validateSerie=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});
|
||||
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=["red","green","blue","yellow","pink","orange"],c.prototype.TYPE=null,c.prototype.addSeries=function(a){this._validateSerie(a),this._series.push(a),null===a.getColor()&&a.setColor(c.prototype.COLORSET[this._series.length%c.prototype.COLORSET.length])},c.prototype.create=function(c,d){var e=new c;return 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;if(c="undefined"==typeof c?0:c,d="undefined"==typeof d?!1:d,e=f[c],"undefined"==typeof e){if(!d)throw new Error("Unknown axis.");e=new b,f[c]=e}return e},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._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._xaxes[b]=a},c.prototype.setYAxis=function(a,b){b="undefined"==typeof b?0:b,this._yaxes[b]=a},c.prototype._validateSerie=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});
|
@ -30,6 +30,8 @@ define(['core/chart_series', 'core/chart_axis'], function(Series, Axis) {
|
||||
this._labels = [];
|
||||
this._xaxes = [];
|
||||
this._yaxes = [];
|
||||
|
||||
this._setDefaults();
|
||||
}
|
||||
Base.prototype._series = null;
|
||||
Base.prototype._labels = null;
|
||||
@ -123,6 +125,10 @@ define(['core/chart_series', 'core/chart_axis'], function(Series, Axis) {
|
||||
return this.__getAxis('y', index, createIfNotExists);
|
||||
};
|
||||
|
||||
Base.prototype._setDefaults = function() {
|
||||
// For the children to extend.
|
||||
};
|
||||
|
||||
Base.prototype.setLabels = function(labels) {
|
||||
if (labels.length && this._series.length && this._series[0].length != labels.length) {
|
||||
throw new Error('Series must match label values.');
|
||||
|
@ -45,6 +45,7 @@ class chart_base implements JsonSerializable, renderable {
|
||||
protected $yaxes = [];
|
||||
|
||||
public function __construct() {
|
||||
$this->set_defaults();
|
||||
}
|
||||
|
||||
public function add_series(chart_series $serie) {
|
||||
@ -114,6 +115,10 @@ class chart_base implements JsonSerializable, renderable {
|
||||
return $this->get_axis('y', $index, $createifnotexists);
|
||||
}
|
||||
|
||||
protected function set_defaults() {
|
||||
// For the child classes to extend.
|
||||
}
|
||||
|
||||
public function set_labels(array $labels) {
|
||||
$this->labels = $labels;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user