view war/scripts/sti/DataObject.js @ 68:8b58d9bc0bb6 trimmed_data

add functionality for additional tabular data from the description field (work in progress)
author Sebastian Kruse <skruse@mpiwg-berlin.mpg.de>
date Thu, 03 Jan 2013 18:43:28 +0100
parents 775477d89709
children
line wrap: on
line source

/**
 * class that contains all needed information about an element of the resulting data set including time and place values
 * @param {String} name the name of the data object
 * @param {String} description description of the data object
 * @param {String} place the place, the data object corresponds to
 * @param {Date} time the time stamp, the data object corresponds to
 * @param {int} granularity the granularity of the given time
 * @param {float} lon the longitude value corresponding to the given place 
 * @param {float} lat the latitude value corresponding to the given place
 * 
 * @constructor
 */
DataObject = function(name, description, place, timeStamp, timeSpan, granularity, lon, lat, descriptionData){

    this.name = name;
    this.description = description;
    this.timeStamp = timeStamp;
    this.timeSpan = timeSpan;
	this.granularity = granularity;
    this.longitude = lon;
    this.latitude = lat;
    
    this.descriptionData = descriptionData;
    
    this.setPlaces(place);
    this.status = false;
    this.percentage = 0;
	this.hoverSelect = false;
    
};

DataObject.prototype = {

    /**
     * sets the selection-percentage of the data object
     * @param {float} percentage sets the percentage value (p); it describes the ratio to the actual selection <br>
     * p = 0 if this data object is unselected, p = 1 if it is selected and 0 < p < 1 if its in a feather range 
     */
    setPercentage: function(percentage){
        if (this.percentage == percentage) 
            this.status = false;
        else {
            this.percentage = percentage;
            this.status = true;
        }
    },
    
    inTime: function( minTime, maxTime ){
    	if( this.timeStamp != undefined ){
    		if( this.timeStamp.getTime() >= minTime.getTime() && this.timeStamp.getTime() <= maxTime.getTime() ){
    			return true;
    		}
    	}
    	else {
    		if( this.timeSpan.start.getTime() >= minTime.getTime() && this.timeSpan.start.getTime() <= maxTime.getTime() ){
    			return true;
    		}
    		if( this.timeSpan.end.getTime() >= minTime.getTime() && this.timeSpan.end.getTime() <= maxTime.getTime() ){
    			return true;
    		}
    	}
		return false;
    },
    
    /**
     * sets the object to a hover selection status
     * @param {boolean} hover bool value that tells if an object is hovered or not
     */
    setHover: function(hover){
    	this.hoverSelect = hover;
    	if( this.percentage != 1 ){
    		this.status = true;
    	} 
    },
    
    /**
     * return the string representation of the objects time
     * @return the string representation of the objects time
     */
    getTimeString: function(){
    	if( this.timeStamp != undefined ){
    		return SimileAjax.DateTime.getTimeString(this.granularity,this.timeStamp)+"";
    	}
    	else {
    		return ( SimileAjax.DateTime.getTimeString(this.granularity,this.timeSpan.start)+" - "+SimileAjax.DateTime.getTimeString(this.granularity,this.timeSpan.end));
    	}
    },
    
    /**
     * return the string representation of the timeStamp
     * @return the string representation of the timeStamp
     */
    getTimeStampString: function(){
    	if( this.timeStamp != undefined ){
    		return SimileAjax.DateTime.getTimeString(this.granularity,this.timeStamp)+"";
    	}
    	return(undefined);
    },

    /**
     * return the string representation of the timeStamp
     * @return the string representation of the timeStamp
     */
    getTimeSpanStartString: function(){
    	if( this.timeSpan != undefined ){
    		return SimileAjax.DateTime.getTimeString(this.granularity,this.timeSpan.start)+"";
    	}
    	return(undefined);
    },

    /**
     * return the string representation of the timeStamp
     * @return the string representation of the timeStamp
     */
    getTimeSpanEndString: function(){
    	if( this.timeSpan != undefined ){
    		return SimileAjax.DateTime.getTimeString(this.granularity,this.timeSpan.end)+"";
    	}
    	return(undefined);
    },

    isSelected: function(){
		if( this.percentage > 0 || this.hoverSelect ){
			return true;
		}
		return false;
    },
    
    setPlaces: function(place){
        this.placeDetail = place.split("/");
        this.place = "";
        for( var i=0; i<this.placeDetail.length; i++ ){
        	if( i>0 ){
        		this.place += ", ";
        	}
        	this.place += this.placeDetail[i];
        }
    },
    
    getPlace: function(level){
    	if( level >= this.placeDetail.length ){
    		return this.placeDetail[this.placeDetail.length-1];
    	}
    	return this.placeDetail[level];
    },
    
    getDescriptionData: function(columnName){
    	if (this.descriptionData[columnName] != null)
    		return this.descriptionData[columnName];
    	else
    		return "";
    }
    
};