Blame | Last modification | View Log | Download | RSS feed
describe 'Morris.Bar', ->describe 'when using vertical grid', ->defaults =element: 'graph'data: [{x: 'foo', y: 2, z: 3}, {x: 'bar', y: 4, z: 6}]xkey: 'x'ykeys: ['y', 'z']labels: ['Y', 'Z']barColors: [ '#0b62a4', '#7a92a3']gridLineColor: '#aaa'gridStrokeWidth: 0.5gridTextColor: '#888'gridTextSize: 12verticalGridCondition: (index) -> index % 2verticalGridColor: '#888888'verticalGridOpacity: '0.2'describe 'svg structure', ->it 'should contain extra rectangles for vertical grid', ->$('#graph').css('height', '250px').css('width', '800px')chart = Morris.Bar $.extend {}, defaults$('#graph').find("rect").size().should.equal 6describe 'svg attributes', ->it 'should have to bars with verticalGrid.color', ->chart = Morris.Bar $.extend {}, defaults$('#graph').find("rect[fill='#{defaults.verticalGridColor}']").size().should.equal 2it 'should have to bars with verticalGrid.color', ->chart = Morris.Bar $.extend {}, defaults$('#graph').find("rect[fill-opacity='#{defaults.verticalGridOpacity}']").size().should.equal 2describe 'svg structure', ->defaults =element: 'graph'data: [{x: 'foo', y: 2, z: 3}, {x: 'bar', y: 4, z: 6}]xkey: 'x'ykeys: ['y', 'z']labels: ['Y', 'Z']it 'should contain a rect for each bar', ->chart = Morris.Bar $.extend {}, defaults$('#graph').find("rect").size().should.equal 4it 'should contain 5 grid lines', ->chart = Morris.Bar $.extend {}, defaults$('#graph').find("path").size().should.equal 5it 'should contain 7 text elements', ->chart = Morris.Bar $.extend {}, defaults$('#graph').find("text").size().should.equal 7describe 'svg attributes', ->defaults =element: 'graph'data: [{x: 'foo', y: 2, z: 3}, {x: 'bar', y: 4, z: 6}]xkey: 'x'ykeys: ['y', 'z']labels: ['Y', 'Z']barColors: [ '#0b62a4', '#7a92a3']gridLineColor: '#aaa'gridStrokeWidth: 0.5gridTextColor: '#888'gridTextSize: 12it 'should have a bar with the first default color', ->chart = Morris.Bar $.extend {}, defaults$('#graph').find("rect[fill='#0b62a4']").size().should.equal 2it 'should have a bar with no stroke', ->chart = Morris.Bar $.extend {}, defaults$('#graph').find("rect[stroke='none']").size().should.equal 4it 'should have text with configured fill color', ->chart = Morris.Bar $.extend {}, defaults$('#graph').find("text[fill='#888888']").size().should.equal 7it 'should have text with configured font size', ->chart = Morris.Bar $.extend {}, defaults$('#graph').find("text[font-size='12px']").size().should.equal 7describe 'when setting bar radius', ->describe 'svg structure', ->defaults =element: 'graph'data: [{x: 'foo', y: 2, z: 3}, {x: 'bar', y: 4, z: 6}]xkey: 'x'ykeys: ['y', 'z']labels: ['Y', 'Z']barRadius: [5, 5, 0, 0]it 'should contain a path for each bar', ->chart = Morris.Bar $.extend {}, defaults$('#graph').find("path").size().should.equal 9it 'should use rects if radius is too big', ->delete defaults.barStylechart = Morris.Bar $.extend {}, defaults,barRadius: [300, 300, 0, 0]$('#graph').find("rect").size().should.equal 4describe 'barSize option', ->describe 'svg attributes', ->defaults =element: 'graph'barSize: 20data: [{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 11it 'should set width to @options.barSize if possible', ->chart = Morris.Bar $.extend {}, defaults$('#graph').find("rect[width='#{defaults.barSize}']").size().should.equal 11