lowered code smells in ChartD3Helper.java 07/108607/1
authorIndrijeet kumar <indriku1@in.ibm.com>
Mon, 1 Jun 2020 04:02:04 +0000 (09:32 +0530)
committerIndrijeet kumar <indriku1@in.ibm.com>
Mon, 1 Jun 2020 04:02:13 +0000 (09:32 +0530)
Lowered code smells in ChartD3Helper.java

Issue-ID: PORTAL-813
Change-Id: Ia2a8451ac94bf59e45da2436ecefd321cf18212e
Signed-off-by: Indrijeet Kumar <indriku1@in.ibm.com>
ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/runtime/ChartD3Helper.java

index dd06355..0934e35 100644 (file)
@@ -436,7 +436,7 @@ public class ChartD3Helper {
                                                         }
                                                         uniqueElement = (String)uniqueElements[j];
                                            if(date==null) {
-                                                       //continue;
+                                                       //continue
                                                        flagNoDate = 1;
                                                        int pos = 0;
                                                                for (int f=0 ; f< uniqueXAxisElements.length; f++) {
@@ -461,7 +461,6 @@ public class ChartD3Helper {
                                                                                          } catch (NumberFormatException ex1) {
                                                                                                  flagNull = 1;
                                                                                          }
-                                                                                       //flagNull = 1;
                                                                                  }
                                                                                    /* For Non-date type value enclose with double quotes  */
 
@@ -506,7 +505,6 @@ public class ChartD3Helper {
                                                                                                  flagNull = 1;
                                                                                          }
                                                                                  
-                                                                                       //flagNull = 1;
                                                                                  }
                                                                HashMap<String, String> dataMap = dataSeriesMap.get((String) uniqueElements[j]);
                                                                                if(logScale) {
@@ -518,7 +516,6 @@ public class ChartD3Helper {
                                                              
 
                                                    }
-                                                        //}
                                                 }
                                                }
                                                for(int kI = 0; kI < uniqueElements.length; kI++) {
@@ -544,7 +541,6 @@ public class ChartD3Helper {
                                                                 YAXISNUM = 0;
                                                                 YAXISDOUBLENUM = 0.0;
                                                                 flagNull= 0;
-                                                                //flagSecondNull = 0;
                                                                 dateStr = ds.getString(i, 1);
                                                                 if(timeAxis) {
                                                                         date = getDateFromDateStr(dateStr);
@@ -552,7 +548,7 @@ public class ChartD3Helper {
                                                                 }
                                                                 uniqueElement = (String)uniqueElements[j];
                                                                 if(date==null) {
-                                                               //continue;
+                                                               //continue
                                                                flagNoDate = 1;
                                                                int pos = 0;
                                                                        for (int f=0 ; f< uniqueXAxisElements.length; f++) {
@@ -579,7 +575,6 @@ public class ChartD3Helper {
                                                                                                                          flagNull = 1;
                                                                                                           }
                                                                                                  
-                                                                                                    //flagNull = 1;
                                                                                                  }
                                                                                         
                                                                                if(logScale) {
@@ -631,7 +626,6 @@ public class ChartD3Helper {
                                                                                                                          flagNull = 1;
                                                                                                           }
                                                                                          
-                                                                                           //flagNull = 1;
                                                                                          }
                                                                                 
                                                                        HashMap<String, String> dataMap = dataSeriesMap.get((String) uniqueElements[j]);
@@ -727,19 +721,16 @@ public class ChartD3Helper {
                                        }
                                        
                                        if(timeAxis) {
-                                               //if(!barRealTimeAxis) { // false - non-time
                                                Object[] dateAllElements = (Object[]) sortSet.toArray();
                                                
                                                 for (int i = 0; i < uniqueElements.length; i++) {
                                                                HashMap<String, String> dataMap = dataSeriesMap.get((String)uniqueElements[i]);
                                                                for (int j=0; j<dateAllElements.length;j++) {
-                                                                       //if(strBuf.toString().indexOf((String) dateAllElements[j]) == -1) {
                                                                        if(!dataMap.containsKey((String) dateAllElements[j])) {
                                                                                dataMap.put((String) dateAllElements[j], "null");
                                                                        }
                                                                }
                                                 }
-                                               //}
                                        }
                                         String valueStr = "";
                                         for (int i = 0; i < uniqueElements.length; i++) {
@@ -782,10 +773,8 @@ public class ChartD3Helper {
                                        wholeScript.append("nv.addGraph(function() { \n");
                                        if(horizontalBar /*&& flagNoDate == 1*/)
                                                wholeScript.append(" chart = nv.models.multiBarHorizontalChart() \n");
-                                       else /*if (flagNoDate == 1)*/
+                                       else
                                                wholeScript.append(" chart = nv.models.multiBarChart() \n");
-                                       /*else
-                                               wholeScript.append(" var chart = nv.models.multiBarTimeSeriesChart() \n");*/
                                        
                                        wholeScript.append("           .margin({top: "+ topMargin +", right: "+ rightMargin +", bottom: "+ bottomMargin +", left: " + leftMargin +"}) \n");
                                                        if(showLegend) {
@@ -797,7 +786,6 @@ public class ChartD3Helper {
                                                                wholeScript.append("          .reduceXTicks(true) \n ");
                                                        else if (!horizontalBar) {
                                                                wholeScript.append("          .reduceXTicks(false) \n ");
-                                                               //wholeScript.append(" chart.lines1.forceY(["+(nvl(reportRuntime.getRangeAxisLowerLimit()).length()<=0?"0":reportRuntime.getRangeAxisLowerLimit()) +", "+ (nvl(reportRuntime.getRangeAxisUpperLimit()).length()<=0?UPPER_RANGE:reportRuntime.getRangeAxisUpperLimit()) + "]); \n" +
                                                                double UPPER_RANGE = 0;
                                                                if(Math.ceil((MAXDOUBLENUM+(MAXDOUBLENUM*25/100))/100) * 100 >= 1) {
                                                                        UPPER_RANGE = Math.ceil(MAXDOUBLENUM+(MAXDOUBLENUM*25/100));
@@ -884,10 +872,7 @@ public class ChartD3Helper {
                                        }
 
                                         if(nvl(chartRightAxisLabel).length() > 0) {
-                                                  //if(flagNoDate == 1)
                                                           wholeScript.append("  chart.yAxis\n");
-                                                  //else
-                                                        //  wholeScript.append("  chart.yAxis1\n");
                                                        if(logScale) {
                                                                wholeScript.append("                    .logScale(true)\n  ");
                                                        } else {
@@ -896,16 +881,10 @@ public class ChartD3Helper {
    
                                                        wholeScript.append("             .axisLabel('" + chartLeftAxisLabel  + "') \n" +
                                                "        .tickFormat(d3.format(',.0f')); \n");
-                                               /*"  chart.yAxis2\n " +
-                                               "             .axisLabel('" + chartRightAxisLabel  + "') \n" +
-                                               "        .tickFormat(d3.format(',.0f')); \n");*/
                                                
                                         
                                         } else {
-                                                  //if(flagNoDate == 1)
                                                           wholeScript.append("  chart.yAxis\n");
-                                                  //else
-                                                        //  wholeScript.append("  chart.yAxis1\n");
                                                                if(logScale) {
                                                                        wholeScript.append("                    .logScale(true)\n  ");
                                                                } else {
@@ -921,7 +900,6 @@ public class ChartD3Helper {
                                                                wholeScript.append("        .tickFormat(d3.format(',."+MAXNUMDECIMALPLACES+"f')); \n");
                                                          else 
                                                                  wholeScript.append("        .tickFormat(d3.format(',." + precision + "f')); \n"); 
-                                                       //"        .tickFormat(d3.format(',.0f')); \n");
                                         }
                                                        wholeScript.append(" d3.select('#chart"+reportRuntime.getReportID()+" svg') \n" +
                                                        "  .datum(historicalBarChart) \n" );
@@ -934,7 +912,6 @@ public class ChartD3Helper {
                                                        "return chart; \n" +
                                                        "}); \n");
                                                        wholeScript.append("function redraw() { \n");
-                                                       //wholeScript.append(" nv.utils.windowResize(chart.update); \n");
                                                        wholeScript.append("    d3.select('#chart"+reportRuntime.getReportID()+" svg') \n")     ;       
                                                        wholeScript.append("            .datum(historicalBarChart) \n");                
                                                        wholeScript.append("            .transition().duration(500) \n");               
@@ -971,7 +948,6 @@ public class ChartD3Helper {
                                int flag = 0;
                                    flag = hasCategoryAxis?1:0;
                                        String uniqueElements [] = null;
-                               //TreeSet ts = new TreeSet();
                                        ArrayList ts = new ArrayList<String>();
                                        HashMap<String, String> columnMap = new HashMap();
                                //check timeAxis
@@ -1020,7 +996,6 @@ public class ChartD3Helper {
                                                                         catStr.append("|"+color);
                                                                 }
                                                         } catch (ArrayIndexOutOfBoundsException ex) {
-                                                                //System.out.println("No Chart Color");
                                                         }
                                                         
                                            if(catStr.length()>0) {
@@ -1030,15 +1005,11 @@ public class ChartD3Helper {
                                                
                                            }
                                        }
-                                       //Object uniqueElements [] = ts.toArray();
-                                       //SortedSet s = Collections.synchronizedSortedSet(ts);
-                                       //uniqueElements = (String[]) ts.toArray();
                                        DataColumnType dct = null;
                                        List yTextSeries = reportRuntime.getChartDisplayNamesList(AppConstants.CHART_ALL_COLUMNS, formValues);
                                        if(yTextSeries.size()==1) {
                                                for (Iterator iter = l.iterator(); iter.hasNext();) {
                                                    dct = (DataColumnType) iter.next();
-                                                   //System.out.println(dct.getDisplayName() + " " + yText);
                                                    if(!(nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND))) {
                                                           if(nvl(chartLeftAxisLabel).length()<=0) {
                                                                   chartLeftAxisLabel = nvl(dct.getYAxis());
@@ -1054,11 +1025,9 @@ public class ChartD3Helper {
                                        DataColumnType dct = null; 
                                        
                                        List yTextSeries = reportRuntime.getChartDisplayNamesList(AppConstants.CHART_ALL_COLUMNS, formValues);
-                                       //if(columnValuesList.size() == 1) {
                                        int dctIndex = 0;
                                                for (Iterator iter = l.iterator(); iter.hasNext();) {
                                                    dct = (DataColumnType) iter.next();
-                                                   //System.out.println(dct.getDisplayName() + " " + yText);
                                                    if(!(nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND))) {
                                                        if(yTextSeries.contains((String)dct.getDisplayName())) {
                                                                if(nvl(dct.getChartColor()).length()>0)
@@ -1096,10 +1065,8 @@ public class ChartD3Helper {
                                                    
                                                }
                                                        
-                                               //SortedSet s = Collections.synchronizedSortedSet(ts);
                                                Object tempArray[] = ts.toArray();
                                                uniqueElements = Arrays.copyOf(tempArray, tempArray.length, String[].class);
-                                               //uniqueElements = (String[]) ts.toArray();
                                                
                                        }
                                        
@@ -1151,29 +1118,20 @@ public class ChartD3Helper {
                                        wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/d3.v3.min.js\"></script>\n");
                                        wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/nv.d3.min.js\"></script> \n");
                                        wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/models/axis.min.js\"></script> \n");
-                                       //wholeScript.append("<script src=\""+ AppUtils.getBaseFolderURL() +"d3/js/models/cumulativeLineChart.js\"></script> \n");
-                                       //if(multipleSeries) 
-                                               //wholeScript.append("<script src=\""+ AppUtils.getBaseFolderURL() +"d3/js/models/multiChart.js\"></script> \n");
                                        
                                        //json
                                        wholeScript.append("<script> \n");
 
                                        wholeScript.append("historicalBarChart = [ \n");
-                                       //wholeScript.append("{ \n");
                                        ArrayList dataSeries = new ArrayList();
                                        String uniqueElement = "";
                                        
                                        String [] uniqueRevElements = null;
                                        //Added to make sure order appears same as legend
-                                       /*if(nvl(subType).length() > 0 && subType.equals("area")) {
-                                               uniqueRevElements = reverse((String[])uniqueElements);
-                                       } else {*/
                                                uniqueRevElements = (String[])uniqueElements;
-                                       //}
 
                                        int RIGHTAXISSERIES = 0;
                                        for (int i = 0; i < uniqueRevElements.length; i++) {
-                                               //element.substring(element.indexOf("|")+1)
                                                uniqueElement = (String)uniqueRevElements[i];
                                                if(multipleSeries && (nvl(chartRightAxisLabel).length() > 0)) {
                                                        if(nvl(subType).length() > 0 && subType.equals("area")) {
@@ -1188,7 +1146,6 @@ public class ChartD3Helper {
                                                                        dataSeries.add(new StringBuffer(" { \"type\":\"line\", \"key\": \""+ ((uniqueElement.indexOf("|") != -1)?uniqueElement.substring(0, uniqueElement.indexOf("|")):uniqueElement) +"\", \"yAxis\": \""+(1)+"\","+ (hasCustomizedChartColor && (uniqueElement.lastIndexOf("|") != -1) ?("\"color\": \""+uniqueElement.substring(uniqueElement.lastIndexOf("|")+1) + "\","):"")+" \"values\": ["));
                                                        }
                                                        RIGHTAXISSERIES = dataSeries.size()-1;
-                                                       //dataSeries.add(new StringBuffer(" { \"type\":\"line\", \"key\": \""+ ((DataColumnType)columnMap.get(i)).getDisplayName() +"\", \"yAxis\": \""+(i+1)+"\", \"values\": ["));
                                                }
                                                else {
                                                                dataSeries.add(new StringBuffer(" { \"type\":\"line\", \"key\": \""+ ((uniqueElement.indexOf("|")!= -1)?uniqueElement.substring(0, uniqueElement.indexOf("|")):uniqueElement) +"\", \"yAxis\": \""+(1)+"\","+ (hasCustomizedChartColor && (uniqueElement.lastIndexOf("|") != -1)?("\"color\": \""+uniqueElement.substring(uniqueElement.lastIndexOf("|")+1) + "\","):"")+"\"values\": ["));
@@ -1222,10 +1179,6 @@ public class ChartD3Helper {
                                                         if(date==null && timeAxis)
                                                                 continue;
                                                        
-                                                        
-                                                        //if(ds.getString(i, 2).equals(uniqueElements[j])) {
-                                                     //if(minTime > date.getTime())
-                                                        // minTime = date.getTime();
                                                    uniqueElement = (String)uniqueRevElements[j];
                                                      try {
                                                         YAXISNUM = Integer.parseInt(ds.getString(i, columnMap.get(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1)?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))));
@@ -1291,16 +1244,12 @@ public class ChartD3Helper {
                                                                                                          date = getDateFromDateStr(dateStr);
                                                                                                          ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime()  + " , \"y\":" + null +"}, ");
                                                                                                  }
-                                                                                                 //((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime()  + " , \"y\":" + null +"}, ");
                                                                                         }
                                                                          }
                                                                          
                                                                     }
-                                                                         
-                                                                        
-                                                        //}
+                                                               
                                                 }
-                                                //((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + minTime  + " , \"y\":" + 0 +"}, ");
                                                }
                                                
                                        } else {
@@ -1320,10 +1269,8 @@ public class ChartD3Helper {
                                                                 continue;
                                                         
                                                    uniqueElement = (String)uniqueRevElements[j];
-                                                        //date = MMDDYYYYFormat.parse(ds.getString(i, 1), new ParsePosition(0));
                                                         if(ds.getString(i, 2).equals(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1) ?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))) {
-                                                     //if(minTime > date.getTime())
-                                                       //  minTime = date.getTime();
+
                                                      try {
                                                                 YAXISNUM = Integer.parseInt(ds.getString(i, 3));
                                                                      if(MAXDOUBLENUM < YAXISNUM)
@@ -1429,7 +1376,6 @@ public class ChartD3Helper {
                     /* Sorting is commented out.*/
                                        StringBuffer dateStrBuf = new StringBuffer("");
                                        if(dateList.size()>0) {
-                                                //SortedSet<String> s = Collections.synchronizedSortedSet(dateList);
                                                 Object[] dateElements = (Object[]) dateList.toArray();
                                                 
                                                 String element = "";
@@ -1442,8 +1388,6 @@ public class ChartD3Helper {
 
                     wholeScript.append(" var chart;\n");  
                                        wholeScript.append("nv.addGraph(function() { \n");
-                                                       //" var chart = nv.models.cumulativeLineChart() \n" + nv.models.lineWithFocusChart()
-//                                                     " chart = nv.models.lineChart() \n" +
                                        if(nvl(subType).length() > 0 && subType.equals("area")) {
                                                wholeScript.append(" chart = nv.models.stackedAreaChart() \n");
                                                if(showControls) {