Changeset 2038

Show
Ignore:
Timestamp:
27-09-11 16:31:52 (3 years ago)
Author:
taco@…
Message:

visualization/VisualizeController.groovy, Fields on the 'groupAxis' that according to their fieldId contain a 'startTime', 'endTime' or 'duration' are now rendered using the 'RelTime?' class's 'toPrettyString' function.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/dbnp/visualization/VisualizeController.groovy

    r2037 r2038  
    584584        def formatData( type, groupedData, fields, groupAxis = "x", valueAxis = "y", errorName = "error" ) { 
    585585        // TODO: Handle name and unit of fields correctly 
     586 
     587        groupedData[groupAxis] = renderTimesAndDatesHumanReadable(groupedData[groupAxis], fields[groupAxis]) 
     588 
    586589        if(type=="table"){ 
    587590            def yName = parseFieldId( fields[ valueAxis ] ).name; 
     
    615618        } 
    616619        } 
     620 
     621    /** 
     622     * If the input variable 'data' contains dates or times according to input variable 'fieldInfo', these dates and times are converted to a human-readable version. 
     623     * @param data  The list of items that needs to be checked/converted 
     624     * @param fieldInfo This variable contains a fieldId, e.g.  
     625     * @return The input variable 'data', with it's date and time elements converted. 
     626     */ 
     627    def renderTimesAndDatesHumanReadable(data, fieldInfo){ 
     628        /* Perhaps this should be replaced with a more structured approach. 
     629         * TODO: Handle the human-readable rendering of dates and times in a more structured fashion */ 
     630        if(fieldInfo.startsWith("startTime") || fieldInfo.startsWith("endTime") || fieldInfo.startsWith("duration")){ 
     631            def tmpTimeContainer = [] 
     632            data. each { 
     633                if(it instanceof Number) { 
     634                    try{ 
     635                        tmpTimeContainer << new RelTime( it ).toPrettyString() 
     636                    } catch(IllegalArgumentException e){ 
     637                        tmpTimeContainer << it 
     638                    } 
     639                } else { 
     640                    tmpTimeContainer << it // To handle items such as 'unknown' 
     641                } 
     642            } 
     643            return tmpTimeContainer 
     644        } else { 
     645            return data 
     646        } 
     647    } 
    617648 
    618649        /**