<commit_before>'use strict';

const Parser = require('./lib/parser');
const Interaction = require('./lib/interaction');

exports.init = function (args, ready) {

    if (!args.parse) {
        return ready(new Error('Flow-visualizer.init: No parse config found.'));
    }

    args.vis = Object.assign({
        nodes: {
            shape: 'dot',
            scaling: { min: 20,max: 30,
                label: { min: 14, max: 30, drawThreshold: 9, maxVisible: 20 }
            },
            font: {size: 14, face: 'Helvetica Neue, Helvetica, Arial'}
        },
        interaction: {
            hover: true,
            hoverConnectedEdges: false,
            selectConnectedEdges: true
        }
    }, args.vis || {});

    this.index = {};
    this.types = args.types || {};
    this.predicates = args.parse;
    this.nodes = new vis.DataSet(args.nodes || []);
    this.edges = new vis.DataSet(args.edges || []);

    if (!(this.view = document.querySelector(args.view))) {
        return ready(new Error('Flow-visualizer: DOM target not found.'));
    }

    this.network = new vis.Network(this.view, {
        nodes: this.nodes,
        edges: this.edges
    }, args.vis);

    Interaction(this, args.interaction);

    ready();
};

exports.parse = function (args, data, next) {

    let triples;
    if (!(data instanceof Array) && args.key && data[args.key]) {
        triples = data[args.key];
        data.nodes = [];
        data.edges = [];
    } else {
        triples = data;
        data = {
            nodes: [],
            edges: []
        };
    }

    const pos = data.id ? this.network.getPositions(data.id)[data.id] : {x: 0, y: 0};

    Parser(this.predicates, triples, this.types, data, pos, this.index);

    next(null, data);
};

exports.add = function (args, data, next) {

    if (!data.nodes && !data.edges) {
        return next(new Error('Flow-visualizer.add: No nodes or edges found.'));
    }

    data.nodes && this.nodes.add(data.nodes);
    data.edges && this.edges.add(data.edges);

    next(null, data);
};


exports.remove = function (args, data, next) {
    console.log('Flow-visualizer.remove:', args, data);
    next(null, data);
};

exports.reset = function (args, data, next) {

    this.network.setData({
        nodes: data.nodes || [],
        edges: data.edges || []
    });

    next(null, data);
};
<commit_msg>get position from node in data<commit_after>'use strict';

const Parser = require('./lib/parser');
const Interaction = require('./lib/interaction');

exports.init = function (args, ready) {

    if (!args.parse) {
        return ready(new Error('Flow-visualizer.init: No parse config found.'));
    }

    args.vis = Object.assign({
        nodes: {
            shape: 'dot',
            scaling: { min: 20,max: 30,
                label: { min: 14, max: 30, drawThreshold: 9, maxVisible: 20 }
            },
            font: {size: 14, face: 'Helvetica Neue, Helvetica, Arial'}
        },
        interaction: {
            hover: true,
            hoverConnectedEdges: false,
            selectConnectedEdges: true
        }
    }, args.vis || {});

    this.index = {};
    this.types = args.types || {};
    this.predicates = args.parse;
    this.nodes = new vis.DataSet(args.nodes || []);
    this.edges = new vis.DataSet(args.edges || []);

    if (!(this.view = document.querySelector(args.view))) {
        return ready(new Error('Flow-visualizer: DOM target not found.'));
    }

    this.network = new vis.Network(this.view, {
        nodes: this.nodes,
        edges: this.edges
    }, args.vis);

    Interaction(this, args.interaction);

    ready();
};

exports.parse = function (args, data, next) {

    let triples;
    if (!(data instanceof Array) && args.key && data[args.key]) {
        triples = data[args.key];
        data.nodes = [];
        data.edges = [];
    } else {
        triples = data;
        data = {
            nodes: [],
            edges: []
        };
    }

    const pos = {x: 0, y: 0};
    if (data.node) {
        pos.x = data.node.x || 0;
        pos.y = data.node.y || 0;
    }

    Parser(this.predicates, triples, this.types, data, pos, this.index);

    next(null, data);
};

exports.add = function (args, data, next) {

    if (!data.nodes && !data.edges) {
        return next(new Error('Flow-visualizer.add: No nodes or edges found.'));
    }

    data.nodes && this.nodes.add(data.nodes);
    data.edges && this.edges.add(data.edges);

    next(null, data);
};


exports.remove = function (args, data, next) {
    console.log('Flow-visualizer.remove:', args, data);
    next(null, data);
};

exports.reset = function (args, data, next) {

    this.network.setData({
        nodes: data.nodes || [],
        edges: data.edges || []
    });

    next(null, data);
};

{'fraction_non_alphanumeric': 0.16520284399832705, 'fraction_numerical': 0.006691760769552488, 'mean_word_length': 2.167549668874172, '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': '1228767', 'n_tokens_mistral': 1569, 'n_tokens_neox': 1496, 'n_words': 351}