Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
8e7271f0
Unverified
Commit
8e7271f0
authored
Jan 25, 2023
by
tom goriunov
Committed by
GitHub
Jan 25, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #538 from blockscout/bugfix/stats-filter
Stats fixes.
parents
1aaeafd5
eae56c21
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
113 additions
and
75 deletions
+113
-75
useClientRect.tsx
lib/hooks/useClientRect.tsx
+39
-0
useFirstMountState.tsx
lib/hooks/useFirstMountState.tsx
+14
-0
useUpdateEffect.tsx
lib/hooks/useUpdateEffect.tsx
+17
-0
EthereumChart.tsx
ui/charts/EthereumChart.tsx
+6
-5
SplineChartExample.tsx
ui/charts/SplineChartExample.tsx
+6
-4
ChainIndicatorChart.tsx
ui/home/indicators/ChainIndicatorChart.tsx
+6
-5
ChartWidgetGraph.tsx
ui/shared/chart/ChartWidgetGraph.tsx
+8
-5
useChartSize.tsx
ui/shared/chart/useChartSize.tsx
+0
-51
calculateInnerSize.ts
ui/shared/chart/utils/calculateInnerSize.ts
+12
-0
ChartWidgetContainer.tsx
ui/stats/ChartWidgetContainer.tsx
+3
-3
StatsFilters.tsx
ui/stats/StatsFilters.tsx
+2
-2
No files found.
lib/hooks/useClientRect.tsx
0 → 100644
View file @
8e7271f0
import
_debounce
from
'
lodash/debounce
'
;
import
type
{
LegacyRef
}
from
'
react
'
;
import
React
from
'
react
'
;
import
useUpdateEffect
from
'
lib/hooks/useUpdateEffect
'
;
export
default
function
useClientRect
<
E
extends
Element
>
():
[
DOMRect
|
null
,
LegacyRef
<
E
>
|
undefined
]
{
const
[
rect
,
setRect
]
=
React
.
useState
<
DOMRect
|
null
>
(
null
);
const
nodeRef
=
React
.
useRef
<
E
>
();
const
ref
=
React
.
useCallback
((
node
:
E
)
=>
{
if
(
node
!==
null
)
{
setRect
(
node
.
getBoundingClientRect
());
}
nodeRef
.
current
=
node
;
},
[]);
useUpdateEffect
(()
=>
{
const
content
=
window
.
document
.
querySelector
(
'
main
'
);
if
(
!
content
)
{
return
;
}
const
resizeHandler
=
_debounce
(()
=>
{
setRect
(
nodeRef
.
current
?.
getBoundingClientRect
()
??
null
);
},
100
);
const
resizeObserver
=
new
ResizeObserver
(
resizeHandler
);
resizeObserver
.
observe
(
content
);
resizeObserver
.
observe
(
window
.
document
.
body
);
return
function
cleanup
()
{
resizeObserver
.
unobserve
(
content
);
resizeObserver
.
unobserve
(
window
.
document
.
body
);
};
},
[
]);
return
[
rect
,
ref
];
}
lib/hooks/useFirstMountState.tsx
0 → 100644
View file @
8e7271f0
import
React
from
'
react
'
;
// Returns true if component is just mounted (on first render) and false otherwise.
export
function
useFirstMountState
():
boolean
{
const
isFirst
=
React
.
useRef
(
true
);
if
(
isFirst
.
current
)
{
isFirst
.
current
=
false
;
return
true
;
}
return
isFirst
.
current
;
}
lib/hooks/useUpdateEffect.tsx
0 → 100644
View file @
8e7271f0
import
React
from
'
react
'
;
import
{
useFirstMountState
}
from
'
./useFirstMountState
'
;
// React effect hook that ignores the first invocation (e.g. on mount). The signature is exactly the same as the useEffect hook.
const
useUpdateEffect
:
typeof
React
.
useEffect
=
(
effect
,
deps
)
=>
{
const
isFirstMount
=
useFirstMountState
();
React
.
useEffect
(()
=>
{
if
(
!
isFirstMount
)
{
return
effect
();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
},
deps
);
};
export
default
useUpdateEffect
;
ui/charts/EthereumChart.tsx
View file @
8e7271f0
...
@@ -6,6 +6,7 @@ import type { TimeChartData } from 'ui/shared/chart/types';
...
@@ -6,6 +6,7 @@ import type { TimeChartData } from 'ui/shared/chart/types';
import
ethTokenTransferData
from
'
data/charts_eth_token_transfer.json
'
;
import
ethTokenTransferData
from
'
data/charts_eth_token_transfer.json
'
;
import
ethTxsData
from
'
data/charts_eth_txs.json
'
;
import
ethTxsData
from
'
data/charts_eth_txs.json
'
;
import
dayjs
from
'
lib/date/dayjs
'
;
import
dayjs
from
'
lib/date/dayjs
'
;
import
useClientRect
from
'
lib/hooks/useClientRect
'
;
import
ChartArea
from
'
ui/shared/chart/ChartArea
'
;
import
ChartArea
from
'
ui/shared/chart/ChartArea
'
;
import
ChartAxis
from
'
ui/shared/chart/ChartAxis
'
;
import
ChartAxis
from
'
ui/shared/chart/ChartAxis
'
;
import
ChartGridLine
from
'
ui/shared/chart/ChartGridLine
'
;
import
ChartGridLine
from
'
ui/shared/chart/ChartGridLine
'
;
...
@@ -16,8 +17,8 @@ import ChartSelectionX from 'ui/shared/chart/ChartSelectionX';
...
@@ -16,8 +17,8 @@ import ChartSelectionX from 'ui/shared/chart/ChartSelectionX';
import
ChartTooltip
from
'
ui/shared/chart/ChartTooltip
'
;
import
ChartTooltip
from
'
ui/shared/chart/ChartTooltip
'
;
// import useBrushX from 'ui/shared/chart/useBrushX';
// import useBrushX from 'ui/shared/chart/useBrushX';
import
useChartLegend
from
'
ui/shared/chart/useChartLegend
'
;
import
useChartLegend
from
'
ui/shared/chart/useChartLegend
'
;
import
useChartSize
from
'
ui/shared/chart/useChartSize
'
;
import
useTimeChartController
from
'
ui/shared/chart/useTimeChartController
'
;
import
useTimeChartController
from
'
ui/shared/chart/useTimeChartController
'
;
import
calculateInnerSize
from
'
ui/shared/chart/utils/calculateInnerSize
'
;
const
CHART_MARGIN
=
{
bottom
:
20
,
left
:
65
,
right
:
30
,
top
:
10
};
const
CHART_MARGIN
=
{
bottom
:
20
,
left
:
65
,
right
:
30
,
top
:
10
};
const
CHART_OFFSET
=
{
const
CHART_OFFSET
=
{
...
@@ -27,10 +28,10 @@ const RANGE_DEFAULT_START_DATE = dayjs.min(dayjs(ethTokenTransferData[0].date),
...
@@ -27,10 +28,10 @@ const RANGE_DEFAULT_START_DATE = dayjs.min(dayjs(ethTokenTransferData[0].date),
const
RANGE_DEFAULT_LAST_DATE
=
dayjs
.
max
(
dayjs
(
ethTokenTransferData
.
at
(
-
1
)?.
date
),
dayjs
(
ethTxsData
.
at
(
-
1
)?.
date
)).
toDate
();
const
RANGE_DEFAULT_LAST_DATE
=
dayjs
.
max
(
dayjs
(
ethTokenTransferData
.
at
(
-
1
)?.
date
),
dayjs
(
ethTxsData
.
at
(
-
1
)?.
date
)).
toDate
();
const
EthereumChart
=
()
=>
{
const
EthereumChart
=
()
=>
{
const
ref
=
React
.
useRef
<
SVGSVGElement
>
(
null
);
const
overlayRef
=
React
.
useRef
<
SVGRectElement
>
(
null
);
const
overlayRef
=
React
.
useRef
<
SVGRectElement
>
(
null
);
const
{
width
,
height
,
innerWidth
,
innerHeight
}
=
useChartSize
(
ref
.
current
,
CHART_MARGIN
,
CHART_OFFSET
);
const
[
rect
,
ref
]
=
useClientRect
<
SVGSVGElement
>
();
const
{
innerWidth
,
innerHeight
}
=
calculateInnerSize
(
rect
,
CHART_MARGIN
,
CHART_OFFSET
);
const
[
range
,
setRange
]
=
React
.
useState
<
[
Date
,
Date
]
>
([
RANGE_DEFAULT_START_DATE
,
RANGE_DEFAULT_LAST_DATE
]);
const
[
range
,
setRange
]
=
React
.
useState
<
[
Date
,
Date
]
>
([
RANGE_DEFAULT_START_DATE
,
RANGE_DEFAULT_LAST_DATE
]);
const
data
:
TimeChartData
=
[
const
data
:
TimeChartData
=
[
...
@@ -75,8 +76,8 @@ const EthereumChart = () => {
...
@@ -75,8 +76,8 @@ const EthereumChart = () => {
return
(
return
(
<
Box
display=
"inline-block"
position=
"relative"
width=
"100%"
height=
"100%"
>
<
Box
display=
"inline-block"
position=
"relative"
width=
"100%"
height=
"100%"
>
<
svg
width=
{
width
||
'
100%
'
}
height=
{
height
||
'
100%
'
}
ref=
{
ref
}
>
<
svg
width=
"100%"
height=
"calc(100% - 26px)"
ref=
{
ref
}
>
<
g
transform=
{
`translate(${ CHART_MARGIN?.left || 0 },${ CHART_MARGIN?.top || 0 })`
}
opacity=
{
width
?
1
:
0
}
>
<
g
transform=
{
`translate(${ CHART_MARGIN?.left || 0 },${ CHART_MARGIN?.top || 0 })`
}
opacity=
{
rect
?
1
:
0
}
>
{
/* BASE GRID LINE */
}
{
/* BASE GRID LINE */
}
<
ChartGridLine
<
ChartGridLine
type=
"horizontal"
type=
"horizontal"
...
...
ui/charts/SplineChartExample.tsx
View file @
8e7271f0
...
@@ -2,17 +2,19 @@ import { useToken } from '@chakra-ui/react';
...
@@ -2,17 +2,19 @@ import { useToken } from '@chakra-ui/react';
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
ethTxsData
from
'
data/charts_eth_txs.json
'
;
import
ethTxsData
from
'
data/charts_eth_txs.json
'
;
import
useClientRect
from
'
lib/hooks/useClientRect
'
;
import
ChartLine
from
'
ui/shared/chart/ChartLine
'
;
import
ChartLine
from
'
ui/shared/chart/ChartLine
'
;
import
useChartSize
from
'
ui/shared/chart/useChartSize
'
;
import
useTimeChartController
from
'
ui/shared/chart/useTimeChartController
'
;
import
useTimeChartController
from
'
ui/shared/chart/useTimeChartController
'
;
import
calculateInnerSize
from
'
ui/shared/chart/utils/calculateInnerSize
'
;
import
{
BlueLineGradient
}
from
'
ui/shared/chart/utils/gradients
'
;
import
{
BlueLineGradient
}
from
'
ui/shared/chart/utils/gradients
'
;
const
CHART_MARGIN
=
{
bottom
:
0
,
left
:
0
,
right
:
0
,
top
:
0
};
const
CHART_MARGIN
=
{
bottom
:
0
,
left
:
0
,
right
:
0
,
top
:
0
};
const
DATA
=
ethTxsData
.
slice
(
-
30
).
map
((
d
)
=>
({
...
d
,
date
:
new
Date
(
d
.
date
)
}));
const
DATA
=
ethTxsData
.
slice
(
-
30
).
map
((
d
)
=>
({
...
d
,
date
:
new
Date
(
d
.
date
)
}));
const
SplineChartExample
=
()
=>
{
const
SplineChartExample
=
()
=>
{
const
ref
=
React
.
useRef
<
SVGSVGElement
>
(
null
);
const
[
rect
,
ref
]
=
useClientRect
<
SVGSVGElement
>
();
const
{
width
,
height
,
innerWidth
,
innerHeight
}
=
useChartSize
(
ref
.
current
,
CHART_MARGIN
);
const
{
innerWidth
,
innerHeight
}
=
calculateInnerSize
(
rect
,
CHART_MARGIN
);
const
color
=
useToken
(
'
colors
'
,
'
blue.500
'
);
const
color
=
useToken
(
'
colors
'
,
'
blue.500
'
);
const
{
xScale
,
yScale
}
=
useTimeChartController
({
const
{
xScale
,
yScale
}
=
useTimeChartController
({
data
:
[
{
items
:
DATA
,
name
:
'
spline
'
,
color
}
],
data
:
[
{
items
:
DATA
,
name
:
'
spline
'
,
color
}
],
...
@@ -21,7 +23,7 @@ const SplineChartExample = () => {
...
@@ -21,7 +23,7 @@ const SplineChartExample = () => {
});
});
return
(
return
(
<
svg
width=
{
width
||
'
100%
'
}
height=
{
height
||
'
100%
'
}
ref=
{
ref
}
>
<
svg
width=
"100%"
height=
"100%"
ref=
{
ref
}
>
<
defs
>
<
defs
>
<
BlueLineGradient
.
defs
/>
<
BlueLineGradient
.
defs
/>
</
defs
>
</
defs
>
...
...
ui/home/indicators/ChainIndicatorChart.tsx
View file @
8e7271f0
...
@@ -3,12 +3,13 @@ import React from 'react';
...
@@ -3,12 +3,13 @@ import React from 'react';
import
type
{
TimeChartData
}
from
'
ui/shared/chart/types
'
;
import
type
{
TimeChartData
}
from
'
ui/shared/chart/types
'
;
import
useClientRect
from
'
lib/hooks/useClientRect
'
;
import
ChartArea
from
'
ui/shared/chart/ChartArea
'
;
import
ChartArea
from
'
ui/shared/chart/ChartArea
'
;
import
ChartLine
from
'
ui/shared/chart/ChartLine
'
;
import
ChartLine
from
'
ui/shared/chart/ChartLine
'
;
import
ChartOverlay
from
'
ui/shared/chart/ChartOverlay
'
;
import
ChartOverlay
from
'
ui/shared/chart/ChartOverlay
'
;
import
ChartTooltip
from
'
ui/shared/chart/ChartTooltip
'
;
import
ChartTooltip
from
'
ui/shared/chart/ChartTooltip
'
;
import
useChartSize
from
'
ui/shared/chart/useChartSize
'
;
import
useTimeChartController
from
'
ui/shared/chart/useTimeChartController
'
;
import
useTimeChartController
from
'
ui/shared/chart/useTimeChartController
'
;
import
calculateInnerSize
from
'
ui/shared/chart/utils/calculateInnerSize
'
;
interface
Props
{
interface
Props
{
data
:
TimeChartData
;
data
:
TimeChartData
;
...
@@ -18,11 +19,11 @@ interface Props {
...
@@ -18,11 +19,11 @@ interface Props {
const
CHART_MARGIN
=
{
bottom
:
5
,
left
:
10
,
right
:
10
,
top
:
0
};
const
CHART_MARGIN
=
{
bottom
:
5
,
left
:
10
,
right
:
10
,
top
:
0
};
const
ChainIndicatorChart
=
({
data
}:
Props
)
=>
{
const
ChainIndicatorChart
=
({
data
}:
Props
)
=>
{
const
ref
=
React
.
useRef
<
SVGSVGElement
>
(
null
);
const
overlayRef
=
React
.
useRef
<
SVGRectElement
>
(
null
);
const
overlayRef
=
React
.
useRef
<
SVGRectElement
>
(
null
);
const
lineColor
=
useToken
(
'
colors
'
,
'
blue.500
'
);
const
lineColor
=
useToken
(
'
colors
'
,
'
blue.500
'
);
const
{
width
,
height
,
innerWidth
,
innerHeight
}
=
useChartSize
(
ref
.
current
,
CHART_MARGIN
);
const
[
rect
,
ref
]
=
useClientRect
<
SVGSVGElement
>
();
const
{
innerWidth
,
innerHeight
}
=
calculateInnerSize
(
rect
,
CHART_MARGIN
);
const
{
xScale
,
yScale
}
=
useTimeChartController
({
const
{
xScale
,
yScale
}
=
useTimeChartController
({
data
,
data
,
width
:
innerWidth
,
width
:
innerWidth
,
...
@@ -30,8 +31,8 @@ const ChainIndicatorChart = ({ data }: Props) => {
...
@@ -30,8 +31,8 @@ const ChainIndicatorChart = ({ data }: Props) => {
});
});
return
(
return
(
<
svg
width=
{
width
||
'
100%
'
}
height=
{
height
||
'
100%
'
}
ref=
{
ref
}
cursor=
"pointer"
>
<
svg
width=
"100%"
height=
"100%"
ref=
{
ref
}
cursor=
"pointer"
>
<
g
transform=
{
`translate(${ CHART_MARGIN?.left || 0 },${ CHART_MARGIN?.top || 0 })`
}
opacity=
{
width
?
1
:
0
}
>
<
g
transform=
{
`translate(${ CHART_MARGIN?.left || 0 },${ CHART_MARGIN?.top || 0 })`
}
opacity=
{
rect
?
1
:
0
}
>
<
ChartArea
<
ChartArea
data=
{
data
[
0
].
items
}
data=
{
data
[
0
].
items
}
xScale=
{
xScale
}
xScale=
{
xScale
}
...
...
ui/shared/chart/ChartWidgetGraph.tsx
View file @
8e7271f0
...
@@ -5,6 +5,7 @@ import React, { useEffect, useMemo } from 'react';
...
@@ -5,6 +5,7 @@ import React, { useEffect, useMemo } from 'react';
import
type
{
ChartMargin
,
TimeChartItem
}
from
'
ui/shared/chart/types
'
;
import
type
{
ChartMargin
,
TimeChartItem
}
from
'
ui/shared/chart/types
'
;
import
dayjs
from
'
lib/date/dayjs
'
;
import
dayjs
from
'
lib/date/dayjs
'
;
import
useClientRect
from
'
lib/hooks/useClientRect
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
import
ChartArea
from
'
ui/shared/chart/ChartArea
'
;
import
ChartArea
from
'
ui/shared/chart/ChartArea
'
;
import
ChartAxis
from
'
ui/shared/chart/ChartAxis
'
;
import
ChartAxis
from
'
ui/shared/chart/ChartAxis
'
;
...
@@ -13,8 +14,8 @@ import ChartLine from 'ui/shared/chart/ChartLine';
...
@@ -13,8 +14,8 @@ import ChartLine from 'ui/shared/chart/ChartLine';
import
ChartOverlay
from
'
ui/shared/chart/ChartOverlay
'
;
import
ChartOverlay
from
'
ui/shared/chart/ChartOverlay
'
;
import
ChartSelectionX
from
'
ui/shared/chart/ChartSelectionX
'
;
import
ChartSelectionX
from
'
ui/shared/chart/ChartSelectionX
'
;
import
ChartTooltip
from
'
ui/shared/chart/ChartTooltip
'
;
import
ChartTooltip
from
'
ui/shared/chart/ChartTooltip
'
;
import
useChartSize
from
'
ui/shared/chart/useChartSize
'
;
import
useTimeChartController
from
'
ui/shared/chart/useTimeChartController
'
;
import
useTimeChartController
from
'
ui/shared/chart/useTimeChartController
'
;
import
calculateInnerSize
from
'
ui/shared/chart/utils/calculateInnerSize
'
;
interface
Props
{
interface
Props
{
isEnlarged
?:
boolean
;
isEnlarged
?:
boolean
;
...
@@ -31,10 +32,12 @@ const DEFAULT_CHART_MARGIN = { bottom: 20, left: 40, right: 20, top: 10 };
...
@@ -31,10 +32,12 @@ 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
}:
Props
)
=>
{
const
isMobile
=
useIsMobile
();
const
isMobile
=
useIsMobile
();
const
color
=
useToken
(
'
colors
'
,
'
blue.200
'
);
const
color
=
useToken
(
'
colors
'
,
'
blue.200
'
);
const
ref
=
React
.
useRef
<
SVGSVGElement
>
(
null
);
const
overlayRef
=
React
.
useRef
<
SVGRectElement
>
(
null
);
const
overlayRef
=
React
.
useRef
<
SVGRectElement
>
(
null
);
const
[
rect
,
ref
]
=
useClientRect
<
SVGSVGElement
>
();
const
chartMargin
=
{
...
DEFAULT_CHART_MARGIN
,
...
margin
};
const
chartMargin
=
{
...
DEFAULT_CHART_MARGIN
,
...
margin
};
const
{
width
,
height
,
innerWidth
,
innerHeight
}
=
useChartSize
(
ref
.
current
,
chartMargin
);
const
{
innerWidth
,
innerHeight
}
=
calculateInnerSize
(
rect
,
chartMargin
);
const
chartId
=
`chart-
${
title
.
split
(
'
'
).
join
(
''
)
}
-
${
isEnlarged
?
'
fullscreen
'
:
'
small
'
}
`
;
const
chartId
=
`chart-
${
title
.
split
(
'
'
).
join
(
''
)
}
-
${
isEnlarged
?
'
fullscreen
'
:
'
small
'
}
`
;
const
[
range
,
setRange
]
=
React
.
useState
<
[
Date
,
Date
]
>
([
items
[
0
].
date
,
items
[
items
.
length
-
1
].
date
]);
const
[
range
,
setRange
]
=
React
.
useState
<
[
Date
,
Date
]
>
([
items
[
0
].
date
,
items
[
items
.
length
-
1
].
date
]);
...
@@ -70,7 +73,7 @@ const ChartWidgetGraph = ({ isEnlarged, items, onZoom, isZoomResetInitial, title
...
@@ -70,7 +73,7 @@ const ChartWidgetGraph = ({ isEnlarged, items, onZoom, isZoomResetInitial, title
},
[
isZoomResetInitial
,
items
]);
},
[
isZoomResetInitial
,
items
]);
return
(
return
(
<
svg
width=
"100%"
height=
{
height
||
'
100%
'
}
ref=
{
ref
}
cursor=
"pointer"
id=
{
chartId
}
opacity=
{
width
?
1
:
0
}
>
<
svg
width=
"100%"
height=
"100%"
ref=
{
ref
}
cursor=
"pointer"
id=
{
chartId
}
opacity=
{
rect
?
1
:
0
}
>
<
g
transform=
{
`translate(${ chartMargin?.left || 0 },${ chartMargin?.top || 0 })`
}
>
<
g
transform=
{
`translate(${ chartMargin?.left || 0 },${ chartMargin?.top || 0 })`
}
>
<
ChartGridLine
<
ChartGridLine
...
@@ -149,6 +152,6 @@ function groupChartItemsByWeekNumber(items: Array<TimeChartItem>): Array<TimeCha
...
@@ -149,6 +152,6 @@ function groupChartItemsByWeekNumber(items: Array<TimeChartItem>): Array<TimeCha
value
:
d3
.
sum
(
group
,
(
d
)
=>
d
.
value
),
value
:
d3
.
sum
(
group
,
(
d
)
=>
d
.
value
),
dateLabel
:
`
${
d3
.
timeFormat
(
'
%e %b %Y
'
)(
group
[
0
].
date
)
}
–
${
d3
.
timeFormat
(
'
%e %b %Y
'
)(
group
[
group
.
length
-
1
].
date
)
}
`
,
dateLabel
:
`
${
d3
.
timeFormat
(
'
%e %b %Y
'
)(
group
[
0
].
date
)
}
–
${
d3
.
timeFormat
(
'
%e %b %Y
'
)(
group
[
group
.
length
-
1
].
date
)
}
`
,
}),
}),
(
t
)
=>
dayjs
(
t
.
date
).
week
()
,
(
t
)
=>
`
${
dayjs
(
t
.
date
).
week
()
}
/
${
dayjs
(
t
.
date
).
year
()
}
`
,
).
map
(([
,
v
])
=>
v
);
).
map
(([
,
v
])
=>
v
);
}
}
ui/shared/chart/useChartSize.tsx
deleted
100644 → 0
View file @
1aaeafd5
import
_debounce
from
'
lodash/debounce
'
;
import
React
from
'
react
'
;
import
type
{
ChartMargin
,
ChartOffset
}
from
'
ui/shared/chart/types
'
;
export
default
function
useChartSize
(
svgEl
:
SVGSVGElement
|
null
,
margin
?:
ChartMargin
,
offsets
?:
ChartOffset
)
{
const
[
rect
,
setRect
]
=
React
.
useState
<
{
width
:
number
;
height
:
number
}
>
({
width
:
0
,
height
:
0
});
const
calculateRect
=
React
.
useCallback
(()
=>
{
const
rect
=
svgEl
?.
getBoundingClientRect
();
return
{
width
:
rect
?.
width
||
0
,
height
:
rect
?.
height
||
0
};
},
[
svgEl
]);
React
.
useEffect
(()
=>
{
setRect
(
calculateRect
());
},
[
calculateRect
]);
React
.
useEffect
(()
=>
{
const
content
=
window
.
document
.
querySelector
(
'
main
'
);
if
(
!
content
)
{
return
;
}
let
timeoutId
:
number
;
const
resizeHandler
=
_debounce
(()
=>
{
setRect
({
width
:
0
,
height
:
0
});
timeoutId
=
window
.
setTimeout
(()
=>
{
setRect
(
calculateRect
());
},
100
);
},
100
);
const
resizeObserver
=
new
ResizeObserver
(
resizeHandler
);
resizeObserver
.
observe
(
content
);
resizeObserver
.
observe
(
window
.
document
.
body
);
return
function
cleanup
()
{
resizeObserver
.
unobserve
(
content
);
resizeObserver
.
unobserve
(
window
.
document
.
body
);
window
.
clearTimeout
(
timeoutId
);
};
},
[
calculateRect
]);
return
React
.
useMemo
(()
=>
{
return
{
width
:
Math
.
max
(
rect
.
width
-
(
offsets
?.
x
||
0
),
0
),
height
:
Math
.
max
(
rect
.
height
-
(
offsets
?.
y
||
0
),
0
),
innerWidth
:
Math
.
max
(
rect
.
width
-
(
offsets
?.
x
||
0
)
-
(
margin
?.
left
||
0
)
-
(
margin
?.
right
||
0
),
0
),
innerHeight
:
Math
.
max
(
rect
.
height
-
(
offsets
?.
y
||
0
)
-
(
margin
?.
bottom
||
0
)
-
(
margin
?.
top
||
0
),
0
),
};
},
[
margin
?.
bottom
,
margin
?.
left
,
margin
?.
right
,
margin
?.
top
,
offsets
?.
x
,
offsets
?.
y
,
rect
.
height
,
rect
.
width
]);
}
ui/shared/chart/utils/calculateInnerSize.ts
0 → 100644
View file @
8e7271f0
import
type
{
ChartMargin
,
ChartOffset
}
from
'
ui/shared/chart/types
'
;
export
default
function
calculateInnerSize
(
rect
:
DOMRect
|
null
,
margin
?:
ChartMargin
,
offsets
?:
ChartOffset
)
{
if
(
!
rect
)
{
return
{
innerWidth
:
0
,
innerHeight
:
0
};
}
return
{
innerWidth
:
Math
.
max
(
rect
.
width
-
(
offsets
?.
x
||
0
)
-
(
margin
?.
left
||
0
)
-
(
margin
?.
right
||
0
),
0
),
innerHeight
:
Math
.
max
(
rect
.
height
-
(
offsets
?.
y
||
0
)
-
(
margin
?.
bottom
||
0
)
-
(
margin
?.
top
||
0
),
0
),
};
}
ui/stats/ChartWidgetContainer.tsx
View file @
8e7271f0
import
React
,
{
useEffect
}
from
'
react
'
;
import
React
,
{
useEffect
,
useMemo
}
from
'
react
'
;
import
type
{
StatsIntervalIds
}
from
'
types/client/stats
'
;
import
type
{
StatsIntervalIds
}
from
'
types/client/stats
'
;
...
@@ -33,9 +33,9 @@ const ChartWidgetContainer = ({ id, title, description, interval, onLoadingError
...
@@ -33,9 +33,9 @@ const ChartWidgetContainer = ({ id, title, description, interval, onLoadingError
},
},
});
});
const
items
=
data
?.
chart
?.
map
((
item
)
=>
{
const
items
=
useMemo
(()
=>
data
?.
chart
?.
map
((
item
)
=>
{
return
{
date
:
new
Date
(
item
.
date
),
value
:
Number
(
item
.
value
)
};
return
{
date
:
new
Date
(
item
.
date
),
value
:
Number
(
item
.
value
)
};
});
})
,
[
data
])
;
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
isError
)
{
if
(
isError
)
{
...
...
ui/stats/StatsFilters.tsx
View file @
8e7271f0
...
@@ -41,8 +41,8 @@ const StatsFilters = ({
...
@@ -41,8 +41,8 @@ const StatsFilters = ({
<
Grid
<
Grid
gap=
{
2
}
gap=
{
2
}
templateAreas=
{
{
templateAreas=
{
{
base
:
`"
input input
"
base
:
`"
section interval
"
"
section interval
"`
,
"
input input
"`
,
lg
:
`"section interval input"`
,
lg
:
`"section interval input"`
,
}
}
}
}
gridTemplateColumns=
{
{
base
:
'
repeat(2, minmax(0, 1fr))
'
,
lg
:
'
auto auto 1fr
'
}
}
gridTemplateColumns=
{
{
base
:
'
repeat(2, minmax(0, 1fr))
'
,
lg
:
'
auto auto 1fr
'
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment