diff --git a/src/components/Broadcast/Layout/Layout.tsx b/src/components/Broadcast/Layout/Layout.tsx
index 13c0a07..e9d5489 100644
--- a/src/components/Broadcast/Layout/Layout.tsx
+++ b/src/components/Broadcast/Layout/Layout.tsx
@@ -17,7 +17,7 @@ export function Layout({ headerHeight }: LayoutProps) {
>Timing Board UI
-
+
@@ -33,7 +33,7 @@ export function Layout({ headerHeight }: LayoutProps) {
>Race Director UI
-
+
diff --git a/src/components/BroadcastGraphics/Chyrons/Driver/ChyronDriver.tsx b/src/components/BroadcastGraphics/Chyrons/Driver/ChyronDriver.tsx
index 888442e..b660457 100644
--- a/src/components/BroadcastGraphics/Chyrons/Driver/ChyronDriver.tsx
+++ b/src/components/BroadcastGraphics/Chyrons/Driver/ChyronDriver.tsx
@@ -98,7 +98,7 @@ export function ChyronDriver({
progress,
5,
);
- return `polygon(${coordinates.map(([x, y]) => `${x}px ${y}px`).join(", ")})`;
+ return `polygon(${coordinates.map(([x, y]) => `${x}% ${y}%`).join(", ")})`;
}),
}}
/>
diff --git a/src/components/BroadcastGraphics/Common/WipeTransition/WipeTransition.tsx b/src/components/BroadcastGraphics/Common/WipeTransition/WipeTransition.tsx
index 7f18d94..ac81376 100644
--- a/src/components/BroadcastGraphics/Common/WipeTransition/WipeTransition.tsx
+++ b/src/components/BroadcastGraphics/Common/WipeTransition/WipeTransition.tsx
@@ -64,7 +64,7 @@ export function WipeTransition({
startingCorner,
angle,
);
- return `polygon(${coordinates.map(([x, y]) => `${x}px ${y}px`).join(", ")})`;
+ return `polygon(${coordinates.map(([x, y]) => `${x}% ${y}%`).join(", ")})`;
}),
}}
ref={childRef}
diff --git a/src/components/BroadcastGraphics/TimingBoard/TimingTower/TimingTowerRow.tsx b/src/components/BroadcastGraphics/TimingBoard/TimingTower/TimingTowerRow.tsx
index d8c7772..71ff63a 100644
--- a/src/components/BroadcastGraphics/TimingBoard/TimingTower/TimingTowerRow.tsx
+++ b/src/components/BroadcastGraphics/TimingBoard/TimingTower/TimingTowerRow.tsx
@@ -305,7 +305,7 @@ export function TimingTowerRow({
3,
3,
);
- return `polygon(${coordinates.map(([x, y]) => `${x}px ${y}px`).join(", ")})`;
+ return `polygon(${coordinates.map(([x, y]) => `${x}% ${y}%`).join(", ")})`;
}),
}}
/>
diff --git a/src/utils/styling.ts b/src/utils/styling.ts
index e919523..bbcbcd8 100644
--- a/src/utils/styling.ts
+++ b/src/utils/styling.ts
@@ -1,7 +1,7 @@
import { css }from "styled-components/macro";
import { clamp } from "lodash";
-import { Corner, Fraction, Placement, Px, TransitionArgs } from "../types/style";
+import { Corner, Fraction, Percent, Placement, Px, TransitionArgs } from "../types/style";
import { Seconds } from "../types/util";
export function placementStyleRules(pos: Placement) {
@@ -14,6 +14,21 @@ export function placementStyleRules(pos: Placement) {
}
+/**
+ * Call to create a function that can be re-used to generate a pair of percent
+ * values to use on a clip-path.
+ * This was necessary to deal with double-applied scaling issues when using
+ * element measurement hooks.
+ * @param width the width of the element to be clipped in pixels
+ * @param height the height of the element to be clipped in pixels
+ * @returns A function that can be used to convert pixel values into percent values
+ */
+const clipConvertToPercent = (width: Px, height: Px) =>
+ (coords: [Px, Px]): [Percent, Percent] => [
+ coords[0] / width * 100,
+ coords[1] / height * 100,
+ ];
+
/**
* Provides the x, y coordinates of a three point polygon for use in a clip-path
* mask. By taking a fraction to indicate the progress through the animation it
@@ -23,7 +38,7 @@ export function placementStyleRules(pos: Placement) {
* @param progress fraction from 0 to 1
* @param startingCorner Which corner the wipe originates from
* @param degrees The angle in degrees of the wipe
- * @returns Array of six numbers representing pixel values of the clip-path
+ * @returns Array of three pairs of percentages to the coordinates of the clip-path
*/
export function wipeCustomDegClip(
width: Px,
@@ -31,33 +46,34 @@ export function wipeCustomDegClip(
progress: Fraction,
startingCorner: Corner,
degrees: number,
-): [[Px, Px], [Px, Px], [Px, Px]] {
+): [[Percent, Percent], [Percent, Percent], [Percent, Percent]] {
const tangent = Math.tan(clamp(degrees, 0.01, 90) * Math.PI / 180);
+ const convert = clipConvertToPercent(width, height);
switch (startingCorner) {
case "topLeft":
return [
- [0, 0],
- [(width + height / tangent) * progress, 0],
- [0, (height + width * tangent) * progress ],
+ convert([0, 0]),
+ convert([(width + height / tangent) * progress, 0]),
+ convert([0, (height + width * tangent) * progress ]),
];
case "topRight":
return [
- [width, 0],
- [width, (height + width * tangent) * progress],
- [width - (width + height / tangent) * progress, 0],
+ convert([width, 0]),
+ convert([width, (height + width * tangent) * progress]),
+ convert([width - (width + height / tangent) * progress, 0]),
];
case "bottomRight":
return [
- [width, height],
- [width, height - (height + width * tangent) * progress],
- [width - (width + height / tangent) * progress, height],
+ convert([width, height]),
+ convert([width, height - (height + width * tangent) * progress]),
+ convert([width - (width + height / tangent) * progress, height]),
];
case "bottomLeft":
return [
- [0, height],
- [0, height - (height + width * tangent) * progress],
- [(width + height / tangent) * progress, height],
+ convert([0, height]),
+ convert([0, height - (height + width * tangent) * progress]),
+ convert([(width + height / tangent) * progress, height]),
];
}
}
@@ -114,7 +130,7 @@ export function commonDirectionalTransition(
* @param progress fraction from 0 to 1
* @param outlineThickness the expected max width of the outline
* @param interiorThickness the expected max width of the outline internally
- * @returns
+ * @returns Array of six pairs of percentages to the coordinates of the clip-path
*/
export function outlineClipPath(
width: Px,
@@ -122,45 +138,53 @@ export function outlineClipPath(
progress: Fraction,
outlineThickness: Px,
interiorThickness: Px = 0,
-): [[Px, Px], [Px, Px], [Px, Px], [Px, Px], [Px, Px], [Px, Px]] {
+): [
+ [Percent, Percent],
+ [Percent, Percent],
+ [Percent, Percent],
+ [Percent, Percent],
+ [Percent, Percent],
+ [Percent, Percent],
+] {
const travelDistance = width * 2 + height;
const pt1End = width / travelDistance;
const pt2End = (width + height) / travelDistance;
+ const convert = clipConvertToPercent(width, height);
// Part 1: Reveal the bottom line.
if (progress <= pt1End) {
const x = width * progress / pt1End;
return [
- [0, height - interiorThickness],
- [0, height - interiorThickness],
- [0, height - interiorThickness],
- [x, height - interiorThickness],
- [x, height + outlineThickness],
- [0, height + outlineThickness],
+ convert([0, height - interiorThickness]),
+ convert([0, height - interiorThickness]),
+ convert([0, height - interiorThickness]),
+ convert([x, height - interiorThickness]),
+ convert([x, height + outlineThickness]),
+ convert([0, height + outlineThickness]),
];
// Part 2: Reveal the right line.
} else if (progress > pt1End && progress <= pt2End) {
const y = height - (height + outlineThickness) * ((progress - pt1End) / (pt2End - pt1End));
return [
- [0, height - interiorThickness],
- [width - Math.max(10, interiorThickness), height - interiorThickness],
- [width - interiorThickness, y],
- [width + outlineThickness, y],
- [width + outlineThickness, height + outlineThickness],
- [0, height + outlineThickness],
+ convert([0, height - interiorThickness]),
+ convert([width - Math.max(10, interiorThickness), height - interiorThickness]),
+ convert([width - interiorThickness, y]),
+ convert([width + outlineThickness, y]),
+ convert([width + outlineThickness, height + outlineThickness]),
+ convert([0, height + outlineThickness]),
];
// Part 3: Reveal the top line.
} else {
const x = width - width * ((progress - pt2End) / (1 - pt2End));
return [
- [0, height - interiorThickness],
- [x - Math.max(10, interiorThickness), height - interiorThickness],
- [x - interiorThickness, -outlineThickness],
- [width + outlineThickness, -outlineThickness],
- [width + outlineThickness, height + outlineThickness],
- [0, height + outlineThickness],
+ convert([0, height - interiorThickness]),
+ convert([x - Math.max(10, interiorThickness), height - interiorThickness]),
+ convert([x - interiorThickness, -outlineThickness]),
+ convert([width + outlineThickness, -outlineThickness]),
+ convert([width + outlineThickness, height + outlineThickness]),
+ convert([0, height + outlineThickness]),
];
}
}