* 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)
| 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 | */ |
| 340 | function 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 | |
| 367 | function getAlignedX(tooltip, align, options) { |
| 368 | const padding = toPadding(options.padding); |
no test coverage detected