<commit_before>/**
 * Setup. Returns a "rendering context" that will need to also be
 * populated with a scene and a camera.
 */
function RenderContext(canvas) {
    this.renderer = new THREE.WebGLRenderer({
            canvas: canvas
    });
    // this.renderer.setSize(1000, 1000);
    this.canvas = canvas;
    this.materials_ = {};
    this.line_materials_ = {};
    this.spheres_ = {};
    this.pending_render = false;
}
RenderContext.MAX_SPHERES = 100;

RenderContext.prototype.render3d = function() {
    this.controls.update();
	this.renderer.render(this.scene, this.camera);
    this.pending_render = false;
};

RenderContext.prototype.render_loop = function() {
    if (!this.pending_render)
	    requestAnimationFrame(this.render3d.bind(this));
    this.pending_render = true;
};

/**
 * Update the map
 */
RenderContext.prototype.updatemap = function(streamset) {
    streamset.ready().then(function() {
        this.updatescene(streamset);
        this.render_loop();
    }.bind(this)).catch(function(ex) { console.error(ex); });
};

RenderContext.prototype.ensureCamera = function() {
    if (!this.camera) {
        // start with a perspective of 1, and then
        this.camera =
            new THREE.PerspectiveCamera( 75,
                                         1, 0.1, 3000 );
        // Create an event listener that resizes the renderer with the browser window.
        window.addEventListener('resize', this.onResize.bind(this));
        this.onResize();

        this.camera.up.set(0,0,1);
        this.controls = new THREE.OrbitControls(this.camera, this.canvas);
        this.controls.addEventListener('change', this.onControlsChange.bind(this));
    }
};

/**
 * Called when the user resizes the window
 */
RenderContext.prototype.onResize = function() {
    this.rect = { width: 1000,
                  height: 1000 };
    var windowrect = this.canvas.getBoundingClientRect();
    var perspective = windowrect.width / windowrect.height;
    this.camera.aspect = perspective;
    this.camera.updateProjectionMatrix();
    this.onControlsChange();
};

/**
 * Called when the user manipulates the controls (i.e. updates the camera)
 */
RenderContext.prototype.onControlsChange = function() {
    // just redraw, don't recreate the scene
    this.render_loop();
};

/**
 * A cache of materials by color.
 */
RenderContext.prototype.getMaterial = function(color) {
    if (!(color in this.materials_)) {
        this.materials_[color] = new THREE.MeshLambertMaterial( {
            color: color,
            shading: THREE.FlatShading
        } );
    }
    return this.materials_[color];
};

RenderContext.prototype.getLineMaterial = function(color, linewidth) {
    if (linewidth === undefined)
        linewidth = 1;
<commit_msg>make sure we have a camera before we have data<commit_after>/**
 * Setup. Returns a "rendering context" that will need to also be
 * populated with a scene and a camera.
 */
function RenderContext(canvas) {
    this.renderer = new THREE.WebGLRenderer({
            canvas: canvas
    });
    // this.renderer.setSize(1000, 1000);
    this.canvas = canvas;
    this.materials_ = {};
    this.line_materials_ = {};
    this.spheres_ = {};
    this.pending_render = false;
}
RenderContext.MAX_SPHERES = 100;

RenderContext.prototype.render3d = function() {
    this.controls.update();
	this.renderer.render(this.scene, this.camera);
    this.pending_render = false;
};

RenderContext.prototype.render_loop = function() {
    if (!this.pending_render)
	    requestAnimationFrame(this.render3d.bind(this));
    this.pending_render = true;
};

/**
 * Update the map
 */
RenderContext.prototype.updatemap = function(streamset) {
    streamset.ready().then(function() {
        this.updatescene(streamset);
        this.render_loop();
    }.bind(this)).catch(function(ex) { console.error(ex); });
};

RenderContext.prototype.ensureCamera = function() {
    if (!this.camera) {
        // start with a perspective of 1, and then
        this.camera =
            new THREE.PerspectiveCamera( 75,
                                         1, 0.1, 3000 );
        // Create an event listener that resizes the renderer with the browser window.
        window.addEventListener('resize', this.onResize.bind(this));
        this.onResize();

        this.camera.up.set(0,0,1);
        this.controls = new THREE.OrbitControls(this.camera, this.canvas);
        this.controls.addEventListener('change', this.onControlsChange.bind(this));
    }
};

/**
 * Called when the user resizes the window
 */
RenderContext.prototype.onResize = function() {
    this.rect = { width: 1000,
                  height: 1000 };
    var windowrect = this.canvas.getBoundingClientRect();
    var perspective = windowrect.width / windowrect.height;
    this.ensureCamera();
    this.camera.aspect = perspective;
    this.camera.updateProjectionMatrix();
    this.onControlsChange();
};

/**
 * Called when the user manipulates the controls (i.e. updates the camera)
 */
RenderContext.prototype.onControlsChange = function() {
    // just redraw, don't recreate the scene
    this.render_loop();
};

/**
 * A cache of materials by color.
 */
RenderContext.prototype.getMaterial = function(color) {
    if (!(color in this.materials_)) {
        this.materials_[color] = new THREE.MeshLambertMaterial( {
            color: color,
            shading: THREE.FlatShading
        } );
    }
    return this.materials_[color];
};

RenderContext.prototype.getLineMaterial = function(color, linewidth) {
    if (linewidth === undefined)
        linewidth = 1;

{'fraction_non_alphanumeric': 0.12742282842785355, 'fraction_numerical': 0.01256281407035176, 'mean_word_length': 2.886331938633194, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4701281', 'n_tokens_mistral': 1679, 'n_tokens_neox': 1590, 'n_words': 362}