Skip to content

Commit f687709

Browse files
[Metrics UI] remove middle number in legend and adjust calculation of max number (#89020) (#89893)
* get midpoint of max and min instead of half of max number * remove middle tick from stepped gradient legend * use value instead of max values to calculate bounds Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
1 parent 7e19db9 commit f687709

File tree

3 files changed

+10
-17
lines changed

3 files changed

+10
-17
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@ interface Props {
1616
bounds: InfraWaffleMapBounds;
1717
formatter: InfraFormatter;
1818
}
19-
19+
type TickValue = 0 | 1;
2020
export const SteppedGradientLegend: React.FC<Props> = ({ legend, bounds, formatter }) => {
2121
return (
2222
<LegendContainer>
2323
<Ticks>
2424
<TickLabel value={0} bounds={bounds} formatter={formatter} />
25-
<TickLabel value={0.5} bounds={bounds} formatter={formatter} />
2625
<TickLabel value={1} bounds={bounds} formatter={formatter} />
2726
</Ticks>
2827
<GradientContainer>
@@ -39,7 +38,7 @@ export const SteppedGradientLegend: React.FC<Props> = ({ legend, bounds, formatt
3938

4039
interface TickProps {
4140
bounds: InfraWaffleMapBounds;
42-
value: number;
41+
value: TickValue;
4342
formatter: InfraFormatter;
4443
}
4544

x-pack/plugins/infra/public/pages/metrics/inventory_view/lib/calculate_bounds_from_nodes.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ describe('calculateBoundsFromNodes', () => {
3737
const bounds = calculateBoundsFromNodes(nodes);
3838
expect(bounds).toEqual({
3939
min: 0.2,
40-
max: 1.5,
40+
max: 0.5,
4141
});
4242
});
4343
it('should have a minimum of 0 for only a single node', () => {
4444
const bounds = calculateBoundsFromNodes([nodes[0]]);
4545
expect(bounds).toEqual({
4646
min: 0,
47-
max: 1.5,
47+
max: 0.5,
4848
});
4949
});
5050
it('should return zero for empty nodes', () => {

x-pack/plugins/infra/public/pages/metrics/inventory_view/lib/calculate_bounds_from_nodes.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,17 @@ import { SnapshotNode } from '../../../../../common/http_api/snapshot_api';
99
import { InfraWaffleMapBounds } from '../../../../lib/lib';
1010

1111
export const calculateBoundsFromNodes = (nodes: SnapshotNode[]): InfraWaffleMapBounds => {
12-
const maxValues = nodes.map((node) => {
12+
const values = nodes.map((node) => {
1313
const metric = first(node.metrics);
14-
if (!metric) return 0;
15-
return metric.max;
16-
});
17-
const minValues = nodes.map((node) => {
18-
const metric = first(node.metrics);
19-
if (!metric) return 0;
20-
return metric.value;
14+
return !metric || !metric.value ? 0 : metric.value;
2115
});
2216
// if there is only one value then we need to set the bottom range to zero for min
2317
// otherwise the legend will look silly since both values are the same for top and
2418
// bottom.
25-
if (minValues.length === 1) {
26-
minValues.unshift(0);
19+
if (values.length === 1) {
20+
values.unshift(0);
2721
}
28-
const maxValue = max(maxValues) || 0;
29-
const minValue = min(minValues) || 0;
22+
const maxValue = max(values) || 0;
23+
const minValue = min(values) || 0;
3024
return { min: isFinite(minValue) ? minValue : 0, max: isFinite(maxValue) ? maxValue : 0 };
3125
};

0 commit comments

Comments
 (0)