From 46de49dc9fc2d041048add6a8bea78053b9e0412 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Mon, 27 Jun 2016 18:50:41 +0800 Subject: [PATCH] MDL-55030 core: Support min and max in axes Part of MDL-54987 epic. --- lib/amd/build/chart_axis.min.js | Bin 997 -> 1311 bytes lib/amd/build/chart_output_chartjs.min.js | Bin 1602 -> 1730 bytes lib/amd/src/chart_axis.js | 20 ++++++++++++++++++++ lib/amd/src/chart_output_chartjs.js | 10 ++++++++++ lib/classes/chart_axis.php | 20 ++++++++++++++++++++ 5 files changed, 50 insertions(+) diff --git a/lib/amd/build/chart_axis.min.js b/lib/amd/build/chart_axis.min.js index 6a8f59dbce229b06479fafc6c430b9b79c2d2eb9..9499e8deb6c66195a320f4b5d64e880a9aa6f59c 100644 GIT binary patch delta 245 zcmaFLKA&sC1IgUP3fsKWoE)7*y@I0rlKhg&f>gcu+|0a*XSd7h6{nW?CRS)9=>e5# z>Li2tnRy_7X5QpRMh|A7?Bt7#l43ylS`;JFfjToMUtpAC1}WXaxVs*x)Hba&FS#T$ zKTji3v$`ZBvlwU-P*kZjFC{fCGcPqoNzoSMfc!LtMEgW5kh@S#1-U0P51TPSQT)bi JPGM?f1OSjlTVwzL delta 23 fcmbQw^^|?WgULLMOD11nbe&wvv}*HO<|0M_czp?d diff --git a/lib/amd/build/chart_output_chartjs.min.js b/lib/amd/build/chart_output_chartjs.min.js index 1bc028f71620cd91bd46610bbddd117eff35399b..e9144ce899b47391fd1e9fe685f83c4746027d35 100644 GIT binary patch delta 81 zcmX@abBK3C7BhcdX-AW<~kj#0t28hNh+tiki$kkQ$!c%si-? L%)HHM%y*aoOTil9 delta 12 TcmX@adx&R47W3v;%r}?-BMk*L diff --git a/lib/amd/src/chart_axis.js b/lib/amd/src/chart_axis.js index ee5d4596fac..53a2b756cc5 100644 --- a/lib/amd/src/chart_axis.js +++ b/lib/amd/src/chart_axis.js @@ -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 diff --git a/lib/amd/src/chart_output_chartjs.js b/lib/amd/src/chart_output_chartjs.js index 9b0e00bb4e2..f2a5c538825 100644 --- a/lib/amd/src/chart_output_chartjs.js +++ b/lib/amd/src/chart_output_chartjs.js @@ -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; }; diff --git a/lib/classes/chart_axis.php b/lib/classes/chart_axis.php index f151aeeace6..3ea13426aec 100644 --- a/lib/classes/chart_axis.php +++ b/lib/classes/chart_axis.php @@ -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; } -- 2.43.0