const {caretSize, caretPadding, cornerRadius} = options;
const {xAlign, yAlign} = alignment;
const paddingAndSize = caretSize + caretPadding;
- const radiusAndPadding = cornerRadius + caretPadding;
+ const {topLeft, topRight, bottomLeft, bottomRight} = toTRBLCorners(cornerRadius);
let x = alignX(size, xAlign);
const y = alignY(size, yAlign, paddingAndSize);
x -= paddingAndSize;
}
} else if (xAlign === 'left') {
- x -= radiusAndPadding;
+ x -= Math.max(topLeft, bottomLeft) + caretPadding;
} else if (xAlign === 'right') {
- x += radiusAndPadding;
+ x += Math.max(topRight, bottomRight) + caretPadding;
}
return {
getCaretPosition(tooltipPoint, size, options) {
const {xAlign, yAlign} = this;
- const {cornerRadius, caretSize} = options;
+ const {caretSize, cornerRadius} = options;
+ const {topLeft, topRight, bottomLeft, bottomRight} = toTRBLCorners(cornerRadius);
const {x: ptX, y: ptY} = tooltipPoint;
const {width, height} = size;
let x1, x2, x3, y1, y2, y3;
x3 = x1;
} else {
if (xAlign === 'left') {
- x2 = ptX + cornerRadius + (caretSize);
+ x2 = ptX + Math.max(topLeft, bottomLeft) + (caretSize);
} else if (xAlign === 'right') {
- x2 = ptX + width - cornerRadius - caretSize;
+ x2 = ptX + width - Math.max(topRight, bottomRight) - caretSize;
} else {
x2 = this.caretX;
}
const {xAlign, yAlign} = this;
const {x, y} = pt;
const {width, height} = tooltipSize;
- const radius = options.cornerRadius;
+ const {topLeft, topRight, bottomLeft, bottomRight} = toTRBLCorners(options.cornerRadius);
ctx.fillStyle = options.backgroundColor;
ctx.strokeStyle = options.borderColor;
ctx.lineWidth = options.borderWidth;
ctx.beginPath();
- ctx.moveTo(x + radius, y);
+ ctx.moveTo(x + topLeft, y);
if (yAlign === 'top') {
this.drawCaret(pt, ctx, tooltipSize, options);
}
- ctx.lineTo(x + width - radius, y);
- ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
+ ctx.lineTo(x + width - topRight, y);
+ ctx.quadraticCurveTo(x + width, y, x + width, y + topRight);
if (yAlign === 'center' && xAlign === 'right') {
this.drawCaret(pt, ctx, tooltipSize, options);
}
- ctx.lineTo(x + width, y + height - radius);
- ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
+ ctx.lineTo(x + width, y + height - bottomRight);
+ ctx.quadraticCurveTo(x + width, y + height, x + width - bottomRight, y + height);
if (yAlign === 'bottom') {
this.drawCaret(pt, ctx, tooltipSize, options);
}
- ctx.lineTo(x + radius, y + height);
- ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
+ ctx.lineTo(x + bottomLeft, y + height);
+ ctx.quadraticCurveTo(x, y + height, x, y + height - bottomLeft);
if (yAlign === 'center' && xAlign === 'left') {
this.drawCaret(pt, ctx, tooltipSize, options);
}
- ctx.lineTo(x, y + radius);
- ctx.quadraticCurveTo(x, y, x + radius, y);
+ ctx.lineTo(x, y + topLeft);
+ ctx.quadraticCurveTo(x, y, x + topLeft, y);
ctx.closePath();
ctx.fill();
--- /dev/null
+const data = [];
+for (let x = 0; x < 3; x++) {
+ for (let y = 0; y < 3; y++) {
+ data.push({x, y});
+ }
+}
+
+module.exports = {
+ config: {
+ type: 'scatter',
+ data: {
+ datasets: [{
+ data,
+ backgroundColor: 'red',
+ radius: 1,
+ hoverRadius: 0
+ }],
+ },
+ options: {
+ scales: {
+ x: {display: false},
+ y: {display: false}
+ },
+ plugins: {
+ legend: false,
+ title: false,
+ filler: false,
+ tooltip: {
+ mode: 'point',
+ intersect: true,
+ // spriteText: use white background to hide any gaps between fonts
+ backgroundColor: 'white',
+ borderColor: 'black',
+ borderWidth: 1,
+ callbacks: {
+ beforeLabel: () => 'before label',
+ label: () => 'label',
+ afterLabel: () => 'after1\nafter2\nafter3\nafter4\nafter5'
+ },
+ cornerRadius: {
+ topLeft: 10,
+ topRight: 20,
+ bottomRight: 5,
+ bottomLeft: 0,
+ }
+ },
+ },
+ },
+ plugins: [{
+ afterDraw: function(chart) {
+ const canvas = chart.canvas;
+ const rect = canvas.getBoundingClientRect();
+ const meta = chart.getDatasetMeta(0);
+ let point, event;
+
+ for (let i = 0; i < data.length; i++) {
+ point = meta.data[i];
+ event = {
+ type: 'mousemove',
+ target: canvas,
+ clientX: rect.left + point.x,
+ clientY: rect.top + point.y
+ };
+ chart._handleEvent(event);
+ chart.tooltip.handleEvent(event);
+ chart.tooltip.draw(chart.ctx);
+ }
+ }
+ }]
+ },
+ options: {
+ spriteText: true,
+ canvas: {
+ height: 400,
+ width: 500
+ }
+ }
+};