Skip to content

Commit f15490e

Browse files
committed
get midpoint of max and min instead of half of max number
1 parent 477d0bb commit f15490e

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

x-pack/plugins/infra/public/pages/metrics/inventory_view/components/waffle/stepped_gradient_legend.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface Props {
1616
bounds: InfraWaffleMapBounds;
1717
formatter: InfraFormatter;
1818
}
19-
19+
type TickValue = 0 | 0.5 | 1;
2020
export const SteppedGradientLegend: React.FC<Props> = ({ legend, bounds, formatter }) => {
2121
return (
2222
<LegendContainer>
@@ -39,12 +39,14 @@ export const SteppedGradientLegend: React.FC<Props> = ({ legend, bounds, formatt
3939

4040
interface TickProps {
4141
bounds: InfraWaffleMapBounds;
42-
value: number;
42+
value: TickValue;
4343
formatter: InfraFormatter;
4444
}
4545

4646
const TickLabel = ({ value, bounds, formatter }: TickProps) => {
47-
const normalizedValue = value === 0 ? bounds.min : bounds.max * value;
47+
// if looking for the midpoint (0.5), calculate from min and max bounds
48+
const normalizedValue =
49+
value === 0 ? bounds.min : value === 0.5 ? (bounds.min + bounds.max) / 2 : bounds.max * value;
4850
const style = { left: `${value * 100}%` };
4951
const label = formatter(normalizedValue);
5052
return <Tick style={style}>{label}</Tick>;

0 commit comments

Comments
 (0)