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
879161c1
Commit
879161c1
authored
Nov 18, 2022
by
tom
Committed by
isstuev
Nov 18, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chart fixes
parent
c2183e47
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
27 additions
and
21 deletions
+27
-21
ChainIndicatorChart.tsx
ui/home/indicators/ChainIndicatorChart.tsx
+3
-6
ChainIndicatorChartContainer.tsx
ui/home/indicators/ChainIndicatorChartContainer.tsx
+3
-4
indicators.tsx
ui/home/indicators/utils/indicators.tsx
+0
-4
ChartArea.tsx
ui/shared/chart/ChartArea.tsx
+19
-5
gradients.tsx
ui/shared/chart/utils/gradients.tsx
+2
-2
No files found.
ui/home/indicators/ChainIndicatorChart.tsx
View file @
879161c1
import
{
useToken
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
type
{
ChainIndicatorChartData
}
from
'
./types
'
;
import
type
{
ChainIndicatorChartData
}
from
'
./types
'
;
...
@@ -8,7 +9,6 @@ import ChartOverlay from 'ui/shared/chart/ChartOverlay';
...
@@ -8,7 +9,6 @@ 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
useChartSize
from
'
ui/shared/chart/useChartSize
'
;
import
useTimeChartController
from
'
ui/shared/chart/useTimeChartController
'
;
import
useTimeChartController
from
'
ui/shared/chart/useTimeChartController
'
;
import
{
BlueLineGradient
}
from
'
ui/shared/chart/utils/gradients
'
;
interface
Props
{
interface
Props
{
data
:
ChainIndicatorChartData
;
data
:
ChainIndicatorChartData
;
...
@@ -20,6 +20,7 @@ const CHART_MARGIN = { bottom: 0, left: 10, right: 10, top: 0 };
...
@@ -20,6 +20,7 @@ const CHART_MARGIN = { bottom: 0, left: 10, right: 10, top: 0 };
const
ChainIndicatorChart
=
({
data
}:
Props
)
=>
{
const
ChainIndicatorChart
=
({
data
}:
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
lineColor
=
useToken
(
'
colors
'
,
'
blue.500
'
);
const
{
width
,
height
,
innerWidth
,
innerHeight
}
=
useChartSize
(
ref
.
current
,
CHART_MARGIN
);
const
{
width
,
height
,
innerWidth
,
innerHeight
}
=
useChartSize
(
ref
.
current
,
CHART_MARGIN
);
const
{
xScale
,
yScale
}
=
useTimeChartController
({
const
{
xScale
,
yScale
}
=
useTimeChartController
({
...
@@ -30,13 +31,9 @@ const ChainIndicatorChart = ({ data }: Props) => {
...
@@ -30,13 +31,9 @@ const ChainIndicatorChart = ({ data }: Props) => {
return
(
return
(
<
svg
width=
{
width
||
'
100%
'
}
height=
{
height
||
'
100%
'
}
ref=
{
ref
}
cursor=
"pointer"
>
<
svg
width=
{
width
||
'
100%
'
}
height=
{
height
||
'
100%
'
}
ref=
{
ref
}
cursor=
"pointer"
>
<
defs
>
<
BlueLineGradient
.
defs
/>
</
defs
>
<
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=
{
width
?
1
:
0
}
>
<
ChartArea
<
ChartArea
data=
{
data
[
0
].
items
}
data=
{
data
[
0
].
items
}
color=
{
data
[
0
].
color
}
xScale=
{
xScale
}
xScale=
{
xScale
}
yScale=
{
yScale
}
yScale=
{
yScale
}
/>
/>
...
@@ -44,7 +41,7 @@ const ChainIndicatorChart = ({ data }: Props) => {
...
@@ -44,7 +41,7 @@ const ChainIndicatorChart = ({ data }: Props) => {
data=
{
data
[
0
].
items
}
data=
{
data
[
0
].
items
}
xScale=
{
xScale
}
xScale=
{
xScale
}
yScale=
{
yScale
}
yScale=
{
yScale
}
stroke=
{
`url(#${ BlueLineGradient.id })`
}
stroke=
{
lineColor
}
animation=
"left"
animation=
"left"
strokeWidth=
{
3
}
strokeWidth=
{
3
}
/>
/>
...
...
ui/home/indicators/ChainIndicatorChartContainer.tsx
View file @
879161c1
import
{
Flex
}
from
'
@chakra-ui/react
'
;
import
{
Flex
,
Spinner
}
from
'
@chakra-ui/react
'
;
import
type
{
UseQueryResult
}
from
'
@tanstack/react-query
'
;
import
type
{
UseQueryResult
}
from
'
@tanstack/react-query
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
type
{
ChainIndicatorChartData
}
from
'
./types
'
;
import
type
{
ChainIndicatorChartData
}
from
'
./types
'
;
import
ChartLineLoader
from
'
ui/shared/chart/ChartLineLoader
'
;
import
DataFetchAlert
from
'
ui/shared/DataFetchAlert
'
;
import
DataFetchAlert
from
'
ui/shared/DataFetchAlert
'
;
import
ChainIndicatorChart
from
'
./ChainIndicatorChart
'
;
import
ChainIndicatorChart
from
'
./ChainIndicatorChart
'
;
...
@@ -15,7 +14,7 @@ const ChainIndicatorChartContainer = ({ data, isError, isLoading }: Props) => {
...
@@ -15,7 +14,7 @@ const ChainIndicatorChartContainer = ({ data, isError, isLoading }: Props) => {
const
content
=
(()
=>
{
const
content
=
(()
=>
{
if
(
isLoading
)
{
if
(
isLoading
)
{
return
<
ChartLineLoader
mt
=
"auto"
/>;
return
<
Spinner
size=
"md"
m
=
"auto"
/>;
}
}
if
(
isError
)
{
if
(
isError
)
{
...
@@ -25,7 +24,7 @@ const ChainIndicatorChartContainer = ({ data, isError, isLoading }: Props) => {
...
@@ -25,7 +24,7 @@ const ChainIndicatorChartContainer = ({ data, isError, isLoading }: Props) => {
return
<
ChainIndicatorChart
data=
{
data
}
/>;
return
<
ChainIndicatorChart
data=
{
data
}
/>;
})();
})();
return
<
Flex
h=
{
{
base
:
'
150px
'
,
lg
:
'
250px
'
}
}
alignItems=
"flex-start"
>
{
content
}
</
Flex
>;
return
<
Flex
h=
{
{
base
:
'
150px
'
,
lg
:
'
auto
'
}
}
minH=
"150px"
alignItems=
"flex-start"
flexGrow=
{
1
}
>
{
content
}
</
Flex
>;
};
};
export
default
React
.
memo
(
ChainIndicatorChartContainer
);
export
default
React
.
memo
(
ChainIndicatorChartContainer
);
ui/home/indicators/utils/indicators.tsx
View file @
879161c1
...
@@ -10,7 +10,6 @@ import txIcon from 'icons/transactions.svg';
...
@@ -10,7 +10,6 @@ import txIcon from 'icons/transactions.svg';
import
{
shortenNumberWithLetter
}
from
'
lib/formatters
'
;
import
{
shortenNumberWithLetter
}
from
'
lib/formatters
'
;
import
{
sortByDateDesc
}
from
'
ui/shared/chart/utils/sorts
'
;
import
{
sortByDateDesc
}
from
'
ui/shared/chart/utils/sorts
'
;
import
TokenLogo
from
'
ui/shared/TokenLogo
'
;
import
TokenLogo
from
'
ui/shared/TokenLogo
'
;
const
CHART_COLOR
=
'
#439AE2
'
;
const
dailyTxsIndicator
:
TChainIndicator
<
QueryKeys
.
chartsTxs
>
=
{
const
dailyTxsIndicator
:
TChainIndicator
<
QueryKeys
.
chartsTxs
>
=
{
id
:
'
daily_txs
'
,
id
:
'
daily_txs
'
,
...
@@ -26,7 +25,6 @@ const dailyTxsIndicator: TChainIndicator<QueryKeys.chartsTxs> = {
...
@@ -26,7 +25,6 @@ const dailyTxsIndicator: TChainIndicator<QueryKeys.chartsTxs> = {
.
map
((
item
)
=>
({
date
:
new
Date
(
item
.
date
),
value
:
item
.
tx_count
}))
.
map
((
item
)
=>
({
date
:
new
Date
(
item
.
date
),
value
:
item
.
tx_count
}))
.
sort
(
sortByDateDesc
),
.
sort
(
sortByDateDesc
),
name
:
'
Tx/day
'
,
name
:
'
Tx/day
'
,
color
:
CHART_COLOR
,
valueFormatter
:
(
x
)
=>
shortenNumberWithLetter
(
x
,
undefined
,
{
maximumFractionDigits
:
2
}),
valueFormatter
:
(
x
)
=>
shortenNumberWithLetter
(
x
,
undefined
,
{
maximumFractionDigits
:
2
}),
}
]),
}
]),
},
},
...
@@ -46,7 +44,6 @@ const coinPriceIndicator: TChainIndicator<QueryKeys.chartsMarket> = {
...
@@ -46,7 +44,6 @@ const coinPriceIndicator: TChainIndicator<QueryKeys.chartsMarket> = {
.
map
((
item
)
=>
({
date
:
new
Date
(
item
.
date
),
value
:
Number
(
item
.
closing_price
)
}))
.
map
((
item
)
=>
({
date
:
new
Date
(
item
.
date
),
value
:
Number
(
item
.
closing_price
)
}))
.
sort
(
sortByDateDesc
),
.
sort
(
sortByDateDesc
),
name
:
`
${
appConfig
.
network
.
currency
.
symbol
}
price`
,
name
:
`
${
appConfig
.
network
.
currency
.
symbol
}
price`
,
color
:
CHART_COLOR
,
valueFormatter
:
(
x
)
=>
'
$
'
+
x
.
toLocaleString
(
undefined
,
{
minimumFractionDigits
:
2
,
maximumFractionDigits
:
6
}),
valueFormatter
:
(
x
)
=>
'
$
'
+
x
.
toLocaleString
(
undefined
,
{
minimumFractionDigits
:
2
,
maximumFractionDigits
:
6
}),
}
]),
}
]),
},
},
...
@@ -67,7 +64,6 @@ const marketPriceIndicator: TChainIndicator<QueryKeys.chartsMarket> = {
...
@@ -67,7 +64,6 @@ const marketPriceIndicator: TChainIndicator<QueryKeys.chartsMarket> = {
.
map
((
item
)
=>
({
date
:
new
Date
(
item
.
date
),
value
:
Number
(
item
.
closing_price
)
*
Number
(
response
.
available_supply
)
}))
.
map
((
item
)
=>
({
date
:
new
Date
(
item
.
date
),
value
:
Number
(
item
.
closing_price
)
*
Number
(
response
.
available_supply
)
}))
.
sort
(
sortByDateDesc
),
.
sort
(
sortByDateDesc
),
name
:
'
Market cap
'
,
name
:
'
Market cap
'
,
color
:
CHART_COLOR
,
valueFormatter
:
(
x
)
=>
'
$
'
+
shortenNumberWithLetter
(
x
,
undefined
,
{
maximumFractionDigits
:
0
}),
valueFormatter
:
(
x
)
=>
'
$
'
+
shortenNumberWithLetter
(
x
,
undefined
,
{
maximumFractionDigits
:
0
}),
}
]),
}
]),
},
},
...
...
ui/shared/chart/ChartArea.tsx
View file @
879161c1
import
{
useColorModeValue
,
useToken
}
from
'
@chakra-ui/react
'
;
import
{
useColorModeValue
,
useToken
,
useTheme
}
from
'
@chakra-ui/react
'
;
import
{
transparentize
}
from
'
@chakra-ui/theme-tools
'
;
import
*
as
d3
from
'
d3
'
;
import
*
as
d3
from
'
d3
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
...
@@ -14,7 +15,13 @@ interface Props extends React.SVGProps<SVGPathElement> {
...
@@ -14,7 +15,13 @@ interface Props extends React.SVGProps<SVGPathElement> {
const
ChartArea
=
({
xScale
,
yScale
,
color
,
data
,
disableAnimation
,
...
props
}:
Props
)
=>
{
const
ChartArea
=
({
xScale
,
yScale
,
color
,
data
,
disableAnimation
,
...
props
}:
Props
)
=>
{
const
ref
=
React
.
useRef
(
null
);
const
ref
=
React
.
useRef
(
null
);
const
theme
=
useTheme
();
const
gradientStopColor
=
useToken
(
'
colors
'
,
useColorModeValue
(
'
whiteAlpha.200
'
,
'
blackAlpha.100
'
));
const
gradientStopColor
=
useToken
(
'
colors
'
,
useColorModeValue
(
'
whiteAlpha.200
'
,
'
blackAlpha.100
'
));
const
defaultGradient
=
{
startColor
:
useToken
(
'
colors
'
,
useColorModeValue
(
'
blue.100
'
,
'
blue.400
'
)),
stopColor
:
useToken
(
'
colors
'
,
transparentize
(
useColorModeValue
(
'
blue.100
'
,
'
blue.400
'
),
0
)(
theme
)),
};
React
.
useEffect
(()
=>
{
React
.
useEffect
(()
=>
{
if
(
disableAnimation
)
{
if
(
disableAnimation
)
{
...
@@ -38,12 +45,19 @@ const ChartArea = ({ xScale, yScale, color, data, disableAnimation, ...props }:
...
@@ -38,12 +45,19 @@ const ChartArea = ({ xScale, yScale, color, data, disableAnimation, ...props }:
return
(
return
(
<>
<>
<
path
ref=
{
ref
}
d=
{
d
}
fill=
{
color
?
`url(#gradient-${ color })`
:
'
none
'
}
opacity=
{
0
}
{
...
props
}
/>
<
path
ref=
{
ref
}
d=
{
d
}
fill=
{
color
?
`url(#gradient-${ color })`
:
'
url(#gradient-chart-area-default)
'
}
opacity=
{
0
}
{
...
props
}
/>
{
color
&&
(
{
color
?
(
<
defs
>
<
defs
>
<
linearGradient
id=
{
`gradient-${ color }`
}
x1=
"0%"
x2=
"0%"
y1=
"0%"
y2=
"100%"
>
<
linearGradient
id=
{
`gradient-${ color }`
}
x1=
"0%"
x2=
"0%"
y1=
"0%"
y2=
"100%"
>
<
stop
offset=
"2%"
stopColor=
{
color
}
/>
<
stop
offset=
"20%"
stopColor=
{
color
}
/>
<
stop
offset=
"78%"
stopColor=
{
gradientStopColor
}
/>
<
stop
offset=
"100%"
stopColor=
{
gradientStopColor
}
/>
</
linearGradient
>
</
defs
>
)
:
(
<
defs
>
<
linearGradient
id=
"gradient-chart-area-default"
x1=
"0%"
x2=
"0%"
y1=
"0%"
y2=
"100%"
>
<
stop
offset=
"0%"
stopColor=
{
defaultGradient
.
startColor
}
/>
<
stop
offset=
"100%"
stopColor=
{
defaultGradient
.
stopColor
}
/>
</
linearGradient
>
</
linearGradient
>
</
defs
>
</
defs
>
)
}
)
}
...
...
ui/shared/chart/utils/gradients.tsx
View file @
879161c1
import
React
from
'
react
'
;
import
React
from
'
react
'
;
export
const
BlueLineGradient
=
{
export
const
BlueLineGradient
=
{
id
:
'
blue-line
ar
-gradient
'
,
id
:
'
blue-line-gradient
'
,
defs
:
()
=>
(
defs
:
()
=>
(
<
linearGradient
id=
"blue-line
ar
-gradient"
>
<
linearGradient
id=
"blue-line-gradient"
>
<
stop
offset=
"0%"
stopColor=
"#4299E1"
/>
<
stop
offset=
"0%"
stopColor=
"#4299E1"
/>
<
stop
offset=
"100%"
stopColor=
"#00B5D8"
/>
<
stop
offset=
"100%"
stopColor=
"#00B5D8"
/>
</
linearGradient
>
</
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