<commit_before>/*=============
 * GLOBAL VARS
 * ============*/
var eventGraph;
var dataHandler;
var mispInteraction;
var nodes = new vis.DataSet();
var edges = new vis.DataSet();

var typeaheadData;
var scope_id = $('#eventgraph_network').data('event-id');
var container = document.getElementById('eventgraph_network');
var user_manipulation = $('#eventgraph_network').data('user-manipulation');
var root_id_attr = "rootNode:attribute"
var root_id_object = "rootNode:object"
var mapping_root_id_to_type = {};
mapping_root_id_to_type[root_id_attr] = 'attribute';
mapping_root_id_to_type[root_id_object] = 'object';
var root_node_x_pos = 800;
var cluster_expand_threshold = 100;

/*=========
 * CLASSES
 * ========*/
// network class (handle the event graph manipulation and events)
class EventGraph {
	constructor(network_options, nodes, edges) {
		// FIXME: Do the mapping between meta-catory and fa-icons.
		// Should be replaced later on.
		this.mapping_meta_fa = new Map();
		this.mapping_meta_fa.set('file', {"meta-category": "file","fa_text": "file","fa-hex": "f15b"});
		this.mapping_meta_fa.set('financial', {"meta-category": "financial","fa_text": "money-bil-alt","fa-hex": "f3d1"});
		this.mapping_meta_fa.set('network', {"meta-category": "network","fa_text": "server","fa-hex": "f233"});
		this.mapping_meta_fa.set('misc', {"meta-category": "misc","fa_text": "cube","fa-hex": "f1b2"});
		// FIXME
		this.network_options = network_options;
		this.first_draw = true;
		this.menu_physic = this.init_physic_menu();
		this.menu_display = this.init_display_menu();
		this.layout = 'default';
		this.solver = 'barnesHut';
		this.backup_connection_edges = {};
		this.nodes = nodes;
		this.edges = edges;
		var data = { // empty
			nodes: this.nodes,
			edges: this.edges
		};
		this.object_templates = {};

		this.cluster_index = 0; // use to get uniq cluster ID
		this.clusters = [];

		this.network = new vis.Network(container, data, this.network_options);
		this.add_unreferenced_root_node();

		var that = this;
		this.network.on("selectNode", function (params) {
			that.network.moveTo({
				position: {
					x: params.pointer.canvas.x,
					y: params.pointer.canvas.y
				},
				animation: true,
			});
		});

	}

	// Util
	get_node_color(uuid) {
		return this.nodes.get(uuid).icon.color;
	}

