Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/core.helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ module.exports = function(Chart) {
};
helpers.callback = function(fn, args, thisArg) {
if (fn && typeof fn.call === 'function') {
fn.apply(thisArg, args);
return fn.apply(thisArg, args);
}
};
helpers.getHoverColor = function(colorValue) {
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/plugin.legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ module.exports = function(Chart) {
beforeBuildLabels: noop,
buildLabels: function() {
var me = this;
var labelOpts = me.options.labels;
var legendItems = labelOpts.generateLabels.call(me, me.chart);
var labelOpts = me.options.labels || {};
var legendItems = helpers.callback(labelOpts.generateLabels, [me.chart], me) || [];

if (labelOpts.filter) {
legendItems = legendItems.filter(function(item) {
Expand Down
25 changes: 25 additions & 0 deletions test/specs/plugin.legend.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,31 @@ describe('Legend block tests', function() {
}]);
});

it('should not throw when the label options are missing', function() {
var makeChart = function() {
window.acquireChart({
type: 'bar',
data: {
datasets: [{
label: 'dataset1',
backgroundColor: '#f31',
borderCapStyle: 'butt',
borderDash: [2, 2],
borderDashOffset: 5.5,
data: []
}],
labels: []
},
options: {
legend: {
labels: false,
}
}
});
};
expect(makeChart).not.toThrow();
});

it('should draw correctly', function() {
var chart = window.acquireChart({
type: 'bar',
Expand Down