Skip to content

Commit

Permalink
Set and unset colors on events with Chart.js 2.7.2 or earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
nagix committed Jan 19, 2019
1 parent 19d93ba commit 2c8103b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/plugins/plugin.colorschemes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import colorschemes from '../colorschemes/index';

var helpers = Chart.helpers;

// Element models are always reset when hovering in Chart.js 2.7.2 or earlier
var hoverReset = Chart.DatasetController.prototype.removeHoverStyle.length === 2;

Chart.defaults.global.plugins.colorschemes = {
scheme: 'brewer.Paired12',
fillAlpha: 0.5
Expand Down Expand Up @@ -93,5 +96,18 @@ export default {
delete dataset.colorschemes;
}
});
},

beforeEvent: function(chart, event, options) {
if (hoverReset) {
this.beforeUpdate(chart, options);
}
return true;
},

afterEvent: function(chart) {
if (hoverReset) {
this.afterUpdate(chart);
}
}
};

1 comment on commit 2c8103b

@bestrong89
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Please sign in to comment.