Commit 87716a55 authored by tom's avatar tom

adjust chart height

parent ea062c17
...@@ -30,6 +30,7 @@ const AddressCoinBalanceChart = ({ addressQuery }: Props) => { ...@@ -30,6 +30,7 @@ const AddressCoinBalanceChart = ({ addressQuery }: Props) => {
return ( return (
<ChartWidget <ChartWidget
chartHeight="200px"
title="Balances" title="Balances"
items={ items } items={ items }
isLoading={ isLoading || isError } isLoading={ isLoading || isError }
......
...@@ -18,11 +18,12 @@ type Props = { ...@@ -18,11 +18,12 @@ type Props = {
title: string; title: string;
description?: string; description?: string;
isLoading: boolean; isLoading: boolean;
chartHeight?: string;
} }
const DOWNLOAD_IMAGE_SCALE = 5; const DOWNLOAD_IMAGE_SCALE = 5;
const ChartWidget = ({ items, title, description, isLoading }: Props) => { const ChartWidget = ({ items, title, description, isLoading, chartHeight }: 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);
...@@ -78,7 +79,7 @@ const ChartWidget = ({ items, title, description, isLoading }: Props) => { ...@@ -78,7 +79,7 @@ const ChartWidget = ({ items, title, description, isLoading }: Props) => {
}, [ title ]); }, [ title ]);
if (isLoading) { if (isLoading) {
return <ChartWidgetSkeleton hasDescription={ Boolean(description) }/>; return <ChartWidgetSkeleton hasDescription={ Boolean(description) } chartHeight={ chartHeight }/>;
} }
if (items) { if (items) {
...@@ -172,12 +173,14 @@ const ChartWidget = ({ items, title, description, isLoading }: Props) => { ...@@ -172,12 +173,14 @@ const ChartWidget = ({ items, title, description, isLoading }: Props) => {
</Menu> </Menu>
</Grid> </Grid>
<ChartWidgetGraph <Box h={ chartHeight || 'auto' }>
items={ items } <ChartWidgetGraph
onZoom={ handleZoom } items={ items }
isZoomResetInitial={ isZoomResetInitial } onZoom={ handleZoom }
title={ title } isZoomResetInitial={ isZoomResetInitial }
/> title={ title }
/>
</Box>
</Box> </Box>
<FullscreenChartModal <FullscreenChartModal
...@@ -194,4 +197,4 @@ const ChartWidget = ({ items, title, description, isLoading }: Props) => { ...@@ -194,4 +197,4 @@ const ChartWidget = ({ items, title, description, isLoading }: Props) => {
return null; return null;
}; };
export default ChartWidget; export default React.memo(ChartWidget);
...@@ -31,7 +31,7 @@ const ChartWidgetGraph = ({ isEnlarged, items, onZoom, isZoomResetInitial, title ...@@ -31,7 +31,7 @@ const ChartWidgetGraph = ({ isEnlarged, items, onZoom, isZoomResetInitial, title
const overlayRef = React.useRef<SVGRectElement>(null); const overlayRef = React.useRef<SVGRectElement>(null);
const chartId = useMemo(() => `chart-${ title.split(' ').join('') }`, [ title ]); const chartId = useMemo(() => `chart-${ title.split(' ').join('') }`, [ title ]);
const [ range, setRange ] = React.useState<[ number, number ]>([ 0, Infinity ]); const [ range, setRange ] = React.useState<[ number, number ]>([ 0, Infinity ]);
const { innerWidth, innerHeight } = useChartSize(ref.current, CHART_MARGIN); const { width, height, innerWidth, innerHeight } = useChartSize(ref.current, CHART_MARGIN);
const displayedData = useMemo(() => items.slice(range[0], range[1]), [ items, range ]); const displayedData = useMemo(() => items.slice(range[0], range[1]), [ items, range ]);
const chartData = [ { items: items, name: 'Value', color } ]; const chartData = [ { items: items, name: 'Value', color } ];
...@@ -54,9 +54,9 @@ const ChartWidgetGraph = ({ isEnlarged, items, onZoom, isZoomResetInitial, title ...@@ -54,9 +54,9 @@ const ChartWidgetGraph = ({ isEnlarged, items, onZoom, isZoomResetInitial, title
}, [ isZoomResetInitial ]); }, [ isZoomResetInitial ]);
return ( return (
<svg width="100%" height="100%" ref={ ref } cursor="pointer" id={ chartId }> <svg width={ width || '100%' } height={ height || 'auto' } ref={ ref } cursor="pointer" id={ chartId } opacity={ width ? 1 : 0 }>
<g transform={ `translate(${ CHART_MARGIN?.left || 0 },${ CHART_MARGIN?.top || 0 })` } opacity={ innerWidth ? 1 : 0 }> <g transform={ `translate(${ CHART_MARGIN?.left || 0 },${ CHART_MARGIN?.top || 0 })` }>
<ChartGridLine <ChartGridLine
type="horizontal" type="horizontal"
scale={ yScale } scale={ yScale }
......
...@@ -3,9 +3,10 @@ import React from 'react'; ...@@ -3,9 +3,10 @@ import React from 'react';
interface Props { interface Props {
hasDescription: boolean; hasDescription: boolean;
chartHeight?: string;
} }
const ChartWidgetSkeleton = ({ hasDescription }: Props) => { const ChartWidgetSkeleton = ({ hasDescription, chartHeight }: Props) => {
return ( return (
<Box <Box
height="235px" height="235px"
...@@ -14,7 +15,7 @@ const ChartWidgetSkeleton = ({ hasDescription }: Props) => { ...@@ -14,7 +15,7 @@ const ChartWidgetSkeleton = ({ hasDescription }: Props) => {
<Skeleton w="75%" h="24px"/> <Skeleton w="75%" h="24px"/>
{ hasDescription && <Skeleton w="50%" h="18px" mt={ 1 }/> } { hasDescription && <Skeleton w="50%" h="18px" mt={ 1 }/> }
<Skeleton w="100%" h="150px" mt={ 5 }/> <Skeleton w="100%" h={ chartHeight || '150px' } mt={ 5 }/>
</Box> </Box>
); );
}; };
......
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