Created
December 10, 2016 18:04
-
-
Save caspg/62c821bbbb6251fe133aff93aa10b50b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react' | |
import { scaleLinear } from 'd3-scale' | |
import { interpolateLab } from 'd3-interpolate' | |
export default class Bars extends Component { | |
constructor(props) { | |
super(props) | |
this.colorScale = scaleLinear() | |
.domain([0, this.props.maxValue]) | |
.range(['#F3E5F5', '#7B1FA2']) | |
.interpolate(interpolateLab) | |
} | |
render() { | |
const { scales, margins, data, svgDimensions } = this.props | |
const { xScale, yScale } = scales | |
const { height } = svgDimensions | |
const bars = ( | |
data.map(datum => | |
<rect | |
key={datum.title} | |
x={xScale(datum.title)} | |
y={yScale(datum.value)} | |
height={height - margins.bottom - scales.yScale(datum.value)} | |
width={xScale.bandwidth()} | |
fill={this.colorScale(datum.value)} | |
/>, | |
) | |
) | |
return ( | |
<g>{bars}</g> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment