Clone SingleStat inside of Dygraph to get access to staticLegendHeight

This way the SingleStat doesn’t obscure the static legend if it is
present
pull/2891/head
Alex P 2018-02-28 15:00:48 -08:00
parent fcb15f10d2
commit 2f45dad9e4
4 changed files with 38 additions and 18 deletions

View File

@ -301,8 +301,9 @@ class Dygraph extends Component {
render() {
const {isHidden, staticLegendHeight} = this.state
const {staticLegend} = this.props
const {staticLegend, children} = this.props
const nestedGraph = (children && children.length && children[0]) || children
let dygraphStyle = {...this.props.containerStyle, zIndex: '2'}
if (staticLegend) {
const cellVerticalPadding = 16
@ -344,12 +345,13 @@ class Dygraph extends Component {
this.handleReceiveStaticLegendHeight
}
/>}
{nestedGraph && React.cloneElement(nestedGraph, {staticLegendHeight})}
</div>
)
}
}
const {array, arrayOf, bool, func, shape, string} = PropTypes
const {array, arrayOf, bool, func, node, shape, string} = PropTypes
Dygraph.defaultProps = {
axes: {
@ -408,6 +410,7 @@ Dygraph.propTypes = {
dygraphRef: func,
onZoom: func,
mode: string,
children: node,
}
const mapStateToProps = ({annotations: {mode}}) => ({

View File

@ -118,17 +118,18 @@ class LineGraph extends Component {
containerStyle={containerStyle}
staticLegend={staticLegend}
isGraphFilled={showSingleStat ? false : isGraphFilled}
/>
{showSingleStat
? <SingleStat
prefix={prefix}
suffix={suffix}
data={data}
lineGraph={true}
colors={colors}
cellHeight={cellHeight}
/>
: null}
>
{showSingleStat
? <SingleStat
prefix={prefix}
suffix={suffix}
data={data}
lineGraph={true}
colors={colors}
cellHeight={cellHeight}
/>
: null}
</Dygraph>
</div>
)
}

View File

@ -3,6 +3,7 @@ import classnames from 'classnames'
import lastValues from 'shared/parsing/lastValues'
import {SMALL_CELL_HEIGHT} from 'shared/graphs/helpers'
import {DYGRAPH_CONTAINER_V_MARGIN} from 'shared/constants'
import {SINGLE_STAT_TEXT} from 'src/dashboards/constants/gaugeColors'
import {generateSingleStatHexs} from 'shared/constants/colorOperations'
@ -16,6 +17,7 @@ class SingleStat extends PureComponent {
prefix,
suffix,
lineGraph,
staticLegendHeight,
} = this.props
// If data for this graph is being fetched for the first time, show a graph-wide spinner.
@ -39,11 +41,24 @@ class SingleStat extends PureComponent {
lastValue
)
const backgroundColor = bgColor
const color = textColor
const height = `calc(100% - ${staticLegendHeight +
DYGRAPH_CONTAINER_V_MARGIN * 2}px)`
const singleStatStyles = staticLegendHeight
? {
backgroundColor,
color,
height,
}
: {
backgroundColor,
color,
}
return (
<div
className="single-stat"
style={{backgroundColor: bgColor, color: textColor}}
>
<div className="single-stat" style={singleStatStyles}>
<span
className={classnames('single-stat--value', {
'single-stat--small': cellHeight === SMALL_CELL_HEIGHT,
@ -77,6 +92,7 @@ SingleStat.propTypes = {
prefix: string,
suffix: string,
lineGraph: bool,
staticLegendHeight: number,
}
export default SingleStat

View File

@ -93,7 +93,7 @@
height: 100% !important;
}
}
.dygraph > .single-stat {
.dygraph-child > .single-stat {
z-index: 3;
}
.single-stat--value {