mirror of
https://github.com/chartjs/Chart.js.git
synced 2026-03-06 00:14:03 +01:00
58 lines
1.4 KiB
JavaScript
58 lines
1.4 KiB
JavaScript
'use strict';
|
|
|
|
module.exports = function(Chart) {
|
|
|
|
var helpers = Chart.helpers,
|
|
globalOpts = Chart.defaults.global,
|
|
defaultColor = globalOpts.defaultColor;
|
|
|
|
globalOpts.elements.point = {
|
|
radius: 3,
|
|
pointStyle: 'circle',
|
|
backgroundColor: defaultColor,
|
|
borderWidth: 1,
|
|
borderColor: defaultColor,
|
|
// Hover
|
|
hitRadius: 1,
|
|
hoverRadius: 4,
|
|
hoverBorderWidth: 1
|
|
};
|
|
|
|
Chart.elements.Point = Chart.Element.extend({
|
|
inRange: function(mouseX, mouseY) {
|
|
var vm = this._view;
|
|
return vm ? ((Math.pow(mouseX - vm.x, 2) + Math.pow(mouseY - vm.y, 2)) < Math.pow(vm.hitRadius + vm.radius, 2)) : false;
|
|
},
|
|
inLabelRange: function(mouseX) {
|
|
var vm = this._view;
|
|
return vm ? (Math.pow(mouseX - vm.x, 2) < Math.pow(vm.radius + vm.hitRadius, 2)) : false;
|
|
},
|
|
tooltipPosition: function() {
|
|
var vm = this._view;
|
|
return {
|
|
x: vm.x,
|
|
y: vm.y,
|
|
padding: vm.radius + vm.borderWidth
|
|
};
|
|
},
|
|
draw: function() {
|
|
var vm = this._view;
|
|
var ctx = this._chart.ctx;
|
|
var pointStyle = vm.pointStyle;
|
|
var radius = vm.radius;
|
|
var x = vm.x;
|
|
var y = vm.y;
|
|
|
|
if (vm.skip) {
|
|
return;
|
|
}
|
|
|
|
ctx.strokeStyle = vm.borderColor || defaultColor;
|
|
ctx.lineWidth = helpers.getValueOrDefault(vm.borderWidth, globalOpts.elements.point.borderWidth);
|
|
ctx.fillStyle = vm.backgroundColor || defaultColor;
|
|
|
|
Chart.canvasHelpers.drawPoint(ctx, pointStyle, radius, x, y);
|
|
}
|
|
});
|
|
};
|