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

Function updateLabelLinePoints

src/label/labelGuideHelper.ts:338–401  ·  view source on GitHub ↗
(
    target: Element,
    labelLineModel: Model<LabelLineOption>
)

Source from the content-addressed store, hash-verified

336 * @param targetRect
337 */
338export function updateLabelLinePoints(
339 target: Element,
340 labelLineModel: Model<LabelLineOption>
341) {
342 if (!target) {
343 return;
344 }
345
346 const labelLine = target.getTextGuideLine();
347 const label = target.getTextContent();
348 // Needs to create text guide in each charts.
349 if (!(label && labelLine)) {
350 return;
351 }
352
353 const labelGuideConfig = target.textGuideLineConfig || {};
354
355 const points = [[0, 0], [0, 0], [0, 0]];
356
357 const searchSpace = labelGuideConfig.candidates || DEFAULT_SEARCH_SPACE;
358 const labelRect = label.getBoundingRect().clone();
359 labelRect.applyTransform(label.getComputedTransform());
360
361 let minDist = Infinity;
362 const anchorPoint = labelGuideConfig.anchor;
363 const targetTransform = target.getComputedTransform();
364 const targetInversedTransform = targetTransform && invert([], targetTransform);
365 const len = labelLineModel.get('length2') || 0;
366
367 if (anchorPoint) {
368 pt2.copy(anchorPoint);
369 }
370 for (let i = 0; i < searchSpace.length; i++) {
371 const candidate = searchSpace[i];
372 getCandidateAnchor(candidate, 0, labelRect, pt0, dir);
373 Point.scaleAndAdd(pt1, pt0, dir, len);
374
375 // Transform to target coord space.
376 pt1.transform(targetInversedTransform);
377
378 // Note: getBoundingRect will ensure the `path` being created.
379 const boundingRect = target.getBoundingRect();
380 const dist = anchorPoint ? anchorPoint.distance(pt1)
381 : (target instanceof Path
382 ? nearestPointOnPath(pt1, target.path, pt2)
383 : nearestPointOnRect(pt1, boundingRect, pt2));
384
385 // TODO pt2 is in the path
386 if (dist < minDist) {
387 minDist = dist;
388 // Transform back to global space.
389 pt1.transform(targetTransform);
390 pt2.transform(targetTransform);
391
392 pt2.toArray(points[0]);
393 pt1.toArray(points[1]);
394 pt0.toArray(points[2]);
395 }

Callers 2

createDragHandlerMethod · 0.90
_updateLabelLineMethod · 0.90

Calls 8

getCandidateAnchorFunction · 0.85
nearestPointOnPathFunction · 0.85
nearestPointOnRectFunction · 0.85
limitTurnAngleFunction · 0.85
setShapeMethod · 0.80
cloneMethod · 0.45
getBoundingRectMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…