Created
June 26, 2015 08:05
-
-
Save goozler/aef858d267de71c44cef to your computer and use it in GitHub Desktop.
StaticBars for charts.js (undescore need)
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
Chart.types.Bar.extend | |
name: 'StaticBar' | |
draw: -> | |
if _.isNumber(@options.barWidth) | |
datasets = @datasets.length | |
columns = @datasets[0].bars.length | |
bars = columns * datasets | |
barsWidth = bars * @options.barWidth | |
datasetSpacing = @options.barDatasetSpacing * columns * (datasets - 1) | |
paddings = @scale.xScalePaddingRight + @scale.xScalePaddingLeft | |
remainingSpace = @chart.width - barsWidth - datasetSpacing - paddings | |
if remainingSpace < 0 | |
console.log "Bars don't fit!" | |
else | |
@options.barValueSpacing = remainingSpace / (columns * 2) | |
Chart.types.Bar.prototype.draw.apply(@, arguments) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment