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

Function avoidOverlap

src/chart/pie/labelLayout.ts:149–257  ·  view source on GitHub ↗
(
    labelLayoutList: LabelLayout[],
    cx: number,
    cy: number,
    r: number,
    viewWidth: number,
    viewHeight: number,
    viewLeft: number,
    viewTop: number
)

Source from the content-addressed store, hash-verified

147}
148
149function avoidOverlap(
150 labelLayoutList: LabelLayout[],
151 cx: number,
152 cy: number,
153 r: number,
154 viewWidth: number,
155 viewHeight: number,
156 viewLeft: number,
157 viewTop: number
158) {
159 const leftList = [];
160 const rightList = [];
161 let leftmostX = Number.MAX_VALUE;
162 let rightmostX = -Number.MAX_VALUE;
163 for (let i = 0; i < labelLayoutList.length; i++) {
164 const label = labelLayoutList[i].label;
165 if (isPositionCenter(labelLayoutList[i])) {
166 continue;
167 }
168 if (label.x < cx) {
169 leftmostX = Math.min(leftmostX, label.x);
170 leftList.push(labelLayoutList[i]);
171 }
172 else {
173 rightmostX = Math.max(rightmostX, label.x);
174 rightList.push(labelLayoutList[i]);
175 }
176 }
177
178 for (let i = 0; i < labelLayoutList.length; i++) {
179 const layout = labelLayoutList[i];
180 if (!isPositionCenter(layout) && layout.linePoints) {
181 if (layout.labelStyleWidth != null) {
182 continue;
183 }
184
185 const label = layout.label;
186 const linePoints = layout.linePoints;
187
188 let targetTextWidth;
189 if (layout.labelAlignTo === 'edge') {
190 if (label.x < cx) {
191 targetTextWidth = linePoints[2][0] - layout.labelDistance
192 - viewLeft - layout.edgeDistance;
193 }
194 else {
195 targetTextWidth = viewLeft + viewWidth - layout.edgeDistance
196 - linePoints[2][0] - layout.labelDistance;
197 }
198 }
199 else if (layout.labelAlignTo === 'labelLine') {
200 if (label.x < cx) {
201 targetTextWidth = leftmostX - viewLeft - layout.bleedMargin;
202 }
203 else {
204 targetTextWidth = viewLeft + viewWidth - rightmostX - layout.bleedMargin;
205 }
206 }

Callers 1

pieLabelLayoutFunction · 0.85

Calls 3

isPositionCenterFunction · 0.85
constrainTextWidthFunction · 0.85
adjustSingleSideFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…