import React, {Component} from "react"; import * as PropTypes from 'prop-types'; export default class HorizontalBarComponent extends Component { render() { let positiveChange = { fill: "green" }; let negativeChange = { fill: "red" }; let text = { position: "absolute", top: 0, width: "100%", textAlign: "right" }; let pctNetChange = this.props.value; let pctNetChangeBar = Math.min(Math.abs(pctNetChange) * 100, 100) / 2; let barWidth = `${pctNetChangeBar}%`; let barStyle = pctNetChange >= 0 ? positiveChange : negativeChange; let barX = `${pctNetChange >= 0 ? '50' : 50 - pctNetChangeBar}%`; return (
{pctNetChange}
) } } HorizontalBarComponent.propTypes = { params: PropTypes.object };