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

Method _getYAxisLabelAlignment

src/core/core.scale.js:1354–1420  ·  view source on GitHub ↗
(tl)

Source from the content-addressed store, hash-verified

1352 }
1353
1354 _getYAxisLabelAlignment(tl) {
1355 const {position, ticks: {crossAlign, mirror, padding}} = this.options;
1356 const labelSizes = this._getLabelSizes();
1357 const tickAndPadding = tl + padding;
1358 const widest = labelSizes.widest.width;
1359
1360 let textAlign;
1361 let x;
1362
1363 if (position === 'left') {
1364 if (mirror) {
1365 x = this.right + padding;
1366
1367 if (crossAlign === 'near') {
1368 textAlign = 'left';
1369 } else if (crossAlign === 'center') {
1370 textAlign = 'center';
1371 x += (widest / 2);
1372 } else {
1373 textAlign = 'right';
1374 x += widest;
1375 }
1376 } else {
1377 x = this.right - tickAndPadding;
1378
1379 if (crossAlign === 'near') {
1380 textAlign = 'right';
1381 } else if (crossAlign === 'center') {
1382 textAlign = 'center';
1383 x -= (widest / 2);
1384 } else {
1385 textAlign = 'left';
1386 x = this.left;
1387 }
1388 }
1389 } else if (position === 'right') {
1390 if (mirror) {
1391 x = this.left + padding;
1392
1393 if (crossAlign === 'near') {
1394 textAlign = 'right';
1395 } else if (crossAlign === 'center') {
1396 textAlign = 'center';
1397 x -= (widest / 2);
1398 } else {
1399 textAlign = 'left';
1400 x -= widest;
1401 }
1402 } else {
1403 x = this.left + tickAndPadding;
1404
1405 if (crossAlign === 'near') {
1406 textAlign = 'left';
1407 } else if (crossAlign === 'center') {
1408 textAlign = 'center';
1409 x += widest / 2;
1410 } else {
1411 textAlign = 'right';

Callers 1

_computeLabelItemsMethod · 0.95

Calls 1

_getLabelSizesMethod · 0.95

Tested by

no test coverage detected