MCPcopy Index your code
hub / github.com/apache/echarts / getLabelPosition

Function getLabelPosition

src/component/axisPointer/PolarAxisPointer.ts:94–140  ·  view source on GitHub ↗
(
    value: ScaleDataValue,
    axisModel: PolarAxisModel,
    axisPointerModel: AxisPointerModel,
    polar: Polar,
    labelMargin: number
)

Source from the content-addressed store, hash-verified

92};
93
94function 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
143const pointerShapeBuilder = {

Callers 1

makeElOptionMethod · 0.85

Calls 9

dataToCoordMethod · 0.80
getAngleAxisMethod · 0.80
getRadiusAxisMethod · 0.80
innerTextLayoutMethod · 0.80
getExtentMethod · 0.65
createMethod · 0.45
getMethod · 0.45
getModelMethod · 0.45
coordToPointMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…