"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 d3Color = __importStar(require("d3-color"));
const chai_1 = require("chai");
const bqplot = __importStar(require(".."));
const dummy_manager_1 = require("./dummy-manager");
const widget_utils_1 = require("./widget-utils");
describe('pie >', () => {
    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 sizes = {
                dtype: 'float32',
                value: new DataView(new Float32Array([0, 1, 4]).buffer),
            };
            const objects = yield widget_utils_1.create_figure_pie(this.manager, sizes, [
                'foo',
                'bar',
                'baz',
            ]);
            const pie = objects.pie;
            d3Timer.timerFlush();
            const slices = pie.d3el.selectAll('.slice');
            const labels = pie.d3el.selectAll('.labels').selectAll('text');
            // Check slice values
            const data = slices.data();
            chai_1.expect(data[0].value).to.equal(0);
            chai_1.expect(data[1].value).to.equal(1);
            chai_1.expect(data[2].value).to.equal(4);
            // Check slice colors
            const sliceElts = slices.nodes();
            chai_1.expect(sliceElts[0].style.fill).to.equal(d3Color.rgb('#1f77b4').toString());
            chai_1.expect(sliceElts[1].style.fill).to.equal(d3Color.rgb('#ff7f0e').toString());
            chai_1.expect(sliceElts[2].style.fill).to.equal(d3Color.rgb('#2ca02c').toString());
            // Check labels
            const labelElts = labels.nodes();
            chai_1.expect(labelElts[0].innerHTML).to.equal('foo');
            chai_1.expect(parseFloat(labelElts[0].style.opacity)).to.equal(0);
            chai_1.expect(labelElts[1].innerHTML).to.equal('bar');
            chai_1.expect(parseFloat(labelElts[1].style.opacity)).to.equal(1);
            chai_1.expect(labelElts[2].innerHTML).to.equal('baz');
            chai_1.expect(parseFloat(labelElts[2].style.opacity)).to.equal(1);
        });
    });
    it('update colors', function () {
        return __awaiter(this, void 0, void 0, function* () {
            const sizes = {
                dtype: 'float32',
                value: new DataView(new Float32Array([1, 3, 4, 5]).buffer),
            };
            const objects = yield widget_utils_1.create_figure_pie(this.manager, sizes, [
                'foo',
                'bar',
                'baz',
                'Hello World',
            ]);
            const pie = objects.pie;
            d3Timer.timerFlush();
            const slices = pie.d3el.selectAll('.slice');
            // Check slice colors
            const sliceElts = slices.nodes();
            chai_1.expect(sliceElts[0].style.fill).to.equal(d3Color.rgb('#1f77b4').toString());
            chai_1.expect(sliceElts[1].style.fill).to.equal(d3Color.rgb('#ff7f0e').toString());
            chai_1.expect(sliceElts[2].style.fill).to.equal(d3Color.rgb('#2ca02c').toString());
            chai_1.expect(sliceElts[3].style.fill).to.equal(d3Color.rgb('#d62728').toString());
            // Update slice colors
            pie.model.set('colors', ['red', 'blue', 'green', 'steelblue']);
            d3Timer.timerFlush();
            chai_1.expect(sliceElts[0].style.fill).to.equal('red');
            chai_1.expect(sliceElts[1].style.fill).to.equal('blue');
            chai_1.expect(sliceElts[2].style.fill).to.equal('green');
            chai_1.expect(sliceElts[3].style.fill).to.equal('steelblue');
            // Update slice colors
            pie.model.set('colors', ['red', 'blue']);
            d3Timer.timerFlush();
            chai_1.expect(sliceElts[0].style.fill).to.equal('red');
            chai_1.expect(sliceElts[1].style.fill).to.equal('blue');
            chai_1.expect(sliceElts[2].style.fill).to.equal('red');
            chai_1.expect(sliceElts[3].style.fill).to.equal('blue');
        });
    });
    it('update text', function () {
        return __awaiter(this, void 0, void 0, function* () {
            const sizes = {
                dtype: 'float32',
                value: new DataView(new Float32Array([1, 0, 4, 5]).buffer),
            };
            const objects = yield widget_utils_1.create_figure_pie(this.manager, sizes, [
                'foo',
                'bar',
                'baz',
                'Hello World',
            ]);
            const pie = objects.pie;
            d3Timer.timerFlush();
            let labels = pie.d3el.selectAll('.labels').selectAll('text');
            // Check labels
            let labelElts = labels.nodes();
            chai_1.expect(labelElts[0].innerHTML).to.equal('foo');
            chai_1.expect(parseFloat(labelElts[0].style.opacity)).to.equal(1);
            chai_1.expect(labelElts[1].innerHTML).to.equal('bar');
            chai_1.expect(parseFloat(labelElts[1].style.opacity)).to.equal(0);
            chai_1.expect(labelElts[2].innerHTML).to.equal('baz');
            chai_1.expect(parseFloat(labelElts[2].style.opacity)).to.equal(1);
            chai_1.expect(labelElts[3].innerHTML).to.equal('Hello World');
            chai_1.expect(parseFloat(labelElts[3].style.opacity)).to.equal(1);
            // Update pie data
            pie.model.set('sizes', [1, 2, 0, 5, 6]);
            pie.model.set('labels', ['hey', 'there', 'how', 'are', 'you']);
            d3Timer.timerFlush();
            labels = pie.d3el.selectAll('.labels').selectAll('text');
            // Check labels
            labelElts = labels.nodes();
            chai_1.expect(labelElts[0].innerHTML).to.equal('hey');
            chai_1.expect(parseFloat(labelElts[0].style.opacity)).to.equal(1);
            chai_1.expect(labelElts[1].innerHTML).to.equal('there');
            chai_1.expect(parseFloat(labelElts[1].style.opacity)).to.equal(1);
            chai_1.expect(labelElts[2].innerHTML).to.equal('how');
            chai_1.expect(parseFloat(labelElts[2].style.opacity)).to.equal(0);
            chai_1.expect(labelElts[3].innerHTML).to.equal('are');
            chai_1.expect(parseFloat(labelElts[3].style.opacity)).to.equal(1);
            chai_1.expect(labelElts[4].innerHTML).to.equal('you');
            chai_1.expect(parseFloat(labelElts[4].style.opacity)).to.equal(1);
        });
    });
    it('update selected', function () {
        return __awaiter(this, void 0, void 0, function* () {
            const sizes = {
                dtype: 'float32',
                value: new DataView(new Float32Array([1, 0, 4, 5]).buffer),
            };
            const objects = yield widget_utils_1.create_figure_pie(this.manager, sizes, [
                'foo',
                'bar',
                'baz',
                'Hello World',
            ]);
            const pie = objects.pie;
            d3Timer.timerFlush();
            pie.model.set('selected', new Float32Array([0, 1]));
            pie.model.set('selected_style', { fill: 'red', opacity: 1 });
            d3Timer.timerFlush();
            const slices = pie.pieSelection.selectAll('.slice');
            // Check slice colors
            const sliceElts = slices.nodes();
            chai_1.expect(sliceElts[0].style.fill).to.equal('red');
            chai_1.expect(sliceElts[1].style.fill).to.equal('red');
            chai_1.expect(sliceElts[2].style.fill).to.equal(d3Color.rgb('#2ca02c').toString());
            chai_1.expect(sliceElts[3].style.fill).to.equal(d3Color.rgb('#d62728').toString());
            pie.model.set('selected', new Float32Array([1, 2]));
            d3Timer.timerFlush();
            chai_1.expect(sliceElts[0].style.fill).to.equal(d3Color.rgb('#1f77b4').toString());
            chai_1.expect(sliceElts[1].style.fill).to.equal('red');
            chai_1.expect(sliceElts[2].style.fill).to.equal('red');
            chai_1.expect(sliceElts[3].style.fill).to.equal(d3Color.rgb('#d62728').toString());
            pie.model.set('selected', new Float32Array([0, 1]));
            pie.model.set('selected_style', {});
            pie.model.set('unselected_style', { fill: 'blue', opacity: 0.1 });
            d3Timer.timerFlush();
            // Check slice colors
            chai_1.expect(sliceElts[0].style.fill).to.equal(d3Color.rgb('#1f77b4').toString());
            chai_1.expect(sliceElts[1].style.fill).to.equal(d3Color.rgb('#ff7f0e').toString());
            chai_1.expect(sliceElts[2].style.fill).to.equal('blue');
            chai_1.expect(parseFloat(sliceElts[2].style.opacity)).to.equal(0.1);
            chai_1.expect(sliceElts[3].style.fill).to.equal('blue');
            chai_1.expect(parseFloat(sliceElts[3].style.opacity)).to.equal(0.1);
            pie.model.set('selected', new Float32Array([1, 2]));
            d3Timer.timerFlush();
            chai_1.expect(sliceElts[0].style.fill).to.equal('blue');
            chai_1.expect(parseFloat(sliceElts[0].style.opacity)).to.equal(0.1);
            chai_1.expect(sliceElts[1].style.fill).to.equal(d3Color.rgb('#ff7f0e').toString());
            chai_1.expect(sliceElts[2].style.fill).to.equal(d3Color.rgb('#2ca02c').toString());
            chai_1.expect(sliceElts[3].style.fill).to.equal('blue');
            chai_1.expect(parseFloat(sliceElts[3].style.opacity)).to.equal(0.1);
        });
    });
});
//# sourceMappingURL=pie.js.map