(
node: GraphNode,
circularRotateLabel: boolean,
cx: number,
cy: number
)
| 191 | }; |
| 192 | |
| 193 | export function rotateNodeLabel( |
| 194 | node: GraphNode, |
| 195 | circularRotateLabel: boolean, |
| 196 | cx: number, |
| 197 | cy: number |
| 198 | ) { |
| 199 | const el = node.getGraphicEl() as Symbol; |
| 200 | // need to check if el exists. '-' value may not create node element. |
| 201 | if (!el) { |
| 202 | return; |
| 203 | } |
| 204 | const nodeModel = node.getModel<GraphNodeItemOption>(); |
| 205 | let labelRotate = nodeModel.get(['label', 'rotate']) || 0; |
| 206 | const symbolPath = el.getSymbolPath(); |
| 207 | if (circularRotateLabel) { |
| 208 | const pos = node.getLayout(); |
| 209 | let rad = Math.atan2(pos[1] - cy, pos[0] - cx); |
| 210 | if (rad < 0) { |
| 211 | rad = Math.PI * 2 + rad; |
| 212 | } |
| 213 | const isLeft = pos[0] < cx; |
| 214 | if (isLeft) { |
| 215 | rad = rad - Math.PI; |
| 216 | } |
| 217 | const textPosition = isLeft ? 'left' as const : 'right' as const; |
| 218 | |
| 219 | symbolPath.setTextConfig({ |
| 220 | rotation: -rad, |
| 221 | position: textPosition, |
| 222 | origin: 'center' |
| 223 | }); |
| 224 | const emphasisState = symbolPath.ensureState('emphasis'); |
| 225 | zrUtil.extend(emphasisState.textConfig || (emphasisState.textConfig = {}), { |
| 226 | position: textPosition |
| 227 | }); |
| 228 | } |
| 229 | else { |
| 230 | symbolPath.setTextConfig({ |
| 231 | rotation: labelRotate *= Math.PI / 180 |
| 232 | }); |
| 233 | } |
| 234 | } |
no test coverage detected
searching dependent graphs…