Changeset 2056

Show
Ignore:
Timestamp:
13-10-11 12:57:58 (3 years ago)
Author:
taco@…
Message:

visualization/VisualizeController.groovy, 'formatData' function, Fixed bug that really bugged me, which occurred when sorting the 'valueAxis' or 'data' items, based on the sorting of the 'groupAxis'

Files:
1 modified

Legend:

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

    r2055 r2056  
    332332            groupedData = groupFieldData( inputData.visualizationType, data ); // Don't indicate axis ordering, standard <"x", "y"> will be used 
    333333        } 
    334                  
    335334        // Format data so it can be rendered as JSON 
    336335        def returnData 
     
    344343            returnData = formatData( inputData.visualizationType, groupedData, fields, groupAxisType, valueAxisType ); // Don't indicate axis ordering, standard <"x", "y"> will be used 
    345344        } 
     345        println "returnData: "+returnData 
    346346        return sendResults(returnData) 
    347347        } 
     
    674674                // We want to sort the data based on the group-axis, but keep the values on the value-axis in sync.  
    675675                // The only way seems to be to combine data from both axes. 
    676                 def combined = [] 
    677                 groupedData[ groupAxis ].eachWithIndex { group, i -> 
    678                         combined << [ "group": group, "value": groupedData[ valueAxis ][ i ] ] 
    679                 } 
    680                 combined.sort { it.group } 
    681                  
     676        def combined = [] 
     677        if(type=="table"){ 
     678            groupedData[ groupAxis ].eachWithIndex { group, i -> 
     679                combined << [ "group": group, "data": groupedData[ 'data' ][ i ] ] 
     680            } 
     681            combined.sort { it.group } 
     682            groupedData[groupAxis] = renderTimesAndDatesHumanReadable(combined*.group, groupAxisType) 
     683            groupedData[valueAxis] = renderTimesAndDatesHumanReadable(groupedData[valueAxis], valueAxisType) 
     684            groupedData["data"] = combined*.data 
     685        } else { 
     686            groupedData[ groupAxis ].eachWithIndex { group, i -> 
     687                combined << [ "group": group, "value": groupedData[ valueAxis ][ i ] ] 
     688            } 
     689            combined.sort { it.group } 
     690            groupedData[groupAxis] = renderTimesAndDatesHumanReadable(combined*.group, groupAxisType) 
     691            groupedData[valueAxis] = renderTimesAndDatesHumanReadable(combined*.value, valueAxisType) 
     692        } 
     693 
    682694        // TODO: Handle name and unit of fields correctly 
    683695        def valueAxisTypeString = (valueAxisType==CATEGORICALDATA || valueAxisType==DATE || valueAxisType==RELTIME ? "categorical" : "numerical") 
    684696        def groupAxisTypeString = (groupAxisType==CATEGORICALDATA || groupAxisType==DATE || groupAxisType==RELTIME ? "categorical" : "numerical") 
    685         groupedData[groupAxis] = renderTimesAndDatesHumanReadable(combined*.group, groupAxisType) 
    686         groupedData[valueAxis] = renderTimesAndDatesHumanReadable(combined*.value, valueAxisType) 
    687697 
    688698        if(type=="table"){ 
     
    725735    def renderTimesAndDatesHumanReadable(data, axisType){ 
    726736        if(axisType==RELTIME){ 
     737            println "RELTIME" 
    727738            data = renderTimesHumanReadable(data) 
    728739        } 
    729740        if(axisType==DATE){ 
     741            println "DATE" 
    730742           data = renderDatesHumanReadable(data) 
    731743        } 
     744        println "NO JOY" 
    732745        return data 
    733746    } 
     
    741754        def tmpTimeContainer = [] 
    742755        data. each { 
     756            println "\t"+it 
    743757            if(it instanceof Number) { 
    744758                try{ 
     
    762776        def tmpDateContainer = [] 
    763777        data. each { 
     778            println "\t"+it 
    764779            if(it instanceof Number) { 
    765780                try{