"use strict";
/* Copyright 2015 Bloomberg Finance L.P.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const widgets = __importStar(require("@jupyter-widgets/base"));
const MarkModel_1 = require("./MarkModel");
const serialize = __importStar(require("./serialize"));
class ImageModel extends MarkModel_1.MarkModel {
    defaults() {
        return Object.assign({}, MarkModel_1.MarkModel.prototype.defaults(), { _model_name: "ImageModel", _view_name: "Image", x: [0.0, 1.0], y: [0.0, 1.0], scales_metadata: {
                'x': { 'orientation': 'horizontal', 'dimension': 'x' },
                'y': { 'orientation': 'vertical', 'dimension': 'y' },
            } });
    }
    initialize(attributes, options) {
        super.initialize(attributes, options);
        this.on_some_change(['x', 'y'], this.update_data, this);
        this.on_some_change(["preserve_domain"], this.update_domains, this);
        this.update_data();
    }
    update_data() {
        this.mark_data = {
            x: this.get("x"), y: this.get("y")
        };
        this.update_domains();
        this.trigger("data_updated");
    }
    update_domains() {
        if (!this.mark_data) {
            return;
        }
        const scales = this.get("scales");
        const x_scale = scales.x;
        const y_scale = scales.y;
        if (x_scale) {
            if (!this.get("preserve_domain").x) {
                x_scale.compute_and_set_domain(this.mark_data['x'], this.model_id + "_x");
            }
            else {
                x_scale.del_domain([], this.model_id + "_x");
            }
        }
        if (y_scale) {
            if (!this.get("preserve_domain").y) {
                y_scale.compute_and_set_domain(this.mark_data['y'], this.model_id + "_y");
            }
            else {
                y_scale.del_domain([], this.model_id + "_y");
            }
        }
    }
}
ImageModel.serializers = Object.assign({}, MarkModel_1.MarkModel.serializers, { image: { deserialize: widgets.unpack_models }, x: serialize.array_or_json, y: serialize.array_or_json });
exports.ImageModel = ImageModel;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSW1hZ2VNb2RlbC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9JbWFnZU1vZGVsLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQTs7Ozs7Ozs7Ozs7OztHQWFHOzs7Ozs7Ozs7QUFFSCwrREFBaUQ7QUFDakQsMkNBQXdDO0FBQ3hDLHVEQUF5QztBQUV6QyxNQUFhLFVBQVcsU0FBUSxxQkFBUztJQUVyQyxRQUFRO1FBQ0oseUJBQVcscUJBQVMsQ0FBQyxTQUFTLENBQUMsUUFBUSxFQUFFLElBQ3JDLFdBQVcsRUFBRSxZQUFZLEVBQ3pCLFVBQVUsRUFBRSxPQUFPLEVBQ25CLENBQUMsRUFBRSxDQUFDLEdBQUcsRUFBRSxHQUFHLENBQUMsRUFDYixDQUFDLEVBQUUsQ0FBQyxHQUFHLEVBQUUsR0FBRyxDQUFDLEVBQ2IsZUFBZSxFQUFFO2dCQUNiLEdBQUcsRUFBRSxFQUFDLGFBQWEsRUFBRSxZQUFZLEVBQUUsV0FBVyxFQUFFLEdBQUcsRUFBQztnQkFDcEQsR0FBRyxFQUFFLEVBQUMsYUFBYSxFQUFFLFVBQVUsRUFBRSxXQUFXLEVBQUUsR0FBRyxFQUFDO2FBQ3JELElBQ0g7SUFDTixDQUFDO0lBRUQsVUFBVSxDQUFDLFVBQVUsRUFBRSxPQUFPO1FBQzFCLEtBQUssQ0FBQyxVQUFVLENBQUMsVUFBVSxFQUFFLE9BQU8sQ0FBQyxDQUFDO1FBQ3RDLElBQUksQ0FBQyxjQUFjLENBQUMsQ0FB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