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

Function buildLabelLinePath

src/label/labelGuideHelper.ts:554–584  ·  view source on GitHub ↗
(path: CanvasRenderingContext2D, shape: Polyline['shape'])

Source from the content-addressed store, hash-verified

552}
553
554function buildLabelLinePath(path: CanvasRenderingContext2D, shape: Polyline['shape']) {
555 const smooth = shape.smooth as number;
556 const points = shape.points;
557 if (!points) {
558 return;
559 }
560 path.moveTo(points[0][0], points[0][1]);
561 if (smooth > 0 && points.length >= 3) {
562 const len1 = vector.dist(points[0], points[1]);
563 const len2 = vector.dist(points[1], points[2]);
564 if (!len1 || !len2) {
565 path.lineTo(points[1][0], points[1][1]);
566 path.lineTo(points[2][0], points[2][1]);
567 return;
568 }
569
570 const moveLen = Math.min(len1, len2) * smooth;
571
572 const midPoint0 = vector.lerp([], points[1], points[0], moveLen / len1);
573 const midPoint2 = vector.lerp([], points[1], points[2], moveLen / len2);
574
575 const midPoint1 = vector.lerp([], midPoint0, midPoint2, 0.5);
576 path.bezierCurveTo(midPoint0[0], midPoint0[1], midPoint0[0], midPoint0[1], midPoint1[0], midPoint1[1]);
577 path.bezierCurveTo(midPoint2[0], midPoint2[1], midPoint2[0], midPoint2[1], points[2][0], points[2][1]);
578 }
579 else {
580 for (let i = 1; i < points.length; i++) {
581 path.lineTo(points[i][0], points[i][1]);
582 }
583 }
584}
585
586/**
587 * Create a label line if necessary and set it's style.

Callers

nothing calls this directly

Calls 1

moveToMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…