import React from 'react'; import { SvgWrapper, ResponsiveWrapper } from 'app/shared/modules/chart/core'; import percentagePipe from 'app/shared/pipes/percent.pipe'; const PROGRESS_BAR_COLORS = [ '#B5E0F4', '#0073AB', '#4DB5AB', '#D6EAE9', ]; export const SUB_PROGRESS_COLOR = '#E69C56'; export const getProgressBarColor = (index: number) => { return PROGRESS_BAR_COLORS[index % PROGRESS_BAR_COLORS.length]; }; const defaultHeight = 16; const defaultFontSize = 12; const sum = (previousValue, currentValue) => previousValue + currentValue; const scaleValues = (values: number[], scale: number) => { const maxValue = values.reduce(sum, 0); return values.map(value => (value * scale) / maxValue); }; const getPercentages = (values: number[], subValues?: number[]) => { const maxValue = values.reduce(sum, 0); return values.map((value, index) => ({ value: percentagePipe.format(value * 100 / maxValue), position: values.slice(0, index).reduce(sum, 0) + value / 2, subValue: subValues && subValues[index] ? percentagePipe.format(subValues[index]) : undefined, })); }; export interface Props { values: number[]; barKey: string; subProgress?: number[]; } export const ProgressBar = ({ values, barKey, subProgress }: Props) => { return
{(size) => { const pathName = window.location.pathname; const bar: number[] = scaleValues(values, Number(size?.width)); const percentages: { value: string, position: number, subValue: string | undefined }[] = getPercentages(bar, subProgress); // @ts-ignore* return {bar.map((barChunk, index) => { const position = bar.slice(0, index).reduce(sum, 0); return {subProgress && } ; })} {percentages.map((percentage, index) => {percentage.value} {percentage.subValue && {percentage.subValue} } )} ; }}
; };