import Animations from '../core/core.animations';
import Element from '../core/core.element';
import {each, noop, isNullOrUndef, isArray, _elementsEqual} from '../helpers/helpers.core';
-import {toPadding} from '../helpers/helpers.options';
+import {toFont, toPadding} from '../helpers/helpers.options';
import {getRtlAdapter, overrideTextDirection, restoreTextDirection} from '../helpers/helpers.rtl';
import {distanceBetweenPoints} from '../helpers/helpers.math';
-import {drawPoint, toFontString} from '../helpers';
+import {drawPoint} from '../helpers';
/**
* @typedef { import("../platform/platform.base").ChartEvent } ChartEvent
function getTooltipSize(tooltip, options) {
const ctx = tooltip._chart.ctx;
const {body, footer, title} = tooltip;
- const {bodyFont, footerFont, titleFont, boxWidth, boxHeight} = options;
+ const {boxWidth, boxHeight} = options;
+ const bodyFont = toFont(options.bodyFont);
+ const titleFont = toFont(options.titleFont);
+ const footerFont = toFont(options.footerFont);
const titleLineCount = title.length;
const footerLineCount = footer.length;
const bodyLineItemCount = body.length;
combinedBodyLength += tooltip.beforeBody.length + tooltip.afterBody.length;
if (titleLineCount) {
- height += titleLineCount * titleFont.size
+ height += titleLineCount * titleFont.lineHeight
+ (titleLineCount - 1) * options.titleSpacing
+ options.titleMarginBottom;
}
if (combinedBodyLength) {
// Body lines may include some extra height depending on boxHeight
- const bodyLineHeight = options.displayColors ? Math.max(boxHeight, bodyFont.size) : bodyFont.size;
+ const bodyLineHeight = options.displayColors ? Math.max(boxHeight, bodyFont.lineHeight) : bodyFont.lineHeight;
height += bodyLineItemCount * bodyLineHeight
- + (combinedBodyLength - bodyLineItemCount) * bodyFont.size
+ + (combinedBodyLength - bodyLineItemCount) * bodyFont.lineHeight
+ (combinedBodyLength - 1) * options.bodySpacing;
}
if (footerLineCount) {
height += options.footerMarginTop
- + footerLineCount * footerFont.size
+ + footerLineCount * footerFont.lineHeight
+ (footerLineCount - 1) * options.footerSpacing;
}
ctx.save();
- ctx.font = toFontString(titleFont);
+ ctx.font = titleFont.string;
each(tooltip.title, maxLineWidth);
// Body width
- ctx.font = toFontString(bodyFont);
+ ctx.font = bodyFont.string;
each(tooltip.beforeBody.concat(tooltip.afterBody), maxLineWidth);
// Body lines may include some extra width due to the color box
widthPadding = 0;
// Footer width
- ctx.font = toFontString(footerFont);
+ ctx.font = footerFont.string;
each(tooltip.footer, maxLineWidth);
ctx.restore();
ctx.textAlign = rtlHelper.textAlign(options.titleAlign);
ctx.textBaseline = 'middle';
- titleFont = options.titleFont;
+ titleFont = toFont(options.titleFont);
titleSpacing = options.titleSpacing;
ctx.fillStyle = options.titleColor;
- ctx.font = toFontString(titleFont);
+ ctx.font = titleFont.string;
for (i = 0; i < length; ++i) {
- ctx.fillText(title[i], rtlHelper.x(pt.x), pt.y + titleFont.size / 2);
- pt.y += titleFont.size + titleSpacing; // Line Height and spacing
+ ctx.fillText(title[i], rtlHelper.x(pt.x), pt.y + titleFont.lineHeight / 2);
+ pt.y += titleFont.lineHeight + titleSpacing; // Line Height and spacing
if (i + 1 === length) {
pt.y += options.titleMarginBottom - titleSpacing; // If Last, add margin, remove spacing
const me = this;
const labelColors = me.labelColors[i];
const labelPointStyle = me.labelPointStyles[i];
- const {boxHeight, boxWidth, bodyFont} = options;
+ const {boxHeight, boxWidth} = options;
+ const bodyFont = toFont(options.bodyFont);
const colorX = getAlignedX(me, 'left', options);
const rtlColorX = rtlHelper.x(colorX);
- const yOffSet = boxHeight < bodyFont.size ? (bodyFont.size - boxHeight) / 2 : 0;
+ const yOffSet = boxHeight < bodyFont.lineHeight ? (bodyFont.lineHeight - boxHeight) / 2 : 0;
const colorY = pt.y + yOffSet;
if (options.usePointStyle) {
drawBody(pt, ctx, options) {
const me = this;
const {body} = me;
- const {bodyFont, bodySpacing, bodyAlign, displayColors, boxHeight, boxWidth} = options;
- let bodyLineHeight = bodyFont.size;
+ const {bodySpacing, bodyAlign, displayColors, boxHeight, boxWidth} = options;
+ const bodyFont = toFont(options.bodyFont);
+ let bodyLineHeight = bodyFont.lineHeight;
let xLinePadding = 0;
const rtlHelper = getRtlAdapter(options.rtl, me.x, me.width);
ctx.textAlign = bodyAlign;
ctx.textBaseline = 'middle';
- ctx.font = toFontString(bodyFont);
+ ctx.font = bodyFont.string;
pt.x = getAlignedX(me, bodyAlignForCalculation, options);
// Draw Legend-like boxes if needed
if (displayColors && lines.length) {
me._drawColorBox(ctx, pt, i, rtlHelper, options);
- bodyLineHeight = Math.max(bodyFont.size, boxHeight);
+ bodyLineHeight = Math.max(bodyFont.lineHeight, boxHeight);
}
for (j = 0, jlen = lines.length; j < jlen; ++j) {
fillLineOfText(lines[j]);
// Reset for any lines that don't include colorbox
- bodyLineHeight = bodyFont.size;
+ bodyLineHeight = bodyFont.lineHeight;
}
each(bodyItem.after, fillLineOfText);
// Reset back to 0 for after body
xLinePadding = 0;
- bodyLineHeight = bodyFont.size;
+ bodyLineHeight = bodyFont.lineHeight;
// After body lines
each(me.afterBody, fillLineOfText);
ctx.textAlign = rtlHelper.textAlign(options.footerAlign);
ctx.textBaseline = 'middle';
- footerFont = options.footerFont;
+ footerFont = toFont(options.footerFont);
ctx.fillStyle = options.footerColor;
- ctx.font = toFontString(footerFont);
+ ctx.font = footerFont.string;
for (i = 0; i < length; ++i) {
- ctx.fillText(footer[i], rtlHelper.x(pt.x), pt.y + footerFont.size / 2);
- pt.y += footerFont.size + options.footerSpacing;
+ ctx.fillText(footer[i], rtlHelper.x(pt.x), pt.y + footerFont.lineHeight / 2);
+ pt.y += footerFont.lineHeight + options.footerSpacing;
}
}
}
}]
}));
- expect(tooltip.x).toBeCloseToPixel(267);
- expect(tooltip.y).toBeCloseToPixel(155);
+ expect(tooltip.x).toBeCloseToPixel(266);
+ expect(tooltip.y).toBeCloseToPixel(150);
});
it('Should only display if intersecting if intersect is set', async function() {
}]);
expect(tooltip.x).toBeCloseToPixel(267);
- expect(tooltip.y).toBeCloseToPixel(312);
+ expect(tooltip.y).toBeCloseToPixel(308);
});
it('Should display information from user callbacks', async function() {
}));
expect(tooltip.x).toBeCloseToPixel(267);
- expect(tooltip.y).toBeCloseToPixel(75);
+ expect(tooltip.y).toBeCloseToPixel(58);
});
it('Should provide context object to user callbacks', async function() {
}));
expect(tooltip.x).toBeCloseToPixel(267);
- expect(tooltip.y).toBeCloseToPixel(155);
+ expect(tooltip.y).toBeCloseToPixel(150);
});
it('Should allow reversing items', async function() {
}));
expect(tooltip.x).toBeCloseToPixel(267);
- expect(tooltip.y).toBeCloseToPixel(155);
+ expect(tooltip.y).toBeCloseToPixel(150);
});
it('Should follow dataset order', async function() {
}));
expect(tooltip.x).toBeCloseToPixel(267);
- expect(tooltip.y).toBeCloseToPixel(155);
+ expect(tooltip.y).toBeCloseToPixel(150);
});
it('should filter items from the tooltip using the callback', async function() {
{name: 'setTextBaseline', args: ['middle']},
{name: 'setFillStyle', args: ['#fff']},
{name: 'setFont', args: ["bold 12px 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"]},
- {name: 'fillText', args: ['title', 105, 111]},
+ {name: 'fillText', args: ['title', 105, 112.2]},
{name: 'setTextAlign', args: ['left']},
{name: 'setTextBaseline', args: ['middle']},
{name: 'setFont', args: ["normal 12px 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"]},
{name: 'setFillStyle', args: ['#fff']},
{name: 'setFillStyle', args: ['#fff']},
- {name: 'fillText', args: ['label', 105, 129]},
+ {name: 'fillText', args: ['label', 105, 132.6]},
{name: 'setTextAlign', args: ['left']},
{name: 'setTextBaseline', args: ['middle']},
{name: 'setFillStyle', args: ['#fff']},
{name: 'setFont', args: ["bold 12px 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"]},
- {name: 'fillText', args: ['footer', 105, 147]},
+ {name: 'fillText', args: ['footer', 105, 153]},
{name: 'restore', args: []}
]));
});
{name: 'setTextBaseline', args: ['middle']},
{name: 'setFillStyle', args: ['#fff']},
{name: 'setFont', args: ["bold 12px 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"]},
- {name: 'fillText', args: ['title', 195, 111]},
+ {name: 'fillText', args: ['title', 195, 112.2]},
{name: 'setTextAlign', args: ['right']},
{name: 'setTextBaseline', args: ['middle']},
{name: 'setFont', args: ["normal 12px 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"]},
{name: 'setFillStyle', args: ['#fff']},
{name: 'setFillStyle', args: ['#fff']},
- {name: 'fillText', args: ['label', 195, 129]},
+ {name: 'fillText', args: ['label', 195, 132.6]},
{name: 'setTextAlign', args: ['right']},
{name: 'setTextBaseline', args: ['middle']},
{name: 'setFillStyle', args: ['#fff']},
{name: 'setFont', args: ["bold 12px 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"]},
- {name: 'fillText', args: ['footer', 195, 147]},
+ {name: 'fillText', args: ['footer', 195, 153]},
{name: 'restore', args: []}
]));
});
{name: 'setTextBaseline', args: ['middle']},
{name: 'setFillStyle', args: ['#fff']},
{name: 'setFont', args: ["bold 12px 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"]},
- {name: 'fillText', args: ['title', 150, 111]},
+ {name: 'fillText', args: ['title', 150, 112.2]},
{name: 'setTextAlign', args: ['center']},
{name: 'setTextBaseline', args: ['middle']},
{name: 'setFont', args: ["normal 12px 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"]},
{name: 'setFillStyle', args: ['#fff']},
{name: 'setFillStyle', args: ['#fff']},
- {name: 'fillText', args: ['label', 150, 129]},
+ {name: 'fillText', args: ['label', 150, 132.6]},
{name: 'setTextAlign', args: ['center']},
{name: 'setTextBaseline', args: ['middle']},
{name: 'setFillStyle', args: ['#fff']},
{name: 'setFont', args: ["bold 12px 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"]},
- {name: 'fillText', args: ['footer', 150, 147]},
+ {name: 'fillText', args: ['footer', 150, 153]},
{name: 'restore', args: []}
]));
});
{name: 'setTextBaseline', args: ['middle']},
{name: 'setFillStyle', args: ['#fff']},
{name: 'setFont', args: ["bold 12px 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"]},
- {name: 'fillText', args: ['title', 195, 111]},
+ {name: 'fillText', args: ['title', 195, 112.2]},
{name: 'setTextAlign', args: ['center']},
{name: 'setTextBaseline', args: ['middle']},
{name: 'setFont', args: ["normal 12px 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"]},
{name: 'setFillStyle', args: ['#fff']},
{name: 'setFillStyle', args: ['#fff']},
- {name: 'fillText', args: ['label', 150, 129]},
+ {name: 'fillText', args: ['label', 150, 132.6]},
{name: 'setTextAlign', args: ['left']},
{name: 'setTextBaseline', args: ['middle']},
{name: 'setFillStyle', args: ['#fff']},
{name: 'setFont', args: ["bold 12px 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"]},
- {name: 'fillText', args: ['footer', 105, 147]},
+ {name: 'fillText', args: ['footer', 105, 153]},
{name: 'restore', args: []}
]));
});