"use strict";
// import * as d3Timer from 'd3-timer';
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 chai_1 = require("chai");
const dummy_manager_1 = require("./dummy-manager");
const widget_utils_1 = require("./widget-utils");
const bqplot = __importStar(require(".."));
describe('hist >', () => {
    beforeEach(function () {
        return __awaiter(this, void 0, void 0, function* () {
            this.manager = new dummy_manager_1.DummyManager({ bqplot: bqplot });
        });
    });
    it('colors', function () {
        return __awaiter(this, void 0, void 0, function* () {
            const sample = {
                dtype: 'float32',
                value: new DataView(new Float32Array(new Array(100).keys()).buffer),
            };
            const objects = yield widget_utils_1.create_figure_hist(this.manager, sample, 3);
            const hist = objects.hist;
            let rects = hist.d3el.selectAll('.bargroup').selectAll('.rect');
            // Default color
            let colors = widget_utils_1.getFills(rects);
            chai_1.expect(colors[0]).to.equal('steelblue');
            chai_1.expect(colors[1]).to.equal('steelblue');
            chai_1.expect(colors[2]).to.equal('steelblue');
            // Update colors
            hist.model.set('colors', ['steelblue', 'red', 'green']);
            colors = widget_utils_1.getFills(rects);
            chai_1.expect(colors[0]).to.equal('steelblue');
            chai_1.expect(colors[1]).to.equal('red');
            chai_1.expect(colors[2]).to.equal('green');
            // Colors should cycle
            hist.model.set('bins', 6);
            rects = hist.d3el.selectAll('.bargroup').selectAll('.rect');
            colors = widget_utils_1.getFills(rects);
            chai_1.expect(colors[0]).to.equal('steelblue');
            chai_1.expect(colors[1]).to.equal('red');
            chai_1.expect(colors[2]).to.equal('green');
            chai_1.expect(colors[3]).to.equal('steelblue');
            chai_1.expect(colors[4]).to.equal('red');
            chai_1.expect(colors[5]).to.equal('green');
        });
    });
    it('selected', function () {
        return __awaiter(this, void 0, void 0, function* () {
            const sample = {
                dtype: 'float32',
                value: new DataView(new Float32Array(new Array(100).keys()).buffer),
            };
            const objects = yield widget_utils_1.create_figure_hist(this.manager, sample, 6);
            const hist = objects.hist;
            const rects = hist.d3el.selectAll('.bargroup').selectAll('.rect');
            hist.model.set('selected_style', { fill: 'orange' });
            hist.model.set('unselected_style', { fill: 'red' });
            // Default color, no selection
            let colors = widget_utils_1.getFills(rects);
            chai_1.expect(colors[0]).to.equal('steelblue');
            chai_1.expect(colors[1]).to.equal('steelblue');
            chai_1.expect(colors[2]).to.equal('steelblue');
            chai_1.expect(colors[3]).to.equal('steelblue');
            chai_1.expect(colors[4]).to.equal('steelblue');
            chai_1.expect(colors[5]).to.equal('steelblue');
            // Simulate selection of the first bar from back-end
            hist.model.set('selected', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
            colors = widget_utils_1.getFills(rects);
            chai_1.expect(colors[0]).to.equal('orange');
            chai_1.expect(colors[1]).to.equal('red');
            chai_1.expect(colors[2]).to.equal('red');
            chai_1.expect(colors[3]).to.equal('red');
            chai_1.expect(colors[4]).to.equal('red');
            chai_1.expect(colors[5]).to.equal('red');
            // Simulate selection of both the first and the second bar from back-end
            // (there is no current way of visually showing the selection of a subset of the data in a bin)
            hist.model.set('selected', [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]);
            colors = widget_utils_1.getFills(rects);
            chai_1.expect(colors[0]).to.equal('orange');
            chai_1.expect(colors[1]).to.equal('orange');
            chai_1.expect(colors[2]).to.equal('red');
            chai_1.expect(colors[3]).to.equal('red');
            chai_1.expect(colors[4]).to.equal('red');
            chai_1.expect(colors[5]).to.equal('red');
        });
    });
});
//# sourceMappingURL=hist.js.map