mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-06 20:29:12 +02:00
Line Chart label hoverMode & tooltips
This commit is contained in:
parent
fb580a6e48
commit
e58421a08a
@ -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'
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user