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
baf00f20
Unverified
Commit
baf00f20
authored
Aug 10, 2022
by
Vignesh Mohankumar
Committed by
GitHub
Aug 10, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: use filterTimeAtom for PriceChart (#4323)
* feat: use filterTimeAtom * comment
parent
1309b1f1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
7 deletions
+10
-7
PriceChart.tsx
src/components/Charts/PriceChart.tsx
+10
-7
No files found.
src/components/Charts/PriceChart.tsx
View file @
baf00f20
...
@@ -3,10 +3,12 @@ import { localPoint } from '@visx/event'
...
@@ -3,10 +3,12 @@ import { localPoint } from '@visx/event'
import
{
EventType
}
from
'
@visx/event/lib/types
'
import
{
EventType
}
from
'
@visx/event/lib/types
'
import
{
GlyphCircle
}
from
'
@visx/glyph
'
import
{
GlyphCircle
}
from
'
@visx/glyph
'
import
{
Line
}
from
'
@visx/shape
'
import
{
Line
}
from
'
@visx/shape
'
import
{
filterTimeAtom
}
from
'
components/Explore/state
'
import
{
bisect
,
curveBasis
,
NumberValue
,
scaleLinear
}
from
'
d3
'
import
{
bisect
,
curveBasis
,
NumberValue
,
scaleLinear
}
from
'
d3
'
import
{
useActiveLocale
}
from
'
hooks/useActiveLocale
'
import
{
useActiveLocale
}
from
'
hooks/useActiveLocale
'
import
useTheme
from
'
hooks/useTheme
'
import
useTheme
from
'
hooks/useTheme
'
import
{
TimePeriod
}
from
'
hooks/useTopTokens
'
import
{
TimePeriod
}
from
'
hooks/useTopTokens
'
import
{
useAtom
}
from
'
jotai
'
import
{
useCallback
,
useState
}
from
'
react
'
import
{
useCallback
,
useState
}
from
'
react
'
import
{
ArrowDownRight
,
ArrowUpRight
}
from
'
react-feather
'
import
{
ArrowDownRight
,
ArrowUpRight
}
from
'
react-feather
'
import
styled
from
'
styled-components/macro
'
import
styled
from
'
styled-components/macro
'
...
@@ -23,6 +25,7 @@ import {
...
@@ -23,6 +25,7 @@ import {
import
data
from
'
./data.json
'
import
data
from
'
./data.json
'
import
LineChart
from
'
./LineChart
'
import
LineChart
from
'
./LineChart
'
// TODO: This should be combined with the logic in TimeSelector.
const
TIME_DISPLAYS
:
[
TimePeriod
,
string
][]
=
[
const
TIME_DISPLAYS
:
[
TimePeriod
,
string
][]
=
[
[
TimePeriod
.
hour
,
'
1H
'
],
[
TimePeriod
.
hour
,
'
1H
'
],
[
TimePeriod
.
day
,
'
1D
'
],
[
TimePeriod
.
day
,
'
1D
'
],
...
@@ -110,10 +113,10 @@ function getTicks(startTimestamp: number, endTimestamp: number, numTicks = 5) {
...
@@ -110,10 +113,10 @@ function getTicks(startTimestamp: number, endTimestamp: number, numTicks = 5) {
function
tickFormat
(
function
tickFormat
(
startTimestamp
:
number
,
startTimestamp
:
number
,
endTimestamp
:
number
,
endTimestamp
:
number
,
activeT
imePeriod
:
TimePeriod
,
t
imePeriod
:
TimePeriod
,
locale
:
string
locale
:
string
):
[
TickFormatter
<
NumberValue
>
,
(
v
:
number
)
=>
string
,
number
[]]
{
):
[
TickFormatter
<
NumberValue
>
,
(
v
:
number
)
=>
string
,
number
[]]
{
switch
(
activeT
imePeriod
)
{
switch
(
t
imePeriod
)
{
case
TimePeriod
.
hour
:
case
TimePeriod
.
hour
:
return
[
hourFormatter
(
locale
),
dayHourFormatter
(
locale
),
getTicks
(
startTimestamp
,
endTimestamp
)]
return
[
hourFormatter
(
locale
),
dayHourFormatter
(
locale
),
getTicks
(
startTimestamp
,
endTimestamp
)]
case
TimePeriod
.
day
:
case
TimePeriod
.
day
:
...
@@ -139,12 +142,12 @@ interface PriceChartProps {
...
@@ -139,12 +142,12 @@ interface PriceChartProps {
}
}
export
function
PriceChart
({
width
,
height
}:
PriceChartProps
)
{
export
function
PriceChart
({
width
,
height
}:
PriceChartProps
)
{
const
[
activeTimePeriod
,
setTimePeriod
]
=
useState
(
TimePeriod
.
hour
)
const
[
timePeriod
,
setTimePeriod
]
=
useAtom
(
filterTimeAtom
)
const
locale
=
useActiveLocale
()
const
locale
=
useActiveLocale
()
const
theme
=
useTheme
()
const
theme
=
useTheme
()
/* TODO: Implement API calls & cache to use here */
/* TODO: Implement API calls & cache to use here */
const
pricePoints
=
data
[
activeT
imePeriod
]
const
pricePoints
=
data
[
t
imePeriod
]
const
startingPrice
=
pricePoints
[
0
]
const
startingPrice
=
pricePoints
[
0
]
const
endingPrice
=
pricePoints
[
pricePoints
.
length
-
1
]
const
endingPrice
=
pricePoints
[
pricePoints
.
length
-
1
]
const
initialState
=
{
pricePoint
:
endingPrice
,
xCoordinate
:
null
}
const
initialState
=
{
pricePoint
:
endingPrice
,
xCoordinate
:
null
}
...
@@ -187,7 +190,7 @@ export function PriceChart({ width, height }: PriceChartProps) {
...
@@ -187,7 +190,7 @@ export function PriceChart({ width, height }: PriceChartProps) {
const
[
tickFormatter
,
crosshairDateFormatter
,
ticks
]
=
tickFormat
(
const
[
tickFormatter
,
crosshairDateFormatter
,
ticks
]
=
tickFormat
(
startingPrice
.
timestamp
,
startingPrice
.
timestamp
,
endingPrice
.
timestamp
,
endingPrice
.
timestamp
,
activeT
imePeriod
,
t
imePeriod
,
locale
locale
)
)
const
[
delta
,
arrow
]
=
getDelta
(
startingPrice
.
value
,
selected
.
pricePoint
.
value
)
const
[
delta
,
arrow
]
=
getDelta
(
startingPrice
.
value
,
selected
.
pricePoint
.
value
)
...
@@ -209,7 +212,7 @@ export function PriceChart({ width, height }: PriceChartProps) {
...
@@ -209,7 +212,7 @@ export function PriceChart({ width, height }: PriceChartProps) {
getY=
{
(
p
:
PricePoint
)
=>
rdScale
(
p
.
value
)
}
getY=
{
(
p
:
PricePoint
)
=>
rdScale
(
p
.
value
)
}
marginTop=
{
margin
.
top
}
marginTop=
{
margin
.
top
}
/* Default curve doesn't look good for the ALL chart */
/* Default curve doesn't look good for the ALL chart */
curve=
{
activeT
imePeriod
===
TimePeriod
.
all
?
curveBasis
:
undefined
}
curve=
{
t
imePeriod
===
TimePeriod
.
all
?
curveBasis
:
undefined
}
strokeWidth=
{
2
}
strokeWidth=
{
2
}
width=
{
graphWidth
}
width=
{
graphWidth
}
height=
{
graphHeight
}
height=
{
graphHeight
}
...
@@ -273,7 +276,7 @@ export function PriceChart({ width, height }: PriceChartProps) {
...
@@ -273,7 +276,7 @@ export function PriceChart({ width, height }: PriceChartProps) {
</
LineChart
>
</
LineChart
>
<
TimeOptionsContainer
>
<
TimeOptionsContainer
>
{
TIME_DISPLAYS
.
map
(([
value
,
display
])
=>
(
{
TIME_DISPLAYS
.
map
(([
value
,
display
])
=>
(
<
TimeButton
key=
{
display
}
active=
{
activeT
imePeriod
===
value
}
onClick=
{
()
=>
setTimePeriod
(
value
)
}
>
<
TimeButton
key=
{
display
}
active=
{
t
imePeriod
===
value
}
onClick=
{
()
=>
setTimePeriod
(
value
)
}
>
{
display
}
{
display
}
</
TimeButton
>
</
TimeButton
>
))
}
))
}
...
...
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