chart-horizontalbar-rails 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
 - data/LICENSE +21 -0
 - data/README.md +15 -0
 - data/lib/chart-horizontalbar-rails.rb +8 -0
 - data/lib/chart-horizontalbar-rails/version.rb +5 -0
 - data/vendor/assets/javascripts/Chart.HorizontalBar.js +504 -0
 - metadata +51 -0
 
    
        checksums.yaml
    ADDED
    
    | 
         @@ -0,0 +1,7 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ---
         
     | 
| 
      
 2 
     | 
    
         
            +
            SHA1:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: e4c2f89f8673414de55c50f6ade1e62fa885c50a
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: a15999c09342d2494bab965264b97be8c105187f
         
     | 
| 
      
 5 
     | 
    
         
            +
            SHA512:
         
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: ac5924345a9daf927f4012ab811f1e65892fb7fe9fadb7ddf7673be1e00e45086cb17d07aa41fa7d873258a94945aa988e935e4d71004ddbc209869e3e595f3a
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 15f0a471a0dfbde29638ec453ab9e92bfb1da2eec422f86d1108faeac0523eaa5bb16041afaa7492751d78becff58e309595395c14a262e0b59aa792a4c2c3fc
         
     | 
    
        data/LICENSE
    ADDED
    
    | 
         @@ -0,0 +1,21 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            The MIT License (MIT)
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            Copyright (c) 2015 Tom Southall
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            Permission is hereby granted, free of charge, to any person obtaining a copy
         
     | 
| 
      
 6 
     | 
    
         
            +
            of this software and associated documentation files (the "Software"), to deal
         
     | 
| 
      
 7 
     | 
    
         
            +
            in the Software without restriction, including without limitation the rights
         
     | 
| 
      
 8 
     | 
    
         
            +
            to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         
     | 
| 
      
 9 
     | 
    
         
            +
            copies of the Software, and to permit persons to whom the Software is
         
     | 
| 
      
 10 
     | 
    
         
            +
            furnished to do so, subject to the following conditions:
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            The above copyright notice and this permission notice shall be included in all
         
     | 
| 
      
 13 
     | 
    
         
            +
            copies or substantial portions of the Software.
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         
     | 
| 
      
 16 
     | 
    
         
            +
            IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         
     | 
| 
      
 17 
     | 
    
         
            +
            FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         
     | 
| 
      
 18 
     | 
    
         
            +
            AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         
     | 
| 
      
 19 
     | 
    
         
            +
            LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         
     | 
| 
      
 20 
     | 
    
         
            +
            OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
         
     | 
