Skip to content

Commit

Permalink
Addressing review comments:
Browse files Browse the repository at this point in the history
- whitespace as tabs only to align with project lint standards
- replacing 'this' references with a local 'me' variable
- removal of label text to avoid cross-platform font issues in image tests
- added an image test for default alignment of 'start' for vertical legends (left/right)
  • Loading branch information
Dave Kichler committed Mar 18, 2019
1 parent c05a2a6 commit 4081897
Show file tree
Hide file tree
Showing 17 changed files with 165 additions and 150 deletions.
13 changes: 7 additions & 6 deletions src/plugins/plugin.legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 17 additions & 18 deletions test/fixtures/plugin.legend/legend-doughnut-left-center-single.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -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
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -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
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -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
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 17 additions & 18 deletions test/fixtures/plugin.legend/legend-doughnut-top-center-single.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
35 changes: 17 additions & 18 deletions test/fixtures/plugin.legend/legend-doughnut-top-end-mulitiline.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -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
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4081897

Please sign in to comment.