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
14fda4e3
Commit
14fda4e3
authored
Oct 25, 2022
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chart resize
parent
bc2cb096
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
21 deletions
+41
-21
EthereumDailyTxsChart.tsx
ui/charts/EthereumDailyTxsChart.tsx
+34
-9
Line.tsx
ui/shared/graphs/Line.tsx
+7
-12
No files found.
ui/charts/EthereumDailyTxsChart.tsx
View file @
14fda4e3
import
{
useToken
}
from
'
@chakra-ui/react
'
;
import
{
useToken
}
from
'
@chakra-ui/react
'
;
import
_debounce
from
'
lodash/debounce
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
json
from
'
data/charts_eth_txs.json
'
;
import
json
from
'
data/charts_eth_txs.json
'
;
...
@@ -27,18 +28,38 @@ const EthereumDailyTxsChart = ({ margin }: Props) => {
...
@@ -27,18 +28,38 @@ const EthereumDailyTxsChart = ({ margin }: Props) => {
const
ref
=
React
.
useRef
<
SVGSVGElement
>
(
null
);
const
ref
=
React
.
useRef
<
SVGSVGElement
>
(
null
);
const
overlayRef
=
React
.
useRef
<
SVGRectElement
>
(
null
);
const
overlayRef
=
React
.
useRef
<
SVGRectElement
>
(
null
);
const
[
rect
,
setRect
]
=
React
.
useState
<
{
width
:
number
;
height
:
number
}
>
();
const
[
rect
,
setRect
]
=
React
.
useState
<
{
width
:
number
;
height
:
number
}
>
(
{
width
:
0
,
height
:
0
}
);
React
.
useEffect
(()
=>
{
const
calculateRect
=
React
.
useCallback
(()
=>
{
const
rect
=
ref
.
current
?.
getBoundingClientRect
();
const
rect
=
ref
.
current
?.
getBoundingClientRect
();
rect
&&
setRect
({
width
:
rect
.
width
,
height
:
rect
.
height
});
return
{
width
:
rect
?.
width
||
0
,
height
:
rect
?.
height
||
0
};
},
[
]);
},
[]);
React
.
useEffect
(()
=>
{
setRect
(
calculateRect
());
},
[
calculateRect
]);
React
.
useEffect
(()
=>
{
let
timeoutId
:
number
;
const
resizeHandler
=
_debounce
(()
=>
{
setRect
({
width
:
0
,
height
:
0
});
timeoutId
=
window
.
setTimeout
(()
=>
{
setRect
(
calculateRect
());
},
0
);
},
100
);
const
resizeObserver
=
new
ResizeObserver
(
resizeHandler
);
const
width
=
rect
?.
width
||
0
;
resizeObserver
.
observe
(
document
.
body
);
const
height
=
rect
?.
height
||
0
;
return
function
cleanup
()
{
resizeObserver
.
unobserve
(
document
.
body
);
window
.
clearTimeout
(
timeoutId
);
};
},
[
calculateRect
]);
const
innerWidth
=
width
-
(
margin
?.
left
||
0
)
-
(
margin
?.
right
||
0
);
const
{
width
,
height
}
=
rect
;
const
innerHeight
=
height
-
(
margin
?.
bottom
||
0
)
-
(
margin
?.
top
||
0
);
const
innerWidth
=
Math
.
max
(
width
-
(
margin
?.
left
||
0
)
-
(
margin
?.
right
||
0
),
0
);
const
innerHeight
=
Math
.
max
(
height
-
(
margin
?.
bottom
||
0
)
-
(
margin
?.
top
||
0
),
0
);
const
{
yTickFormat
,
xScale
,
yScale
}
=
useTimeGraphController
({
data
,
width
:
innerWidth
,
height
:
innerHeight
});
const
{
yTickFormat
,
xScale
,
yScale
}
=
useTimeGraphController
({
data
,
width
:
innerWidth
,
height
:
innerHeight
});
...
@@ -46,7 +67,7 @@ const EthereumDailyTxsChart = ({ margin }: Props) => {
...
@@ -46,7 +67,7 @@ const EthereumDailyTxsChart = ({ margin }: Props) => {
return
(
return
(
<
svg
width=
{
width
||
'
100%
'
}
height=
{
height
||
'
100%
'
}
ref=
{
ref
}
>
<
svg
width=
{
width
||
'
100%
'
}
height=
{
height
||
'
100%
'
}
ref=
{
ref
}
>
<
g
transform=
{
`translate(${ margin?.left || 0 },${ margin?.top || 0 })`
}
>
<
g
transform=
{
`translate(${ margin?.left || 0 },${ margin?.top || 0 })`
}
opacity=
{
width
?
1
:
0
}
>
{
/* BASE GRID LINE */
}
{
/* BASE GRID LINE */
}
<
GridLine
<
GridLine
type=
"horizontal"
type=
"horizontal"
...
@@ -63,12 +84,14 @@ const EthereumDailyTxsChart = ({ margin }: Props) => {
...
@@ -63,12 +84,14 @@ const EthereumDailyTxsChart = ({ margin }: Props) => {
ticks=
{
5
}
ticks=
{
5
}
size=
{
innerHeight
}
size=
{
innerHeight
}
transform=
{
`translate(0, ${ innerHeight })`
}
transform=
{
`translate(0, ${ innerHeight })`
}
disableAnimation
/>
/>
<
GridLine
<
GridLine
type=
"horizontal"
type=
"horizontal"
scale=
{
yScale
}
scale=
{
yScale
}
ticks=
{
5
}
ticks=
{
5
}
size=
{
innerWidth
}
size=
{
innerWidth
}
disableAnimation
/>
/>
{
/* GRAPH */
}
{
/* GRAPH */
}
...
@@ -92,6 +115,7 @@ const EthereumDailyTxsChart = ({ margin }: Props) => {
...
@@ -92,6 +115,7 @@ const EthereumDailyTxsChart = ({ margin }: Props) => {
scale=
{
yScale
}
scale=
{
yScale
}
ticks=
{
5
}
ticks=
{
5
}
tickFormat=
{
yTickFormat
}
tickFormat=
{
yTickFormat
}
disableAnimation
/>
/>
<
Overlay
ref=
{
overlayRef
}
width=
{
innerWidth
}
height=
{
innerHeight
}
>
<
Overlay
ref=
{
overlayRef
}
width=
{
innerWidth
}
height=
{
innerHeight
}
>
<
Axis
<
Axis
...
@@ -100,6 +124,7 @@ const EthereumDailyTxsChart = ({ margin }: Props) => {
...
@@ -100,6 +124,7 @@ const EthereumDailyTxsChart = ({ margin }: Props) => {
transform=
{
`translate(0, ${ innerHeight })`
}
transform=
{
`translate(0, ${ innerHeight })`
}
ticks=
{
5
}
ticks=
{
5
}
anchorEl=
{
overlayRef
.
current
}
anchorEl=
{
overlayRef
.
current
}
disableAnimation
/>
/>
<
Tooltip
<
Tooltip
anchorEl=
{
overlayRef
.
current
}
anchorEl=
{
overlayRef
.
current
}
...
...
ui/shared/graphs/Line.tsx
View file @
14fda4e3
...
@@ -39,18 +39,13 @@ const Line = ({ xScale, yScale, data, animation, ...props }: Props) => {
...
@@ -39,18 +39,13 @@ const Line = ({ xScale, yScale, data, animation, ...props }: Props) => {
},
[]);
},
[]);
React
.
useEffect
(()
=>
{
React
.
useEffect
(()
=>
{
switch
(
animation
)
{
const
ANIMATIONS
=
{
case
'
left
'
:
left
:
animateLeft
,
animateLeft
();
fadeIn
:
animateFadeIn
,
break
;
none
:
noneAnimation
,
case
'
fadeIn
'
:
};
animateFadeIn
();
const
animationFn
=
ANIMATIONS
[
animation
];
break
;
window
.
setTimeout
(
animationFn
,
100
);
case
'
none
'
:
default
:
noneAnimation
();
break
;
}
},
[
animateLeft
,
animateFadeIn
,
noneAnimation
,
animation
]);
},
[
animateLeft
,
animateFadeIn
,
noneAnimation
,
animation
]);
// Recalculate line length if scale has changed
// Recalculate line length if scale has changed
...
...
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