Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | espaco | 1 | describe 'Morris.Bar#colorFor', -> |
| 2 | |||
| 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 | |||
| 10 | it 'should fetch colours from an array', -> |
||
| 11 | chart = Morris.Bar $.extend {}, defaults, barColors: ['#f00', '#0f0', '#00f'] |
||
| 12 | chart.colorFor(chart.data[0], 0, 'bar').should.equal '#f00' |
||
| 13 | chart.colorFor(chart.data[0], 0, 'hover').should.equal '#f00' |
||
| 14 | chart.colorFor(chart.data[0], 1, 'bar').should.equal '#0f0' |
||
| 15 | chart.colorFor(chart.data[0], 1, 'hover').should.equal '#0f0' |
||
| 16 | chart.colorFor(chart.data[0], 2, 'bar').should.equal '#00f' |
||
| 17 | chart.colorFor(chart.data[0], 2, 'hover').should.equal '#00f' |
||
| 18 | chart.colorFor(chart.data[0], 3, 'bar').should.equal '#f00' |
||
| 19 | chart.colorFor(chart.data[0], 4, 'hover').should.equal '#0f0' |
||
| 20 | |||
| 21 | it 'should defer to a callback', -> |
||
| 22 | stub = sinon.stub().returns '#f00' |
||
| 23 | chart = Morris.Bar $.extend {}, defaults, barColors: stub |
||
| 24 | stub.reset() |
||
| 25 | |||
| 26 | chart.colorFor(chart.data[0], 0, 'bar') |
||
| 27 | stub.should.have.been.calledWith( |
||
| 28 | {x:0, y:2, label:'foo'}, |
||
| 29 | {index:0, key:'y', label:'Y'}, |
||
| 30 | 'bar') |
||
| 31 | |||
| 32 | chart.colorFor(chart.data[0], 1, 'hover') |
||
| 33 | stub.should.have.been.calledWith( |
||
| 34 | {x:0, y:3, label:'foo'}, |
||
| 35 | {index:1, key:'z', label:'Z'}, |
||
| 36 | 'hover') |