<commit_before>'use strict';

// ---external global dependencies
/* global d3:false */

var heatmap = module.exports = {},
    Plotly = require('./plotly'),
    tinycolor = require('tinycolor2'),
    scatterAttrs = Plotly.Scatter.attributes;

heatmap.attributes = {
    z: {type: 'data_array'},
    x: scatterAttrs.x,
    x0: scatterAttrs.x0,
    dx: scatterAttrs.dx,
    y: scatterAttrs.y,
    y0: scatterAttrs.y0,
    dy: scatterAttrs.dy,
    text: {type: 'data_array'},
    transpose: {
        type: 'boolean',
        dflt: false
    },
    xtype: {
        type: 'enumerated',
        values: ['array', 'scaled']
    },
    ytype: {
        type: 'enumerated',
        values: ['array', 'scaled']
    },
    zauto: {
        type: 'boolean',
        dflt: true
    },
    zmin: {
        type: 'number',
        dflt: null
    },
    zmax: {
        type: 'number',
        dflt: null
    },
    colorscale: {
        type: 'colorscale'
    },
    autocolorscale: {
        type: 'boolean',
        dflt: false
    },
    reversescale: {
        type: 'boolean',
        dflt: false
    },
    showscale: {
        type: 'boolean',
        dflt: true
    },
    zsmooth: {
        type: 'enumerated',
        values: ['fast', 'best', false],
        dflt: false
    },
    connectgaps: {
        type: 'boolean',
        dflt: false
    },
    _nestedModules: {  // nested module coupling
        'colorbar': 'Colorbar'
    },
    _composedModules: {  // composed module coupling
        'histogram2d': 'Histogram',
        'histogram2dcontour': 'Histogram'
    }
};

heatmap.supplyDefaults = function(traceIn, traceOut, defaultColor, layout) {
    function coerce(attr, dflt) {
        return Plotly.Lib.coerce(traceIn, traceOut, heatmap.attributes, attr, dflt);
    }

    function isValidZ(z) {
        var allRowsAreArrays = true,
            oneRowIsFilled = false,
            zi;

        if (!(Array.isArray(z) && z.length)) return false;

        for (var i = 0; i < z.length; i++) {
            zi = z[i];
            if (!Array.isArray(zi)) allRowsAreArrays = false;
            if (!oneRowIsFilled && zi.length) oneRowIsFilled = true;
            for(var j = 0; j < zi.length; j++) {
                if(!$.isNumeric(zi[j])) return false;
            }
        }
        return (allRowsAreArrays && oneRowIsFilled);
    }

    if(Plotly.Plots.isHist2D(traceOut.type)) {
        // x, y, z, marker.color, and x0, dx, y0, dy are coerced
        // in Histogram.supplyDefaults
        // (along with histogram-specific attributes)
        Plotly.Histogram.supplyDefaults(traceIn, traceOut);
        if(traceOut.visible === false) return;
    }
    else {
        var z = coerce('z');
        if(!isValidZ(z)) {
            traceOut.visible = false;
            return;
        }

        coerce('transpose');

        var x = coerce('x'),
            xtype = x ? coerce('xtype', 'array') : 'scaled';<commit_msg>Fix logic to make heatmap trace invisible<commit_after>'use strict';

// ---external global dependencies
/* global d3:false */

var heatmap = module.exports = {},
    Plotly = require('./plotly'),
    tinycolor = require('tinycolor2'),
    scatterAttrs = Plotly.Scatter.attributes;

heatmap.attributes = {
    z: {type: 'data_array'},
    x: scatterAttrs.x,
    x0: scatterAttrs.x0,
    dx: scatterAttrs.dx,
    y: scatterAttrs.y,
    y0: scatterAttrs.y0,
    dy: scatterAttrs.dy,
    text: {type: 'data_array'},
    transpose: {
        type: 'boolean',
        dflt: false
    },
    xtype: {
        type: 'enumerated',
        values: ['array', 'scaled']
    },
    ytype: {
        type: 'enumerated',
        values: ['array', 'scaled']
    },
    zauto: {
        type: 'boolean',
        dflt: true
    },
    zmin: {
        type: 'number',
        dflt: null
    },
    zmax: {
        type: 'number',
        dflt: null
    },
    colorscale: {
        type: 'colorscale'
    },
    autocolorscale: {
        type: 'boolean',
        dflt: false
    },
    reversescale: {
        type: 'boolean',
        dflt: false
    },
    showscale: {
        type: 'boolean',
        dflt: true
    },
    zsmooth: {
        type: 'enumerated',
        values: ['fast', 'best', false],
        dflt: false
    },
    connectgaps: {
        type: 'boolean',
        dflt: false
    },
    _nestedModules: {  // nested module coupling
        'colorbar': 'Colorbar'
    },
    _composedModules: {  // composed module coupling
        'histogram2d': 'Histogram',
        'histogram2dcontour': 'Histogram'
    }
};

heatmap.supplyDefaults = function(traceIn, traceOut, defaultColor, layout) {
    function coerce(attr, dflt) {
        return Plotly.Lib.coerce(traceIn, traceOut, heatmap.attributes, attr, dflt);
    }

    function isValidZ(z) {
        var allRowsAreArrays = true,
            oneRowIsFilled = false,
            zi,
            noNumbers = true;

        if (!(Array.isArray(z) && z.length)) return false;

        for (var i = 0; i < z.length; i++) {
            zi = z[i];
            if (!Array.isArray(zi)) allRowsAreArrays = false;
            if (!oneRowIsFilled && zi.length) oneRowIsFilled = true;
            for(var j = 0; j < zi.length; j++) {
            // Check that there is at least one numeric element...
                if($.isNumeric(zi[j])) {
                    noNumbers = false;
                    break;
                }
            }
        }
        // ... otherwise set array as invalid:
        if(noNumbers) return false;

        return (allRowsAreArrays && oneRowIsFilled);
    }

    if(Plotly.Plots.isHist2D(traceOut.type)) {
        // x, y, z, marker.color, and x0, dx, y0, dy are coerced
        // in Histogram.supplyDefaults
        // (along with histogram-specific attributes)
        Plotly.Histogram.supplyDefaults(traceIn, traceOut);
        if(traceOut.visible === false) return;
    }
    else {
        var z = coerce('z');
        if(!isValidZ(z)) {
            traceOut.visible = false;
            return;
        }

        coerce('transpose');

        var x = coerce('x'),
            xtype = x ? coerce('xtype', 'array') : 'scaled';
{'fraction_non_alphanumeric': 0.13915171288743883, 'fraction_numerical': 0.004241435562805873, 'mean_word_length': 1.826648224988474, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3098769', 'n_tokens_mistral': 2052, 'n_tokens_neox': 2005, 'n_words': 445}