Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/core/core.tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,25 @@ function getBackgroundPoint(vm, size, alignment, chart) {
};
}

/**
* Align pt.x to match given aling (and using xPadding)
* @param {object} pt - point to aling {x}
* @param {object} vm - rectangle text should be aligned in (x, y, width, height, xPadding)
* @param {string} align - left, center, right
*/
function xAlignText(pt, vm, align) {
switch (align) {
case 'center':
pt.x = vm.x + vm.width / 2;
break;
case 'right':
pt.x = vm.x + vm.width - vm.xPadding;
break;
default:
pt.x = vm.x + vm.xPadding;
}
}

/**
* Helper to build before and after body lines
*/
Expand Down Expand Up @@ -905,16 +924,18 @@ var exports = Element.extend({
this.drawBackground(pt, vm, ctx, tooltipSize);

// Draw Title, Body, and Footer
pt.x += vm.xPadding;
pt.y += vm.yPadding;

// Titles
xAlignText(pt, vm, vm._titleAlign);
this.drawTitle(pt, vm, ctx);

// Body
xAlignText(pt, vm, vm._bodyAlign);
this.drawBody(pt, vm, ctx);

// Footer
xAlignText(pt, vm, vm._footerAlign);
this.drawFooter(pt, vm, ctx);

ctx.restore();
Expand Down