Yield histogram plot data to children
parent
531560d971
commit
51aad407f5
|
@ -26,6 +26,14 @@ const PADDING_TOP = 0.2
|
||||||
const DIGIT_WIDTH = 7
|
const DIGIT_WIDTH = 7
|
||||||
const PERIOD_DIGIT_WIDTH = 4
|
const PERIOD_DIGIT_WIDTH = 4
|
||||||
|
|
||||||
|
interface RenderPropArgs {
|
||||||
|
xScale: ScaleTime<number, number>
|
||||||
|
yScale: ScaleLinear<number, number>
|
||||||
|
adjustedWidth: number
|
||||||
|
adjustedHeight: number
|
||||||
|
margins: Margins
|
||||||
|
}
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
data: HistogramData
|
data: HistogramData
|
||||||
width: number
|
width: number
|
||||||
|
@ -34,6 +42,7 @@ interface Props {
|
||||||
colorScale: ColorScale
|
colorScale: ColorScale
|
||||||
onBarClick?: (time: string) => void
|
onBarClick?: (time: string) => void
|
||||||
sortBarGroups: SortFn
|
sortBarGroups: SortFn
|
||||||
|
children?: (args: RenderPropArgs) => JSX.Element
|
||||||
}
|
}
|
||||||
|
|
||||||
interface State {
|
interface State {
|
||||||
|
@ -56,6 +65,7 @@ class HistogramChart extends PureComponent<Props, State> {
|
||||||
colors,
|
colors,
|
||||||
onBarClick,
|
onBarClick,
|
||||||
sortBarGroups,
|
sortBarGroups,
|
||||||
|
children,
|
||||||
} = this.props
|
} = this.props
|
||||||
const {margins} = this
|
const {margins} = this
|
||||||
|
|
||||||
|
@ -76,8 +86,16 @@ class HistogramChart extends PureComponent<Props, State> {
|
||||||
const {hoverData} = this.state
|
const {hoverData} = this.state
|
||||||
const {xScale, yScale, adjustedWidth, adjustedHeight, bodyTransform} = this
|
const {xScale, yScale, adjustedWidth, adjustedHeight, bodyTransform} = this
|
||||||
|
|
||||||
|
const renderPropArgs = {
|
||||||
|
xScale,
|
||||||
|
yScale,
|
||||||
|
adjustedWidth,
|
||||||
|
adjustedHeight,
|
||||||
|
margins,
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<div className="histogram-chart">
|
||||||
<svg width={width} height={height} className="histogram-chart">
|
<svg width={width} height={height} className="histogram-chart">
|
||||||
<defs>
|
<defs>
|
||||||
<clipPath id="histogram-chart--bars-clip">
|
<clipPath id="histogram-chart--bars-clip">
|
||||||
|
@ -113,6 +131,8 @@ class HistogramChart extends PureComponent<Props, State> {
|
||||||
/>
|
/>
|
||||||
</g>
|
</g>
|
||||||
</svg>
|
</svg>
|
||||||
|
<div className="histogram-chart--overlays">
|
||||||
|
{!!children && children(renderPropArgs)}
|
||||||
{hoverData && (
|
{hoverData && (
|
||||||
<HistogramChartTooltip
|
<HistogramChartTooltip
|
||||||
data={hoverData}
|
data={hoverData}
|
||||||
|
@ -120,7 +140,8 @@ class HistogramChart extends PureComponent<Props, State> {
|
||||||
colors={colors}
|
colors={colors}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</>
|
</div>
|
||||||
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
.histogram-chart {
|
.histogram-chart {
|
||||||
user-select: none;
|
user-select: none;
|
||||||
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
.histogram-chart-bars--bar {
|
.histogram-chart-bars--bar {
|
||||||
|
@ -64,3 +65,9 @@
|
||||||
.histogram-chart-tooltip--column:first-child {
|
.histogram-chart-tooltip--column:first-child {
|
||||||
margin-right: 12px;
|
margin-right: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.histogram-chart--overlays {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
}
|
||||||
|
|
|
@ -176,6 +176,9 @@ exports[`HistogramChart displays the visualization with bars if nonempty data is
|
||||||
height={400}
|
height={400}
|
||||||
sortBarGroups={[Function]}
|
sortBarGroups={[Function]}
|
||||||
width={600}
|
width={600}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="histogram-chart"
|
||||||
>
|
>
|
||||||
<svg
|
<svg
|
||||||
className="histogram-chart"
|
className="histogram-chart"
|
||||||
|
@ -419,5 +422,9 @@ exports[`HistogramChart displays the visualization with bars if nonempty data is
|
||||||
</HistogramChartBars>
|
</HistogramChartBars>
|
||||||
</g>
|
</g>
|
||||||
</svg>
|
</svg>
|
||||||
|
<div
|
||||||
|
className="histogram-chart--overlays"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</HistogramChart>
|
</HistogramChart>
|
||||||
`;
|
`;
|
||||||
|
|
Loading…
Reference in New Issue