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
087575e8
Commit
087575e8
authored
Oct 25, 2022
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adaptive chart
parent
b16ab20b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
65 deletions
+86
-65
EthereumDailyTxsChart.tsx
ui/charts/EthereumDailyTxsChart.tsx
+80
-64
Graph.tsx
ui/pages/Graph.tsx
+6
-1
No files found.
ui/charts/EthereumDailyTxsChart.tsx
View file @
087575e8
...
...
@@ -8,82 +8,98 @@ import GridLine from 'ui/shared/graphs/GridLine';
import
Line
from
'
ui/shared/graphs/Line
'
;
import
useTimeGraphController
from
'
ui/shared/graphs/useTimeGraphController
'
;
const
dimensions
=
{
width
:
600
,
height
:
300
,
margin
:
{
top
:
0
,
right
:
0
,
bottom
:
20
,
left
:
65
},
};
const
data
=
{
items
:
json
.
map
((
d
)
=>
({
...
d
,
date
:
new
Date
(
d
.
date
)
})),
};
const
EthereumDailyTxsChart
=
()
=>
{
const
{
width
,
height
,
margin
}
=
dimensions
;
const
svgWidth
=
width
+
margin
.
left
+
margin
.
right
;
const
svgHeight
=
height
+
margin
.
top
+
margin
.
bottom
;
const
controller
=
useTimeGraphController
({
data
,
width
,
height
});
const
{
yTickFormat
,
xScale
,
yScale
}
=
controller
;
interface
Props
{
margin
?:
{
top
?:
number
;
right
?:
number
;
bottom
?:
number
;
left
?:
number
;
};
}
const
EthereumDailyTxsChart
=
({
margin
}:
Props
)
=>
{
const
ref
=
React
.
useRef
<
SVGSVGElement
>
(
null
);
const
[
rect
,
setRect
]
=
React
.
useState
<
{
width
:
number
;
height
:
number
}
>
();
React
.
useEffect
(()
=>
{
const
rect
=
ref
.
current
?.
getBoundingClientRect
();
rect
&&
setRect
({
width
:
rect
.
width
,
height
:
rect
.
height
});
},
[
]);
const
width
=
rect
?.
width
||
0
;
const
height
=
rect
?.
height
||
0
;
const
innerWidth
=
width
-
(
margin
?.
left
||
0
)
-
(
margin
?.
right
||
0
);
const
innerHeight
=
height
-
(
margin
?.
bottom
||
0
)
-
(
margin
?.
top
||
0
);
const
{
yTickFormat
,
xScale
,
yScale
}
=
useTimeGraphController
({
data
,
width
:
innerWidth
,
height
:
innerHeight
});
const
lineColor
=
useToken
(
'
colors
'
,
'
blue.500
'
);
return
(
<
svg
width=
{
svgWidth
}
height=
{
svgHeight
}
>
<
g
transform=
{
`translate(${ margin.left },${ margin.top })`
}
>
{
/* BASE GRID LINE */
}
<
GridLine
type=
"horizontal"
scale=
{
yScale
}
ticks=
{
1
}
size=
{
width
}
disableAnimation
/>
<
svg
width=
{
width
||
'
100%
'
}
height=
{
height
||
'
100%
'
}
ref=
{
ref
}
>
{
width
>
0
&&
(
<
g
transform=
{
`translate(${ margin?.left || 0 },${ margin?.top || 0 })`
}
>
{
/* BASE GRID LINE */
}
<
GridLine
type=
"horizontal"
scale=
{
yScale
}
ticks=
{
1
}
size=
{
innerWidth
}
disableAnimation
/>
{
/* GIRD LINES */
}
<
GridLine
type=
"vertical"
scale=
{
xScale
}
ticks=
{
5
}
size=
{
h
eight
}
transform=
{
`translate(0, ${ h
eight })`
}
/>
<
GridLine
type=
"horizontal"
scale=
{
yScale
}
ticks=
{
5
}
size=
{
w
idth
}
/>
{
/* GIRD LINES */
}
<
GridLine
type=
"vertical"
scale=
{
xScale
}
ticks=
{
5
}
size=
{
innerH
eight
}
transform=
{
`translate(0, ${ innerH
eight })`
}
/>
<
GridLine
type=
"horizontal"
scale=
{
yScale
}
ticks=
{
5
}
size=
{
innerW
idth
}
/>
{
/* GRAPH */
}
<
Line
data=
{
data
.
items
}
xScale=
{
xScale
}
yScale=
{
yScale
}
stroke=
{
lineColor
}
animation=
"left"
/>
<
Area
data=
{
data
.
items
}
color=
{
lineColor
}
xScale=
{
xScale
}
yScale=
{
yScale
}
/>
{
/* GRAPH */
}
<
Line
data=
{
data
.
items
}
xScale=
{
xScale
}
yScale=
{
yScale
}
stroke=
{
lineColor
}
animation=
"left"
/>
<
Area
data=
{
data
.
items
}
color=
{
lineColor
}
xScale=
{
xScale
}
yScale=
{
yScale
}
/>
{
/* AXISES */
}
<
Axis
type=
"left"
scale=
{
yScale
}
ticks=
{
5
}
tickFormat=
{
yTickFormat
}
/>
<
Axis
type=
"bottom"
scale=
{
xScale
}
transform=
{
`translate(0, ${ height })`
}
ticks=
{
5
}
/>
</
g
>
{
/* AXISES */
}
<
Axis
type=
"left"
scale=
{
yScale
}
ticks=
{
5
}
tickFormat=
{
yTickFormat
}
/>
<
Axis
type=
"bottom"
scale=
{
xScale
}
transform=
{
`translate(0, ${ innerHeight })`
}
ticks=
{
5
}
/>
</
g
>
)
}
</
svg
>
);
};
export
default
EthereumDailyTxsChart
;
export
default
React
.
memo
(
EthereumDailyTxsChart
)
;
ui/pages/Graph.tsx
View file @
087575e8
import
{
Box
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
EthereumDailyTxsChart
from
'
ui/charts/EthereumDailyTxsChart
'
;
import
Page
from
'
ui/shared/Page/Page
'
;
import
PageTitle
from
'
ui/shared/Page/PageTitle
'
;
const
CHART_MARGIN
=
{
bottom
:
20
,
left
:
65
};
const
Graph
=
()
=>
{
return
(
<
Page
>
<
PageTitle
text=
"Ethereum Daily Transactions Chart"
/>
<
EthereumDailyTxsChart
/>
<
Box
w=
"100%"
h=
"400px"
>
<
EthereumDailyTxsChart
margin=
{
CHART_MARGIN
}
/>
</
Box
>
</
Page
>
);
};
...
...
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