Part of MDL-54987 epic.
/** @override */
Line.prototype.TYPE = 'line';
+ /**
+ * Whether the line should be smooth or not.
+ *
+ * By default the chart lines are not smooth.
+ *
+ * @type {Bool}
+ * @protected
+ */
+ Line.prototype._smooth = false;
+
+ /** @override */
+ Line.prototype.create = function(Klass, data) {
+ var chart = Base.prototype.create.apply(this, arguments);
+ chart.setSmooth(data.smooth);
+ return chart;
+ };
+
+ /**
+ * Get whether the line should be smooth or not.
+ *
+ * @method getSmooth
+ * @returns {Bool}
+ */
+ Line.prototype.getSmooth = function() {
+ return this._smooth;
+ };
+
+ /**
+ * Set whether the line should be smooth or not.
+ *
+ * @method setSmooth
+ * @param {Bool} smooth True if the line chart should be smooth, false otherwise.
+ */
+ Line.prototype.setSmooth = function(smooth) {
+ this._smooth = Boolean(smooth);
+ };
+
return Line;
});
'core/chartjs',
'core/chart_axis',
'core/chart_output_base',
+ 'core/chart_line',
'core/chart_pie',
-], function($, Chartjs, Axis, Base, Pie) {
+ 'core/chart_series'
+], function($, Chartjs, Axis, Base, Line, Pie, Series) {
/**
* Makes an axis ID.
backgroundColor: colors,
// Pie charts look better without borders.
borderColor: this._chart.getType() == Pie.prototype.TYPE ? null : colors,
+ lineTension: this._isSmooth(series) ? 0.3 : 0
};
if (series.getXAxis() !== null) {
return sets;
};
+ /**
+ * Verify if the chart line is smooth or not.
+ *
+ * @protected
+ * @param {module:core/chart_series} series The series.
+ * @returns {Bool}
+ */
+ Output.prototype._isSmooth = function(series) {
+ var smooth = false;
+ if (this._chart.getType() === Line.prototype.TYPE) {
+ smooth = series.getSmooth();
+ if (smooth === null) {
+ smooth = this._chart.getSmooth();
+ }
+ } else if (series.getType() === Series.prototype.TYPE_LINE) {
+ smooth = series.getSmooth();
+ }
+
+ return smooth;
+ };
+
/** @override */
Output.prototype.update = function() {
$.extend(true, this._config, this._makeConfig());
*/
Series.prototype._label = null;
+ /**
+ * Whether the line of the serie should be smooth or not.
+ *
+ * @type {Bool}
+ * @protected
+ */
+ Series.prototype._smooth = false;
+
/**
* The type of the series.
*
s.setColor(obj.colors[0]);
}
+ s.setSmooth(obj.smooth);
return s;
};
return this._label;
};
+ /**
+ * Get whether the line of the serie should be smooth or not.
+ *
+ * @returns {Bool}
+ */
+ Series.prototype.getSmooth = function() {
+ return this._smooth;
+ };
+
/**
* Get the series type.
*
this._colors = colors || [];
};
+ /**
+ * Set Whether the line of the serie should be smooth or not.
+ *
+ * Only applicable for line chart or a line series, if null it assumes the chart default (not smooth).
+ *
+ * @param smooth
+ */
+ Series.prototype.setSmooth = function(smooth) {
+ smooth = typeof smooth === 'undefined' ? null : smooth;
+ this._smooth = smooth;
+ };
+
/**
* Set the type of the series.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class chart_line extends chart_base {
+
+ /** @var bool Whether the line should be smooth or not. */
+ protected $smooth = false;
+
+ /**
+ * Add the smooth to the parent and return the serialized data.
+ *
+ * @return array
+ */
+ public function jsonSerialize() {
+ $data = parent::jsonSerialize();
+ $data['smooth'] = $this->get_smooth();
+ return $data;
+ }
+
+ /**
+ * Get whether a lines should be smooth or not.
+ *
+ * @return bool
+ */
+ public function get_smooth() {
+ return $this->smooth;
+ }
+
+ /**
+ * Set Whether the line should be smooth or not.
+ *
+ * @param bool $smooth True if the line chart should be smooth, false otherwise.
+ */
+ public function set_smooth($smooth) {
+ $this->smooth = $smooth;
+ }
}
protected $colors = [];
/** @var string Label for this series. */
protected $label;
+ /** @var bool Whether the line of the serie should be smooth or not. */
+ protected $smooth = null;
/** @var string Type of the series. */
protected $type = self::TYPE_DEFAULT;
/** @var float[] Values of the series. */
return $this->label;
}
+ /**
+ * Get whether the line of the serie should be smooth or not.
+ *
+ * @return bool
+ */
+ public function get_smooth() {
+ return $this->smooth;
+ }
+
/**
* Get the type of series.
*
'axes' => [
'x' => $this->xaxis,
'y' => $this->yaxis,
- ]
+ ],
+ 'smooth' => $this->smooth
];
return $data;
}
$this->colors = $colors;
}
+ /**
+ * Set whether the line of the serie should be smooth or not.
+ *
+ * Only applicable for line chart or a line series, if null it assumes the chart default (not smooth).
+ *
+ * @param bool true if the line should be smooth, false if not.
+ */
+ public function set_smooth($smooth) {
+ $this->smooth = $smooth;
+ }
+
/**
* Set the type of the series.
*