From d06fbc772f727ae7ab3fec7d7b18f9271d4df6ee Mon Sep 17 00:00:00 2001 From: MatthieuRivaud Date: Mon, 8 Aug 2016 15:35:46 +0200 Subject: [PATCH] - Added dataset option |cubicInterpolationMode| to allow for curves with different interpolation modes on the same graph (updated doc accordingly) - Added new sample file to demonstrate the monotone cubic interpolation mode - Fixed a typo in a comment in updateBezierControlPoints --- docs/03-Line-Chart.md | 2 +- samples/line-cubicInterpolationMode.html | 113 +++++++++++++++++++++++ src/controllers/controller.line.js | 5 +- 3 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 samples/line-cubicInterpolationMode.html diff --git a/docs/03-Line-Chart.md b/docs/03-Line-Chart.md index 35e518018..f62a20879 100644 --- a/docs/03-Line-Chart.md +++ b/docs/03-Line-Chart.md @@ -39,7 +39,7 @@ label | `String` | The label for the dataset which appears in the legend and too xAxisID | `String` | The ID of the x axis to plot this dataset on yAxisID | `String` | The ID of the y axis to plot this dataset on fill | `Boolean` | If true, fill the area under the line -cubicInterpolationMode | `String` | Algorithm used to interpolate a smooth curve from the discrete data points. Options are 'default' and 'monotone'. The 'default' algorithm uses a custom weighted cubic interpolation, which produces pleasant curves for all types of datasets. The 'monotone' algorithm is more suited to `y = f(x)` datasets : it preserves monotonicity (or piecewise monotonicity) of the dataset being interpolated, and ensures local extremums (if any) stay at input data points. If unknown or `undefined`, this options is treated as 'default'. +cubicInterpolationMode | `String` | Algorithm used to interpolate a smooth curve from the discrete data points. Options are 'default' and 'monotone'. The 'default' algorithm uses a custom weighted cubic interpolation, which produces pleasant curves for all types of datasets. The 'monotone' algorithm is more suited to `y = f(x)` datasets : it preserves monotonicity (or piecewise monotonicity) of the dataset being interpolated, and ensures local extremums (if any) stay at input data points. If left untouched (`undefined`), the global `options.elements.line.cubicInterpolationMode` property is used. lineTension | `Number` | Bezier curve tension of the line. Set to 0 to draw straightlines. This option is ignored if monotone cubic interpolation is used. *Note* This was renamed from 'tension' but the old name still works. backgroundColor | `Color` | The fill color under the line. See [Colors](#chart-configuration-colors) borderWidth | `Number` | The width of the line in pixels diff --git a/samples/line-cubicInterpolationMode.html b/samples/line-cubicInterpolationMode.html new file mode 100644 index 000000000..97dac46ca --- /dev/null +++ b/samples/line-cubicInterpolationMode.html @@ -0,0 +1,113 @@ + + + + + Line Chart - Cubic interpolation mode + + + + + + +
+ +
+
+
+ + + + + \ No newline at end of file diff --git a/src/controllers/controller.line.js b/src/controllers/controller.line.js index 5b453b44b..b103907ea 100644 --- a/src/controllers/controller.line.js +++ b/src/controllers/controller.line.js @@ -90,6 +90,7 @@ module.exports = function(Chart) { borderJoinStyle: custom.borderJoinStyle ? custom.borderJoinStyle : (dataset.borderJoinStyle || lineElementOptions.borderJoinStyle), fill: custom.fill ? custom.fill : (dataset.fill !== undefined ? dataset.fill : lineElementOptions.fill), steppedLine: custom.steppedLine ? custom.steppedLine : helpers.getValueOrDefault(dataset.steppedLine, lineElementOptions.stepped), + cubicInterpolationMode: custom.cubicInterpolationMode ? custom.cubicInterpolationMode : helpers.getValueOrDefault(dataset.cubicInterpolationMode, lineElementOptions.cubicInterpolationMode), // Scale scaleTop: scale.top, scaleBottom: scale.bottom, @@ -248,7 +249,7 @@ module.exports = function(Chart) { var meta = me.getMeta(); var area = me.chart.chartArea; - // only consider points that are drawn in case the spanGaps option is ued + // Only consider points that are drawn in case the spanGaps option is used var points = (meta.data || []).filter(function(pt) { return !pt._model.skip; }); var i, ilen, point, model, controlPoints; @@ -256,7 +257,7 @@ module.exports = function(Chart) { return Math.max(Math.min(pt, max), min); } - if (me.chart.options.elements.line.cubicInterpolationMode == 'monotone') { + if (meta.dataset._model.cubicInterpolationMode == 'monotone') { helpers.splineCurveMonotone(points); } else { -- 2.47.3