Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
interface
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
LuckySwap
interface
Commits
5d4b25f4
Unverified
Commit
5d4b25f4
authored
Oct 06, 2022
by
cartcrom
Committed by
GitHub
Oct 06, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: chart states polish (#4819)
* init * finished missing data component * finished feature
parent
c88d7c88
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
119 additions
and
75 deletions
+119
-75
PriceChart.tsx
src/components/Tokens/TokenDetails/PriceChart.tsx
+119
-75
No files found.
src/components/Tokens/TokenDetails/PriceChart.tsx
View file @
5d4b25f4
import
{
Trans
}
from
'
@lingui/macro
'
import
{
AxisBottom
,
TickFormatter
}
from
'
@visx/axis
'
import
{
AxisBottom
,
TickFormatter
}
from
'
@visx/axis
'
import
{
localPoint
}
from
'
@visx/event
'
import
{
localPoint
}
from
'
@visx/event
'
import
{
EventType
}
from
'
@visx/event/lib/types
'
import
{
EventType
}
from
'
@visx/event/lib/types
'
...
@@ -10,8 +11,8 @@ import { PricePoint } from 'graphql/data/Token'
...
@@ -10,8 +11,8 @@ import { PricePoint } from 'graphql/data/Token'
import
{
TimePeriod
}
from
'
graphql/data/util
'
import
{
TimePeriod
}
from
'
graphql/data/util
'
import
{
useActiveLocale
}
from
'
hooks/useActiveLocale
'
import
{
useActiveLocale
}
from
'
hooks/useActiveLocale
'
import
{
useAtom
}
from
'
jotai
'
import
{
useAtom
}
from
'
jotai
'
import
{
useCallback
,
useEffect
,
useMemo
,
useState
}
from
'
react
'
import
{
ReactNode
,
useCallback
,
useEffect
,
useMemo
,
useState
}
from
'
react
'
import
{
ArrowDownRight
,
ArrowUpRight
}
from
'
react-feather
'
import
{
ArrowDownRight
,
ArrowUpRight
,
TrendingUp
}
from
'
react-feather
'
import
styled
,
{
useTheme
}
from
'
styled-components/macro
'
import
styled
,
{
useTheme
}
from
'
styled-components/macro
'
import
{
import
{
dayHourFormatter
,
dayHourFormatter
,
...
@@ -248,17 +249,13 @@ export function PriceChart({ width, height, prices }: PriceChartProps) {
...
@@ -248,17 +249,13 @@ export function PriceChart({ width, height, prices }: PriceChartProps) {
setDisplayPrice
(
endingPrice
)
setDisplayPrice
(
endingPrice
)
},
[
setCrosshair
,
setDisplayPrice
,
endingPrice
])
},
[
setCrosshair
,
setDisplayPrice
,
endingPrice
])
// TODO: Display no data available error
if
(
!
prices
)
{
return
null
}
const
[
tickFormatter
,
crosshairDateFormatter
,
ticks
]
=
tickFormat
(
timePeriod
,
locale
)
const
[
tickFormatter
,
crosshairDateFormatter
,
ticks
]
=
tickFormat
(
timePeriod
,
locale
)
const
delta
=
calculateDelta
(
startingPrice
.
value
,
displayPrice
.
value
)
const
delta
=
calculateDelta
(
startingPrice
.
value
,
displayPrice
.
value
)
const
formattedDelta
=
formatDelta
(
delta
)
const
formattedDelta
=
formatDelta
(
delta
)
const
arrow
=
getDeltaArrow
(
delta
)
const
arrow
=
getDeltaArrow
(
delta
)
const
crosshairEdgeMax
=
width
*
0.85
const
crosshairEdgeMax
=
width
*
0.85
const
crosshairAtEdge
=
!!
crosshair
&&
crosshair
>
crosshairEdgeMax
const
crosshairAtEdge
=
!!
crosshair
&&
crosshair
>
crosshairEdgeMax
const
hasData
=
prices
&&
prices
.
length
>
0
/*
/*
* Default curve doesn't look good for the HOUR chart.
* Default curve doesn't look good for the HOUR chart.
...
@@ -266,7 +263,6 @@ export function PriceChart({ width, height, prices }: PriceChartProps) {
...
@@ -266,7 +263,6 @@ export function PriceChart({ width, height, prices }: PriceChartProps) {
* making it unacceptable for shorter durations / smaller variances.
* making it unacceptable for shorter durations / smaller variances.
*/
*/
const
curveTension
=
timePeriod
===
TimePeriod
.
HOUR
?
1
:
0.9
const
curveTension
=
timePeriod
===
TimePeriod
.
HOUR
?
1
:
0.9
return
(
return
(
<>
<>
<
ChartHeader
>
<
ChartHeader
>
...
@@ -276,6 +272,13 @@ export function PriceChart({ width, height, prices }: PriceChartProps) {
...
@@ -276,6 +272,13 @@ export function PriceChart({ width, height, prices }: PriceChartProps) {
<
ArrowCell
>
{
arrow
}
</
ArrowCell
>
<
ArrowCell
>
{
arrow
}
</
ArrowCell
>
</
DeltaContainer
>
</
DeltaContainer
>
</
ChartHeader
>
</
ChartHeader
>
{
!
hasData
?
(
<
MissingPriceChart
width=
{
width
}
height=
{
graphHeight
}
message=
{
prices
&&
prices
.
length
===
0
?
<
NoV3DataMessage
/>
:
<
MissingDataMessage
/>
}
/>
)
:
(
<
AnimatedInLineChart
<
AnimatedInLineChart
data=
{
prices
}
data=
{
prices
}
getX=
{
(
p
:
PricePoint
)
=>
timeScale
(
p
.
timestamp
)
}
getX=
{
(
p
:
PricePoint
)
=>
timeScale
(
p
.
timestamp
)
}
...
@@ -346,6 +349,7 @@ export function PriceChart({ width, height, prices }: PriceChartProps) {
...
@@ -346,6 +349,7 @@ export function PriceChart({ width, height, prices }: PriceChartProps) {
onMouseLeave=
{
resetDisplay
}
onMouseLeave=
{
resetDisplay
}
/>
/>
</
AnimatedInLineChart
>
</
AnimatedInLineChart
>
)
}
<
TimeOptionsWrapper
>
<
TimeOptionsWrapper
>
<
TimeOptionsContainer
>
<
TimeOptionsContainer
>
{
ORDERED_TIMES
.
map
((
time
)
=>
(
{
ORDERED_TIMES
.
map
((
time
)
=>
(
...
@@ -365,4 +369,44 @@ export function PriceChart({ width, height, prices }: PriceChartProps) {
...
@@ -365,4 +369,44 @@ export function PriceChart({ width, height, prices }: PriceChartProps) {
)
)
}
}
const
StyledMissingChart
=
styled
.
svg
`
text {
font-size: 12px;
font-weight: 400;
}
`
const
chartBottomPadding
=
15
const
NoV3DataMessage
=
()
=>
(
<
Trans
>
This token doesn
'
t have chart data because it hasn
'
t been traded on Uniswap v3
</
Trans
>
)
const
MissingDataMessage
=
()
=>
<
Trans
>
Missing chart data
</
Trans
>
function
MissingPriceChart
({
width
,
height
,
message
}:
{
width
:
number
;
height
:
number
;
message
:
ReactNode
})
{
const
theme
=
useTheme
()
const
midPoint
=
height
/
2
+
45
return
(
<
StyledMissingChart
width=
{
width
}
height=
{
height
}
>
<
path
d=
{
`M 0 ${midPoint} Q 104 ${midPoint - 70}, 208 ${midPoint} T 416 ${midPoint}
M 416 ${midPoint} Q 520 ${midPoint - 70}, 624 ${midPoint} T 832 ${midPoint}`
}
stroke=
{
theme
.
backgroundOutline
}
fill=
"transparent"
strokeWidth=
"2"
/>
<
TrendingUp
stroke=
{
theme
.
textTertiary
}
x=
{
0
}
size=
{
12
}
y=
{
height
-
chartBottomPadding
-
10
}
/>
<
text
y=
{
height
-
chartBottomPadding
}
x=
"20"
fill=
{
theme
.
textTertiary
}
>
{
message
||
<
Trans
>
Missing chart data
</
Trans
>
}
</
text
>
<
path
d=
{
`M 0 ${height - 1}, ${width} ${height - 1}`
}
stroke=
{
theme
.
backgroundOutline
}
fill=
"transparent"
strokeWidth=
"1"
/>
</
StyledMissingChart
>
)
}
export
default
PriceChart
export
default
PriceChart
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