Skip to content

Add arrowHeadSize prop #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/few-bars-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"slidev-addon-fancy-arrow": minor
---

arrowHeadSize prop
2 changes: 2 additions & 0 deletions components/FancyArrow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const props = defineProps<{
twoWay?: boolean;
arc?: number | string;
arrowHeadType?: "line" | "polygon";
arrowHeadSize?: number | string;
}>();

const point1 = props.id1
Expand All @@ -35,6 +36,7 @@ const roughSvg = useRoughArrow({
twoWay: props.twoWay ?? false,
centerPositionParam: Number(props.arc ?? 0),
arrowHeadType: props.arrowHeadType ?? "line",
arrowHeadSize: props.arrowHeadSize ? Number(props.arrowHeadSize) : null,
});
</script>

Expand Down
12 changes: 9 additions & 3 deletions components/use-rough-arrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export function useRoughArrow(props: {
color: string;
width: number;
arrowHeadType: "line" | "polygon";
arrowHeadSize: number | null;
twoWay: boolean;
centerPositionParam: number;
}) {
Expand All @@ -54,6 +55,7 @@ export function useRoughArrow(props: {
color,
width,
arrowHeadType,
arrowHeadSize,
twoWay,
centerPositionParam,
} = props;
Expand Down Expand Up @@ -178,11 +180,15 @@ export function useRoughArrow(props: {
};
});

const arrowSize = computed(() => {
const computedArrowHeadSize = computed(() => {
if (line.value == null) {
return 0;
}

if (arrowHeadSize != null) {
return arrowHeadSize;
}

// The arrow size is proportional to the line length.
// The constant factor is chosen so that the arrow size is 30 when the line length is 200.
return (30 * Math.log(line.value.lineLength)) / Math.log(200);
Expand All @@ -191,15 +197,15 @@ export function useRoughArrow(props: {
const arrowHead1 = computed(() =>
createArrowHeadSvg(
rc.value as RoughSVG,
arrowSize.value,
computedArrowHeadSize.value,
arrowHeadType,
options,
),
);
const arrowHead2 = computed(() =>
createArrowHeadSvg(
rc.value as RoughSVG,
arrowSize.value,
computedArrowHeadSize.value,
arrowHeadType,
options,
),
Expand Down
2 changes: 1 addition & 1 deletion slides.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

<FancyArrow id1="block1" pos1="bottom" id2="block2" pos2="top" color="red" width="3" twoWay />

<FancyArrow id1="block1" pos1="bottomright" id2="block2" pos2="topright" color="red" width="3" twoWay arc="0.5" arrowHeadType="polygon" />
<FancyArrow id1="block1" pos1="bottomright" id2="block2" pos2="topright" color="red" width="3" twoWay arc="0.5" arrowHeadType="polygon" arrowHeadSize="30" />

---

Expand Down