| 
      
 21 
     | 
    
         
            +
            SOFTWARE.
         
     | 
    
        data/README.md
    ADDED
    
    | 
         @@ -0,0 +1,15 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # chart-horizontalbar-rails
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            Horizontal Bar Chart plugin for [Chart.js](http://chartjs.org), written by [Tom Southall](https://github.com/tomsouthall), packaged for the Rails asset pipeline.
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            ## Usage
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            Add the following to your JavaScript application manifest:
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            ```
         
     | 
| 
      
 10 
     | 
    
         
            +
            //= require Chart.HorizontalBar
         
     | 
| 
      
 11 
     | 
    
         
            +
            ```
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            ## Disclaimer
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            This repo is a Rails gem package. All issues with the library should be reported on the library's [GitHub page](https://github.com/tomsouthall/Chart.HorizontalBar.js). This repo will be updated each time a new version of the library is released.
         
     | 
| 
         @@ -0,0 +1,504 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            (function(){
         
     | 
| 
      
 2 
     | 
    
         
            +
                "use strict";
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
                var root = this,
         
     | 
| 
      
 5 
     | 
    
         
            +
                    Chart = root.Chart,
         
     | 
| 
      
 6 
     | 
    
         
            +
                    helpers = Chart.helpers;
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                var defaultConfig = {
         
     | 
| 
      
 10 
     | 
    
         
            +
                    //Boolean - Whether the scale should start at zero, or an order of magnitude down from the lowest value
         
     | 
| 
      
 11 
     | 
    
         
            +
                    scaleBeginAtZero : true,
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                    //Boolean - Whether grid lines are shown across the chart
         
     | 
| 
      
 14 
     | 
    
         
            +
                    scaleShowGridLines : true,
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                    //String - Colour of the grid lines
         
     | 
| 
      
 17 
     | 
    
         
            +
                    scaleGridLineColor : "rgba(0,0,0,.05)",
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                    //Number - Width of the grid lines
         
     | 
| 
      
 20 
     | 
    
         
            +
                    scaleGridLineWidth : 1,
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                    //Boolean - Whether to show horizontal lines (except X axis)
         
     | 
| 
      
 23 
     | 
    
         
            +
                    scaleShowHorizontalLines: true,
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                    //Boolean - Whether to show vertical lines (except Y axis)
         
     | 
| 
      
 26 
     | 
    
         
            +
                    scaleShowVerticalLines: true,
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                    //Boolean - If there is a stroke on each bar
         
     | 
| 
      
 29 
     | 
    
         
            +
                    barShowStroke : true,
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                    //Number - Pixel width of the bar stroke
         
     | 
| 
      
 32 
     | 
    
         
            +
                    barStrokeWidth : 2,
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                    //Number - Spacing between each of the X value sets
         
     | 
| 
      
 35 
     | 
    
         
            +
                    barValueSpacing : 5,
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                    //Number - Spacing between data sets within X values
         
     | 
| 
      
 38 
     | 
    
         
            +
                    barDatasetSpacing : 1,
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                    //String - A legend template
         
     | 
| 
      
 41 
     | 
    
         
            +
                    legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].fillColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                };
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
              Chart.HorizontalRectangle = Chart.Element.extend({
         
     | 
| 
      
 46 
     | 
    
         
            +
                    draw : function(){
         
     | 
| 
      
 47 
     | 
    
         
            +
                        var ctx = this.ctx,
         
     | 
| 
      
 48 
     | 
    
         
            +
                            halfHeight = this.height/2,
         
     | 
| 
      
 49 
     | 
    
         
            +
                            top = this.y - halfHeight,
         
     | 
| 
      
 50 
     | 
    
         
            +
                            bottom = this.y + halfHeight,
         
     | 
| 
      
 51 
     | 
    
         
            +
                            right = this.left - (this.left - this.x),
         
     | 
| 
      
 52 
     | 
    
         
            +
                            halfStroke = this.strokeWidth / 2;
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                        // Canvas doesn't allow us to stroke inside the width so we can
         
     | 
| 
      
 55 
     | 
    
         
            +
                        // adjust the sizes to fit if we're setting a stroke on the line
         
     | 
| 
      
 56 
     | 
    
         
            +
                        if (this.showStroke){
         
     | 
| 
      
 57 
     | 
    
         
            +
                            top += halfStroke;
         
     | 
| 
      
 58 
     | 
    
         
            +
                            bottom -= halfStroke;
         
     | 
| 
      
 59 
     | 
    
         
            +
                            right += halfStroke;
         
     | 
| 
      
 60 
     | 
    
         
            +
                        }
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
                        ctx.beginPath();
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
                        ctx.fillStyle = this.fillColor;
         
     | 
| 
      
 65 
     | 
    
         
            +
                        ctx.strokeStyle = this.strokeColor;
         
     | 
| 
      
 66 
     | 
    
         
            +
                        ctx.lineWidth = this.strokeWidth;
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
                        // It'd be nice to keep this class totally generic to any rectangle
         
     | 
| 
      
 69 
     | 
    
         
            +
                        // and simply specify which border to miss out.
         
     | 
| 
      
 70 
     | 
    
         
            +
                        ctx.moveTo(this.left, top);
         
     | 
| 
      
 71 
     | 
    
         
            +
                        ctx.lineTo(right, top);
         
     | 
| 
      
 72 
     | 
    
         
            +
                        ctx.lineTo(right, bottom);
         
     | 
| 
      
 73 
     | 
    
         
            +
                        ctx.lineTo(this.left, bottom);
         
     | 
| 
      
 74 
     | 
    
         
            +
                        ctx.fill();
         
     | 
| 
      
 75 
     | 
    
         
            +
                        if (this.showStroke){
         
     | 
| 
      
 76 
     | 
    
         
            +
                            ctx.stroke();
         
     | 
| 
      
 77 
     | 
    
         
            +
                        }
         
     | 
| 
      
 78 
     | 
    
         
            +
                    },
         
     | 
| 
      
 79 
     | 
    
         
            +
                    inRange : function(chartX,chartY){
         
     | 
| 
      
 80 
     | 
    
         
            +
                        return (chartX >= this.left && chartX <= this.x && chartY >= (this.y - this.height/2) && chartY <= (this.y + this.height/2));
         
     | 
| 
      
 81 
     | 
    
         
            +
                    }
         
     | 
| 
      
 82 
     | 
    
         
            +
                });
         
     | 
| 
      
 83 
     | 
    
         
            +
             
     | 
| 
      
 84 
     | 
    
         
            +
                Chart.Type.extend({
         
     | 
| 
      
 85 
     | 
    
         
            +
                    name: "HorizontalBar",
         
     | 
| 
      
 86 
     | 
    
         
            +
                    defaults : defaultConfig,
         
     | 
| 
      
 87 
     | 
    
         
            +
                    initialize:  function(data){
         
     | 
| 
      
 88 
     | 
    
         
            +
             
     | 
| 
      
 89 
     | 
    
         
            +
                        //Expose options as a scope variable here so we can access it in the ScaleClass
         
     | 
| 
      
 90 
     | 
    
         
            +
                        var options = this.options;
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
                        this.ScaleClass = Chart.Scale.extend({
         
     | 
| 
      
 93 
     | 
    
         
            +
                            offsetGridLines : true,
         
     | 
| 
      
 94 
     | 
    
         
            +
                            calculateBarX : function(datasetCount, datasetIndex, barIndex){
         
     | 
| 
      
 95 
     | 
    
         
            +
                                //Reusable method for calculating the xPosition of a given bar based on datasetIndex & width of the bar
         
     | 
| 
      
 96 
     | 
    
         
            +
                                var xWidth = this.calculateBaseWidth(),
         
     | 
| 
      
 97 
     | 
    
         
            +
                                    xAbsolute = this.calculateX(barIndex) - (xWidth/2),
         
     | 
| 
      
 98 
     | 
    
         
            +
                                    barWidth = this.calculateBarWidth(datasetCount);
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
                                return xAbsolute + (barWidth * datasetIndex) + (datasetIndex * options.barDatasetSpacing) + barWidth/2;
         
     | 
| 
      
 101 
     | 
    
         
            +
                            },
         
     | 
| 
      
 102 
     | 
    
         
            +
                            calculateBaseWidth : function(){
         
     | 
| 
      
 103 
     | 
    
         
            +
                                return (this.calculateX(1) - this.calculateX(0)) - (2*options.barValueSpacing);
         
     | 
| 
      
 104 
     | 
    
         
            +
                            },
         
     | 
| 
      
 105 
     | 
    
         
            +
                            calculateBarWidth : function(datasetCount){
         
     | 
| 
      
 106 
     | 
    
         
            +
                                //The padding between datasets is to the right of each bar, providing that there are more than 1 dataset
         
     | 
| 
      
 107 
     | 
    
         
            +
                                var baseWidth = this.calculateBaseWidth() - ((datasetCount - 1) * options.barDatasetSpacing);
         
     | 
| 
      
 108 
     | 
    
         
            +
             
     | 
| 
      
 109 
     | 
    
         
            +
                                return (baseWidth / datasetCount);
         
     | 
| 
      
 110 
     | 
    
         
            +
                            },
         
     | 
| 
      
 111 
     | 
    
         
            +
             
     | 
| 
      
 112 
     | 
    
         
            +
                    calculateBaseHeight : function(){
         
     | 
| 
      
 113 
     | 
    
         
            +
                                return ((this.endPoint - this.startPoint) / this.yLabels.length) - (2*options.barValueSpacing);
         
     | 
| 
      
 114 
     | 
    
         
            +
                            },
         
     | 
| 
      
 115 
     | 
    
         
            +
                            calculateBarHeight : function(datasetCount){
         
     | 
| 
      
 116 
     | 
    
         
            +
                                //The padding between datasets is to the right of each bar, providing that there are more than 1 dataset
         
     | 
| 
      
 117 
     | 
    
         
            +
                                var baseHeight = this.calculateBaseHeight() - ((datasetCount) * options.barDatasetSpacing);
         
     | 
| 
      
 118 
     | 
    
         
            +
             
     | 
| 
      
 119 
     | 
    
         
            +
                                return (baseHeight / datasetCount);
         
     | 
| 
      
 120 
     | 
    
         
            +
                            },
         
     | 
| 
      
 121 
     | 
    
         
            +
             
     | 
| 
      
 122 
     | 
    
         
            +
                            calculateXInvertXY : function(value) {
         
     | 
| 
      
 123 
     | 
    
         
            +
                                var scalingFactor = (this.width - Math.round(this.xScalePaddingLeft) - this.xScalePaddingRight) / (this.max - this.min);
         
     | 
| 
      
 124 
     | 
    
         
            +
                                return Math.round(this.xScalePaddingLeft) + (scalingFactor * (value - this.min));
         
     | 
| 
      
 125 
     | 
    
         
            +
                            },
         
     | 
| 
      
 126 
     | 
    
         
            +
             
     | 
| 
      
 127 
     | 
    
         
            +
                            calculateYInvertXY : function(index){
         
     | 
| 
      
 128 
     | 
    
         
            +
                                return index * ((this.startPoint - this.endPoint) / (this.yLabels.length));
         
     | 
| 
      
 129 
     | 
    
         
            +
                            },
         
     | 
| 
      
 130 
     | 
    
         
            +
             
     | 
| 
      
 131 
     | 
    
         
            +
                            calculateBarY : function(datasetCount, datasetIndex, barIndex){
         
     | 
| 
      
 132 
     | 
    
         
            +
                                //Reusable method for calculating the yPosition of a given bar based on datasetIndex & height of the bar
         
     | 
| 
      
 133 
     | 
    
         
            +
                                var yHeight = this.calculateBaseHeight(),
         
     | 
| 
      
 134 
     | 
    
         
            +
                                    yAbsolute = (this.endPoint + this.calculateYInvertXY(barIndex) - (yHeight / 2)) - 5,
         
     | 
| 
      
 135 
     | 
    
         
            +
                                    barHeight = this.calculateBarHeight(datasetCount);
         
     | 
| 
      
 136 
     | 
    
         
            +
                                if (datasetCount > 1) yAbsolute = yAbsolute + (barHeight * (datasetIndex - 1)) - (datasetIndex * options.barDatasetSpacing) + barHeight/2;
         
     | 
| 
      
 137 
     | 
    
         
            +
                                return yAbsolute;
         
     | 
| 
      
 138 
     | 
    
         
            +
                            },
         
     | 
| 
      
 139 
     | 
    
         
            +
             
     | 
| 
      
 140 
     | 
    
         
            +
                    buildCalculatedLabels : function() {
         
     | 
| 
      
 141 
     | 
    
         
            +
                            this.calculatedLabels = [];
         
     | 
| 
      
 142 
     | 
    
         
            +
             
     | 
| 
      
 143 
     | 
    
         
            +
                            var stepDecimalPlaces = helpers.getDecimalPlaces(this.stepValue);
         
     | 
| 
      
 144 
     | 
    
         
            +
             
     | 
| 
      
 145 
     | 
    
         
            +
                            for (var i=0; i<=this.steps; i++){
         
     | 
| 
      
 146 
     | 
    
         
            +
                                this.calculatedLabels.push(helpers.template(this.templateString,{value:(this.min + (i * this.stepValue)).toFixed(stepDecimalPlaces)}));
         
     | 
| 
      
 147 
     | 
    
         
            +
                            }
         
     | 
| 
      
 148 
     | 
    
         
            +
                        },
         
     | 
| 
      
 149 
     | 
    
         
            +
             
     | 
| 
      
 150 
     | 
    
         
            +
                        buildYLabels : function(){
         
     | 
| 
      
 151 
     | 
    
         
            +
                      this.buildYLabelCounter = (typeof this.buildYLabelCounter === 'undefined') ? 0 : this.buildYLabelCounter + 1;
         
     | 
| 
      
 152 
     | 
    
         
            +
                            this.buildCalculatedLabels();
         
     | 
| 
      
 153 
     | 
    
         
            +
                            if(this.buildYLabelCounter === 0) this.yLabels = this.xLabels;
         
     | 
| 
      
 154 
     | 
    
         
            +
                      this.xLabels = this.calculatedLabels;
         
     | 
| 
      
 155 
     | 
    
         
            +
                            this.yLabelWidth = (this.display && this.showLabels) ? helpers.longestText(this.ctx,this.font,this.yLabels) : 0;
         
     | 
| 
      
 156 
     | 
    
         
            +
                        },
         
     | 
| 
      
 157 
     | 
    
         
            +
             
     | 
| 
      
 158 
     | 
    
         
            +
                    calculateX : function(index){
         
     | 
| 
      
 159 
     | 
    
         
            +
                            var isRotated = (this.xLabelRotation > 0),
         
     | 
| 
      
 160 
     | 
    
         
            +
                                innerWidth = this.width - (this.xScalePaddingLeft + this.xScalePaddingRight),
         
     | 
| 
      
 161 
     | 
    
         
            +
                                valueWidth = innerWidth/(this.steps - ((this.offsetGridLines) ? 0 : 1)),
         
     | 
| 
      
 162 
     | 
    
         
            +
                                valueOffset = (valueWidth * index) + this.xScalePaddingLeft;
         
     | 
| 
      
 163 
     | 
    
         
            +
             
     | 
| 
      
 164 
     | 
    
         
            +
                            if (this.offsetGridLines){
         
     | 
| 
      
 165 
     | 
    
         
            +
                                valueOffset += (valueWidth/2);
         
     | 
| 
      
 166 
     | 
    
         
            +
                            }
         
     | 
| 
      
 167 
     | 
    
         
            +
             
     | 
| 
      
 168 
     | 
    
         
            +
                            return Math.round(valueOffset);
         
     | 
| 
      
 169 
     | 
    
         
            +
                        },
         
     | 
| 
      
 170 
     | 
    
         
            +
             
     | 
| 
      
 171 
     | 
    
         
            +
                    draw : function(){
         
     | 
| 
      
 172 
     | 
    
         
            +
                            var ctx = this.ctx,
         
     | 
| 
      
 173 
     | 
    
         
            +
                                yLabelGap = (this.endPoint - this.startPoint) / this.yLabels.length,
         
     | 
| 
      
 174 
     | 
    
         
            +
                                xStart = Math.round(this.xScalePaddingLeft);
         
     | 
| 
      
 175 
     | 
    
         
            +
                            if (this.display){
         
     | 
| 
      
 176 
     | 
    
         
            +
                                ctx.fillStyle = this.textColor;
         
     | 
| 
      
 177 
     | 
    
         
            +
                                ctx.font = this.font;
         
     | 
| 
      
 178 
     | 
    
         
            +
                                helpers.each(this.yLabels,function(labelString,index){
         
     | 
| 
      
 179 
     | 
    
         
            +
                                    var yLabelCenter = this.endPoint - (yLabelGap * index),
         
     | 
| 
      
 180 
     | 
    
         
            +
                                        linePositionY = Math.round(yLabelCenter),
         
     | 
| 
      
 181 
     | 
    
         
            +
                                        drawHorizontalLine = this.showHorizontalLines;
         
     | 
| 
      
 182 
     | 
    
         
            +
             
     | 
| 
      
 183 
     | 
    
         
            +
                                    yLabelCenter -= yLabelGap / 2;
         
     | 
| 
      
 184 
     | 
    
         
            +
             
     | 
| 
      
 185 
     | 
    
         
            +
                                    ctx.textAlign = "right";
         
     | 
| 
      
 186 
     | 
    
         
            +
                                    ctx.textBaseline = "middle";
         
     | 
| 
      
 187 
     | 
    
         
            +
                                    if (this.showLabels){
         
     | 
| 
      
 188 
     | 
    
         
            +
                                        ctx.fillText(labelString,xStart - 10,yLabelCenter);
         
     | 
| 
      
 189 
     | 
    
         
            +
                                    }
         
     | 
| 
      
 190 
     | 
    
         
            +
             
     | 
| 
      
 191 
     | 
    
         
            +
                                    if (index === 0 && !drawHorizontalLine) {
         
     | 
| 
      
 192 
     | 
    
         
            +
                                        drawHorizontalLine = true;
         
     | 
| 
      
 193 
     | 
    
         
            +
                                    }
         
     | 
| 
      
 194 
     | 
    
         
            +
                                    if (drawHorizontalLine){
         
     | 
| 
      
 195 
     | 
    
         
            +
                                        ctx.beginPath();
         
     | 
| 
      
 196 
     | 
    
         
            +
                                    }
         
     | 
| 
      
 197 
     | 
    
         
            +
                                    if (index > 0){
         
     | 
| 
      
 198 
     | 
    
         
            +
                                        // This is a grid line in the centre, so drop that
         
     | 
| 
      
 199 
     | 
    
         
            +
                                        ctx.lineWidth = this.gridLineWidth;
         
     | 
| 
      
 200 
     | 
    
         
            +
                                        ctx.strokeStyle = this.gridLineColor;
         
     | 
| 
      
 201 
     | 
    
         
            +
                                    } else {
         
     | 
| 
      
 202 
     | 
    
         
            +
                                        // This is the first line on the scale
         
     | 
| 
      
 203 
     | 
    
         
            +
                                        ctx.lineWidth = this.lineWidth;
         
     | 
| 
      
 204 
     | 
    
         
            +
                                        ctx.strokeStyle = this.lineColor;
         
     | 
| 
      
 205 
     | 
    
         
            +
                                    }
         
     | 
| 
      
 206 
     | 
    
         
            +
             
     | 
| 
      
 207 
     | 
    
         
            +
                                    linePositionY += helpers.aliasPixel(ctx.lineWidth);
         
     | 
| 
      
 208 
     | 
    
         
            +
             
     | 
| 
      
 209 
     | 
    
         
            +
                                    if(drawHorizontalLine){
         
     | 
| 
      
 210 
     | 
    
         
            +
                                        ctx.moveTo(xStart, linePositionY);
         
     | 
| 
      
 211 
     | 
    
         
            +
                                        ctx.lineTo(this.width, linePositionY);
         
     | 
| 
      
 212 
     | 
    
         
            +
                                        ctx.stroke();
         
     | 
| 
      
 213 
     | 
    
         
            +
                                        ctx.closePath();
         
     | 
| 
      
 214 
     | 
    
         
            +
                                    }
         
     | 
| 
      
 215 
     | 
    
         
            +
             
     | 
| 
      
 216 
     | 
    
         
            +
                                    ctx.lineWidth = this.lineWidth;
         
     | 
| 
      
 217 
     | 
    
         
            +
                                    ctx.strokeStyle = this.lineColor;
         
     | 
| 
      
 218 
     | 
    
         
            +
                                    ctx.beginPath();
         
     | 
| 
      
 219 
     | 
    
         
            +
                                    ctx.moveTo(xStart - 5, linePositionY);
         
     | 
| 
      
 220 
     | 
    
         
            +
                                    ctx.lineTo(xStart, linePositionY);
         
     | 
| 
      
 221 
     | 
    
         
            +
                                    ctx.stroke();
         
     | 
| 
      
 222 
     | 
    
         
            +
                                    ctx.closePath();
         
     | 
| 
      
 223 
     | 
    
         
            +
             
     | 
| 
      
 224 
     | 
    
         
            +
                                },this);
         
     | 
| 
      
 225 
     | 
    
         
            +
             
     | 
| 
      
 226 
     | 
    
         
            +
                                helpers.each(this.xLabels,function(label,index){
         
     | 
| 
      
 227 
     | 
    
         
            +
                                    var width = this.calculateX(1) - this.calculateX(0);
         
     | 
| 
      
 228 
     | 
    
         
            +
                                    var xPos = this.calculateX(index) + helpers.aliasPixel(this.lineWidth) - (width / 2),
         
     | 
| 
      
 229 
     | 
    
         
            +
                                        // Check to see if line/bar here and decide where to place the line
         
     | 
| 
      
 230 
     | 
    
         
            +
                                        linePos = this.calculateX(index - (this.offsetGridLines ? 0.5 : 0)) + helpers.aliasPixel(this.lineWidth),
         
     | 
| 
      
 231 
     | 
    
         
            +
                                        isRotated = (this.xLabelRotation > 0);
         
     | 
| 
      
 232 
     | 
    
         
            +
             
     | 
| 
      
 233 
     | 
    
         
            +
                                    ctx.beginPath();
         
     | 
| 
      
 234 
     | 
    
         
            +
             
     | 
| 
      
 235 
     | 
    
         
            +
                                    if (index > 0){
         
     | 
| 
      
 236 
     | 
    
         
            +
                                        // This is a grid line in the centre, so drop that
         
     | 
| 
      
 237 
     | 
    
         
            +
                                        ctx.lineWidth = this.gridLineWidth;
         
     | 
| 
      
 238 
     | 
    
         
            +
                                        ctx.strokeStyle = this.gridLineColor;
         
     | 
| 
      
 239 
     | 
    
         
            +
                                    } else {
         
     | 
| 
      
 240 
     | 
    
         
            +
                                        // This is the first line on the scale
         
     | 
| 
      
 241 
     | 
    
         
            +
                                        ctx.lineWidth = this.lineWidth;
         
     | 
| 
      
 242 
     | 
    
         
            +
                                        ctx.strokeStyle = this.lineColor;
         
     | 
| 
      
 243 
     | 
    
         
            +
                                    }
         
     | 
| 
      
 244 
     | 
    
         
            +
                                    ctx.moveTo(linePos,this.endPoint);
         
     | 
| 
      
 245 
     | 
    
         
            +
                                    ctx.lineTo(linePos,this.startPoint - 3);
         
     | 
| 
      
 246 
     | 
    
         
            +
                                    ctx.stroke();
         
     | 
| 
      
 247 
     | 
    
         
            +
                                    ctx.closePath();
         
     | 
| 
      
 248 
     | 
    
         
            +
             
     | 
| 
      
 249 
     | 
    
         
            +
             
     | 
| 
      
 250 
     | 
    
         
            +
                                    ctx.lineWidth = this.lineWidth;
         
     | 
| 
      
 251 
     | 
    
         
            +
                                    ctx.strokeStyle = this.lineColor;
         
     | 
| 
      
 252 
     | 
    
         
            +
             
     | 
| 
      
 253 
     | 
    
         
            +
             
     | 
| 
      
 254 
     | 
    
         
            +
                                    // Small lines at the bottom of the base grid line
         
     | 
| 
      
 255 
     | 
    
         
            +
                                    ctx.beginPath();
         
     | 
| 
      
 256 
     | 
    
         
            +
                                    ctx.moveTo(linePos,this.endPoint);
         
     | 
| 
      
 257 
     | 
    
         
            +
                                    ctx.lineTo(linePos,this.endPoint + 5);
         
     | 
| 
      
 258 
     | 
    
         
            +
                                    ctx.stroke();
         
     | 
| 
      
 259 
     | 
    
         
            +
                                    ctx.closePath();
         
     | 
| 
      
 260 
     | 
    
         
            +
             
     | 
| 
      
 261 
     | 
    
         
            +
                                    ctx.save();
         
     | 
| 
      
 262 
     | 
    
         
            +
                                    ctx.translate(xPos,(isRotated) ? this.endPoint + 12 : this.endPoint + 8);
         
     | 
| 
      
 263 
     | 
    
         
            +
                                    ctx.rotate(helpers.radians(this.xLabelRotation)*-1);
         
     | 
| 
      
 264 
     | 
    
         
            +
                                    ctx.font = this.font;
         
     | 
| 
      
 265 
     | 
    
         
            +
                                    ctx.textAlign = (isRotated) ? "right" : "center";
         
     | 
| 
      
 266 
     | 
    
         
            +
                                    ctx.textBaseline = (isRotated) ? "middle" : "top";
         
     | 
| 
      
 267 
     | 
    
         
            +
                                    ctx.fillText(label, 0, 0);
         
     | 
| 
      
 268 
     | 
    
         
            +
                                    ctx.restore();
         
     | 
| 
      
 269 
     | 
    
         
            +
                                },this);
         
     | 
| 
      
 270 
     | 
    
         
            +
             
     | 
| 
      
 271 
     | 
    
         
            +
                            }
         
     | 
| 
      
 272 
     | 
    
         
            +
                        }
         
     | 
| 
      
 273 
     | 
    
         
            +
             
     | 
| 
      
 274 
     | 
    
         
            +
                        });
         
     | 
| 
      
 275 
     | 
    
         
            +
             
     | 
| 
      
 276 
     | 
    
         
            +
                        this.datasets = [];
         
     | 
| 
      
 277 
     | 
    
         
            +
             
     | 
| 
      
 278 
     | 
    
         
            +
                        //Set up tooltip events on the chart
         
     | 
| 
      
 279 
     | 
    
         
            +
                        if (this.options.showTooltips){
         
     | 
| 
      
 280 
     | 
    
         
            +
                            helpers.bindEvents(this, this.options.tooltipEvents, function(evt){
         
     | 
| 
      
 281 
     | 
    
         
            +
                                var activeBars = (evt.type !== 'mouseout') ? this.getBarsAtEvent(evt) : [];
         
     | 
| 
      
 282 
     | 
    
         
            +
             
     | 
| 
      
 283 
     | 
    
         
            +
                                this.eachBars(function(bar){
         
     | 
| 
      
 284 
     | 
    
         
            +
                                    bar.restore(['fillColor', 'strokeColor']);
         
     | 
| 
      
 285 
     | 
    
         
            +
                                });
         
     | 
| 
      
 286 
     | 
    
         
            +
                                helpers.each(activeBars, function(activeBar){
         
     | 
| 
      
 287 
     | 
    
         
            +
                                    activeBar.fillColor = activeBar.highlightFill;
         
     | 
| 
      
 288 
     | 
    
         
            +
                                    activeBar.strokeColor = activeBar.highlightStroke;
         
     | 
| 
      
 289 
     | 
    
         
            +
                                });
         
     | 
| 
      
 290 
     | 
    
         
            +
                                this.showTooltip(activeBars);
         
     | 
| 
      
 291 
     | 
    
         
            +
                            });
         
     | 
| 
      
 292 
     | 
    
         
            +
                        }
         
     | 
| 
      
 293 
     | 
    
         
            +
             
     | 
| 
      
 294 
     | 
    
         
            +
                        //Declare the extension of the default point, to cater for the options passed in to the constructor
         
     | 
| 
      
 295 
     | 
    
         
            +
                        this.BarClass = Chart.HorizontalRectangle.extend({
         
     | 
| 
      
 296 
     | 
    
         
            +
                            strokeWidth : this.options.barStrokeWidth,
         
     | 
| 
      
 297 
     | 
    
         
            +
                            showStroke : this.options.barShowStroke,
         
     | 
| 
      
 298 
     | 
    
         
            +
                            ctx : this.chart.ctx
         
     | 
| 
      
 299 
     | 
    
         
            +
                        });
         
     | 
| 
      
 300 
     | 
    
         
            +
             
     | 
| 
      
 301 
     | 
    
         
            +
                        //Iterate through each of the datasets, and build this into a property of the chart
         
     | 
| 
      
 302 
     | 
    
         
            +
                        helpers.each(data.datasets,function(dataset,datasetIndex){
         
     | 
| 
      
 303 
     | 
    
         
            +
             
     | 
| 
      
 304 
     | 
    
         
            +
                            var datasetObject = {
         
     | 
| 
      
 305 
     | 
    
         
            +
                                label : dataset.label || null,
         
     | 
| 
      
 306 
     | 
    
         
            +
                                fillColor : dataset.fillColor,
         
     | 
| 
      
 307 
     | 
    
         
            +
                                strokeColor : dataset.strokeColor,
         
     | 
| 
      
 308 
     | 
    
         
            +
                                bars : []
         
     | 
| 
      
 309 
     | 
    
         
            +
                            };
         
     | 
| 
      
 310 
     | 
    
         
            +
             
     | 
| 
      
 311 
     | 
    
         
            +
                            this.datasets.push(datasetObject);
         
     | 
| 
      
 312 
     | 
    
         
            +
             
     | 
| 
      
 313 
     | 
    
         
            +
                            helpers.each(dataset.data,function(dataPoint,index){
         
     | 
| 
      
 314 
     | 
    
         
            +
                                //Add a new point for each piece of data, passing any required data to draw.
         
     | 
| 
      
 315 
     | 
    
         
            +
                                datasetObject.bars.push(new this.BarClass({
         
     | 
| 
      
 316 
     | 
    
         
            +
                                    value : dataPoint,
         
     | 
| 
      
 317 
     | 
    
         
            +
                                    label : data.labels[index],
         
     | 
| 
      
 318 
     | 
    
         
            +
                                    datasetLabel: dataset.label,
         
     | 
| 
      
 319 
     | 
    
         
            +
                                    strokeColor : dataset.strokeColor,
         
     | 
| 
      
 320 
     | 
    
         
            +
                                    fillColor : dataset.fillColor,
         
     | 
| 
      
 321 
     | 
    
         
            +
                                    highlightFill : dataset.highlightFill || dataset.fillColor,
         
     | 
| 
      
 322 
     | 
    
         
            +
                                    highlightStroke : dataset.highlightStroke || dataset.strokeColor
         
     | 
| 
      
 323 
     | 
    
         
            +
                                }));
         
     | 
| 
      
 324 
     | 
    
         
            +
                            },this);
         
     | 
| 
      
 325 
     | 
    
         
            +
             
     | 
| 
      
 326 
     | 
    
         
            +
                        },this);
         
     | 
| 
      
 327 
     | 
    
         
            +
             
     | 
| 
      
 328 
     | 
    
         
            +
                        this.buildScale(data.labels);
         
     | 
| 
      
 329 
     | 
    
         
            +
             
     | 
| 
      
 330 
     | 
    
         
            +
                  this.BarClass.prototype.left = Math.round(this.scale.xScalePaddingLeft);
         
     | 
| 
      
 331 
     | 
    
         
            +
             
     | 
| 
      
 332 
     | 
    
         
            +
                        this.eachBars(function(bar, index, datasetIndex){
         
     | 
| 
      
 333 
     | 
    
         
            +
                            helpers.extend(bar, {
         
     | 
| 
      
 334 
     | 
    
         
            +
                      x: Math.round(this.scale.xScalePaddingLeft),
         
     | 
| 
      
 335 
     | 
    
         
            +
                                y : this.scale.calculateBarY(this.datasets.length, datasetIndex, index),
         
     | 
| 
      
 336 
     | 
    
         
            +
                                height : this.scale.calculateBarHeight(this.datasets.length)
         
     | 
| 
      
 337 
     | 
    
         
            +
                            });
         
     | 
| 
      
 338 
     | 
    
         
            +
                            bar.save();
         
     | 
| 
      
 339 
     | 
    
         
            +
                        }, this);
         
     | 
| 
      
 340 
     | 
    
         
            +
             
     | 
| 
      
 341 
     | 
    
         
            +
                        this.render();
         
     | 
| 
      
 342 
     | 
    
         
            +
                    },
         
     | 
| 
      
 343 
     | 
    
         
            +
                    update : function(){
         
     | 
| 
      
 344 
     | 
    
         
            +
                        this.scale.update();
         
     | 
| 
      
 345 
     | 
    
         
            +
                        // Reset any highlight colours before updating.
         
     | 
| 
      
 346 
     | 
    
         
            +
                        helpers.each(this.activeElements, function(activeElement){
         
     | 
| 
      
 347 
     | 
    
         
            +
                            activeElement.restore(['fillColor', 'strokeColor']);
         
     | 
| 
      
 348 
     | 
    
         
            +
                        });
         
     | 
| 
      
 349 
     | 
    
         
            +
             
     | 
| 
      
 350 
     | 
    
         
            +
                        this.eachBars(function(bar){
         
     | 
| 
      
 351 
     | 
    
         
            +
                            bar.save();
         
     | 
| 
      
 352 
     | 
    
         
            +
                        });
         
     | 
| 
      
 353 
     | 
    
         
            +
                        this.render();
         
     | 
| 
      
 354 
     | 
    
         
            +
                    },
         
     | 
| 
      
 355 
     | 
    
         
            +
                    eachBars : function(callback){
         
     | 
| 
      
 356 
     | 
    
         
            +
                        helpers.each(this.datasets,function(dataset, datasetIndex){
         
     | 
| 
      
 357 
     | 
    
         
            +
                            helpers.each(dataset.bars, callback, this, datasetIndex);
         
     | 
| 
      
 358 
     | 
    
         
            +
                        },this);
         
     | 
| 
      
 359 
     | 
    
         
            +
                    },
         
     | 
| 
      
 360 
     | 
    
         
            +
                    getBarsAtEvent : function(e){
         
     | 
| 
      
 361 
     | 
    
         
            +
                        var barsArray = [],
         
     | 
| 
      
 362 
     | 
    
         
            +
                            eventPosition = helpers.getRelativePosition(e),
         
     | 
| 
      
 363 
     | 
    
         
            +
                            datasetIterator = function(dataset){
         
     | 
| 
      
 364 
     | 
    
         
            +
                                barsArray.push(dataset.bars[barIndex]);
         
     | 
| 
      
 365 
     | 
    
         
            +
                            },
         
     | 
| 
      
 366 
     | 
    
         
            +
                            barIndex;
         
     | 
| 
      
 367 
     | 
    
         
            +
             
     | 
| 
      
 368 
     | 
    
         
            +
                        for (var datasetIndex = 0; datasetIndex < this.datasets.length; datasetIndex++) {
         
     | 
| 
      
 369 
     | 
    
         
            +
                            for (barIndex = 0; barIndex < this.datasets[datasetIndex].bars.length; barIndex++) {
         
     | 
| 
      
 370 
     | 
    
         
            +
                                if (this.datasets[datasetIndex].bars[barIndex].inRange(eventPosition.x,eventPosition.y)){
         
     | 
| 
      
 371 
     | 
    
         
            +
                                    helpers.each(this.datasets, datasetIterator);
         
     | 
| 
      
 372 
     | 
    
         
            +
                                    return barsArray;
         
     | 
| 
      
 373 
     | 
    
         
            +
                                }
         
     | 
| 
      
 374 
     | 
    
         
            +
                            }
         
     | 
| 
      
 375 
     | 
    
         
            +
                        }
         
     | 
| 
      
 376 
     | 
    
         
            +
             
     | 
| 
      
 377 
     | 
    
         
            +
                        return barsArray;
         
     | 
| 
      
 378 
     | 
    
         
            +
                    },
         
     | 
| 
      
 379 
     | 
    
         
            +
                    buildScale : function(labels){
         
     | 
| 
      
 380 
     | 
    
         
            +
                        var self = this;
         
     | 
| 
      
 381 
     | 
    
         
            +
             
     | 
| 
      
 382 
     | 
    
         
            +
                        var dataTotal = function(){
         
     | 
| 
      
 383 
     | 
    
         
            +
                            var values = [];
         
     | 
| 
      
 384 
     | 
    
         
            +
                            self.eachBars(function(bar){
         
     | 
| 
      
 385 
     | 
    
         
            +
                                values.push(bar.value);
         
     | 
| 
      
 386 
     | 
    
         
            +
                            });
         
     | 
| 
      
 387 
     | 
    
         
            +
                            return values;
         
     | 
| 
      
 388 
     | 
    
         
            +
                        };
         
     | 
| 
      
 389 
     | 
    
         
            +
             
     | 
| 
      
 390 
     | 
    
         
            +
                        var scaleOptions = {
         
     | 
| 
      
 391 
     | 
    
         
            +
                            templateString : this.options.scaleLabel,
         
     | 
| 
      
 392 
     | 
    
         
            +
                            height : this.chart.height,
         
     | 
| 
      
 393 
     | 
    
         
            +
                            width : this.chart.width,
         
     | 
| 
      
 394 
     | 
    
         
            +
                            ctx : this.chart.ctx,
         
     | 
| 
      
 395 
     | 
    
         
            +
                            textColor : this.options.scaleFontColor,
         
     | 
| 
      
 396 
     | 
    
         
            +
                            fontSize : this.options.scaleFontSize,
         
     | 
| 
      
 397 
     | 
    
         
            +
                            fontStyle : this.options.scaleFontStyle,
         
     | 
| 
      
 398 
     | 
    
         
            +
                            fontFamily : this.options.scaleFontFamily,
         
     | 
| 
      
 399 
     | 
    
         
            +
                            valuesCount : labels.length,
         
     | 
| 
      
 400 
     | 
    
         
            +
                            beginAtZero : this.options.scaleBeginAtZero,
         
     | 
| 
      
 401 
     | 
    
         
            +
                            integersOnly : this.options.scaleIntegersOnly,
         
     | 
| 
      
 402 
     | 
    
         
            +
                            calculateYRange: function(currentHeight){
         
     | 
| 
      
 403 
     | 
    
         
            +
                                var updatedRanges = helpers.calculateScaleRange(
         
     | 
| 
      
 404 
     | 
    
         
            +
                                    dataTotal(),
         
     | 
| 
      
 405 
     | 
    
         
            +
                                    currentHeight,
         
     | 
| 
      
 406 
     | 
    
         
            +
                                    this.fontSize,
         
     | 
| 
      
 407 
     | 
    
         
            +
                                    this.beginAtZero,
         
     | 
| 
      
 408 
     | 
    
         
            +
                                    this.integersOnly
         
     | 
| 
      
 409 
     | 
    
         
            +
                                );
         
     | 
| 
      
 410 
     | 
    
         
            +
                                helpers.extend(this, updatedRanges);
         
     | 
| 
      
 411 
     | 
    
         
            +
                            },
         
     | 
| 
      
 412 
     | 
    
         
            +
                            xLabels : labels,
         
     | 
| 
      
 413 
     | 
    
         
            +
                            font : helpers.fontString(this.options.scaleFontSize, this.options.scaleFontStyle, this.options.scaleFontFamily),
         
     | 
| 
      
 414 
     | 
    
         
            +
                            lineWidth : this.options.scaleLineWidth,
         
     | 
| 
      
 415 
     | 
    
         
            +
                            lineColor : this.options.scaleLineColor,
         
     | 
| 
      
 416 
     | 
    
         
            +
                            showHorizontalLines : this.options.scaleShowHorizontalLines,
         
     | 
| 
      
 417 
     | 
    
         
            +
                            showVerticalLines : this.options.scaleShowVerticalLines,
         
     | 
| 
      
 418 
     | 
    
         
            +
                            gridLineWidth : (this.options.scaleShowGridLines) ? this.options.scaleGridLineWidth : 0,
         
     | 
| 
      
 419 
     | 
    
         
            +
                            gridLineColor : (this.options.scaleShowGridLines) ? this.options.scaleGridLineColor : "rgba(0,0,0,0)",
         
     | 
| 
      
 420 
     | 
    
         
            +
                            padding : (this.options.showScale) ? 0 : (this.options.barShowStroke) ? this.options.barStrokeWidth : 0,
         
     | 
| 
      
 421 
     | 
    
         
            +
                            showLabels : this.options.scaleShowLabels,
         
     | 
| 
      
 422 
     | 
    
         
            +
                            display : this.options.showScale
         
     | 
| 
      
 423 
     | 
    
         
            +
                        };
         
     | 
| 
      
 424 
     | 
    
         
            +
             
     | 
| 
      
 425 
     | 
    
         
            +
                        if (this.options.scaleOverride){
         
     | 
| 
      
 426 
     | 
    
         
            +
                            helpers.extend(scaleOptions, {
         
     | 
| 
      
 427 
     | 
    
         
            +
                                calculateYRange: helpers.noop,
         
     | 
| 
      
 428 
     | 
    
         
            +
                                steps: this.options.scaleSteps,
         
     | 
| 
      
 429 
     | 
    
         
            +
                                stepValue: this.options.scaleStepWidth,
         
     | 
| 
      
 430 
     | 
    
         
            +
                                min: this.options.scaleStartValue,
         
     | 
| 
      
 431 
     | 
    
         
            +
                                max: this.options.scaleStartValue + (this.options.scaleSteps * this.options.scaleStepWidth)
         
     | 
| 
      
 432 
     | 
    
         
            +
                            });
         
     | 
| 
      
 433 
     | 
    
         
            +
                        }
         
     | 
| 
      
 434 
     | 
    
         
            +
             
     | 
| 
      
 435 
     | 
    
         
            +
                        this.scale = new this.ScaleClass(scaleOptions);
         
     | 
| 
      
 436 
     | 
    
         
            +
                    },
         
     | 
| 
      
 437 
     | 
    
         
            +
                    addData : function(valuesArray,label){
         
     | 
| 
      
 438 
     | 
    
         
            +
                        //Map the values array for each of the datasets
         
     | 
| 
      
 439 
     | 
    
         
            +
                        helpers.each(valuesArray,function(value,datasetIndex){
         
     | 
| 
      
 440 
     | 
    
         
            +
                            //Add a new point for each piece of data, passing any required data to draw.
         
     | 
| 
      
 441 
     | 
    
         
            +
                            this.datasets[datasetIndex].bars.push(new this.BarClass({
         
     | 
| 
      
 442 
     | 
    
         
            +
                                value : value,
         
     | 
| 
      
 443 
     | 
    
         
            +
                                label : label,
         
     | 
| 
      
 444 
     | 
    
         
            +
                                x: this.scale.calculateBarX(this.datasets.length, datasetIndex, this.scale.valuesCount+1),
         
     | 
| 
      
 445 
     | 
    
         
            +
                                y: this.scale.endPoint,
         
     | 
| 
      
 446 
     | 
    
         
            +
                                width : this.scale.calculateBarWidth(this.datasets.length),
         
     | 
| 
      
 447 
     | 
    
         
            +
                                base : this.scale.endPoint,
         
     | 
| 
      
 448 
     | 
    
         
            +
                                strokeColor : this.datasets[datasetIndex].strokeColor,
         
     | 
| 
      
 449 
     | 
    
         
            +
                                fillColor : this.datasets[datasetIndex].fillColor
         
     | 
| 
      
 450 
     | 
    
         
            +
                            }));
         
     | 
| 
      
 451 
     | 
    
         
            +
                        },this);
         
     | 
| 
      
 452 
     | 
    
         
            +
             
     | 
| 
      
 453 
     | 
    
         
            +
                        this.scale.addXLabel(label);
         
     | 
| 
      
 454 
     | 
    
         
            +
                        //Then re-render the chart.
         
     | 
| 
      
 455 
     | 
    
         
            +
                        this.update();
         
     | 
| 
      
 456 
     | 
    
         
            +
                    },
         
     | 
| 
      
 457 
     | 
    
         
            +
                    removeData : function(){
         
     | 
| 
      
 458 
     | 
    
         
            +
                        this.scale.removeXLabel();
         
     | 
| 
      
 459 
     | 
    
         
            +
                        //Then re-render the chart.
         
     | 
| 
      
 460 
     | 
    
         
            +
                        helpers.each(this.datasets,function(dataset){
         
     | 
| 
      
 461 
     | 
    
         
            +
                            dataset.bars.shift();
         
     | 
| 
      
 462 
     | 
    
         
            +
                        },this);
         
     | 
| 
      
 463 
     | 
    
         
            +
                        this.update();
         
     | 
| 
      
 464 
     | 
    
         
            +
                    },
         
     | 
| 
      
 465 
     | 
    
         
            +
                    reflow : function(){
         
     | 
| 
      
 466 
     | 
    
         
            +
                        helpers.extend(this.BarClass.prototype,{
         
     | 
| 
      
 467 
     | 
    
         
            +
                            y: this.scale.endPoint,
         
     | 
| 
      
 468 
     | 
    
         
            +
                            base : this.scale.endPoint
         
     | 
| 
      
 469 
     | 
    
         
            +
                        });
         
     | 
| 
      
 470 
     | 
    
         
            +
                        var newScaleProps = helpers.extend({
         
     | 
| 
      
 471 
     | 
    
         
            +
                            height : this.chart.height,
         
     | 
| 
      
 472 
     | 
    
         
            +
                            width : this.chart.width
         
     | 
| 
      
 473 
     | 
    
         
            +
                        });
         
     | 
| 
      
 474 
     | 
    
         
            +
             
     | 
| 
      
 475 
     | 
    
         
            +
                        this.scale.update(newScaleProps);
         
     | 
| 
      
 476 
     | 
    
         
            +
                    },
         
     | 
| 
      
 477 
     | 
    
         
            +
                    draw : function(ease){
         
     | 
| 
      
 478 
     | 
    
         
            +
                        var easingDecimal = ease || 1;
         
     | 
| 
      
 479 
     | 
    
         
            +
                        this.clear();
         
     | 
| 
      
 480 
     | 
    
         
            +
             
     | 
| 
      
 481 
     | 
    
         
            +
                        var ctx = this.chart.ctx;
         
     | 
| 
      
 482 
     | 
    
         
            +
             
     | 
| 
      
 483 
     | 
    
         
            +
                        this.scale.draw(easingDecimal);
         
     | 
| 
      
 484 
     | 
    
         
            +
             
     | 
| 
      
 485 
     | 
    
         
            +
                        //Draw all the bars for each dataset
         
     | 
| 
      
 486 
     | 
    
         
            +
                        helpers.each(this.datasets,function(dataset,datasetIndex){
         
     | 
| 
      
 487 
     | 
    
         
            +
                            helpers.each(dataset.bars,function(bar,index){
         
     | 
| 
      
 488 
     | 
    
         
            +
                                if (bar.hasValue()){
         
     | 
| 
      
 489 
     | 
    
         
            +
                                    bar.left = Math.round(this.scale.xScalePaddingLeft);
         
     | 
| 
      
 490 
     | 
    
         
            +
                                    //Transition then draw
         
     | 
| 
      
 491 
     | 
    
         
            +
                                    bar.transition({
         
     | 
| 
      
 492 
     | 
    
         
            +
                                        x : this.scale.calculateXInvertXY(bar.value),
         
     | 
| 
      
 493 
     | 
    
         
            +
                                        y : this.scale.calculateBarY(this.datasets.length, datasetIndex, index),
         
     | 
| 
      
 494 
     | 
    
         
            +
                                        height : this.scale.calculateBarHeight(this.datasets.length)
         
     | 
| 
      
 495 
     | 
    
         
            +
                                    }, easingDecimal).draw();
         
     | 
| 
      
 496 
     | 
    
         
            +
                                }
         
     | 
| 
      
 497 
     | 
    
         
            +
                            },this);
         
     | 
| 
      
 498 
     | 
    
         
            +
             
     | 
| 
      
 499 
     | 
    
         
            +
                        },this);
         
     | 
| 
      
 500 
     | 
    
         
            +
                    }
         
     | 
| 
      
 501 
     | 
    
         
            +
                });
         
     | 
| 
      
 502 
     | 
    
         
            +
             
     | 
| 
      
 503 
     | 
    
         
            +
             
     | 
| 
      
 504 
     | 
    
         
            +
            }).call(this);
         
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,51 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: chart-horizontalbar-rails
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.0.4
         
     | 
