<commit_before>var createPlot          = require('gl-plot3d'),
    m4FromQuat          = require('gl-mat4/fromQuat'),
    createAxesOptions   = require('./convert/axes'),
    createSpikeOptions  = require('./convert/spikes'),
    createScatterTrace  = require('./convert/scatter'),
    createSurfaceTrace  = require('./convert/surface'),
    computeTickMarks    = require('./lib/tick-marks'),
    createCamera        = require('./lib/camera'),
    str2RGBAarray       = require('./lib/str2rgbarray');

function render(scene) {
    computeTickMarks(scene);
    scene.scene.axes.update(scene.axesOptions);

    var keys = Object.keys(scene.traces);
    for(var i=0; i<keys.length; ++i) {
        var trace = scene.traces[keys[i]];
        trace.handlePick(scene.scene.selection);
        if(trace.setContourLevels) {
            trace.setContourLevels();
        }
    }
}

function Scene(options) {
    var glOptions = options.glOptions;
    if(glOptions.preserveDrawingBuffer) {
        glOptions.premultipliedAlpha = true;
    }

    this.Plotly       = options.Plotly;
    this.sceneLayout  = options.sceneLayout;
    this.fullLayout   = options.fullLayout;

    this.axesOptions  = createAxesOptions(options.sceneLayout);
    this.spikeOptions = createSpikeOptions(options.sceneLayout);

    this.container    = options.container;

    //WARNING!!!! Only set camera position on first call to plot!!!!
    this.hasPlotBeenCalled = false;

    this.sceneKey     = options.sceneKey || 'scene';

    this.scene        = createPlot({
        container:  options.container,
        glOptions:  glOptions,
        axes:       this.axesOptions,
        spikes:     this.spikeOptions,
        pickRadius: 10,
        snapToData: true,
        autoScale:  true,
        autoBounds: false
    });

    this.camera = createCamera(this.container, {
        center: [0,0,0],
        eye:    [1.25,1.25,1.25],
        up:     [0,0,1],
        zoomMin: 0.1,
        zoomMax: 100,
        mode:   'orbit'
    });

    this.scene.camera = this.camera;

    this.scene.onrender = render.bind(null, this);

    //List of scene objects
    this.traces = {};

    this.contourLevels = [ [], [], [] ];
}

var proto = Scene.prototype;

var axisProperties = [ 'xaxis', 'yaxis', 'zaxis' ];

