]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Better property picking. Added a helper function so we don't have to write a complica... 1774/head
authorEvert Timberg <evert.timberg@gmail.com>
Sat, 12 Dec 2015 13:52:06 +0000 (08:52 -0500)
committerEvert Timberg <evert.timberg@gmail.com>
Sat, 12 Dec 2015 13:52:06 +0000 (08:52 -0500)
src/controllers/controller.line.js
src/controllers/controller.radar.js
src/core/core.helpers.js
test/controller.line.tests.js

index 1755ca99efa3f251c2ef6e886597efb15c2f536a..8d0ad0eb18c6bd7e3cc2a798dbf29160402b8f9a 100644 (file)
                                // Model
                                _model: {
                                        // Appearance
-                                       tension: line.custom && line.custom.tension ? line.custom.tension : (this.getDataset().tension || this.chart.options.elements.line.tension),
+                                       tension: line.custom && line.custom.tension ? line.custom.tension : helpers.getValueOrDefault(this.getDataset().tension, this.chart.options.elements.line.tension),
                                        backgroundColor: line.custom && line.custom.backgroundColor ? line.custom.backgroundColor : (this.getDataset().backgroundColor || this.chart.options.elements.line.backgroundColor),
                                        borderWidth: line.custom && line.custom.borderWidth ? line.custom.borderWidth : (this.getDataset().borderWidth || this.chart.options.elements.line.borderWidth),
                                        borderColor: line.custom && line.custom.borderColor ? line.custom.borderColor : (this.getDataset().borderColor || this.chart.options.elements.line.borderColor),
                                        x: xScale.getPixelForValue(this.getDataset().data[index], index, this.index, this.chart.isCombo),
                                        y: reset ? scaleBase : this.calculatePointY(this.getDataset().data[index], index, this.index, this.chart.isCombo),
                                        // Appearance
-                                       tension: point.custom && point.custom.tension ? point.custom.tension : (this.getDataset().tension || this.chart.options.elements.line.tension),
+                                       tension: point.custom && point.custom.tension ? point.custom.tension : helpers.getValueOrDefault(this.getDataset().tension, this.chart.options.elements.line.tension),
                                        radius: point.custom && point.custom.radius ? point.custom.radius : helpers.getValueAtIndexOrDefault(this.getDataset().radius, index, this.chart.options.elements.point.radius),
                                        backgroundColor: this.getPointBackgroundColor(point, index),
                                        borderColor: this.getPointBorderColor(point, index),
index 639c8772269087038cbaab7b33be8b3d602a7230..9bec21e2b12d6425638531f5b17ad7171d64178f 100644 (file)
                                // Model
                                _model: {
                                        // Appearance
-                                       tension: this.getDataset().tension || this.chart.options.elements.line.tension,
+                                       tension: helpers.getValueOrDefault(this.getDataset().tension, this.chart.options.elements.line.tension),
                                        backgroundColor: this.getDataset().backgroundColor || this.chart.options.elements.line.backgroundColor,
                                        borderWidth: this.getDataset().borderWidth || this.chart.options.elements.line.borderWidth,
                                        borderColor: this.getDataset().borderColor || this.chart.options.elements.line.borderColor,
                                        y: reset ? this.chart.scale.yCenter : pointPosition.y,
 
                                        // Appearance
-                                       tension: point.custom && point.custom.tension ? point.custom.tension : this.chart.options.elements.line.tension,
+                                       tension: point.custom && point.custom.tension ? point.custom.tension : helpers.getValueOrDefault(this.getDataset().tension, this.chart.options.elements.line.tension),
                                        radius: point.custom && point.custom.radius ? point.custom.pointRadius : helpers.getValueAtIndexOrDefault(this.getDataset().pointRadius, index, this.chart.options.elements.point.radius),
                                        backgroundColor: point.custom && point.custom.backgroundColor ? point.custom.backgroundColor : helpers.getValueAtIndexOrDefault(this.getDataset().pointBackgroundColor, index, this.chart.options.elements.point.backgroundColor),
                                        borderColor: point.custom && point.custom.borderColor ? point.custom.borderColor : helpers.getValueAtIndexOrDefault(this.getDataset().pointBorderColor, index, this.chart.options.elements.point.borderColor),
index 2fc62ec2fae441db8896191ff28ee1d04217571d..177397a2065b9a23e32c19dcabc3f80f943b2a3f 100644 (file)
 
                        return value;
                },
+               getValueOrDefault = helpers.getValueOrDefault = function(value, defaultValue) {
+                       return value === undefined ? defaultValue : value;
+               },
                indexOf = helpers.indexOf = function(arrayToSearch, item) {
                        if (Array.prototype.indexOf) {
                                return arrayToSearch.indexOf(item);
index a729fe6743ccbae73c42daa67971756870de5af2..f813bb55db358d51ebaf5b3d1149dc38a4b8f132 100644 (file)
@@ -342,7 +342,7 @@ describe('Line controller tests', function() {
                });
 
                // Use dataset level styles for lines & points
-               chart.data.datasets[0].tension = 0.2;
+               chart.data.datasets[0].tension = 0;
                chart.data.datasets[0].backgroundColor = 'rgb(98, 98, 98)';
                chart.data.datasets[0].borderColor = 'rgb(8, 8, 8)';
                chart.data.datasets[0].borderWidth = 0.55;
@@ -370,7 +370,7 @@ describe('Line controller tests', function() {
                        borderJoinStyle: 'miter',
                        borderWidth: 0.55,
                        fill: false,
-                       tension: 0.2,
+                       tension: 0,
 
                        scaleTop: 0,
                        scaleBottom: 200,
@@ -384,7 +384,7 @@ describe('Line controller tests', function() {
                        hitRadius: 3.3,
                        radius: 22,
                        skip: false,
-                       tension: 0.2,
+                       tension: 0,
 
                        // Point
                        x: 81,
@@ -393,8 +393,8 @@ describe('Line controller tests', function() {
                        // Control points
                        controlPointPreviousX: 81,
                        controlPointPreviousY: 62,
-                       controlPointNextX: 91,
-                       controlPointNextY: 52.6,
+                       controlPointNextX: 81,
+                       controlPointNextY: 62,
                });
 
                expect(chart.data.datasets[0].metaData[1]._model).toEqual({
@@ -404,17 +404,17 @@ describe('Line controller tests', function() {
                        hitRadius: 3.3,
                        radius: 22,
                        skip: false,
-                       tension: 0.2,
+                       tension: 0,
 
                        // Point
                        x: 131,
                        y: 15,
 
                        // Control points
-                       controlPointPreviousX: 124.65778768378175,
-                       controlPointPreviousY: 9.097346953222619,
-                       controlPointNextX: 144.85778768378177,
-                       controlPointNextY: 27.897346953222623,
+                       controlPointPreviousX: 131,
+                       controlPointPreviousY: 15,
+                       controlPointNextX: 131,
+                       controlPointNextY: 15,
                });
 
                expect(chart.data.datasets[0].metaData[2]._model).toEqual({
@@ -424,17 +424,17 @@ describe('Line controller tests', function() {
                        hitRadius: 3.3,
                        radius: 22,
                        skip: false,
-                       tension: 0.2,
+                       tension: 0,
 
                        // Point
                        x: 182,
                        y: 156,
 
                        // Control points
-                       controlPointPreviousX: 167.76304506745115,
-                       controlPointPreviousY: 130.76816898092827,
-                       controlPointNextX: 187.96304506745116,
-                       controlPointNextY: 166.56816898092828,
+                       controlPointPreviousX: 182,
+                       controlPointPreviousY: 156,
+                       controlPointNextX: 182,
+                       controlPointNextY: 156,
                });
 
                expect(chart.data.datasets[0].metaData[3]._model).toEqual({
@@ -444,15 +444,15 @@ describe('Line controller tests', function() {
                        hitRadius: 3.3,
                        radius: 22,
                        skip: false,
-                       tension: 0.2,
+                       tension: 0,
 
                        // Point
                        x: 232,
                        y: 194,
 
                        // Control points
-                       controlPointPreviousX: 222,
-                       controlPointPreviousY: 186.4,
+                       controlPointPreviousX: 232,
+                       controlPointPreviousY: 194,
                        controlPointNextX: 232,
                        controlPointNextY: 194,
                });