MCPcopy
hub / github.com/apache/echarts / rotateNodeLabel

Function rotateNodeLabel

src/chart/graph/circularLayoutHelper.ts:193–234  ·  view source on GitHub ↗
(
    node: GraphNode,
    circularRotateLabel: boolean,
    cx: number,
    cy: number
)

Source from the content-addressed store, hash-verified

191};
192
193export 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}

Callers 2

renderMethod · 0.90
circularLayoutFunction · 0.85

Calls 5

getGraphicElMethod · 0.80
getSymbolPathMethod · 0.80
getLayoutMethod · 0.65
getModelMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…