diff --git a/src/plugins/plugin.legend.js b/src/plugins/plugin.legend.js index 3503dc0aed3..8c0e38be31b 100644 --- a/src/plugins/plugin.legend.js +++ b/src/plugins/plugin.legend.js @@ -102,22 +102,23 @@ function getBoxWidth(labelOpts, fontSize) { var Legend = Element.extend({ initialize: function(config) { - helpers.extend(this, config); + var me = this; + helpers.extend(me, config); - if (this.options && !this.options.align) { + if (me.options && !me.align) { // to maintain backward compatibility with existing default - this.options.align = this.isHorizontal() ? 'center' : 'start'; + me.options.align = me.isHorizontal() ? 'center' : 'start'; } // Contains hit boxes for each dataset (in dataset order) - this.legendHitBoxes = []; + me.legendHitBoxes = []; /** * @private */ - this._hoveredItem = null; + me._hoveredItem = null; // Are we in doughnut mode which has a different data type - this.doughnutMode = false; + me.doughnutMode = false; }, // These methods are ordered by lifecycle. Utilities then follow. diff --git a/test/fixtures/plugin.legend/legend-doughnut-left-center-mulitiline.json b/test/fixtures/plugin.legend/legend-doughnut-left-center-mulitiline.json index c19a109329b..51359b29470 100644 --- a/test/fixtures/plugin.legend/legend-doughnut-left-center-mulitiline.json +++ b/test/fixtures/plugin.legend/legend-doughnut-left-center-mulitiline.json @@ -1,24 +1,23 @@ { - "config": { - "type": "doughnut", - "data": { - "labels": ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16"], - "datasets": [{ - "data": [10, 20, 30, 40, 50, 60, 70, 10, 20, 30, 40, 50, 60, 70, 10, 20, 30] - }] - }, - "options": { - "responsive": false, + "config": { + "type": "doughnut", + "data": { + "labels": ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""], + "datasets": [{ + "data": [10, 20, 30, 40, 50, 60, 70, 10, 20, 30, 40, 50, 60, 70, 10, 20, 30] + }] + }, + "options": { "legend": { "position": "left", "align": "center" } - } - }, - "options": { - "canvas": { - "height": 256, - "width": 512 - } - } + } + }, + "options": { + "canvas": { + "height": 256, + "width": 512 + } + } } diff --git a/test/fixtures/plugin.legend/legend-doughnut-left-center-mulitiline.png b/test/fixtures/plugin.legend/legend-doughnut-left-center-mulitiline.png index b9aefa86c9a..23630db0df2 100644 Binary files a/test/fixtures/plugin.legend/legend-doughnut-left-center-mulitiline.png and b/test/fixtures/plugin.legend/legend-doughnut-left-center-mulitiline.png differ diff --git a/test/fixtures/plugin.legend/legend-doughnut-left-center-single.json b/test/fixtures/plugin.legend/legend-doughnut-left-center-single.json index 88d8cac1359..808a6c125b9 100644 --- a/test/fixtures/plugin.legend/legend-doughnut-left-center-single.json +++ b/test/fixtures/plugin.legend/legend-doughnut-left-center-single.json @@ -1,24 +1,23 @@ { - "config": { - "type": "doughnut", - "data": { - "labels": ["0"], - "datasets": [{ - "data": [10] - }] - }, - "options": { - "responsive": false, + "config": { + "type": "doughnut", + "data": { + "labels": [""], + "datasets": [{ + "data": [10] + }] + }, + "options": { "legend": { "position": "left", "align": "center" } - } - }, - "options": { - "canvas": { - "height": 256, - "width": 512 - } - } + } + }, + "options": { + "canvas": { + "height": 256, + "width": 512 + } + } } diff --git a/test/fixtures/plugin.legend/legend-doughnut-left-default-start.json b/test/fixtures/plugin.legend/legend-doughnut-left-default-start.json new file mode 100644 index 00000000000..c8b2c5858ed --- /dev/null +++ b/test/fixtures/plugin.legend/legend-doughnut-left-default-start.json @@ -0,0 +1,22 @@ +{ + "config": { + "type": "doughnut", + "data": { + "labels": ["", "", "", "", "", ""], + "datasets": [{ + "data": [10, 20, 30, 40, 50] + }] + }, + "options": { + "legend": { + "position": "left" + } + } + }, + "options": { + "canvas": { + "height": 256, + "width": 512 + } + } +} diff --git a/test/fixtures/plugin.legend/legend-doughnut-left-default-start.png b/test/fixtures/plugin.legend/legend-doughnut-left-default-start.png new file mode 100644 index 00000000000..ac89adbe89e Binary files /dev/null and b/test/fixtures/plugin.legend/legend-doughnut-left-default-start.png differ diff --git a/test/fixtures/plugin.legend/legend-doughnut-left-end-mulitiline.json b/test/fixtures/plugin.legend/legend-doughnut-left-end-mulitiline.json index 4370fcdd288..db96db93ee0 100644 --- a/test/fixtures/plugin.legend/legend-doughnut-left-end-mulitiline.json +++ b/test/fixtures/plugin.legend/legend-doughnut-left-end-mulitiline.json @@ -1,24 +1,23 @@ { - "config": { - "type": "doughnut", - "data": { - "labels": ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16"], - "datasets": [{ - "data": [10, 20, 30, 40, 50, 60, 70, 10, 20, 30, 40, 50, 60, 70, 10, 20, 30] - }] - }, - "options": { - "responsive": false, + "config": { + "type": "doughnut", + "data": { + "labels": ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""], + "datasets": [{ + "data": [10, 20, 30, 40, 50, 60, 70, 10, 20, 30, 40, 50, 60, 70, 10, 20, 30] + }] + }, + "options": { "legend": { "position": "left", "align": "end" } - } - }, - "options": { - "canvas": { - "height": 256, - "width": 512 - } - } + } + }, + "options": { + "canvas": { + "height": 256, + "width": 512 + } + } } diff --git a/test/fixtures/plugin.legend/legend-doughnut-left-end-mulitiline.png b/test/fixtures/plugin.legend/legend-doughnut-left-end-mulitiline.png index 308ebe94da4..e8e66c30e05 100644 Binary files a/test/fixtures/plugin.legend/legend-doughnut-left-end-mulitiline.png and b/test/fixtures/plugin.legend/legend-doughnut-left-end-mulitiline.png differ diff --git a/test/fixtures/plugin.legend/legend-doughnut-left-start-mulitiline.json b/test/fixtures/plugin.legend/legend-doughnut-left-start-mulitiline.json index 86cd0eca1b9..2ce4e1a9b28 100644 --- a/test/fixtures/plugin.legend/legend-doughnut-left-start-mulitiline.json +++ b/test/fixtures/plugin.legend/legend-doughnut-left-start-mulitiline.json @@ -1,24 +1,23 @@ { - "config": { - "type": "doughnut", - "data": { - "labels": ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16"], - "datasets": [{ - "data": [10, 20, 30, 40, 50, 60, 70, 10, 20, 30, 40, 50, 60, 70, 10, 20, 30] - }] - }, - "options": { - "responsive": false, + "config": { + "type": "doughnut", + "data": { + "labels": ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""], + "datasets": [{ + "data": [10, 20, 30, 40, 50, 60, 70, 10, 20, 30, 40, 50, 60, 70, 10, 20, 30] + }] + }, + "options": { "legend": { "position": "left", "align": "start" } - } - }, - "options": { - "canvas": { - "height": 256, - "width": 512 - } - } + } + }, + "options": { + "canvas": { + "height": 256, + "width": 512 + } + } } diff --git a/test/fixtures/plugin.legend/legend-doughnut-left-start-mulitiline.png b/test/fixtures/plugin.legend/legend-doughnut-left-start-mulitiline.png index 362cd71f4d1..a5afe65f124 100644 Binary files a/test/fixtures/plugin.legend/legend-doughnut-left-start-mulitiline.png and b/test/fixtures/plugin.legend/legend-doughnut-left-start-mulitiline.png differ diff --git a/test/fixtures/plugin.legend/legend-doughnut-top-center-mulitiline.json b/test/fixtures/plugin.legend/legend-doughnut-top-center-mulitiline.json index 4b4e2e866f2..a2a3467e11d 100644 --- a/test/fixtures/plugin.legend/legend-doughnut-top-center-mulitiline.json +++ b/test/fixtures/plugin.legend/legend-doughnut-top-center-mulitiline.json @@ -1,24 +1,23 @@ { - "config": { - "type": "doughnut", - "data": { - "labels": ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16"], - "datasets": [{ - "data": [10, 20, 30, 40, 50, 60, 70, 10, 20, 30, 40, 50, 60, 70, 10, 20, 30] - }] - }, - "options": { - "responsive": false, + "config": { + "type": "doughnut", + "data": { + "labels": ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""], + "datasets": [{ + "data": [10, 20, 30, 40, 50, 60, 70, 10, 20, 30, 40, 50, 60, 70, 10, 20, 30, 20, 10] + }] + }, + "options": { "legend": { "position": "top", "align": "center" } - } - }, - "options": { - "canvas": { - "height": 256, - "width": 512 - } - } + } + }, + "options": { + "canvas": { + "height": 256, + "width": 512 + } + } } diff --git a/test/fixtures/plugin.legend/legend-doughnut-top-center-mulitiline.png b/test/fixtures/plugin.legend/legend-doughnut-top-center-mulitiline.png index 7449703add8..510e4c5307a 100644 Binary files a/test/fixtures/plugin.legend/legend-doughnut-top-center-mulitiline.png and b/test/fixtures/plugin.legend/legend-doughnut-top-center-mulitiline.png differ diff --git a/test/fixtures/plugin.legend/legend-doughnut-top-center-single.json b/test/fixtures/plugin.legend/legend-doughnut-top-center-single.json index d8542512ca7..56c0e486712 100644 --- a/test/fixtures/plugin.legend/legend-doughnut-top-center-single.json +++ b/test/fixtures/plugin.legend/legend-doughnut-top-center-single.json @@ -1,24 +1,23 @@ { - "config": { - "type": "doughnut", - "data": { - "labels": ["0"], - "datasets": [{ - "data": [10] - }] - }, - "options": { - "responsive": false, + "config": { + "type": "doughnut", + "data": { + "labels": [""], + "datasets": [{ + "data": [10] + }] + }, + "options": { "legend": { "position": "top", "align": "center" } - } - }, - "options": { - "canvas": { - "height": 256, - "width": 512 - } - } + } + }, + "options": { + "canvas": { + "height": 256, + "width": 512 + } + } } diff --git a/test/fixtures/plugin.legend/legend-doughnut-top-end-mulitiline.json b/test/fixtures/plugin.legend/legend-doughnut-top-end-mulitiline.json index b349210a4c0..ff9b02a34b4 100644 --- a/test/fixtures/plugin.legend/legend-doughnut-top-end-mulitiline.json +++ b/test/fixtures/plugin.legend/legend-doughnut-top-end-mulitiline.json @@ -1,24 +1,23 @@ { - "config": { - "type": "doughnut", - "data": { - "labels": ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16"], - "datasets": [{ - "data": [10, 20, 30, 40, 50, 60, 70, 10, 20, 30, 40, 50, 60, 70, 10, 20, 30] - }] - }, - "options": { - "responsive": false, + "config": { + "type": "doughnut", + "data": { + "labels": ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""], + "datasets": [{ + "data": [10, 20, 30, 40, 50, 60, 70, 10, 20, 30, 40, 50, 60, 70, 10] + }] + }, + "options": { "legend": { "position": "top", "align": "end" } - } - }, - "options": { - "canvas": { - "height": 256, - "width": 512 - } - } + } + }, + "options": { + "canvas": { + "height": 256, + "width": 512 + } + } } diff --git a/test/fixtures/plugin.legend/legend-doughnut-top-end-mulitiline.png b/test/fixtures/plugin.legend/legend-doughnut-top-end-mulitiline.png index 1764487e64f..db064e5d204 100644 Binary files a/test/fixtures/plugin.legend/legend-doughnut-top-end-mulitiline.png and b/test/fixtures/plugin.legend/legend-doughnut-top-end-mulitiline.png differ diff --git a/test/fixtures/plugin.legend/legend-doughnut-top-start-mulitiline.json b/test/fixtures/plugin.legend/legend-doughnut-top-start-mulitiline.json index 7139e180c3d..eaebd9a95f8 100644 --- a/test/fixtures/plugin.legend/legend-doughnut-top-start-mulitiline.json +++ b/test/fixtures/plugin.legend/legend-doughnut-top-start-mulitiline.json @@ -1,24 +1,23 @@ { - "config": { - "type": "doughnut", - "data": { - "labels": ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16"], - "datasets": [{ - "data": [10, 20, 30, 40, 50, 60, 70, 10, 20, 30, 40, 50, 60, 70, 10, 20, 30] - }] - }, - "options": { - "responsive": false, + "config": { + "type": "doughnut", + "data": { + "labels": ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""], + "datasets": [{ + "data": [10, 20, 30, 40, 50, 60, 70, 10, 20, 30, 40, 50, 60, 70, 10] + }] + }, + "options": { "legend": { "position": "top", "align": "start" } - } - }, - "options": { - "canvas": { - "height": 256, - "width": 512 - } - } + } + }, + "options": { + "canvas": { + "height": 256, + "width": 512 + } + } } diff --git a/test/fixtures/plugin.legend/legend-doughnut-top-start-mulitiline.png b/test/fixtures/plugin.legend/legend-doughnut-top-start-mulitiline.png index 8dc26c2ec7f..0254988e62f 100644 Binary files a/test/fixtures/plugin.legend/legend-doughnut-top-start-mulitiline.png and b/test/fixtures/plugin.legend/legend-doughnut-top-start-mulitiline.png differ