|
|
|
@ -1,6 +1,7 @@ |
|
|
|
|
// Library
|
|
|
|
|
import React, { PureComponent, ReactNode, CSSProperties } from 'react'; |
|
|
|
|
import $ from 'jquery'; |
|
|
|
|
import { css } from 'emotion'; |
|
|
|
|
|
|
|
|
|
// Utils
|
|
|
|
|
import { getColorFromHexRgbOrName } from '../../utils'; |
|
|
|
@ -98,36 +99,67 @@ export class BigValue extends PureComponent<Props> { |
|
|
|
|
return <span style={css}>{value.text}</span>; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
render() { |
|
|
|
|
const { height, width, value, prefix, suffix, sparkline, backgroundColor } = this.props; |
|
|
|
|
renderSparkline(sparkline: BigValueSparkline) { |
|
|
|
|
const { height, width } = this.props; |
|
|
|
|
|
|
|
|
|
const plotCss: CSSProperties = {}; |
|
|
|
|
plotCss.position = 'absolute'; |
|
|
|
|
|
|
|
|
|
if (sparkline) { |
|
|
|
|
if (sparkline.full) { |
|
|
|
|
plotCss.bottom = '5px'; |
|
|
|
|
plotCss.left = '-5px'; |
|
|
|
|
plotCss.width = width - 10 + 'px'; |
|
|
|
|
const dynamicHeightMargin = height <= 100 ? 5 : Math.round(height / 100) * 15 + 5; |
|
|
|
|
plotCss.height = height - dynamicHeightMargin + 'px'; |
|
|
|
|
} else { |
|
|
|
|
plotCss.bottom = '0px'; |
|
|
|
|
plotCss.left = '-5px'; |
|
|
|
|
plotCss.width = width - 10 + 'px'; |
|
|
|
|
plotCss.height = Math.floor(height * 0.25) + 'px'; |
|
|
|
|
} |
|
|
|
|
plotCss.bottom = '0px'; |
|
|
|
|
plotCss.left = '0px'; |
|
|
|
|
plotCss.width = width + 'px'; |
|
|
|
|
|
|
|
|
|
if (sparkline.full) { |
|
|
|
|
const dynamicHeightMargin = height <= 100 ? 5 : Math.round(height / 100) * 15 + 5; |
|
|
|
|
plotCss.height = height - dynamicHeightMargin + 'px'; |
|
|
|
|
} else { |
|
|
|
|
plotCss.height = Math.floor(height * 0.25) + 'px'; |
|
|
|
|
} |
|
|
|
|
return <div style={plotCss} ref={element => (this.canvasElement = element)} />; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
render() { |
|
|
|
|
const { height, width, value, prefix, suffix, sparkline, backgroundColor } = this.props; |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<div className="big-value" style={{ width, height, backgroundColor }}> |
|
|
|
|
<span className="big-value__value"> |
|
|
|
|
<div |
|
|
|
|
className={css({ |
|
|
|
|
position: 'relative', |
|
|
|
|
display: 'table', |
|
|
|
|
})} |
|
|
|
|
style={{ width, height, backgroundColor }} |
|
|
|
|
> |
|
|
|
|
{value.title && ( |
|
|
|
|
<div |
|
|
|
|
className={css({ |
|
|
|
|
lineHeight: 1, |
|
|
|
|
textAlign: 'center', |
|
|
|
|
zIndex: 1, |
|
|
|
|
display: 'block', |
|
|
|
|
width: '100%', |
|
|
|
|
position: 'absolute', |
|
|
|
|
})} |
|
|
|
|
> |
|
|
|
|
{value.title} |
|
|
|
|
</div> |
|
|
|
|
)} |
|
|
|
|
<span |
|
|
|
|
className={css({ |
|
|
|
|
lineHeight: 1, |
|
|
|
|
textAlign: 'center', |
|
|
|
|
zIndex: 1, |
|
|
|
|
display: 'table-cell', |
|
|
|
|
verticalAlign: 'middle', |
|
|
|
|
position: 'relative', |
|
|
|
|
fontSize: '3em', |
|
|
|
|
fontWeight: 500, // TODO: $font-weight-semi-bold
|
|
|
|
|
})} |
|
|
|
|
> |
|
|
|
|
{this.renderText(prefix, '0px 2px 0px 0px')} |
|
|
|
|
{this.renderText(value)} |
|
|
|
|
{this.renderText(suffix)} |
|
|
|
|
</span> |
|
|
|
|
|
|
|
|
|
{sparkline && <div style={plotCss} ref={element => (this.canvasElement = element)} />} |
|
|
|
|
{sparkline && this.renderSparkline(sparkline)} |
|
|
|
|
</div> |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|