| 
      
 5 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 6 
     | 
    
         
            +
            authors:
         
     | 
| 
      
 7 
     | 
    
         
            +
            - Curt Howard
         
     | 
| 
      
 8 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 9 
     | 
    
         
            +
            bindir: bin
         
     | 
| 
      
 10 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2016-02-14 00:00:00.000000000 Z
         
     | 
| 
      
 12 
     | 
    
         
            +
            dependencies: []
         
     | 
| 
      
 13 
     | 
    
         
            +
            description: A build of the Chart.js Horizontal Bar plugin, written by Tom Southall,
         
     | 
| 
      
 14 
     | 
    
         
            +
              packaged for the Rails asset pipeline.
         
     | 
| 
      
 15 
     | 
    
         
            +
            email:
         
     | 
| 
      
 16 
     | 
    
         
            +
            - choward@weblinc.com
         
     | 
| 
      
 17 
     | 
    
         
            +
            executables: []
         
     | 
| 
      
 18 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 19 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 20 
     | 
    
         
            +
            files:
         
     | 
| 
      
 21 
     | 
    
         
            +
            - LICENSE
         
     | 
| 
      
 22 
     | 
    
         
            +
            - README.md
         
     | 
| 
      
 23 
     | 
    
         
            +
            - lib/chart-horizontalbar-rails.rb
         
     | 
