Create "%" strings inside Bar component
This commit is contained in:
parent
c76cfc3bfe
commit
45c5d1a257
|
|
@ -2,8 +2,10 @@ import styled from "styled-components";
|
|||
import { ZoneIndex } from "make-workout";
|
||||
|
||||
export type BarProps = {
|
||||
width: string;
|
||||
height: string;
|
||||
// Percentage of total workout length
|
||||
durationPercentage: number;
|
||||
// Percentage of maximum intensity in workout
|
||||
intensityPercentage: number;
|
||||
zone: ZoneIndex;
|
||||
};
|
||||
|
||||
|
|
@ -19,10 +21,11 @@ const zoneColorsMap: Record<ZoneIndex, string> = {
|
|||
export const Bar = styled.div<BarProps>`
|
||||
display: inline-block;
|
||||
border-radius: 10px;
|
||||
margin-right: 0.1%;
|
||||
vertical-align: bottom;
|
||||
height: ${(props) => props.height};
|
||||
margin-right: 0.1%;
|
||||
/* exclude 0.1% margin from bar width */
|
||||
width: ${(props) => props.durationPercentage - 0.1}%;
|
||||
height: ${(props) => props.intensityPercentage}%;
|
||||
background: ${(props) => zoneColorsMap[props.zone]};
|
||||
width: ${(props) => props.width};
|
||||
transition: width 0.1s, height 0.1s, background-color 0.1s;
|
||||
`;
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ import { BarProps, Bar } from "./Bar";
|
|||
|
||||
const toBarProps = (interval: Interval, workoutDuration: Duration, maxIntensity: Intensity): BarProps => ({
|
||||
zone: intensityToZoneIndex(interval.intensity),
|
||||
width: `${interval.duration.seconds / workoutDuration.seconds * 100 - 0.1}%`,
|
||||
height: `${interval.intensity.value / maxIntensity.value * 100}%`,
|
||||
durationPercentage: interval.duration.seconds / workoutDuration.seconds * 100,
|
||||
intensityPercentage: interval.intensity.value / maxIntensity.value * 100,
|
||||
});
|
||||
|
||||
const Plot = styled.div`
|
||||
|
|
|
|||
Loading…
Reference in New Issue