Skip to content

Commit 482a128

Browse files
Merge pull request #250 from digma-ai/fix/duration-chart-bar-height
Set minimal bar height
2 parents a4b8e18 + fa62e76 commit 482a128

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/components/Insights/DurationInsight/index.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { DoubleCircleIcon } from "../../common/icons/DoubleCircleIcon";
2121
import { DurationChange, isChangeMeaningfulEnough } from "../DurationChange";
2222
import { InsightCard } from "../InsightCard";
2323
import { Description } from "../styles";
24-
import { HistogramBarData, Trace } from "../types";
24+
import { HistogramBarData, NormalizedHistogramBarData, Trace } from "../types";
2525
import { ReferenceLineLabel } from "./ReferenceLineLabel";
2626
import { XAxisTick } from "./XAxisTick";
2727
import { DIVIDER } from "./constants";
@@ -31,6 +31,8 @@ import { DurationInsightProps, TickData } from "./types";
3131
const LAST_CALL_TIME_DISTANCE_LIMIT = 60 * 1000; // in milliseconds
3232

3333
// in pixels
34+
const MIN_BAR_HEIGHT = 5;
35+
const MAX_BAR_HEIGHT = 80;
3436
const BAR_WIDTH = 5;
3537
const MIN_X_AXIS_PADDING = 80;
3638
const MIN_CHART_CONTAINER_HEIGHT = 120;
@@ -268,6 +270,17 @@ export const DurationInsight = (props: DurationInsightProps) => {
268270
chartContainerHeight += CHART_Y_MARGIN * 2;
269271
}
270272

273+
const maxCount = Math.max(...notEmptyBars.map((x) => x.count));
274+
const normalizedChartData: NormalizedHistogramBarData[] = chartData.map(
275+
(x) => ({
276+
...x,
277+
normalizedCount:
278+
x.count > 0
279+
? Math.max((maxCount / MAX_BAR_HEIGHT) * MIN_BAR_HEIGHT, x.count)
280+
: 0
281+
})
282+
);
283+
271284
return (
272285
<InsightCard
273286
data={props.insight}
@@ -358,14 +371,14 @@ export const DurationInsight = (props: DurationInsightProps) => {
358371
left: 0
359372
}}
360373
barSize={BAR_WIDTH}
361-
data={chartData}
374+
data={normalizedChartData}
362375
>
363376
<Bar
364-
dataKey={"count"}
377+
dataKey={"normalizedCount"}
365378
radius={BAR_WIDTH / 2}
366379
isAnimationActive={false}
367380
>
368-
{chartData.map((entry, index) => (
381+
{normalizedChartData.map((entry, index) => (
369382
<Cell
370383
key={`cell-${index}`}
371384
fill={getBarColor(entry.end, p50, p95)}

src/components/Insights/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ export interface HistogramBarData {
169169
end: Duration;
170170
}
171171

172+
export interface NormalizedHistogramBarData extends HistogramBarData {
173+
normalizedCount: number;
174+
}
175+
172176
export interface SpanDurationsInsight extends SpanInsight {
173177
name: "Performance Stats";
174178
type: InsightType.SpanDurations;

0 commit comments

Comments
 (0)