From a6c6faefb754747f8007ac7d12c3d7eec0b61910 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Tue, 28 Jun 2016 12:20:38 +0800 Subject: [PATCH 1/1] MDL-55030 core: Support setting defaults in charts Part of MDL-54987 epic. --- lib/amd/build/chart_base.min.js | Bin 2248 -> 2306 bytes lib/amd/src/chart_base.js | 6 ++++++ lib/classes/chart_base.php | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/lib/amd/build/chart_base.min.js b/lib/amd/build/chart_base.min.js index 0ec2d171ebcd4173941e7a9d44cd63cf8c4a11e5..375f189bbc6fff01de1b4f876f47e22ff8ca008f 100644 GIT binary patch delta 61 zcmX>h*d#QeT|}oOBePg9zBskSB{eOvG^eCkLvv&M4ps?dA=|XlyyTM1{5%cK>dl61 G)0qIvY8Jr& delta 15 WcmZn?Iw3fredFvMteY#@I+*}9(*{cb diff --git a/lib/amd/src/chart_base.js b/lib/amd/src/chart_base.js index 113f39a2e07..74da8635c85 100644 --- a/lib/amd/src/chart_base.js +++ b/lib/amd/src/chart_base.js @@ -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.'); diff --git a/lib/classes/chart_base.php b/lib/classes/chart_base.php index 1bf9082ff6f..6abbcf592b0 100644 --- a/lib/classes/chart_base.php +++ b/lib/classes/chart_base.php @@ -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; } -- 2.43.0