Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align title, body and footer inside tooltip #5925

Merged
merged 9 commits into from Jan 8, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 22 additions & 1 deletion 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}
kurkle marked this conversation as resolved.
Show resolved Hide resolved
* @param {object} vm - rectangle text should be aligned in (x, y, width, height, xPadding)
* @param {string} align - left, center, right
kurkle marked this conversation as resolved.
Show resolved Hide resolved
*/
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