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
8b3da3db
Unverified
Commit
8b3da3db
authored
Sep 22, 2021
by
Justin Domingue
Committed by
GitHub
Sep 22, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: infinite loop when brushing (#2422)
* refine comparison method * adjust comment
parent
8bb1983a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
3 deletions
+11
-3
Brush.tsx
src/components/LiquidityChartRangeInput/Brush.tsx
+11
-3
No files found.
src/components/LiquidityChartRangeInput/Brush.tsx
View file @
8b3da3db
...
@@ -43,8 +43,16 @@ const FLIP_HANDLE_THRESHOLD_PX = 20
...
@@ -43,8 +43,16 @@ const FLIP_HANDLE_THRESHOLD_PX = 20
// margin to prevent tick snapping from putting the brush off screen
// margin to prevent tick snapping from putting the brush off screen
const
BRUSH_EXTENT_MARGIN_PX
=
2
const
BRUSH_EXTENT_MARGIN_PX
=
2
const
compare
=
(
a1
:
[
number
,
number
],
a2
:
[
number
,
number
],
xScale
:
ScaleLinear
<
number
,
number
>
):
boolean
=>
/**
xScale
(
a1
[
0
])
!==
xScale
(
a2
[
0
])
||
xScale
(
a1
[
1
])
!==
xScale
(
a2
[
1
])
* Returns true if every element in `a` maps to the
* same pixel coordinate as elements in `b`
*/
const
compare
=
(
a
:
[
number
,
number
],
b
:
[
number
,
number
],
xScale
:
ScaleLinear
<
number
,
number
>
):
boolean
=>
{
// normalize pixels to 1 decimals
const
aNorm
=
a
.
map
((
x
)
=>
xScale
(
x
).
toFixed
(
1
))
const
bNorm
=
b
.
map
((
x
)
=>
xScale
(
x
).
toFixed
(
1
))
return
aNorm
.
every
((
v
,
i
)
=>
v
===
bNorm
[
i
])
}
export
const
Brush
=
({
export
const
Brush
=
({
id
,
id
,
...
@@ -91,7 +99,7 @@ export const Brush = ({
...
@@ -91,7 +99,7 @@ export const Brush = ({
const
scaled
=
(
selection
as
[
number
,
number
]).
map
(
xScale
.
invert
)
as
[
number
,
number
]
const
scaled
=
(
selection
as
[
number
,
number
]).
map
(
xScale
.
invert
)
as
[
number
,
number
]
// avoid infinite render loop by checking for change
// avoid infinite render loop by checking for change
if
(
type
===
'
end
'
&&
compare
(
brushExtent
,
scaled
,
xScale
))
{
if
(
type
===
'
end
'
&&
!
compare
(
brushExtent
,
scaled
,
xScale
))
{
setBrushExtent
(
scaled
,
mode
)
setBrushExtent
(
scaled
,
mode
)
}
}
...
...
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