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
958286c8
Commit
958286c8
authored
Nov 09, 2022
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add spline chart and line color customization
parent
8193c7d1
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
90 additions
and
11 deletions
+90
-11
SplineChartExample.tsx
ui/charts/SplineChartExample.tsx
+40
-0
Graph.tsx
ui/pages/Graph.tsx
+5
-0
ChartArea.tsx
ui/shared/chart/ChartArea.tsx
+12
-9
ChartLine.tsx
ui/shared/chart/ChartLine.tsx
+2
-1
types.tsx
ui/shared/chart/types.tsx
+1
-1
gradients.tsx
ui/shared/chart/utils/gradients.tsx
+30
-0
No files found.
ui/charts/SplineChartExample.tsx
0 → 100644
View file @
958286c8
import
{
useToken
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
ethTxsData
from
'
data/charts_eth_txs.json
'
;
import
ChartLine
from
'
ui/shared/chart/ChartLine
'
;
import
useChartSize
from
'
ui/shared/chart/useChartSize
'
;
import
useTimeChartController
from
'
ui/shared/chart/useTimeChartController
'
;
import
{
BlueLinearGradient
}
from
'
ui/shared/chart/utils/gradients
'
;
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
SplineChartExample
=
()
=>
{
const
ref
=
React
.
useRef
<
SVGSVGElement
>
(
null
);
const
{
width
,
height
,
innerWidth
,
innerHeight
}
=
useChartSize
(
ref
.
current
,
CHART_MARGIN
);
const
color
=
useToken
(
'
colors
'
,
'
blue.500
'
);
const
{
xScale
,
yScale
}
=
useTimeChartController
({
data
:
[
{
items
:
DATA
,
name
:
'
spline
'
,
color
}
],
width
:
innerWidth
,
height
:
innerHeight
,
});
return
(
<
svg
width=
{
width
||
'
100%
'
}
height=
{
height
||
'
100%
'
}
ref=
{
ref
}
>
<
defs
>
<
BlueLinearGradient
.
defs
/>
</
defs
>
<
ChartLine
data=
{
DATA
}
xScale=
{
xScale
}
yScale=
{
yScale
}
stroke=
{
`url(#${ BlueLinearGradient.id })`
}
animation=
"left"
strokeWidth=
{
3
}
/>
</
svg
>
);
};
export
default
SplineChartExample
;
ui/pages/Graph.tsx
View file @
958286c8
...
...
@@ -2,6 +2,7 @@ import { Box, Heading } from '@chakra-ui/react';
import
React
from
'
react
'
;
import
EthereumChart
from
'
ui/charts/EthereumChart
'
;
import
SplineChartExample
from
'
ui/charts/SplineChartExample
'
;
import
Page
from
'
ui/shared/Page/Page
'
;
import
PageTitle
from
'
ui/shared/Page/PageTitle
'
;
...
...
@@ -13,6 +14,10 @@ const Graph = () => {
<
Box
w=
"100%"
h=
"400px"
>
<
EthereumChart
/>
</
Box
>
<
Heading
as=
"h2"
size=
"sm"
fontWeight=
"500"
mb=
{
3
}
mt=
"100px"
>
Ethereum Daily Transactions For Last Month
</
Heading
>
<
Box
w=
"240px"
h=
"150px"
>
<
SplineChartExample
/>
</
Box
>
</
Page
>
);
};
...
...
ui/shared/chart/ChartArea.tsx
View file @
958286c8
...
...
@@ -6,7 +6,7 @@ import type { TimeChartItem } from 'ui/shared/chart/types';
interface
Props
extends
React
.
SVGProps
<
SVGPathElement
>
{
xScale
:
d3
.
ScaleTime
<
number
,
number
>
|
d3
.
ScaleLinear
<
number
,
number
>
;
yScale
:
d3
.
ScaleTime
<
number
,
number
>
|
d3
.
ScaleLinear
<
number
,
number
>
;
color
:
string
;
color
?
:
string
;
data
:
Array
<
TimeChartItem
>
;
disableAnimation
?:
boolean
;
}
...
...
@@ -28,19 +28,22 @@ const ChartArea = ({ xScale, yScale, color, data, disableAnimation, ...props }:
const
area
=
d3
.
area
<
TimeChartItem
>
()
.
x
(({
date
})
=>
xScale
(
date
))
.
y1
(({
value
})
=>
yScale
(
value
))
.
y0
(()
=>
yScale
(
yScale
.
domain
()[
0
]));
.
y0
(()
=>
yScale
(
yScale
.
domain
()[
0
]))
.
curve
(
d3
.
curveNatural
);
return
area
(
data
)
||
undefined
;
},
[
xScale
,
yScale
,
data
]);
return
(
<>
<
path
ref=
{
ref
}
d=
{
d
}
fill=
{
`url(#gradient-${ color })`
}
opacity=
{
0
}
{
...
props
}
/>
<
defs
>
<
linearGradient
id=
{
`gradient-${ color }`
}
x1=
"0%"
x2=
"0%"
y1=
"0%"
y2=
"100%"
>
<
stop
offset=
"0%"
stopColor=
{
color
}
stopOpacity=
{
1
}
/>
<
stop
offset=
"100%"
stopColor=
{
color
}
stopOpacity=
{
0.15
}
/>
</
linearGradient
>
</
defs
>
<
path
ref=
{
ref
}
d=
{
d
}
fill=
{
color
?
`url(#gradient-${ color })`
:
'
none
'
}
opacity=
{
0
}
{
...
props
}
/>
{
color
&&
(
<
defs
>
<
linearGradient
id=
{
`gradient-${ color }`
}
x1=
"0%"
x2=
"0%"
y1=
"0%"
y2=
"100%"
>
<
stop
offset=
"0%"
stopColor=
{
color
}
stopOpacity=
{
0.8
}
/>
<
stop
offset=
"100%"
stopColor=
{
color
}
stopOpacity=
{
0.02
}
/>
</
linearGradient
>
</
defs
>
)
}
</>
);
};
...
...
ui/shared/chart/ChartLine.tsx
View file @
958286c8
...
...
@@ -61,7 +61,8 @@ const ChartLine = ({ xScale, yScale, data, animation, ...props }: Props) => {
const
line
=
d3
.
line
<
TimeChartItem
>
()
.
x
((
d
)
=>
xScale
(
d
.
date
))
.
y
((
d
)
=>
yScale
(
d
.
value
));
.
y
((
d
)
=>
yScale
(
d
.
value
))
.
curve
(
d3
.
curveNatural
);
return
(
<
path
...
...
ui/shared/chart/types.tsx
View file @
958286c8
...
...
@@ -13,7 +13,7 @@ export interface ChartMargin {
export
interface
TimeChartDataItem
{
items
:
Array
<
TimeChartItem
>
;
name
:
string
;
color
:
string
;
color
?
:
string
;
}
export
type
TimeChartData
=
Array
<
TimeChartDataItem
>
;
ui/shared/chart/utils/gradients.tsx
0 → 100644
View file @
958286c8
import
React
from
'
react
'
;
export
const
BlueLinearGradient
=
{
id
:
'
blue-linear-gradient
'
,
defs
:
()
=>
(
<
linearGradient
id=
"blue-linear-gradient"
>
<
stop
offset=
"0%"
stopColor=
"#4299E1"
/>
<
stop
offset=
"100%"
stopColor=
"#00B5D8"
/>
</
linearGradient
>
),
};
export
const
RainbowGradient
=
{
id
:
'
rainbow-gradient
'
,
defs
:
()
=>
(
<
linearGradient
id=
"rainbow-gradient"
>
<
stop
offset=
"0%"
stopColor=
"rgba(255, 0, 0, 1)"
/>
<
stop
offset=
"10%"
stopColor=
"rgba(255, 154, 0, 1)"
/>
<
stop
offset=
"20%"
stopColor=
"rgba(208, 222, 33, 1)"
/>
<
stop
offset=
"30%"
stopColor=
"rgba(79, 220, 74, 1)"
/>
<
stop
offset=
"40%"
stopColor=
"rgba(63, 218, 216, 1)"
/>
<
stop
offset=
"50%"
stopColor=
"rgba(47, 201, 226, 1)"
/>
<
stop
offset=
"60%"
stopColor=
"rgba(28, 127, 238, 1)"
/>
<
stop
offset=
"70%"
stopColor=
"rgba(95, 21, 242, 1)"
/>
<
stop
offset=
"80%"
stopColor=
"rgba(186, 12, 248, 1)"
/>
<
stop
offset=
"90%"
stopColor=
"rgba(251, 7, 217, 1)"
/>
<
stop
offset=
"100%"
stopColor=
"rgba(255, 0, 0, 1)"
/>
</
linearGradient
>
),
};
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