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

Method _getYAxisLabelAlignment

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

Source from the content-addressed store, hash-verified

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

Callers 1

_computeLabelItemsMethod · 0.95

Calls 1

_getLabelSizesMethod · 0.95

Tested by

no test coverage detected