Skip to content

Commit

Permalink
[ES|QL] [Unified Histogram] Changes the ratio to be rectangle (#187981)
Browse files Browse the repository at this point in the history
## Summary

<img width="1250" alt="image"
src="https://github.com/elastic/kibana/assets/17003240/9a41566c-76b5-4c32-97c1-50a3b57a51f3">


We had a chat with @gvnmagni about the ratio of the metric in Discover.
The square one is okeish but not for multi values.

We decided to change it in rectangle to be closer to how it will look in
a dashboard
  • Loading branch information
stratoula authored Jul 11, 2024
1 parent a4cd90b commit 5e0a52c
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions src/plugins/unified_histogram/public/chart/histogram.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* Side Public License, v 1.
*/

import { useEuiTheme, useResizeObserver } from '@elastic/eui';
import { useEuiTheme } from '@elastic/eui';
import { css } from '@emotion/react';
import React, { useState, useRef, useEffect } from 'react';
import React, { useState } from 'react';
import type { DataView } from '@kbn/data-views-plugin/public';
import type { DefaultInspectorAdapters, Datatable } from '@kbn/expressions-plugin/common';
import type { IKibanaSearchResponse } from '@kbn/search-types';
Expand Down Expand Up @@ -106,7 +106,6 @@ export function Histogram({
abortController,
}: HistogramProps) {
const [bucketInterval, setBucketInterval] = useState<UnifiedHistogramBucketInterval>();
const [chartSize, setChartSize] = useState('100%');
const { timeRangeText, timeRangeDisplay } = useTimeRange({
uiSettings,
bucketInterval,
Expand All @@ -115,19 +114,8 @@ export function Histogram({
isPlainRecord,
timeField: dataView.timeFieldName,
});
const chartRef = useRef<HTMLDivElement | null>(null);
const { height: containerHeight, width: containerWidth } = useResizeObserver(chartRef.current);
const { attributes } = visContext;

useEffect(() => {
if (attributes.visualizationType === 'lnsMetric') {
const size = containerHeight < containerWidth ? containerHeight : containerWidth;
setChartSize(`${size}px`);
} else {
setChartSize('100%');
}
}, [attributes, containerHeight, containerWidth]);

const onLoad = useStableCallback(
(
isLoading: boolean,
Expand Down Expand Up @@ -197,7 +185,7 @@ export function Histogram({
}
& .lnsExpressionRenderer {
width: ${chartSize};
width: ${attributes.visualizationType === 'lnsMetric' ? '90$' : '100%'};
margin: auto;
box-shadow: ${attributes.visualizationType === 'lnsMetric' ? boxShadow : 'none'};
}
Expand All @@ -222,7 +210,6 @@ export function Histogram({
data-request-data={requestData}
data-suggestion-type={visContext.suggestionType}
css={chartCss}
ref={chartRef}
>
<lens.EmbeddableComponent
{...lensProps}
Expand Down

0 comments on commit 5e0a52c

Please sign in to comment.