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

Function determineXAlign

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

Source from the content-addressed store, hash-verified

280}
281
282function determineXAlign(chart, options, size, yAlign) {
283 const {x, width} = size;
284 const {width: chartWidth, chartArea: {left, right}} = chart;
285 let xAlign = 'center';
286
287 if (yAlign === 'center') {
288 xAlign = x <= (left + right) / 2 ? 'left' : 'right';
289 } else if (x <= width / 2) {
290 xAlign = 'left';
291 } else if (x >= chartWidth - width / 2) {
292 xAlign = 'right';
293 }
294
295 if (doesNotFitWithAlign(xAlign, chart, options, size)) {
296 xAlign = 'center';
297 }
298
299 return xAlign;
300}
301
302/**
303 * 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