<commit_before>const dagreD3 = require('dagre-d3');
const d3 = require('d3');
const graphCreator = require('./src/graphCreator.js');

let graph_dot ; 


function drawGraph() {

    graphCreator.createGraph(graph_dot);

    let graph = graphCreator.getGraph();

    let g = new dagreD3.graphlib.Graph().setGraph({});

    // Automatically label each of the nodes
    for (let i = 0; i < graph.nodes.length; i++)
        g.setNode(graph.nodes[i].id, { label: graph.nodes[i].label, style : "fill: #00ffd0" });

    // Set up the edges
    for (let i = 0; i < graph.edges.length; i++)
        g.setEdge(graph.edges[i].source, graph.edges[i].target, { label: graph.edges[i].label, lineInterpolate: 'basis' });


    // Set some general styles
    g.nodes().forEach(function (v) {
        let node = g.node(v);
        node.rx = node.ry = 5;
    });

    let svg = d3.select("svg"),
        inner = svg.select("g");

    // Set up zoom support
    let zoom = d3.behavior.zoom().on("zoom", function () {
        inner.attr("transform", "translate(" + d3.event.translate + ")" +
            "scale(" + d3.event.scale + ")");
    });
    svg.call(zoom);


    

    // Create the renderer
    let render = new dagreD3.render();

    // Run the renderer. This is what draws the final graph.
    render(inner, g);

    // Center the graph
    let initialScale = 0.75;
    zoom
        .translate([(svg.attr("width") - g.graph().width * initialScale) / 2, 20])
        .scale(initialScale)
        .event(svg);
    svg.attr('height', g.graph().height * initialScale + 40);
}


const { ipcRenderer } = require('electron')

ipcRenderer.send('openFile', () => {
    console.log("Event sent.");
})
ipcRenderer.on('fileData', (event, data) => {
   graph_dot = data; 
   drawGraph();  
})




<commit_msg>refactor the code and now graph can be updated and redrawn<commit_after>const dagreD3 = require('dagre-d3');
const d3 = require('d3');
const graphCreator = require('./src/graphCreator.js');
const graphStyleUpdater = require('./src/graphStyleUpdater.js');

let svg; 

function init() {
     svg = d3.select("svg")
}

function drawGraph(g) {

    /*********** updating examples **************/
    // g = graphStyleUpdater.change_node(g,"n30", "red");
    // g = graphStyleUpdater.change_neighbours(g, "n32", "red");
    // g = graphStyleUpdater.change_edge(g,"n32","n33", "blue");
    // g = graphStyleUpdater.change_two_nodes_of_edge(g,"n32","n33", "red");

    //svg.selectAll("*").remove();
    let inner = svg.select("g");

    // Set up zoom support
    let zoom = d3.behavior.zoom().on("zoom", function () {
        inner.attr("transform", "translate(" + d3.event.translate + ")" +
            "scale(" + d3.event.scale + ")");
    });
    svg.call(zoom);

    // Create the renderer
    let render = new dagreD3.render();

    // Run the renderer. This is what draws the final graph.
    render(inner, g);


    let w = 800, h = 500;
    let colors = d3.scale.category20();

    let vis = d3.select("#chart").append("svg:svg")
        .attr("width", w)
        .attr("height", h);

    var data = d3.range(20).map(function (i) {
        return { i: i, x: Math.random() * w, y: Math.random() * h, r: Math.random() * 30 }
    });

    vis.selectAll("g.node")
        .data(data)
        .enter().append("svg:g.node")
        .attr("stroke", "black")
        .attr("fill", function (d, i) { return colors(i); })
        .attr("cx", function (d, i) { return d.x; })
        .attr("cy", function (d, i) { return d.y; })
        .attr("r", function (d, i) { return d.r; });

    $('svg g.node').tipsy({
        gravity: 'w',
        html: true,
        title: function () {
            var d = this.__data__, c = colors(d.i);
            return d;
        }
    });

    // Center the graph
    let initialScale = 0.75;
    zoom
        .translate([(svg.attr("width") - g.graph().width * initialScale) / 2, 20])
        .scale(initialScale)
        .event(svg);
    svg.attr(window.width, window.height);

}


const { ipcRenderer } = require('electron')

ipcRenderer.send('openFile', () => {
    console.log("Event sent.");
})
ipcRenderer.on('fileData', (event, data) => {
    graph_dot = data;
    init();
    let g = graphCreator.getGraph(graph_dot, "TB", "ellipse");
    drawGraph(g);
})









{'fraction_non_alphanumeric': 0.1894540363975735, 'fraction_numerical': 0.015398973401773215, 'mean_word_length': 2.581453634085213, 'pattern_counts': {'":': 0, '<': 5, '<?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': '764052', 'n_tokens_mistral': 1521, 'n_tokens_neox': 1442, 'n_words': 328}