(
sector: Sector,
textPosition: T,
positionMapping: (seriesLabelPosition: T) => SectorTextPosition,
rotateType: number | 'auto'
)
| 190 | } |
| 191 | |
| 192 | export function setSectorTextRotation<T extends (string | (number | string)[])>( |
| 193 | sector: Sector, |
| 194 | textPosition: T, |
| 195 | positionMapping: (seriesLabelPosition: T) => SectorTextPosition, |
| 196 | rotateType: number | 'auto' |
| 197 | ) { |
| 198 | if (isNumber(rotateType)) { |
| 199 | // user-set rotation |
| 200 | sector.setTextConfig({ |
| 201 | rotation: rotateType |
| 202 | }); |
| 203 | return; |
| 204 | } |
| 205 | else if (isArray(textPosition)) { |
| 206 | // user-set position, use 0 as auto rotation |
| 207 | sector.setTextConfig({ |
| 208 | rotation: 0 |
| 209 | }); |
| 210 | return; |
| 211 | } |
| 212 | |
| 213 | const shape = sector.shape; |
| 214 | const startAngle = shape.clockwise ? shape.startAngle : shape.endAngle; |
| 215 | const endAngle = shape.clockwise ? shape.endAngle : shape.startAngle; |
| 216 | const middleAngle = (startAngle + endAngle) / 2; |
| 217 | |
| 218 | let anchorAngle; |
| 219 | const mappedSectorPosition = positionMapping(textPosition); |
| 220 | switch (mappedSectorPosition) { |
| 221 | case 'startArc': |
| 222 | case 'insideStartArc': |
| 223 | case 'middle': |
| 224 | case 'insideEndArc': |
| 225 | case 'endArc': |
| 226 | anchorAngle = middleAngle; |
| 227 | break; |
| 228 | |
| 229 | case 'startAngle': |
| 230 | case 'insideStartAngle': |
| 231 | anchorAngle = startAngle; |
| 232 | break; |
| 233 | |
| 234 | case 'endAngle': |
| 235 | case 'insideEndAngle': |
| 236 | anchorAngle = endAngle; |
| 237 | break; |
| 238 | |
| 239 | default: |
| 240 | sector.setTextConfig({ |
| 241 | rotation: 0 |
| 242 | }); |
| 243 | return; |
| 244 | } |
| 245 | |
| 246 | let rotate = Math.PI * 1.5 - anchorAngle; |
| 247 | /** |
| 248 | * TODO: labels with rotate > Math.PI / 2 should be rotate another |
| 249 | * half round flipped to increase readability. However, only middle |
no test coverage detected
searching dependent graphs…