proto.plot = function(sceneData, sceneLayout) {

    var data, trace;

    if(sceneLayout.bgcolor) {
        this.scene.clearColor = str2RGBAarray(sceneLayout.bgcolor);
    } else {
        this.scene.clearColor = [0,0,0,0];
    }

    //Update layout
    this.sceneLayout = sceneLayout;
    this.axesOptions.merge(sceneLayout);
    this.spikeOptions.merge(sceneLayout);

    //Update camera position
    if(!this.hasPlotBeenCalled) {
      this.hasPlotBeenCalled = true;
      var camera = sceneLayout.cameraposition;
      if(camera) {
          this.setCameraPosition(camera);
      }
    }

    //Update scene
    this.scene.update({});

    //Update traces
    if(sceneData) {
        if(!Array.isArray(sceneData)) {
            sceneData = [sceneData];
        }
        for(var i=0; i<sceneData.length; ++i) {
            data = sceneData[i];
            if(!data.visible) {
                continue;
            }
            trace = this.traces[data.uid];
            if(trace) {
                trace.update(data);
            } else {
                switch(data.type) {
                    case 'scatter3d':
                        trace = createScatterTrace(this, data);
                    break;

                    case 'surface':
                        trace = createSurfaceTrace(this, data);
                    break;

                    default:
                }
                this.traces[data.uid] = trace;
            }
        }
    } else {
        sceneData = [];
    }

    var traceIds = Object.keys(this.traces);
trace_id_loop:
    for(var i=0; i<traceIds.length; ++i) {
        for(var j=0; j<sceneData.length; ++j) {
            if(sceneData[j].uid === traceIds[i] && sceneData[j].visible) {
                continue trace_id_loop;
            }
        }
        trace = this.traces[traceIds[i]];
        trace.dispose();
        delete this.traces[traceIds[i]];
    }

    //Update ranges (needs to be called *after* objects are added due to updates)
    var sceneBounds = this.scene.bounds;
    for(var i=0; i<3; ++i) {
        var axis = sceneLayout[axisProperties[i]];
        if(axis.autorange) {
            sceneBounds[0][i] = Infinity;
            sceneBounds[1][i] = -Infinity;
            for(var j=0; j<this.scene.objects.length; ++j) {
                var objBounds = this.scene.objects[j].bounds;
                sceneBounds[0][i] = Math.min(sceneBounds[0][i], objBounds[0][i]);
                sceneBounds[1][i] = Math.max(sceneBounds[1][i], objBounds[1][i]);
            }
            if('rangemode' in axis && axis.rangemode === 'tozero') {
                sceneBounds[0][i] = Math.min(sceneBounds[0][i], 0);
                sceneBounds[1][i] = Math.max(sceneBounds[1][i], 0);
            }
            if(sceneBounds[0][i] > sceneBounds[1][i]) {
                sceneBounds[0][i] = -1;
                sceneBounds[1][i] =  1;
            } else {
                var d = sceneBounds[1][i] - sceneBounds[0][i];<commit_msg>check for visible===true not for visible truthy<commit_after>var createPlot          = require('gl-plot3d'),
    m4FromQuat          = require('gl-mat4/fromQuat'),
    createAxesOptions   = require('./convert/axes'),
    createSpikeOptions  = require('./convert/spikes'),
    createScatterTrace  = require('./convert/scatter'),
    createSurfaceTrace  = require('./convert/surface'),
    computeTickMarks    = require('./lib/tick-marks'),
    createCamera        = require('./lib/camera'),
    str2RGBAarray       = require('./lib/str2rgbarray');

function render(scene) {
    computeTickMarks(scene);
    scene.scene.axes.update(scene.axesOptions);

    var keys = Object.keys(scene.traces);
    for(var i=0; i<keys.length; ++i) {
        var trace = scene.traces[keys[i]];
        trace.handlePick(scene.scene.selection);
        if(trace.setContourLevels) {
            trace.setContourLevels();
        }
    }
}

function Scene(options) {
    var glOptions = options.glOptions;
    if(glOptions.preserveDrawingBuffer) {
        glOptions.premultipliedAlpha = true;
    }

    this.Plotly       = options.Plotly;
    this.sceneLayout  = options.sceneLayout;
    this.fullLayout   = options.fullLayout;

    this.axesOptions  = createAxesOptions(options.sceneLayout);
    this.spikeOptions = createSpikeOptions(options.sceneLayout);

    this.container    = options.container;

    //WARNING!!!! Only set camera position on first call to plot!!!!
    this.hasPlotBeenCalled = false;

    this.sceneKey     = options.sceneKey || 'scene';

    this.scene        = createPlot({
        container:  options.container,
        glOptions:  glOptions,
        axes:       this.axesOptions,
        spikes:     this.spikeOptions,
        pickRadius: 10,
        snapToData: true,
        autoScale:  true,
        autoBounds: false
    });

    this.camera = createCamera(this.container, {
        center: [0,0,0],
        eye:    [1.25,1.25,1.25],
        up:     [0,0,1],
        zoomMin: 0.1,
        zoomMax: 100,
        mode:   'orbit'
    });

    this.scene.camera = this.camera;

    this.scene.onrender = render.bind(null, this);

    //List of scene objects
    this.traces = {};

    this.contourLevels = [ [], [], [] ];
}

var proto = Scene.prototype;

var axisProperties = [ 'xaxis', 'yaxis', 'zaxis' ];

proto.plot = function(sceneData, sceneLayout) {

    var data, trace;

    if(sceneLayout.bgcolor) {
        this.scene.clearColor = str2RGBAarray(sceneLayout.bgcolor);
    } else {
        this.scene.clearColor = [0,0,0,0];
    }

    //Update layout
    this.sceneLayout = sceneLayout;
    this.axesOptions.merge(sceneLayout);
    this.spikeOptions.merge(sceneLayout);

    //Update camera position
    if(!this.hasPlotBeenCalled) {
      this.hasPlotBeenCalled = true;
      var camera = sceneLayout.cameraposition;
      if(camera) {
          this.setCameraPosition(camera);
      }
    }

    //Update scene
    this.scene.update({});

    //Update traces
    if(sceneData) {
        if(!Array.isArray(sceneData)) {
            sceneData = [sceneData];
        }
        for(var i=0; i<sceneData.length; ++i) {
            data = sceneData[i];
            if(data.visible!==true) {
                continue;
            }
            trace = this.traces[data.uid];
            if(trace) {
                trace.update(data);
            } else {
                switch(data.type) {
                    case 'scatter3d':
                        trace = createScatterTrace(this, data);
                    break;

                    case 'surface':
                        trace = createSurfaceTrace(this, data);
                    break;

                    default:
                }
                this.traces[data.uid] = trace;
            }
        }
    } else {
        sceneData = [];
    }

    var traceIds = Object.keys(this.traces);
trace_id_loop:
    for(var i=0; i<traceIds.length; ++i) {
        for(var j=0; j<sceneData.length; ++j) {
            if(sceneData[j].uid === traceIds[i] && sceneData[j].visible===true) {
                continue trace_id_loop;
            }
        }
        trace = this.traces[traceIds[i]];
        trace.dispose();
        delete this.traces[traceIds[i]];
    }

    //Update ranges (needs to be called *after* objects are added due to updates)
    var sceneBounds = this.scene.bounds;
    for(var i=0; i<3; ++i) {
        var axis = sceneLayout[axisProperties[i]];
        if(axis.autorange) {
            sceneBounds[0][i] = Infinity;
            sceneBounds[1][i] = -Infinity;
            for(var j=0; j<this.scene.objects.length; ++j) {
                var objBounds = this.scene.objects[j].bounds;
                sceneBounds[0][i] = Math.min(sceneBounds[0][i], objBounds[0][i]);
                sceneBounds[1][i] = Math.max(sceneBounds[1][i], objBounds[1][i]);
            }
            if('rangemode' in axis && axis.rangemode === 'tozero') {
                sceneBounds[0][i] = Math.min(sceneBounds[0][i], 0);
                sceneBounds[1][i] = Math.max(sceneBounds[1][i], 0);
            }
            if(sceneBounds[0][i] > sceneBounds[1][i]) {
                sceneBounds[0][i] = -1;
                sceneBounds[1][i] =  1;
            } else {
                var d = sceneBounds[1][i] - sceneBounds[0][i];
{'fraction_non_alphanumeric': 0.13766258425899552, 'fraction_numerical': 0.01177252444697617, 'mean_word_length': 1.9515270383861025, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 5, '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': '7583088', 'n_tokens_mistral': 3363, 'n_tokens_neox': 3195, 'n_words': 557}