"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.prototype.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 = require("..");
const widget_utils_1 = require("./widget-utils");
const d3Timer = __importStar(require("d3-timer"));
describe('lines >', () => {
    beforeEach(function () {
        return __awaiter(this, void 0, void 0, function* () {
            this.manager = new dummy_manager_1.DummyManager({ bqplot: bqplot });
        });
    });
    it('model mark set methods', 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_lines(this.manager, x, y);
            const lines = objects.lines;
            lines.model.set('marker_size', 7);
            lines.model.set('marker', 'circle');
            lines.model.set('stroke_width', 3);
            lines.model.set('labels_visibility', 'label');
            lines.model.set('curves_subset', [2, 4, 5]);
            lines.model.set('line_style', 'solid');
        });
    });
    it('create 1d ordinal', function () {
        return __awaiter(this, void 0, void 0, function* () {
            const x = ['a', 'b'];
            const scale_x = yield widget_utils_1.create_model_bqplot(this.manager, 'OrdinalScale', 'scale_x_ordinal', { allow_padding: false, domain: [] });
            const y = {
                dtype: 'float32',
                value: new DataView(new Float32Array([2, 3]).buffer),
            };
            const objects = yield widget_utils_1.create_figure_lines(this.manager, x, y, {
                x: scale_x.toJSON(),
            });
            const lines = objects.lines;
            const data = lines.d3el.selectAll('.curve').data();
            chai_1.expect(data[0].values[0].x).to.equal('a');
            chai_1.expect(data[0].values[1].x).to.equal('b');
            chai_1.expect(data[0].values[0].y).to.equal(2);
            chai_1.expect(data[0].values[1].y).to.equal(3);
            lines.update_line_xy();
            d3Timer.timerFlush(); // this makes sure the animations are all executed
            const paths = lines.d3el
                .selectAll('.curve path.line')
                .nodes()
                .map((el) => el.getAttribute('d'));
            const width = objects.figure.plotarea_width;
            const height = objects.figure.plotarea_height;
            chai_1.expect(paths).to.deep.equal([
                `M${(width * 1) / 4},${height}L${(width * 3) / 4},0`,
            ]);
        });
    });
    it('create 1d', 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_lines(this.manager, x, y);
            const lines = objects.lines;
            const data = lines.d3el.selectAll('.curve').data();
            chai_1.expect(data[0].values[0].x).to.equal(0);
            chai_1.expect(data[0].values[1].x).to.equal(1);
            chai_1.expect(data[0].values[0].y).to.equal(2);
            chai_1.expect(data[0].values[1].y).to.equal(3);
            lines.update_line_xy();
            d3Timer.timerFlush(); // this makes sure the animations are all executed
            const paths = lines.d3el
                .selectAll('.curve path.line')
                .nodes()
                .map((el) => el.getAttribute('d'));
            const width = objects.figure.plotarea_width;
            const height = objects.figure.plotarea_height;
            chai_1.expect(paths).to.deep.equal([`M0,${height}L${width},0`]);
        });
    });
    it('create 2d classic', function () {
        return __awaiter(this, void 0, void 0, function* () {
            const x = [
                [0, 0.5, 1],
                [0.5, 0.5, 1],
            ];
            const y = [
                [2, 2.0, 3],
                [2.0, 2.5, 3],
            ];
            const objects = yield widget_utils_1.create_figure_lines(this.manager, x, y);
            const lines = objects.lines;
            const data = lines.d3el.selectAll('.curve').data();
            chai_1.expect(data[0].values[0].x).to.equal(0);
            chai_1.expect(data[0].values[1].x).to.equal(0.5);
            chai_1.expect(data[0].values[2].x).to.equal(1);
            chai_1.expect(data[0].values[0].y).to.equal(2);
            chai_1.expect(data[0].values[1].y).to.equal(2);
            chai_1.expect(data[0].values[2].y).to.equal(3);
            chai_1.expect(data[0].values).to.have.lengthOf(3);
            chai_1.expect(data[1].values[0].x).to.equal(0.5);
            chai_1.expect(data[1].values[1].x).to.equal(0.5);
            chai_1.expect(data[1].values[2].x).to.equal(1);
            chai_1.expect(data[1].values[0].y).to.equal(2.0);
            chai_1.expect(data[1].values[1].y).to.equal(2.5);
            chai_1.expect(data[1].values[2].y).to.equal(3);
            chai_1.expect(data[1].values).to.have.lengthOf(3);
            lines.update_line_xy();
            d3Timer.timerFlush(); // this makes sure the animations are all executed
            const paths = lines.d3el
                .selectAll('.curve path.line')
                .nodes()
                .map((el) => el.getAttribute('d'));
            const width = objects.figure.plotarea_width;
            const height = objects.figure.plotarea_height;
            chai_1.expect(paths).to.deep.equal([
                `M0,${height}L${width / 2},${height}L${width},0`,
                `M${width / 2},${height}L${width / 2},${height / 2}L${width},0`,
            ]);
        });
    });
    it('create 2d binary', function () {
        return __awaiter(this, void 0, void 0, function* () {
            const x = {
                dtype: 'float32',
                value: new DataView(new Float32Array([0.0, 0.5, 1.0, 0.5, 0.5, 1.0]).buffer),
                shape: [2, 3],
            };
            const y = {
                dtype: 'float32',
                value: new DataView(new Float32Array([2.0, 2.0, 3.0, 2.0, 2.5, 3.0]).buffer),
                shape: [2, 3],
            };
            const objects = yield widget_utils_1.create_figure_lines(this.manager, x, y);
            const lines = objects.lines;
            const data = lines.d3el.selectAll('.curve').data();
            chai_1.expect(data[0].values[0].x).to.equal(0);
            chai_1.expect(data[0].values[1].x).to.equal(0.5);
            chai_1.expect(data[0].values[2].x).to.equal(1);
            chai_1.expect(data[0].values[0].y).to.equal(2);
            chai_1.expect(data[0].values[1].y).to.equal(2);
            chai_1.expect(data[0].values[2].y).to.equal(3);
            chai_1.expect(data[0].values).to.have.lengthOf(3);
            chai_1.expect(data[1].values[0].x).to.equal(0.5);
            chai_1.expect(data[1].values[1].x).to.equal(0.5);
            chai_1.expect(data[1].values[2].x).to.equal(1);
            chai_1.expect(data[1].values[0].y).to.equal(2.0);
            chai_1.expect(data[1].values[1].y).to.equal(2.5);
            chai_1.expect(data[1].values[2].y).to.equal(3);
            chai_1.expect(data[1].values).to.have.lengthOf(3);
            lines.update_line_xy();
            d3Timer.timerFlush(); // this makes sure the animations are all executed
            const paths = lines.d3el
                .selectAll('.curve path.line')
                .nodes()
                .map((el) => el.getAttribute('d'));
            const width = objects.figure.plotarea_width;
            const height = objects.figure.plotarea_height;
            chai_1.expect(paths).to.deep.equal([
                `M0,${height}L${width / 2},${height}L${width},0`,
                `M${width / 2},${height}L${width / 2},${height / 2}L${width},0`,
            ]);
        });
    });
    it('create 2d binary shared x', function () {
        return __awaiter(this, void 0, void 0, function* () {
            const x = {
                dtype: 'float32',
                value: new DataView(new Float32Array([0.0, 0.5, 1.0]).buffer),
                shape: [3],
            };
            const y = {
                dtype: 'float32',
                value: new DataView(new Float32Array([2.0, 2.0, 3.0, 2.0, 2.5, 3.0]).buffer),
                shape: [2, 3],
            };
            const objects = yield widget_utils_1.create_figure_lines(this.manager, x, y);
            const lines = objects.lines;
            const data = lines.d3el.selectAll('.curve').data();
            chai_1.expect(data[0].values[0].x).to.equal(0);
            chai_1.expect(data[0].values[1].x).to.equal(0.5);
            chai_1.expect(data[0].values[2].x).to.equal(1);
            chai_1.expect(data[0].values[0].y).to.equal(2);
            chai_1.expect(data[0].values[1].y).to.equal(2);
            chai_1.expect(data[0].values[2].y).to.equal(3);
            chai_1.expect(data[0].values).to.have.lengthOf(3);
            chai_1.expect(data[1].values[0].x).to.equal(0.0);
            chai_1.expect(data[1].values[1].x).to.equal(0.5);
            chai_1.expect(data[1].values[2].x).to.equal(1);
            chai_1.expect(data[1].values[0].y).to.equal(2.0);
            chai_1.expect(data[1].values[1].y).to.equal(2.5);
            chai_1.expect(data[1].values[2].y).to.equal(3);
            chai_1.expect(data[1].values).to.have.lengthOf(3);
            lines.update_line_xy();
            d3Timer.timerFlush(); // this makes sure the animations are all executed
            const paths = lines.d3el
                .selectAll('.curve path.line')
                .nodes()
                .map((el) => el.getAttribute('d'));
            const width = objects.figure.plotarea_width;
            const height = objects.figure.plotarea_height;
            chai_1.expect(paths).to.deep.equal([
                `M0,${height}L${width / 2},${height}L${width},0`,
                `M0,${height}L${width / 2},${height / 2}L${width},0`,
            ]);
        });
    });
});
//# sourceMappingURL=lines.js.map