Changeset 2039
- Timestamp:
- Sep 29, 2011, 1:48:21 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/dbnp/visualization/VisualizeController.groovy
r2038 r2039 123 123 } 124 124 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 } 125 135 return sendResults(['studyIds': studies, 'fields': fields]) 126 136 } … … 283 293 def inputData = parseGetDataParams(); 284 294 295 println ": "+params 296 285 297 if(inputData.columnIds == null || inputData.rowIds == null){ 286 298 infoMessage = "Please select data sources for the y- and x-axes." … … 307 319 groupedData = groupFieldData( inputData.visualizationType, data ); // Don't indicate axis ordering, standard <"x", "y"> will be used 308 320 } 309 321 310 322 // Format data so it can be rendered as JSON 311 323 def returnData 312 324 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 314 328 } 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 316 332 } 317 333 return sendResults(returnData) … … 562 578 * @param fields Map with key-value pairs determining the name and fieldId to retrieve data for. Example: 563 579 * [ "x": "field-id-1", "y": "field-id-3" ] 580 * @param groupAxisType Integer, either CATEGORICAL or NUMERIACAL 581 * @param valueAxisType Integer, either CATEGORICAL or NUMERIACAL 564 582 * @param groupAxis Name of the axis to with group data. Defaults to "x" 565 583 * @param valueAxis Name of the axis where the values are stored. Defaults to "y" … … 582 600 * 583 601 */ 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" ) { 585 603 // TODO: Handle name and unit of fields correctly 586 604 605 def valueAxisTypeString = (valueAxisType==CATEGORICALDATA ? "categorical" : "numerical") 606 def groupAxisTypeString = (groupAxisType==CATEGORICALDATA ? "categorical" : "numerical") 587 607 groupedData[groupAxis] = renderTimesAndDatesHumanReadable(groupedData[groupAxis], fields[groupAxis]) 588 608 589 609 if(type=="table"){ 590 def yName = parseFieldId( fields[ valueAxis ] ).name;591 592 610 def return_data = [:] 593 611 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 ]) 596 614 return_data.put("series", [[ 597 615 "x": groupedData[ groupAxis ].collect { it.toString() }, … … 606 624 def return_data = [:] 607 625 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 ]) 610 628 return_data.put("series", [[ 611 629 "name": yName, … … 906 924 * @param studyId An id that can be used with Study.get/1 to retrieve a study from the database 907 925 * @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 908 927 * @return Either CATEGORICALDATA of NUMERICALDATA 909 928 */ 910 protected int determineFieldType(studyId, fieldId ){929 protected int determineFieldType(studyId, fieldId, inputData = null){ 911 930 def parsedField = parseFieldId( fieldId ); 912 931 def study = Study.get(studyId) … … 927 946 } 928 947 } 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 } 932 954 } 933 955 } catch(Exception e){
Note: See TracChangeset
for help on using the changeset viewer.