1
0
mirror of https://github.com/excalidraw/excalidraw.git synced 2024-11-10 11:35:52 +01:00

Set arrow cap size based on minimum the full length of the arrow instead of last segment (#709)

This commit is contained in:
Gasim Gasimzada 2020-02-05 15:54:17 +04:00 committed by GitHub
parent 27a1217981
commit c7d7d65e1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -125,8 +125,15 @@ export function getArrowPoints(element: ExcalidrawElement) {
const size = 30; // pixels
const distance = Math.hypot(x2 - x1, y2 - y1);
const arrowLength = element.points.reduce((total, [cx, cy], idx, points) => {
const [px, py] = idx > 0 ? points[idx - 1] : [0, 0];
return total + Math.hypot(cx - px, cy - py);
}, 0);
// Scale down the arrow until we hit a certain size so that it doesn't look weird
const minSize = Math.min(size, distance / 2);
// This value is selected by minizing a minmum size with the whole length of the arrow
// intead of last segment of the arrow
const minSize = Math.min(size, arrowLength / 2);
const xs = x2 - ((x2 - x1) / distance) * minSize;
const ys = y2 - ((y2 - y1) / distance) * minSize;