| 1 |
import * as d3Timer from 'd3-timer'; |
| 2 |
|
| 3 |
import { expect } from 'chai'; |
| 4 |
|
| 5 |
import * as bqplot from '..'; |
| 6 |
|
| 7 |
import { DummyManager } from './dummy-manager'; |
| 8 |
|
| 9 |
import { create_figure_gridheatmap, getFills } from './widget-utils'; |
| 10 |
|
| 11 |
describe('gridheatmap >', () => { |
| 12 |
beforeEach(async function () { |
| 13 |
this.manager = new DummyManager({ bqplot: bqplot }); |
| 14 |
}); |
| 15 |
|
| 16 |
it('create', async function () { |
| 17 |
const colors = [ |
| 18 |
[0, 1, 2], |
| 19 |
[3, 4, 5], |
| 20 |
[6, 7, 8], |
| 21 |
]; |
| 22 |
const objects = await create_figure_gridheatmap(this.manager, colors); |
| 23 |
const grid = objects.grid; |
| 24 |
|
| 25 |
d3Timer.timerFlush(); |
| 26 |
|
| 27 |
const rows = grid.d3el.selectAll('.heatmaprow'); |
| 28 |
|
| 29 |
const rowPositions = rows |
| 30 |
.nodes() |
| 31 |
.map((row) => row.getAttribute('transform')); |
| 32 |
expect(rowPositions[0]).to.equal('translate(0, 0)'); |
| 33 |
expect(rowPositions[1]).to.equal('translate(0, 166.66666666666666)'); |
| 34 |
expect(rowPositions[2]).to.equal('translate(0, 333.3333333333333)'); |
| 35 |
|
| 36 |
const rects = rows.selectAll('rect'); |
| 37 |
const expectedColors = [ |
| 38 |
'rgb(165, 0, 38)', |
| 39 |
'rgb(222, 63, 46)', |
| 40 |
'rgb(249, 142, 82)', |
| 41 |
'rgb(254, 212, 129)', |
| 42 |
'rgb(255, 255, 191)', |
| 43 |
'rgb(204, 234, 131)', |
| 44 |
'rgb(134, 203, 103)', |
| 45 |
'rgb(45, 161, 85)', |
| 46 |
'rgb(0, 104, 55)', |
| 47 |
]; |
| 48 |
expect(getFills(rects)).to.eql(expectedColors); |
| 49 |
}); |
| 50 |
|
| 51 |
it('update selected', async function () { |
| 52 |
const colors = [ |
| 53 |
[0, 1, 2], |
| 54 |
[3, 4, 5], |
| 55 |
[6, 7, 8], |
| 56 |
]; |
| 57 |
const objects = await create_figure_gridheatmap(this.manager, colors); |
| 58 |
const grid = objects.grid; |
| 59 |
|
| 60 |
d3Timer.timerFlush(); |
| 61 |
|
| 62 |
grid.model.set('selected', [ |
| 63 |
[0, 1], |
| 64 |
[1, 1], |
| 65 |
[2, 0], |
| 66 |
]); |
| 67 |
grid.model.set('selected_style', { fill: 'red', opacity: 1 }); |
| 68 |
|
| 69 |
d3Timer.timerFlush(); |
| 70 |
|
| 71 |
const rows = grid.d3el.selectAll('.heatmaprow'); |
| 72 |
const rects = rows.selectAll('rect'); |
| 73 |
let expectedColors = [ |
| 74 |
'rgb(165, 0, 38)', |
| 75 |
'red', |
| 76 |
'rgb(249, 142, 82)', |
| 77 |
'rgb(254, 212, 129)', |
| 78 |
'red', |
| 79 |
'rgb(204, 234, 131)', |
| 80 |
'red', |
| 81 |
'rgb(45, 161, 85)', |
| 82 |
'rgb(0, 104, 55)', |
| 83 |
]; |
| 84 |
|
| 85 |
expect(getFills(rects)).to.eql(expectedColors); |
| 86 |
|
| 87 |
grid.model.set('selected', [ |
| 88 |
[0, 2], |
| 89 |
[1, 1], |
| 90 |
[2, 1], |
| 91 |
]); |
| 92 |
|
| 93 |
d3Timer.timerFlush(); |
| 94 |
|
| 95 |
expectedColors = [ |
| 96 |
'rgb(165, 0, 38)', |
| 97 |
'rgb(222, 63, 46)', |
| 98 |
'red', |
| 99 |
'rgb(254, 212, 129)', |
| 100 |
'red', |
| 101 |
'rgb(204, 234, 131)', |
| 102 |
'rgb(134, 203, 103)', |
| 103 |
'red', |
| 104 |
'rgb(0, 104, 55)', |
| 105 |
]; |
| 106 |
|
| 107 |
expect(getFills(rects)).to.eql(expectedColors); |
| 108 |
}); |
| 109 |
}); |