(
value: ScaleDataValue,
axisModel: PolarAxisModel,
axisPointerModel: AxisPointerModel,
polar: Polar,
labelMargin: number
)
| 92 | }; |
| 93 | |
| 94 | function getLabelPosition( |
| 95 | value: ScaleDataValue, |
| 96 | axisModel: PolarAxisModel, |
| 97 | axisPointerModel: AxisPointerModel, |
| 98 | polar: Polar, |
| 99 | labelMargin: number |
| 100 | ) { |
| 101 | const axis = axisModel.axis; |
| 102 | const coord = axis.dataToCoord(value); |
| 103 | let axisAngle = polar.getAngleAxis().getExtent()[0]; |
| 104 | axisAngle = axisAngle / 180 * Math.PI; |
| 105 | const radiusExtent = polar.getRadiusAxis().getExtent(); |
| 106 | let position; |
| 107 | let align: ZRTextAlign; |
| 108 | let verticalAlign: ZRTextVerticalAlign; |
| 109 | |
| 110 | if (axis.dim === 'radius') { |
| 111 | const transform = matrix.create(); |
| 112 | matrix.rotate(transform, transform, axisAngle); |
| 113 | matrix.translate(transform, transform, [polar.cx, polar.cy]); |
| 114 | position = graphic.applyTransform([coord, -labelMargin], transform); |
| 115 | |
| 116 | const labelRotation = axisModel.getModel('axisLabel').get('rotate') || 0; |
| 117 | // @ts-ignore |
| 118 | const labelLayout = AxisBuilder.innerTextLayout( |
| 119 | axisAngle, labelRotation * Math.PI / 180, -1 |
| 120 | ); |
| 121 | align = labelLayout.textAlign; |
| 122 | verticalAlign = labelLayout.textVerticalAlign; |
| 123 | } |
| 124 | else { // angle axis |
| 125 | const r = radiusExtent[1]; |
| 126 | position = polar.coordToPoint([r + labelMargin, coord]); |
| 127 | const cx = polar.cx; |
| 128 | const cy = polar.cy; |
| 129 | align = Math.abs(position[0] - cx) / r < 0.3 |
| 130 | ? 'center' : (position[0] > cx ? 'left' : 'right'); |
| 131 | verticalAlign = Math.abs(position[1] - cy) / r < 0.3 |
| 132 | ? 'middle' : (position[1] > cy ? 'top' : 'bottom'); |
| 133 | } |
| 134 | |
| 135 | return { |
| 136 | position: position, |
| 137 | align: align, |
| 138 | verticalAlign: verticalAlign |
| 139 | }; |
| 140 | } |
| 141 | |
| 142 | |
| 143 | const pointerShapeBuilder = { |
no test coverage detected
searching dependent graphs…