"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 chai_1 = require("chai");
const dummy_manager_1 = require("./dummy-manager");
const bqplot = __importStar(require(".."));
const widget_utils_1 = require("./widget-utils");
const d3Timer = __importStar(require("d3-timer"));
describe('scatter >', () => {
    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 x = {
                dtype: 'float32',
                value: new DataView(new Float32Array([0, 1]).buffer),
            };
            const y = {
                dtype: 'float32',
                value: new DataView(new Float32Array([2, 3]).buffer),
            };
            const objects = yield widget_utils_1.create_figure_scatter(this.manager, x, y);
            const scatter = objects.scatter;
            const data = scatter.d3el.selectAll('.object_grp').data();
            chai_1.expect(data[0].x).to.equal(0);
            chai_1.expect(data[1].x).to.equal(1);
            chai_1.expect(data[0].y).to.equal(2);
            chai_1.expect(data[1].y).to.equal(3);
            d3Timer.timerFlush(); // this makes sure the animations are all executed
            const transforms = scatter.d3el
                .selectAll('.object_grp')
                .nodes()
                .map((el) => el.getAttribute('transform'));
            const width = objects.figure.plotarea_width;
            const height = objects.figure.plotarea_height;
            chai_1.expect(transforms).to.deep.equal([
                `translate(0, ${height})`,
                `translate(${width}, 0)`,
            ]);
        });
    });
    it('computed fill', function () {
        return __awaiter(this, void 0, void 0, function* () {
            const x = [0, 1];
            const y = [2, 3];
            const objects = yield widget_utils_1.create_figure_scatter(this.manager, x, y);
            const scatter = objects.scatter;
            const elements = scatter.d3el.selectAll('.object_grp .element');
            chai_1.expect(widget_utils_1.getFills(elements)).to.deep.equal(['steelblue', 'steelblue']);
            scatter.model.set('unselected_style', { fill: 'orange', stroke: 'none' });
            scatter.model.set('selected', [0]);
            chai_1.expect(widget_utils_1.getFills(elements)).to.deep.equal(['steelblue', 'orange']);
            scatter.model.set('colors', ['red']);
            chai_1.expect(widget_utils_1.getFills(elements)).to.deep.equal(['red', 'orange']);
            scatter.model.set('selected_style', { fill: 'green', stroke: 'none' });
            scatter.model.set('selected', [0]);
            chai_1.expect(widget_utils_1.getFills(elements)).to.deep.equal(['green', 'orange']);
            scatter.model.set('selected', [1]);
            chai_1.expect(widget_utils_1.getFills(elements)).to.deep.equal(['orange', 'green']);
            scatter.model.set('unselected_style', {});
            chai_1.expect(widget_utils_1.getFills(elements)).to.deep.equal(['red', 'green']);
            scatter.model.set('colors', []);
            chai_1.expect(widget_utils_1.getFills(elements)).to.deep.equal(['', 'green']);
            scatter.model.set('selected_style', {});
            chai_1.expect(widget_utils_1.getFills(elements)).to.deep.equal(['', '']);
        });
    });
});
//# sourceMappingURL=scatter.js.map