<commit_before>/* global d3, event */
/* exported renderGraph */
let clickedOnce = false;  // For monitoring the click event on node
let timer;                // For click event monitoring
const noRoot = -1;

let width = 1000;         // D3 window Width
let height = 800;         // D3 window height
let reducedOpacity = 0.2; // highlight opacity to reduce to

let nodesToRender = [];   // Gets passed into the D3 force nodes function
let edgesToRender = [];   // Gets passed into the D3 force links function
let nodeToEdgeMap = {};   // Hold the mapping of node to edges

let projectNode = null;   // The project name node
let node = null;          // The collection of node html objects
let path = null;          // The collection of path html objects

let svg = null;           // The svg window
let force = null;         // The force layout for d3
let relationsChecked = false;   // Flag to see if relations check was run

let currentProjectId;
let currentRootId;

// ////// DEMO VARS//////

let curves = false;
let physics = true;
let itemNames = true;
let floatDown = true;

// /////////////////////

/**
 * Initialize by adding a project node and mapping the nodes and edges.
 * @param graphData
 * @param rootId
 */
function initializeGraphData (graphData, rootId) {
  insertProjectNode(graphData, rootId);
  mapNodesToEdges(graphData);  // Pre-process data for faster data retrieval
}

/**
 * Base function to render the graph. It is invoked by the view through an AJAX call after the data has been retrieved.
 * @param graphData
 */
// eslint-disable-next-line no-unused-vars
export default function renderGraph (graphData, selectedProjectId, rootId) {
  // console.log('Root ID: ' + rootId + '  CurrentRootId: ' + currentRootId);
  // console.log('Project ID: ' + selectedProjectId + '  CurrentProjectId: ' + currentProjectId);

  if (currentProjectId !== selectedProjectId) {
    initializeGraphData(graphData, rootId);
    currentProjectId = selectedProjectId;
  }

  // console.log(nodeToEdgeMap[rootId]);

  if (rootId !== currentRootId) {
    clearGraph(); // Clear all of the graph data
    filterJSON(graphData, rootId); // Filters the JSON for only the downStream nodes from the selected item
    resetVisitedFlag(); // Sets all of the visited flags to false

    configureD3Graph();
    updateGraph(graphData, rootId);  // Render the graph
    if (rootId) {
      collapseAll(rootId);  // Collapses all the nodes except the root node
    }
    updateOpacity();
    currentRootId = rootId;
  }
}

/**
 * Adds a project node to the graph
 * @param graphData
 */
function insertProjectNode (graphData, rootId) {
  // Create a project node and add it to the nodes list
  projectNode = {id: noRoot, name: graphData.name, image: '', type: -1};
  graphData.items.unshift(projectNode);

  // Add a relationship from project node to root id if one was passed in
  if (rootId !== noRoot && rootId !== null && rootId !== undefined) {
    graphData.relationships.push({id: -1, source: -1, target: rootId, type: -1});
  }
}

/**
 * Configures the D3 force layout graph by appending it to the body and setting its properties
 */
function configureD3Graph () {
  // Append the SVG object to the body
  // Add a group element within it to encompass all the nodes - this fixes the chrome
  svg = d3.select('body').append('svg')
    .attr('id', 'graphSVG')<commit_msg>render d3 into d3Container div<commit_after>/* global d3, event */
/* exported renderGraph */
let clickedOnce = false;  // For monitoring the click event on node
let timer;                // For click event monitoring
const noRoot = -1;

let width = 1000;         // D3 window Width
let height = 800;         // D3 window height
let reducedOpacity = 0.2; // highlight opacity to reduce to

let nodesToRender = [];   // Gets passed into the D3 force nodes function
let edgesToRender = [];   // Gets passed into the D3 force links function
let nodeToEdgeMap = {};   // Hold the mapping of node to edges

let projectNode = null;   // The project name node
let node = null;          // The collection of node html objects
let path = null;          // The collection of path html objects

let svg = null;           // The svg window
let force = null;         // The force layout for d3
let relationsChecked = false;   // Flag to see if relations check was run

let currentProjectId;
let currentRootId;

// ////// DEMO VARS//////

let curves = false;
let physics = true;
let itemNames = true;
let floatDown = true;

// /////////////////////

/**
 * Initialize by adding a project node and mapping the nodes and edges.
 * @param graphData
 * @param rootId
 */
function initializeGraphData (graphData, rootId) {
  insertProjectNode(graphData, rootId);
  mapNodesToEdges(graphData);  // Pre-process data for faster data retrieval
}

/**
 * Base function to render the graph. It is invoked by the view through an AJAX call after the data has been retrieved.
 * @param graphData
 */
// eslint-disable-next-line no-unused-vars
export default function renderGraph (graphData, selectedProjectId, rootId) {
  // console.log('Root ID: ' + rootId + '  CurrentRootId: ' + currentRootId);
  // console.log('Project ID: ' + selectedProjectId + '  CurrentProjectId: ' + currentProjectId);

  if (currentProjectId !== selectedProjectId) {
    initializeGraphData(graphData, rootId);
    currentProjectId = selectedProjectId;
  }

  // console.log(nodeToEdgeMap[rootId]);

  if (rootId !== currentRootId) {
    clearGraph(); // Clear all of the graph data
    filterJSON(graphData, rootId); // Filters the JSON for only the downStream nodes from the selected item
    resetVisitedFlag(); // Sets all of the visited flags to false

    configureD3Graph();
    updateGraph(graphData, rootId);  // Render the graph
    if (rootId) {
      collapseAll(rootId);  // Collapses all the nodes except the root node
    }
    updateOpacity();
    currentRootId = rootId;
  }
}

/**
 * Adds a project node to the graph
 * @param graphData
 */
function insertProjectNode (graphData, rootId) {
  // Create a project node and add it to the nodes list
  projectNode = {id: noRoot, name: graphData.name, image: '', type: -1};
  graphData.items.unshift(projectNode);

  // Add a relationship from project node to root id if one was passed in
  if (rootId !== noRoot && rootId !== null && rootId !== undefined) {
    graphData.relationships.push({id: -1, source: -1, target: rootId, type: -1});
  }
}

/**
 * Configures the D3 force layout graph by appending it to the body and setting its properties
 */
function configureD3Graph () {
  // Append the SVG object to the body
  // Add a group element within it to encompass all the nodes - this fixes the chrome
  svg = d3.select('#d3Container').append('svg')
    .attr('id', 'graphSVG')
{'fraction_non_alphanumeric': 0.1107169253510717, 'fraction_numerical': 0.00753880266075388, 'mean_word_length': 3.05878824235153, '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': '7566068', 'n_tokens_mistral': 1942, 'n_tokens_neox': 1897, 'n_words': 765}