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

Method adjustHitBoxes

src/plugins/plugin.legend.js:230–263  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

228 }
229
230 adjustHitBoxes() {
231 if (!this.options.display) {
232 return;
233 }
234 const titleHeight = this._computeTitleHeight();
235 const {legendHitBoxes: hitboxes, options: {align, labels: {padding}, rtl}} = this;
236 const rtlHelper = getRtlAdapter(rtl, this.left, this.width);
237 if (this.isHorizontal()) {
238 let row = 0;
239 let left = _alignStartEnd(align, this.left + padding, this.right - this.lineWidths[row]);
240 for (const hitbox of hitboxes) {
241 if (row !== hitbox.row) {
242 row = hitbox.row;
243 left = _alignStartEnd(align, this.left + padding, this.right - this.lineWidths[row]);
244 }
245 hitbox.top += this.top + titleHeight + padding;
246 hitbox.left = rtlHelper.leftForLtr(rtlHelper.x(left), hitbox.width);
247 left += hitbox.width + padding;
248 }
249 } else {
250 let col = 0;
251 let top = _alignStartEnd(align, this.top + titleHeight + padding, this.bottom - this.columnSizes[col].height);
252 for (const hitbox of hitboxes) {
253 if (hitbox.col !== col) {
254 col = hitbox.col;
255 top = _alignStartEnd(align, this.top + titleHeight + padding, this.bottom - this.columnSizes[col].height);
256 }
257 hitbox.top = top;
258 hitbox.left += this.left + padding;
259 hitbox.left = rtlHelper.leftForLtr(rtlHelper.x(hitbox.left), hitbox.width);
260 top += hitbox.height + padding;
261 }
262 }
263 }
264
265 isHorizontal() {
266 return this.options.position === 'top' || this.options.position === 'bottom';

Callers 1

afterUpdateFunction · 0.80

Calls 6

_computeTitleHeightMethod · 0.95
isHorizontalMethod · 0.95
getRtlAdapterFunction · 0.85
_alignStartEndFunction · 0.85
leftForLtrMethod · 0.80
xMethod · 0.80

Tested by

no test coverage detected