Skip to content

Commit

Permalink
Bump version to 0.5.5
Browse files Browse the repository at this point in the history
  • Loading branch information
compwright committed May 20, 2017
1 parent 5d67701 commit c5c18b2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 20 deletions.
50 changes: 33 additions & 17 deletions chartjs-plugin-annotation.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* chartjs-plugin-annotation.js
* http://chartjs.org/
* Version: 0.5.4
* Version: 0.5.5
*
* Copyright 2016 Evert Timberg
* Released under the MIT license
Expand All @@ -25,6 +25,20 @@ module.exports = function(Chart) {
});
}

function draw(drawTime) {
return function(chartInstance, easingDecimal) {
var defaultDrawTime = chartInstance.annotation.options.drawTime;

helpers.elements(chartInstance)
.filter(function(element) {
return drawTime === (element.options.drawTime || defaultDrawTime);
})
.forEach(function(element) {
element.transition(easingDecimal).draw();
});
};
}

return {
beforeInit: function(chartInstance) {
var chartOptions = chartInstance.options;
Expand All @@ -38,12 +52,6 @@ module.exports = function(Chart) {
supported: false
};

ns[ns.options.drawTime] = function(easingDecimal) {
helpers.elements(chartInstance).forEach(function(element) {
element.transition(easingDecimal).draw();
});
};

// Add the annotation scale adjuster to each scale's afterDataLimits hook
chartInstance.ensureScalesHaveIDs();
if (chartOptions.scales) {
Expand Down Expand Up @@ -103,15 +111,9 @@ module.exports = function(Chart) {
element.configure();
});
},
beforeDatasetsDraw: function(chartInstance, easingDecimal) {
(chartInstance.annotation.beforeDatasetsDraw || helpers.noop)(easingDecimal);
},
afterDatasetsDraw: function(chartInstance, easingDecimal) {
(chartInstance.annotation.afterDatasetsDraw || helpers.noop)(easingDecimal);
},
afterDraw: function(chartInstance, easingDecimal) {
(chartInstance.annotation.afterDraw || helpers.noop)(easingDecimal);
},
beforeDatasetsDraw: draw('beforeDatasetsDraw'),
afterDatasetsDraw: draw('afterDatasetsDraw'),
afterDraw: draw('afterDraw'),
afterInit: function(chartInstance) {
// Detect and intercept events that happen on an annotation element
var watchFor = chartInstance.annotation.options.events;
Expand Down Expand Up @@ -274,6 +276,7 @@ module.exports = function(Chart) {
function noop() {}

function elements(chartInstance) {
// Turn the elements object into an array of elements
var elements = chartInstance.annotation.elements;
return Object.keys(elements).map(function(id) {
return elements[id];
Expand Down Expand Up @@ -740,7 +743,20 @@ module.exports = function(Chart) {
},
inRange: function(mouseX, mouseY) {
var model = this._model;
return (model.line && model.line.intersects(mouseX, mouseY, this.getHeight()));

return (
// On the line
model.line &&
model.line.intersects(mouseX, mouseY, this.getHeight())
) || (
// On the label
model.labelEnabled &&
model.labelContent &&
mouseX >= model.labelX &&
mouseX <= model.labelX + model.labelWidth &&
mouseY >= model.labelY &&
mouseY <= model.labelY + model.labelHeight
);
},
getCenterPoint: function() {
return {
Expand Down
Loading

0 comments on commit c5c18b2

Please sign in to comment.