Commit 622c0e0b authored by tom's avatar tom

add units in tooltip

parent 4d0bc72e
...@@ -44,6 +44,7 @@ export type StatsChartInfo = { ...@@ -44,6 +44,7 @@ export type StatsChartInfo = {
id: string; id: string;
title: string; title: string;
description: string; description: string;
units: string | null;
} }
export type StatsChart = { chart: Array<StatsChartItem> }; export type StatsChart = { chart: Array<StatsChartItem> };
......
...@@ -80,7 +80,10 @@ const ChartTooltip = ({ chartId, xScale, yScale, width, tooltipWidth, height, da ...@@ -80,7 +80,10 @@ const ChartTooltip = ({ chartId, xScale, yScale, width, tooltipWidth, height, da
const updateDisplayedValue = React.useCallback((d: TimeChartItem, i: number) => { const updateDisplayedValue = React.useCallback((d: TimeChartItem, i: number) => {
d3.selectAll(`${ chartId ? `#${ chartId }` : '' } .ChartTooltip__value`) d3.selectAll(`${ chartId ? `#${ chartId }` : '' } .ChartTooltip__value`)
.filter((td, tIndex) => tIndex === i) .filter((td, tIndex) => tIndex === i)
.text(data[i].valueFormatter?.(d.value) || d.value.toLocaleString()); .text(
(data[i].valueFormatter?.(d.value) || d.value.toLocaleString()) +
(data[i].units ? ` ${ data[i].units }` : ''),
);
}, [ data, chartId ]); }, [ data, chartId ]);
const drawPoints = React.useCallback((x: number) => { const drawPoints = React.useCallback((x: number) => {
......
...@@ -37,6 +37,7 @@ type Props = { ...@@ -37,6 +37,7 @@ type Props = {
items?: Array<TimeChartItem>; items?: Array<TimeChartItem>;
title: string; title: string;
description?: string; description?: string;
units?: string;
isLoading: boolean; isLoading: boolean;
className?: string; className?: string;
isError: boolean; isError: boolean;
...@@ -44,7 +45,7 @@ type Props = { ...@@ -44,7 +45,7 @@ type Props = {
const DOWNLOAD_IMAGE_SCALE = 5; const DOWNLOAD_IMAGE_SCALE = 5;
const ChartWidget = ({ items, title, description, isLoading, className, isError }: Props) => { const ChartWidget = ({ items, title, description, isLoading, className, isError, units }: Props) => {
const ref = useRef<HTMLDivElement>(null); const ref = useRef<HTMLDivElement>(null);
const [ isFullscreen, setIsFullscreen ] = useState(false); const [ isFullscreen, setIsFullscreen ] = useState(false);
const [ isZoomResetInitial, setIsZoomResetInitial ] = React.useState(true); const [ isZoomResetInitial, setIsZoomResetInitial ] = React.useState(true);
...@@ -151,6 +152,7 @@ const ChartWidget = ({ items, title, description, isLoading, className, isError ...@@ -151,6 +152,7 @@ const ChartWidget = ({ items, title, description, isLoading, className, isError
onZoom={ handleZoom } onZoom={ handleZoom }
isZoomResetInitial={ isZoomResetInitial } isZoomResetInitial={ isZoomResetInitial }
title={ title } title={ title }
units={ units }
/> />
</Box> </Box>
); );
......
...@@ -20,6 +20,7 @@ import calculateInnerSize from 'ui/shared/chart/utils/calculateInnerSize'; ...@@ -20,6 +20,7 @@ import calculateInnerSize from 'ui/shared/chart/utils/calculateInnerSize';
interface Props { interface Props {
isEnlarged?: boolean; isEnlarged?: boolean;
title: string; title: string;
units?: string;
items: Array<TimeChartItem>; items: Array<TimeChartItem>;
onZoom: () => void; onZoom: () => void;
isZoomResetInitial: boolean; isZoomResetInitial: boolean;
...@@ -29,7 +30,7 @@ interface Props { ...@@ -29,7 +30,7 @@ interface Props {
const MAX_SHOW_ITEMS = 100; const MAX_SHOW_ITEMS = 100;
const DEFAULT_CHART_MARGIN = { bottom: 20, left: 40, right: 20, top: 10 }; const DEFAULT_CHART_MARGIN = { bottom: 20, left: 40, right: 20, top: 10 };
const ChartWidgetGraph = ({ isEnlarged, items, onZoom, isZoomResetInitial, title, margin }: Props) => { const ChartWidgetGraph = ({ isEnlarged, items, onZoom, isZoomResetInitial, title, margin, units }: Props) => {
const isMobile = useIsMobile(); const isMobile = useIsMobile();
const color = useToken('colors', 'blue.200'); const color = useToken('colors', 'blue.200');
const overlayRef = React.useRef<SVGRectElement>(null); const overlayRef = React.useRef<SVGRectElement>(null);
...@@ -53,7 +54,7 @@ const ChartWidgetGraph = ({ isEnlarged, items, onZoom, isZoomResetInitial, title ...@@ -53,7 +54,7 @@ const ChartWidgetGraph = ({ isEnlarged, items, onZoom, isZoomResetInitial, title
return rangedItems; return rangedItems;
} }
}, [ isGroupedValues, rangedItems ]); }, [ isGroupedValues, rangedItems ]);
const chartData = [ { items: displayedData, name: 'Value', color } ]; const chartData = React.useMemo(() => ([ { items: displayedData, name: 'Value', color, units } ]), [ color, displayedData, units ]);
const { xTickFormat, yTickFormat, xScale, yScale } = useTimeChartController({ const { xTickFormat, yTickFormat, xScale, yScale } = useTimeChartController({
data: [ { items: displayedData, name: title, color } ], data: [ { items: displayedData, name: title, color } ],
......
...@@ -19,6 +19,7 @@ export interface ChartOffset { ...@@ -19,6 +19,7 @@ export interface ChartOffset {
export interface TimeChartDataItem { export interface TimeChartDataItem {
items: Array<TimeChartItem>; items: Array<TimeChartItem>;
name: string; name: string;
units?: string;
color?: string; color?: string;
valueFormatter?: (value: number) => string; valueFormatter?: (value: number) => string;
} }
......
...@@ -11,6 +11,7 @@ type Props = { ...@@ -11,6 +11,7 @@ type Props = {
id: string; id: string;
title: string; title: string;
description: string; description: string;
units?: string;
interval: StatsIntervalIds; interval: StatsIntervalIds;
onLoadingError: () => void; onLoadingError: () => void;
} }
...@@ -19,7 +20,7 @@ function formatDate(date: Date) { ...@@ -19,7 +20,7 @@ function formatDate(date: Date) {
return date.toISOString().substring(0, 10); return date.toISOString().substring(0, 10);
} }
const ChartWidgetContainer = ({ id, title, description, interval, onLoadingError }: Props) => { const ChartWidgetContainer = ({ id, title, description, interval, onLoadingError, units }: Props) => {
const selectedInterval = STATS_INTERVALS[interval]; const selectedInterval = STATS_INTERVALS[interval];
const endDate = selectedInterval.start ? formatDate(new Date()) : undefined; const endDate = selectedInterval.start ? formatDate(new Date()) : undefined;
...@@ -48,6 +49,7 @@ const ChartWidgetContainer = ({ id, title, description, interval, onLoadingError ...@@ -48,6 +49,7 @@ const ChartWidgetContainer = ({ id, title, description, interval, onLoadingError
isError={ isError } isError={ isError }
items={ items } items={ items }
title={ title } title={ title }
units={ units }
description={ description } description={ description }
isLoading={ isLoading } isLoading={ isLoading }
/> />
......
...@@ -99,6 +99,7 @@ const ChartsWidgetsList = ({ filterQuery, isError, isLoading, charts, interval } ...@@ -99,6 +99,7 @@ const ChartsWidgetsList = ({ filterQuery, isError, isLoading, charts, interval }
title={ chart.title } title={ chart.title }
description={ chart.description } description={ chart.description }
interval={ interval } interval={ interval }
units={ chart.units || undefined }
onLoadingError={ handleChartLoadingError } onLoadingError={ handleChartLoadingError }
/> />
</GridItem> </GridItem>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment