Throw error when gauge is passed bad values

pull/10616/head
Alex P 2017-11-16 10:53:23 -08:00
parent 6559aea618
commit 24a71b6c99
1 changed files with 23 additions and 0 deletions

View File

@ -14,11 +14,32 @@ class Gauge extends Component {
}
componentDidMount() {
this.validateValues()
this.updateCanvas()
}
componentDidUpdate() {
this.validateValues()
this.updateCanvas()
}
validateValues = () => {
const {
minValue,
maxValue,
lowerThreshold,
upperThreshold,
gaugePosition,
} = this.props
if (
!(minValue < lowerThreshold < upperThreshold < maxValue) ||
gaugePosition < minValue ||
gaugePosition > maxValue
) {
console.error('Gauge component has received bad values')
}
}
resetCanvas = (canvas, context) => {
context.setTransform(1, 0, 0, 1, 0, 0)
context.clearRect(0, 0, canvas.width, canvas.height)
@ -261,6 +282,8 @@ const {number} = PropTypes
Gauge.propTypes = {
minValue: number.isRequired,
maxValue: number.isRequired,
lowerThreshold: number.isRequired,
upperThreshold: number.isRequired,
gaugePosition: number.isRequired,
}