Skip to content

Instantly share code, notes, and snippets.

@caspg
Created December 10, 2016 17:58
Show Gist options
  • Save caspg/be0d4752e96d55610934772ef3cec71b to your computer and use it in GitHub Desktop.
Save caspg/be0d4752e96d55610934772ef3cec71b to your computer and use it in GitHub Desktop.
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