mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
MDL-55030 core: Support min and max in axes
Part of MDL-54987 epic.
This commit is contained in:
parent
909c5cf207
commit
46de49dc9f
2
lib/amd/build/chart_axis.min.js
vendored
2
lib/amd/build/chart_axis.min.js
vendored
@ -1 +1 @@
|
||||
define([],function(){function a(){}return a.prototype.POS_DEFAULT=null,a.prototype.POS_BOTTOM="bottom",a.prototype.POS_LEFT="left",a.prototype.POS_RIGHT="right",a.prototype.POS_TOP="top",a.prototype._label=null,a.prototype._position=null,a.prototype._stepSize=null,a.prototype.create=function(b){var c=new a;return c.setPosition(b.position),c.setLabel(b.label),c.setStepSize(b.stepSize),c},a.prototype.getLabel=function(){return this._label},a.prototype.getPosition=function(){return this._position},a.prototype.getStepSize=function(){return this._stepSize},a.prototype.setLabel=function(a){this._label=a||null},a.prototype.setPosition=function(a){if(a!=this.POS_DEFAULT&&a!=this.POS_BOTTOM&&a!=this.POS_LEFT&&a!=this.POS_RIGHT&&a!=this.POS_TOP)throw new Error("Invalid axis position.");this._position=a},a.prototype.setStepSize=function(a){if("undefined"==typeof a||null===a)a=null;else{if(isNaN(Number(a)))throw new Error("Value for stepSize is not a number.");a=Number(a)}this._stepSize=a},a});
|
||||
define([],function(){function a(){}return a.prototype.POS_DEFAULT=null,a.prototype.POS_BOTTOM="bottom",a.prototype.POS_LEFT="left",a.prototype.POS_RIGHT="right",a.prototype.POS_TOP="top",a.prototype._label=null,a.prototype._max=null,a.prototype._min=null,a.prototype._position=null,a.prototype._stepSize=null,a.prototype.create=function(b){var c=new a;return c.setPosition(b.position),c.setLabel(b.label),c.setStepSize(b.stepSize),c.setMax(b.max),c.setMin(b.min),c},a.prototype.getLabel=function(){return this._label},a.prototype.getMax=function(){return this._max},a.prototype.getMin=function(){return this._min},a.prototype.getPosition=function(){return this._position},a.prototype.getStepSize=function(){return this._stepSize},a.prototype.setLabel=function(a){this._label=a||null},a.prototype.setMax=function(a){this._max="undefined"!=typeof a?a:null},a.prototype.setMin=function(a){this._min="undefined"!=typeof a?a:null},a.prototype.setPosition=function(a){if(a!=this.POS_DEFAULT&&a!=this.POS_BOTTOM&&a!=this.POS_LEFT&&a!=this.POS_RIGHT&&a!=this.POS_TOP)throw new Error("Invalid axis position.");this._position=a},a.prototype.setStepSize=function(a){if("undefined"==typeof a||null===a)a=null;else{if(isNaN(Number(a)))throw new Error("Value for stepSize is not a number.");a=Number(a)}this._stepSize=a},a});
|
2
lib/amd/build/chart_output_chartjs.min.js
vendored
2
lib/amd/build/chart_output_chartjs.min.js
vendored
@ -1 +1 @@
|
||||
define(["jquery","core/chartjs","core/chart_axis","core/chart_output_base"],function(a,b,c,d){function e(){d.prototype.constructor.apply(this,arguments),this._build()}return e.prototype=Object.create(d.prototype),e.prototype._config=null,e.prototype._chartjs=null,e.prototype.getDatasets=function(){var a=this._chart.getSeries().map(function(a){return{label:a.getLabel(),data:a.getValues(),type:a.getType(),fill:!1,borderColor:a.getColor(),backgroundColor:a.getColor()}});return a},e.prototype._build=function(){this._config=this._makeConfig(),this._chartjs=new b(this._node[0],this._config)},e.prototype._makeAxisConfig=function(a){var b={};return a.getPosition()!==c.prototype.POS_DEFAULT&&(b.position=a.getPosition()),null!==a.getLabel()&&(b.scaleLabel={display:!0,labelString:a.getLabel()}),null!==a.getStepSize()&&(b.ticks=b.ticks||{},b.ticks.stepSize=a.getStepSize()),b},e.prototype._makeConfig=function(){var a={type:this._chart.getType(),data:{labels:this._chart.getLabels(),datasets:this.getDatasets()},options:{title:{display:null!==this._chart.getTitle(),text:this._chart.getTitle()}}};return this._chart.getXAxes().forEach(function(b,c){a.options.scales=a.options.scales||{},a.options.scales.xAxes=a.options.scales.xAxes||[],a.options.scales.xAxes[c]=this._makeAxisConfig(b)}.bind(this)),this._chart.getYAxes().forEach(function(b,c){a.options.scales=a.options.scales||{},a.options.scales.yAxes=a.options.scales.yAxes||[],a.options.scales.yAxes[c]=this._makeAxisConfig(b)}.bind(this)),a},e.prototype.update=function(){a.extend(!0,this._config,this._makeConfig()),this._chartjs.update()},e});
|
||||
define(["jquery","core/chartjs","core/chart_axis","core/chart_output_base"],function(a,b,c,d){function e(){d.prototype.constructor.apply(this,arguments),this._build()}return e.prototype=Object.create(d.prototype),e.prototype._config=null,e.prototype._chartjs=null,e.prototype.getDatasets=function(){var a=this._chart.getSeries().map(function(a){return{label:a.getLabel(),data:a.getValues(),type:a.getType(),fill:!1,borderColor:a.getColor(),backgroundColor:a.getColor()}});return a},e.prototype._build=function(){this._config=this._makeConfig(),this._chartjs=new b(this._node[0],this._config)},e.prototype._makeAxisConfig=function(a){var b={};return a.getPosition()!==c.prototype.POS_DEFAULT&&(b.position=a.getPosition()),null!==a.getLabel()&&(b.scaleLabel={display:!0,labelString:a.getLabel()}),null!==a.getStepSize()&&(b.ticks=b.ticks||{},b.ticks.stepSize=a.getStepSize()),null!==a.getMax()&&(b.ticks=b.ticks||{},b.ticks.max=a.getMax()),null!==a.getMin()&&(b.ticks=b.ticks||{},b.ticks.min=a.getMin()),b},e.prototype._makeConfig=function(){var a={type:this._chart.getType(),data:{labels:this._chart.getLabels(),datasets:this.getDatasets()},options:{title:{display:null!==this._chart.getTitle(),text:this._chart.getTitle()}}};return this._chart.getXAxes().forEach(function(b,c){a.options.scales=a.options.scales||{},a.options.scales.xAxes=a.options.scales.xAxes||[],a.options.scales.xAxes[c]=this._makeAxisConfig(b)}.bind(this)),this._chart.getYAxes().forEach(function(b,c){a.options.scales=a.options.scales||{},a.options.scales.yAxes=a.options.scales.yAxes||[],a.options.scales.yAxes[c]=this._makeAxisConfig(b)}.bind(this)),a},e.prototype.update=function(){a.extend(!0,this._config,this._makeConfig()),this._chartjs.update()},e});
|
@ -36,6 +36,8 @@ define([], function() {
|
||||
Axis.prototype.POS_TOP = 'top';
|
||||
|
||||
Axis.prototype._label = null;
|
||||
Axis.prototype._max = null;
|
||||
Axis.prototype._min = null;
|
||||
Axis.prototype._position = null;
|
||||
Axis.prototype._stepSize = null;
|
||||
|
||||
@ -44,6 +46,8 @@ define([], function() {
|
||||
s.setPosition(obj.position);
|
||||
s.setLabel(obj.label);
|
||||
s.setStepSize(obj.stepSize);
|
||||
s.setMax(obj.max);
|
||||
s.setMin(obj.min);
|
||||
return s;
|
||||
};
|
||||
|
||||
@ -51,6 +55,14 @@ define([], function() {
|
||||
return this._label;
|
||||
};
|
||||
|
||||
Axis.prototype.getMax = function() {
|
||||
return this._max;
|
||||
};
|
||||
|
||||
Axis.prototype.getMin = function() {
|
||||
return this._min;
|
||||
};
|
||||
|
||||
Axis.prototype.getPosition = function() {
|
||||
return this._position;
|
||||
};
|
||||
@ -63,6 +75,14 @@ define([], function() {
|
||||
this._label = label || null;
|
||||
};
|
||||
|
||||
Axis.prototype.setMax = function(max) {
|
||||
this._max = typeof max !== 'undefined' ? max : null;
|
||||
};
|
||||
|
||||
Axis.prototype.setMin = function(min) {
|
||||
this._min = typeof min !== 'undefined' ? min : null;
|
||||
};
|
||||
|
||||
Axis.prototype.setPosition = function(position) {
|
||||
if (position != this.POS_DEFAULT
|
||||
&& position != this.POS_BOTTOM
|
||||
|
@ -78,6 +78,16 @@ define([
|
||||
scaleData.ticks.stepSize = axis.getStepSize();
|
||||
}
|
||||
|
||||
if (axis.getMax() !== null) {
|
||||
scaleData.ticks = scaleData.ticks || {};
|
||||
scaleData.ticks.max = axis.getMax();
|
||||
}
|
||||
|
||||
if (axis.getMin() !== null) {
|
||||
scaleData.ticks = scaleData.ticks || {};
|
||||
scaleData.ticks.min = axis.getMin();
|
||||
}
|
||||
|
||||
return scaleData;
|
||||
};
|
||||
|
||||
|
@ -45,6 +45,8 @@ class chart_axis implements JsonSerializable {
|
||||
const POS_TOP = 'top';
|
||||
|
||||
protected $label = null;
|
||||
protected $max = null;
|
||||
protected $min = null;
|
||||
protected $position = self::POS_DEFAULT;
|
||||
protected $stepsize = null;
|
||||
|
||||
@ -55,6 +57,14 @@ class chart_axis implements JsonSerializable {
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
public function get_max() {
|
||||
return $this->max;
|
||||
}
|
||||
|
||||
public function get_min() {
|
||||
return $this->min;
|
||||
}
|
||||
|
||||
public function get_position() {
|
||||
return $this->position;
|
||||
}
|
||||
@ -66,6 +76,8 @@ class chart_axis implements JsonSerializable {
|
||||
public function jsonSerialize() {
|
||||
return [
|
||||
'label' => $this->label,
|
||||
'max' => $this->max,
|
||||
'min' => $this->min,
|
||||
'position' => $this->position,
|
||||
'stepSize' => $this->stepsize,
|
||||
];
|
||||
@ -75,6 +87,14 @@ class chart_axis implements JsonSerializable {
|
||||
return $this->label = $label;
|
||||
}
|
||||
|
||||
public function set_max($max) {
|
||||
return $this->max = $max;
|
||||
}
|
||||
|
||||
public function set_min($min) {
|
||||
return $this->min = $min;
|
||||
}
|
||||
|
||||
public function set_position($position) {
|
||||
return $this->position = $position;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user