Make curve configurable on generic charts
This commit is contained in:
parent
39638a3888
commit
794fffec6a
|
@ -1,6 +1,7 @@
|
||||||
import { useMemo } from 'react'
|
import { useMemo } from 'react'
|
||||||
import { last, sortBy } from 'lodash'
|
import { last, sortBy } from 'lodash'
|
||||||
import { scaleTime, scaleLinear } from 'd3-scale'
|
import { scaleTime, scaleLinear } from 'd3-scale'
|
||||||
|
import { curveStepAfter } from 'd3-shape'
|
||||||
|
|
||||||
import { Bet } from 'common/bet'
|
import { Bet } from 'common/bet'
|
||||||
import { getProbability, getInitialProbability } from 'common/calculate'
|
import { getProbability, getInitialProbability } from 'common/calculate'
|
||||||
|
@ -76,6 +77,7 @@ export const BinaryContractChart = (props: {
|
||||||
yScale={yScale}
|
yScale={yScale}
|
||||||
data={data}
|
data={data}
|
||||||
color="#11b981"
|
color="#11b981"
|
||||||
|
curve={curveStepAfter}
|
||||||
onMouseOver={onMouseOver}
|
onMouseOver={onMouseOver}
|
||||||
Tooltip={BinaryChartTooltip}
|
Tooltip={BinaryChartTooltip}
|
||||||
pct
|
pct
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { useMemo } from 'react'
|
import { useMemo } from 'react'
|
||||||
import { last, sum, sortBy, groupBy } from 'lodash'
|
import { last, sum, sortBy, groupBy } from 'lodash'
|
||||||
import { scaleTime, scaleLinear } from 'd3-scale'
|
import { scaleTime, scaleLinear } from 'd3-scale'
|
||||||
|
import { curveStepAfter } from 'd3-shape'
|
||||||
|
|
||||||
import { Bet } from 'common/bet'
|
import { Bet } from 'common/bet'
|
||||||
import { Answer } from 'common/answer'
|
import { Answer } from 'common/answer'
|
||||||
|
@ -214,6 +215,7 @@ export const ChoiceContractChart = (props: {
|
||||||
yScale={yScale}
|
yScale={yScale}
|
||||||
data={data}
|
data={data}
|
||||||
colors={CATEGORY_COLORS}
|
colors={CATEGORY_COLORS}
|
||||||
|
curve={curveStepAfter}
|
||||||
onMouseOver={onMouseOver}
|
onMouseOver={onMouseOver}
|
||||||
Tooltip={ChoiceTooltip}
|
Tooltip={ChoiceTooltip}
|
||||||
pct
|
pct
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { useMemo } from 'react'
|
import { useMemo } from 'react'
|
||||||
import { last, sortBy } from 'lodash'
|
import { last, sortBy } from 'lodash'
|
||||||
import { scaleTime, scaleLog, scaleLinear } from 'd3-scale'
|
import { scaleTime, scaleLog, scaleLinear } from 'd3-scale'
|
||||||
|
import { curveStepAfter } from 'd3-shape'
|
||||||
|
|
||||||
import { Bet } from 'common/bet'
|
import { Bet } from 'common/bet'
|
||||||
import { DAY_MS } from 'common/util/time'
|
import { DAY_MS } from 'common/util/time'
|
||||||
|
@ -97,6 +98,7 @@ export const PseudoNumericContractChart = (props: {
|
||||||
xScale={xScale}
|
xScale={xScale}
|
||||||
yScale={yScale}
|
yScale={yScale}
|
||||||
data={data}
|
data={data}
|
||||||
|
curve={curveStepAfter}
|
||||||
onMouseOver={onMouseOver}
|
onMouseOver={onMouseOver}
|
||||||
Tooltip={PseudoNumericChartTooltip}
|
Tooltip={PseudoNumericChartTooltip}
|
||||||
color={NUMERIC_GRAPH_COLOR}
|
color={NUMERIC_GRAPH_COLOR}
|
||||||
|
|
|
@ -4,11 +4,11 @@ import { axisBottom, axisLeft } from 'd3-axis'
|
||||||
import { D3BrushEvent } from 'd3-brush'
|
import { D3BrushEvent } from 'd3-brush'
|
||||||
import { ScaleTime, ScaleContinuousNumeric } from 'd3-scale'
|
import { ScaleTime, ScaleContinuousNumeric } from 'd3-scale'
|
||||||
import {
|
import {
|
||||||
|
CurveFactory,
|
||||||
|
SeriesPoint,
|
||||||
curveLinear,
|
curveLinear,
|
||||||
curveStepAfter,
|
|
||||||
stack,
|
stack,
|
||||||
stackOrderReverse,
|
stackOrderReverse,
|
||||||
SeriesPoint,
|
|
||||||
} from 'd3-shape'
|
} from 'd3-shape'
|
||||||
import { range } from 'lodash'
|
import { range } from 'lodash'
|
||||||
|
|
||||||
|
@ -52,10 +52,11 @@ export const DistributionChart = <P extends DistributionPoint>(props: {
|
||||||
color: string
|
color: string
|
||||||
xScale: ScaleContinuousNumeric<number, number>
|
xScale: ScaleContinuousNumeric<number, number>
|
||||||
yScale: ScaleContinuousNumeric<number, number>
|
yScale: ScaleContinuousNumeric<number, number>
|
||||||
|
curve?: CurveFactory
|
||||||
onMouseOver?: (p: P | undefined) => void
|
onMouseOver?: (p: P | undefined) => void
|
||||||
Tooltip?: TooltipComponent<number, P>
|
Tooltip?: TooltipComponent<number, P>
|
||||||
}) => {
|
}) => {
|
||||||
const { color, data, yScale, w, h, Tooltip } = props
|
const { color, data, yScale, w, h, curve, Tooltip } = props
|
||||||
|
|
||||||
const [viewXScale, setViewXScale] =
|
const [viewXScale, setViewXScale] =
|
||||||
useState<ScaleContinuousNumeric<number, number>>()
|
useState<ScaleContinuousNumeric<number, number>>()
|
||||||
|
@ -100,7 +101,7 @@ export const DistributionChart = <P extends DistributionPoint>(props: {
|
||||||
px={px}
|
px={px}
|
||||||
py0={py0}
|
py0={py0}
|
||||||
py1={py1}
|
py1={py1}
|
||||||
curve={curveLinear}
|
curve={curve ?? curveLinear}
|
||||||
/>
|
/>
|
||||||
</SVGChart>
|
</SVGChart>
|
||||||
)
|
)
|
||||||
|
@ -113,11 +114,12 @@ export const MultiValueHistoryChart = <P extends MultiPoint>(props: {
|
||||||
colors: readonly string[]
|
colors: readonly string[]
|
||||||
xScale: ScaleTime<number, number>
|
xScale: ScaleTime<number, number>
|
||||||
yScale: ScaleContinuousNumeric<number, number>
|
yScale: ScaleContinuousNumeric<number, number>
|
||||||
|
curve?: CurveFactory
|
||||||
onMouseOver?: (p: P | undefined) => void
|
onMouseOver?: (p: P | undefined) => void
|
||||||
Tooltip?: TooltipComponent<Date, P>
|
Tooltip?: TooltipComponent<Date, P>
|
||||||
pct?: boolean
|
pct?: boolean
|
||||||
}) => {
|
}) => {
|
||||||
const { colors, data, yScale, w, h, Tooltip, pct } = props
|
const { colors, data, yScale, w, h, curve, Tooltip, pct } = props
|
||||||
|
|
||||||
const [viewXScale, setViewXScale] = useState<ScaleTime<number, number>>()
|
const [viewXScale, setViewXScale] = useState<ScaleTime<number, number>>()
|
||||||
const xScale = viewXScale ?? props.xScale
|
const xScale = viewXScale ?? props.xScale
|
||||||
|
@ -177,7 +179,7 @@ export const MultiValueHistoryChart = <P extends MultiPoint>(props: {
|
||||||
px={px}
|
px={px}
|
||||||
py0={py0}
|
py0={py0}
|
||||||
py1={py1}
|
py1={py1}
|
||||||
curve={curveStepAfter}
|
curve={curve ?? curveLinear}
|
||||||
fill={colors[i]}
|
fill={colors[i]}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
@ -192,11 +194,12 @@ export const SingleValueHistoryChart = <P extends HistoryPoint>(props: {
|
||||||
color: string
|
color: string
|
||||||
xScale: ScaleTime<number, number>
|
xScale: ScaleTime<number, number>
|
||||||
yScale: ScaleContinuousNumeric<number, number>
|
yScale: ScaleContinuousNumeric<number, number>
|
||||||
|
curve?: CurveFactory
|
||||||
onMouseOver?: (p: P | undefined) => void
|
onMouseOver?: (p: P | undefined) => void
|
||||||
Tooltip?: TooltipComponent<Date, P>
|
Tooltip?: TooltipComponent<Date, P>
|
||||||
pct?: boolean
|
pct?: boolean
|
||||||
}) => {
|
}) => {
|
||||||
const { color, data, yScale, w, h, Tooltip, pct } = props
|
const { color, data, yScale, w, h, curve, Tooltip, pct } = props
|
||||||
|
|
||||||
const [viewXScale, setViewXScale] = useState<ScaleTime<number, number>>()
|
const [viewXScale, setViewXScale] = useState<ScaleTime<number, number>>()
|
||||||
const xScale = viewXScale ?? props.xScale
|
const xScale = viewXScale ?? props.xScale
|
||||||
|
@ -246,7 +249,7 @@ export const SingleValueHistoryChart = <P extends HistoryPoint>(props: {
|
||||||
px={px}
|
px={px}
|
||||||
py0={py0}
|
py0={py0}
|
||||||
py1={py1}
|
py1={py1}
|
||||||
curve={curveStepAfter}
|
curve={curve ?? curveLinear}
|
||||||
/>
|
/>
|
||||||
</SVGChart>
|
</SVGChart>
|
||||||
)
|
)
|
||||||
|
|
|
@ -10,7 +10,7 @@ import {
|
||||||
import { pointer, select } from 'd3-selection'
|
import { pointer, select } from 'd3-selection'
|
||||||
import { Axis, AxisScale } from 'd3-axis'
|
import { Axis, AxisScale } from 'd3-axis'
|
||||||
import { brushX, D3BrushEvent } from 'd3-brush'
|
import { brushX, D3BrushEvent } from 'd3-brush'
|
||||||
import { area, line, curveStepAfter, CurveFactory } from 'd3-shape'
|
import { area, line, CurveFactory } from 'd3-shape'
|
||||||
import { nanoid } from 'nanoid'
|
import { nanoid } from 'nanoid'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import clsx from 'clsx'
|
import clsx from 'clsx'
|
||||||
|
@ -73,11 +73,11 @@ const LinePathInternal = <P,>(
|
||||||
data: P[]
|
data: P[]
|
||||||
px: number | ((p: P) => number)
|
px: number | ((p: P) => number)
|
||||||
py: number | ((p: P) => number)
|
py: number | ((p: P) => number)
|
||||||
curve?: CurveFactory
|
curve: CurveFactory
|
||||||
} & SVGProps<SVGPathElement>
|
} & SVGProps<SVGPathElement>
|
||||||
) => {
|
) => {
|
||||||
const { data, px, py, curve, ...rest } = props
|
const { data, px, py, curve, ...rest } = props
|
||||||
const d3Line = line<P>(px, py).curve(curve ?? curveStepAfter)
|
const d3Line = line<P>(px, py).curve(curve)
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
return <path {...rest} fill="none" d={d3Line(data)!} />
|
return <path {...rest} fill="none" d={d3Line(data)!} />
|
||||||
}
|
}
|
||||||
|
@ -89,11 +89,11 @@ const AreaPathInternal = <P,>(
|
||||||
px: number | ((p: P) => number)
|
px: number | ((p: P) => number)
|
||||||
py0: number | ((p: P) => number)
|
py0: number | ((p: P) => number)
|
||||||
py1: number | ((p: P) => number)
|
py1: number | ((p: P) => number)
|
||||||
curve?: CurveFactory
|
curve: CurveFactory
|
||||||
} & SVGProps<SVGPathElement>
|
} & SVGProps<SVGPathElement>
|
||||||
) => {
|
) => {
|
||||||
const { data, px, py0, py1, curve, ...rest } = props
|
const { data, px, py0, py1, curve, ...rest } = props
|
||||||
const d3Area = area<P>(px, py0, py1).curve(curve ?? curveStepAfter)
|
const d3Area = area<P>(px, py0, py1).curve(curve)
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
return <path {...rest} d={d3Area(data)!} />
|
return <path {...rest} d={d3Area(data)!} />
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@ export const AreaWithTopStroke = <P,>(props: {
|
||||||
px: number | ((p: P) => number)
|
px: number | ((p: P) => number)
|
||||||
py0: number | ((p: P) => number)
|
py0: number | ((p: P) => number)
|
||||||
py1: number | ((p: P) => number)
|
py1: number | ((p: P) => number)
|
||||||
curve?: CurveFactory
|
curve: CurveFactory
|
||||||
}) => {
|
}) => {
|
||||||
const { color, data, px, py0, py1, curve } = props
|
const { color, data, px, py0, py1, curve } = props
|
||||||
return (
|
return (
|
||||||
|
|
Loading…
Reference in New Issue
Block a user