Show x value in numeric graph's tooltip
This commit is contained in:
parent
f85b10e517
commit
1c73bba908
|
@ -114,17 +114,11 @@ export function DailyPercentChart(props: {
|
||||||
function Tooltip(props: { point: Point }) {
|
function Tooltip(props: { point: Point }) {
|
||||||
const { point } = props
|
const { point } = props
|
||||||
return (
|
return (
|
||||||
<Col
|
<Col className="border border-gray-300 bg-white py-2 px-3">
|
||||||
className="border bg-white py-1 px-3 "
|
|
||||||
style={{
|
|
||||||
border: '1px solid #ccc',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
<div
|
||||||
key={point.id}
|
className="pb-1"
|
||||||
style={{
|
style={{
|
||||||
color: point.serieColor,
|
color: point.serieColor,
|
||||||
padding: '3px 0',
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<strong>{point.serieId}</strong> {point.data.yFormatted}
|
<strong>{point.serieId}</strong> {point.data.yFormatted}
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
import { DatumValue } from '@nivo/core'
|
import { DatumValue } from '@nivo/core'
|
||||||
import { ResponsiveLine } from '@nivo/line'
|
import { Point, ResponsiveLine } from '@nivo/line'
|
||||||
import { NUMERIC_GRAPH_COLOR } from 'common/numeric-constants'
|
import { NUMERIC_GRAPH_COLOR } from 'common/numeric-constants'
|
||||||
import { memo } from 'react'
|
import { memo } from 'react'
|
||||||
import { range } from 'lodash'
|
import { range } from 'lodash'
|
||||||
import { getDpmOutcomeProbabilities } from '../../../common/calculate-dpm'
|
import { getDpmOutcomeProbabilities } from '../../../common/calculate-dpm'
|
||||||
import { NumericContract } from '../../../common/contract'
|
import { NumericContract } from '../../../common/contract'
|
||||||
import { useWindowSize } from '../../hooks/use-window-size'
|
import { useWindowSize } from '../../hooks/use-window-size'
|
||||||
|
import { Col } from '../layout/col'
|
||||||
|
import { formatLargeNumber } from 'common/util/format'
|
||||||
|
|
||||||
export const NumericGraph = memo(function NumericGraph(props: {
|
export const NumericGraph = memo(function NumericGraph(props: {
|
||||||
contract: NumericContract
|
contract: NumericContract
|
||||||
|
@ -62,6 +64,10 @@ export const NumericGraph = memo(function NumericGraph(props: {
|
||||||
colors={{ datum: 'color' }}
|
colors={{ datum: 'color' }}
|
||||||
pointSize={0}
|
pointSize={0}
|
||||||
enableSlices="x"
|
enableSlices="x"
|
||||||
|
sliceTooltip={({ slice }) => {
|
||||||
|
const point = slice.points[0]
|
||||||
|
return <Tooltip point={point} />
|
||||||
|
}}
|
||||||
enableGridX={!!width && width >= 800}
|
enableGridX={!!width && width >= 800}
|
||||||
enableArea
|
enableArea
|
||||||
margin={{ top: 20, right: 28, bottom: 22, left: 50 }}
|
margin={{ top: 20, right: 28, bottom: 22, left: 50 }}
|
||||||
|
@ -74,3 +80,20 @@ function formatPercent(y: DatumValue) {
|
||||||
const p = Math.round(+y * 100) / 100
|
const p = Math.round(+y * 100) / 100
|
||||||
return `${p}%`
|
return `${p}%`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Tooltip(props: { point: Point }) {
|
||||||
|
const { point } = props
|
||||||
|
return (
|
||||||
|
<Col className="border border-gray-300 bg-white py-2 px-3">
|
||||||
|
<div
|
||||||
|
className="pb-1"
|
||||||
|
style={{
|
||||||
|
color: point.serieColor,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<strong>{point.serieId}</strong> {point.data.yFormatted}
|
||||||
|
</div>
|
||||||
|
<div>{formatLargeNumber(+point.data.x)}</div>
|
||||||
|
</Col>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user