ISSUE-057 - Added outline effect to position changes left half side.

Refactored outlineClipPath() to support outlines that have been offset to be inside.
Added animation duration configuration to the TimingBoard workspace.
This commit is contained in:
Kyle Geib committed 2022-03-03 15:38:59 -05:00
1 parent e88bd614d3
commit cdf8d2b332
7 files changed
+127 -28

No files matched your search

@@ -1,3 +0,0 @@
import styled from "styled-components";
export const Foo = styled.div``;
@@ -1,9 +1,14 @@
import { useSelector } from "react-redux";
import { workspaceSelector } from "../../../features/workspace/workspaceSelector";
import { theme } from "../../../shared/theme"; import { theme } from "../../../shared/theme";
import { MockupBlock } from "../../Common/MockupBlock.styled";
import { TimingBoardLayout } from "./styles"; import { TimingBoardLayout } from "./styles";
import { MockupBlock } from "../../Common/MockupBlock.styled";
import { TimingTower } from "./TimingTower"; import { TimingTower } from "./TimingTower";
export function TimingBoard() { export function TimingBoard() {
const { debugDurationMultiplier } = useSelector(workspaceSelector);
return ( return (
<TimingBoardLayout> <TimingBoardLayout>
<MockupBlock <MockupBlock
@@ -11,7 +16,9 @@ export function TimingBoard() {
width={`${theme.design.timingTower.rowLeftHalfWidthPx}px`} width={`${theme.design.timingTower.rowLeftHalfWidthPx}px`}
color="black" color="black"
/> />
<TimingTower /> <TimingTower
debugDurationMultiplier={debugDurationMultiplier}
/>
</TimingBoardLayout> </TimingBoardLayout>
); );
} }
@@ -4,11 +4,16 @@ import { useSelector } from "react-redux";
import { broadcastGraphicsSelector } from "../../../../features/broadcast/graphics/broadcastGraphicsSelector"; import { broadcastGraphicsSelector } from "../../../../features/broadcast/graphics/broadcastGraphicsSelector";
import { eventSelector } from "../../../../features/event/eventSelector"; import { eventSelector } from "../../../../features/event/eventSelector";
import { CarStatus } from "../../../../types/state"; import { CarStatus } from "../../../../types/state";
import { Fraction } from "../../../../types/style";
import { RowsContainer } from "./styles"; import { RowsContainer } from "./styles";
import { TimingTowerRow } from "./TimingTowerRow"; import { TimingTowerRow } from "./TimingTowerRow";
export function TimingTower() { type TimingTowerProps = {
debugDurationMultiplier?: Fraction,
};
export function TimingTower({ debugDurationMultiplier: DDM }: TimingTowerProps) {
const { lastUpdate, grid, trackLength } = useSelector(eventSelector); const { lastUpdate, grid, trackLength } = useSelector(eventSelector);
const { timingBoard: { timingTower: { splitsMode, displayMode } } } = useSelector( const { timingBoard: { timingTower: { splitsMode, displayMode } } } = useSelector(
broadcastGraphicsSelector, broadcastGraphicsSelector,
@@ -41,6 +46,7 @@ export function TimingTower() {
splitsMode={splitsMode} splitsMode={splitsMode}
displayMode={displayMode} displayMode={displayMode}
trackLength={trackLength} trackLength={trackLength}
debugDurationMultiplier={DDM}
/>)); />));
}, [lastUpdate, splitsMode]); }, [lastUpdate, splitsMode]);
@@ -1,10 +1,11 @@
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import useTimeoutWhen from "@rooks/use-timeout-when"; import useTimeoutWhen from "@rooks/use-timeout-when";
import { useSpring } from "@react-spring/web";
import { theme } from "../../../../shared/theme"; import { theme } from "../../../../shared/theme";
import { orMatch } from "../../../../utils/common"; import { orMatch } from "../../../../utils/common";
import { getCarAtPos, timeDiff } from "../../../../utils/event"; import { getCarAtPos, timeDiff } from "../../../../utils/event";
import { formatTime } from "../../../../utils/styling"; import { formatTime, outlineClipPath } from "../../../../utils/styling";
import { Fraction } from "../../../../types/style"; import { Fraction } from "../../../../types/style";
import { Meters, Milliseconds } from "../../../../types/util"; import { Meters, Milliseconds } from "../../../../types/util";
@@ -32,10 +33,13 @@ import {
RowRightHalfLayout, RowRightHalfLayout,
TimeDiff, TimeDiff,
RowLeftHalfPosFlagChangeContainer, RowLeftHalfPosFlagChangeContainer,
AnimatedRowLeftHalfOutline,
} from "./styles"; } from "./styles";
import useMeasure from "react-use-measure";
const WIPE_DELAY: Milliseconds = 3500; const WIPE_DELAY: Milliseconds = 3500;
const WIPE_DURATION: Milliseconds = 400; const WIPE_DURATION: Milliseconds = 400;
const TRAVEL_DURATION: Milliseconds = 750;
interface TimingTowerRowProps { interface TimingTowerRowProps {
car: Car; car: Car;
@@ -45,6 +49,7 @@ interface TimingTowerRowProps {
splitsMode: BGTimingTowerSplitsMode; splitsMode: BGTimingTowerSplitsMode;
displayMode: BGTimingTowerDisplayMode; displayMode: BGTimingTowerDisplayMode;
trackLength: Meters; trackLength: Meters;
debugDurationMultiplier?: Fraction,
} }
export function TimingTowerRow({ export function TimingTowerRow({
car, car,
@@ -54,26 +59,41 @@ export function TimingTowerRow({
splitsMode, splitsMode,
displayMode, displayMode,
trackLength, trackLength,
debugDurationMultiplier: DDM = 1.0,
}: TimingTowerRowProps) { }: TimingTowerRowProps) {
const [pastPos, setPastPos] = useState(car.position); const [pastPos, setPastPos] = useState(car.position);
const [posChange, setPosChange] = useState(0); const [posChange, setPosChange] = useState(0);
// Using timeouts and boolean states I can manipulate visiblity of the position // Using timeouts and boolean states I can manipulate visiblity of the position
// change effects. wipeVisible is true for only 1ms before being switched back off. // change effects. wipeVisible is true for only 1ms before being switched back off.
const [showChange, setShowChange] = useState(false); const [showPosChange, setshowPosChange] = useState(false);
const [showOutline, setShowOutline] = useState(false);
const [wipeVisible, setWipeVisible] = useState(false); const [wipeVisible, setWipeVisible] = useState(false);
useTimeoutWhen(() => setShowChange(false), WIPE_DELAY + WIPE_DURATION, showChange); useTimeoutWhen(() => setshowPosChange(false), (WIPE_DELAY + WIPE_DURATION) * DDM, showPosChange);
useTimeoutWhen(() => setShowOutline(false), TRAVEL_DURATION * DDM, showOutline);
useTimeoutWhen(() => setWipeVisible(false), 1, wipeVisible); useTimeoutWhen(() => setWipeVisible(false), 1, wipeVisible);
useEffect(() => { useEffect(() => {
if (car.position !== pastPos) { if (car.position !== pastPos) {
setPastPos(car.position); setPastPos(car.position);
setPosChange(pastPos - car.position); setPosChange(pastPos - car.position);
setShowChange(true); setshowPosChange(true);
setShowOutline(true);
setWipeVisible(true); setWipeVisible(true);
} }
}, [car.position]); }, [car.position]);
const { outlineClipPathProgress } = useSpring({
outlineClipPathProgress: showPosChange ? 1 : 0,
config: { duration: 333 * DDM },
delay: 0 * DDM,
});
const [leftHalfRef, {
height: leftHalfHeight,
width: leftHalfWidth,
}] = useMeasure();
const bottomRounded = car.status === CarStatus.Retired ? ( const bottomRounded = car.status === CarStatus.Retired ? (
car.position === startingCarsCount car.position === startingCarsCount
) : ( ) : (
@@ -113,7 +133,7 @@ export function TimingTowerRow({
retired={car.status === CarStatus.Retired} retired={car.status === CarStatus.Retired}
wide={displayMode !== BGTimingTowerDisplayMode.LeftOnly} wide={displayMode !== BGTimingTowerDisplayMode.LeftOnly}
top={(car.position - 1) * theme.design.timingTower.rowHeightPx} top={(car.position - 1) * theme.design.timingTower.rowHeightPx}
transitionTime={750} transitionTime={TRAVEL_DURATION * DDM}
> >
{car.notices.includes(CarNotice.FastestLap) && ( {car.notices.includes(CarNotice.FastestLap) && (
<FastestLapGem /> <FastestLapGem />
@@ -126,6 +146,8 @@ export function TimingTowerRow({
BGTimingTowerDisplayMode.FullLeft, BGTimingTowerDisplayMode.FullLeft,
) ? 5 : undefined ) ? 5 : undefined
} }
transitionTime={TRAVEL_DURATION * DDM}
ref={leftHalfRef}
> >
<RowLeftHalfLayout> <RowLeftHalfLayout>
{car.status !== CarStatus.Retired && ( {car.status !== CarStatus.Retired && (
@@ -137,15 +159,15 @@ export function TimingTowerRow({
/> />
<RowLeftHalfPosFlagChangeContainer <RowLeftHalfPosFlagChangeContainer
size={32} size={32}
visible={showChange} visible={showPosChange}
transitionTime={167} transitionTime={167 * DDM}
> >
{showChange && ( {showPosChange && (
<WipeTransition <WipeTransition
visible={wipeVisible} visible={wipeVisible}
delay={WIPE_DELAY} delay={WIPE_DELAY * DDM}
angle={45} angle={45}
duration={WIPE_DURATION} duration={WIPE_DURATION * DDM}
startingCorner="topLeft" startingCorner="topLeft"
> >
<PositionFlag <PositionFlag
@@ -170,7 +192,36 @@ export function TimingTowerRow({
<RowLeftHalfGemContainer> <RowLeftHalfGemContainer>
<TeamGem team={car.driver.team.id} height={30} /> <TeamGem team={car.driver.team.id} height={30} />
</RowLeftHalfGemContainer> </RowLeftHalfGemContainer>
<AnimatedRowLeftHalfOutline
open={showOutline}
startThickness={1.5}
endThickness={1.5}
startColor={posChange > 0
? theme.colors.posGainedGreen
: theme.colors.posLostRed}
endColor={posChange > 0
? theme.colors.posGainedGreen
: theme.colors.posLostRed}
transitionProps={[{
property: "opacity",
duration: 333 * DDM,
}]}
style={{
clipPath: outlineClipPathProgress.to(progress => {
const coordinates = outlineClipPath(
leftHalfWidth,
leftHalfHeight,
progress,
3,
3,
);
return `polygon(${coordinates.map(([x, y]) => `${x}px ${y}px`).join(", ")})`;
}),
}}
/>
</RowLeftHalf> </RowLeftHalf>
<RowRightHalf <RowRightHalf
roundedCornerTop={car.position === 1 ? 5 : undefined} roundedCornerTop={car.position === 1 ? 5 : undefined}
roundedCornerBottom={ roundedCornerBottom={
@@ -180,6 +231,7 @@ export function TimingTowerRow({
BGTimingTowerSplitsMode.Interval, BGTimingTowerSplitsMode.Interval,
) ? 5 : undefined ) ? 5 : undefined
} }
transitionTime={TRAVEL_DURATION * DDM}
> >
<RowRightHalfLayout> <RowRightHalfLayout>
<TimeDiff xScale={xScale} yScale={yScale}> <TimeDiff xScale={xScale} yScale={yScale}>
@@ -1,11 +1,20 @@
import styled, { css } from "styled-components"; import styled, { css } from "styled-components";
import { animated } from "@react-spring/web"; import { animated } from "@react-spring/web";
import { Fraction, Px } from "../../../../types/style"; import { Fraction, Px, TransitionArgs } from "../../../../types/style";
import { Milliseconds } from "../../../../types/util"; import { Milliseconds } from "../../../../types/util";
import { commonTransition } from "../../../../utils/styling";
import fastestLapIcon from "../../../../public/images/icons/fastest-lap.svg"; import fastestLapIcon from "../../../../public/images/icons/fastest-lap.svg";
type OpenProps = {
open: boolean,
};
type TransitionProps = OpenProps & {
transitionProps: TransitionArgs[],
};
type RowsContainerProps = { type RowsContainerProps = {
carsToDisplay: number, carsToDisplay: number,
retiredCarsPresent: boolean, retiredCarsPresent: boolean,
@@ -52,13 +61,15 @@ AnimatedRowContainer.displayName = "AnimatedRowContainer";
type RoundedProp = { type RoundedProp = {
roundedCornerTop?: Px, roundedCornerTop?: Px,
roundedCornerBottom?: Px, roundedCornerBottom?: Px,
transitionTime: Milliseconds,
}; };
const Rounded = styled.div<RoundedProp>` const Rounded = styled.div<RoundedProp>`
${({ roundedCornerTop }) => ${({ roundedCornerTop }) =>
roundedCornerTop && css`border-top-right-radius: ${roundedCornerTop}px;`} roundedCornerTop && css`border-top-right-radius: ${roundedCornerTop}px;`}
${({ roundedCornerBottom }) => ${({ roundedCornerBottom }) =>
roundedCornerBottom && css`border-bottom-right-radius: ${roundedCornerBottom}px;`} roundedCornerBottom && css`border-bottom-right-radius: ${roundedCornerBottom}px;`}
transition: border-top-right-radius 500ms, border-bottom-right-radius 500ms; transition: border-top-right-radius ${({ transitionTime }) => transitionTime}ms,
border-bottom-right-radius ${({ transitionTime }) => transitionTime}ms;
`; `;
export const RowLeftHalf = styled(Rounded)` export const RowLeftHalf = styled(Rounded)`
@@ -73,6 +84,29 @@ export const RowLeftHalf = styled(Rounded)`
`; `;
RowLeftHalf.displayName = "RowLeftHalf"; RowLeftHalf.displayName = "RowLeftHalf";
type AnimatedRowLeftHalfOutlineProps = TransitionProps & {
startThickness: Px,
endThickness: Px,
startColor: string,
endColor: string,
};
export const AnimatedRowLeftHalfOutline = animated(styled(Rounded) <AnimatedRowLeftHalfOutlineProps>`
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: ${({ open }) => open ? 1 : 0};
outline: ${({ open, startThickness, endThickness, startColor, endColor }) => open
? `${endThickness}px solid ${endColor}`
: `${startThickness}px solid ${startColor}`};
outline-offset: ${({ startThickness }) => -startThickness}px;
${({ transitionProps }) => commonTransition(transitionProps)}
`);
AnimatedRowLeftHalfOutline.displayName = "AnimatedRowLeftHalfOutline";
export const RowLeftHalfLayout = styled.div` export const RowLeftHalfLayout = styled.div`
position: relative; position: relative;
width: 100%; width: 100%;
@@ -97,6 +97,7 @@ export default function Workspaces() {
previewContent={<TimingBoard />} previewContent={<TimingBoard />}
prototypeControls={<TimingTowerPrototypeControls />} prototypeControls={<TimingTowerPrototypeControls />}
bleedover={500} bleedover={500}
showAnimationSpeedSelector
/> />
} /> } />
<Route path="*" element={<IndexHeading>Unknown Workspace</IndexHeading>} /> <Route path="*" element={<IndexHeading>Unknown Workspace</IndexHeading>} />
+12 -10
View File
@@ -80,6 +80,7 @@ export function commonTransition(propsArray: TransitionArgs[]) {
* @param height element height in pixels * @param height element height in pixels
* @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
* @returns * @returns
*/ */
export function outlineClipPath( export function outlineClipPath(
@@ -87,6 +88,7 @@ export function outlineClipPath(
height: Px, height: Px,
progress: Fraction, progress: Fraction,
outlineThickness: Px, outlineThickness: Px,
interiorThickness: Px = 0,
): [[Px, Px], [Px, Px], [Px, Px], [Px, Px], [Px, Px], [Px, Px]] { ): [[Px, Px], [Px, Px], [Px, Px], [Px, Px], [Px, Px], [Px, Px]] {
const travelDistance = width * 2 + height; const travelDistance = width * 2 + height;
const pt1End = width / travelDistance; const pt1End = width / travelDistance;
@@ -96,10 +98,10 @@ export function outlineClipPath(
if (progress <= pt1End) { if (progress <= pt1End) {
const x = width * progress / pt1End; const x = width * progress / pt1End;
return [ return [
[0, height], [0, height - interiorThickness],
[0, height], [0, height - interiorThickness],
[0, height], [0, height - interiorThickness],
[x, height], [x, height - interiorThickness],
[x, height + outlineThickness], [x, height + outlineThickness],
[0, height + outlineThickness], [0, height + outlineThickness],
]; ];
@@ -108,9 +110,9 @@ export function outlineClipPath(
} 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], [0, height - interiorThickness],
[width - 10, height], [width - Math.max(10, interiorThickness), height - interiorThickness],
[width, y], [width - interiorThickness, y],
[width + outlineThickness, y], [width + outlineThickness, y],
[width + outlineThickness, height + outlineThickness], [width + outlineThickness, height + outlineThickness],
[0, height + outlineThickness], [0, height + outlineThickness],
@@ -120,9 +122,9 @@ export function outlineClipPath(
} else { } else {
const x = width - width * ((progress - pt2End) / (1 - pt2End)); const x = width - width * ((progress - pt2End) / (1 - pt2End));
return [ return [
[0, height], [0, height - interiorThickness],
[x - 10, height], [x - Math.max(10, interiorThickness), height - interiorThickness],
[x, -outlineThickness], [x - interiorThickness, -outlineThickness],
[width + outlineThickness, -outlineThickness], [width + outlineThickness, -outlineThickness],
[width + outlineThickness, height + outlineThickness], [width + outlineThickness, height + outlineThickness],
[0, height + outlineThickness], [0, height + outlineThickness],