ISSUE-053 - To avoid messing with code that already works I dropped in a function-function that will convert pixel values to percent values. This fix adds a little bit of overhead, I guess, but it works without munging up any clean looking code.
This commit is contained in:
1 parent
b48579ac54
commit
a11f5b8eb6
5 files changed
+64
-40
No files matched your search
@@ -17,7 +17,7 @@ export function Layout({ headerHeight }: LayoutProps) {
|
|||||||
>Timing Board UI</MockupBlock>
|
>Timing Board UI</MockupBlock>
|
||||||
</LayoutGridItem>
|
</LayoutGridItem>
|
||||||
|
|
||||||
<LayoutGridItem column={2} row={1} columnSpan={5} rowSpan={6} >
|
<LayoutGridItem column={2} row={1} columnSpan={5} rowSpan={7} >
|
||||||
<VideoFeed />
|
<VideoFeed />
|
||||||
</LayoutGridItem>
|
</LayoutGridItem>
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ export function Layout({ headerHeight }: LayoutProps) {
|
|||||||
>Race Director UI</MockupBlock>
|
>Race Director UI</MockupBlock>
|
||||||
</LayoutGridItem>
|
</LayoutGridItem>
|
||||||
|
|
||||||
<LayoutGridItem column={2} row={7} columnSpan={5} rowSpan={4}>
|
<LayoutGridItem column={2} row={8} columnSpan={5} rowSpan={3}>
|
||||||
<TimingTowerPrototypeControls />
|
<TimingTowerPrototypeControls />
|
||||||
</LayoutGridItem>
|
</LayoutGridItem>
|
||||||
</LayoutGrid>
|
</LayoutGrid>
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ export function ChyronDriver({
|
|||||||
progress,
|
progress,
|
||||||
5,
|
5,
|
||||||
);
|
);
|
||||||
return `polygon(${coordinates.map(([x, y]) => `${x}px ${y}px`).join(", ")})`;
|
return `polygon(${coordinates.map(([x, y]) => `${x}% ${y}%`).join(", ")})`;
|
||||||
}),
|
}),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ export function WipeTransition({
|
|||||||
startingCorner,
|
startingCorner,
|
||||||
angle,
|
angle,
|
||||||
);
|
);
|
||||||
return `polygon(${coordinates.map(([x, y]) => `${x}px ${y}px`).join(", ")})`;
|
return `polygon(${coordinates.map(([x, y]) => `${x}% ${y}%`).join(", ")})`;
|
||||||
}),
|
}),
|
||||||
}}
|
}}
|
||||||
ref={childRef}
|
ref={childRef}
|
||||||
|
|||||||
@@ -305,7 +305,7 @@ export function TimingTowerRow({
|
|||||||
3,
|
3,
|
||||||
3,
|
3,
|
||||||
);
|
);
|
||||||
return `polygon(${coordinates.map(([x, y]) => `${x}px ${y}px`).join(", ")})`;
|
return `polygon(${coordinates.map(([x, y]) => `${x}% ${y}%`).join(", ")})`;
|
||||||
}),
|
}),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
+59
-35
@@ -1,7 +1,7 @@
|
|||||||
import { css }from "styled-components/macro";
|
import { css }from "styled-components/macro";
|
||||||
import { clamp } from "lodash";
|
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";
|
import { Seconds } from "../types/util";
|
||||||
|
|
||||||
export function placementStyleRules(pos: Placement) {
|
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
|
* 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
|
* 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 progress fraction from 0 to 1
|
||||||
* @param startingCorner Which corner the wipe originates from
|
* @param startingCorner Which corner the wipe originates from
|
||||||
* @param degrees The angle in degrees of the wipe
|
* @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(
|
export function wipeCustomDegClip(
|
||||||
width: Px,
|
width: Px,
|
||||||
@@ -31,33 +46,34 @@ export function wipeCustomDegClip(
|
|||||||
progress: Fraction,
|
progress: Fraction,
|
||||||
startingCorner: Corner,
|
startingCorner: Corner,
|
||||||
degrees: number,
|
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 tangent = Math.tan(clamp(degrees, 0.01, 90) * Math.PI / 180);
|
||||||
|
const convert = clipConvertToPercent(width, height);
|
||||||
|
|
||||||
switch (startingCorner) {
|
switch (startingCorner) {
|
||||||
case "topLeft":
|
case "topLeft":
|
||||||
return [
|
return [
|
||||||
[0, 0],
|
convert([0, 0]),
|
||||||
[(width + height / tangent) * progress, 0],
|
convert([(width + height / tangent) * progress, 0]),
|
||||||
[0, (height + width * tangent) * progress ],
|
convert([0, (height + width * tangent) * progress ]),
|
||||||
];
|
];
|
||||||
case "topRight":
|
case "topRight":
|
||||||
return [
|
return [
|
||||||
[width, 0],
|
convert([width, 0]),
|
||||||
[width, (height + width * tangent) * progress],
|
convert([width, (height + width * tangent) * progress]),
|
||||||
[width - (width + height / tangent) * progress, 0],
|
convert([width - (width + height / tangent) * progress, 0]),
|
||||||
];
|
];
|
||||||
case "bottomRight":
|
case "bottomRight":
|
||||||
return [
|
return [
|
||||||
[width, height],
|
convert([width, height]),
|
||||||
[width, height - (height + width * tangent) * progress],
|
convert([width, height - (height + width * tangent) * progress]),
|
||||||
[width - (width + height / tangent) * progress, height],
|
convert([width - (width + height / tangent) * progress, height]),
|
||||||
];
|
];
|
||||||
case "bottomLeft":
|
case "bottomLeft":
|
||||||
return [
|
return [
|
||||||
[0, height],
|
convert([0, height]),
|
||||||
[0, height - (height + width * tangent) * progress],
|
convert([0, height - (height + width * tangent) * progress]),
|
||||||
[(width + height / tangent) * progress, height],
|
convert([(width + height / tangent) * progress, height]),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -114,7 +130,7 @@ export function commonDirectionalTransition(
|
|||||||
* @param progress fraction from 0 to 1
|
* @param progress fraction from 0 to 1
|
||||||
* @param outlineThickness the expected max width of the outline
|
* @param outlineThickness the expected max width of the outline
|
||||||
* @param interiorThickness the expected max width of the outline internally
|
* @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(
|
export function outlineClipPath(
|
||||||
width: Px,
|
width: Px,
|
||||||
@@ -122,45 +138,53 @@ export function outlineClipPath(
|
|||||||
progress: Fraction,
|
progress: Fraction,
|
||||||
outlineThickness: Px,
|
outlineThickness: Px,
|
||||||
interiorThickness: Px = 0,
|
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 travelDistance = width * 2 + height;
|
||||||
const pt1End = width / travelDistance;
|
const pt1End = width / travelDistance;
|
||||||
const pt2End = (width + height) / travelDistance;
|
const pt2End = (width + height) / travelDistance;
|
||||||
|
const convert = clipConvertToPercent(width, height);
|
||||||
|
|
||||||
// Part 1: Reveal the bottom line.
|
// Part 1: Reveal the bottom line.
|
||||||
if (progress <= pt1End) {
|
if (progress <= pt1End) {
|
||||||
const x = width * progress / pt1End;
|
const x = width * progress / pt1End;
|
||||||
return [
|
return [
|
||||||
[0, height - interiorThickness],
|
convert([0, height - interiorThickness]),
|
||||||
[0, height - interiorThickness],
|
convert([0, height - interiorThickness]),
|
||||||
[0, height - interiorThickness],
|
convert([0, height - interiorThickness]),
|
||||||
[x, height - interiorThickness],
|
convert([x, height - interiorThickness]),
|
||||||
[x, height + outlineThickness],
|
convert([x, height + outlineThickness]),
|
||||||
[0, height + outlineThickness],
|
convert([0, height + outlineThickness]),
|
||||||
];
|
];
|
||||||
|
|
||||||
// Part 2: Reveal the right line.
|
// Part 2: Reveal the right line.
|
||||||
} else if (progress > pt1End && progress <= pt2End) {
|
} else if (progress > pt1End && progress <= pt2End) {
|
||||||
const y = height - (height + outlineThickness) * ((progress - pt1End) / (pt2End - pt1End));
|
const y = height - (height + outlineThickness) * ((progress - pt1End) / (pt2End - pt1End));
|
||||||
return [
|
return [
|
||||||
[0, height - interiorThickness],
|
convert([0, height - interiorThickness]),
|
||||||
[width - Math.max(10, interiorThickness), height - interiorThickness],
|
convert([width - Math.max(10, interiorThickness), height - interiorThickness]),
|
||||||
[width - interiorThickness, y],
|
convert([width - interiorThickness, y]),
|
||||||
[width + outlineThickness, y],
|
convert([width + outlineThickness, y]),
|
||||||
[width + outlineThickness, height + outlineThickness],
|
convert([width + outlineThickness, height + outlineThickness]),
|
||||||
[0, height + outlineThickness],
|
convert([0, height + outlineThickness]),
|
||||||
];
|
];
|
||||||
|
|
||||||
// Part 3: Reveal the top line.
|
// Part 3: Reveal the top line.
|
||||||
} else {
|
} else {
|
||||||
const x = width - width * ((progress - pt2End) / (1 - pt2End));
|
const x = width - width * ((progress - pt2End) / (1 - pt2End));
|
||||||
return [
|
return [
|
||||||
[0, height - interiorThickness],
|
convert([0, height - interiorThickness]),
|
||||||
[x - Math.max(10, interiorThickness), height - interiorThickness],
|
convert([x - Math.max(10, interiorThickness), height - interiorThickness]),
|
||||||
[x - interiorThickness, -outlineThickness],
|
convert([x - interiorThickness, -outlineThickness]),
|
||||||
[width + outlineThickness, -outlineThickness],
|
convert([width + outlineThickness, -outlineThickness]),
|
||||||
[width + outlineThickness, height + outlineThickness],
|
convert([width + outlineThickness, height + outlineThickness]),
|
||||||
[0, height + outlineThickness],
|
convert([0, height + outlineThickness]),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user