MCPcopy Create free account
hub / github.com/chartjs/Chart.js / getBackgroundPoint

Function getBackgroundPoint

src/plugins/plugin.tooltip.js:340–365  ·  view source on GitHub ↗

* Helper to get the location a tooltip needs to be placed at given the initial position (via the vm) and the size and alignment

(options, size, alignment, chart)

Source from the content-addressed store, hash-verified

338 * Helper to get the location a tooltip needs to be placed at given the initial position (via the vm) and the size and alignment
339 */
340function getBackgroundPoint(options, size, alignment, chart) {
341 const {caretSize, caretPadding, cornerRadius} = options;
342 const {xAlign, yAlign} = alignment;
343 const paddingAndSize = caretSize + caretPadding;
344 const {topLeft, topRight, bottomLeft, bottomRight} = toTRBLCorners(cornerRadius);
345
346 let x = alignX(size, xAlign);
347 const y = alignY(size, yAlign, paddingAndSize);
348
349 if (yAlign === 'center') {
350 if (xAlign === 'left') {
351 x += paddingAndSize;
352 } else if (xAlign === 'right') {
353 x -= paddingAndSize;
354 }
355 } else if (xAlign === 'left') {
356 x -= Math.max(topLeft, bottomLeft) + caretSize;
357 } else if (xAlign === 'right') {
358 x += Math.max(topRight, bottomRight) + caretSize;
359 }
360
361 return {
362 x: _limitValue(x, 0, chart.width - size.width),
363 y: _limitValue(y, 0, chart.height - size.height)
364 };
365}
366
367function getAlignedX(tooltip, align, options) {
368 const padding = toPadding(options.padding);

Callers 2

updateMethod · 0.85

Calls 4

toTRBLCornersFunction · 0.85
alignXFunction · 0.85
alignYFunction · 0.85
_limitValueFunction · 0.85

Tested by

no test coverage detected