<commit_before>"use strict";

/*global d3, ProcessModel*/

if (!ProcessModel) {
    var ProcessModel = {};
}

ProcessModel.DrawNodeTypes = function(drawNodes, trackAllowedTypes, nodes, update) {
    var junctionRadius = 5;

    var findDragTarget = function() {
	var target = document.elementFromPoint(
	    d3.event.sourceEvent.clientX, 
	    d3.event.sourceEvent.clientY);
	while (target.parentNode) {
	    var targetSelection = d3.select(target);
	    if (targetSelection.classed("process-node")) {
		return targetSelection;
	    } else {
		target = target.parentNode;
	    }
	}
	return null;
    };

    var dragNode = d3.behavior.drag()
	    .on("dragstart", function(d){
		/* Nothing else should get this click now. */
		d3.event.sourceEvent.stopPropagation();
	    })
	    .on("drag", function(d){
		/* Highlight things we're dragging over to aid the user. */
		var target = findDragTarget();
		if (target === d.previousDragTarget) {
		    return;
		} else {
		    if (d.previousDragTarget) {
			d.previousDragTarget.classed("drag-target", false);
		    }
		    if (target) {
			target.classed("drag-target", true);
		    }
		    d.previousDragTarget = target;
		}
	    })
	    .on("dragend", function(d, i){
		/* See if we're over an existing different node. 
		 If so, make an edge to it.
		 Otherwise, we'll make an edge to a new node. */
		var oldNode = d,
		    target = findDragTarget(),
		    newNode;

		if (target && target.datum().name() !== oldNode.name()) {
		    newNode = target.datum();
		} else {
		    if (oldNode.allowedChildren.empty()) {
			throw new Error("Nodes of type " + oldNode.type + " cannot have children.");
		    }
		    if (oldNode.allowedChildren.values().length === 1) {
			newNode = nodes.create(oldNode.allowedChildren.values()[0]);
		    } else {
			newNode = nodes.create('undecided');
		    };
		}

		try {
		    if (oldNode.collapsed()) {
			return;
		    }
		    oldNode.edgeTo(newNode); 
		    update();
		} finally {
		    if (d.previousDragTarget) {
			d.previousDragTarget.classed("drag-target", false);
		    }
		}
	    });

    var drawEdgeJunctionGroup = function(nodes) {
	var junctions = nodes
		.selectAll("g.handle")
		.data(function(d, i){
		    return [d];
		});

	junctions.exit().remove();

	junctions.enter()
	    .append("g")
	    .classed("handle", true)
	    .attr("transform", "translate(" + drawNodes.nodeWidth + "," + drawNodes.nodeCenter[1] + ")")
	    .attr("draggable", true)
	    .call(dragNode);

	junctions.style("visibility", function(d, i){
	    return d.collapsed() ? "hidden" : "visible";
	});

	return junctions;
    };

    var drawSimpleJunction = function(junctions) {
	junctions.append("circle")
	    .attr("r", junctionRadius);
    };

    var drawDependencyArc = function(junctions) {
	var arc = d3.svg.arc()
		.outerRadius(junctionRadius),
	    pie = d3.layout.pie()
		.sort(null)<commit_msg>Stopped making multiple circles elements for junctions.<commit_after>"use strict";

/*global d3, ProcessModel*/

if (!ProcessModel) {
    var ProcessModel = {};
}

ProcessModel.DrawNodeTypes = function(drawNodes, trackAllowedTypes, nodes, update) {
    var junctionRadius = 5;

    var findDragTarget = function() {
	var target = document.elementFromPoint(
	    d3.event.sourceEvent.clientX, 
	    d3.event.sourceEvent.clientY);
	while (target.parentNode) {
	    var targetSelection = d3.select(target);
	    if (targetSelection.classed("process-node")) {
		return targetSelection;
	    } else {
		target = target.parentNode;
	    }
	}
	return null;
    };

    var dragNode = d3.behavior.drag()
	    .on("dragstart", function(d){
		/* Nothing else should get this click now. */
		d3.event.sourceEvent.stopPropagation();
	    })
	    .on("drag", function(d){
		/* Highlight things we're dragging over to aid the user. */
		var target = findDragTarget();
		if (target === d.previousDragTarget) {
		    return;
		} else {
		    if (d.previousDragTarget) {
			d.previousDragTarget.classed("drag-target", false);
		    }
		    if (target) {
			target.classed("drag-target", true);
		    }
		    d.previousDragTarget = target;
		}
	    })
	    .on("dragend", function(d, i){
		/* See if we're over an existing different node. 
		 If so, make an edge to it.
		 Otherwise, we'll make an edge to a new node. */
		var oldNode = d,
		    target = findDragTarget(),
		    newNode;

		if (target && target.datum().name() !== oldNode.name()) {
		    newNode = target.datum();
		} else {
		    if (oldNode.allowedChildren.empty()) {
			throw new Error("Nodes of type " + oldNode.type + " cannot have children.");
		    }
		    if (oldNode.allowedChildren.values().length === 1) {
			newNode = nodes.create(oldNode.allowedChildren.values()[0]);
		    } else {
			newNode = nodes.create('undecided');
		    };
		}

		try {
		    if (oldNode.collapsed()) {
			return;
		    }
		    oldNode.edgeTo(newNode); 
		    update();
		} finally {
		    if (d.previousDragTarget) {
			d.previousDragTarget.classed("drag-target", false);
		    }
		}
	    });

    var drawEdgeJunctionGroup = function(nodes) {
	var junctions = nodes
		.selectAll("g.handle")
		.data(function(d, i){
		    return [d];
		});

	junctions.exit().remove();

	junctions.enter()
	    .append("g")
	    .classed("handle", true)
	    .attr("transform", "translate(" + drawNodes.nodeWidth + "," + drawNodes.nodeCenter[1] + ")")
	    .attr("draggable", true)
	    .call(dragNode);

	junctions.style("visibility", function(d, i){
	    return d.collapsed() ? "hidden" : "visible";
	});

	return junctions;
    };

    var drawSimpleJunction = function(junctions) {
	var circles = junctions.selectAll("circle")
	    .data(function(d, i) {
		return [d];
	    });

	circles.exit().remove();

	circles
	    .enter()
	    .append("circle")
	    .attr("r", junctionRadius);
    };

    var drawDependencyArc = function(junctions) {
	var arc = d3.svg.arc()
		.outerRadius(junctionRadius),
	    pie = d3.layout.pie()
		.sort(null)
{'fraction_non_alphanumeric': 0.15360026917900405, 'fraction_numerical': 0.004037685060565276, 'mean_word_length': 2.8754889178617993, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2070332', 'n_tokens_mistral': 2161, 'n_tokens_neox': 1891, 'n_words': 415}