"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 ScatterBaseModel_1 = require("./ScatterBaseModel");
const serialize = __importStar(require("./serialize"));
const _ = __importStar(require("underscore"));
class ScatterModel extends ScatterBaseModel_1.ScatterBaseModel {
    defaults() {
        return Object.assign({}, ScatterBaseModel_1.ScatterBaseModel.prototype.defaults(), { _model_name: "ScatterModel", _view_name: "Scatter", skew: null, marker: "circle", stroke: null, stroke_width: 1.5, default_skew: 0.5, default_size: 64, names: [], display_names: true, fill: true, drag_color: null, drag_size: 5.0, names_unique: true });
    }
    initialize(attributes, options) {
        // TODO: Normally, color, opacity and size should not require a redraw
        super.initialize(attributes, options);
        this.on("change:skew", this.update_data, this);
        this.on_some_change(["names", "names_unique"], function () {
            this.update_unique_ids();
            this.trigger("data_updated");
        }, this);
    }
    update_mark_data() {
        super.update_mark_data();
        const skew = this.get("skew") || [];
        this.mark_data.forEach(function (d, i) { d.skew = skew[i]; });
    }
    update_unique_ids() {
        let names = this.get("names");
        const show_labels = (names != null && names.length !== 0);
        names = (show_labels) ? names : this.mark_data.map(function (data, index) {
            return "Dot" + index;
        });
        let unique_ids = [];
        if (this.get("names_unique")) {
            unique_ids = names.slice(0);
        }
        else {
            unique_ids = _.range(this.mark_data.length);
        }
        this.mark_data.forEach(function (data, index) {
            data.name = names[index];
            data.unique_id = unique_ids[index];
        });
    }
}
ScatterModel.serializers = Object.assign({}, ScatterBaseModel_1.ScatterBaseModel.serializers, { skew: serialize.array_or_json, names: serialize.array_or_json });
exports.ScatterModel = ScatterModel;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiU2NhdHRlck1vZGVsLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL1NjYXR0ZXJNb2RlbC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7Ozs7Ozs7Ozs7Ozs7R0FhRzs7Ozs7Ozs7O0FBRUgseURBQXFEO0FBQ3JELHVEQUF5QztBQUN6Qyw4Q0FBZ0M7QUFFaEMsTUFBYSxZQUFhLFNBQVEsbUNBQWdCO0lBRTlDLFFBQVE7UUFDSix5QkFBVyxtQ0FBZ0IsQ0FBQyxTQUFTLENBQUMsUUFBUSxFQUFFLElBQzVDLFdBQVcsRUFBRSxjQUFjLEVBQzNCLFVBQVUsRUFBRSxTQUFTLEVBQ3JCLElBQUksRUFBRSxJQUFJLEVBQ1YsTUFBTSxFQUFFLFFBQVEsRUFDaEIsTUFBTSxFQUFFLElBQUksRUFDWixZQUFZLEVBQUUsR0FBRyxFQUNqQixZQUFZLEVBQUUsR0FBRyxFQUNqQixZQUFZLEVBQUUsRUFBRSxFQUNoQixLQUFLLEVBQUUsRUFBRSxFQUNULGFBQWEsRUFBRSxJQUFJLEVBQ25CLElBQUksRUFBRSxJQUFJLEVBQ1YsVUFBVSxFQUFFLElBQUksRUFDaEIsU0FBUyxFQUFFLEdBQUcsRUFDZCxZQUFZLEVBQUUsSUFBSSxJQUNwQjtJQUNOLENBQUM7SUFFRCxVQUFVLENBQUMsVUFBVSxFQUFFLE9BQU87UUFDMUIsc0VBQXNFO1FBQ3RFLEtBQUssQ0FBQyxVQUFVLENBQUMsVUFBVSxFQUFFLE9BQU8sQ0FBQyxDQUFDO1FBQ3RDL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