(scale, offset, position, align)
| 129 | } |
| 130 | |
| 131 | function titleArgs(scale, offset, position, align) { |
| 132 | const {top, left, bottom, right, chart} = scale; |
| 133 | const {chartArea, scales} = chart; |
| 134 | let rotation = 0; |
| 135 | let maxWidth, titleX, titleY; |
| 136 | const height = bottom - top; |
| 137 | const width = right - left; |
| 138 | |
| 139 | if (scale.isHorizontal()) { |
| 140 | titleX = _alignStartEnd(align, left, right); |
| 141 | |
| 142 | if (isObject(position)) { |
| 143 | const positionAxisID = Object.keys(position)[0]; |
| 144 | const value = position[positionAxisID]; |
| 145 | titleY = scales[positionAxisID].getPixelForValue(value) + height - offset; |
| 146 | } else if (position === 'center') { |
| 147 | titleY = (chartArea.bottom + chartArea.top) / 2 + height - offset; |
| 148 | } else { |
| 149 | titleY = offsetFromEdge(scale, position, offset); |
| 150 | } |
| 151 | maxWidth = right - left; |
| 152 | } else { |
| 153 | if (isObject(position)) { |
| 154 | const positionAxisID = Object.keys(position)[0]; |
| 155 | const value = position[positionAxisID]; |
| 156 | titleX = scales[positionAxisID].getPixelForValue(value) - width + offset; |
| 157 | } else if (position === 'center') { |
| 158 | titleX = (chartArea.left + chartArea.right) / 2 - width + offset; |
| 159 | } else { |
| 160 | titleX = offsetFromEdge(scale, position, offset); |
| 161 | } |
| 162 | titleY = _alignStartEnd(align, bottom, top); |
| 163 | rotation = position === 'left' ? -HALF_PI : HALF_PI; |
| 164 | } |
| 165 | return {titleX, titleY, maxWidth, rotation}; |
| 166 | } |
| 167 | |
| 168 | export default class Scale extends Element { |
| 169 |
no test coverage detected