	init_physic_menu() {
		var menu_physic = new ContextualMenu({container: document.getElementById("network-physic-param")});
		menu_physic.add_select({
			id: "select_physic_solver",
			label: "Solver",
			tooltip: "Physics solver to use",
			event: function(value) {
				eventGraph.physics_change_solver(value);
			},
			options: ["barnesHut", "repulsion"],
			default: "barnesHut"
		});
		menu_physic.add_slider({
			id: 'slider_physic_node_repulsion',
			label: "Node repulsion",
			min: 0,
			max: 1000,
			value: this.network_options.physics.barnesHut.springLength,
			step: 10,
			event: function(value) {
				eventGraph.physics_change_repulsion(parseInt(value));
			},
			tooltip: "Correspond to spring length for barnesHut and node spacing for hierachical"
		});
		menu_physic.add_checkbox({
			label: "Enable physics",
			event: function(checked) {
				eventGraph.physics_state(checked);
			},
			checked: true
		});
		return menu_physic;
	}
	init_display_menu() {
		var menu_display = new ContextualMenu({container: document.getElementById("network-display")});
		menu_display.add_select({
			id: "select_display_object_field",
			label: "Object-relation to be displayed",
			event: function(value) {
				dataHandler.fetch_data_and_update();
			},
			options: Array.from(dataHandler.all_objects_relation),
			title: "If no item is selected, display the first requiredOneOf of the object"
		});
		menu_display.add_button({
			label: "Expand all nodes",
			type: "danger",
			event: function() {
				var objectIds = eventGraph.nodes.getIds({
					filter: function(item) { return item.group == 'object'; }
				})
				for(var nodeId of objectIds) {
					eventGraph.expand_node(nodeId);
				}
			}
		});
		menu_display.add_button({
			label: "Collapse all nodes",
			type: "danger",
			event: function() {
				var objectIds = eventGraph.nodes.getIds({<commit_msg>Usage of bootstrap popover instead of floating contextual menu<commit_after>/*=============
 * GLOBAL VARS
 * ============*/
var eventGraph;
var dataHandler;
var mispInteraction;
var nodes = new vis.DataSet();
var edges = new vis.DataSet();

var typeaheadData;
var scope_id = $('#eventgraph_network').data('event-id');
var container = document.getElementById('eventgraph_network');
var user_manipulation = $('#eventgraph_network').data('user-manipulation');
var root_id_attr = "rootNode:attribute"
var root_id_object = "rootNode:object"
var mapping_root_id_to_type = {};
mapping_root_id_to_type[root_id_attr] = 'attribute';
mapping_root_id_to_type[root_id_object] = 'object';
var root_node_x_pos = 800;
var cluster_expand_threshold = 100;

/*=========
 * CLASSES
 * ========*/
// network class (handle the event graph manipulation and events)
class EventGraph {
	constructor(network_options, nodes, edges) {
		// FIXME: Do the mapping between meta-catory and fa-icons.
		// Should be replaced later on.
		this.mapping_meta_fa = new Map();
		this.mapping_meta_fa.set('file', {"meta-category": "file","fa_text": "file","fa-hex": "f15b"});
		this.mapping_meta_fa.set('financial', {"meta-category": "financial","fa_text": "money-bil-alt","fa-hex": "f3d1"});
		this.mapping_meta_fa.set('network', {"meta-category": "network","fa_text": "server","fa-hex": "f233"});
		this.mapping_meta_fa.set('misc', {"meta-category": "misc","fa_text": "cube","fa-hex": "f1b2"});
		// FIXME
		this.network_options = network_options;
		this.first_draw = true;
		this.menu_physic = this.init_physic_menu();
		this.menu_display = this.init_display_menu();
		this.layout = 'default';
		this.solver = 'barnesHut';
		this.backup_connection_edges = {};
		this.nodes = nodes;
		this.edges = edges;
		var data = { // empty
			nodes: this.nodes,
			edges: this.edges
		};
		this.object_templates = {};

		this.cluster_index = 0; // use to get uniq cluster ID
		this.clusters = [];

		this.network = new vis.Network(container, data, this.network_options);
		this.add_unreferenced_root_node();

		var that = this;
		this.network.on("selectNode", function (params) {
			that.network.moveTo({
				position: {
					x: params.pointer.canvas.x,
					y: params.pointer.canvas.y
				},
				animation: true,
			});
		});

	}

	// Util
	get_node_color(uuid) {
		return this.nodes.get(uuid).icon.color;
	}

	init_physic_menu() {
		var menu_physic = new ContextualMenu({
			trigger_container: document.getElementById("network-physic-param"),
			bootstrap_popover: true
		});
		menu_physic.add_select({
			id: "select_physic_solver",
			label: "Solver",
			tooltip: "Physics solver to use",
			event: function(value) {
				eventGraph.physics_change_solver(value);
			},
			options: ["barnesHut", "repulsion"],
			default: "barnesHut"
		});
		menu_physic.add_slider({
			id: 'slider_physic_node_repulsion',
			label: "Node repulsion",
			min: 0,
			max: 1000,
			value: this.network_options.physics.barnesHut.springLength,
			step: 10,
			event: function(value) {
				eventGraph.physics_change_repulsion(parseInt(value));
			},
			tooltip: "Correspond to spring length for barnesHut and node spacing for hierachical"
		});
		menu_physic.add_checkbox({
			label: "Enable physics",
			event: function(checked) {
				eventGraph.physics_state(checked);
			},
			checked: true
		});
		return menu_physic;
	}
	init_display_menu() {
		var menu_display = new ContextualMenu({
			trigger_container: document.getElementById("network-display"),
			bootstrap_popover: true
		});
		menu_display.add_select({
			id: "select_display_object_field",
			label: "Object-relation to be displayed",
			event: function(value) {
				dataHandler.fetch_data_and_update();
			},
			options: Array.from(dataHandler.all_objects_relation),
			title: "If no item is selected, display the first requiredOneOf of the object"
		});
		menu_display.add_button({
			label: "Expand all nodes",
			type: "danger",
			event: function() {
				var objectIds = eventGraph.nodes.getIds({
					filter: function(item) { return item.group == 'object'; }
				})
				for(var nodeId of objectIds) {
					eventGraph.expand_node(nodeId);
				}
			}
		});
		menu_display.add_button({
			label: "Collapse all nodes",
			type: "danger",
			event: function() {
				var objectIds = eventGraph.nodes.getIds({
{'fraction_non_alphanumeric': 0.15224831818718282, 'fraction_numerical': 0.005429009795822023, 'mean_word_length': 4.421625079974408, 'pattern_counts': {'":': 24, '<': 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': '3282919', 'n_tokens_mistral': 3256, 'n_tokens_neox': 2833, 'n_words': 585}