Make margins on charts configurable
This commit is contained in:
parent
4ab843d34f
commit
9bddae17bb
|
@ -9,8 +9,6 @@ import { BinaryContract } from 'common/contract'
|
||||||
import { DAY_MS } from 'common/util/time'
|
import { DAY_MS } from 'common/util/time'
|
||||||
import {
|
import {
|
||||||
TooltipProps,
|
TooltipProps,
|
||||||
MARGIN_X,
|
|
||||||
MARGIN_Y,
|
|
||||||
getDateRange,
|
getDateRange,
|
||||||
getRightmostVisibleDate,
|
getRightmostVisibleDate,
|
||||||
formatDateInRange,
|
formatDateInRange,
|
||||||
|
@ -20,6 +18,10 @@ import { HistoryPoint, SingleValueHistoryChart } from '../generic-charts'
|
||||||
import { Row } from 'web/components/layout/row'
|
import { Row } from 'web/components/layout/row'
|
||||||
import { Avatar } from 'web/components/avatar'
|
import { Avatar } from 'web/components/avatar'
|
||||||
|
|
||||||
|
const MARGIN = { top: 20, right: 10, bottom: 20, left: 40 }
|
||||||
|
const MARGIN_X = MARGIN.left + MARGIN.right
|
||||||
|
const MARGIN_Y = MARGIN.top + MARGIN.bottom
|
||||||
|
|
||||||
const getBetPoints = (bets: Bet[]) => {
|
const getBetPoints = (bets: Bet[]) => {
|
||||||
return sortBy(bets, (b) => b.createdTime).map((b) => ({
|
return sortBy(bets, (b) => b.createdTime).map((b) => ({
|
||||||
x: new Date(b.createdTime),
|
x: new Date(b.createdTime),
|
||||||
|
@ -73,6 +75,7 @@ export const BinaryContractChart = (props: {
|
||||||
<SingleValueHistoryChart
|
<SingleValueHistoryChart
|
||||||
w={width}
|
w={width}
|
||||||
h={height}
|
h={height}
|
||||||
|
margin={MARGIN}
|
||||||
xScale={xScale}
|
xScale={xScale}
|
||||||
yScale={yScale}
|
yScale={yScale}
|
||||||
yKind="percent"
|
yKind="percent"
|
||||||
|
|
|
@ -10,8 +10,6 @@ import { getOutcomeProbability } from 'common/calculate'
|
||||||
import { DAY_MS } from 'common/util/time'
|
import { DAY_MS } from 'common/util/time'
|
||||||
import {
|
import {
|
||||||
TooltipProps,
|
TooltipProps,
|
||||||
MARGIN_X,
|
|
||||||
MARGIN_Y,
|
|
||||||
getDateRange,
|
getDateRange,
|
||||||
getRightmostVisibleDate,
|
getRightmostVisibleDate,
|
||||||
formatPct,
|
formatPct,
|
||||||
|
@ -79,6 +77,10 @@ const CATEGORY_COLORS = [
|
||||||
'#70a560',
|
'#70a560',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
const MARGIN = { top: 20, right: 10, bottom: 20, left: 40 }
|
||||||
|
const MARGIN_X = MARGIN.left + MARGIN.right
|
||||||
|
const MARGIN_Y = MARGIN.top + MARGIN.bottom
|
||||||
|
|
||||||
const getTrackedAnswers = (
|
const getTrackedAnswers = (
|
||||||
contract: FreeResponseContract | MultipleChoiceContract,
|
contract: FreeResponseContract | MultipleChoiceContract,
|
||||||
topN: number
|
topN: number
|
||||||
|
@ -211,6 +213,7 @@ export const ChoiceContractChart = (props: {
|
||||||
<MultiValueHistoryChart
|
<MultiValueHistoryChart
|
||||||
w={width}
|
w={width}
|
||||||
h={height}
|
h={height}
|
||||||
|
margin={MARGIN}
|
||||||
xScale={xScale}
|
xScale={xScale}
|
||||||
yScale={yScale}
|
yScale={yScale}
|
||||||
yKind="percent"
|
yKind="percent"
|
||||||
|
|
|
@ -6,9 +6,13 @@ import { formatLargeNumber } from 'common/util/format'
|
||||||
import { getDpmOutcomeProbabilities } from 'common/calculate-dpm'
|
import { getDpmOutcomeProbabilities } from 'common/calculate-dpm'
|
||||||
import { NumericContract } from 'common/contract'
|
import { NumericContract } from 'common/contract'
|
||||||
import { NUMERIC_GRAPH_COLOR } from 'common/numeric-constants'
|
import { NUMERIC_GRAPH_COLOR } from 'common/numeric-constants'
|
||||||
import { TooltipProps, MARGIN_X, MARGIN_Y, formatPct } from '../helpers'
|
import { TooltipProps, formatPct } from '../helpers'
|
||||||
import { DistributionPoint, DistributionChart } from '../generic-charts'
|
import { DistributionPoint, DistributionChart } from '../generic-charts'
|
||||||
|
|
||||||
|
const MARGIN = { top: 20, right: 10, bottom: 20, left: 40 }
|
||||||
|
const MARGIN_X = MARGIN.left + MARGIN.right
|
||||||
|
const MARGIN_Y = MARGIN.top + MARGIN.bottom
|
||||||
|
|
||||||
const getNumericChartData = (contract: NumericContract) => {
|
const getNumericChartData = (contract: NumericContract) => {
|
||||||
const { totalShares, bucketCount, min, max } = contract
|
const { totalShares, bucketCount, min, max } = contract
|
||||||
const step = (max - min) / bucketCount
|
const step = (max - min) / bucketCount
|
||||||
|
@ -48,6 +52,7 @@ export const NumericContractChart = (props: {
|
||||||
<DistributionChart
|
<DistributionChart
|
||||||
w={width}
|
w={width}
|
||||||
h={height}
|
h={height}
|
||||||
|
margin={MARGIN}
|
||||||
xScale={xScale}
|
xScale={xScale}
|
||||||
yScale={yScale}
|
yScale={yScale}
|
||||||
data={data}
|
data={data}
|
||||||
|
|
|
@ -11,8 +11,6 @@ import { PseudoNumericContract } from 'common/contract'
|
||||||
import { NUMERIC_GRAPH_COLOR } from 'common/numeric-constants'
|
import { NUMERIC_GRAPH_COLOR } from 'common/numeric-constants'
|
||||||
import {
|
import {
|
||||||
TooltipProps,
|
TooltipProps,
|
||||||
MARGIN_X,
|
|
||||||
MARGIN_Y,
|
|
||||||
getDateRange,
|
getDateRange,
|
||||||
getRightmostVisibleDate,
|
getRightmostVisibleDate,
|
||||||
formatDateInRange,
|
formatDateInRange,
|
||||||
|
@ -21,6 +19,10 @@ import { HistoryPoint, SingleValueHistoryChart } from '../generic-charts'
|
||||||
import { Row } from 'web/components/layout/row'
|
import { Row } from 'web/components/layout/row'
|
||||||
import { Avatar } from 'web/components/avatar'
|
import { Avatar } from 'web/components/avatar'
|
||||||
|
|
||||||
|
const MARGIN = { top: 20, right: 10, bottom: 20, left: 40 }
|
||||||
|
const MARGIN_X = MARGIN.left + MARGIN.right
|
||||||
|
const MARGIN_Y = MARGIN.top + MARGIN.bottom
|
||||||
|
|
||||||
// mqp: note that we have an idiosyncratic version of 'log scale'
|
// mqp: note that we have an idiosyncratic version of 'log scale'
|
||||||
// contracts. the values are stored "linearly" and can include zero.
|
// contracts. the values are stored "linearly" and can include zero.
|
||||||
// as a result, we have to do some weird-looking stuff in this code
|
// as a result, we have to do some weird-looking stuff in this code
|
||||||
|
@ -95,6 +97,7 @@ export const PseudoNumericContractChart = (props: {
|
||||||
<SingleValueHistoryChart
|
<SingleValueHistoryChart
|
||||||
w={width}
|
w={width}
|
||||||
h={height}
|
h={height}
|
||||||
|
margin={MARGIN}
|
||||||
xScale={xScale}
|
xScale={xScale}
|
||||||
yScale={yScale}
|
yScale={yScale}
|
||||||
data={data}
|
data={data}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import { range } from 'lodash'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ContinuousScale,
|
ContinuousScale,
|
||||||
|
Margin,
|
||||||
SVGChart,
|
SVGChart,
|
||||||
AreaPath,
|
AreaPath,
|
||||||
AreaWithTopStroke,
|
AreaWithTopStroke,
|
||||||
|
@ -52,13 +53,14 @@ export const DistributionChart = <P extends DistributionPoint>(props: {
|
||||||
w: number
|
w: number
|
||||||
h: number
|
h: number
|
||||||
color: string
|
color: string
|
||||||
|
margin: Margin
|
||||||
xScale: ScaleContinuousNumeric<number, number>
|
xScale: ScaleContinuousNumeric<number, number>
|
||||||
yScale: ScaleContinuousNumeric<number, number>
|
yScale: ScaleContinuousNumeric<number, number>
|
||||||
curve?: CurveFactory
|
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, curve, Tooltip } = props
|
const { data, w, h, color, margin, yScale, curve, Tooltip } = props
|
||||||
|
|
||||||
const [viewXScale, setViewXScale] =
|
const [viewXScale, setViewXScale] =
|
||||||
useState<ScaleContinuousNumeric<number, number>>()
|
useState<ScaleContinuousNumeric<number, number>>()
|
||||||
|
@ -96,6 +98,7 @@ export const DistributionChart = <P extends DistributionPoint>(props: {
|
||||||
<SVGChart
|
<SVGChart
|
||||||
w={w}
|
w={w}
|
||||||
h={h}
|
h={h}
|
||||||
|
margin={margin}
|
||||||
xAxis={xAxis}
|
xAxis={xAxis}
|
||||||
yAxis={yAxis}
|
yAxis={yAxis}
|
||||||
onSelect={onSelect}
|
onSelect={onSelect}
|
||||||
|
@ -119,6 +122,7 @@ export const MultiValueHistoryChart = <P extends MultiPoint>(props: {
|
||||||
w: number
|
w: number
|
||||||
h: number
|
h: number
|
||||||
colors: readonly string[]
|
colors: readonly string[]
|
||||||
|
margin: Margin
|
||||||
xScale: ScaleTime<number, number>
|
xScale: ScaleTime<number, number>
|
||||||
yScale: ScaleContinuousNumeric<number, number>
|
yScale: ScaleContinuousNumeric<number, number>
|
||||||
yKind?: ValueKind
|
yKind?: ValueKind
|
||||||
|
@ -126,7 +130,7 @@ export const MultiValueHistoryChart = <P extends MultiPoint>(props: {
|
||||||
onMouseOver?: (p: P | undefined) => void
|
onMouseOver?: (p: P | undefined) => void
|
||||||
Tooltip?: TooltipComponent<Date, P>
|
Tooltip?: TooltipComponent<Date, P>
|
||||||
}) => {
|
}) => {
|
||||||
const { colors, data, yScale, yKind, w, h, curve, Tooltip } = props
|
const { data, w, h, colors, margin, yScale, yKind, curve, Tooltip } = 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
|
||||||
|
@ -138,7 +142,8 @@ export const MultiValueHistoryChart = <P extends MultiPoint>(props: {
|
||||||
|
|
||||||
const { xAxis, yAxis } = useMemo(() => {
|
const { xAxis, yAxis } = useMemo(() => {
|
||||||
const [min, max] = yScale.domain()
|
const [min, max] = yScale.domain()
|
||||||
const pctTickValues = getTickValues(min, max, h < 200 ? 3 : 5)
|
const nTicks = h < 200 ? 3 : 5
|
||||||
|
const pctTickValues = getTickValues(min, max, nTicks)
|
||||||
const xAxis = axisBottom<Date>(xScale).ticks(w / 100)
|
const xAxis = axisBottom<Date>(xScale).ticks(w / 100)
|
||||||
const yAxis =
|
const yAxis =
|
||||||
yKind === 'percent'
|
yKind === 'percent'
|
||||||
|
@ -146,8 +151,10 @@ export const MultiValueHistoryChart = <P extends MultiPoint>(props: {
|
||||||
.tickValues(pctTickValues)
|
.tickValues(pctTickValues)
|
||||||
.tickFormat((n) => formatPct(n))
|
.tickFormat((n) => formatPct(n))
|
||||||
: yKind === 'm$'
|
: yKind === 'm$'
|
||||||
? axisLeft<number>(yScale).tickFormat((n) => formatMoney(n))
|
? axisLeft<number>(yScale)
|
||||||
: axisLeft<number>(yScale)
|
.ticks(nTicks)
|
||||||
|
.tickFormat((n) => formatMoney(n))
|
||||||
|
: axisLeft<number>(yScale).ticks(nTicks)
|
||||||
return { xAxis, yAxis }
|
return { xAxis, yAxis }
|
||||||
}, [w, h, yKind, xScale, yScale])
|
}, [w, h, yKind, xScale, yScale])
|
||||||
|
|
||||||
|
@ -181,6 +188,7 @@ export const MultiValueHistoryChart = <P extends MultiPoint>(props: {
|
||||||
<SVGChart
|
<SVGChart
|
||||||
w={w}
|
w={w}
|
||||||
h={h}
|
h={h}
|
||||||
|
margin={margin}
|
||||||
xAxis={xAxis}
|
xAxis={xAxis}
|
||||||
yAxis={yAxis}
|
yAxis={yAxis}
|
||||||
onSelect={onSelect}
|
onSelect={onSelect}
|
||||||
|
@ -207,6 +215,7 @@ export const SingleValueHistoryChart = <P extends HistoryPoint>(props: {
|
||||||
w: number
|
w: number
|
||||||
h: number
|
h: number
|
||||||
color: string
|
color: string
|
||||||
|
margin: Margin
|
||||||
xScale: ScaleTime<number, number>
|
xScale: ScaleTime<number, number>
|
||||||
yScale: ScaleContinuousNumeric<number, number>
|
yScale: ScaleContinuousNumeric<number, number>
|
||||||
yKind?: ValueKind
|
yKind?: ValueKind
|
||||||
|
@ -215,7 +224,7 @@ export const SingleValueHistoryChart = <P extends HistoryPoint>(props: {
|
||||||
Tooltip?: TooltipComponent<Date, P>
|
Tooltip?: TooltipComponent<Date, P>
|
||||||
pct?: boolean
|
pct?: boolean
|
||||||
}) => {
|
}) => {
|
||||||
const { color, data, yScale, yKind, w, h, curve, Tooltip } = props
|
const { data, w, h, color, margin, yScale, yKind, curve, Tooltip } = 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
|
||||||
|
@ -226,7 +235,8 @@ export const SingleValueHistoryChart = <P extends HistoryPoint>(props: {
|
||||||
|
|
||||||
const { xAxis, yAxis } = useMemo(() => {
|
const { xAxis, yAxis } = useMemo(() => {
|
||||||
const [min, max] = yScale.domain()
|
const [min, max] = yScale.domain()
|
||||||
const pctTickValues = getTickValues(min, max, h < 200 ? 3 : 5)
|
const nTicks = h < 200 ? 3 : 5
|
||||||
|
const pctTickValues = getTickValues(min, max, nTicks)
|
||||||
const xAxis = axisBottom<Date>(xScale).ticks(w / 100)
|
const xAxis = axisBottom<Date>(xScale).ticks(w / 100)
|
||||||
const yAxis =
|
const yAxis =
|
||||||
yKind === 'percent'
|
yKind === 'percent'
|
||||||
|
@ -234,8 +244,10 @@ export const SingleValueHistoryChart = <P extends HistoryPoint>(props: {
|
||||||
.tickValues(pctTickValues)
|
.tickValues(pctTickValues)
|
||||||
.tickFormat((n) => formatPct(n))
|
.tickFormat((n) => formatPct(n))
|
||||||
: yKind === 'm$'
|
: yKind === 'm$'
|
||||||
? axisLeft<number>(yScale).tickFormat((n) => formatMoney(n))
|
? axisLeft<number>(yScale)
|
||||||
: axisLeft<number>(yScale)
|
.ticks(nTicks)
|
||||||
|
.tickFormat((n) => formatMoney(n))
|
||||||
|
: axisLeft<number>(yScale).ticks(nTicks)
|
||||||
return { xAxis, yAxis }
|
return { xAxis, yAxis }
|
||||||
}, [w, h, yKind, xScale, yScale])
|
}, [w, h, yKind, xScale, yScale])
|
||||||
|
|
||||||
|
@ -261,6 +273,7 @@ export const SingleValueHistoryChart = <P extends HistoryPoint>(props: {
|
||||||
<SVGChart
|
<SVGChart
|
||||||
w={w}
|
w={w}
|
||||||
h={h}
|
h={h}
|
||||||
|
margin={margin}
|
||||||
xAxis={xAxis}
|
xAxis={xAxis}
|
||||||
yAxis={yAxis}
|
yAxis={yAxis}
|
||||||
onSelect={onSelect}
|
onSelect={onSelect}
|
||||||
|
|
|
@ -27,11 +27,12 @@ export interface ContinuousScale<T> extends AxisScale<T> {
|
||||||
export type XScale<P> = P extends Point<infer X, infer _> ? AxisScale<X> : never
|
export type XScale<P> = P extends Point<infer X, infer _> ? AxisScale<X> : never
|
||||||
export type YScale<P> = P extends Point<infer _, infer Y> ? AxisScale<Y> : never
|
export type YScale<P> = P extends Point<infer _, infer Y> ? AxisScale<Y> : never
|
||||||
|
|
||||||
export const MARGIN = { top: 20, right: 10, bottom: 20, left: 40 }
|
export type Margin = {
|
||||||
export const MARGIN_X = MARGIN.right + MARGIN.left
|
top: number
|
||||||
export const MARGIN_Y = MARGIN.top + MARGIN.bottom
|
right: number
|
||||||
const MARGIN_STYLE = `${MARGIN.top}px ${MARGIN.right}px ${MARGIN.bottom}px ${MARGIN.left}px`
|
bottom: number
|
||||||
const MARGIN_XFORM = `translate(${MARGIN.left}, ${MARGIN.top})`
|
left: number
|
||||||
|
}
|
||||||
|
|
||||||
export const XAxis = <X,>(props: { w: number; h: number; axis: Axis<X> }) => {
|
export const XAxis = <X,>(props: { w: number; h: number; axis: Axis<X> }) => {
|
||||||
const { h, axis } = props
|
const { h, axis } = props
|
||||||
|
@ -55,8 +56,6 @@ export const YAxis = <Y,>(props: { w: number; h: number; axis: Axis<Y> }) => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (axisRef.current != null) {
|
if (axisRef.current != null) {
|
||||||
select(axisRef.current)
|
select(axisRef.current)
|
||||||
.transition()
|
|
||||||
.duration(250)
|
|
||||||
.call(axis)
|
.call(axis)
|
||||||
.call((g) =>
|
.call((g) =>
|
||||||
g.selectAll('.tick line').attr('x2', w).attr('stroke-opacity', 0.1)
|
g.selectAll('.tick line').attr('x2', w).attr('stroke-opacity', 0.1)
|
||||||
|
@ -128,18 +127,29 @@ export const SVGChart = <X, TT>(props: {
|
||||||
children: ReactNode
|
children: ReactNode
|
||||||
w: number
|
w: number
|
||||||
h: number
|
h: number
|
||||||
|
margin: Margin
|
||||||
xAxis: Axis<X>
|
xAxis: Axis<X>
|
||||||
yAxis: Axis<number>
|
yAxis: Axis<number>
|
||||||
onSelect?: (ev: D3BrushEvent<any>) => void
|
onSelect?: (ev: D3BrushEvent<any>) => void
|
||||||
onMouseOver?: (mouseX: number, mouseY: number) => TT | undefined
|
onMouseOver?: (mouseX: number, mouseY: number) => TT | undefined
|
||||||
Tooltip?: TooltipComponent<X, TT>
|
Tooltip?: TooltipComponent<X, TT>
|
||||||
}) => {
|
}) => {
|
||||||
const { children, w, h, xAxis, yAxis, onMouseOver, onSelect, Tooltip } = props
|
const {
|
||||||
|
children,
|
||||||
|
w,
|
||||||
|
h,
|
||||||
|
margin,
|
||||||
|
xAxis,
|
||||||
|
yAxis,
|
||||||
|
onMouseOver,
|
||||||
|
onSelect,
|
||||||
|
Tooltip,
|
||||||
|
} = props
|
||||||
const [mouse, setMouse] = useState<{ x: number; y: number; data: TT }>()
|
const [mouse, setMouse] = useState<{ x: number; y: number; data: TT }>()
|
||||||
const tooltipMeasure = useMeasureSize()
|
const tooltipMeasure = useMeasureSize()
|
||||||
const overlayRef = useRef<SVGGElement>(null)
|
const overlayRef = useRef<SVGGElement>(null)
|
||||||
const innerW = w - MARGIN_X
|
const innerW = w - (margin.left + margin.right)
|
||||||
const innerH = h - MARGIN_Y
|
const innerH = h - (margin.top + margin.bottom)
|
||||||
const clipPathId = useMemo(() => nanoid(), [])
|
const clipPathId = useMemo(() => nanoid(), [])
|
||||||
|
|
||||||
const justSelected = useRef(false)
|
const justSelected = useRef(false)
|
||||||
|
@ -194,6 +204,7 @@ export const SVGChart = <X, TT>(props: {
|
||||||
{mouse && Tooltip && (
|
{mouse && Tooltip && (
|
||||||
<TooltipContainer
|
<TooltipContainer
|
||||||
setElem={tooltipMeasure.setElem}
|
setElem={tooltipMeasure.setElem}
|
||||||
|
margin={margin}
|
||||||
pos={getTooltipPosition(
|
pos={getTooltipPosition(
|
||||||
mouse.x,
|
mouse.x,
|
||||||
mouse.y,
|
mouse.y,
|
||||||
|
@ -215,7 +226,7 @@ export const SVGChart = <X, TT>(props: {
|
||||||
<clipPath id={clipPathId}>
|
<clipPath id={clipPathId}>
|
||||||
<rect x={0} y={0} width={innerW} height={innerH} />
|
<rect x={0} y={0} width={innerW} height={innerH} />
|
||||||
</clipPath>
|
</clipPath>
|
||||||
<g transform={MARGIN_XFORM}>
|
<g transform={`translate(${margin.left}, ${margin.top})`}>
|
||||||
<XAxis axis={xAxis} w={innerW} h={innerH} />
|
<XAxis axis={xAxis} w={innerW} h={innerH} />
|
||||||
<YAxis axis={yAxis} w={innerW} h={innerH} />
|
<YAxis axis={yAxis} w={innerW} h={innerH} />
|
||||||
<g clipPath={`url(#${clipPathId})`}>{children}</g>
|
<g clipPath={`url(#${clipPathId})`}>{children}</g>
|
||||||
|
@ -275,10 +286,11 @@ export type TooltipComponent<X, T> = React.ComponentType<TooltipProps<X, T>>
|
||||||
export const TooltipContainer = (props: {
|
export const TooltipContainer = (props: {
|
||||||
setElem: (e: HTMLElement | null) => void
|
setElem: (e: HTMLElement | null) => void
|
||||||
pos: TooltipPosition
|
pos: TooltipPosition
|
||||||
|
margin: Margin
|
||||||
className?: string
|
className?: string
|
||||||
children: React.ReactNode
|
children: React.ReactNode
|
||||||
}) => {
|
}) => {
|
||||||
const { setElem, pos, className, children } = props
|
const { setElem, pos, margin, className, children } = props
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
ref={setElem}
|
ref={setElem}
|
||||||
|
@ -286,7 +298,10 @@ export const TooltipContainer = (props: {
|
||||||
className,
|
className,
|
||||||
'pointer-events-none absolute z-10 whitespace-pre rounded border border-gray-200 bg-white/80 p-2 px-4 py-2 text-xs sm:text-sm'
|
'pointer-events-none absolute z-10 whitespace-pre rounded border border-gray-200 bg-white/80 p-2 px-4 py-2 text-xs sm:text-sm'
|
||||||
)}
|
)}
|
||||||
style={{ margin: MARGIN_STYLE, ...pos }}
|
style={{
|
||||||
|
margin: `${margin.top}px ${margin.right}px ${margin.bottom}px ${margin.left}px`,
|
||||||
|
...pos,
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -6,9 +6,13 @@ import dayjs from 'dayjs'
|
||||||
import { formatPercent } from 'common/util/format'
|
import { formatPercent } from 'common/util/format'
|
||||||
import { Row } from '../layout/row'
|
import { Row } from '../layout/row'
|
||||||
import { HistoryPoint, SingleValueHistoryChart } from './generic-charts'
|
import { HistoryPoint, SingleValueHistoryChart } from './generic-charts'
|
||||||
import { TooltipProps, MARGIN_X, MARGIN_Y } from './helpers'
|
import { TooltipProps } from './helpers'
|
||||||
import { SizedContainer } from 'web/components/sized-container'
|
import { SizedContainer } from 'web/components/sized-container'
|
||||||
|
|
||||||
|
const MARGIN = { top: 20, right: 10, bottom: 20, left: 40 }
|
||||||
|
const MARGIN_X = MARGIN.left + MARGIN.right
|
||||||
|
const MARGIN_Y = MARGIN.top + MARGIN.bottom
|
||||||
|
|
||||||
const getPoints = (startDate: number, dailyValues: number[]) => {
|
const getPoints = (startDate: number, dailyValues: number[]) => {
|
||||||
const startDateDayJs = dayjs(startDate)
|
const startDateDayJs = dayjs(startDate)
|
||||||
return dailyValues.map((y, i) => ({
|
return dailyValues.map((y, i) => ({
|
||||||
|
@ -63,6 +67,7 @@ export function DailyChart(props: {
|
||||||
<SingleValueHistoryChart
|
<SingleValueHistoryChart
|
||||||
w={width}
|
w={width}
|
||||||
h={height}
|
h={height}
|
||||||
|
margin={MARGIN}
|
||||||
xScale={scaleTime([minDate, maxDate], [0, width - MARGIN_X])}
|
xScale={scaleTime([minDate, maxDate], [0, width - MARGIN_X])}
|
||||||
yScale={scaleLinear([0, maxValue], [height - MARGIN_Y, 0])}
|
yScale={scaleLinear([0, maxValue], [height - MARGIN_Y, 0])}
|
||||||
yKind={pct ? 'percent' : 'amount'}
|
yKind={pct ? 'percent' : 'amount'}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user