"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 version_1 = require("./version");
const serialize = __importStar(require("./serialize"));
class MarkModel extends widgets.WidgetModel {
    defaults() {
        return Object.assign({}, widgets.WidgetModel.prototype.defaults(), { _model_name: "MarkModel", _model_module: "bqplot", _view_module: "bqplot", _model_module_version: version_1.semver_range, _view_module_version: version_1.semver_range, scales: {}, scales_metadata: {}, preserve_domain: {}, display_legend: false, labels: [], apply_clip: true, visible: true, selected_style: {}, unselected_style: {}, selected: null, enable_hover: true, tooltip: null, tooltip_style: { opacity: 0.9 }, interactions: { hover: "tooltip" }, tooltip_location: "mouse" });
    }
    // These two attributes are the pixel values which should be appended
    // to the area of the plot to make sure that the entire mark is visible
    initialize(attributes, options) {
        super.initialize(attributes, options);
        this.on("change:scales", this.update_scales, this);
        this.once("destroy", this.handle_destroy, this);
        // `this.dirty` is set to `true` before starting computations that
        // might lead the state of the model to be temporarily inconsistent.
        // certain functions of views on that model might check the value
        // of `this.dirty` before rendering
        this.dirty = false;
        this.update_scales();
    }
    update_data() {
        // Update_data is typically overloaded in each mark
        // it triggers the "data_updated" event
        this.update_domains();
        this.trigger("data_updated");
    }
    update_domains() {
        // update_domains is typically overloaded in each mark to update
        // the domains related to its scales
    }
    update_scales() {
        this.unregister_all_scales(this.previous("scales"));
        this.trigger("scales_updated");
        this.update_domains();
    }
    unregister_all_scales(scales) {
        // disassociates the mark with the scale
        this.dirty = true;
        for (let key in scales) {
            scales[key].del_domain([], this.model_id + "_" + key);
        }
        this.dirty = false;
        //TODO: Check if the views are being removed
    }
    handle_destroy() {
        this.unregister_all_scales(this.get("scales"));
    }
    get_key_for_dimension(dimension) {
        const scales_metadata = this.get("scales_metadata");
        for (let scale in scales_metadata) {
            if (scales_metadata[scale].dimension === dimension) {
                return scale;
            }
        }
        return null;
    }
    get_key_for_orientation(orientation) {
        const scales_metadata = this.get("scales_metadata");
        for (let scale in scales_metadata) {
            if (scales_metadata[scale].orientation === orientation) {
                return scale;
            }
        }
        return null;
    }
    // TODO make this abstract
    get_data_dict(data, index) {
        return data;
    }
}
MarkModel.serializers = Object.assign({}, widgets.WidgetModel.serializers, { scales: { deserialize: widgets.unpack_models }, tooltip: { deserialize: widgets.unpack_models }, selected: serialize.array_or_json });
exports.MarkModel = MarkModel;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTWFya01vZGVsLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL01hcmtNb2RlbC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7Ozs7Ozs7Ozs7Ozs7R0FhRzs7Ozs7Ozs7O0FBRUgsK0RBQWlEO0FBQ2pELHVDQUF5QztBQUN6Qyx1REFBeUM7QUFFekMsTUFBYSxTQUFVLFNBQVEsT0FBTyxDQUFDLFdBQVc7SUFFOUMsUUFBUTtRQUNKLHlCQUFXLE9BQU8sQ0FBQyxXQUFXLENBQUMsU0FBUyxDQUFDLFFBQVEsRUFBRSxJQUMvQyxXQUFXLEVBQUUsV0FBVyxFQUN4QixhQUFhLEVBQUUsUUFBUSxFQUN2QixZQUFZLEVBQUUsUUFBUSxFQUN0QixxQkFBcUIsRUFBRSxzQkFBWSxF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