(first, last, sin, cos)
| 687 | } |
| 688 | |
| 689 | _calculatePadding(first, last, sin, cos) { |
| 690 | const {ticks: {align, padding}, position} = this.options; |
| 691 | const isRotated = this.labelRotation !== 0; |
| 692 | const labelsBelowTicks = position !== 'top' && this.axis === 'x'; |
| 693 | |
| 694 | if (this.isHorizontal()) { |
| 695 | const offsetLeft = this.getPixelForTick(0) - this.left; |
| 696 | const offsetRight = this.right - this.getPixelForTick(this.ticks.length - 1); |
| 697 | let paddingLeft = 0; |
| 698 | let paddingRight = 0; |
| 699 | |
| 700 | // Ensure that our ticks are always inside the canvas. When rotated, ticks are right aligned |
| 701 | // which means that the right padding is dominated by the font height |
| 702 | if (isRotated) { |
| 703 | if (labelsBelowTicks) { |
| 704 | paddingLeft = cos * first.width; |
| 705 | paddingRight = sin * last.height; |
| 706 | } else { |
| 707 | paddingLeft = sin * first.height; |
| 708 | paddingRight = cos * last.width; |
| 709 | } |
| 710 | } else if (align === 'start') { |
| 711 | paddingRight = last.width; |
| 712 | } else if (align === 'end') { |
| 713 | paddingLeft = first.width; |
| 714 | } else if (align !== 'inner') { |
| 715 | paddingLeft = first.width / 2; |
| 716 | paddingRight = last.width / 2; |
| 717 | } |
| 718 | |
| 719 | // Adjust padding taking into account changes in offsets |
| 720 | this.paddingLeft = Math.max((paddingLeft - offsetLeft + padding) * this.width / (this.width - offsetLeft), 0); |
| 721 | this.paddingRight = Math.max((paddingRight - offsetRight + padding) * this.width / (this.width - offsetRight), 0); |
| 722 | } else { |
| 723 | let paddingTop = last.height / 2; |
| 724 | let paddingBottom = first.height / 2; |
| 725 | |
| 726 | if (align === 'start') { |
| 727 | paddingTop = 0; |
| 728 | paddingBottom = first.height; |
| 729 | } else if (align === 'end') { |
| 730 | paddingTop = last.height; |
| 731 | paddingBottom = 0; |
| 732 | } |
| 733 | |
| 734 | this.paddingTop = paddingTop + padding; |
| 735 | this.paddingBottom = paddingBottom + padding; |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | /** |
| 740 | * Handle margins and padding interactions |
no test coverage detected