From 51aad407f54d3b7941bb16305ebbd8e1c904cca9 Mon Sep 17 00:00:00 2001 From: Christopher Henn Date: Fri, 13 Jul 2018 12:54:30 -0700 Subject: [PATCH] Yield histogram plot data to children --- ui/src/shared/components/HistogramChart.tsx | 39 +- ui/src/style/components/histogram-chart.scss | 7 + .../HistogramChart.test.tsx.snap | 477 +++++++++--------- 3 files changed, 279 insertions(+), 244 deletions(-) diff --git a/ui/src/shared/components/HistogramChart.tsx b/ui/src/shared/components/HistogramChart.tsx index b58ba6fc98..190329ce1c 100644 --- a/ui/src/shared/components/HistogramChart.tsx +++ b/ui/src/shared/components/HistogramChart.tsx @@ -26,6 +26,14 @@ const PADDING_TOP = 0.2 const DIGIT_WIDTH = 7 const PERIOD_DIGIT_WIDTH = 4 +interface RenderPropArgs { + xScale: ScaleTime + yScale: ScaleLinear + adjustedWidth: number + adjustedHeight: number + margins: Margins +} + interface Props { data: HistogramData width: number @@ -34,6 +42,7 @@ interface Props { colorScale: ColorScale onBarClick?: (time: string) => void sortBarGroups: SortFn + children?: (args: RenderPropArgs) => JSX.Element } interface State { @@ -56,6 +65,7 @@ class HistogramChart extends PureComponent { colors, onBarClick, sortBarGroups, + children, } = this.props const {margins} = this @@ -76,8 +86,16 @@ class HistogramChart extends PureComponent { const {hoverData} = this.state const {xScale, yScale, adjustedWidth, adjustedHeight, bodyTransform} = this + const renderPropArgs = { + xScale, + yScale, + adjustedWidth, + adjustedHeight, + margins, + } + return ( - <> +
@@ -113,14 +131,17 @@ class HistogramChart extends PureComponent { /> - {hoverData && ( - - )} - +
+ {!!children && children(renderPropArgs)} + {hoverData && ( + + )} +
+
) } diff --git a/ui/src/style/components/histogram-chart.scss b/ui/src/style/components/histogram-chart.scss index e7483ef225..08eebf9a21 100644 --- a/ui/src/style/components/histogram-chart.scss +++ b/ui/src/style/components/histogram-chart.scss @@ -1,5 +1,6 @@ .histogram-chart { user-select: none; + position: relative; } .histogram-chart-bars--bar { @@ -64,3 +65,9 @@ .histogram-chart-tooltip--column:first-child { margin-right: 12px; } + +.histogram-chart--overlays { + position: absolute; + top: 0; + left: 0; +} diff --git a/ui/test/shared/components/__snapshots__/HistogramChart.test.tsx.snap b/ui/test/shared/components/__snapshots__/HistogramChart.test.tsx.snap index a1f6ef7171..c658797a4f 100644 --- a/ui/test/shared/components/__snapshots__/HistogramChart.test.tsx.snap +++ b/ui/test/shared/components/__snapshots__/HistogramChart.test.tsx.snap @@ -177,247 +177,254 @@ exports[`HistogramChart displays the visualization with bars if nonempty data is sortBarGroups={[Function]} width={600} > - - - - - - - - + + + + + + - - - - - - - 0 - - - 0.5 - - - 1 - - - 1.5 - - - 2 - - - .001 - - - .002 - - - - - - - - - - - - - - - - - - - - - - - - + + + + + 0 + + + 0.5 + + + 1 + + + 1.5 + + + 2 + + + .001 + + + .002 + + + + + + + + + + + + + + + + + + + + + + + + +
+
`;