<commit_before>'use strict';

var Plotly = require('./plotly'),
    objectAssign = require('object-assign');

var graphReference = {},
    Methods = {};

var NESTEDMODULEID = '_nestedModules',
    COMPOSEDMODULEID = '_composedModules';

function getGraphReference() {
    var Plots = Plotly.Plots;

    Plots.allTypes.forEach(function(type) {

        graphReference[type] = {};
        Methods.getAttributes(type);
        Methods.getLayoutAttributes(type);

    });

    return graphReference;
}

module.exports = getGraphReference;

Methods.getAttributes = function(type) {
    var globalAttributes = Plotly.Plots.attributes,
        attributes = {};

    var module;

    // global attributes
    attributes = objectAssign(attributes, globalAttributes);

    // module attributes (+ nested + composed)
    module = Methods.getModule({type: type});
    attributes = Methods.coupleAttrs(
        module.attributes, attributes,
        'attributes', type
    );
    attributes.type = type;
    attributes = Methods.removeUnderscoreAttrs(attributes);

    graphReference[type].attributes = attributes;
};

Methods.getLayoutAttributes = function(type) {
    var Plots = Plotly.Plots,
        globalLayoutAttributes = Plots.layoutAttributes,
        layoutAttributes = {};

    var sceneAttrs;

    // global layout attributes
    layoutAttributes = objectAssign(layoutAttributes, globalLayoutAttributes);

    // more global (maybe list these in graph_obj ??)
    layoutAttributes = objectAssign(layoutAttributes, Plotly.Fx.layoutAttributes);
    layoutAttributes.legend = Plotly.Legend.layoutAttributes;

    if (Plots.traceIs(type, 'gl3d')) {
        sceneAttrs = Plotly.Gl3dLayout.layoutAttributes;
        sceneAttrs = Methods.coupleAttrs(
            sceneAttrs, {},
            'layoutAttributes', '-'
        );
        layoutAttributes.scene = sceneAttrs;
    }
    else {
        layoutAttributes.xaxis = Plotly.Axes.layoutAttributes;
        layoutAttributes.yaxis = Plotly.Axes.layoutAttributes;
        layoutAttributes.annotations = Plotly.Annotations.layoutAttributes;
    }

    // TODO how to present keys '{x,y}axis[1-9]' or 'scene[1-9]'?
    // TODO how to present 'annotations' Array ?

    layoutAttributes = Methods.removeUnderscoreAttrs(layoutAttributes);

    graphReference[type].layoutAttributes = layoutAttributes;
};

Methods.coupleAttrs = function(attrsIn, attrsOut, whichAttrs, type) {
    var nestedModule, nestedAttrs, nestedReference,
        composedModule, composedAttrs;

    Object.keys(attrsIn).forEach(function(k) {

        if(k === NESTEDMODULEID) {
            Object.keys(attrsIn[k]).forEach(function(kk) {
                nestedModule = Methods.getModule({module: attrsIn[k][kk]});
                nestedAttrs = nestedModule[whichAttrs];
                nestedReference = Methods.coupleAttrs(
                    nestedAttrs, {},
                    whichAttrs, type
                );
                Plotly.Lib.nestedProperty(attrsOut, kk)
                    .set(nestedReference);
            });
            return;
        }

        if(k === COMPOSEDMODULEID) {
            Object.keys(attrsIn[k]).forEach(function(kk) {
                if (kk !== type) return;
                composedModule = Methods.getModule({module: attrsIn[k][kk]});
                composedAttrs = composedModule[whichAttrs];
                composedAttrs = Methods.coupleAttrs(
                    composedAttrs, {},
                    whichAttrs, type
                );
                attrsOut = objectAssign(attrsOut, composedAttrs);
            });
            return;
        }

        attrsOut[k] = attrsIn[k];
    });

    return attrsOut;
};<commit_msg>don't nest nor compose module if DNE in graph_reference<commit_after>'use strict';

var Plotly = require('./plotly'),
    objectAssign = require('object-assign');

var graphReference = {},
    Methods = {};

