Created
December 10, 2016 17:58
-
-
Save caspg/be0d4752e96d55610934772ef3cec71b 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 * as d3Axis from 'd3-axis' | |
import { select as d3Select } from 'd3-selection' | |
import './Axis.css' | |
export default class Axis extends Component { | |
componentDidMount() { | |
this.renderAxis() | |
} | |
componentDidUpdate() { | |
this.renderAxis() | |
} | |
renderAxis() { | |
const axisType = `axis${this.props.orient}` | |
const axis = d3Axis[axisType]() | |
.scale(this.props.scale) | |
.tickSize(-this.props.tickSize) | |
.tickPadding([12]) | |
.ticks([4]) | |
d3Select(this.axisElement).call(axis) | |
} | |
render() { | |
return ( | |
<g | |
className={`Axis Axis-${this.props.orient}`} | |
ref={(el) => { this.axisElement = el; }} | |
transform={this.props.translate} | |
/> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment