From fa62e7637604c59e19dd08c65feee8857c148d73 Mon Sep 17 00:00:00 2001 From: Kyrylo Shmidt Date: Tue, 3 Oct 2023 18:16:23 +0200 Subject: [PATCH] Set minimal bar height --- .../Insights/DurationInsight/index.tsx | 21 +++++++++++++++---- src/components/Insights/types.ts | 4 ++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/components/Insights/DurationInsight/index.tsx b/src/components/Insights/DurationInsight/index.tsx index 31f032fdb..05eb1f5d0 100644 --- a/src/components/Insights/DurationInsight/index.tsx +++ b/src/components/Insights/DurationInsight/index.tsx @@ -21,7 +21,7 @@ import { DoubleCircleIcon } from "../../common/icons/DoubleCircleIcon"; import { DurationChange, isChangeMeaningfulEnough } from "../DurationChange"; import { InsightCard } from "../InsightCard"; import { Description } from "../styles"; -import { HistogramBarData, Trace } from "../types"; +import { HistogramBarData, NormalizedHistogramBarData, Trace } from "../types"; import { ReferenceLineLabel } from "./ReferenceLineLabel"; import { XAxisTick } from "./XAxisTick"; import { DIVIDER } from "./constants"; @@ -31,6 +31,8 @@ import { DurationInsightProps, TickData } from "./types"; const LAST_CALL_TIME_DISTANCE_LIMIT = 60 * 1000; // in milliseconds // in pixels +const MIN_BAR_HEIGHT = 5; +const MAX_BAR_HEIGHT = 80; const BAR_WIDTH = 5; const MIN_X_AXIS_PADDING = 80; const MIN_CHART_CONTAINER_HEIGHT = 120; @@ -268,6 +270,17 @@ export const DurationInsight = (props: DurationInsightProps) => { chartContainerHeight += CHART_Y_MARGIN * 2; } + const maxCount = Math.max(...notEmptyBars.map((x) => x.count)); + const normalizedChartData: NormalizedHistogramBarData[] = chartData.map( + (x) => ({ + ...x, + normalizedCount: + x.count > 0 + ? Math.max((maxCount / MAX_BAR_HEIGHT) * MIN_BAR_HEIGHT, x.count) + : 0 + }) + ); + return ( { left: 0 }} barSize={BAR_WIDTH} - data={chartData} + data={normalizedChartData} > - {chartData.map((entry, index) => ( + {normalizedChartData.map((entry, index) => (