35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
|
import ProjectTimeUnit from "./ProjectTimeUnit";
|
||
|
import { getRoundUpEstimations } from "../types/params";
|
||
|
import { Project } from "../types/project";
|
||
|
import React, { Fragment,FunctionComponent } from "react";
|
||
|
import { Estimation } from "../hooks/useProjectEstimations";
|
||
|
|
||
|
export interface EstimationRangeProps {
|
||
|
project: Project,
|
||
|
estimation: Estimation
|
||
|
}
|
||
|
|
||
|
export const EstimationRange: FunctionComponent<EstimationRangeProps> = ({ project, estimation }) => {
|
||
|
const roundUp = getRoundUpEstimations(project);
|
||
|
let e: number|string = estimation.e;
|
||
|
let sd: number|string = estimation.sd;
|
||
|
let max = e+sd;
|
||
|
let min = Math.max(e-sd, 0);
|
||
|
if (roundUp) {
|
||
|
sd = Math.ceil(sd);
|
||
|
e = Math.ceil(e);
|
||
|
max = Math.ceil(max);
|
||
|
min = Math.ceil(min);
|
||
|
} else {
|
||
|
sd = sd.toFixed(2);
|
||
|
e = e.toFixed(2);
|
||
|
}
|
||
|
return (
|
||
|
<Fragment>
|
||
|
<abbr title={`max: ${max.toFixed(2)}, min: ${min.toFixed(2)}`}>{`${e} ± ${sd}`}</abbr> <ProjectTimeUnit project={project} />
|
||
|
</Fragment>
|
||
|
|
||
|
);
|
||
|
}
|
||
|
|
||
|
export default EstimationRange;
|