<commit_before>var d3 = require('d3');

exports.Shape = function(name, canvas, canvasScale) {
	// public member variables
    this.id = name;
    this.position = {
        minX: 30,
        maxX: 50,
        minY: 30,
        maxY: 50
    };
    this.type = "square";
    this.color = "blue";
    this.rotation = 0;
    this.minWidth = 15;
    this.maxWidth = 30;
    this.minHeight = 10;
    this.maxHeight = 50;
    
    // Private variables
    //Declaring a shape as this so our private functions can access our public variables
    var shape = this;
    var x = 20;
    var y = 20;
    var height = 10;
    var width = 15;
    //Our d3 object
    var d3Obj = canvas.append('ellipse')
                    .attr('rx', this.minWidth)
                    .attr('ry', this.minHeight)
                    .attr('cx', this.position.x)
                    .attr('cy', this.position.y);
    //This helps us scale our shapes to our canvas size                
    var scale = canvasScale;

    //Public functions
    //This function is used to clear our d3object when the editor is exited, just in case
    this.cleard3 = function() {
        d3Obj = null;
    }

    //This function is used to reappend our svgs, just in case they were deleted
    this.reappend = function(canvas) {
        if(!d3Obj) {
            console.log('append');
            d3Obj = canvas.append('ellipse')
                        .attr('rx', this.minWidth)
                        .attr('ry', this.minHeight)
                        .attr('cx', this.position.x)
                        .attr('cy', this.position.y);
        }
    }

    //Our update function for our shapes
    this.update = function(data) {
        //assume data passed in is an integer from 0-100
        var freq = data.frequency;

        //simple toy algorithm, sets size to percentage of max size
        // this.height = freq*this.max_height
        // this.width = freq*this.max_width

        updateSize(freq);
        updatePos(freq);

        //Update our d3Obj if it is available
        if(d3Obj) {
            d3Obj.attr('rx', width)
                .attr('ry', height)
                .attr('cx', x)
                .attr('cy', y);
        };

    }

    //Function to update the size, right now I'm defaulting to frequency which is being passed directly
    var updateSize = function(data) {
        height = shape.minHeight + ((shape.maxHeight-shape.minHeight) * data);
        width = shape.minWidth + ((shape.maxWidth-shape.minWidth) * data);
    }

    //Function to update the position, default to frequency
    var updatePos = function(data) {
        x = scale.x * (shape.position.minX + ((shape.position.maxX-shape.position.minX) * data));
        y = scale.y * (shape.position.minY + ((shape.position.maxY-shape.position.minY) * data));
    }

}<commit_msg>added simple color link to music  frequency<commit_after>var d3 = require('d3');

exports.Shape = function(name, canvas, canvasScale) {
	// public member variables
    this.id = name;
    this.position = {
     /* minX: 30,
        maxX: 50,
        minY: 30,
        maxY: 50 */
        minX: 1000, //These initial values were better for testing on my machine with 
        maxX: 1000, //the app at half size. Original values commented out above
        minY: 500,
        maxY: 500 
    };
    this.type = "square";
    this.color = "blue";
    this.rotation = 0;
    this.minWidth = 15;
    this.maxWidth = 30;
    this.minHeight = 10;
    this.maxHeight = 50;
    
    // Private variables
    //Declaring a shape as this so our private functions can access our public variables
    var shape = this;
    var x = 20;
    var y = 20;
    var height = 10;
    var width = 15;
    var colorHex = "#0000ff";
    //Our d3 object
    var d3Obj = canvas.append('ellipse')
                    .attr('rx', this.minWidth)
                    .attr('ry', this.minHeight)
                    .attr('cx', this.position.x)
                    .attr('cy', this.position.y);
    //This helps us scale our shapes to our canvas size                
    var scale = canvasScale;

    //Public functionsheight
    //This function is used to clear our d3object when the editor is exited, just in case
    this.cleard3 = function() {
        d3Obj = null;
    }

    //This function is used to reappend our svgs, just in case they were deleted
    this.reappend = function(canvas) {
        if(!d3Obj) {
            console.log('append');
            d3Obj = canvas.append('ellipse')
                        .attr('rx', this.minWidth)
                        .attr('ry', this.minHeight)
                        .attr('cx', this.position.x)
                        .attr('cy', this.position.y);
        }
    }

    //Our update function for our shapes
    this.update = function(data) {
        //assume data passed in is an integer from 0-100
        var freq = data.frequency;

        //simple toy algorithm, sets size to percentage of max size
        // this.height = freq*this.max_height
        // this.width = freq*this.max_width

        updateSize(freq);
        updatePos(freq);
        updateCol(freq);

        //Update our d3Obj if it is available
        if(d3Obj) {
            d3Obj.attr('rx', width)
                .attr('ry', height)
                .attr('cx', x)
                .attr('cy', y)
                .style('fill',colorHex);
        };

    }

    //Function to update the size, right now I'm defaulting to frequency which is being passed directly
    var updateSize = function(data) {
        height = shape.minHeight + ((shape.maxHeight-shape.minHeight) * data);
        width = shape.minWidth + ((shape.maxWidth-shape.minWidth) * data);
    }

    //Function to update the position, default to frequency
    var updatePos = function(data) {
        x = scale.x * (shape.position.minX + ((shape.position.maxX-shape.position.minX) * data));
        y = scale.y * (shape.position.minY + ((shape.position.maxY-shape.position.minY) * data));
    }

    //helper function for updateCol
    function decimalToHexString(number){
        if (number < 0){
            number = 0xFFFFFFFF + number + 1;
        }

    return number.toString(16).toUpperCase();
    }

    //Function to update the color, default to frequency
    var updateCol = function(data) {
        bigData = data * 100000000;
        littleData = bigData % 16777215;
        
        // can do something like this \/ to have more control over the colors
       /* littleData = bigData % 225;

        if(bigData > 50000000){
             r = (littleData + 75) % 255;
             g = (littleData*.3);
             b = (littleData*.5);
             rHex = decimalToHexString(r);
             gHex = decimalToHexString(g);
             bHex = decimalToHexString(b);
        }
        else if(bigData > 35000000){
             b = (littleData + 75) % 255;
             g = (littleData*.5);
             r = (littleData*.3) ;
             rHex = decimalToHexString(r);
             gHex = decimalToHexString(g);
             bHex = decimalToHexString(b);

        }
        else{
             g = (littleData +75) % 255;
             b = (littleData*.5);
             r = (littleData*.3);
             rHex = decimalToHexString(r);
             gHex = decimalToHexString(g);
             bHex = decimalToHexString(b);
        }
        colorHex = rHex + bHex + gHex;*/

        colorHex = decimalToHexString(littleData);     
    }

}
{'fraction_non_alphanumeric': 0.11453566621803499, 'fraction_numerical': 0.02180349932705249, 'mean_word_length': 1.730981256890849, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 3, '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': '2724243', 'n_tokens_mistral': 2313, 'n_tokens_neox': 2126, 'n_words': 627}