mirror of
https://github.com/morrisjs/morris.js.git
synced 2024-11-10 21:36:34 +01:00
Merge pull request #358 from sudodoki/feature/#311
Feature - bar max width
This commit is contained in:
commit
07c740414b
@ -92,7 +92,9 @@ class Morris.Bar extends Morris.Grid
|
||||
groupWidth = @width / @options.data.length
|
||||
numBars = if @options.stacked? then 1 else @options.ykeys.length
|
||||
barWidth = (groupWidth * @options.barSizeRatio - @options.barGap * (numBars - 1)) / numBars
|
||||
leftPadding = groupWidth * (1 - @options.barSizeRatio) / 2
|
||||
barWidth = Math.min(barWidth, @options.barSize) if @options.barSize
|
||||
spaceLeft = groupWidth - barWidth * numBars - @options.barGap * (numBars - 1)
|
||||
leftPadding = spaceLeft / 2
|
||||
zeroPos = if @ymin <= 0 and @ymax >= 0 then @transY(0) else null
|
||||
@bars = for row, idx in @data
|
||||
lastTop = 0
|
||||
|
@ -68,3 +68,31 @@ describe 'Morris.Bar', ->
|
||||
chart = Morris.Bar $.extend {}, defaults,
|
||||
barRadius: [300, 300, 0, 0]
|
||||
$('#graph').find("rect").size().should.equal 4
|
||||
|
||||
describe 'barSize option', ->
|
||||
describe 'svg attributes', ->
|
||||
defaults =
|
||||
element: 'graph'
|
||||
barSize: 20
|
||||
data: [
|
||||
{x: '2011 Q1', y: 3, z: 2, a: 3}
|
||||
{x: '2011 Q2', y: 2, z: null, a: 1}
|
||||
{x: '2011 Q3', y: 0, z: 2, a: 4}
|
||||
{x: '2011 Q4', y: 2, z: 4, a: 3}
|
||||
],
|
||||
xkey: 'x'
|
||||
ykeys: ['y', 'z', 'a']
|
||||
labels: ['Y', 'Z', 'A']
|
||||
|
||||
it 'should calc the width if too narrow for barSize', ->
|
||||
$('#graph').width('200px')
|
||||
chart = Morris.Bar $.extend {}, defaults
|
||||
$('#graph').find("rect").filter((i) ->
|
||||
parseFloat($(@).attr('width'), 10) < 10
|
||||
).size().should.equal 11
|
||||
|
||||
it 'should set width to @options.barSize if possible', ->
|
||||
chart = Morris.Bar $.extend {}, defaults
|
||||
$('#graph').find("rect[width='#{defaults.barSize}']").size().should.equal 11
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user