ISSUE-054 - Have static timing display mostly figured out.
Some subtle scaling was necessary to accomplish the proper spacing.
This commit is contained in:
1 parent
22ebab1101
commit
7507868dce
8 files changed
+134
-45
No files matched your search
@@ -4,6 +4,8 @@ import { broadcastGraphicsSelector } from "../../../../features/broadcast/graphi
|
|||||||
import { eventSelector } from "../../../../features/event/eventSelector";
|
import { eventSelector } from "../../../../features/event/eventSelector";
|
||||||
import { BGTimingTowerModes, Car, CarStatus } from "../../../../types/state";
|
import { BGTimingTowerModes, Car, CarStatus } from "../../../../types/state";
|
||||||
import { orMatch } from "../../../../utils/common";
|
import { orMatch } from "../../../../utils/common";
|
||||||
|
import { timeDiff } from "../../../../utils/event";
|
||||||
|
import { formatTime } from "../../../../utils/styling";
|
||||||
import { PositionFlag } from "../../Common/PositionFlag";
|
import { PositionFlag } from "../../Common/PositionFlag";
|
||||||
import { Spacer } from "../../Common/Spacer.styled";
|
import { Spacer } from "../../Common/Spacer.styled";
|
||||||
|
|
||||||
@@ -15,6 +17,7 @@ import {
|
|||||||
RowRightHalf,
|
RowRightHalf,
|
||||||
RowRightHalfLayout,
|
RowRightHalfLayout,
|
||||||
RowsContainer,
|
RowsContainer,
|
||||||
|
TimeDiff,
|
||||||
} from "./styles";
|
} from "./styles";
|
||||||
|
|
||||||
type TimingTowerProps = {
|
type TimingTowerProps = {
|
||||||
@@ -39,6 +42,8 @@ export function TimingTower({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let forwardCarDistance = -1;
|
||||||
|
|
||||||
const buildRow = (
|
const buildRow = (
|
||||||
car: Car,
|
car: Car,
|
||||||
index: number,
|
index: number,
|
||||||
@@ -46,6 +51,32 @@ export function TimingTower({
|
|||||||
) => {
|
) => {
|
||||||
const lastRow = index + 1 === count;
|
const lastRow = index + 1 === count;
|
||||||
|
|
||||||
|
let leader = false;
|
||||||
|
if (forwardCarDistance === -1) {
|
||||||
|
leader = true;
|
||||||
|
forwardCarDistance = car.distance;
|
||||||
|
}
|
||||||
|
|
||||||
|
let rightHalfContent = "";
|
||||||
|
let xScale = 1.0;
|
||||||
|
if (leader) {
|
||||||
|
rightHalfContent = timingBoard.timingTower.mode === BGTimingTowerModes.Leader
|
||||||
|
? "Leader" : timingBoard.timingTower.mode === BGTimingTowerModes.Interval
|
||||||
|
? "Interval" : "";
|
||||||
|
} else if (car.status === CarStatus.Retired) {
|
||||||
|
rightHalfContent = "OUT";
|
||||||
|
} else {
|
||||||
|
rightHalfContent = `+${formatTime(timeDiff(
|
||||||
|
forwardCarDistance,
|
||||||
|
car.distance,
|
||||||
|
))}`;
|
||||||
|
xScale = rightHalfContent.includes(".") && rightHalfContent.length > 7 ? 0.75 : 0.9;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (timingBoard.timingTower.mode === BGTimingTowerModes.Interval) {
|
||||||
|
forwardCarDistance = car.distance;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RowContainer
|
<RowContainer
|
||||||
key={car.driver.id}
|
key={car.driver.id}
|
||||||
@@ -54,11 +85,13 @@ export function TimingTower({
|
|||||||
wide={timingBoard.timingTower.mode !== BGTimingTowerModes.Minimum}
|
wide={timingBoard.timingTower.mode !== BGTimingTowerModes.Minimum}
|
||||||
>
|
>
|
||||||
<RowLeftHalf
|
<RowLeftHalf
|
||||||
roundedCorner={lastRow && orMatch(
|
roundedCornerBottom={
|
||||||
timingBoard.timingTower.mode,
|
lastRow && orMatch(
|
||||||
BGTimingTowerModes.Minimum,
|
timingBoard.timingTower.mode,
|
||||||
BGTimingTowerModes.FullName,
|
BGTimingTowerModes.Minimum,
|
||||||
)}
|
BGTimingTowerModes.FullName,
|
||||||
|
) ? 5 : undefined
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<RowLeftHalfLayout>
|
<RowLeftHalfLayout>
|
||||||
<Spacer width="3px" />
|
<Spacer width="3px" />
|
||||||
@@ -75,14 +108,22 @@ export function TimingTower({
|
|||||||
</RowLeftHalfLayout>
|
</RowLeftHalfLayout>
|
||||||
</RowLeftHalf>
|
</RowLeftHalf>
|
||||||
<RowRightHalf
|
<RowRightHalf
|
||||||
roundedCorner={lastRow && orMatch(
|
roundedCornerTop={
|
||||||
timingBoard.timingTower.mode,
|
index === 0 && car.status !== CarStatus.Retired
|
||||||
BGTimingTowerModes.Leader,
|
? 5 : undefined
|
||||||
BGTimingTowerModes.Interval,
|
}
|
||||||
)}
|
roundedCornerBottom={
|
||||||
|
lastRow && orMatch(
|
||||||
|
timingBoard.timingTower.mode,
|
||||||
|
BGTimingTowerModes.Leader,
|
||||||
|
BGTimingTowerModes.Interval,
|
||||||
|
) ? 5 : undefined
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<RowRightHalfLayout>
|
<RowRightHalfLayout>
|
||||||
|
<TimeDiff xScale={xScale}>
|
||||||
|
{rightHalfContent}
|
||||||
|
</TimeDiff>
|
||||||
</RowRightHalfLayout>
|
</RowRightHalfLayout>
|
||||||
</RowRightHalf>
|
</RowRightHalf>
|
||||||
</RowContainer>
|
</RowContainer>
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import styled, { css } from "styled-components";
|
import styled, { css } from "styled-components";
|
||||||
|
|
||||||
|
import { Fraction, Px } from "../../../../types/style";
|
||||||
|
|
||||||
export const RowsContainer = styled.div`
|
export const RowsContainer = styled.div`
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
@@ -25,14 +27,18 @@ export const RowContainer = styled.div<RowContainerProps>`
|
|||||||
|
|
||||||
${({ topGap }) => topGap && css`margin-top: 3px;`}
|
${({ topGap }) => topGap && css`margin-top: 3px;`}
|
||||||
${({ bottomGap }) => bottomGap && css`margin-bottom: 3px;`}
|
${({ bottomGap }) => bottomGap && css`margin-bottom: 3px;`}
|
||||||
${({ retired }) => retired && css`opacity: 0.4;`}
|
${({ retired }) => retired && css`opacity: 0.7;`}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
type RoundedProp = {
|
type RoundedProp = {
|
||||||
roundedCorner?: boolean;
|
roundedCornerTop?: Px,
|
||||||
|
roundedCornerBottom?: Px,
|
||||||
};
|
};
|
||||||
const Rounded = styled.div<RoundedProp>`
|
const Rounded = styled.div<RoundedProp>`
|
||||||
${({ roundedCorner }) => roundedCorner && css`border-bottom-right-radius: 5px;`}
|
${({ roundedCornerTop }) =>
|
||||||
|
roundedCornerTop && css`border-top-right-radius: ${roundedCornerTop}px;`}
|
||||||
|
${({ roundedCornerBottom }) =>
|
||||||
|
roundedCornerBottom && css`border-bottom-right-radius: ${roundedCornerBottom}px;`}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const RowLeftHalf = styled(Rounded)`
|
export const RowLeftHalf = styled(Rounded)`
|
||||||
@@ -43,7 +49,7 @@ export const RowLeftHalf = styled(Rounded)`
|
|||||||
width: 147px; // Future will be animated.
|
width: 147px; // Future will be animated.
|
||||||
height: 36px;
|
height: 36px;
|
||||||
|
|
||||||
background-color: #000000cb
|
background-color: #000000e5
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const RowLeftHalfLayout = styled.div`
|
export const RowLeftHalfLayout = styled.div`
|
||||||
@@ -77,6 +83,7 @@ export const RowRightHalfLayout = styled.div`
|
|||||||
|
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
|
padding-right: 8px;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const DriverName = styled.span`
|
export const DriverName = styled.span`
|
||||||
@@ -84,3 +91,18 @@ export const DriverName = styled.span`
|
|||||||
font-family: ${p => p.theme.fonts.f1Bold};
|
font-family: ${p => p.theme.fonts.f1Bold};
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
type TimeDiffProps = {
|
||||||
|
xScale: Fraction,
|
||||||
|
};
|
||||||
|
export const TimeDiff = styled.span<TimeDiffProps>`
|
||||||
|
color: white;
|
||||||
|
font-family: ${p => p.theme.fonts.f1Regular};
|
||||||
|
font-size: 20px;
|
||||||
|
|
||||||
|
text-align: end;
|
||||||
|
|
||||||
|
font-feature-settings: 'tnum' 1;
|
||||||
|
transform-origin: right;
|
||||||
|
transform: scaleX(${({ xScale }) => xScale});
|
||||||
|
`;
|
||||||
@@ -92,8 +92,8 @@ export const workspaces: WorkspaceObject = {
|
|||||||
"timing-board-intervals-yellow-flag.png",
|
"timing-board-intervals-yellow-flag.png",
|
||||||
],
|
],
|
||||||
previewWindowDimensions: {
|
previewWindowDimensions: {
|
||||||
width: 350,
|
width: 700,
|
||||||
height: 820,
|
height: 900,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
timingBoardShort: {
|
timingBoardShort: {
|
||||||
@@ -102,8 +102,8 @@ export const workspaces: WorkspaceObject = {
|
|||||||
"timing-board-portrait-gap.png",
|
"timing-board-portrait-gap.png",
|
||||||
],
|
],
|
||||||
previewWindowDimensions: {
|
previewWindowDimensions: {
|
||||||
width: 350,
|
width: 700,
|
||||||
height: 410,
|
height: 450,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -19,26 +19,26 @@ const initialState: RootState["event"] = {
|
|||||||
lapCount: 10,
|
lapCount: 10,
|
||||||
},
|
},
|
||||||
grid: [
|
grid: [
|
||||||
{ position: 1, status: CarStatus.Normal, driver: cloneDriver("verstappen") },
|
{ position: 1, status: CarStatus.Normal, distance: 2000 * 2, driver: cloneDriver("verstappen") },
|
||||||
{ position: 2, status: CarStatus.Normal, driver: cloneDriver("hamilton") },
|
{ position: 2, status: CarStatus.Normal, distance: 1900 * 2, driver: cloneDriver("hamilton") },
|
||||||
{ position: 3, status: CarStatus.Normal, driver: cloneDriver("bottas") },
|
{ position: 3, status: CarStatus.Normal, distance: 1800 * 2, driver: cloneDriver("bottas") },
|
||||||
{ position: 4, status: CarStatus.Retired, driver: cloneDriver("perez") },
|
{ position: 4, status: CarStatus.Retired, distance: 1700 * 2, driver: cloneDriver("perez") },
|
||||||
{ position: 5, status: CarStatus.Normal, driver: cloneDriver("sainz") },
|
{ position: 5, status: CarStatus.Normal, distance: 1600 * 2, driver: cloneDriver("sainz") },
|
||||||
{ position: 6, status: CarStatus.Retired, driver: cloneDriver("norris") },
|
{ position: 6, status: CarStatus.Retired, distance: 1500 * 2, driver: cloneDriver("norris") },
|
||||||
{ position: 7, status: CarStatus.Normal, driver: cloneDriver("leclerc") },
|
{ position: 7, status: CarStatus.Normal, distance: 1400 * 2, driver: cloneDriver("leclerc") },
|
||||||
{ position: 8, status: CarStatus.Normal, driver: cloneDriver("ricciardo") },
|
{ position: 8, status: CarStatus.Normal, distance: 1300 * 2, driver: cloneDriver("ricciardo") },
|
||||||
{ position: 9, status: CarStatus.Normal, driver: cloneDriver("gasly") },
|
{ position: 9, status: CarStatus.Normal, distance: 1200 * 2, driver: cloneDriver("gasly") },
|
||||||
{ position: 10, status: CarStatus.Normal, driver: cloneDriver("alonso") },
|
{ position: 10, status: CarStatus.Normal, distance: 1100 * 2, driver: cloneDriver("alonso") },
|
||||||
{ position: 11, status: CarStatus.Normal, driver: cloneDriver("ocon") },
|
{ position: 11, status: CarStatus.Normal, distance: 1000 * 2, driver: cloneDriver("ocon") },
|
||||||
{ position: 12, status: CarStatus.Normal, driver: cloneDriver("vettel") },
|
{ position: 12, status: CarStatus.Normal, distance: 900 * 2, driver: cloneDriver("vettel") },
|
||||||
{ position: 13, status: CarStatus.Normal, driver: cloneDriver("stroll") },
|
{ position: 13, status: CarStatus.Normal, distance: 800 * 2, driver: cloneDriver("stroll") },
|
||||||
{ position: 14, status: CarStatus.Normal, driver: cloneDriver("tsunoda") },
|
{ position: 14, status: CarStatus.Normal, distance: 700 * 2, driver: cloneDriver("tsunoda") },
|
||||||
{ position: 15, status: CarStatus.Normal, driver: cloneDriver("russell") },
|
{ position: 15, status: CarStatus.Normal, distance: 600 * 2, driver: cloneDriver("russell") },
|
||||||
{ position: 16, status: CarStatus.Normal, driver: cloneDriver("raikkonen") },
|
{ position: 16, status: CarStatus.Normal, distance: 500 * 2, driver: cloneDriver("raikkonen") },
|
||||||
{ position: 17, status: CarStatus.Normal, driver: cloneDriver("latifi") },
|
{ position: 17, status: CarStatus.Normal, distance: 400 * 2, driver: cloneDriver("latifi") },
|
||||||
{ position: 18, status: CarStatus.Normal, driver: cloneDriver("giovinazzi") },
|
{ position: 18, status: CarStatus.Normal, distance: 300 * 2, driver: cloneDriver("giovinazzi") },
|
||||||
{ position: 19, status: CarStatus.Normal, driver: cloneDriver("schumacher") },
|
{ position: 19, status: CarStatus.Normal, distance: 200 * 2, driver: cloneDriver("schumacher") },
|
||||||
{ position: 20, status: CarStatus.Normal, driver: cloneDriver("mazepin") },
|
{ position: 20, status: CarStatus.Normal, distance: 1, driver: cloneDriver("mazepin") },
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Vendored
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
import { Milliseconds, Optional } from "./util";
|
import { Meters, Milliseconds, Optional } from "./util";
|
||||||
import { Corner, Fraction } from "./style";
|
import { Corner, Fraction } from "./style";
|
||||||
|
|
||||||
export interface RootState {
|
export interface RootState {
|
||||||
@@ -113,7 +113,7 @@ export interface Car {
|
|||||||
status: CarStatus;
|
status: CarStatus;
|
||||||
// flags: ???, // blue, red, meatball, black/white, black
|
// flags: ???, // blue, red, meatball, black/white, black
|
||||||
// notices: ???; // Penalties, warnings, investigations, blue flags, etc
|
// notices: ???; // Penalties, warnings, investigations, blue flags, etc
|
||||||
// distance: number;
|
distance: Meters;
|
||||||
}
|
}
|
||||||
export interface Driver {
|
export interface Driver {
|
||||||
id: DriverId;
|
id: DriverId;
|
||||||
|
|||||||
Vendored
+6
@@ -9,3 +9,9 @@ export type Milliseconds = number;
|
|||||||
* Type to remind you that we're dealing with seconds.
|
* Type to remind you that we're dealing with seconds.
|
||||||
*/
|
*/
|
||||||
export type Seconds = number;
|
export type Seconds = number;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type to remind you that we're dealing with meters.
|
||||||
|
*/
|
||||||
|
export type Meters = number;
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import { random } from "lodash";
|
||||||
|
|
||||||
|
import { Meters } from "../types/util";
|
||||||
|
|
||||||
|
export function timeDiff(
|
||||||
|
front: Meters,
|
||||||
|
back: Meters,
|
||||||
|
) {
|
||||||
|
/**
|
||||||
|
* Spa length in 2020 was 308,052m. Hamilton won it in 1:24:08.761.
|
||||||
|
* That's 3600 + 1440 + 8.761 = 5,048.761 seconds.
|
||||||
|
* 61.015 m/s average. So, let's do that.
|
||||||
|
*/
|
||||||
|
|
||||||
|
return random(0.95, 1.05) * ((front - back) / 61.015);
|
||||||
|
}
|
||||||
@@ -127,9 +127,13 @@ export function outlineClipPath(
|
|||||||
[0, height + outlineThickness],
|
[0, height + outlineThickness],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatTime(time: number) {
|
||||||
// return [
|
if (time < 60) {
|
||||||
|
return String(time.toFixed(3));
|
||||||
// ]
|
}
|
||||||
|
const minutes = Math.floor(time / 60);
|
||||||
|
const seconds = time % 60;
|
||||||
|
return `${minutes}:${String(seconds.toFixed(3)).padStart(6, "0")}`;
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user