Commit e3d8599d authored by Greg Bugyis's avatar Greg Bugyis Committed by GitHub

fix: [TokenDetails] Glyph placement on line chart (#4525)

* Modify line curve on token price chart to fix inconsistency on steep drops/increases and glyph placement

* Make curve required on LineChart

* Add curve to SparkLine chart

* Remove dependency: d3-curve-circlecornders - no longer used

* Drop d3-curve-circlecorner from react-app-env
Co-authored-by: default avatargbugyis <greg@bugyis.com>
parent 77ee69ad
...@@ -175,7 +175,6 @@ ...@@ -175,7 +175,6 @@
"clsx": "^1.1.1", "clsx": "^1.1.1",
"copy-to-clipboard": "^3.2.0", "copy-to-clipboard": "^3.2.0",
"d3": "^7.6.1", "d3": "^7.6.1",
"d3-curve-circlecorners": "^0.1.6",
"ethers": "^5.1.4", "ethers": "^5.1.4",
"firebase": "^9.1.3", "firebase": "^9.1.3",
"focus-visible": "^5.2.0", "focus-visible": "^5.2.0",
......
import { Group } from '@visx/group' import { Group } from '@visx/group'
import { LinePath } from '@visx/shape' import { LinePath } from '@visx/shape'
import { CurveFactory } from 'd3' import { CurveFactory } from 'd3'
import { radius } from 'd3-curve-circlecorners'
import React from 'react' import React from 'react'
import { ReactNode } from 'react' import { ReactNode } from 'react'
import { useTheme } from 'styled-components/macro' import { useTheme } from 'styled-components/macro'
...@@ -12,7 +11,7 @@ interface LineChartProps<T> { ...@@ -12,7 +11,7 @@ interface LineChartProps<T> {
getX: (t: T) => number getX: (t: T) => number
getY: (t: T) => number getY: (t: T) => number
marginTop?: number marginTop?: number
curve?: CurveFactory curve: CurveFactory
color?: Color color?: Color
strokeWidth: number strokeWidth: number
children?: ReactNode children?: ReactNode
...@@ -37,7 +36,7 @@ function LineChart<T>({ ...@@ -37,7 +36,7 @@ function LineChart<T>({
<svg width={width} height={height}> <svg width={width} height={height}>
<Group top={marginTop}> <Group top={marginTop}>
<LinePath <LinePath
curve={curve ?? radius(0.25)} curve={curve}
stroke={color ?? theme.accentAction} stroke={color ?? theme.accentAction}
strokeWidth={strokeWidth} strokeWidth={strokeWidth}
data={data} data={data}
......
import { scaleLinear } from 'd3' import { curveCardinalOpen, scaleLinear } from 'd3'
import React from 'react' import React from 'react'
import { useTheme } from 'styled-components/macro' import { useTheme } from 'styled-components/macro'
...@@ -37,6 +37,7 @@ function SparklineChart({ width, height }: SparklineChartProps) { ...@@ -37,6 +37,7 @@ function SparklineChart({ width, height }: SparklineChartProps) {
data={pricePoints} data={pricePoints}
getX={(p: PricePoint) => timeScale(p.timestamp)} getX={(p: PricePoint) => timeScale(p.timestamp)}
getY={(p: PricePoint) => rdScale(p.value)} getY={(p: PricePoint) => rdScale(p.value)}
curve={curveCardinalOpen.tension(0.9)}
marginTop={0} marginTop={0}
color={isPositive ? theme.accentSuccess : theme.accentFailure} color={isPositive ? theme.accentSuccess : theme.accentFailure}
strokeWidth={1.5} strokeWidth={1.5}
......
...@@ -5,7 +5,7 @@ import { EventType } from '@visx/event/lib/types' ...@@ -5,7 +5,7 @@ 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/Tokens/state' import { filterTimeAtom } from 'components/Tokens/state'
import { bisect, curveBasis, NumberValue, scaleLinear } from 'd3' import { bisect, curveCardinalOpen, NumberValue, scaleLinear } from 'd3'
import { useTokenPriceQuery } from 'graphql/data/TokenPriceQuery' import { useTokenPriceQuery } from 'graphql/data/TokenPriceQuery'
import { TimePeriod } from 'graphql/data/TopTokenQuery' import { TimePeriod } from 'graphql/data/TopTokenQuery'
import { useActiveLocale } from 'hooks/useActiveLocale' import { useActiveLocale } from 'hooks/useActiveLocale'
...@@ -232,6 +232,9 @@ export function PriceChart({ width, height, token }: PriceChartProps) { ...@@ -232,6 +232,9 @@ export function PriceChart({ width, height, token }: PriceChartProps) {
const crosshairEdgeMax = width * 0.85 const crosshairEdgeMax = width * 0.85
const crosshairAtEdge = !!crosshair && crosshair > crosshairEdgeMax const crosshairAtEdge = !!crosshair && crosshair > crosshairEdgeMax
/* Default curve doesn't look good for the ALL chart */
const curveTension = timePeriod === TimePeriod.ALL ? 0.75 : 0.9
return ( return (
<> <>
<ChartHeader> <ChartHeader>
...@@ -246,8 +249,7 @@ export function PriceChart({ width, height, token }: PriceChartProps) { ...@@ -246,8 +249,7 @@ export function PriceChart({ width, height, token }: PriceChartProps) {
getX={(p: PricePoint) => timeScale(p.timestamp)} getX={(p: PricePoint) => timeScale(p.timestamp)}
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 */ curve={curveCardinalOpen.tension(curveTension)}
curve={timePeriod === TimePeriod.ALL ? curveBasis : undefined}
strokeWidth={2} strokeWidth={2}
width={graphWidth} width={graphWidth}
height={graphHeight} height={graphHeight}
......
...@@ -26,10 +26,6 @@ declare module 'multihashes' { ...@@ -26,10 +26,6 @@ declare module 'multihashes' {
declare function toB58String(hash: Uint8Array): string declare function toB58String(hash: Uint8Array): string
} }
declare module 'd3-curve-circlecorners' {
declare function radius(r: number): d3.CurveFactory
}
declare module 'babel-plugin-relay/macro' { declare module 'babel-plugin-relay/macro' {
export { graphql as default } from 'react-relay' export { graphql as default } from 'react-relay'
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment