<commit_before>var JJSdiagram = {

	paper: null,

	makeDiagram: function(container, model) {
		container.html('<div id="jjsPaper"></div>');

		var graph = new joint.dia.Graph;

		// start by making the paper the same size as container and then scaling the model to fit
		this.paper = new joint.dia.Paper({
			el: jQuery("#jjsPaper"),
			width: container.width(),
			height: container.height(),
			model: graph,
			gridSize: 1
		});

		graph.addCells(this.JJsParse.makeClasses(model));
		graph.addCells(this.JJsParse.makeAssociations(model));
		graph.addCells(this.JJsParse.makeGeneralizationLinks(model));
		graph.addCells(this.JJsParse.makeInterfaceLinks(model));

		// call this after having added all diagram elements to scale them to fit the available space
		this.paper.scaleContentToFit({padding: 15});

		return this.paper;
	},

	JJsUtils: {

		// from JointJS tutorial: http://resources.jointjs.com/tutorial/multiple-links-between-elements
		adjustVertices: function (graph, cell) {

			// If the cell is a view, find its model.
			cell = cell.model || cell;

			if (cell instanceof joint.dia.Element) {

				_.chain(graph.getConnectedLinks(cell)).groupBy(function(link) {
					// the key of the group is the model id of the link's source or target, but not our cell id.
					return _.omit([link.get('source').id, link.get('target').id], cell.id)[0];
				}).each(function(group, key) {
					// If the member of the group has both source and target model adjust vertices.
					if (key !== 'undefined') adjustVertices(graph, _.first(group));
				});

				return;
			}

			// The cell is a link. Let's find its source and target models.
			var srcId = cell.get('source').id || cell.previous('source').id;
			var trgId = cell.get('target').id || cell.previous('target').id;

			// If one of the ends is not a model, the link has no siblings.
			if (!srcId || !trgId) return;

			var siblings = _.filter(graph.getLinks(), function(sibling) {

				var _srcId = sibling.get('source').id;
				var _trgId = sibling.get('target').id;

				return (_srcId === srcId && _trgId === trgId) || (_srcId === trgId && _trgId === srcId);
			});

			switch (siblings.length) {

			case 0:
				// The link was removed and had no siblings.
				break;

			case 1:
				// There is only one link between the source and target. No vertices needed.
				cell.unset('vertices');
				break;

			default:

				// There is more than one siblings. We need to create vertices.<commit_msg>Fixing a bug hiding overlapping associations<commit_after>var JJSdiagram = {

	paper: null,

	makeDiagram: function(container, model) {
		container.html('<div id="jjsPaper"></div>');

		var graph = new joint.dia.Graph;

		// start by making the paper the same size as container and then scaling the model to fit
		this.paper = new joint.dia.Paper({
			el: jQuery("#jjsPaper"),
			width: container.width(),
			height: container.height(),
			model: graph,
			gridSize: 1
		});

		graph.addCells(this.JJsParse.makeClasses(model));
		graph.addCells(this.JJsParse.makeAssociations(model));
		graph.addCells(this.JJsParse.makeGeneralizationLinks(model));
		graph.addCells(this.JJsParse.makeInterfaceLinks(model));

		JJSdiagram.paper.model.getCells().forEach(function(cell) {
			JJSdiagram.JJsUtils.adjustVertices(JJSdiagram.paper.model,cell);
		});

		// call this after having added all diagram elements to scale them to fit the available space
		this.paper.scaleContentToFit({padding: 15});

		return this.paper;
	},

	JJsUtils: {

		// from JointJS tutorial: http://resources.jointjs.com/tutorial/multiple-links-between-elements
		adjustVertices: function (graph, cell) {

			// If the cell is a view, find its model.
			cell = cell.model || cell;

			if (cell instanceof joint.dia.Element) {

				_.chain(graph.getConnectedLinks(cell)).groupBy(function(link) {
					// the key of the group is the model id of the link's source or target, but not our cell id.
					return _.omit([link.get('source').id, link.get('target').id], cell.id)[0];
				}).each(function(group, key) {
					// If the member of the group has both source and target model adjust vertices.
					if (key !== 'undefined') adjustVertices(graph, _.first(group));
				});

				return;
			}

			// The cell is a link. Let's find its source and target models.
			var srcId = cell.get('source').id || cell.previous('source').id;
			var trgId = cell.get('target').id || cell.previous('target').id;

			// If one of the ends is not a model, the link has no siblings.
			if (!srcId || !trgId) return;

			var siblings = _.filter(graph.getLinks(), function(sibling) {

				var _srcId = sibling.get('source').id;
				var _trgId = sibling.get('target').id;

				return (_srcId === srcId && _trgId === trgId) || (_srcId === trgId && _trgId === srcId);
			});

			switch (siblings.length) {

			case 0:
				// The link was removed and had no siblings.
				break;

			case 1:
				// There is only one link between the source and target. No vertices needed.

				// Have commented this out, as the positive benefits are unknown,
				//   but it certainly breaks the work established to make generalization links and self-referential associations
				// cell.unset('vertices');
				break;

			default:

				// There is more than one siblings. We need to create vertices.
{'fraction_non_alphanumeric': 0.13295454545454546, 'fraction_numerical': 0.0022727272727272726, 'mean_word_length': 3.3898586866167912, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3088428', 'n_tokens_mistral': 1918, 'n_tokens_neox': 1594, 'n_words': 506}