mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Canvas: Ensure tangency for first segment (#86543)
This commit is contained in:
parent
2049f766c6
commit
173ba73a8a
@ -196,7 +196,7 @@ export const ConnectionSVG = ({
|
|||||||
const Yn = vertices[index + 1].y * yDist + yStart;
|
const Yn = vertices[index + 1].y * yDist + yStart;
|
||||||
if (index === 0) {
|
if (index === 0) {
|
||||||
// First vertex
|
// First vertex
|
||||||
angle1 = calculateAngle(xStart, yStart, X, Y);
|
angle1 = calculateAngle(x1, y1, X, Y);
|
||||||
angle2 = calculateAngle(X, Y, Xn, Yn);
|
angle2 = calculateAngle(X, Y, Xn, Yn);
|
||||||
} else {
|
} else {
|
||||||
// All vertices
|
// All vertices
|
||||||
@ -239,7 +239,7 @@ export const ConnectionSVG = ({
|
|||||||
// Only calculate arcs if there is a radius
|
// Only calculate arcs if there is a radius
|
||||||
if (radius) {
|
if (radius) {
|
||||||
// Length of segment
|
// Length of segment
|
||||||
const lSegment = calculateDistance(X, Y, xStart, yStart);
|
const lSegment = calculateDistance(X, Y, x1, y1);
|
||||||
if (Math.abs(lHalfArc) > 0.5 * Math.abs(lSegment)) {
|
if (Math.abs(lHalfArc) > 0.5 * Math.abs(lSegment)) {
|
||||||
// Limit curve control points to mid segment
|
// Limit curve control points to mid segment
|
||||||
lHalfArc = 0.5 * lSegment;
|
lHalfArc = 0.5 * lSegment;
|
||||||
@ -250,8 +250,8 @@ export const ConnectionSVG = ({
|
|||||||
if (index < vertices.length - 1) {
|
if (index < vertices.length - 1) {
|
||||||
// Not also the last point
|
// Not also the last point
|
||||||
const nextVertex = vertices[index + 1];
|
const nextVertex = vertices[index + 1];
|
||||||
Xn = nextVertex.x * xDist + xStart;
|
Xn = nextVertex.x * xDist + x1;
|
||||||
Yn = nextVertex.y * yDist + yStart;
|
Yn = nextVertex.y * yDist + y1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Length of next segment
|
// Length of next segment
|
||||||
@ -262,15 +262,15 @@ export const ConnectionSVG = ({
|
|||||||
}
|
}
|
||||||
// Calculate arc control points
|
// Calculate arc control points
|
||||||
const lDelta = lSegment - lHalfArc;
|
const lDelta = lSegment - lHalfArc;
|
||||||
xa = lDelta * Math.cos(angle1) + xStart;
|
xa = lDelta * Math.cos(angle1) + x1;
|
||||||
ya = lDelta * Math.sin(angle1) + yStart;
|
ya = lDelta * Math.sin(angle1) + y1;
|
||||||
xb = lHalfArc * Math.cos(angle2) + X;
|
xb = lHalfArc * Math.cos(angle2) + X;
|
||||||
yb = lHalfArc * Math.sin(angle2) + Y;
|
yb = lHalfArc * Math.sin(angle2) + Y;
|
||||||
|
|
||||||
// Check if arc control points are inside of segment, otherwise swap sign
|
// Check if arc control points are inside of segment, otherwise swap sign
|
||||||
if ((xa > X && xa > xStart) || (xa < X && xa < xStart)) {
|
if ((xa > X && xa > x1) || (xa < X && xa < x1)) {
|
||||||
xa = (lDelta + 2 * lHalfArc) * Math.cos(angle1) + xStart;
|
xa = (lDelta + 2 * lHalfArc) * Math.cos(angle1) + x1;
|
||||||
ya = (lDelta + 2 * lHalfArc) * Math.sin(angle1) + yStart;
|
ya = (lDelta + 2 * lHalfArc) * Math.sin(angle1) + y1;
|
||||||
xb = -lHalfArc * Math.cos(angle2) + X;
|
xb = -lHalfArc * Math.cos(angle2) + X;
|
||||||
yb = -lHalfArc * Math.sin(angle2) + Y;
|
yb = -lHalfArc * Math.sin(angle2) + Y;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user