| 
      
 24 
     | 
    
         
            +
            - lib/chart-horizontalbar-rails/version.rb
         
     | 
| 
      
 25 
     | 
    
         
            +
            - vendor/assets/javascripts/Chart.HorizontalBar.js
         
     | 
| 
      
 26 
     | 
    
         
            +
            homepage: https://github.com/meowsus/chart-horizontalbar-rails
         
     | 
| 
      
 27 
     | 
    
         
            +
            licenses:
         
     | 
| 
      
 28 
     | 
    
         
            +
            - MIT
         
     | 
| 
      
 29 
     | 
    
         
            +
            metadata: {}
         
     | 
| 
      
 30 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
      
 31 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 32 
     | 
    
         
            +
            require_paths:
         
     | 
| 
      
 33 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 34 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 35 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 36 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 37 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 38 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 39 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 40 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 41 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 42 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 43 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 44 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 45 
     | 
    
         
            +
            rubyforge_project: 
         
     | 
| 
      
 46 
     | 
    
         
            +
            rubygems_version: 2.4.5
         
     | 
| 
      
 47 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 48 
     | 
    
         
            +
            specification_version: 4
         
     | 
| 
      
 49 
     | 
    
         
            +
            summary: A build of the Chart.js Horizontal Bar plugin, written by Tom Southall, packaged
         
     | 
| 
      
 50 
     | 
    
         
            +
              for the Rails asset pipeline.
         
     | 
| 
      
 51 
     | 
    
         
            +
            test_files: []
         
     |