Skip to content

🎥 Make videos programmatically with React

add support for counterclockwise

Jonny Burger3ba066a44f13
diff --git a/packages/docs/components/demos/Pie.tsx b/packages/docs/components/demos/Pie.tsx
index daac0b0f5a..35a96f59cb 100644
--- a/packages/docs/components/demos/Pie.tsx
+++ b/packages/docs/components/demos/Pie.tsx
@@ -8,12 +8,14 @@ export const PieDemo: React.FC<{
progress: number;
closePath: boolean;
showStrokeInsteadPreviewOnly: boolean;
+ counterClockwise: boolean;
}> = ({
radius,
darkMode,
progress,
closePath,
showStrokeInsteadPreviewOnly,
+ counterClockwise,
}) => {
return (
<AbsoluteFill
@@ -35,6 +37,7 @@ export const PieDemo: React.FC<{
closePath={closePath}
stroke={darkMode ? "white" : "var(--ifm-link-color)"}
strokeWidth={showStrokeInsteadPreviewOnly ? 5 : 0}
+ counterClockwise={counterClockwise}
/>
</AbsoluteFill>
);
diff --git a/packages/docs/components/demos/types.ts b/packages/docs/components/demos/types.ts
index d0730d62ff..0739d3e445 100644
--- a/packages/docs/components/demos/types.ts
+++ b/packages/docs/components/demos/types.ts
@@ -199,6 +199,12 @@ export const pieDemo: DemoType = {
name: "closePath",
optional: "no",
},
+ {
+ default: false,
+ type: "boolean",
+ name: "counterClockwise",
+ optional: "no",
+ },
{
default: false,
type: "boolean",
diff --git a/packages/docs/components/shapes/shapes-info.tsx b/packages/docs/components/shapes/shapes-info.tsx
index 4fad35ffd8..f449be11bb 100644
--- a/packages/docs/components/shapes/shapes-info.tsx
+++ b/packages/docs/components/shapes/shapes-info.tsx
@@ -68,6 +68,12 @@ export const shapeComponents: ShapeComponent[] = [
description:
"The percentage of the circle that is filled. 0 means fully empty, 1 means fully filled.",
},
+ {
+ name: "counterClockwise",
+ type: "boolean",
+ description:
+ "If set, the circle gets filled counterclockwise instead of clockwise. Default false.",
+ },
],
},
{
diff --git a/packages/shapes/src/components/pie.tsx b/packages/shapes/src/components/pie.tsx
index bcd642590c..73656b5393 100644
--- a/packages/shapes/src/components/pie.tsx
+++ b/packages/shapes/src/components/pie.tsx
@@ -10,7 +10,13 @@ export const Pie: React.FC<PieProps> = ({
radius,
progress,
closePath,
+ counterClockwise,
...props
}) => {
- return <RenderSvg {...makePie({radius, progress, closePath})} {...props} />;
+ return (
+ <RenderSvg
+ {...makePie({radius, progress, closePath, counterClockwise})}
+ {...props}
+ />
+ );
};
diff --git a/packages/shapes/src/utils/make-pie.ts b/packages/shapes/src/utils/make-pie.ts
index 6d4d5a7828..0471945975 100644
--- a/packages/shapes/src/utils/make-pie.ts
+++ b/packages/shapes/src/utils/make-pie.ts
@@ -5,15 +5,24 @@ export type MakePieProps = {
radius: number;
progress: number;
closePath?: boolean;
+ counterClockwise?: boolean;
};
-export const makePie = ({progress, radius, closePath = true}: MakePieProps) => {
+export const makePie = ({
+ progress,
+ radius,
+ closePath = true,
+ counterClockwise = false,
+}: MakePieProps) => {
const actualProgress = Math.min(Math.max(progress, 0), 1);
+ const factor = counterClockwise ? -1 : 1;
const endAngleX =
- Math.cos(actualProgress * Math.PI * 2 + Math.PI * 1.5) * radius + radius;
+ Math.cos(factor * actualProgress * Math.PI * 2 + Math.PI * 1.5) * radius +
+ radius;
const endAngleY =
- Math.sin(actualProgress * Math.PI * 2 + Math.PI * 1.5) * radius + radius;
+ Math.sin(factor * actualProgress * Math.PI * 2 + Math.PI * 1.5) * radius +
+ radius;
const start = {x: radius, y: 0};
const end = {x: endAngleX, y: endAngleY};
@@ -29,7 +38,7 @@ export const makePie = ({progress, radius, closePath = true}: MakePieProps) => {
ry: radius,
xAxisRotation: 0,
largeArcFlag: false,
- sweepFlag: true,
+ sweepFlag: !counterClockwise,
x: actualProgress <= 0.5 ? endAngleX : radius,
y: actualProgress <= 0.5 ? endAngleY : radius * 2,
},
@@ -40,7 +49,7 @@ export const makePie = ({progress, radius, closePath = true}: MakePieProps) => {
ry: radius,
xAxisRotation: 0,
largeArcFlag: false,
- sweepFlag: true,
+ sweepFlag: !counterClockwise,
...end,
}
: null,