MCPcopy
hub / github.com/chartjs/Chart.js / getBackgroundPoint

Function getBackgroundPoint

src/plugins/plugin.tooltip.js:304–329  ·  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

302 * Helper to get the location a tooltip needs to be placed at given the initial position (via the vm) and the size and alignment
303 */
304function getBackgroundPoint(options, size, alignment, chart) {
305 const {caretSize, caretPadding, cornerRadius} = options;
306 const {xAlign, yAlign} = alignment;
307 const paddingAndSize = caretSize + caretPadding;
308 const {topLeft, topRight, bottomLeft, bottomRight} = toTRBLCorners(cornerRadius);
309
310 let x = alignX(size, xAlign);
311 const y = alignY(size, yAlign, paddingAndSize);
312
313 if (yAlign === 'center') {
314 if (xAlign === 'left') {
315 x += paddingAndSize;
316 } else if (xAlign === 'right') {
317 x -= paddingAndSize;
318 }
319 } else if (xAlign === 'left') {
320 x -= Math.max(topLeft, bottomLeft) + caretSize;
321 } else if (xAlign === 'right') {
322 x += Math.max(topRight, bottomRight) + caretSize;
323 }
324
325 return {
326 x: _limitValue(x, 0, chart.width - size.width),
327 y: _limitValue(y, 0, chart.height - size.height)
328 };
329}
330
331function getAlignedX(tooltip, align, options) {
332 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