<commit_before>(function () {

    angular.module('weblearner.directives')
        .directive('hypothesis', hypothesis);

    hypothesis.$inject = ['$window', 'paths', 'CounterExampleService', '_', 'dagreD3', 'd3', 'graphlib'];

    function intersectNode(node, point) {
        return node.intersect(point);
    }

    function calcPoints(g, e) {
        var edge = g.edge(e), tail = g.node(e.v), head = g.node(e.w), points = edge.points
            .slice(1, edge.points.length - 1);

        points.unshift(intersectNode(tail, points[0]));
        points.push(intersectNode(head, points[points.length - 1]));

        return createLine(edge, points);
    }

    function createLine(edge, points) {
        var line = d3.svg.line().x(function (d) {
            return d.x;
        }).y(function (d) {
            return d.y;
        });

        if (_.has(edge, "lineInterpolate")) {
            line.interpolate(edge.lineInterpolate);
        }

        if (_.has(edge, "lineTension")) {
            line.tension(Number(edge.lineTension));
        }

        return line(points);
    }

    function hypothesis($window, paths, CounterExampleService, _, dagreD3, d3, graphlib) {

        return {
            scope: {
                test: '=',
                layoutSettings: '=',
                isSelectable: '@'
            },
            templateUrl: paths.views.DIRECTIVES + '/hypothesis.html',
            link: link
        };

        function link(scope, el, attrs) {

            var _svg;
            var _svgGroup;
            var _svgContainer;
            var _graph;
            var _renderer;

            var labelStyle = 'display: inline; font-weight: bold; line-height: 1; text-align: center; white-space: nowrap; vertical-align: baseline;';
            var labelStyleEdge = labelStyle + 'font-size: 10px';
            var labelStyleNode = labelStyle + 'font-size: 12px';

            scope.$watch('test', function (test) {
                if (angular.isDefined(test) && test != null) {
                    createHypothesis();
                }
            });

            scope.$watch('layoutSettings', function (ls) {
                if (angular.isDefined(ls)) {
                    createHypothesis();
                }
            });

            function createHypothesis() {
                clearSvg();
                initGraph();
                layout();
                renderGraph();
                handleEvents();
            }

            function clearSvg() {
                el.find('svg')[0].innerHTML = '';
            }

            function initGraph() {

                _svg = d3.select(el.find('svg')[0]);
                _svgGroup = _svg.append("g");
                _svgContainer = _svg.node().parentNode;

                _svg.style('font-family', '"Helvetica Neue",Helvetica,Arial,sans-serif');
                _svg.style('font-size', '12px');
                _svg.style('line-height', '1.42857');
                _svg.style('color', '#333');

                _graph = new graphlib.Graph({
                    directed: true,
                    multigraph: true
                });

                if (angular.isDefined(scope.layoutSettings)) {
                    _graph.setGraph({
                        edgesep: scope.layoutSettings.edgesep,
                        nodesep: scope.layoutSettings.nodesep,
                        ranksep: scope.layoutSettings.ranksep
                    });
                } else {
                    _graph.setGraph({
                        edgesep: 25
                    });
                }
            }

            function layout() {
                if (angular.isDefined(scope.layoutSettings)) {
                    if (scope.layoutSettings.multigraph) {
                        layoutAsMultiGraph();
                    } else {
                        layoutAsGraph();
                    }
                } else {
                    layoutAsGraph();
                }
            }

            function layoutAsMultiGraph() {

                // add nodes to the graph
                _.forEach(scope.test.hypothesis.nodes, function (node, i) {
                    var n = {
                        shape: 'circle',
                        label: node.toString(),
                        width: 25,
                        labelStyle: labelStyleNode
                    };

                    if (node === scope.test.hypothesis.initNode) {
                        n.style = 'fill: #B3E6B3; stroke: #5cb85c; stroke-width: 3';
                    } else {
                        n.style = 'fill: #fff; stroke: #000; stroke-width: 1';
                    }

                    _graph.setNode("" + i, n);
                });

                // add edges to the graph
                _.forEach(scope.test.hypothesis.edges, function (edge, i) {
                    var edgeName = edge.from + "-" + edge.to + "|" + i;
                    _graph.setEdge(edge.from, edge.to, {
                        label: edge.input + "/" + edge.output,
                        labeloffset: 5,
                        lineInterpolate: 'basis',
                        style: "stroke: rgba(0, 0, 0, 0.3); stroke-width: 3; fill:none",
                        labelStyle: labelStyleEdge
                    }, edgeName);
                });

                // layout it
                dagreD3.dagre.layout(_graph, {});
            }

            function layoutAsGraph() {

                // another format of a graph for merged multi edges
                // graph = {<from>: {<to>: <label[]>, ...}, ...}
                var graph = {};

                // add nodes to the rendered graph
                _.forEach(scope.test.hypothesis.nodes, function (node, i) {
                    var n = {
                        shape: 'circle',
                        label: node.toString(),
                        width: 25,
                        labelStyle: labelStyleNode
                    };

                    if (node === scope.test.hypothesis.initNode) {
                        n.style = 'fill: #B3E6B3; stroke: #5cb85c; stroke-width: 3';
                    } else {
                        n.style = 'fill: #fff; stroke: #000; stroke-width: 1';
                    }

                    _graph.setNode("" + i, n);
                });

                // build data structure for the alternative representation by
                // pushing some data
                _.forEach(scope.test.hypothesis.edges, function (edge) {
                    if (!graph[edge.from]) {
                        graph[edge.from] = {};
                        graph[edge.from][edge.to] = [edge.input + "/"
                        + edge.output];
                    } else {
                        if (!graph[edge.from][edge.to]) {
                            graph[edge.from][edge.to] = [edge.input + "/"
                            + edge.output];
                        } else {
                            graph[edge.from][edge.to].push(edge.input + "/"
                            + edge.output);
                        }
                    }
                });

                // add edges to the rendered graph and combine <label[]><commit_msg>important fix: hypothesis displays initNode and node order correctly... nexttime i should use the node name as label and not the index of it in the array ............... sry<commit_after>(function () {

    angular.module('weblearner.directives')
        .directive('hypothesis', hypothesis);

    hypothesis.$inject = ['$window', 'paths', 'CounterExampleService', '_', 'dagreD3', 'd3', 'graphlib'];

    function intersectNode(node, point) {
        return node.intersect(point);
    }

    function calcPoints(g, e) {
        var edge = g.edge(e), tail = g.node(e.v), head = g.node(e.w), points = edge.points
            .slice(1, edge.points.length - 1);

        points.unshift(intersectNode(tail, points[0]));
        points.push(intersectNode(head, points[points.length - 1]));

        return createLine(edge, points);
    }

    function createLine(edge, points) {
        var line = d3.svg.line().x(function (d) {
            return d.x;
        }).y(function (d) {
            return d.y;
        });

        if (_.has(edge, "lineInterpolate")) {
            line.interpolate(edge.lineInterpolate);
        }

        if (_.has(edge, "lineTension")) {
            line.tension(Number(edge.lineTension));
        }

        return line(points);
    }

    function hypothesis($window, paths, CounterExampleService, _, dagreD3, d3, graphlib) {

        return {
            scope: {
                test: '=',
                layoutSettings: '=',
                isSelectable: '@'
            },
            templateUrl: paths.views.DIRECTIVES + '/hypothesis.html',
            link: link
        };

        function link(scope, el, attrs) {

            var _svg;
            var _svgGroup;
            var _svgContainer;
            var _graph;
            var _renderer;

            var labelStyle = 'display: inline; font-weight: bold; line-height: 1; text-align: center; white-space: nowrap; vertical-align: baseline;';
            var labelStyleEdge = labelStyle + 'font-size: 10px';
            var labelStyleNode = labelStyle + 'font-size: 12px';

            scope.$watch('test', function (test) {
                if (angular.isDefined(test) && test != null) {
                    createHypothesis();
                }
            });

            scope.$watch('layoutSettings', function (ls) {
                if (angular.isDefined(ls)) {
                    createHypothesis();
                }
            });

            function createHypothesis() {
                clearSvg();
                initGraph();
                layout();
                renderGraph();
                handleEvents();
            }

            function clearSvg() {
                el.find('svg')[0].innerHTML = '';
            }

            function initGraph() {

                _svg = d3.select(el.find('svg')[0]);
                _svgGroup = _svg.append("g");
                _svgContainer = _svg.node().parentNode;

                _svg.style('font-family', '"Helvetica Neue",Helvetica,Arial,sans-serif');
                _svg.style('font-size', '12px');
                _svg.style('line-height', '1.42857');
                _svg.style('color', '#333');

                _graph = new graphlib.Graph({
                    directed: true,
                    multigraph: true
                });

                if (angular.isDefined(scope.layoutSettings)) {
                    _graph.setGraph({
                        edgesep: scope.layoutSettings.edgesep,
                        nodesep: scope.layoutSettings.nodesep,
                        ranksep: scope.layoutSettings.ranksep
                    });
                } else {
                    _graph.setGraph({
                        edgesep: 25
                    });
                }
            }

            function layout() {
                if (angular.isDefined(scope.layoutSettings)) {
                    if (scope.layoutSettings.multigraph) {
                        layoutAsMultiGraph();
                    } else {
                        layoutAsGraph();
                    }
                } else {
                    layoutAsGraph();
                }
            }

            function layoutAsMultiGraph() {

                // add nodes to the graph
                _.forEach(scope.test.hypothesis.nodes, function (node, i) {
                    var n = {
                        shape: 'circle',
                        label: node.toString(),
                        width: 25,
                        labelStyle: labelStyleNode
                    };

                    if (node === scope.test.hypothesis.initNode) {
                        n.style = 'fill: #B3E6B3; stroke: #5cb85c; stroke-width: 3';
                    } else {
                        n.style = 'fill: #fff; stroke: #000; stroke-width: 1';
                    }

                    _graph.setNode(node.toString(), n);
                });

                // add edges to the graph
                _.forEach(scope.test.hypothesis.edges, function (edge, i) {
                    var edgeName = edge.from + "-" + edge.to + "|" + i;
                    _graph.setEdge(edge.from, edge.to, {
                        label: edge.input + "/" + edge.output,
                        labeloffset: 5,
                        lineInterpolate: 'basis',
                        style: "stroke: rgba(0, 0, 0, 0.3); stroke-width: 3; fill:none",
                        labelStyle: labelStyleEdge
                    }, edgeName);
                });

                // layout it
                dagreD3.dagre.layout(_graph, {});
            }

            function layoutAsGraph() {

                // another format of a graph for merged multi edges
                // graph = {<from>: {<to>: <label[]>, ...}, ...}
                var graph = {};

                // add nodes to the rendered graph
                _.forEach(scope.test.hypothesis.nodes, function (node, i) {
                    var n = {
                        shape: 'circle',
                        label: node.toString(),
                        width: 25,
                        labelStyle: labelStyleNode
                    };

                    if (node === scope.test.hypothesis.initNode) {
                        n.style = 'fill: #B3E6B3; stroke: #5cb85c; stroke-width: 3';
                    } else {
                        n.style = 'fill: #fff; stroke: #000; stroke-width: 1';
                    }

                    _graph.setNode(node.toString(), n);
                });

                // build data structure for the alternative representation by
                // pushing some data
                _.forEach(scope.test.hypothesis.edges, function (edge) {
                    if (!graph[edge.from]) {
                        graph[edge.from] = {};
                        graph[edge.from][edge.to] = [edge.input + "/"
                        + edge.output];
                    } else {
                        if (!graph[edge.from][edge.to]) {
                            graph[edge.from][edge.to] = [edge.input + "/"
                            + edge.output];
                        } else {
                            graph[edge.from][edge.to].push(edge.input + "/"
                            + edge.output);
                        }
                    }
                });

                // add edges to the rendered graph and combine <label[]>
{'fraction_non_alphanumeric': 0.12044492971202402, 'fraction_numerical': 0.008734816432373414, 'mean_word_length': 1.1125846907885253, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6099182', 'n_tokens_mistral': 3963, 'n_tokens_neox': 3576, 'n_words': 754}