2015-06-12 22:00:48 +02:00
|
|
|
(function() {
|
|
|
|
|
2015-06-13 16:15:21 +02:00
|
|
|
"use strict";
|
2015-06-12 22:00:48 +02:00
|
|
|
|
2015-06-13 16:15:21 +02:00
|
|
|
var root = this,
|
|
|
|
Chart = root.Chart,
|
|
|
|
helpers = Chart.helpers;
|
2015-06-12 22:00:48 +02:00
|
|
|
|
2015-06-13 16:15:21 +02:00
|
|
|
Chart.defaults.global.elements.rectangle = {
|
|
|
|
backgroundColor: Chart.defaults.global.defaultColor,
|
|
|
|
borderWidth: 0,
|
|
|
|
borderColor: Chart.defaults.global.defaultColor,
|
|
|
|
};
|
2015-06-12 22:00:48 +02:00
|
|
|
|
2015-06-15 22:36:02 +02:00
|
|
|
Chart.elements.Rectangle = Chart.Element.extend({
|
2015-06-13 16:15:21 +02:00
|
|
|
draw: function() {
|
2015-06-12 22:00:48 +02:00
|
|
|
|
2015-06-13 16:15:21 +02:00
|
|
|
var ctx = this._chart.ctx;
|
|
|
|
var vm = this._view;
|
2015-06-12 22:00:48 +02:00
|
|
|
|
2015-06-13 16:15:21 +02:00
|
|
|
var halfWidth = vm.width / 2,
|
|
|
|
leftX = vm.x - halfWidth,
|
|
|
|
rightX = vm.x + halfWidth,
|
|
|
|
top = vm.base - (vm.base - vm.y),
|
|
|
|
halfStroke = vm.borderWidth / 2;
|
2015-06-12 22:00:48 +02:00
|
|
|
|
2015-06-13 16:15:21 +02:00
|
|
|
// Canvas doesn't allow us to stroke inside the width so we can
|
|
|
|
// adjust the sizes to fit if we're setting a stroke on the line
|
|
|
|
if (vm.borderWidth) {
|
|
|
|
leftX += halfStroke;
|
|
|
|
rightX -= halfStroke;
|
|
|
|
top += halfStroke;
|
|
|
|
}
|
2015-06-12 22:00:48 +02:00
|
|
|
|
2015-06-13 16:15:21 +02:00
|
|
|
ctx.beginPath();
|
2015-06-12 22:00:48 +02:00
|
|
|
|
2015-06-13 16:15:21 +02:00
|
|
|
ctx.fillStyle = vm.backgroundColor;
|
|
|
|
ctx.strokeStyle = vm.borderColor;
|
|
|
|
ctx.lineWidth = vm.borderWidth;
|
2015-06-12 22:00:48 +02:00
|
|
|
|
2015-06-13 16:15:21 +02:00
|
|
|
// It'd be nice to keep this class totally generic to any rectangle
|
|
|
|
// and simply specify which border to miss out.
|
|
|
|
ctx.moveTo(leftX, vm.base);
|
|
|
|
ctx.lineTo(leftX, top);
|
|
|
|
ctx.lineTo(rightX, top);
|
|
|
|
ctx.lineTo(rightX, vm.base);
|
|
|
|
ctx.fill();
|
|
|
|
if (vm.borderWidth) {
|
|
|
|
ctx.stroke();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
height: function() {
|
|
|
|
var vm = this._view;
|
|
|
|
return vm.base - vm.y;
|
|
|
|
},
|
|
|
|
inRange: function(mouseX, mouseY) {
|
|
|
|
var vm = this._view;
|
2015-08-29 14:53:42 +02:00
|
|
|
var inRange = false;
|
|
|
|
|
|
|
|
if (vm) {
|
|
|
|
if (vm.y < vm.base) {
|
|
|
|
inRange = (mouseX >= vm.x - vm.width / 2 && mouseX <= vm.x + vm.width / 2) && (mouseY >= vm.y && mouseY <= vm.base);
|
|
|
|
} else {
|
|
|
|
inRange = (mouseX >= vm.x - vm.width / 2 && mouseX <= vm.x + vm.width / 2) && (mouseY >= vm.base && mouseY <= vm.y);
|
|
|
|
}
|
2015-09-18 19:31:25 +02:00
|
|
|
}
|
2015-08-29 14:53:42 +02:00
|
|
|
|
|
|
|
return inRange;
|
2015-06-13 16:15:21 +02:00
|
|
|
},
|
2015-06-16 00:18:56 +02:00
|
|
|
inLabelRange: function(mouseX) {
|
2015-06-13 16:15:21 +02:00
|
|
|
var vm = this._view;
|
2015-08-29 14:53:42 +02:00
|
|
|
|
|
|
|
if (vm) {
|
|
|
|
return (mouseX >= vm.x - vm.width / 2 && mouseX <= vm.x + vm.width / 2);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2015-06-13 16:15:21 +02:00
|
|
|
},
|
|
|
|
tooltipPosition: function() {
|
|
|
|
var vm = this._view;
|
2015-12-21 21:52:19 +01:00
|
|
|
return {
|
|
|
|
x: vm.x,
|
|
|
|
y: vm.y
|
|
|
|
};
|
2015-06-13 16:15:21 +02:00
|
|
|
},
|
|
|
|
});
|
2015-06-12 22:00:48 +02:00
|
|
|
|
2015-06-15 22:36:02 +02:00
|
|
|
|
|
|
|
|
2015-06-12 22:00:48 +02:00
|
|
|
}).call(this);
|