Skip to content

Commit bf81391

Browse files
committed
aling title,body and footer inside tooltip
1 parent c8ce3d2 commit bf81391

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/core/core.tooltip.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,25 @@ function getBackgroundPoint(vm, size, alignment, chart) {
463463
};
464464
}
465465

466+
/**
467+
* Align pt.x to match given aling (and using xPadding)
468+
* @param {object} pt - point to aling {x}
469+
* @param {object} vm - rectangle text should be aligned in (x, y, width, height, xPadding)
470+
* @param {string} align - left, center, right
471+
*/
472+
function xAlignText(pt, vm, align) {
473+
switch (align) {
474+
case 'center':
475+
pt.x = vm.x + vm.width / 2;
476+
break;
477+
case 'right':
478+
pt.x = vm.x + vm.width - vm.xPadding;
479+
break;
480+
default:
481+
pt.x = vm.x + vm.xPadding;
482+
}
483+
}
484+
466485
/**
467486
* Helper to build before and after body lines
468487
*/
@@ -905,16 +924,17 @@ var exports = Element.extend({
905924
this.drawBackground(pt, vm, ctx, tooltipSize);
906925

907926
// Draw Title, Body, and Footer
908-
pt.x += vm.xPadding;
909927
pt.y += vm.yPadding;
910-
911928
// Titles
929+
xAlignText(pt, vm, vm._titleAlign);
912930
this.drawTitle(pt, vm, ctx);
913931

914932
// Body
933+
xAlignText(pt, vm, vm._bodyAlign);
915934
this.drawBody(pt, vm, ctx);
916935

917936
// Footer
937+
xAlignText(pt, vm, vm._footerAlign);
918938
this.drawFooter(pt, vm, ctx);
919939

920940
ctx.restore();

0 commit comments

Comments
 (0)