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