var NESTEDMODULEID = '_nestedModules',
    COMPOSEDMODULEID = '_composedModules';


function getGraphReference() {
    var Plots = Plotly.Plots;

    Plots.allTypes.forEach(function(type) {

        graphReference[type] = {};
        Methods.getAttributes(type);
        Methods.getLayoutAttributes(type);

    });

    return graphReference;
}

module.exports = getGraphReference;

Methods.getAttributes = function(type) {
    var globalAttributes = Plotly.Plots.attributes,
        attributes = {};

    var module;

    // global attributes
    attributes = objectAssign(attributes, globalAttributes);

    // module attributes (+ nested + composed)
    module = Methods.getModule({type: type});
    attributes = Methods.coupleAttrs(
        module.attributes, attributes,
        'attributes', type
    );
    attributes.type = type;
    attributes = Methods.removeUnderscoreAttrs(attributes);

    graphReference[type].attributes = attributes;
};

Methods.getLayoutAttributes = function(type) {
    var Plots = Plotly.Plots,
        globalLayoutAttributes = Plots.layoutAttributes,
        layoutAttributes = {};

    var sceneAttrs;

    // global layout attributes
    layoutAttributes = objectAssign(layoutAttributes, globalLayoutAttributes);

    // more global (maybe list these in graph_obj ??)
    layoutAttributes = objectAssign(layoutAttributes, Plotly.Fx.layoutAttributes);
    layoutAttributes.legend = Plotly.Legend.layoutAttributes;

    if (Plots.traceIs(type, 'gl3d')) {
        sceneAttrs = Plotly.Gl3dLayout.layoutAttributes;
        sceneAttrs = Methods.coupleAttrs(
            sceneAttrs, {},
            'layoutAttributes', '-'
        );
        layoutAttributes.scene = sceneAttrs;
    }
    else {
        layoutAttributes.xaxis = Plotly.Axes.layoutAttributes;
        layoutAttributes.yaxis = Plotly.Axes.layoutAttributes;
        layoutAttributes.annotations = Plotly.Annotations.layoutAttributes;
    }

    // TODO how to present keys '{x,y}axis[1-9]' or 'scene[1-9]'?
    // TODO how to present 'annotations' Array ?

    layoutAttributes = Methods.removeUnderscoreAttrs(layoutAttributes);

    graphReference[type].layoutAttributes = layoutAttributes;
};

Methods.coupleAttrs = function(attrsIn, attrsOut, whichAttrs, type) {
    var nestedModule, nestedAttrs, nestedReference,
        composedModule, composedAttrs;

    Object.keys(attrsIn).forEach(function(k) {

        if(k === NESTEDMODULEID) {
            Object.keys(attrsIn[k]).forEach(function(kk) {
                nestedModule = Methods.getModule({module: attrsIn[k][kk]});
                if(nestedModule === undefined) return;
                nestedAttrs = nestedModule[whichAttrs];
                nestedReference = Methods.coupleAttrs(
                    nestedAttrs, {},
                    whichAttrs, type
                );
                Plotly.Lib.nestedProperty(attrsOut, kk)
                    .set(nestedReference);
            });
            return;
        }

        if(k === COMPOSEDMODULEID) {
            Object.keys(attrsIn[k]).forEach(function(kk) {
                if (kk !== type) return;
                composedModule = Methods.getModule({module: attrsIn[k][kk]});
                if(composedModule === undefined) return;
                composedAttrs = composedModule[whichAttrs];
                composedAttrs = Methods.coupleAttrs(
                    composedAttrs, {},
                    whichAttrs, type
                );
                attrsOut = objectAssign(attrsOut, composedAttrs);
            });
            return;
        }

        attrsOut[k] = attrsIn[k];
    });

    return attrsOut;
};
{'fraction_non_alphanumeric': 0.10848492896029743, 'fraction_numerical': 0.0015934138892577346, 'mean_word_length': 2.4838112858464383, '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': '3628330', 'n_tokens_mistral': 2083, 'n_tokens_neox': 1995, 'n_words': 370}