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

Function determineXAlign

src/plugins/plugin.tooltip.js:246–264  ·  view source on GitHub ↗
(chart, options, size, yAlign)

Source from the content-addressed store, hash-verified

244}
245
246function determineXAlign(chart, options, size, yAlign) {
247 const {x, width} = size;
248 const {width: chartWidth, chartArea: {left, right}} = chart;
249 let xAlign = 'center';
250
251 if (yAlign === 'center') {
252 xAlign = x <= (left + right) / 2 ? 'left' : 'right';
253 } else if (x <= width / 2) {
254 xAlign = 'left';
255 } else if (x >= chartWidth - width / 2) {
256 xAlign = 'right';
257 }
258
259 if (doesNotFitWithAlign(xAlign, chart, options, size)) {
260 xAlign = 'center';
261 }
262
263 return xAlign;
264}
265
266/**
267 * Helper to get the alignment of a tooltip given the size

Callers 1

determineAlignmentFunction · 0.85

Calls 1

doesNotFitWithAlignFunction · 0.85

Tested by

no test coverage detected