Skip to content

Commit

Permalink
[Metrics UI] remove middle number in legend and adjust calculation of…
Browse files Browse the repository at this point in the history
… max number (#89020)

* 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>
  • Loading branch information
neptunian and kibanamachine authored Feb 1, 2021
1 parent 9787911 commit 16500d8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ interface Props {
bounds: InfraWaffleMapBounds;
formatter: InfraFormatter;
}

type TickValue = 0 | 1;
export const SteppedGradientLegend: React.FC<Props> = ({ legend, bounds, formatter }) => {
return (
<LegendContainer>
<Ticks>
<TickLabel value={0} bounds={bounds} formatter={formatter} />
<TickLabel value={0.5} bounds={bounds} formatter={formatter} />
<TickLabel value={1} bounds={bounds} formatter={formatter} />
</Ticks>
<GradientContainer>
Expand All @@ -39,7 +38,7 @@ export const SteppedGradientLegend: React.FC<Props> = ({ legend, bounds, formatt

interface TickProps {
bounds: InfraWaffleMapBounds;
value: number;
value: TickValue;
formatter: InfraFormatter;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ describe('calculateBoundsFromNodes', () => {
const bounds = calculateBoundsFromNodes(nodes);
expect(bounds).toEqual({
min: 0.2,
max: 1.5,
max: 0.5,
});
});
it('should have a minimum of 0 for only a single node', () => {
const bounds = calculateBoundsFromNodes([nodes[0]]);
expect(bounds).toEqual({
min: 0,
max: 1.5,
max: 0.5,
});
});
it('should return zero for empty nodes', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,17 @@ import { SnapshotNode } from '../../../../../common/http_api/snapshot_api';
import { InfraWaffleMapBounds } from '../../../../lib/lib';

export const calculateBoundsFromNodes = (nodes: SnapshotNode[]): InfraWaffleMapBounds => {
const maxValues = nodes.map((node) => {
const values = nodes.map((node) => {
const metric = first(node.metrics);
if (!metric) return 0;
return metric.max;
});
const minValues = nodes.map((node) => {
const metric = first(node.metrics);
if (!metric) return 0;
return metric.value;
return !metric || !metric.value ? 0 : metric.value;
});
// if there is only one value then we need to set the bottom range to zero for min
// otherwise the legend will look silly since both values are the same for top and
// bottom.
if (minValues.length === 1) {
minValues.unshift(0);
if (values.length === 1) {
values.unshift(0);
}
const maxValue = max(maxValues) || 0;
const minValue = min(minValues) || 0;
const maxValue = max(values) || 0;
const minValue = min(values) || 0;
return { min: isFinite(minValue) ? minValue : 0, max: isFinite(maxValue) ? maxValue : 0 };
};

0 comments on commit 16500d8

Please sign in to comment.