<commit_before>define(['Helper', 'Animator', 'TreeNode', 'SVGHelpers'], function(Helpers, Animator, TreeNode, SVG) {

    'use strict'

    var ConnectionType = {
        STRAIGHT: 0,
        BEZIER: 1,
        POLYGONAL: 2
    }

    var FaultTree = function(surface, configs) {
        this.jsonTree = {};

        this.jsonList = {};
        this.nodesCollection = [];
        this.svgSurface = new SVG(surface);

        this.config = {
             siblingSeparation : 40,
             treeTop: 80,
             treeLeft: surface.clientWidth - surface.parentNode.clientWidth / 2,
             logicInputRadius: 50,
             r: 10,
             inputHeight: 30,
             inputWidth: 50,

             currentScale: 1,
             offsetX: 0,
             offsetY: 0
        }

        this.apexNode = null;

        Helpers.extend(this.config, configs);
    };

    FaultTree.prototype = {
        /**
          * @desc applies json data, runs algorithm and initializes svg handlers
          * @param obj data - JSON data to be processed; authomatically generated if not provided
          * @return void
        */
        init: function(data) {
            if (!data) {
                data = Helpers.generateJson(5, 2);
            }
            this.jsonTree = data;
            this.jsonList = Helpers.extend({}, data);
            this.treeLayout();
            this.initHandlers();
        },

        /**
          * @desc retuns working tree in JSON to String
          * @return string
        */
        getJsonTree: function() {
            return JSON.stringify(this.jsonTree);
        },

        /**
          * @desc creates TreeNode collection based on provided JSON
          * @return void
        */
        initNodes: function() {
            var json = this.jsonTree,
                self = this,
                node = null, pnode = null;

            self.nodesCollection = [];
            self.apexNode = null;
            json.pid = 0;

            function findParentNode(node) {
                var pnode = null,
                    i, n = self.nodesCollection.length;

                if (node._pid === -1) {
                    return null;
                }
                for (i = 0; i < n; i++) {
                    if (self.nodesCollection[i]._id === node._pid) {
                        pnode = self.nodesCollection[i];
                        break;
                    }
                }
                return pnode;
            }

            function loop(root) {
                var isApex = false,
                    depth = 0;

                if (root) {
                    // Creating a tree node here
                    if (!root.pid) {
                        pnode = null;
                        root.pid = -1;
                        isApex = true;
                    }

                    node = new TreeNode({
                        _id: root.id,
                        _pid: root.pid,
                        depth: depth
                    });

                    if (isApex) {
                        self.apexNode = node;
                    }
                    pnode = findParentNode(node);
                    node.nodeParent = pnode;
                    if (pnode) {
                        pnode.nodeChildren.push(node);
                        node.number = pnode.nodeChildren.length - 1;
                        node.depth = pnode.depth + 1;
                    }
                    node.attachSurface(self.svgSurface);
                    self.nodesCollection.push(node);
                } else {
                    return;
                }
                if (!(root.children instanceof Array)) {
                    console.warn('Seems that you forgot to wrap ' + root.id + '\'s children with a []')
                    return;
                }

                Array.prototype.forEach.call(root.children, function(el) {
                    if (el) {
                        loop(el);
                    }
                });
            }
            loop(json);
        },

        /**
          * @desc initializes all major svg handlers
          * @return void
        */
        initHandlers: function() {
            var self = this,
                receiver = null,
                offsetStart = {},
                downFlag = false;

            var removeNode = function(e) {
                if (e.target.nodeName === 'rect') {
                    var id = e.target.id, el = null, pIds = [];
                    for (var i = 0; i < self.nodesCollection.length; i++) {
                        if (id === self.nodesCollection[i]._id) {
                            el = self.nodesCollection[i];
                            break;
                        }
                    }
                    pIds.push(el._id);
                    while (el = el.nodeParent) {
                        pIds.push(el._id);
                    }
                    //console.log(pIds);

                    receiver = self.jsonTree
                    for (var i = pIds.length - 2; i >= 0; i--) {
                        for (var j = 0; j < receiver.children.length; j++) {
                            if (receiver.children[j].id === pIds[i]) {
                                if (i === 0) {
                                    //console.log(receiver.children[j]);
                                    receiver.children.pop(j);
                                } else {
                                    receiver = receiver.children[j];
                                }
                                break;
                            }
                        }
                    }
                    self.treeLayout();
                }
            }

            var onWheelScroll = function(e) {
                var delta = (e.wheelDelta) < 0 ? -0.5 : 0.5;
                if (self.config.currentScale <= 1 && delta < 0) {
                    self.config.currentScale /= 2;
                } else {
                    self.config.currentScale += delta;
                }
                self.drawAllNodes();
            }

            var canvasDrag = {
                mousedown: function(e) {
                    downFlag = true;
                    offsetStart = { x: e.clientX, y: e.clientY };<commit_msg>fixed FF and IE issue with incorrect zooming<commit_after>define(['Helper', 'Animator', 'TreeNode', 'SVGHelpers'], function(Helpers, Animator, TreeNode, SVG) {

    'use strict'

    var ConnectionType = {
        STRAIGHT: 0,
        BEZIER: 1,
        POLYGONAL: 2
    }

    var FaultTree = function(surface, configs) {
        this.jsonTree = {};

        this.jsonList = {};
        this.nodesCollection = [];
        this.svgSurface = new SVG(surface);

        this.config = {
             siblingSeparation : 40,
             treeTop: 80,
             treeLeft: surface.clientWidth - surface.parentNode.clientWidth / 2,
             logicInputRadius: 50,
             r: 10,
             inputHeight: 30,
             inputWidth: 50,

             currentScale: 1,
             offsetX: 0,
             offsetY: 0
        }

        this.apexNode = null;

        Helpers.extend(this.config, configs);
    };

    FaultTree.prototype = {
        /**
          * @desc applies json data, runs algorithm and initializes svg handlers
          * @param obj data - JSON data to be processed; authomatically generated if not provided
          * @return void
        */
        init: function(data) {
            if (!data) {
                data = Helpers.generateJson(5, 2);
            }
            this.jsonTree = data;
            this.jsonList = Helpers.extend({}, data);
            this.treeLayout();
            this.initHandlers();
        },

        /**
          * @desc retuns working tree in JSON to String
          * @return string
        */
        getJsonTree: function() {
            return JSON.stringify(this.jsonTree);
        },

        /**
          * @desc creates TreeNode collection based on provided JSON
          * @return void
        */
        initNodes: function() {
            var json = this.jsonTree,
                self = this,
                node = null, pnode = null;

            self.nodesCollection = [];
            self.apexNode = null;
            json.pid = 0;

            function findParentNode(node) {
                var pnode = null,
                    i, n = self.nodesCollection.length;

                if (node._pid === -1) {
                    return null;
                }
                for (i = 0; i < n; i++) {
                    if (self.nodesCollection[i]._id === node._pid) {
                        pnode = self.nodesCollection[i];
                        break;
                    }
                }
                return pnode;
            }

            function loop(root) {
                var isApex = false,
                    depth = 0;

                if (root) {
                    // Creating a tree node here
                    if (!root.pid) {
                        pnode = null;
                        root.pid = -1;
                        isApex = true;
                    }

                    node = new TreeNode({
                        _id: root.id,
                        _pid: root.pid,
                        depth: depth
                    });

                    if (isApex) {
                        self.apexNode = node;
                    }
                    pnode = findParentNode(node);
                    node.nodeParent = pnode;
                    if (pnode) {
                        pnode.nodeChildren.push(node);
                        node.number = pnode.nodeChildren.length - 1;
                        node.depth = pnode.depth + 1;
                    }
                    node.attachSurface(self.svgSurface);
                    self.nodesCollection.push(node);
                } else {
                    return;
                }
                if (!(root.children instanceof Array)) {
                    console.warn('Seems that you forgot to wrap ' + root.id + '\'s children with a []')
                    return;
                }

                Array.prototype.forEach.call(root.children, function(el) {
                    if (el) {
                        loop(el);
                    }
                });
            }
            loop(json);
        },

        /**
          * @desc initializes all major svg handlers
          * @return void
        */
        initHandlers: function() {
            var self = this,
                receiver = null,
                offsetStart = {},
                downFlag = false;

            var removeNode = function(e) {
                if (e.target.nodeName === 'rect') {
                    var id = e.target.id, el = null, pIds = [];
                    for (var i = 0; i < self.nodesCollection.length; i++) {
                        if (id === self.nodesCollection[i]._id) {
                            el = self.nodesCollection[i];
                            break;
                        }
                    }
                    pIds.push(el._id);
                    while (el = el.nodeParent) {
                        pIds.push(el._id);
                    }
                    //console.log(pIds);

                    receiver = self.jsonTree
                    for (var i = pIds.length - 2; i >= 0; i--) {
                        for (var j = 0; j < receiver.children.length; j++) {
                            if (receiver.children[j].id === pIds[i]) {
                                if (i === 0) {
                                    //console.log(receiver.children[j]);
                                    receiver.children.pop(j);
                                } else {
                                    receiver = receiver.children[j];
                                }
                                break;
                            }
                        }
                    }
                    self.treeLayout();
                }
            }

            var onWheelScroll = function(e) {
                var delta = (e.deltaY) < 0 ? -0.5 : 0.5;
                if (self.config.currentScale <= 1 && delta < 0) {
                    self.config.currentScale /= 2;
                } else {
                    self.config.currentScale += delta;
                }
                self.drawAllNodes();
            }

            var canvasDrag = {
                mousedown: function(e) {
                    downFlag = true;
                    offsetStart = { x: e.clientX, y: e.clientY };
{'fraction_non_alphanumeric': 0.09850581073602656, 'fraction_numerical': 0.006482725907186339, 'mean_word_length': 0.8724097098875074, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1724809', 'n_tokens_mistral': 3282, 'n_tokens_neox': 2980, 'n_words': 699}