Line Chart label hoverMode & tooltips

This commit is contained in:
Tanner Linsley 2015-05-15 17:03:51 -06:00
parent fb580a6e48
commit e58421a08a
3 changed files with 11 additions and 5 deletions

View File

@ -47,7 +47,8 @@
window.onload = function(){
var ctx = document.getElementById("canvas").getContext("2d");
window.myLine = new Chart(ctx).Line(lineChartData, {
responsive: true
responsive: true,
hoverMode: 'label'
});
};

View File

@ -1009,7 +1009,7 @@
for (var datasetIndex = 0; datasetIndex < this.data.datasets.length; datasetIndex++) {
for (elementIndex = 0; elementIndex < this.data.datasets[datasetIndex].metaData.length; elementIndex++) {
if (this.data.datasets[datasetIndex].metaData[elementIndex].inRange(eventPosition.x,eventPosition.y)){
if (this.data.datasets[datasetIndex].metaData[elementIndex].inGroupRange(eventPosition.x,eventPosition.y)){
helpers.each(this.data.datasets, datasetIterator);
}
}
@ -1190,10 +1190,14 @@
Chart.Point = Chart.Element.extend({
inRange: function(chartX,chartY){
inRange: function(mouseX,mouseY){
var vm = this._vm;
var hoverRange = vm.hoverRadius + vm.radius;
return ((Math.pow(chartX - vm.x, 2)+Math.pow(chartY - vm.y, 2)) < Math.pow(hoverRange,2));
return ((Math.pow(mouseX - vm.x, 2)+Math.pow(mouseY - vm.y, 2)) < Math.pow(hoverRange,2));
},
inGroupRange: function(mouseX){
var vm = this._vm;
return (Math.pow(mouseX-vm.x, 2) < Math.pow(vm.radius + this.hoverRadius,2));
},
tooltipPosition : function(){
var vm = this._vm;

View File

@ -225,6 +225,8 @@
// Hover animations
this.tooltip.pivot();
if(!this.animating){
var changed;
@ -239,7 +241,6 @@
(this.lastActive.length && !this.active.length)||
(this.lastActive.length && this.active.length && changed)){
this.tooltip.pivot();
this.stop();
this.render(this.options.hoverAnimationDuration);
}