Created
          November 26, 2015 18:44 
        
      - 
      
- 
        Save basmoura/44715b3f99c6bb4f7269 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or 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
    
  
  
    
  | # rubocop:disable MethodLength | |
| module HitsBarGraphHelper | |
| def hits_bar_chart(data, options = {}) | |
| data_formated = [ | |
| { | |
| name: 'Erros', | |
| data: [['Questões', data[:incorrect]]] | |
| }, | |
| { | |
| name: 'Acertos', | |
| data: [['Questões', data[:correct]]] | |
| } | |
| ] | |
| bar_chart data_formated, default_options.deep_merge(options) | |
| end | |
| def questions_bar_chart(correct, incorrect) | |
| data_formated = [] | |
| colors = [] | |
| if correct > 0 | |
| data_formated << { | |
| name: 'Acertos', | |
| data: [['Questões', correct]] | |
| } | |
| colors << color_correct | |
| end | |
| if incorrect > 0 | |
| data_formated << { | |
| name: 'Erros', | |
| data: [['Questões', incorrect]] | |
| } | |
| colors << color_incorrect | |
| end | |
| options = { | |
| colors: colors, | |
| library: { | |
| plotOptions: { | |
| series: { | |
| stacking: 'percent' | |
| } | |
| } | |
| } | |
| } | |
| bar_chart data_formated, default_options.deep_merge(options) | |
| end | |
| private | |
| def default_options | |
| { | |
| stacked: true, height: '85px', width: '100%', colors: [color_incorrect, color_correct], | |
| library: { | |
| chart: { | |
| spacingTop: -5, | |
| animation: false, | |
| backgroundColor: 'transparent' | |
| }, | |
| legend: { | |
| itemStyle: { | |
| fontSize: '11px' | |
| }, | |
| reversed: true, | |
| margin: -20 | |
| }, | |
| tooltip: { enabled: false }, | |
| xAxis: { | |
| labels: { enabled: false }, | |
| lineWidth: 0 | |
| }, | |
| yAxis: { | |
| maxPadding: 0, | |
| labels: { enabled: false }, | |
| gridLineWidth: 0 | |
| }, | |
| plotOptions: { | |
| series: { | |
| animation: false, | |
| stacking: 'normal', | |
| dataLabels: { | |
| enabled: true, | |
| color: '#FFFFFF', | |
| style: { | |
| fontWeight: 'bold', | |
| fontSize: '14px' | |
| } | |
| }, | |
| events: { legendItemClick: false } | |
| } | |
| } | |
| } | |
| } | |
| end | |
| def color_correct | |
| '#00C89C' | |
| end | |
| def color_incorrect | |
| '#ED5C23' | |
| end | |
| end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment