<commit_before>/* 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.
 */

define(["widgets/js/manager", "d3", "./utils", "./Overlay"], function(WidgetManager, d3, utils, Overlay) {
    var HandDraw = Overlay.extend({

        render: function() {
            HandDraw.__super__.render.apply(this);
            var that = this;
            this.el.style({"cursor": "crosshair"});
            this.active = false;

            // Underlying line mark
            this.lines_model = this.model.get("lines");

            // Register the mouse callback when the mark view promises are
            // resolved.
            this.set_lines_view().then(function() {
                that.el
                    .on("mousedown", function() { that.mousedown(); })
                    .on("mousemove", function() { that.mousemove(); })
                    .on("mouseup", function() { that.mouseup(); });
            });

            // Update line index
            this.update_line_index();
            this.model.on("change:line_index", this.update_line_index, this);
        },
        set_lines_view: function() {
            var fig = this.parent;
            var self = this;
            return Promise.all(fig.mark_views.views).then(function(views) {
                var fig_mark_ids = fig.mark_views._models.map(function(mark_model) { return mark_model.id; });  // Model ids of the marks in the figure
                var mark_index = fig_mark_ids.indexOf(self.lines_model.id);
                self.lines_view = views[mark_index];
            });
        },
        mousedown: function () {
            this.active = true;
            this.mouse_entry(false);
            var that = this;
            this.el.on("mouseleave", function() { that.mouseup(); })
        },
        mouseup: function () {
            if (this.active) {
                this.mouse_entry(true);
                this.lines_model.set_typed_field("y", utils.deep_2d_copy(this.lines_model.y_data) );
                this.lines_view.touch();
                this.active = false;
                this.el.off("mouseleave");
            }
        },
        mousemove: function() {
            this.mouse_entry(true);
        },
        mouse_entry: function(memory) {
            // If memory is set to true, itermediate positions between the last
            // position of the mouse and the current one will be interpolated.
            if (this.active) {
                var that  = this;<commit_msg>in handdrawing widget, only bind mousemove and mouseup/mouseleave after mousedown is triggered<commit_after>/* Copyright 2015 <NAME>.
 *
 * 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.
 */

define(["widgets/js/manager", "d3", "./utils", "./Overlay"], function(WidgetManager, d3, utils, Overlay) {
    var HandDraw = Overlay.extend({

        render: function() {
            HandDraw.__super__.render.apply(this);
            var that = this;
            this.el.style({"cursor": "crosshair"});
            this.active = false;

            // Underlying line mark
            this.lines_model = this.model.get("lines");

            // Register the mouse callback when the mark view promises are
            // resolved.
            this.set_lines_view().then(function() {
                that.el.on("mousedown", function() { return that.mousedown(); })
            });

            // Update line index
            this.update_line_index();
            this.model.on("change:line_index", this.update_line_index, this);
        },
        set_lines_view: function() {
            var fig = this.parent;
            var self = this;
            return Promise.all(fig.mark_views.views).then(function(views) {
                var fig_mark_ids = fig.mark_views._models.map(function(mark_model) { return mark_model.id; });  // Model ids of the marks in the figure
                var mark_index = fig_mark_ids.indexOf(self.lines_model.id);
                self.lines_view = views[mark_index];
            });
        },
        mousedown: function () {
            this.active = true;
            this.mouse_entry(false);
            var that = this;
            this.el.on("mousemove", function() { that.mousemove(); })
            this.el.on("mouseleave", function() { that.mouseup(); });
            this.el.on("mouseup", function() { that.mouseup(); });
        },
        mouseup: function () {
            if (this.active) {
                this.mouse_entry(true);
                this.lines_model.set_typed_field("y", utils.deep_2d_copy(this.lines_model.y_data) );
                this.lines_view.touch();
                this.active = false;
                this.el.off("mousemove");
                this.el.off("mouseleave");
                this.el.off("mouseup");
            }
        },
        mousemove: function() {
            this.mouse_entry(true);
        },
        mouse_entry: function(memory) {
            // If memory is set to true, itermediate positions between the last
            // position of the mouse and the current one will be interpolated.
            if (this.active) {
                var that  = this;
{'fraction_non_alphanumeric': 0.11462899821399578, 'fraction_numerical': 0.003572008442929047, 'mean_word_length': 1.9473684210526316, 'pattern_counts': {'":': 2, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5308695', 'n_tokens_mistral': 1669, 'n_tokens_neox': 1612, 'n_words': 452}