Sha256: ea1e2fd76447ec22ad03c2e6ccef6cebacfad856d018b59df10381d7f9a26380

Contents?: true

Size: 1.7 KB

Versions: 8

Compression:

Stored size: 1.7 KB

Contents

Rev.registerComponent 'BarChart',
  propTypes:
    data: React.PropTypes.array.isRequired
    options: React.PropTypes.object
    width: React.PropTypes.number
    height: React.PropTypes.number
    title: React.PropTypes.string

  getDefaultProps: ->
    title: "Bar Chart"
    width: 300
    height: 300

  componentDidMount: ->
    ctx = @refs.canvas.getDOMNode().getContext('2d')
    @_chart = @renderChart(ctx)

  componentWillUnmount: ->
    @_chart.destroy()

  renderChart: (ctx) ->
    new Chart(ctx).Bar(@props.data, @getDefaultOptions())

  getDefaultOptions: ->
    defaultOptions =
      # Whether the scale should start at zero, or an order of magnitude down from the lowest value
      scaleBeginAtZero : true
      scaleShowGridLines : true
      scaleGridLineColor : "rgba(0,0,0,.05)"
      scaleGridLineWidth : 1
      # Whether to show horizontal lines (except X axis)
      scaleShowHorizontalLines: true
      # Whether to show vertical lines (except Y axis)
      scaleShowVerticalLines: false
      barShowStroke : true
      barStrokeWidth : 2
      # Spacing between each of the X value sets
      barValueSpacing : 5
      # Spacing between data sets within X values
      barDatasetSpacing : 1
      # Amount extra to add to the radius to cater for hit detection outside the drawn point
      pointHitDetectionRadius : 20
      # Whether to show a stroke for datasets
      datasetStroke : true
      datasetStrokeWidth : 2
      datasetFill : false

    defaultOptions = Object.assign(defaultOptions, @props.options)

  render: ->
    <div>
      <h3 className="ChartTitle">{ @props.title }</h3>
      <canvas
        ref="canvas"
        width={ @props.width }
        height={ @props.height }
      />
    </div>

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
revelry_core-0.1.12.6 app/assets/javascripts/revelry/ui/charts/BarChart.js.cjsx
revelry_core-0.1.12.5 app/assets/javascripts/revelry/ui/charts/BarChart.js.cjsx
revelry_core-0.1.12.4 app/assets/javascripts/revelry/ui/charts/BarChart.js.cjsx
revelry_core-0.1.12.3 app/assets/javascripts/revelry/ui/charts/BarChart.js.cjsx
revelry_core-0.1.12.2 app/assets/javascripts/revelry/ui/charts/BarChart.js.cjsx
revelry_core-0.1.12.0 app/assets/javascripts/revelry/ui/charts/BarChart.js.cjsx
revelry_core-0.1.11.6 app/assets/javascripts/revelry/ui/charts/BarChart.js.cjsx
revelry_core-0.1.11.5 app/assets/javascripts/revelry/ui/charts/BarChart.js.cjsx