Subversion-Projekte lars-tiefland.cienc

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
5 lars 1
describe 'Morris.Bar', ->
2
  describe 'when using vertical grid', ->
3
    defaults =
4
      element: 'graph'
5
      data: [{x: 'foo', y: 2, z: 3}, {x: 'bar', y: 4, z: 6}]
6
      xkey: 'x'
7
      ykeys: ['y', 'z']
8
      labels: ['Y', 'Z']
9
      barColors: [ '#0b62a4', '#7a92a3']
10
      gridLineColor: '#aaa'
11
      gridStrokeWidth: 0.5
12
      gridTextColor: '#888'
13
      gridTextSize: 12
14
      verticalGridCondition: (index) -> index % 2
15
      verticalGridColor: '#888888'
16
      verticalGridOpacity: '0.2'
17
 
18
    describe 'svg structure', ->
19
      it 'should contain extra rectangles for vertical grid', ->
20
        $('#graph').css('height', '250px').css('width', '800px')
21
        chart = Morris.Bar $.extend {}, defaults
22
        $('#graph').find("rect").size().should.equal 6
23
 
24
    describe 'svg attributes', ->
25
      it 'should have to bars with verticalGrid.color', ->
26
        chart = Morris.Bar $.extend {}, defaults
27
        $('#graph').find("rect[fill='#{defaults.verticalGridColor}']").size().should.equal 2
28
      it 'should have to bars with verticalGrid.color', ->
29
        chart = Morris.Bar $.extend {}, defaults
30
        $('#graph').find("rect[fill-opacity='#{defaults.verticalGridOpacity}']").size().should.equal 2
31
 
32
  describe 'svg structure', ->
33
    defaults =
34
      element: 'graph'
35
      data: [{x: 'foo', y: 2, z: 3}, {x: 'bar', y: 4, z: 6}]
36
      xkey: 'x'
37
      ykeys: ['y', 'z']
38
      labels: ['Y', 'Z']
39
 
40
    it 'should contain a rect for each bar', ->
41
      chart = Morris.Bar $.extend {}, defaults
42
      $('#graph').find("rect").size().should.equal 4
43
 
44
    it 'should contain 5 grid lines', ->
45
      chart = Morris.Bar $.extend {}, defaults
46
      $('#graph').find("path").size().should.equal 5
47
 
48
    it 'should contain 7 text elements', ->
49
      chart = Morris.Bar $.extend {}, defaults
50
      $('#graph').find("text").size().should.equal 7
51
 
52
  describe 'svg attributes', ->
53
    defaults =
54
      element: 'graph'
55
      data: [{x: 'foo', y: 2, z: 3}, {x: 'bar', y: 4, z: 6}]
56
      xkey: 'x'
57
      ykeys: ['y', 'z']
58
      labels: ['Y', 'Z']
59
      barColors: [ '#0b62a4', '#7a92a3']
60
      gridLineColor: '#aaa'
61
      gridStrokeWidth: 0.5
62
      gridTextColor: '#888'
63
      gridTextSize: 12
64
 
65
    it 'should have a bar with the first default color', ->
66
      chart = Morris.Bar $.extend {}, defaults
67
      $('#graph').find("rect[fill='#0b62a4']").size().should.equal 2
68
 
69
    it 'should have a bar with no stroke', ->
70
      chart = Morris.Bar $.extend {}, defaults
71
      $('#graph').find("rect[stroke='none']").size().should.equal 4
72
 
73
    it 'should have text with configured fill color', ->
74
      chart = Morris.Bar $.extend {}, defaults
75
      $('#graph').find("text[fill='#888888']").size().should.equal 7
76
 
77
    it 'should have text with configured font size', ->
78
      chart = Morris.Bar $.extend {}, defaults
79
      $('#graph').find("text[font-size='12px']").size().should.equal 7
80
 
81
  describe 'when setting bar radius', ->
82
    describe 'svg structure', ->
83
      defaults =
84
        element: 'graph'
85
        data: [{x: 'foo', y: 2, z: 3}, {x: 'bar', y: 4, z: 6}]
86
        xkey: 'x'
87
        ykeys: ['y', 'z']
88
        labels: ['Y', 'Z']
89
        barRadius: [5, 5, 0, 0]
90
 
91
      it 'should contain a path for each bar', ->
92
        chart = Morris.Bar $.extend {}, defaults
93
        $('#graph').find("path").size().should.equal 9
94
 
95
      it 'should use rects if radius is too big', ->
96
        delete defaults.barStyle
97
        chart = Morris.Bar $.extend {}, defaults,
98
            barRadius: [300, 300, 0, 0]
99
        $('#graph').find("rect").size().should.equal 4
100
 
101
  describe 'barSize option', ->
102
    describe 'svg attributes', ->
103
      defaults =
104
        element: 'graph'
105
        barSize: 20
106
        data: [
107
          {x: '2011 Q1', y: 3, z: 2, a: 3}
108
          {x: '2011 Q2', y: 2, z: null, a: 1}
109
          {x: '2011 Q3', y: 0, z: 2, a: 4}
110
          {x: '2011 Q4', y: 2, z: 4, a: 3}
111
        ],
112
        xkey: 'x'
113
        ykeys: ['y', 'z', 'a']
114
        labels: ['Y', 'Z', 'A']
115
 
116
      it 'should calc the width if too narrow for barSize', ->
117
        $('#graph').width('200px')
118
        chart = Morris.Bar $.extend {}, defaults
119
        $('#graph').find("rect").filter((i) ->
120
          parseFloat($(@).attr('width'), 10) < 10
121
        ).size().should.equal 11
122
 
123
      it 'should set width to @options.barSize if possible', ->
124
        chart = Morris.Bar $.extend {}, defaults
125
        $('#graph').find("rect[width='#{defaults.barSize}']").size().should.equal 11
126
 
127