"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const d3Timer = __importStar(require("d3-timer"));
const chai_1 = require("chai");
const bqplot = __importStar(require(".."));
const dummy_manager_1 = require("./dummy-manager");
const widget_utils_1 = require("./widget-utils");
describe('gridheatmap >', () => {
    beforeEach(function () {
        return __awaiter(this, void 0, void 0, function* () {
            this.manager = new dummy_manager_1.DummyManager({ bqplot: bqplot });
        });
    });
    it('create', function () {
        return __awaiter(this, void 0, void 0, function* () {
            const colors = [
                [0, 1, 2],
                [3, 4, 5],
                [6, 7, 8],
            ];
            const objects = yield widget_utils_1.create_figure_gridheatmap(this.manager, colors);
            const grid = objects.grid;
            d3Timer.timerFlush();
            const rows = grid.d3el.selectAll('.heatmaprow');
            const rowPositions = rows
                .nodes()
                .map((row) => row.getAttribute('transform'));
            chai_1.expect(rowPositions[0]).to.equal('translate(0, 0)');
            chai_1.expect(rowPositions[1]).to.equal('translate(0, 166.66666666666666)');
            chai_1.expect(rowPositions[2]).to.equal('translate(0, 333.3333333333333)');
            const rects = rows.selectAll('rect');
            const expectedColors = [
                'rgb(165, 0, 38)',
                'rgb(222, 63, 46)',
                'rgb(249, 142, 82)',
                'rgb(254, 212, 129)',
                'rgb(255, 255, 191)',
                'rgb(204, 234, 131)',
                'rgb(134, 203, 103)',
                'rgb(45, 161, 85)',
                'rgb(0, 104, 55)',
            ];
            chai_1.expect(widget_utils_1.getFills(rects)).to.eql(expectedColors);
        });
    });
    it('update selected', function () {
        return __awaiter(this, void 0, void 0, function* () {
            const colors = [
                [0, 1, 2],
                [3, 4, 5],
                [6, 7, 8],
            ];
            const objects = yield widget_utils_1.create_figure_gridheatmap(this.manager, colors);
            const grid = objects.grid;
            d3Timer.timerFlush();
            grid.model.set('selected', [
                [0, 1],
                [1, 1],
                [2, 0],
            ]);
            grid.model.set('selected_style', { fill: 'red', opacity: 1 });
            d3Timer.timerFlush();
            const rows = grid.d3el.selectAll('.heatmaprow');
            const rects = rows.selectAll('rect');
            let expectedColors = [
                'rgb(165, 0, 38)',
                'red',
                'rgb(249, 142, 82)',
                'rgb(254, 212, 129)',
                'red',
                'rgb(204, 234, 131)',
                'red',
                'rgb(45, 161, 85)',
                'rgb(0, 104, 55)',
            ];
            chai_1.expect(widget_utils_1.getFills(rects)).to.eql(expectedColors);
            grid.model.set('selected', [
                [0, 2],
                [1, 1],
                [2, 1],
            ]);
            d3Timer.timerFlush();
            expectedColors = [
                'rgb(165, 0, 38)',
                'rgb(222, 63, 46)',
                'red',
                'rgb(254, 212, 129)',
                'red',
                'rgb(204, 234, 131)',
                'rgb(134, 203, 103)',
                'red',
                'rgb(0, 104, 55)',
            ];
            chai_1.expect(widget_utils_1.getFills(rects)).to.eql(expectedColors);
        });
    });
});
//# sourceMappingURL=gridheatmap.js.map