Skip to content

Commit

Permalink
aling title,body and footer inside tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Dec 19, 2018
1 parent c8ce3d2 commit bf81391
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/core/core.tooltip.js
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,17 @@ 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

0 comments on commit bf81391

Please sign in to comment.