Changeset 2039


Ignore:
Timestamp:
Sep 29, 2011, 1:48:21 PM (5 years ago)
Author:
taco@…
Message:

visualization/VisualizeController.groovy, VIS-9 'Sort response getFields ', VIS-28 'Table needs axis names and unit', VIS-29 'Add axis types to getData-response'

File:
1 edited

Legend:

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

    r2038 r2039  
    123123        }
    124124
     125        fields.unique() // Todo: find out root cause of why some fields occur more than once
     126        fields.sort { a, b ->
     127            def sourceEquality = a.source.toString().toLowerCase().compareTo(b.source.toString().toLowerCase())
     128            if( sourceEquality == 0 ) {
     129                def categoryEquality = a.category.toString().toLowerCase().compareTo(b.category.toString().toLowerCase())
     130                if( categoryEquality == 0 ){
     131                    a.name.toString().toLowerCase().compareTo(b.name.toString().toLowerCase())
     132                } else return categoryEquality
     133            } else return sourceEquality
     134        }
    125135                return sendResults(['studyIds': studies, 'fields': fields])
    126136        }
     
    283293                def inputData = parseGetDataParams();
    284294
     295        println ": "+params
     296
    285297        if(inputData.columnIds == null || inputData.rowIds == null){
    286298            infoMessage = "Please select data sources for the y- and x-axes."
     
    307319            groupedData = groupFieldData( inputData.visualizationType, data ); // Don't indicate axis ordering, standard <"x", "y"> will be used
    308320        }
    309    
     321
    310322        // Format data so it can be rendered as JSON
    311323        def returnData
    312324        if(inputData.visualizationType=='horizontal_barchart'){
    313             returnData = formatData( inputData.visualizationType, groupedData, fields, "y", "x" ); // Indicate non-standard axis ordering
     325            def valueAxisType = determineFieldType(inputData.studyIds[0], inputData.rowIds[0], groupedData["x"])
     326            def groupAxisType = determineFieldType(inputData.studyIds[0], inputData.columnIds[0], groupedData["y"])
     327            returnData = formatData( inputData.visualizationType, groupedData, fields, groupAxisType, valueAxisType , "y", "x" ); // Indicate non-standard axis ordering
    314328        } else {
    315             returnData = formatData( inputData.visualizationType, groupedData, fields); // Don't indicate axis ordering, standard <"x", "y"> will be used
     329            def valueAxisType = determineFieldType(inputData.studyIds[0], inputData.rowIds[0], groupedData["y"])
     330            def groupAxisType = determineFieldType(inputData.studyIds[0], inputData.columnIds[0], groupedData["x"])
     331            returnData = formatData( inputData.visualizationType, groupedData, fields, groupAxisType, valueAxisType ); // Don't indicate axis ordering, standard <"x", "y"> will be used
    316332        }
    317333        return sendResults(returnData)
     
    562578         * @param fields                Map with key-value pairs determining the name and fieldId to retrieve data for. Example:
    563579         *                                                      [ "x": "field-id-1", "y": "field-id-3" ]
     580     * @param groupAxisType Integer, either CATEGORICAL or NUMERIACAL
     581     * @param valueAxisType Integer, either CATEGORICAL or NUMERIACAL
    564582         * @param groupAxis             Name of the axis to with group data. Defaults to "x"
    565583         * @param valueAxis             Name of the axis where the values are stored. Defaults to "y"
     
    582600         *
    583601         */
    584         def formatData( type, groupedData, fields, groupAxis = "x", valueAxis = "y", errorName = "error" ) {
     602        def formatData( type, groupedData, fields, groupAxisType, valueAxisType, groupAxis = "x", valueAxis = "y", errorName = "error" ) {
    585603        // TODO: Handle name and unit of fields correctly
    586604
     605        def valueAxisTypeString = (valueAxisType==CATEGORICALDATA ? "categorical" : "numerical")
     606        def groupAxisTypeString = (groupAxisType==CATEGORICALDATA ? "categorical" : "numerical")
    587607        groupedData[groupAxis] = renderTimesAndDatesHumanReadable(groupedData[groupAxis], fields[groupAxis])
    588608
    589609        if(type=="table"){
    590             def yName = parseFieldId( fields[ valueAxis ] ).name;
    591 
    592610            def return_data = [:]
    593611            return_data[ "type" ] = type
    594             return_data.put("yaxis", ["title" : "", "unit" : "" ])
    595             return_data.put("xaxis", ["title" : "", "unit": "" ])
     612            return_data.put("yaxis", ["title" : parseFieldId( fields[ valueAxis ] ).name, "unit" : "", "type":valueAxisTypeString ])
     613            return_data.put("xaxis", ["title" : parseFieldId( fields[ groupAxis ] ).name, "unit": "", "type":groupAxisTypeString ])
    596614            return_data.put("series", [[
    597615                    "x": groupedData[ groupAxis ].collect { it.toString() },
     
    606624            def return_data = [:]
    607625            return_data[ "type" ] = type
    608             return_data.put("yaxis", ["title" : yName, "unit" : "" ])
    609             return_data.put("xaxis", ["title" : parseFieldId( fields[ groupAxis ] ).name, "unit": "" ])
     626            return_data.put("yaxis", ["title" : yName, "unit" : "", "type":valueAxisTypeString ])
     627            return_data.put("xaxis", ["title" : parseFieldId( fields[ groupAxis ] ).name, "unit": "", "type":groupAxisTypeString ])
    610628            return_data.put("series", [[
    611629                "name": yName,
     
    906924     * @param studyId An id that can be used with Study.get/1 to retrieve a study from the database
    907925     * @param fieldId The field id as returned from the client, will be used to retrieve the data required to determine the type of data a field contains
     926     * @param inputData Optional parameter that contains the data we are computing the type of. When including in the function call we do not need to request data from a module, should the data belong to a module
    908927     * @return Either CATEGORICALDATA of NUMERICALDATA
    909928     */
    910     protected int determineFieldType(studyId, fieldId){
     929    protected int determineFieldType(studyId, fieldId, inputData = null){
    911930                def parsedField = parseFieldId( fieldId );
    912931        def study = Study.get(studyId)
     
    927946                }
    928947            } else {
    929                 data = getModuleData( study, study.getSamples(), parsedField.source, parsedField.name );
    930                 def cat = determineCategoryFromData(data)
    931                 return cat
     948                if(inputData == null){ // If we did not get data, we need to request it from the module first
     949                    data = getModuleData( study, study.getSamples(), parsedField.source, parsedField.name );
     950                    return determineCategoryFromData(data)
     951                } else {
     952                    return determineCategoryFromData(inputData)
     953                }
    932954            }
    933955        } catch(Exception e){
Note: See TracChangeset for help on using the changeset viewer.