2 * ================LICENSE_START==========================================
4 * =======================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * =======================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ================LICENSE_END============================================
38 package org.onap.portalsdk.analytics.model.runtime;
40 import java.io.BufferedWriter;
41 import java.io.FileWriter;
42 import java.io.IOException;
43 import java.io.UnsupportedEncodingException;
44 import java.text.ParsePosition;
45 import java.text.SimpleDateFormat;
46 import java.util.ArrayList;
47 import java.util.Arrays;
48 import java.util.Collections;
49 import java.util.Enumeration;
50 import java.util.GregorianCalendar;
51 import java.util.HashMap;
52 import java.util.Iterator;
53 import java.util.List;
55 import java.util.Map.Entry;
57 import java.util.SortedSet;
58 import java.util.TimeZone;
59 import java.util.TreeSet;
60 import java.util.regex.Matcher;
61 import java.util.regex.Pattern;
63 import javax.servlet.http.HttpServletRequest;
64 import javax.servlet.http.HttpSession;
66 import org.apache.commons.lang.time.DateUtils;
67 import org.onap.portalsdk.analytics.error.RaptorException;
68 import org.onap.portalsdk.analytics.model.base.ChartSeqComparator;
69 import org.onap.portalsdk.analytics.system.AppUtils;
70 import org.onap.portalsdk.analytics.system.ConnectionUtils;
71 import org.onap.portalsdk.analytics.system.Globals;
72 import org.onap.portalsdk.analytics.util.AppConstants;
73 import org.onap.portalsdk.analytics.util.DataSet;
74 import org.onap.portalsdk.analytics.util.HtmlStripper;
75 import org.onap.portalsdk.analytics.util.Utils;
76 import org.onap.portalsdk.analytics.xmlobj.DataColumnType;
77 import org.onap.portalsdk.analytics.xmlobj.FormFieldType;
78 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
79 import org.onap.portalsdk.core.web.support.UserUtils;
81 public class ChartD3Helper {
83 private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ChartD3Helper.class);
85 private ReportRuntime reportRuntime;
86 private String chartType;
88 public static final long HOUR = 3600l*1000l;
89 public static final long DAY = 3600l*1000l*24l;
90 public static final long MONTH = 3600l*1000l*24l*31l;
91 public static final long YEAR = 3600l*1000l*24l*365l;
93 private static final String REPORT_ID = "Report ID : ";
94 private static final String QUERY = "QUERY - ";
96 public ChartD3Helper() {
100 public ChartD3Helper(ReportRuntime rr) {
101 this.reportRuntime = rr;
104 private void printDebugLogSeparatorLine()
106 logger.debug(EELFLoggerDelegate.debugLogger, ("********************************************************************************"));
110 * @return the chartType
112 public String getChartType() {
117 * @param chartType the chartType to set
119 public void setChartType(String chartType) {
120 this.chartType = chartType;
123 public String createVisualization(ReportRuntime reportRuntime, Map<String,String> chartOptionsMap,
124 HttpServletRequest request) {
126 boolean isEmbedded = false;
127 if(request.getParameter("embedded")!=null) {
130 String width = chartOptionsMap.get("width");
131 String height = chartOptionsMap.get("height");
132 boolean animation = getBooleanValue(chartOptionsMap.get("animation"), true);
133 String rotateLabels = chartOptionsMap.get("rotateLabels");
134 boolean staggerLabels = getBooleanValue(chartOptionsMap.get("staggerLabels"));
135 boolean showMaxMin = getBooleanValue(chartOptionsMap.get("showMaxMin"), false);
136 boolean showLegend = getBooleanValue(chartOptionsMap.get("showLegend"), true);
137 boolean showControls = getBooleanValue(chartOptionsMap.get("showControls"), true);
138 String topMargin = chartOptionsMap.get("topMargin");
139 String bottomMargin = chartOptionsMap.get("bottomMargin");
140 String leftMargin = chartOptionsMap.get("leftMargin");
141 String rightMargin = chartOptionsMap.get("rightMargin");
142 boolean showTitle = getBooleanValue(chartOptionsMap.get("showTitle"), true);
143 String subType = chartOptionsMap.get("subType");
144 boolean stacked = getBooleanValue(chartOptionsMap.get("stacked"), false);
145 boolean horizontalBar = getBooleanValue(chartOptionsMap.get("horizontalBar"), false);
146 boolean barRealTimeAxis = getBooleanValue(chartOptionsMap.get("barRealTimeAxis"), true);
147 boolean barReduceXAxisLabels= getBooleanValue(chartOptionsMap.get("barReduceXAxisLabels"), false);
148 boolean timeAxis = getBooleanValue(chartOptionsMap.get("timeAxis"), true);
151 boolean logScale = getBooleanValue(chartOptionsMap.get("logScale"), false);
156 precision = Integer.parseInt(chartOptionsMap.get("precision"));
157 } catch (NumberFormatException ex) {
158 logger.debug(EELFLoggerDelegate.debugLogger, ex.getMessage());
161 final Long user_id = new Long((long) UserUtils.getUserId(request));
163 String chartType = reportRuntime.getChartType();
164 List l = reportRuntime.getAllColumns();
166 String chartLeftAxisLabel = reportRuntime.getFormFieldFilled(nvl(reportRuntime.getChartLeftAxisLabel()));
167 String chartRightAxisLabel = reportRuntime.getFormFieldFilled(nvl(reportRuntime.getChartRightAxisLabel()));
169 boolean multipleSeries = reportRuntime.isMultiSeries();
171 java.util.HashMap formValues = null;
172 formValues = getRequestParametersMap(reportRuntime, request);
175 String legendColumnName = (reportRuntime.getChartLegendColumn()!=null)?reportRuntime.getChartLegendColumn().getDisplayName():"Legend Column";
176 boolean displayChart = (nvl(chartType).length()>0)&&reportRuntime.getDisplayChart();
178 StringBuilder wholeScript = new StringBuilder("");
180 String title = reportRuntime.getReportTitle();
182 title = parseTitle(title, formValues);
184 String chartScriptsPath = (isEmbedded?AppUtils.getChartScriptsPath(""):AppUtils.getChartScriptsPath());
189 if (!(chartType.equals(AppConstants.GT_HIERARCHICAL) || chartType.equals(AppConstants.GT_HIERARCHICAL_SUNBURST) || chartType.equals(AppConstants.GT_ANNOTATION_CHART))) {
190 ds = loadChartData(Long.toString(user_id), request);
191 } else if(chartType.equals(AppConstants.GT_ANNOTATION_CHART)) {
192 String reportSQL = reportRuntime.getWholeSQL();
193 String dbInfo = reportRuntime.getDBInfo();
194 ds = ConnectionUtils.getDataSet(reportSQL, dbInfo);
195 if(ds.getRowCount()<=0) {
196 printDebugLogSeparatorLine();
197 logger.debug(EELFLoggerDelegate.debugLogger, (chartType.toUpperCase()+" - " + REPORT_ID + reportRuntime.getReportID() + " DATA IS EMPTY"));
198 logger.debug(EELFLoggerDelegate.debugLogger, (QUERY + reportSQL));
199 printDebugLogSeparatorLine();
201 } else if(chartType.equals(AppConstants.GT_HIERARCHICAL)||chartType.equals(AppConstants.GT_HIERARCHICAL_SUNBURST)) {
202 String reportSQL = reportRuntime.getWholeSQL();
203 String dbInfo = reportRuntime.getDBInfo();
204 ds = ConnectionUtils.getDataSet(reportSQL, dbInfo);
206 } catch (RaptorException ex) {
207 printDebugLogSeparatorLine();
208 logger.error(EELFLoggerDelegate.debugLogger, (chartType.toUpperCase()+" - " + REPORT_ID + reportRuntime.getReportID() + " ERROR THROWN FOR GIVEN QUERY "));
209 logger.error(EELFLoggerDelegate.debugLogger, (QUERY + reportRuntime.getWholeSQL()));
210 logger.error(EELFLoggerDelegate.debugLogger, ("ERROR STACK TRACE" + ex.getMessage()));
211 printDebugLogSeparatorLine();
215 if(chartType.equals(AppConstants.GT_ANNOTATION_CHART))
218 displayChart = false;
222 if (chartType.equals(AppConstants.GT_BAR_3D)) {
224 // get category if not give the column name for the data column use this to develop series.
225 boolean hasCategoryAxis = reportRuntime.hasSeriesColumn();
227 boolean hasCustomizedChartColor = false;
229 flag = hasCategoryAxis?1:0;
230 Object[] uniqueElements = null;
231 ArrayList uniqueElementsList = new ArrayList();
232 Object[] uniqueXAxisElements = null;
233 ArrayList ts = new ArrayList();
234 ArrayList<String> ts1 = new ArrayList();
235 HashMap<String, String> columnMap = new HashMap();
236 String uniqueXAxisStr = "";
238 for (int i = 0; i < ds.getRowCount(); i++) {
239 uniqueXAxisStr = ds.getString(i, 0);
240 ts1.add(uniqueXAxisStr);
243 uniqueElementsList.addAll(ts1);
244 uniqueXAxisElements = ts1.toArray();
247 StringBuilder catStr;
249 for (int i = 0; i < ds.getRowCount(); i++) {
250 catStr = new StringBuilder("");
251 catStr.append(ds.getString(i, 2));
253 if(ds.getString(i, "chart_color")!=null) {
254 color = ds.getString(i, "chart_color");
255 hasCustomizedChartColor = true;
256 catStr.append("|"+color);
258 } catch (ArrayIndexOutOfBoundsException ex) {
259 logger.debug(EELFLoggerDelegate.debugLogger, ex.getMessage());
262 if(catStr.length()>0) {
263 //duplicates are avoided
264 if(!ts.contains(catStr.toString()))
265 ts.add(catStr.toString());
268 /* Get Chart LeftAxis Label even from Range Axis definition. */
269 DataColumnType dct = null;
270 for (Iterator iter = l.iterator(); iter.hasNext();) {
271 dct = (DataColumnType) iter.next();
272 if(!(nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND))) {
273 if(nvl(chartLeftAxisLabel).length()<=0) {
274 chartLeftAxisLabel = nvl(dct.getYAxis());
275 chartLeftAxisLabel = (chartLeftAxisLabel.indexOf("|")!=-1)?chartLeftAxisLabel.substring(0,chartLeftAxisLabel.indexOf("|")):"";
281 uniqueElements = ts.toArray();
283 DataColumnType dct = null;
284 List yTextSeries = reportRuntime.getChartDisplayNamesList(AppConstants.CHART_ALL_COLUMNS, formValues);
286 for (Iterator iter = l.iterator(); iter.hasNext();) {
287 dct = (DataColumnType) iter.next();
289 if(!(nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND))) {
290 if((dct.isChartSeries()!=null && dct.isChartSeries().booleanValue()) || (dct.getChartSeq()!=null && dct.getChartSeq()>0) ) {
292 if(nvl(dct.getChartColor()).length()>0)
293 hasCustomizedChartColor = true;
294 if(hasCustomizedChartColor) {
295 //duplicates are avoided
296 if(!ts.contains(dct.getDisplayName()+"|"+nvl(dct.getChartColor())))
297 ts.add(dct.getDisplayName()+"|"+nvl(dct.getChartColor()));
299 //duplicates are avoided
300 if(!ts.contains(dct.getDisplayName()))
301 ts.add(dct.getDisplayName());
303 if(nvl(chartLeftAxisLabel).length()<=0) {
304 chartLeftAxisLabel = nvl(dct.getYAxis());
305 chartLeftAxisLabel = (chartLeftAxisLabel.indexOf("|")!=-1)?chartLeftAxisLabel.substring(0,chartLeftAxisLabel.indexOf("|")):"";
307 columnMap.put(dct.getDisplayName(), dct.getColId());
312 uniqueElements = ts.toArray();
316 wholeScript.append("<!DOCTYPE html>\n");
317 wholeScript.append("<html>\n");
318 wholeScript.append("<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF8\">\n");
319 wholeScript.append("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n");
320 wholeScript.append("<link href=\""+ chartScriptsPath +"d3/css/nv.d3.css\" rel=\"stylesheet\" type=\"text/css\">\n");
321 //wholeScript.append("")
322 wholeScript.append("<style>\n " +
324 " overflow-y:scroll; \n" +
327 " font: 12px sans-serif; \n" +
330 " display: block;\n" +
332 " #chart"+reportRuntime.getReportID()+" svg { \n" +
333 " height: "+ (nvl(height).length()>0?(height.endsWith("px")?height:height+"px"):"420px") + "; \n" +
334 " width: "+ (nvl(width).length()>0?(width.endsWith("px")?width:width+"px"):"700px") + "; \n" +
335 " min-width: 100px; \n" +
336 " min-height: 100px; \n" +
338 " tr.z-row-over > td.z-row-inner, tr.z-row-over > .z-cell {" +
339 " background-color: rgb(255, 255, 255); "+
342 wholeScript.append(".nodatadiv {\n");
343 wholeScript.append(" display: table-cell;\n");
344 wholeScript.append(" width: 700px;\n");
345 wholeScript.append(" height:370px;\n");
346 wholeScript.append(" text-align:center;\n");
347 wholeScript.append(" vertical-align: middle;\n");
348 wholeScript.append("}\n");
349 wholeScript.append(".nodatainner {\n");
350 wholeScript.append(" padding: 10px;\n");
351 wholeScript.append("}\n");
353 wholeScript.append(" </style> \n" );
354 wholeScript.append("<body> \n");
356 wholeScript.append("<div align=\"center\"><H3>" + title +"</H3></div>");
358 wholeScript.append("<div id=\"chart"+reportRuntime.getReportID()+"\"> <svg></svg> </div> \n");
360 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/d3.v3.min.js\"></script>");
361 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/nv.d3.min.js\"></script> \n");
362 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/tooltip.js\"></script> \n");
363 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/utils.js\"></script> \n");
364 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/models/axis.min.js\"></script> \n");
365 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/models/multiChart.js\"></script> \n");
367 wholeScript.append("<script> \n");
368 wholeScript.append("historicalBarChart = [ \n");
370 ArrayList dataSeries = new ArrayList();
372 String uniqueElement = "";
373 for (int i = 0; i < uniqueElements.length; i++) {
374 uniqueElement = (String)uniqueElements[i];
375 if(multipleSeries && (nvl(chartRightAxisLabel).length() > 0))
376 dataSeries.add(new StringBuffer(" { \"type\":\"bar\", \"key\": \""+ (hasCustomizedChartColor?(uniqueElement.indexOf("|")!=-1?uniqueElement.substring(0, uniqueElement.indexOf("|")):uniqueElement):uniqueElement) +"\", \"yAxis\": \""+(i+1)+"\", "+ (hasCustomizedChartColor?("\"color\": \""+uniqueElement.substring(uniqueElement.indexOf("|")+1) + "\","):"")+"\"values\": ["));
378 dataSeries.add(new StringBuffer(" { \"type\":\"bar\", \"key\": \""+ (hasCustomizedChartColor?(uniqueElement.indexOf("|")!=-1?uniqueElement.substring(0, uniqueElement.indexOf("|")):uniqueElement):uniqueElement) +"\", \"yAxis\": \""+(1)+"\", "+ (hasCustomizedChartColor?("\"color\": \""+uniqueElement.substring(uniqueElement.indexOf("|")+1) + "\","):"")+"\"values\": ["));
381 // added to load all date elements
382 HashMap<String, HashMap<String, String>> dataSeriesMap = new HashMap<>();
384 for (int i = 0; i < uniqueElements.length; i++) {
385 if(multipleSeries && (nvl(chartRightAxisLabel).length() > 0))
386 dataSeriesMap.put((String) uniqueElements[i], new HashMap<String, String>());
388 dataSeriesMap.put((String) uniqueElements[i], new HashMap<String, String>());
391 String dateStr = null;
392 java.util.Date date = null;
394 final int YEARFLAG = 1;
395 final int MONTHFLAG = 2;
396 final int DAYFLAG = 3;
397 final int HOURFLAG = 4;
398 final int MINFLAG = 5;
399 final int SECFLAG = 6;
400 final int MILLISECFLAG = 7;
401 final int DAYOFTHEWEEKFLAG = 8;
402 final int FLAGDATE = 9;
410 double YAXISDOUBLENUM = 0.0;
411 double MAXDOUBLENUM = 0.0;
412 int MAXNUMDECIMALPLACES = 0;
416 TreeSet<String> dateStrList = new TreeSet<>();
417 // added to store all date elements
418 SortedSet<String> sortSet = new TreeSet<>();
421 HashMap dataSeriesStrMap = new HashMap();
422 HashMap dataSeriesOverAllMap = new HashMap();
423 String valueDataSeries = "";
425 for (int j = 0; j < uniqueElements.length; j++) {
426 dataSeriesStrMap = new HashMap();
427 for (int i = 0; i < ds.getRowCount(); i++) {
430 YAXISDOUBLENUM = 0.0;
432 dateStr = ds.getString(i, 1);
434 date = getDateFromDateStr(dateStr);
435 formatFlag = getFlagFromDateStr(dateStr);
437 uniqueElement = (String)uniqueElements[j];
442 for (int f=0 ; f< uniqueXAxisElements.length; f++) {
443 if(uniqueXAxisElements[f].equals(dateStr)){
449 dateStrList.add("'"+dateStr+"'");
451 YAXISNUM = Integer.parseInt(ds.getString(i, columnMap.get((hasCustomizedChartColor?(uniqueElement.indexOf("|")!=-1?uniqueElement.substring(0, uniqueElement.indexOf("|")):uniqueElement):uniqueElement))));
453 if(MAXDOUBLENUM < YAXISNUM)
454 MAXDOUBLENUM = YAXISNUM;
455 } catch (NumberFormatException ex) {
457 YAXISDOUBLENUM = Double.parseDouble(ds.getString(i, columnMap.get((hasCustomizedChartColor?(uniqueElement.indexOf("|")!=-1?uniqueElement.substring(0, uniqueElement.indexOf("|")):uniqueElement):uniqueElement))));
458 MAXNUMDECIMALPLACES = getNumberOfDecimalPlaces(YAXISDOUBLENUM);
459 if(MAXDOUBLENUM < YAXISDOUBLENUM)
460 MAXDOUBLENUM = YAXISDOUBLENUM;
461 } catch (NumberFormatException ex1) {
466 /* For Non-date type value enclose with double quotes */
470 valueDataSeries = "{ \"x\":\"" + dateStr + "\" , \"y\":" + (flagNull == 0 ? (YAXISDOUBLENUM>0?new Double(Math.log10(YAXISDOUBLENUM)).toString():new Double(Math.log10(new Double(YAXISNUM>0?YAXISNUM:1).doubleValue())).toString()): null) +"}, ";
471 dataSeriesStrMap.put(dateStr, valueDataSeries);
473 valueDataSeries = "{ \"x\":\"" + dateStr + "\" , \"y\":" + (flagNull == 0 ? (YAXISDOUBLENUM>0?YAXISDOUBLENUM:YAXISNUM): null) +"}, ";
474 dataSeriesStrMap.put(dateStr, valueDataSeries);
478 dataSeriesOverAllMap.put(uniqueElements[j], dataSeriesStrMap);
482 if(!barRealTimeAxis) { // true - non-time
483 if(!dateStrList.contains(new Long(date.getTime()).toString())) {
484 dateStrList.add(new Long(date.getTime()).toString());
485 for (int k = 0; k < uniqueElements.length; k++) {
486 HashMap<String, String> dataMap = dataSeriesMap.get((String) uniqueElements[k]);
487 dataMap.put(date.getTime()+"", "null");
494 YAXISNUM = Integer.parseInt(ds.getString(i, columnMap.get(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1)?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))));
495 dateStrList.add(new Long(date.getTime()).toString());
497 if(MAXDOUBLENUM < YAXISNUM)
498 MAXDOUBLENUM = YAXISNUM;
499 } catch (NumberFormatException ex) {
501 YAXISDOUBLENUM = Double.parseDouble(ds.getString(i, columnMap.get(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1) ?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))));
502 MAXNUMDECIMALPLACES = getNumberOfDecimalPlaces(YAXISDOUBLENUM);
503 if(MAXDOUBLENUM < YAXISDOUBLENUM)
504 MAXDOUBLENUM = YAXISDOUBLENUM;
505 } catch (NumberFormatException ex1) {
511 HashMap<String, String> dataMap = dataSeriesMap.get((String) uniqueElements[j]);
513 dataMap.put(date.getTime()+"", (flagNull == 0 ? (YAXISDOUBLENUM>0?new Double(Math.log10(YAXISDOUBLENUM)).toString():(YAXISNUM>0?new Double(Math.log10(new Integer(YAXISNUM).doubleValue())).toString():null)): "null"));
515 dataMap.put(date.getTime()+"", (flagNull == 0 ? (YAXISDOUBLENUM>0?new Double(YAXISDOUBLENUM).toString():new Integer(YAXISNUM).toString()): "null"));
524 for(int kI = 0; kI < uniqueElements.length; kI++) {
525 HashMap dataSeriesStrMap1 = (HashMap) dataSeriesOverAllMap.get(uniqueElements[kI]);
526 for (int kL = 0; kL < uniqueXAxisElements.length; kL++) {
527 if(dataSeriesStrMap1.containsKey(uniqueXAxisElements[kL])) {
528 ((StringBuffer) dataSeries.get(kI)).append ((String)dataSeriesStrMap1.get(uniqueXAxisElements[kL]));
530 ((StringBuffer) dataSeries.get(kI)).append ("{ \"x\":\"" + uniqueXAxisElements[kL] + "\" , \"y\": null }, ");
536 HashMap dataSeriesStrMap = new HashMap();
537 HashMap dataSeriesOverAllMap = new HashMap();
538 String valueDataSeries = "";
539 for (int j = 0; j < uniqueElements.length; j++) {
540 dataSeriesStrMap = new HashMap();
542 for (int i = 0; i < ds.getRowCount(); i++) {
545 YAXISDOUBLENUM = 0.0;
547 //flagSecondNull = 0;
548 dateStr = ds.getString(i, 1);
550 date = getDateFromDateStr(dateStr);
551 formatFlag = getFlagFromDateStr(dateStr);
553 uniqueElement = (String)uniqueElements[j];
558 for (int f=0 ; f< uniqueXAxisElements.length; f++) {
559 if(uniqueXAxisElements[f].equals(dateStr)){
566 if(ds.getString(i, 2).equals(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1) ?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))) {
567 dateStrList.add("'"+dateStr+"'");
569 YAXISNUM = Integer.parseInt(ds.getString(i, 3));
570 if(MAXDOUBLENUM < YAXISNUM)
571 MAXDOUBLENUM = YAXISNUM;
572 } catch (NumberFormatException ex) {
574 YAXISDOUBLENUM = Double.parseDouble(ds.getString(i, 3));
575 MAXNUMDECIMALPLACES = getNumberOfDecimalPlaces(YAXISDOUBLENUM);
576 if(MAXDOUBLENUM < YAXISDOUBLENUM)
577 MAXDOUBLENUM = YAXISDOUBLENUM;
578 } catch (NumberFormatException ex1) {
587 valueDataSeries = "{ \"x\":" + dateStr + " , \"y\":" + (flagNull == 0 ? (YAXISDOUBLENUM>0?new Double(Math.log10(YAXISDOUBLENUM)).toString():new Double(Math.log10(new Double(YAXISNUM>0?YAXISNUM:1).doubleValue())).toString()): null) +"}, ";
588 dataSeriesStrMap.put(dateStr, valueDataSeries);
590 valueDataSeries = "{ \"x\":\"" + dateStr + "\" , \"y\":" + (flagNull == 0 ? (YAXISDOUBLENUM>0?new Double(Math.log10(YAXISDOUBLENUM)).toString():new Double(Math.log10(new Double(YAXISNUM>0?YAXISNUM:1).doubleValue())).toString()): null) +"}, ";
591 dataSeriesStrMap.put(dateStr, valueDataSeries);
595 valueDataSeries = "{ \"x\":" + dateStr + " , \"y\":" + (flagNull == 0 ? (YAXISDOUBLENUM>0?YAXISDOUBLENUM:YAXISNUM): null) +"}, ";
596 dataSeriesStrMap.put(dateStr, valueDataSeries);
599 valueDataSeries = "{ \"x\":\"" + dateStr + "\" , \"y\":" + (flagNull == 0 ? (YAXISDOUBLENUM>0?YAXISDOUBLENUM:YAXISNUM): null) +"}, ";
600 dataSeriesStrMap.put(dateStr, valueDataSeries);
606 dataSeriesOverAllMap.put(uniqueElements[j], dataSeriesStrMap);
608 if(!barRealTimeAxis) { // true - non-time
609 if(!dateStrList.contains(new Long(date.getTime()).toString())) {
610 dateStrList.add(new Long(date.getTime()).toString());
611 for (int k = 0; k < uniqueElements.length; k++) {
612 HashMap<String, String> dataMap = dataSeriesMap.get((String) uniqueElements[k]);
613 dataMap.put(date.getTime()+"", "null");
618 if(ds.getString(i, 2).equals(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1) ?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))) {
619 dateStrList.add(new Long(date.getTime()).toString());
621 YAXISNUM = Integer.parseInt(ds.getString(i, 3));
622 if(MAXDOUBLENUM < YAXISNUM)
623 MAXDOUBLENUM = YAXISNUM;
624 } catch (NumberFormatException ex) {
626 YAXISDOUBLENUM = Double.parseDouble(ds.getString(i, 3));
627 MAXNUMDECIMALPLACES = getNumberOfDecimalPlaces(YAXISDOUBLENUM);
628 if(MAXDOUBLENUM < YAXISDOUBLENUM)
629 MAXDOUBLENUM = YAXISDOUBLENUM;
630 } catch (NumberFormatException ex1) {
637 HashMap<String, String> dataMap = dataSeriesMap.get((String) uniqueElements[j]);
639 dataMap.put(date.getTime()+"", (flagNull == 0 ? (YAXISDOUBLENUM>0?new Double(Math.log10(YAXISDOUBLENUM)).toString():new Double(Math.log10(new Double(YAXISNUM>0?YAXISNUM:1).doubleValue())).toString()): "null"));
641 if(dataMap.containsKey(new String(""+date.getTime())) && dataMap.get(new String(""+date.getTime())).equals("null")) {
642 dataMap.remove(date.getTime());
644 dataMap.put(date.getTime()+"", (flagNull == 0 ? (YAXISDOUBLENUM>0?new Double(YAXISDOUBLENUM).toString():new Integer(YAXISNUM).toString()): "null"));
648 } else if (AppUtils.nvl(ds.getString(i, 2)).length()<=0) {
649 dateStrList.add(new Long(date.getTime()).toString());
650 HashMap<String, String> dataMap1 = null;
651 String uniqueElement1 = "";
652 for (int j1 = 0; j1 < uniqueElements.length; j1++) {
653 uniqueElement1 = (String)uniqueElements[j];
654 if(ds.getString(i, 2).equals(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement1.lastIndexOf("|") != -1) ?uniqueElement1.substring(0, uniqueElement1.lastIndexOf("|")):uniqueElement1))) {
655 dataMap1 = dataSeriesMap.get((String) uniqueElements[j1]);
656 if(!dataMap1.containsKey(new String(""+date.getTime())))
657 dataMap1.put(date.getTime()+"", "null");
665 for(int kI = 0; kI < uniqueElements.length; kI++) {
666 HashMap dataSeriesStrMap1 = (HashMap) dataSeriesOverAllMap.get(uniqueElements[kI]);
667 for (int kL = 0; kL < uniqueXAxisElements.length; kL++) {
668 if(dataSeriesStrMap1.containsKey(uniqueXAxisElements[kL])) {
669 ((StringBuffer) dataSeries.get(kI)).append ((String)dataSeriesStrMap1.get(uniqueXAxisElements[kL]));
671 ((StringBuffer) dataSeries.get(kI)).append ("{ \"x\":\"" + uniqueXAxisElements[kL] + "\" , \"y\": null }, ");
677 StringBuilder dateStrBuf = new StringBuilder("");
679 if(dateStrList.size()>0) {
680 SortedSet<String> s = Collections.synchronizedSortedSet(dateStrList);
681 Object[] dateElements = (Object[]) s.toArray();
684 /* if not date value */
686 for (int i = 0; i < dateElements.length; i++) {
687 dateStrBuf.append(dateElements[i]+",");
690 if(!barRealTimeAxis || (flagNoDate == 1)) { // non-time
691 for (int i = 0; i < dateElements.length; i++) {
692 dateStrBuf.append(dateElements[i]+",");
695 Long initialDate = Long.parseLong((String)dateElements[0]);
696 Long endDate = Long.parseLong((String) dateElements[dateElements.length-1]);
697 java.util.Date date1 = null;
699 date1 = new java.util.Date(initialDate.longValue());
700 dateStrBuf.append(initialDate+",");
701 sortSet.add(""+initialDate);
705 while ( initialDate <= endDate) {
706 date1 = new java.util.Date(initialDate.longValue());
707 if(formatFlag==HOURFLAG)
708 date1 = DateUtils.addHours(date1, 1);
709 else if(formatFlag==MINFLAG)
710 date1 = DateUtils.addMinutes(date1, 30);
711 else if (formatFlag == DAYFLAG)
712 date1 = DateUtils.addDays(date1, 1);
713 else if (formatFlag == MONTHFLAG)
714 date1 = DateUtils.addMonths(date1, 1);
715 else if (formatFlag == YEARFLAG)
716 date1 = DateUtils.addMonths(date1, 1);
717 initialDate = date1.getTime();
719 if(initialDate <= endDate) {
720 dateStrBuf.append(initialDate+",");
721 sortSet.add(""+initialDate);
726 dateStrBuf.deleteCharAt(dateStrBuf.length()-1);
730 //if(!barRealTimeAxis) { // false - non-time
731 Object[] dateAllElements = (Object[]) sortSet.toArray();
733 for (int i = 0; i < uniqueElements.length; i++) {
734 HashMap<String, String> dataMap = dataSeriesMap.get((String)uniqueElements[i]);
735 for (int j=0; j<dateAllElements.length;j++) {
736 //if(strBuf.toString().indexOf((String) dateAllElements[j]) == -1) {
737 if(!dataMap.containsKey((String) dateAllElements[j])) {
738 dataMap.put((String) dateAllElements[j], "null");
744 String valueStr = "";
745 for (int i = 0; i < uniqueElements.length; i++) {
746 HashMap<String, String> dataMap = dataSeriesMap.get((String)uniqueElements[i]);
747 Set<String> keySet = dataMap.keySet();
748 ArrayList<String> keySortedList = new ArrayList<>(new TreeSet<String>(keySet));
750 for (int k=0; k < keySortedList.size(); k++) {
751 valueStr = dataSeriesMap.get((String)uniqueElements[i]).get(keySortedList.get(k));
752 if(valueStr.equals("null"))
755 ((StringBuffer) dataSeries.get(i)).append ("{ \"x\":" + keySortedList.get(k) + " , \"y\":" + valueStr +"}, ");
761 for (int i = 0; i < uniqueElements.length; i++) {
762 ((StringBuffer) dataSeries.get(i)).deleteCharAt(((StringBuffer) dataSeries.get(i)).lastIndexOf(","));
763 if(i < (uniqueElements.length -1) ) {
764 ((StringBuffer) dataSeries.get(i)).append("] } , \n");
767 ((StringBuffer) dataSeries.get(i)).append("] } \n");
770 if(ds.getRowCount() > 0) {
771 for (int i = 0; i < uniqueElements.length; i++) {
772 wholeScript.append((StringBuffer)dataSeries.get(i));
777 wholeScript.append("]; \n");
779 //add global variable
780 wholeScript.append("var chart; \n");
781 //javascript to create Bar Chart
782 wholeScript.append("nv.addGraph(function() { \n");
783 if(horizontalBar /*&& flagNoDate == 1*/)
784 wholeScript.append(" chart = nv.models.multiBarHorizontalChart() \n");
785 else /*if (flagNoDate == 1)*/
786 wholeScript.append(" chart = nv.models.multiBarChart() \n");
788 wholeScript.append(" var chart = nv.models.multiBarTimeSeriesChart() \n");*/
790 wholeScript.append(" .margin({top: "+ topMargin +", right: "+ rightMargin +", bottom: "+ bottomMargin +", left: " + leftMargin +"}) \n");
792 wholeScript.append(" .showLegend(true) \n ");
794 wholeScript.append(" .showLegend(false) \n ");
796 if(!horizontalBar && barReduceXAxisLabels)
797 wholeScript.append(" .reduceXTicks(true) \n ");
798 else if (!horizontalBar) {
799 wholeScript.append(" .reduceXTicks(false) \n ");
800 //wholeScript.append(" chart.lines1.forceY(["+(nvl(reportRuntime.getRangeAxisLowerLimit()).length()<=0?"0":reportRuntime.getRangeAxisLowerLimit()) +", "+ (nvl(reportRuntime.getRangeAxisUpperLimit()).length()<=0?UPPER_RANGE:reportRuntime.getRangeAxisUpperLimit()) + "]); \n" +
801 double UPPER_RANGE = 0;
802 if(Math.ceil((MAXDOUBLENUM+(MAXDOUBLENUM*25/100))/100) * 100 >= 1) {
803 UPPER_RANGE = Math.ceil(MAXDOUBLENUM+(MAXDOUBLENUM*25/100));
804 } else UPPER_RANGE = 1;
805 wholeScript.append(" .forceY(["+(nvl(reportRuntime.getRangeAxisLowerLimit()).length()<=0?"0":reportRuntime.getRangeAxisLowerLimit()) +", "+ (nvl(reportRuntime.getRangeAxisUpperLimit()).length()<=0?UPPER_RANGE:reportRuntime.getRangeAxisUpperLimit()) + "])\n");
808 wholeScript.append(" .delay(0) \n ");
811 wholeScript.append(" .showControls(true) \n ");
812 } else if (!showControls){
813 wholeScript.append(" .showControls(false) \n ");
815 if(stacked && !logScale)
816 wholeScript.append(" .stacked(true)\n ");
817 else if(!stacked || logScale)
818 wholeScript.append(" .stacked(false)\n ");
820 wholeScript.append(" .logScale(true)\n ");
822 wholeScript.append(" .logScale(false)\n ");
825 if(AppUtils.nvl(reportRuntime.getLegendPosition()).length()>=0 && reportRuntime.getLegendPosition().equals("right")) {
826 wholeScript.append(" .legendPos('right')\n" );
828 wholeScript.append(" .legendPos('top')\n" );
830 if(uniqueElements.length <= 10) {
831 wholeScript.append(" .color(d3.scale.category10().range()); \n" +
833 } else if (uniqueElements.length <= 20) {
834 wholeScript.append(" .color(d3.scale.category50().range()); \n" +
837 wholeScript.append(" .color(d3.scale.category50().range()); \n" +
843 wholeScript.append(" .tickValues(["+ dateStrBuf.toString() + "])\n ");
845 wholeScript.append(" .tickValues(["+ dateStrBuf.toString() + "])\n ");
848 wholeScript.append(" .staggerLabels(true) \n");
850 wholeScript.append(" .staggerLabels(false) \n");
854 wholeScript.append(" .showMaxMin(true) \n ");
856 wholeScript.append(" .showMaxMin(false) \n ");
859 if(nvl(rotateLabels).length()>0) {
860 wholeScript.append(" .rotateLabels("+ rotateLabels+ ") \n ");
862 wholeScript.append(" .rotateLabels(\"0\") \n ");
864 wholeScript.append(" .axisLabel('" + legendColumnName + "')");
865 if(flagNoDate == 1 || !timeAxis) {
866 wholeScript.append(";\n");
868 wholeScript.append("\n .tickFormat(function(d) { \n");
870 if(formatFlag==HOURFLAG)
871 wholeScript.append(" return d3.time.format('%x %H')(new Date(d)) }); \n");
872 else if(formatFlag==MINFLAG)
873 wholeScript.append(" return d3.time.format('%x %H:%M')(new Date(d)) }); \n");
874 else if(formatFlag==SECFLAG)
875 wholeScript.append(" return d3.time.format('%X')(new Date(d)) }); \n");
876 else if(formatFlag==MONTHFLAG)
877 wholeScript.append(" return d3.time.format('%b %y')(new Date(d)) }); \n");
879 wholeScript.append(" return d3.time.format('%x')(new Date(d)) }); \n");
882 wholeScript.append(" return d; }); \n");
886 if(nvl(chartRightAxisLabel).length() > 0) {
887 //if(flagNoDate == 1)
888 wholeScript.append(" chart.yAxis\n");
890 // wholeScript.append(" chart.yAxis1\n");
892 wholeScript.append(" .logScale(true)\n ");
894 wholeScript.append(" .logScale(false)\n ");
897 wholeScript.append(" .axisLabel('" + chartLeftAxisLabel + "') \n" +
898 " .tickFormat(d3.format(',.0f')); \n");
899 /*" chart.yAxis2\n " +
900 " .axisLabel('" + chartRightAxisLabel + "') \n" +
901 " .tickFormat(d3.format(',.0f')); \n");*/
905 //if(flagNoDate == 1)
906 wholeScript.append(" chart.yAxis\n");
908 // wholeScript.append(" chart.yAxis1\n");
910 wholeScript.append(" .logScale(true)\n ");
912 wholeScript.append(" .logScale(false)\n ");
914 wholeScript.append(" .axisLabel('" + chartLeftAxisLabel + "') \n");
916 if(MAXDOUBLENUM <=5 && MAXNUMDECIMALPLACES == 0 )
917 MAXNUMDECIMALPLACES = 2;
918 if( MAXNUMDECIMALPLACES >=3 )
919 MAXNUMDECIMALPLACES = 2;
921 wholeScript.append(" .tickFormat(d3.format(',."+MAXNUMDECIMALPLACES+"f')); \n");
923 wholeScript.append(" .tickFormat(d3.format(',." + precision + "f')); \n");
924 //" .tickFormat(d3.format(',.0f')); \n");
926 wholeScript.append(" d3.select('#chart"+reportRuntime.getReportID()+" svg') \n" +
927 " .datum(historicalBarChart) \n" );
929 wholeScript.append(" .transition().duration(1000) \n" );
931 wholeScript.append(" .transition().duration(0) \n" );
932 wholeScript.append(" .call(chart); \n" +
933 "nv.utils.windowResize(chart.update); \n" +
936 wholeScript.append("function redraw() { \n");
937 //wholeScript.append(" nv.utils.windowResize(chart.update); \n");
938 wholeScript.append(" d3.select('#chart"+reportRuntime.getReportID()+" svg') \n") ;
939 wholeScript.append(" .datum(historicalBarChart) \n");
940 wholeScript.append(" .transition().duration(500) \n");
941 wholeScript.append(" .call(chart); \n");
942 wholeScript.append("} \n");
943 wholeScript.append("\n");
944 wholeScript.append(" setInterval(function () { \n");
945 wholeScript.append(" redraw(); \n");
946 wholeScript.append(" }, 1500) \n");
948 wholeScript.append("if(historicalBarChart.length <= 0 ) {\n");
949 wholeScript.append(" document.getElementById(\"chart"+reportRuntime.getReportID()+"\").innerHTML = \"<div id='noData'><b>No Data Available</b></div>\";\n");
950 wholeScript.append(" document.getElementById(\"chart"+reportRuntime.getReportID()+"\").className=\"nodatadiv\";\n");
951 wholeScript.append(" document.getElementById(\"nodata\").className=\"nodatainner\";\n");
952 wholeScript.append("}\n");
953 wholeScript.append("</script> </body></html> \n");
955 } else if (chartType.equals(AppConstants.GT_TIME_SERIES)) {
957 // get category if not give the column name for the data column use this to develop series.
958 boolean hasCategoryAxis = reportRuntime.hasSeriesColumn();
961 final int YEARFLAG = 1;
962 final int MONTHFLAG = 2;
963 final int DAYFLAG = 3;
964 final int HOURFLAG = 4;
965 final int MINFLAG = 5;
966 final int SECFLAG = 6;
967 final int MILLISECFLAG = 7;
968 final int DAYOFTHEWEEKFLAG = 8;
969 final int FLAGDATE = 9;
972 flag = hasCategoryAxis?1:0;
973 String uniqueElements [] = null;
974 //TreeSet ts = new TreeSet();
975 ArrayList ts = new ArrayList<String>();
976 HashMap<String, String> columnMap = new HashMap();
978 String dateStr = null;
979 java.util.Date date = null;
980 if( ds.getRowCount() > 0) {
981 dateStr = ds.getString(0, 1);
983 date = getDateFromDateStr(dateStr);
985 reportRuntime.setTimeAxis(true);
986 timeAxis = reportRuntime.isTimeAxis();
993 ArrayList<String> ts1 = new ArrayList();
994 ArrayList uniqueElementsList = new ArrayList();
995 Object uniqueXAxisElements[] = null;
996 String uniqueXAxisStr = "";
998 for (int i = 0; i < ds.getRowCount(); i++) {
999 uniqueXAxisStr = ds.getString(i, 0);
1000 ts1.add(uniqueXAxisStr);
1003 uniqueElementsList.addAll(ts1);
1004 uniqueXAxisElements = ts1.toArray();
1009 boolean hasCustomizedChartColor = false;
1011 StringBuffer catStr = new StringBuffer("");
1013 for (int i = 0; i < ds.getRowCount(); i++) {
1014 catStr = new StringBuffer("");
1015 catStr.append(ds.getString(i, 2));
1017 if(ds.getString(i, "chart_color")!=null) {
1018 color = ds.getString(i, "chart_color");
1019 hasCustomizedChartColor = true;
1020 catStr.append("|"+color);
1022 } catch (ArrayIndexOutOfBoundsException ex) {
1023 //System.out.println("No Chart Color");
1026 if(catStr.length()>0) {
1027 //duplicates are avoided
1028 if(!ts.contains(catStr.toString()))
1029 ts.add(catStr.toString());
1033 //Object uniqueElements [] = ts.toArray();
1034 //SortedSet s = Collections.synchronizedSortedSet(ts);
1035 //uniqueElements = (String[]) ts.toArray();
1036 DataColumnType dct = null;
1037 List yTextSeries = reportRuntime.getChartDisplayNamesList(AppConstants.CHART_ALL_COLUMNS, formValues);
1038 if(yTextSeries.size()==1) {
1039 for (Iterator iter = l.iterator(); iter.hasNext();) {
1040 dct = (DataColumnType) iter.next();
1041 //System.out.println(dct.getDisplayName() + " " + yText);
1042 if(!(nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND))) {
1043 if(nvl(chartLeftAxisLabel).length()<=0) {
1044 chartLeftAxisLabel = nvl(dct.getYAxis());
1045 chartLeftAxisLabel = (chartLeftAxisLabel.indexOf("|")!=-1)?chartLeftAxisLabel.substring(0,chartLeftAxisLabel.indexOf("|")):"";
1050 Object tempArray[] = ts.toArray();
1051 uniqueElements = Arrays.copyOf(tempArray, tempArray.length, String[].class);
1054 DataColumnType dct = null;
1056 List yTextSeries = reportRuntime.getChartDisplayNamesList(AppConstants.CHART_ALL_COLUMNS, formValues);
1057 //if(columnValuesList.size() == 1) {
1059 for (Iterator iter = l.iterator(); iter.hasNext();) {
1060 dct = (DataColumnType) iter.next();
1061 //System.out.println(dct.getDisplayName() + " " + yText);
1062 if(!(nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND))) {
1063 if(yTextSeries.contains((String)dct.getDisplayName())) {
1064 if(nvl(dct.getChartColor()).length()>0)
1065 hasCustomizedChartColor = true;
1066 if(hasCustomizedChartColor) {
1067 //duplicates are avoided
1068 if(!ts.contains(dct.getDisplayName()+"|"+nvl(dct.getChartColor())))
1069 ts.add(dct.getDisplayName()+"|"+nvl(dct.getChartColor()));
1071 //duplicates are avoided
1072 if(!ts.contains(dct.getDisplayName()))
1073 ts.add(dct.getDisplayName());
1075 if(nvl(chartLeftAxisLabel).length()<=0) {
1076 chartLeftAxisLabel = nvl(dct.getYAxis());
1077 chartLeftAxisLabel = (chartLeftAxisLabel.indexOf("|")!=-1)?chartLeftAxisLabel.substring(0,chartLeftAxisLabel.indexOf("|")):"";
1079 if(nvl(chartRightAxisLabel).length()>0) {
1080 String dctYAxis = nvl(dct.getYAxis());
1081 String yAxis = (dctYAxis.indexOf("|")!=-1)?dctYAxis.substring(0,dctYAxis.indexOf("|")):dctYAxis;
1082 if(chartRightAxisLabel.equals(yAxis)) {
1083 if(ts.contains(dct.getDisplayName())) {
1084 if(hasCustomizedChartColor) {
1085 ts.set(dctIndex, dct.getDisplayName()+"|R|"+nvl(dct.getChartColor()));
1087 ts.set(dctIndex, dct.getDisplayName()+"|R");
1092 columnMap.put(dct.getDisplayName(), dct.getColId());
1099 //SortedSet s = Collections.synchronizedSortedSet(ts);
1100 Object tempArray[] = ts.toArray();
1101 uniqueElements = Arrays.copyOf(tempArray, tempArray.length, String[].class);
1102 //uniqueElements = (String[]) ts.toArray();
1106 wholeScript.append("<!DOCTYPE html>\n");
1107 wholeScript.append("<html>\n");
1108 wholeScript.append("<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF8\">\n");
1109 wholeScript.append("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n");
1110 wholeScript.append("<link href=\""+ chartScriptsPath +"d3/css/nv.d3.css\" rel=\"stylesheet\" type=\"text/css\">\n");
1111 wholeScript.append("<style>\n " +
1113 " overflow-y:scroll; \n" +
1116 " font: 12px sans-serif; \n" +
1119 " display: block;\n" +
1121 " #chart"+reportRuntime.getReportID()+" svg { \n" +
1122 " height: "+ (nvl(height).length()>0?(height.endsWith("px")?height:height+"px"):"420px") + "; \n" +
1123 " width: "+ (nvl(width).length()>0?(width.endsWith("px")?width:width+"px"):"700px") + "; \n" +
1124 " min-width: 100px; \n" +
1125 " min-height: 100px; \n" +
1127 " tr.z-row-over > td.z-row-inner, tr.z-row-over > .z-cell {" +
1128 " background-color: rgb(255, 255, 255); "+
1130 wholeScript.append(".nodatadiv {\n");
1131 wholeScript.append(" display: table-cell;\n");
1132 wholeScript.append(" width: 700px;\n");
1133 wholeScript.append(" height:370px;\n");
1134 wholeScript.append(" text-align:center;\n");
1135 wholeScript.append(" vertical-align: middle;\n");
1136 wholeScript.append("}\n");
1137 wholeScript.append(".nodatainner {\n");
1138 wholeScript.append(" padding: 10px;\n");
1139 wholeScript.append("}\n");
1141 wholeScript.append(" </style> \n" );
1143 wholeScript.append("<body> \n");
1146 wholeScript.append("<div align=\"center\"><H3>" + title +"</H3></div>");
1149 wholeScript.append("<div id=\"chart"+reportRuntime.getReportID()+"\"> <svg></svg> </div> \n");
1151 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/d3.v3.min.js\"></script>\n");
1152 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/nv.d3.min.js\"></script> \n");
1153 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/models/axis.min.js\"></script> \n");
1154 //wholeScript.append("<script src=\""+ AppUtils.getBaseFolderURL() +"d3/js/models/cumulativeLineChart.js\"></script> \n");
1155 //if(multipleSeries)
1156 //wholeScript.append("<script src=\""+ AppUtils.getBaseFolderURL() +"d3/js/models/multiChart.js\"></script> \n");
1159 wholeScript.append("<script> \n");
1161 wholeScript.append("historicalBarChart = [ \n");
1162 //wholeScript.append("{ \n");
1163 ArrayList dataSeries = new ArrayList();
1164 String uniqueElement = "";
1166 String [] uniqueRevElements = null;
1167 //Added to make sure order appears same as legend
1168 /*if(nvl(subType).length() > 0 && subType.equals("area")) {
1169 uniqueRevElements = reverse((String[])uniqueElements);
1171 uniqueRevElements = (String[])uniqueElements;
1174 int RIGHTAXISSERIES = 0;
1175 for (int i = 0; i < uniqueRevElements.length; i++) {
1176 //element.substring(element.indexOf("|")+1)
1177 uniqueElement = (String)uniqueRevElements[i];
1178 if(multipleSeries && (nvl(chartRightAxisLabel).length() > 0)) {
1179 if(nvl(subType).length() > 0 && subType.equals("area")) {
1180 if(nvl(uniqueElement).indexOf("|R") !=-1)
1181 dataSeries.add(new StringBuffer(" { \"type\":\"line\", \"key\": \""+ ((uniqueElement.indexOf("|") != -1)?uniqueElement.substring(0, uniqueElement.indexOf("|")):uniqueElement) +"\", \"yAxis\": \""+(2)+"\", "+ (hasCustomizedChartColor && (uniqueElement.lastIndexOf("|") != -1) ?("\"color\": \""+uniqueElement.substring(uniqueElement.lastIndexOf("|")+1) + "\","):"")+" \"values\": ["));
1183 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\": ["));
1185 if(nvl(uniqueElement).indexOf("|R") !=-1)
1186 dataSeries.add(new StringBuffer(" { \"type\":\"line\", \"key\": \""+ ((uniqueElement.indexOf("|") != -1)?uniqueElement.substring(0, uniqueElement.indexOf("|")):uniqueElement) +"\", \"yAxis\": \""+(2)+"\","+ (hasCustomizedChartColor && (uniqueElement.lastIndexOf("|") != -1) ?("\"color\": \""+uniqueElement.substring(uniqueElement.lastIndexOf("|")+1) + "\","):"")+" \"values\": ["));
1188 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\": ["));
1190 RIGHTAXISSERIES = dataSeries.size()-1;
1191 //dataSeries.add(new StringBuffer(" { \"type\":\"line\", \"key\": \""+ ((DataColumnType)columnMap.get(i)).getDisplayName() +"\", \"yAxis\": \""+(i+1)+"\", \"values\": ["));
1194 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\": ["));
1200 double MAXDOUBLENUM = 0.0;
1202 double YAXISDOUBLENUM = 0.0;
1203 int MAXNUMDECIMALPLACES = 0;
1205 int flagSecondNull = 0;
1206 TreeSet dateList = new TreeSet();
1209 for (int j = 0; j < uniqueRevElements.length; j++) {
1210 for (int i = 0; i < ds.getRowCount(); i++) {
1214 YAXISDOUBLENUM = 0.0;
1217 dateStr = ds.getString(i, 1);
1219 date = getDateFromDateStr(dateStr);
1220 formatFlag = getFlagFromDateStr(dateStr);
1222 if(date==null && timeAxis)
1226 //if(ds.getString(i, 2).equals(uniqueElements[j])) {
1227 //if(minTime > date.getTime())
1228 // minTime = date.getTime();
1229 uniqueElement = (String)uniqueRevElements[j];
1231 YAXISNUM = Integer.parseInt(ds.getString(i, columnMap.get(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1)?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))));
1232 if(MAXDOUBLENUM < YAXISNUM)
1233 MAXDOUBLENUM = YAXISNUM;
1234 } catch (NumberFormatException ex) {
1236 YAXISDOUBLENUM = Double.parseDouble(ds.getString(i, columnMap.get(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1) ?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))));
1237 if(RIGHTAXISSERIES!=j) {
1238 MAXNUMDECIMALPLACES = getNumberOfDecimalPlaces(YAXISDOUBLENUM);
1239 if(MAXDOUBLENUM < YAXISDOUBLENUM)
1240 MAXDOUBLENUM = YAXISDOUBLENUM;
1242 } catch (NumberFormatException ex1) {
1248 dateList.add(dateStr);
1249 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":\"" + dateStr + "\" , \"y\":" + (flagNull==0?(YAXISDOUBLENUM>0?YAXISDOUBLENUM:YAXISNUM):null) +"}, ");
1251 dateList.add(new Long(date.getTime()).toString());
1252 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime() + " , \"y\":" + (flagNull==0?(YAXISDOUBLENUM>0?YAXISDOUBLENUM:YAXISNUM):null) +"}, ");
1257 if(nvl(subType).length() > 0 && subType.equals("area")) {
1260 if(i<ds.getRowCount()-1) {
1262 YAXISNUM = Integer.parseInt(ds.getString(i+1, columnMap.get(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1)?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))));
1263 if(MAXDOUBLENUM < YAXISNUM)
1264 MAXDOUBLENUM = YAXISNUM;
1265 } catch (NumberFormatException ex) {
1267 YAXISDOUBLENUM = Double.parseDouble(ds.getString(i+1, columnMap.get(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1) ?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))));
1268 if(RIGHTAXISSERIES!=j) {
1269 MAXNUMDECIMALPLACES = getNumberOfDecimalPlaces(YAXISDOUBLENUM);
1270 if(MAXDOUBLENUM < YAXISDOUBLENUM)
1271 MAXDOUBLENUM = YAXISDOUBLENUM;
1273 } catch (NumberFormatException ex1) {
1278 if(flagSecondNull==1 && date == null) {
1279 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":\"" + dateStr + "\" , \"y\":" + null +"}, ");
1280 } else if( flagSecondNull == 1){
1281 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime() + " , \"y\":" + null +"}, ");
1285 if(i<ds.getRowCount()-1) {
1286 dateStr = ds.getString(i+1, 1);
1289 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":\"" + dateStr + "\" , \"y\":" + null +"}, ");
1291 date = getDateFromDateStr(dateStr);
1292 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime() + " , \"y\":" + null +"}, ");
1294 //((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime() + " , \"y\":" + null +"}, ");
1303 //((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + minTime + " , \"y\":" + 0 +"}, ");
1307 for (int j = 0; j < uniqueRevElements.length; j++) {
1308 for (int i = 0; i < ds.getRowCount(); i++) {
1310 YAXISDOUBLENUM = 0.0;
1313 dateStr = ds.getString(i, 1);
1315 date = getDateFromDateStr(dateStr);
1316 formatFlag = getFlagFromDateStr(dateStr);
1319 if(date==null && timeAxis)
1322 uniqueElement = (String)uniqueRevElements[j];
1323 //date = MMDDYYYYFormat.parse(ds.getString(i, 1), new ParsePosition(0));
1324 if(ds.getString(i, 2).equals(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1) ?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))) {
1325 //if(minTime > date.getTime())
1326 // minTime = date.getTime();
1328 YAXISNUM = Integer.parseInt(ds.getString(i, 3));
1329 if(MAXDOUBLENUM < YAXISNUM)
1330 MAXDOUBLENUM = YAXISNUM;
1331 } catch (NumberFormatException ex) {
1333 YAXISDOUBLENUM = Double.parseDouble(ds.getString(i, 3));
1334 if(RIGHTAXISSERIES!=j) {
1335 MAXNUMDECIMALPLACES = getNumberOfDecimalPlaces(YAXISDOUBLENUM);
1336 if(MAXDOUBLENUM < YAXISDOUBLENUM)
1337 MAXDOUBLENUM = YAXISDOUBLENUM;
1340 } catch (NumberFormatException ex1) {
1346 dateList.add(dateStr);
1347 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + dateStr + " , \"y\":" + (flagNull==0?(YAXISDOUBLENUM!=0.0?YAXISDOUBLENUM:YAXISNUM):null) +"}, ");
1349 dateList.add(new Long(date.getTime()).toString());
1350 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime() + " , \"y\":" + (flagNull==0?(YAXISDOUBLENUM!=0.0?YAXISDOUBLENUM:YAXISNUM):null) +"}, ");
1354 if(nvl(subType).length() > 0 && subType.equals("area")) {
1357 if(i<ds.getRowCount()-1) {
1358 for (int k = i+1; k < ds.getRowCount(); k++) {
1359 if (ds.getString(k, 2).equals(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1) ?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))) {
1361 YAXISNUM = Integer.parseInt(ds.getString(k, 3));
1362 if(MAXDOUBLENUM < YAXISNUM)
1363 MAXDOUBLENUM = YAXISNUM;
1364 } catch (NumberFormatException ex) {
1366 YAXISDOUBLENUM = Double.parseDouble(ds.getString(k, 3));
1367 if(RIGHTAXISSERIES!=j) {
1368 MAXNUMDECIMALPLACES = getNumberOfDecimalPlaces(YAXISDOUBLENUM);
1369 if(MAXDOUBLENUM < YAXISDOUBLENUM)
1370 MAXDOUBLENUM = YAXISDOUBLENUM;
1372 } catch (NumberFormatException ex1) {
1380 if(date==null && flagSecondNull==1){
1381 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + dateStr + " , \"y\":" + null +"}, ");
1382 } else if(flagSecondNull == 1){
1383 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime() + " , \"y\":" + null +"}, ");
1388 if(i<ds.getRowCount()-1) {
1389 for (int k = i+1; k < ds.getRowCount(); k++) {
1390 if (ds.getString(k, 2).equals(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1) ?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))) {
1391 dateStr = ds.getString(k, 1);
1393 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime() + " , \"y\":" + null +"}, ");
1396 date = getDateFromDateStr(dateStr);
1397 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime() + " , \"y\":" + null +"}, ");
1412 for (int i = 0; i < uniqueRevElements.length; i++) {
1413 StringBuffer strBuf = ((StringBuffer) dataSeries.get(i));
1414 ((StringBuffer) dataSeries.get(i)).deleteCharAt(((StringBuffer) dataSeries.get(i)).lastIndexOf(","));
1415 if(i < (uniqueRevElements.length -1) ) {
1416 ((StringBuffer) dataSeries.get(i)).append("] } , \n");
1419 ((StringBuffer) dataSeries.get(i)).append("] } \n");
1423 for (int i = 0; i < uniqueRevElements.length; i++) {
1424 wholeScript.append((StringBuffer)dataSeries.get(i));
1427 wholeScript.append("];\n");
1429 /* Sorting is commented out.*/
1430 StringBuffer dateStrBuf = new StringBuffer("");
1431 if(dateList.size()>0) {
1432 //SortedSet<String> s = Collections.synchronizedSortedSet(dateList);
1433 Object[] dateElements = (Object[]) dateList.toArray();
1435 String element = "";
1437 for (int i = 0; i < dateElements.length; i++) {
1438 dateStrBuf.append(dateElements[i]+",");
1440 dateStrBuf.deleteCharAt(dateStrBuf.length()-1);
1443 wholeScript.append(" var chart;\n");
1444 wholeScript.append("nv.addGraph(function() { \n");
1445 //" var chart = nv.models.cumulativeLineChart() \n" + nv.models.lineWithFocusChart()
1446 // " chart = nv.models.lineChart() \n" +
1447 if(nvl(subType).length() > 0 && subType.equals("area")) {
1448 wholeScript.append(" chart = nv.models.stackedAreaChart() \n");
1450 wholeScript.append(" .showControls(true) \n ");
1452 wholeScript.append(" .showControls(false) \n ");
1455 wholeScript.append(" chart = nv.models.multiChart() \n");
1456 if(nvl(chartRightAxisLabel).length() > 0) {
1457 wholeScript.append(" .dualaxis(true) \n ");
1459 wholeScript.append(" .dualaxis(false) \n ");
1462 if(AppUtils.nvl(reportRuntime.getLegendPosition()).length()>=0 && reportRuntime.getLegendPosition().equals("right")) {
1463 wholeScript.append(" .legendPos('right')\n" );
1465 wholeScript.append(" .legendPos('top')\n" );
1471 wholeScript.append(" .margin({top: "+ topMargin +", right: "+ rightMargin +", bottom: "+ bottomMargin +", left: " + leftMargin +"}) \n");
1473 wholeScript.append(" .showLegend(true) \n ");
1475 wholeScript.append(" .showLegend(false) \n ");
1478 if(nvl(subType).length() > 0 && subType.equals("area")) {
1479 if( MAXNUMDECIMALPLACES >=3 ) {
1480 wholeScript.append(" .yAxisTooltipFormat(d3.format(',.3f')) \n");
1482 wholeScript.append(" .yAxisTooltipFormat(d3.format(',."+MAXNUMDECIMALPLACES+ "f')) \n");
1485 wholeScript.append(".x (function(d) {return d.x;}) \n" +
1486 ".y (function(d) {return d.y;}) \n");
1489 //" .x(function(d) { return d[0] }) \n" +
1490 //" .y(function(d) { return d[1] }) \n" +
1491 //" .forceY("+(nvl(reportRuntime.getRangeAxisLowerLimit()).length()<=0?"0":reportRuntime.getRangeAxisLowerLimit()) +", "+ Math.ceil((MAXNUM+(MAXNUM*25/100))/100) * 100 + ") \n" + // reportRuntime.getRangeAxisUpperLimit()+") \n" +
1492 wholeScript.append(" .color(d3.scale.category10().range()); \n");
1493 if(!(nvl(subType).length() > 0 && subType.equals("area"))) {
1494 double UPPER_RANGE = 0;
1495 if(Math.ceil((MAXDOUBLENUM+(MAXDOUBLENUM*25/100))/100) * 100 >= 1) {
1496 UPPER_RANGE = Math.ceil(MAXDOUBLENUM+(MAXDOUBLENUM*25/100));
1497 } else UPPER_RANGE = 1;
1499 wholeScript.append(" chart.lines1.forceY(["+(nvl(reportRuntime.getRangeAxisLowerLimit()).length()<=0?"0":reportRuntime.getRangeAxisLowerLimit()) +", "+ (nvl(reportRuntime.getRangeAxisUpperLimit()).length()<=0?UPPER_RANGE:reportRuntime.getRangeAxisUpperLimit()) + "]); \n" +
1500 " chart.lines2.forceY([0,1]); \n");
1502 wholeScript.append(" chart.xAxis\n");
1503 if(reportRuntime.isShowXaxisLabel()) {
1504 // X axis label is commented for time-being. This should be derived from request parameter.
1505 //" .axisLabel('" + legendColumnName + "') \n" +
1506 wholeScript.append(" .axisLabel('" + legendColumnName + "') \n");
1508 wholeScript.append(" .axisLabel('') \n");
1510 if(reportRuntime.isAddXAxisTickers()) {
1511 wholeScript.append(" .tickValues(["+ dateStrBuf.toString()+ "])\n ");
1513 //wholeScript.append(" .tickValues([])\n ");
1516 wholeScript.append(" .staggerLabels(true) \n");
1518 wholeScript.append(" .staggerLabels(false) \n");
1521 wholeScript.append(" .showMaxMin(true) \n ");
1523 wholeScript.append(" .showMaxMin(false) \n ");
1526 if(nvl(rotateLabels).length()>0) {
1527 wholeScript.append(" .rotateLabels("+ rotateLabels+ ") \n ");
1529 wholeScript.append(" .rotateLabels(\"0\") \n ");
1532 wholeScript.append(" .tickFormat(function(d) { \n");
1533 wholeScript.append(" var local_dt = new Date(); \n var utc = d + (local_dt.getTimezoneOffset() * 60000);\n");
1534 wholeScript.append(" var nd = new Date(utc + (3600000*"+getCurrentTimezoneOffset()+")); ");
1536 if(formatFlag==DAYFLAG)
1537 wholeScript.append(" return d3.time.format('%m/%d/%Y')(new Date(d)) }); \n");
1538 else if(formatFlag==HOURFLAG)
1539 wholeScript.append(" return d3.time.format('%x %H')(new Date(d)) }); \n");
1540 else if(formatFlag==MINFLAG)
1541 wholeScript.append(" return d3.time.format('%x %H:%M')(new Date(d)) }); \n");
1542 else if(formatFlag==SECFLAG)
1543 wholeScript.append(" return d3.time.format('%x %X')(new Date(d)) }); \n");
1544 else if(formatFlag==MONTHFLAG)
1545 wholeScript.append(" return d3.time.format('%b %y')(new Date(d)) }); \n");
1548 wholeScript.append(" return d3.time.format('%x')(new Date(d)) }); \n");
1550 wholeScript.append(" return d; }); \n");
1551 if(nvl(chartRightAxisLabel).length() > 0) {
1552 if(nvl(subType).length() > 0 && subType.equals("area")) {
1553 wholeScript.append(" chart.yAxis\n");
1555 wholeScript.append(" chart.yAxis1\n");
1557 wholeScript.append(" .axisLabel('" + chartLeftAxisLabel + "') \n");
1558 //if(nvl(subType).length() > 0 && subType.equals("area")) {
1559 if(MAXDOUBLENUM <=5 && MAXNUMDECIMALPLACES == 0 )
1560 MAXNUMDECIMALPLACES = 2;
1561 if( MAXNUMDECIMALPLACES >=3 )
1562 MAXNUMDECIMALPLACES = 2;
1563 wholeScript.append(" .tickFormat(d3.format(',."+MAXNUMDECIMALPLACES+"f')); \n");
1565 wholeScript.append(" .tickFormat(d3.format(',.2f')); \n");
1567 // " .tickFormat(function (d) {return d;} ); \n");
1568 //" .tickFormat(function(d) {if (d >= 1000) return Math.round(d/1000)+\"K\"; else return d;}); \n");
1569 if(!(nvl(subType).length() > 0 && subType.equals("area"))) {
1570 wholeScript.append(" chart.yAxis2\n " +
1571 " .axisLabel('" + chartRightAxisLabel + "') \n" +
1572 " .tickFormat(d3.format(',.02f')); \n");
1573 //" .tickFormat(function(d) {if (d >= 1000) return Math.round(d/1000)+\"K\"; else return d;}); \n");
1574 //" .tickFormat(function(d) {if( d <= 1) return Math.round(d*100)+\"%\"; else return d;}); \n");
1575 // " .tickFormat(function(d) { return d;}); \n");
1580 if(nvl(subType).length() > 0 && subType.equals("area")) {
1581 wholeScript.append(" chart.yAxis\n");
1583 wholeScript.append(" chart.yAxis1\n");
1585 wholeScript.append(" .axisLabel('" + chartLeftAxisLabel + "') \n");
1586 //if(nvl(subType).length() > 0 && subType.equals("area")) {
1587 if(MAXDOUBLENUM <=5 && MAXNUMDECIMALPLACES == 0 )
1588 MAXNUMDECIMALPLACES = 2;
1589 if( MAXNUMDECIMALPLACES >=3 ) {
1590 MAXNUMDECIMALPLACES = 2;
1592 wholeScript.append(" .tickFormat(d3.format(',."+MAXNUMDECIMALPLACES+"f')); \n");
1594 wholeScript.append(" .tickFormat(d3.format(',.2f')); \n");
1596 //" .tickFormat(function(d) {if (d >= 1000) return Math.round(d/1000)+\"K\"; else return d;}); \n");
1598 wholeScript.append(" d3.select('#chart"+reportRuntime.getReportID()+" svg') \n" +
1599 " .datum(historicalBarChart) \n" );
1601 wholeScript.append(" .transition().duration(1000) \n" );
1602 wholeScript.append(" .call(chart); \n" +
1603 "nv.utils.windowResize(chart.update); \n" +
1604 "return chart; \n" +
1607 wholeScript.append("function redraw() { \n");
1608 //wholeScript.append(" nv.utils.windowResize(chart.update); \n");
1609 wholeScript.append(" d3.select('#chart"+reportRuntime.getReportID()+" svg') \n") ;
1610 wholeScript.append(" .datum(historicalBarChart) \n");
1611 wholeScript.append(" .transition().duration(500) \n");
1612 wholeScript.append(" .call(chart); \n");
1613 wholeScript.append("} \n");
1614 wholeScript.append("\n");
1615 wholeScript.append(" setInterval(function () { \n");
1616 wholeScript.append(" redraw(); \n");
1617 wholeScript.append(" }, 1500) \n");
1619 wholeScript.append("if(historicalBarChart.length <= 0 ) {\n");
1620 wholeScript.append(" document.getElementById(\"chart"+reportRuntime.getReportID()+"\").innerHTML = \"<div id='noData'><b>No Data Available</b></div>\";\n");
1621 wholeScript.append(" document.getElementById(\"chart"+reportRuntime.getReportID()+"\").className=\"nodatadiv\";\n");
1622 wholeScript.append(" document.getElementById(\"nodata\").className=\"nodatainner\";\n");
1623 wholeScript.append("}\n");
1625 wholeScript.append("</script> </body> </html> \n");
1627 } else if (chartType.equals(AppConstants.GT_PIE) || chartType.equals(AppConstants.GT_PIE_3D)) {
1628 wholeScript.append("<!DOCTYPE html>\n");
1629 wholeScript.append("<html>\n");
1630 wholeScript.append("<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF8\">\n");
1631 wholeScript.append("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n");
1632 wholeScript.append("<link href=\""+ AppUtils.getBaseFolderURL() +"d3/css/nv.d3.css\" rel=\"stylesheet\" type=\"text/css\">\n");
1633 wholeScript.append("<style>\n " +
1635 " overflow-y:scroll; \n" +
1638 " font: 12px sans-serif; \n" +
1640 " tr.z-row-over > td.z-row-inner, tr.z-row-over > .z-cell {" +
1641 " background-color: rgb(255, 255, 255); "+
1643 " svg { display: block; } " +
1644 " #chart"+reportRuntime.getReportID()+" svg { \n" +
1645 " height: "+ (nvl(height).length()>0?(height.endsWith("px")?height:height+"px"):"420px") + "; \n" +
1646 " width: "+ (nvl(width).length()>0?(width.endsWith("px")?width:width+"px"):"700px") + "; \n" +
1647 " min-width: 100px; \n" +
1648 " min-height: 100px; \n" +
1651 wholeScript.append("<body> \n");
1654 wholeScript.append("<div align=\"center\"><H3>" + title +"</H3></div>");
1656 wholeScript.append("<div id=\"chart"+reportRuntime.getReportID()+"\"><svg></svg></div>");
1657 //"<svg id=\"test2\"></svg>\n");
1659 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/d3.v3.min.js\"></script>\n");
1660 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/nv.d3.min.js\"></script> \n");
1661 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/models/legend.js\"></script> \n");
1662 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/models/pie.js\"></script> \n");
1663 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/models/pieChart.js\"></script> \n");
1664 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/utils.js\"></script> \n");
1665 wholeScript.append("<script> \n");
1667 wholeScript.append("historicalBarChart = [ \n");
1672 TreeSet<String> colorList = new TreeSet<>();
1673 for (int i = 0; i < ds.getRowCount(); i++) {
1676 value = Double.parseDouble(ds.getString(i, 2));
1677 total = total+value;
1678 } catch (NumberFormatException ex) {
1681 String key = ds.getString(i, 0);
1683 if(ds.getString(i, "chart_color")!=null) {
1684 colorList.add(key+"|"+ds.getString(i, "chart_color"));
1686 } catch (ArrayIndexOutOfBoundsException ex) {
1687 //System.out.println("No Chart Color");
1689 wholeScript.append("{ \""+ "key" +"\":\""+ key+"\", \""+ "y" +"\":"+value+"}, \n");
1692 StringBuffer color = new StringBuffer("");
1693 if(colorList.size()>0) {
1694 SortedSet<String> s = Collections.synchronizedSortedSet(colorList);
1695 Object[] colorElements = (Object[]) s.toArray();
1697 String element = "";
1699 for (int i = 0; i < colorElements.length; i++) {
1700 element = ((String)colorElements[i]);
1701 color.append("'"+element.substring(element.lastIndexOf("|")+1)+"',");
1703 color.deleteCharAt(color.length()-1);
1706 wholeScript.append("];\n");
1709 wholeScript.append("var chart; \n");
1710 wholeScript.append("nv.addGraph(function() { \n" +
1711 " var width1= 700, height1=720; \n" +
1712 " chart = nv.models.pieChart() \n" +
1713 " .margin({top: "+ topMargin +", right: "+ rightMargin +", bottom: "+ bottomMargin +", left: " + leftMargin +"}) \n" +
1715 //" .x(function(d) { return d.key +\" \"+ Math.round(d.y/"+TOTAL+" *100) + \"%\" }) \n" +
1716 " .x(function(d) { return d.key }) \n" +
1717 " .y(function(d) { return d.y }) \n");
1718 if(colorList.size()>0) {
1719 wholeScript.append(" .color(["+ color.toString() + "] ) \n");
1721 //wholeScript.append(" .values(function(d) { return d }) \n");
1722 //" .color(d3.scale.category10().range()); \n" +
1724 wholeScript.append(" chart.showLegend(true);\n ");
1726 wholeScript.append(" chart.showLegend(false);\n ");
1729 //wholeScript.append("chart.showLegend(false);\n" +
1730 //" .width(width1) \n" +
1731 //" .height(height1); \n" +
1732 wholeScript.append(" d3.select('#chart"+reportRuntime.getReportID()+" svg') \n" +
1733 " .datum(historicalBarChart) \n");
1735 wholeScript.append(" .transition().duration(1200) \n" );
1736 /* " .attr(\"width\", width1) \n" +
1737 " .attr(\"height\", height1) \n" +
1738 */ wholeScript.append(" .call(chart); \n" +
1739 " nv.utils.windowResize(chart.update);\n"+
1740 "return chart; \n" +
1743 wholeScript.append("function redraw() { \n");
1744 //wholeScript.append(" nv.utils.windowResize(chart.update); \n");
1745 wholeScript.append(" d3.select('#chart"+reportRuntime.getReportID()+" svg') \n") ;
1746 wholeScript.append(" .datum(historicalBarChart) \n");
1747 wholeScript.append(" .transition().duration(500) \n");
1748 wholeScript.append(" .call(chart); \n");
1749 wholeScript.append("} \n");
1750 wholeScript.append("\n");
1751 wholeScript.append(" setInterval(function () { \n");
1752 wholeScript.append(" redraw(); \n");
1753 wholeScript.append(" }, 1500) \n");
1757 wholeScript.append("if(historicalBarChart.length <= 0 ) {\n");
1758 wholeScript.append(" document.getElementById(\"chart"+reportRuntime.getReportID()+"\").innerHTML = \"<div id='noData'><b>No Data Available</b></div>\";\n");
1759 wholeScript.append(" document.getElementById(\"chart"+reportRuntime.getReportID()+"\").className=\"nodatadiv\";\n");
1760 wholeScript.append(" document.getElementById(\"nodata\").className=\"nodatainner\";\n");
1761 wholeScript.append("}\n");
1763 wholeScript.append("</script> </body> </html> \n");
1765 } else if (chartType.equals(AppConstants.GT_ANNOTATION_CHART) || chartType.equals(AppConstants.GT_FLEX_TIME_CHARTS)) {
1767 boolean timeCharts = chartType.equals(AppConstants.GT_FLEX_TIME_CHARTS);
1769 String dateStr = null;
1770 java.util.Date date = null;
1772 final int YEARFLAG = 1;
1773 final int MONTHFLAG = 2;
1774 final int DAYFLAG = 3;
1775 final int HOURFLAG = 4;
1776 final int MINFLAG = 5;
1777 final int SECFLAG = 6;
1778 final int MILLISECFLAG = 7;
1779 final int DAYOFTHEWEEKFLAG = 8;
1780 final int FLAGDATE = 9;
1788 double YAXISDOUBLENUM = 0.0;
1789 double MAXDOUBLENUM = 0.0;
1790 int MAXNUMDECIMALPLACES = 0;
1794 TreeSet<String> dateStrList = new TreeSet<>();
1795 // added to store all date elements
1796 SortedSet<String> sortSet = new TreeSet<>();
1800 boolean hasCategoryAxis = reportRuntime.hasSeriesColumn();
1801 flag = hasCategoryAxis?1:0;
1804 String anomalyText = "";
1806 StringBuffer dataStrBuf = new StringBuffer("");
1807 StringBuffer annotationsStrBuf = new StringBuffer("");
1809 String xAxisLabel = (reportRuntime.getChartLegendColumn()!=null)?reportRuntime.getChartLegendColumn().getDisplayName():"";
1811 //finding actual string
1812 String actualText = "";
1813 DataColumnType dct = null;
1814 for (Iterator iter = l.iterator(); iter.hasNext();) {
1815 dct = (DataColumnType) iter.next();
1816 if((dct.getChartSeq()!=null && dct.getChartSeq() >=0) && !AppUtils.nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND)) {
1817 //if(AppUtils.nvl(dct.getDisplayName()).toLowerCase().contains("actual")) {
1818 actualText = dct.getDisplayName();
1825 int columnIndex = 1;
1826 ArrayList columnNames = new ArrayList();
1827 ArrayList columnValues = new ArrayList();
1829 String columnName = "";
1830 String columnValue = "";
1833 StringBuffer seriesBuffer = new StringBuffer("");
1835 for (int i = 0; i < ds.getRowCount(); i++) {
1836 columnNames = new ArrayList();
1837 columnValues = new ArrayList();
1842 dateStr = ds.getString(i, 0);
1843 date = getDateFromDateStr(dateStr);
1844 if(date.getTime() > maxDate )
1845 maxDate = date.getTime();
1847 formatFlag = getFlagFromDateStr(dateStr);
1850 for (;columnIndex<ds.getColumnCount();columnIndex++) {
1851 columnName = ds.getColumnName(columnIndex);
1852 if(!timeCharts && !columnName.toLowerCase().equals("anomaly_text")) {
1853 columnNames.add(columnName);
1854 columnValues.add(AppUtils.nvls(ds.getString(i, columnIndex), "null"));
1855 } else if (timeCharts) {
1856 columnNames.add(columnName);
1857 columnValues.add(AppUtils.nvls(ds.getString(i, columnIndex), "null"));
1861 anomalyText = ds.getString(i, "anomaly_text");
1862 //dataStrBuf.append(" [new Date(moment(\""+dateStr+"\")),"+ actual /*+","+ forecast*/+","+ lowerBound +","+ upperBound +"],\n");
1863 dataStrBuf.append(" [new Date(moment(\""+dateStr+"\"))");
1864 for(int c=0; c< columnNames.size(); c++ ) {
1865 columnName = (String) columnNames.get(c);
1866 columnValue = (String) columnValues.get(c);
1867 for (Iterator iter1 = l.iterator(); iter1.hasNext();) {
1868 dct = (DataColumnType) iter1.next();
1869 if((dct.getChartSeq()!=null && dct.getChartSeq() >=0) && !AppUtils.nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND)) {
1870 if((!timeCharts && !AppUtils.nvl(dct.getColId()).toLowerCase().equals("anomaly_text")) && AppUtils.nvl(dct.getColId()).toLowerCase().equals(columnName.toLowerCase())) {
1871 dataStrBuf.append(","+columnValue);
1873 } else if(timeCharts && AppUtils.nvl(dct.getColId()).toLowerCase().equals(columnName.toLowerCase())){
1874 dataStrBuf.append(","+columnValue);
1881 dataStrBuf.append("],\n");
1883 if(AppUtils.nvl(anomalyText).length()>0) {
1885 annotationsStrBuf.append("anns.push( {\n");
1886 annotationsStrBuf.append(" series: '"+actualText+"',\n");
1887 annotationsStrBuf.append(" x: moment(\""+dateStr+"\"),\n");
1888 annotationsStrBuf.append(" shortText: '"+ IntToLetter(anomalyRec).toUpperCase() +"',\n");
1889 annotationsStrBuf.append(" text: '"+ anomalyText + "'\n");
1890 annotationsStrBuf.append("});\n");
1898 minDate = maxDate - (new Long(reportRuntime.getZoomIn()).longValue()*60*60*1000);
1899 System.out.println(new java.util.Date(maxDate) + " " + new java.util.Date(minDate) + " " + reportRuntime.getZoomIn());
1900 if(dataStrBuf.lastIndexOf(",")!= -1)
1901 dataStrBuf.deleteCharAt(dataStrBuf.lastIndexOf(","));
1903 wholeScript = new StringBuilder("");
1904 wholeScript.append("<!DOCTYPE html>\n");
1905 wholeScript.append("<html>\n");
1906 wholeScript.append(" <head>\n");
1907 wholeScript.append("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n");
1908 wholeScript.append("<script type=\"text/javascript\" src=\""+ chartScriptsPath +"dy3/js/dygraph-combined.js\"></script>\n");
1909 wholeScript.append("<script type=\"text/javascript\" src=\""+ chartScriptsPath +"dy3/js/moment.min.js\"></script>\n");
1910 wholeScript.append("<script type=\"text/javascript\" src=\""+ chartScriptsPath +"dy3/js/interaction.min.js\"></script>\n");
1912 wholeScript.append("<script type=\"text/javascript\">\n");
1913 if(AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("30min")) {
1914 wholeScript.append("var click=2;\n");
1915 } else if (AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("hourly")) {
1916 wholeScript.append("var click=3;\n");
1917 } else if (AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("daily")) {
1918 wholeScript.append("var click=3;\n");
1920 wholeScript.append("var click=3;\n");
1921 //wholeScript.append(" var click=0;\n");
1922 wholeScript.append(" function downV3(event, g, context) { \n");
1923 wholeScript.append(" context.initializeMouseDown(event, g, context); \n");
1924 wholeScript.append(" if (event.altKey || event.shiftKey) { \n");
1925 wholeScript.append(" var minDate = g.xAxisRange()[0]; \n");
1926 wholeScript.append(" var maxDate = g.xAxisRange()[1]; \n");
1927 if(AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("daily")) {
1928 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60*24)) > 6) \n");
1929 wholeScript.append(" Dygraph.startZoom(event, g, context); \n");
1930 } else if(AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("hourly")) {
1931 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60)) > 6) \n");
1932 wholeScript.append(" Dygraph.startZoom(event, g, context); \n");
1933 } else if(AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("30min")) {
1934 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60*2)) > 6) \n");
1935 wholeScript.append(" Dygraph.startZoom(event, g, context); \n");
1938 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60)) > 6) \n");
1939 wholeScript.append(" Dygraph.startZoom(event, g, context); \n");
1941 if(AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("30min")) {
1942 wholeScript.append(" click=2;\n");
1943 } else if (AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("hourly")) {
1944 wholeScript.append(" click=3;\n");
1945 } else if (AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("daily")) {
1946 wholeScript.append(" click=3;\n");
1948 wholeScript.append(" click=3;\n");
1949 wholeScript.append(" } else if (event.ctrlKey) {\n");
1952 wholeScript.append(" click++;\n");
1953 wholeScript.append(" if(click == 1)\n");
1954 wholeScript.append(" zoom_custom(3600);\n");
1955 wholeScript.append(" else if(click == 2)\n");
1956 wholeScript.append(" zoom_custom(12*3600);\n");
1957 wholeScript.append(" else if(click == 3)\n");
1958 wholeScript.append(" zoom_custom(86400);\n");
1959 wholeScript.append(" else if (click == 4)\n");
1960 wholeScript.append(" zoom_custom(7*86400);\n");
1961 wholeScript.append(" else if (click == 5)\n");
1962 wholeScript.append(" zoom_custom(30*86400);\n");
1963 wholeScript.append(" else if (click == 6)\n");
1964 wholeScript.append(" zoom_custom(90*86400);\n");
1965 wholeScript.append(" else if (click == 7)\n");
1966 wholeScript.append(" zoom_custom(180*86400);\n");
1967 wholeScript.append(" else if (click == 8)\n");
1968 wholeScript.append(" zoom_custom(365*86400);\n");
1969 wholeScript.append(" else if (click == 10)\n");
1970 wholeScript.append(" zoom_custom(5*365*86400);\n");
1971 wholeScript.append(" else { \n");
1972 wholeScript.append(" reset();\n");
1973 wholeScript.append(" }\n");
1974 //wholeScript.append(" \n");
1975 wholeScript.append(" } else {\n");
1976 wholeScript.append(" Dygraph.startPan(event, g, context); \n");
1977 wholeScript.append(" } \n");
1978 wholeScript.append(" } \n");
1979 wholeScript.append("</script>\n ");
1980 wholeScript.append("<style type=\"text/css\">\n");
1981 wholeScript.append(".annotation {\n");
1982 wholeScript.append("}");
1983 wholeScript.append(".dygraph-title {\n");
1984 wholeScript.append("color: black;\n");
1985 wholeScript.append("font-weight:bold; \n");
1986 wholeScript.append("}\n");
1987 wholeScript.append(".dygraph-axis-label-x { ");
1988 wholeScript.append("-webkit-transform:rotate(-0deg);");
1989 wholeScript.append("display:block;");
1990 /*position:absolute;
1993 wholeScript.append("}\n");
1996 if(nvl(width).length() > 0) {
1998 widthInt = new Integer(width).intValue();
1999 } catch(Exception ex) {
2000 if(width.endsWith("px")) {
2002 widthInt = new Integer(width.substring(0, width.indexOf("px")));
2003 } catch (Exception ex1) {
2010 } else widthInt = 700;
2012 wholeScript.append(".dygraph-legend {\n");
2013 wholeScript.append(" left: "+(widthInt-200)+"px !important;\n");
2014 wholeScript.append(" top: 5px !important;\n");
2015 wholeScript.append("}\n");
2017 wholeScript.append(".nodatadiv {\n");
2018 wholeScript.append(" display: table-cell;\n");
2019 wholeScript.append(" width: 700px;\n");
2020 wholeScript.append(" height:370px;\n");
2021 wholeScript.append(" text-align:center;\n");
2022 wholeScript.append(" vertical-align: middle;\n");
2023 wholeScript.append("}\n");
2024 wholeScript.append(".nodatainner {\n");
2025 wholeScript.append(" padding: 10px;\n");
2026 wholeScript.append("}\n");
2028 wholeScript.append("canvas {\n");
2029 wholeScript.append(" -webkit-touch-callout: none; \n");
2030 wholeScript.append(" -webkit-user-select: none;\n");
2031 wholeScript.append(" -khtml-user-select: none;\n");
2032 wholeScript.append(" -moz-user-select: none;\n");
2033 wholeScript.append(" user-select: none;\n");
2034 wholeScript.append(" user-select: none;\n");
2035 wholeScript.append(" outline: none;\n");
2036 wholeScript.append(" -webkit-tap-highlight-color: rgba(255, 255, 255, 0); /* mobile webkit */\n");
2037 wholeScript.append("}\n");
2038 wholeScript.append("</style>\n");
2039 wholeScript.append("</head>\n");
2040 wholeScript.append("<body> \n");
2043 wholeScript.append(" <p align=\"center\"><b> " + (AppUtils.nvl(reportRuntime.getReportTitle()).length()>0?reportRuntime.getReportTitle():reportRuntime.getReportName()) + "</b></p>\n");
2045 wholeScript.append(" <table>\n");
2047 wholeScript.append(" <tr> \n ");
2048 wholeScript.append(" <td> \n ");
2049 wholeScript.append(" <div class=\"dygraph-label dygraph-title\" align=\"center\">"+title+"</div> \n");
2050 wholeScript.append(" </td> \n ");
2053 wholeScript.append(" </tr> \n ");
2055 wholeScript.append(" <tr> \n ");
2056 wholeScript.append(" <td> \n ");
2057 if(AppUtils.nvl(reportRuntime.getLegendPosition()).length()<=0 || reportRuntime.getLegendPosition().equals("top")) {
2058 wholeScript.append(" <div id=\"labelDiv"+reportRuntime.getReportID()+"\"></div>\n");
2060 wholeScript.append(" <div id=\"message"+reportRuntime.getReportID()+"\"></div> \n");
2061 wholeScript.append(" </td> \n ");
2063 wholeScript.append(" </tr> \n ");
2064 wholeScript.append(" <tr>\n");
2065 wholeScript.append(" <td>\n");
2068 if(nvl(height).length() > 0) {
2070 heightInt = new Integer(height).intValue();
2072 } catch(Exception ex) {
2073 if(height.endsWith("px")) {
2075 heightInt = new Integer(height.substring(0, height.indexOf("px")));
2077 } catch (Exception ex1) {
2084 } else heightInt = 420;
2085 if(AppUtils.nvl(reportRuntime.getLegendPosition()).length()>=0 && reportRuntime.getLegendPosition().equals("right")) {
2086 wholeScript.append(" <div id=\"div_g"+reportRuntime.getReportID()+"\" style=\"width:"+ (widthInt-250)+ "px; \n" );
2088 wholeScript.append(" <div id=\"div_g"+reportRuntime.getReportID()+"\" style=\"width:"+ (widthInt)+ "px; \n" );
2090 wholeScript.append(" height:"+ heightInt +"px;\"></div> \n");
2091 wholeScript.append(" </td>\n");
2092 if(AppUtils.nvl(reportRuntime.getLegendPosition()).length()>=0 && reportRuntime.getLegendPosition().equals("right")) {
2093 wholeScript.append(" <td valign=\"top\">\n");
2094 wholeScript.append(" <div id=\"labelDiv3716\" valign=\"top\" style=\"width:250px;height:"+ heightInt +"px;\"></div>\n");
2095 wholeScript.append(" </td>\n");
2097 wholeScript.append(" </tr>\n");
2098 if(anomalyRec > 0) {
2099 wholeScript.append(" <tr>\n");
2100 wholeScript.append(" <td>\n");
2101 wholeScript.append(" <table>\n");
2102 wholeScript.append(" <tr>\n");
2103 wholeScript.append(" <td align=\"center\"><font size=\"2px\"><B><align=\"center\">Anomaly Description</align></B></font></td>\n");
2104 wholeScript.append(" </tr>\n");
2105 wholeScript.append(" <tr>\n");
2106 wholeScript.append(" <td><div id=\"list"+reportRuntime.getReportID()+"\" style=\"width:" + widthInt + "px; height:50px;\"></div></td>\n" );
2107 wholeScript.append(" </tr>\n");
2108 wholeScript.append(" </table>\n");
2109 wholeScript.append(" </td>\n");
2110 wholeScript.append(" </tr>\n");
2112 wholeScript.append(" </table>\n");
2114 wholeScript.append(" <script type=\"text/javascript\">\n");
2115 wholeScript.append(" Dygraph.addEvent(document, \"mousewheel\", function() { lastClickedGraph = null; });\n");
2116 wholeScript.append(" Dygraph.addEvent(document, \"click\", function() { lastClickedGraph = null; });\n");
2117 wholeScript.append(" var data = []; \n");
2118 wholeScript.append(" data = [\n ");
2119 wholeScript.append( dataStrBuf.toString());
2120 wholeScript.append(" ];\n");
2121 wholeScript.append(" if(data.length > 0 ) { \n");
2122 wholeScript.append(" var orig_range = [ data[0][0].valueOf(), data[data.length - 1][0].valueOf() ];\n");
2124 wholeScript.append(" function nameAnnotation(ann) { \n");
2125 wholeScript.append(" return ann.shortText; \n");
2126 wholeScript.append(" }\n");
2127 wholeScript.append(" anns = [];\n");
2129 wholeScript.append(" var graph_initialized = false;\n");
2130 wholeScript.append(" if(navigator.platform == 'iPad') { ");
2131 wholeScript.append(" g = new Dygraph(\n");
2132 wholeScript.append(" document.getElementById(\"div_g"+reportRuntime.getReportID()+"\"),\n");
2134 wholeScript.append(" data , \n");
2135 wholeScript.append(" {\n");
2140 StringBuilder labelStrBuf = new StringBuilder("");
2141 StringBuilder colorsStrBuf = new StringBuilder("");
2142 StringBuilder visibilityStrBuf = new StringBuilder("");
2143 int countChartValues = 0;
2144 for (Iterator iter = l.iterator(); iter.hasNext();) {
2145 dct = (DataColumnType) iter.next();
2146 if((dct.getChartSeq()!=null && dct.getChartSeq() >=0) || AppUtils.nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND)) {
2147 if(!AppUtils.nvl(dct.getDisplayName()).toLowerCase().equals("anomaly_text")) {
2149 labelStrBuf.append("'"+ dct.getDisplayName()+"',");
2150 if(!AppUtils.nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND))
2151 colorsStrBuf.append("'"+ AppUtils.nvl(dct.getChartColor())+"',");
2152 visibilityStrBuf.append("true,");
2156 if(labelStrBuf.indexOf(",")!=-1) {
2157 labelStrBuf.deleteCharAt(labelStrBuf.lastIndexOf(","));
2158 visibilityStrBuf.deleteCharAt(visibilityStrBuf.lastIndexOf(","));
2160 if(colorsStrBuf.indexOf(",")!=-1)
2161 colorsStrBuf.deleteCharAt(colorsStrBuf.lastIndexOf(","));
2163 //wholeScript.append("title: '" + (AppUtils.nvl(reportRuntime.getReportTitle()).length()>0?reportRuntime.getReportTitle():reportRuntime.getReportName()) + "',\n");
2164 wholeScript.append("maxNumberWidth:6,\n");
2165 wholeScript.append("xAxisHeight: 70,\n");
2166 wholeScript.append("yAxisLabelWidth: 70,\n");
2167 wholeScript.append("xAxisLabelWidth: 45,\n");
2168 wholeScript.append("axes: {\n");
2169 wholeScript.append("x: {\n");
2170 wholeScript.append(" axisLabelFormatter: function(d, gran) {\n");
2171 wholeScript.append(" var month = d.getMonth()+1;\n");
2172 wholeScript.append(" var day = d.getDate();\n");
2173 wholeScript.append(" var year = d.getFullYear();\n");
2174 wholeScript.append(" var hour = d.getHours();\n");
2175 wholeScript.append(" var minutes = d.getMinutes();\n");
2176 wholeScript.append(" var seconds = d.getSeconds();\n");
2177 wholeScript.append(" var wholeString = Dygraph.zeropad(month)+'/'+Dygraph.zeropad(day);\n");
2178 if(AppUtils.nvl(reportRuntime.getTimeAxisType()).length()==0 || AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("hourly"))
2179 wholeScript.append(" wholeString += ' ' + Dygraph.zeropad(hour) + ':'+Dygraph.zeropad(minutes);\n");
2180 wholeScript.append(" return wholeString; \n");
2181 wholeScript.append(" },\n");
2182 wholeScript.append(" ticker: function (a, b, pixels, opts, dygraph, vals) { \n ");
2183 wholeScript.append(" if(((b-a)/(1000*60*60)) <= 6) { \n");
2184 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.THIRTY_MINUTELY, opts, dygraph); \n");
2185 wholeScript.append(" } else if(((b-a)/(1000*60*60)) <= 12) { \n");
2186 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.HOURLY, opts, dygraph); \n");
2187 wholeScript.append(" } else if (((b-a)/(1000*60*60)) <= 25) \n ");
2188 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.TWO_HOURLY, opts, dygraph); \n ");
2189 wholeScript.append(" else if(((b-a)/(1000*60*60)) <= 78) \n ");
2190 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.SIX_HOURLY, opts, dygraph); \n ");
2191 wholeScript.append(" else if(((b-a)/(1000*60*60*24)) <= 12)\n");
2192 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.DAILY, opts, dygraph); \n");
2193 wholeScript.append(" else if(((b-a)/(1000*60*60*24)) <= 90) \n");
2194 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.WEEKLY, opts, dygraph); \n");
2195 wholeScript.append(" else \n");
2196 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.MONTHLY, opts, dygraph); \n");
2197 wholeScript.append(" }, \n");
2198 wholeScript.append(" valueFormatter: function(ms) { \n");
2199 wholeScript.append(" return new Date(ms).strftime(\"%m/%d/%Y %H:%M\"); \n");
2200 wholeScript.append( " }\n" );
2201 wholeScript.append(" }\n");
2202 wholeScript.append("},\n");
2203 wholeScript.append(" interactionModel : { \n");
2204 wholeScript.append(" 'mousedown' : downV4,\n");
2205 wholeScript.append(" touchstart : newDygraphTouchstart,\n");
2206 wholeScript.append(" touchend : Dygraph.defaultInteractionModel.touchend,\n");
2207 wholeScript.append(" touchmove : Dygraph.defaultInteractionModel.touchmove\n");
2208 wholeScript.append("},\n");
2209 /*wholeScript.append(" zoomCallback: function(minDate, maxDate, yRanges) { \n");
2210 if(AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("daily")) {
2211 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60*24)) < 6) { \n");
2212 wholeScript.append(" maxDate = new Date(minDate).setMinutes(6*24*60);\n");
2213 wholeScript.append(" g.updateOptions({\n");
2214 wholeScript.append(" interactionModel: {},\n");
2215 wholeScript.append(" dateWindow: [minDate, maxDate]\n");
2216 wholeScript.append(" });\n");
2217 } else if (AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("hourly")) {
2218 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60)) <= 6) { \n");
2219 wholeScript.append(" maxDate = new Date(minDate).setMinutes(360);\n");
2220 wholeScript.append(" g.updateOptions({\n");
2221 wholeScript.append(" interactionModel: {},\n");
2222 wholeScript.append(" dateWindow: [minDate, maxDate]\n");
2223 wholeScript.append(" });\n");
2224 } else if (AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("30min")) {
2225 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60)) <= 3) { \n");
2226 wholeScript.append(" maxDate = new Date(minDate).setMinutes(180);\n");
2227 wholeScript.append(" g.updateOptions({\n");
2228 wholeScript.append(" interactionModel: {},\n");
2229 wholeScript.append(" dateWindow: [minDate, maxDate]\n");
2230 wholeScript.append(" });\n");
2231 } else if (AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("weekly")) {
2232 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60*24)) < 7) { \n");
2233 wholeScript.append(" maxDate = new Date(minDate).setMinutes(7*24*60);\n");
2234 wholeScript.append(" g.updateOptions({\n");
2235 wholeScript.append(" interactionModel: {},\n");
2236 wholeScript.append(" dateWindow: [minDate, maxDate]\n");
2237 wholeScript.append(" });\n");
2239 wholeScript.append(" } else {\n");
2240 wholeScript.append(" g.updateOptions({\n");
2241 wholeScript.append(" interactionModel : {\n");
2242 wholeScript.append(" 'mousedown' : downV3,\n");
2243 wholeScript.append(" 'mousemove' : moveV3,\n");
2244 wholeScript.append(" 'mouseup' : upV3,\n");
2245 wholeScript.append(" 'click' : clickV3,\n");
2246 wholeScript.append(" 'dblclick' : dblClickV3,\n");
2247 wholeScript.append(" 'mousewheel' : scrollV3\n");
2248 wholeScript.append(" }\n");
2249 wholeScript.append(" });\n");
2250 wholeScript.append(" } \n");
2251 wholeScript.append(" } ,\n");*/
2252 wholeScript.append("dateWindow: ["+minDate+", "+maxDate+"],\n");
2253 wholeScript.append("labels: ["+ labelStrBuf +"],\n");
2254 wholeScript.append("labelsDiv: \"labelDiv"+reportRuntime.getReportID()+"\",\n");
2255 wholeScript.append("labelsShowZeroValues: true,\n");
2256 if(AppUtils.nvl(reportRuntime.getLegendPosition()).length()>=0 && reportRuntime.getLegendPosition().equals("right")) {
2257 wholeScript.append("labelsSeparateLines: true,\n");
2259 wholeScript.append("labelsDivWidth: 200,\n");
2261 wholeScript.append("animatedZooms: true,\n");
2262 wholeScript.append("strokeWidth: 3.0,\n");
2263 wholeScript.append("strokeBorderWidth: 2.0,\n");
2264 /*wholeScript.append(" labelsDivStyles: { \n");
2265 wholeScript.append(" 'backgroundColor': 'rgba(200, 200, 255, 0.75)',\n");
2266 wholeScript.append(" 'padding': '4px',\n");
2267 wholeScript.append(" 'border': '1px solid black',\n");
2268 wholeScript.append(" 'borderRadius': '10px',\n");
2269 wholeScript.append(" 'boxShadow': '4px 4px 4px #888',\n");
2270 wholeScript.append(" 'width': '50px'\n");
2271 wholeScript.append("}, \n");
2273 wholeScript.append("visibility: ["+ visibilityStrBuf +"],\n");
2274 if(colorsStrBuf.length() > 0 && colorsStrBuf.length()>=(countChartValues*3+5))
2275 wholeScript.append("colors: ["+ colorsStrBuf +"],\n");
2277 wholeScript.append(" legend: 'always', \n");
2279 wholeScript.append(" ylabel: '"+ chartLeftAxisLabel +"' , \n");
2282 wholeScript.append(" xlabel: '"+ xAxisLabel +"' , \n");
2285 wholeScript.append(" drawPoints: true, \n");
2288 wholeScript.append(" stackedGraph: false, \n");
2291 for (Iterator iter = l.iterator(); iter.hasNext();) {
2292 dct = (DataColumnType) iter.next();
2293 if(!(nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND))) {
2294 if(!AppUtils.nvl(dct.getDisplayName()).toLowerCase().equals("anomaly_text")) {
2295 if(dct.getChartSeq()!=null && dct.getChartSeq() >=0) {
2296 wholeScript.append(" '"+ dct.getDisplayName() + "': {\n");
2297 if(AppUtils.nvl(dct.getChartLineType()).length()>0)
2298 wholeScript.append(" strokePattern: Dygraph.DASHED_LINE,\n");
2299 if(dct.isIsRangeAxisFilled()!=null && dct.isIsRangeAxisFilled().booleanValue()) {
2300 wholeScript.append(" fillGraph: true\n");
2302 wholeScript.append(" },\n");
2309 wholeScript.append(" 'Forecast': {\n");
2312 wholeScript.append(" strokePattern: Dygraph.DASHED_LINE,\n");
2315 wholeScript.append(" fillGraph: true\n");
2317 // close each labels
2318 wholeScript.append(" }\n");
2321 if(anomalyRec > 0) {
2322 wholeScript.append(" drawCallback: function(g, is_initial) { \n");
2323 wholeScript.append(" if (is_initial) { \n");
2324 wholeScript.append(" graph_initialized = true; \n");
2325 wholeScript.append(" if (anns.length > 0) { \n");
2326 wholeScript.append(" g.setAnnotations(anns); \n");
2327 wholeScript.append(" }\n");
2328 wholeScript.append(" }\n");
2330 wholeScript.append(" var anns1 = g.annotations();\n");
2331 //wholeScript.append(" var html = \"\";\n");
2332 wholeScript.append(" var html = \"<select id='x' size='1' style='width: "+ widthInt +"px; font-family : courier; font-size:8pt; font-weight:bold;'>\";\n");
2333 wholeScript.append(" for (var i = anns1.length-1; i >= 0 ; i--) {\n");
2334 wholeScript.append(" var name = nameAnnotation(anns1[i]);\n");
2335 //wholeScript.append(" html += \"<span id='\" + name + \"'>\"\n");
2336 wholeScript.append(" if(i==anns1.length-1)\n");
2337 wholeScript.append(" html += \"<option value='\" + name + \"' selected ><font size=1>\" \n");
2338 wholeScript.append(" else \n");
2339 wholeScript.append(" html += \"<option value='\" + name + \"'><font size=1>\" \n");
2340 wholeScript.append(" html += name \n");
2341 //wholeScript.append(" html += name + \": \" + (anns1[i].shortText || '(icon)')\n");
2342 //wholeScript.append(" html += \" -> \" + anns1[i].text + \"</span><br/>\";\n");
2343 wholeScript.append(" html += \" : \" + anns1[i].text + \"</font></option>\";\n");
2344 wholeScript.append(" }\n");
2345 wholeScript.append(" html += \"</select>\" \n");
2346 wholeScript.append(" document.getElementById(\"list"+reportRuntime.getReportID()+"\").innerHTML = html;\n");
2347 wholeScript.append(" }\n");
2350 wholeScript.append(" }\n");
2351 wholeScript.append(" )\n");
2354 wholeScript.append(annotationsStrBuf.toString());
2356 wholeScript.append(" if (graph_initialized) {\n");
2357 wholeScript.append(" g.setAnnotations(anns);\n");
2358 wholeScript.append(" } \n");
2359 //upate handler script
2361 wholeScript.append(" var saveBg = '';\n");
2362 wholeScript.append(" var num = 0;\n");
2363 wholeScript.append(" g.updateOptions( {\n");
2364 wholeScript.append(" annotationMouseOverHandler: function(ann) { \n");
2365 //wholeScript.append(" document.getElementById(nameAnnotation(ann)).style.fontWeight = 'bold';\n");
2366 //wholeScript.append(" saveBg = ann.div.style.backgroundColor;\n");
2367 //wholeScript.append(" ann.div.style.backgroundColor = '#ddd';\n");
2368 wholeScript.append(" var selectobject = document.getElementById(\"x\");\n");
2369 wholeScript.append(" for(var i=0; i<selectobject.length;i++) {\n ");
2370 wholeScript.append(" if(selectobject.options[i].value == nameAnnotation(ann)) {\n ");
2371 wholeScript.append(" selectobject.options[i].selected = true; \n ");
2372 wholeScript.append(" } ");
2373 wholeScript.append(" } ");
2375 wholeScript.append(" },\n");
2376 wholeScript.append(" annotationMouseOutHandler: function(ann) {\n");
2377 wholeScript.append(" document.getElementById(nameAnnotation(ann)).style.fontWeight = 'normal';\n");
2378 wholeScript.append(" ann.div.style.backgroundColor = saveBg;\n");
2379 //wholeScript.append(" var selectobject = document.getElementById(\"x\");\n");
2380 //wholeScript.append(" for(var i=0; i<selectobject.length;i++) {\n ");
2381 //wholeScript.append(" if(selectobject.options[i].value == nameAnnotation(ann)) {\n ");
2382 //wholeScript.append(" selectobject.options[i].selected = false; \n ");
2383 //wholeScript.append(" } ");
2384 //wholeScript.append(" } ");
2386 wholeScript.append(" }\n");
2388 wholeScript.append(" });\n");
2391 wholeScript.append("} else { \n");
2393 wholeScript.append(" g = new Dygraph(\n");
2394 wholeScript.append(" document.getElementById(\"div_g"+reportRuntime.getReportID()+"\"),\n");
2396 /*wholeScript.append(" [\n");
2397 wholeScript.append(dataStrBuf.toString());
2398 wholeScript.append(" ],\n");*/
2399 wholeScript.append(" data , \n");
2400 wholeScript.append(" {\n");
2405 labelStrBuf = new StringBuilder("");
2406 colorsStrBuf = new StringBuilder("");
2407 visibilityStrBuf = new StringBuilder("");
2408 countChartValues = 0;
2409 for (Iterator iter = l.iterator(); iter.hasNext();) {
2410 dct = (DataColumnType) iter.next();
2411 if((dct.getChartSeq()!=null && dct.getChartSeq() >=0) || AppUtils.nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND)) {
2412 if(!AppUtils.nvl(dct.getDisplayName()).toLowerCase().equals("anomaly_text")) {
2414 labelStrBuf.append("'"+ dct.getDisplayName()+"',");
2415 if(!AppUtils.nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND))
2416 colorsStrBuf.append("'"+ AppUtils.nvl(dct.getChartColor())+"',");
2417 visibilityStrBuf.append("true,");
2421 if(labelStrBuf.indexOf(",")!=-1) {
2422 labelStrBuf.deleteCharAt(labelStrBuf.lastIndexOf(","));
2423 visibilityStrBuf.deleteCharAt(visibilityStrBuf.lastIndexOf(","));
2425 if(colorsStrBuf.indexOf(",")!=-1)
2426 colorsStrBuf.deleteCharAt(colorsStrBuf.lastIndexOf(","));
2428 //wholeScript.append("title: '" + (AppUtils.nvl(reportRuntime.getReportTitle()).length()>0?reportRuntime.getReportTitle():reportRuntime.getReportName()) + "',\n");
2429 wholeScript.append("maxNumberWidth:6,\n");
2430 wholeScript.append("xAxisHeight: 70,\n");
2431 wholeScript.append("yAxisLabelWidth: 70,\n");
2432 wholeScript.append("xAxisLabelWidth: 45,\n");
2433 wholeScript.append("axes: {\n");
2434 wholeScript.append("x: {\n");
2435 wholeScript.append(" axisLabelFormatter: function(d, gran) {\n");
2436 wholeScript.append(" var month = d.getMonth()+1;\n");
2437 wholeScript.append(" var day = d.getDate();\n");
2438 wholeScript.append(" var year = d.getFullYear();\n");
2439 wholeScript.append(" var hour = d.getHours();\n");
2440 wholeScript.append(" var minutes = d.getMinutes();\n");
2441 wholeScript.append(" var seconds = d.getSeconds();\n");
2442 wholeScript.append(" var wholeString = Dygraph.zeropad(month)+'/'+Dygraph.zeropad(day);\n");
2443 // wholeScript.append(" if(hour >= 0 && minutes > 0 && seconds > 0) {\n");
2444 //wholeScript.append(" wholeString += ' ' + Dygraph.zeropad(hour) + ':'+Dygraph.zeropad(minutes)+':'+Dygraph.zeropad(seconds);\n");
2445 //wholeScript.append(" } else if (hour >= 0 && minutes > 0 && seconds == 0) {\n");
2446 if(AppUtils.nvl(reportRuntime.getTimeAxisType()).length()==0 || AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("hourly"))
2447 wholeScript.append(" wholeString += ' ' + Dygraph.zeropad(hour) + ':'+Dygraph.zeropad(minutes);\n");
2448 //wholeScript.append(" } else if (hour >= 0 && (minutes >= 0 && seconds > 0)) {\n");
2449 //wholeScript.append(" wholeString += ' ' + Dygraph.zeropad(hour) + ':'+Dygraph.zeropad(minutes)+':'+Dygraph.zeropad(seconds);\n");
2450 //wholeScript.append(" } else if (hour >= 0) { \n");
2451 //wholeScript.append(" wholeString += ' ' + Dygraph.zeropad(hour); \n");
2452 //wholeScript.append(" } \n");
2453 wholeScript.append(" return wholeString; \n");
2454 wholeScript.append(" },\n");
2455 wholeScript.append(" ticker: function (a, b, pixels, opts, dygraph, vals) { \n ");
2456 wholeScript.append(" if(((b-a)/(1000*60*60)) <= 6) { \n");
2457 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.THIRTY_MINUTELY, opts, dygraph); \n");
2458 wholeScript.append(" } else if(((b-a)/(1000*60*60)) <= 12) { \n");
2459 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.HOURLY, opts, dygraph); \n");
2460 wholeScript.append(" } else if (((b-a)/(1000*60*60)) <= 25) \n ");
2461 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.TWO_HOURLY, opts, dygraph); \n ");
2462 wholeScript.append(" else if(((b-a)/(1000*60*60)) <= 78) \n ");
2463 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.SIX_HOURLY, opts, dygraph); \n ");
2464 wholeScript.append(" else if(((b-a)/(1000*60*60*24)) <= 12)\n");
2465 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.DAILY, opts, dygraph); \n");
2466 wholeScript.append(" else if(((b-a)/(1000*60*60*24)) <= 90) \n");
2467 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.WEEKLY, opts, dygraph); \n");
2468 wholeScript.append(" else \n");
2469 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.MONTHLY, opts, dygraph); \n");
2470 wholeScript.append(" }, \n");
2471 wholeScript.append(" valueFormatter: function(ms) { \n");
2472 wholeScript.append(" return new Date(ms).strftime(\"%m/%d/%Y %H:%M\"); \n");
2473 wholeScript.append( " }\n" );
2474 wholeScript.append(" }\n");
2475 wholeScript.append("},\n");
2476 wholeScript.append(" interactionModel : { \n");
2478 wholeScript.append(" 'mousedown' : downV3,\n");
2479 wholeScript.append(" 'mousemove' : moveV3,\n");
2480 wholeScript.append(" 'mouseup' : upV3,\n");
2481 wholeScript.append(" 'click' : clickV3,\n");
2482 wholeScript.append(" 'dblclick' : dblClickV3,\n");
2483 wholeScript.append(" 'mousewheel' : scrollV3\n");
2484 wholeScript.append("},\n");
2485 wholeScript.append(" zoomCallback: function(minDate, maxDate, yRanges) { \n");
2486 if(AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("daily")) {
2487 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60*24)) < 6) { \n");
2488 wholeScript.append(" maxDate = new Date(minDate).setMinutes(6*24*60);\n");
2489 wholeScript.append(" g.updateOptions({\n");
2490 wholeScript.append(" interactionModel: {},\n");
2491 wholeScript.append(" dateWindow: [minDate, maxDate]\n");
2492 wholeScript.append(" });\n");
2493 } else if (AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("hourly")) {
2494 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60)) <= 6) { \n");
2495 wholeScript.append(" maxDate = new Date(minDate).setMinutes(360);\n");
2496 wholeScript.append(" g.updateOptions({\n");
2497 wholeScript.append(" interactionModel: {},\n");
2498 wholeScript.append(" dateWindow: [minDate, maxDate]\n");
2499 wholeScript.append(" });\n");
2500 } else if (AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("30min")) {
2501 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60)) <= 3) { \n");
2502 wholeScript.append(" maxDate = new Date(minDate).setMinutes(180);\n");
2503 wholeScript.append(" g.updateOptions({\n");
2504 wholeScript.append(" interactionModel: {},\n");
2505 wholeScript.append(" dateWindow: [minDate, maxDate]\n");
2506 wholeScript.append(" });\n");
2507 } else if (AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("weekly")) {
2508 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60*24)) < 7) { \n");
2509 wholeScript.append(" maxDate = new Date(minDate).setMinutes(7*24*60);\n");
2510 wholeScript.append(" g.updateOptions({\n");
2511 wholeScript.append(" interactionModel: {},\n");
2512 wholeScript.append(" dateWindow: [minDate, maxDate]\n");
2513 wholeScript.append(" });\n");
2515 wholeScript.append(" } else {\n");
2516 wholeScript.append(" g.updateOptions({\n");
2517 wholeScript.append(" interactionModel : {\n");
2518 wholeScript.append(" 'mousedown' : downV3,\n");
2519 wholeScript.append(" 'mousemove' : moveV3,\n");
2520 wholeScript.append(" 'mouseup' : upV3,\n");
2521 wholeScript.append(" 'click' : clickV3,\n");
2522 wholeScript.append(" 'dblclick' : dblClickV3,\n");
2523 wholeScript.append(" 'mousewheel' : scrollV3\n");
2524 wholeScript.append(" }\n");
2525 wholeScript.append(" });\n");
2526 wholeScript.append(" } \n");
2527 wholeScript.append(" } ,\n");
2528 wholeScript.append("dateWindow: ["+minDate+", "+maxDate+"],\n");
2529 wholeScript.append("labels: ["+ labelStrBuf +"],\n");
2530 wholeScript.append("labelsDiv: \"labelDiv"+reportRuntime.getReportID()+"\",\n");
2531 wholeScript.append("labelsShowZeroValues: true,\n");
2532 if(AppUtils.nvl(reportRuntime.getLegendPosition()).length()>=0 && reportRuntime.getLegendPosition().equals("right")) {
2533 wholeScript.append("labelsSeparateLines: true,\n");
2535 wholeScript.append("labelsDivWidth: 200,\n");
2538 wholeScript.append("animatedZooms: true,\n");
2539 wholeScript.append("strokeWidth: 3.0,\n");
2540 wholeScript.append("strokeBorderWidth: 2.0,\n");
2542 /*wholeScript.append(" labelsDivStyles: { \n");
2543 wholeScript.append(" 'backgroundColor': 'rgba(200, 200, 255, 0.75)',\n");
2544 wholeScript.append(" 'padding': '4px',\n");
2545 wholeScript.append(" 'border': '1px solid black',\n");
2546 wholeScript.append(" 'borderRadius': '10px',\n");
2547 wholeScript.append(" 'boxShadow': '4px 4px 4px #888',\n");
2548 wholeScript.append(" 'width': '50px'\n");
2549 wholeScript.append("}, \n");
2551 wholeScript.append("visibility: ["+ visibilityStrBuf +"],\n");
2552 if(colorsStrBuf.length() > 0 && colorsStrBuf.length()>=(countChartValues*3+5))
2553 wholeScript.append("colors: ["+ colorsStrBuf +"],\n");
2555 wholeScript.append(" legend: 'always', \n");
2557 wholeScript.append(" ylabel: '"+ chartLeftAxisLabel +"' , \n");
2560 wholeScript.append(" xlabel: '"+ xAxisLabel +"' , \n");
2564 wholeScript.append(" drawPoints: true, \n");
2567 wholeScript.append(" stackedGraph: false, \n");
2570 for (Iterator iter = l.iterator(); iter.hasNext();) {
2571 dct = (DataColumnType) iter.next();
2572 if(!(nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND))) {
2573 if(!AppUtils.nvl(dct.getDisplayName()).toLowerCase().equals("anomaly_text")) {
2574 if(dct.getChartSeq()!=null && dct.getChartSeq() >=0) {
2575 wholeScript.append(" '"+ dct.getDisplayName() + "': {\n");
2576 if(AppUtils.nvl(dct.getChartLineType()).length()>0)
2577 wholeScript.append(" strokePattern: Dygraph.DASHED_LINE,\n");
2578 if(dct.isIsRangeAxisFilled()!=null && dct.isIsRangeAxisFilled().booleanValue()) {
2579 wholeScript.append(" fillGraph: true\n");
2581 wholeScript.append(" },\n");
2588 wholeScript.append(" 'Forecast': {\n");
2591 wholeScript.append(" strokePattern: Dygraph.DASHED_LINE,\n");
2594 wholeScript.append(" fillGraph: true\n");
2596 // close each labels
2597 wholeScript.append(" }\n");
2600 if(anomalyRec > 0) {
2601 wholeScript.append(" drawCallback: function(g, is_initial) { \n");
2602 wholeScript.append(" if (is_initial) { \n");
2603 wholeScript.append(" graph_initialized = true; \n");
2604 wholeScript.append(" if (anns.length > 0) { \n");
2605 wholeScript.append(" g.setAnnotations(anns); \n");
2606 wholeScript.append(" }\n");
2607 wholeScript.append(" }\n");
2609 wholeScript.append(" var anns1 = g.annotations();\n");
2610 //wholeScript.append(" var html = \"\";\n");
2611 wholeScript.append(" var html = \"<select id='x' size='1' style='width: "+ widthInt +"px; font-family : courier; font-size:8pt; font-weight:bold;'>\";\n");
2612 wholeScript.append(" for (var i = anns1.length-1; i >= 0 ; i--) {\n");
2613 wholeScript.append(" var name = nameAnnotation(anns1[i]);\n");
2614 //wholeScript.append(" html += \"<span id='\" + name + \"'>\"\n");
2615 wholeScript.append(" if(i==anns1.length-1)\n");
2616 wholeScript.append(" html += \"<option value='\" + name + \"' selected ><font size=1>\" \n");
2617 wholeScript.append(" else \n");
2618 wholeScript.append(" html += \"<option value='\" + name + \"'><font size=1>\" \n");
2619 wholeScript.append(" html += name \n");
2620 //wholeScript.append(" html += name + \": \" + (anns1[i].shortText || '(icon)')\n");
2621 //wholeScript.append(" html += \" -> \" + anns1[i].text + \"</span><br/>\";\n");
2622 wholeScript.append(" html += \" : \" + anns1[i].text + \"</font></option>\";\n");
2623 wholeScript.append(" }\n");
2624 wholeScript.append(" html += \"</select>\" \n");
2625 wholeScript.append(" document.getElementById(\"list"+reportRuntime.getReportID()+"\").innerHTML = html;\n");
2626 wholeScript.append(" }\n");
2629 wholeScript.append(" }\n");
2630 wholeScript.append(" )\n");
2633 wholeScript.append(annotationsStrBuf.toString());
2635 wholeScript.append(" if (graph_initialized) {\n");
2636 wholeScript.append(" g.setAnnotations(anns);\n");
2637 wholeScript.append(" } \n");
2638 //upate handler script
2640 wholeScript.append(" var saveBg = '';\n");
2641 wholeScript.append(" var num = 0;\n");
2642 wholeScript.append(" g.updateOptions( {\n");
2643 wholeScript.append(" annotationMouseOverHandler: function(ann) { \n");
2644 //wholeScript.append(" document.getElementById(nameAnnotation(ann)).style.fontWeight = 'bold';\n");
2645 //wholeScript.append(" saveBg = ann.div.style.backgroundColor;\n");
2646 //wholeScript.append(" ann.div.style.backgroundColor = '#ddd';\n");
2647 wholeScript.append(" var selectobject = document.getElementById(\"x\");\n");
2648 wholeScript.append(" for(var i=0; i<selectobject.length;i++) {\n ");
2649 wholeScript.append(" if(selectobject.options[i].value == nameAnnotation(ann)) {\n ");
2650 wholeScript.append(" selectobject.options[i].selected = true; \n ");
2651 wholeScript.append(" } ");
2652 wholeScript.append(" } ");
2654 wholeScript.append(" },\n");
2655 wholeScript.append(" annotationMouseOutHandler: function(ann) {\n");
2656 //wholeScript.append(" document.getElementById(nameAnnotation(ann)).style.fontWeight = 'normal';\n");
2657 wholeScript.append(" ann.div.style.backgroundColor = saveBg;\n");
2658 //wholeScript.append(" var selectobject = document.getElementById(\"x\");\n");
2659 //wholeScript.append(" for(var i=0; i<selectobject.length;i++) {\n ");
2660 //wholeScript.append(" if(selectobject.options[i].value == nameAnnotation(ann)) {\n ");
2661 //wholeScript.append(" selectobject.options[i].selected = false; \n ");
2662 //wholeScript.append(" } ");
2663 //wholeScript.append(" } ");
2665 wholeScript.append(" }\n");
2667 wholeScript.append(" });\n");
2670 wholeScript.append("} \n");
2672 wholeScript.append("} else {\n");
2673 wholeScript.append("document.getElementById(\"message"+ reportRuntime.getReportID()+"\").display = \"none\";\n");
2674 wholeScript.append("document.getElementById(\"labelDiv"+ reportRuntime.getReportID()+"\").display=\"none\";\n");
2675 wholeScript.append("document.getElementById(\"div_g"+reportRuntime.getReportID()+"\").display=\"none\";\n");
2677 wholeScript.append("document.getElementById(\"div_g"+reportRuntime.getReportID()+"\").innerHTML = \"<div id='noData'><b>No Data Available</b></div>\";\n");
2678 wholeScript.append("document.getElementById(\"div_g"+reportRuntime.getReportID()+"\").className=\"nodatadiv\";\n");
2679 wholeScript.append("document.getElementById(\"nodata\").className=\"nodatainner\";\n");
2681 wholeScript.append("document.getElementById(\"list"+reportRuntime.getReportID()+"\").display=\"none\";\n");
2682 wholeScript.append("}\n");
2683 wholeScript.append(" </script>\n");
2684 wholeScript.append(" </body>\n");
2685 wholeScript.append("</html>");
2688 } else if (chartType.equals(AppConstants.GT_SCATTER)) {
2690 wholeScript.append("<link href=\""+ chartScriptsPath +"d3/css/nv.d3.css\" rel=\"stylesheet\" type=\"text/css\">\n");
2691 wholeScript.append("<style>\n " +
2693 " overflow-y:scroll; \n" +
2696 " font: 12px sans-serif; \n" +
2698 " tr.z-row-over > td.z-row-inner, tr.z-row-over > .z-cell {" +
2699 " background-color: rgb(255, 255, 255); "+
2701 " svg { display: block; } " +
2702 " #chart1 svg { \n" +
2703 " height: 420px; \n" +
2704 " width: 800px; \n" +
2705 " min-width: 100px; \n" +
2706 " min-height: 100px; \n" +
2710 wholeScript.append("<body> \n");
2711 wholeScript.append("<div id=\"chart1\"><svg></svg></div>");
2713 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/d3.v2.js\"></script>\n");
2714 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/nv.d3.js\"></script> \n");
2715 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/tooltip.js\"></script> \n");
2716 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/utils.js\"></script> \n");
2717 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/models/legend.js\"></script> \n");
2718 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/models/axis.js\"></script> \n");
2719 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/models/distribution.js\"></script> \n");
2720 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/models/scatter.js\"></script> \n");
2721 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/models/scatterChart.js\"></script> \n");
2722 wholeScript.append("<script> \n");
2723 wholeScript.append("nv.addGraph(function() { \n" +
2724 " var width1=900, height1=220; \n" +
2725 " var chart = nv.models.scatterChart() \n" +
2726 " .showDistX(true) \n" +
2727 " .showDistY(true) \n" +
2728 " .useVoronoi(true) \n" +
2729 " .color(d3.scale.category10().range()); \n" +
2730 /* " .width(width1) \n" +
2731 " .height(height1); \n" +
2732 */ " chart.xAxis\n" +
2733 " .axisLabel('" +legendColumnName + "')\n" +
2734 " .tickFormat(d3.format('.02f'));\n" +
2736 " .axisLabel('" + chartLeftAxisLabel + "')\n" +
2737 " .tickFormat(d3.format('.02f'));\n" +
2738 " d3.select('#chart1 svg') \n" +
2739 " .datum(getData()) \n" );
2741 wholeScript.append(" .transition().duration(1200) \n" );
2742 /* " .attr(\"width\", width1) \n" +
2743 " .attr(\"height\", height1) \n" +
2744 */ wholeScript.append(" .call(chart); \n" +
2745 " nv.utils.windowResize(chart.update);\n"+
2746 "return chart; \n" +
2749 String dateStr = "";
2750 Object uniqueElements [] = null;
2751 TreeSet ts = new TreeSet();
2752 for (int i = 0; i < ds.getRowCount(); i++) {
2753 dateStr = ds.getString(i, 2);
2754 if(dateStr.length()>0)
2757 SortedSet s = Collections.synchronizedSortedSet(ts);
2758 uniqueElements = s.toArray();
2760 wholeScript.append(" function getData() { \n " +
2761 " var data = [];\n ");
2762 for (int i = 0; i < uniqueElements.length; i++) {
2763 wholeScript.append(" data.push( {key:'"+ uniqueElements[i]+ "', values:[]})\n");
2767 for (int i = 0; i < ds.getRowCount(); i++) {
2768 for (int k = 0; k < uniqueElements.length; k++) {
2769 if(ds.getString(i, 2).equals(uniqueElements[k])) {
2770 wholeScript.append("data["+k+"].values.push({x:"+ ds.getString(i, 1) +",y:"+ds.getString(i, 3) + ", size: Math.random() });\n");
2775 wholeScript.append("return data; } </script></body>\n");
2776 } else if (chartType.equals(AppConstants.GT_HIERARCHICAL_SUNBURST)) {
2778 StringBuilder dataStr = new StringBuilder("");
2779 StringBuilder groupBuffer = new StringBuilder("");
2780 StringBuilder s = new StringBuilder("");
2781 dataStr.append("{");
2782 dataStr.append(" \"xxxxxx\":{\n");
2785 String level = "-1";
2786 String levelOld = "-1";
2788 for (int i = 0; i < ds.getRowCount(); i++) {
2789 mid = ds.getString(i, "mid");
2790 level = ds.getString(i, "level1");
2791 eid = ds.getString(i, "eid");
2792 if(mid.equals(midOld)) {
2793 dataStr.append("\""+ eid +"\": 9956,\n");
2795 if(dataStr.lastIndexOf(",")!= -1)
2796 dataStr.deleteCharAt(dataStr.lastIndexOf(","));
2797 //if(Integer.parseInt(levelOld)==Integer.parseInt(level))
2798 //dataStr.append("},\n");
2799 if (Integer.parseInt(levelOld)<Integer.parseInt(level))
2800 dataStr.append("},\n");
2801 dataStr.append("\""+ mid +"\": { \n");
2807 if(dataStr.toString().endsWith(","))
2808 dataStr.deleteCharAt(dataStr.lastIndexOf(","));
2809 dataStr.append("}\n");
2810 dataStr.append("}\n");
2812 String formattedReportName = new HtmlStripper().stripSpecialCharacters(reportRuntime.getReportName());
2813 String formattedDate = new SimpleDateFormat("MMddyyyyHHmm").format(new java.util.Date());
2814 String filename=formattedReportName+formattedDate+user_id+".json";
2815 String filenamepath = AppUtils.getExcelTemplatePath()+"../../json/"+filename;
2816 System.out.println("filenamepath " + filenamepath);
2817 BufferedWriter out = new BufferedWriter(new FileWriter(filenamepath));
2818 out.write(dataStr.toString());
2820 request.getSession().setAttribute("jsonFileName", filename);
2821 } catch (IOException e) {
2822 e.printStackTrace();
2823 System.out.println("Exception ");
2825 } else if (chartType.equals(AppConstants.GT_HIERARCHICAL)) {
2827 StringBuilder dataStr = new StringBuilder("");
2828 StringBuilder groupBuffer = new StringBuilder("");
2829 StringBuilder s = new StringBuilder("");
2830 dataStr.append("{");
2831 dataStr.append(" \"groups\":[");
2833 for (int i = 0; i < ds.getRowCount(); i++) {
2834 if(ds.getString(i,"group_ind").equals("Y")) {
2835 groupBuffer.append(" { \"name\": \""+ ds.getString(i,"ei1") +"\" },\n");
2839 groupBuffer.deleteCharAt(groupBuffer.lastIndexOf(","));
2840 dataStr.append(groupBuffer.toString());
2841 dataStr.append("],");
2842 dataStr.append("\"nodes\":[");
2843 int rowCount = ds.getRowCount();
2844 for (int i = 0; i < ds.getRowCount(); i++) {
2845 s.append("{ \"name\": \""+ ds.getString(i,"ei1") +"\" , \"group\":"+ ds.getString(i,"groups") +", \"level\":2 }");
2846 if (i < (rowCount-1))
2849 s = new StringBuilder("");
2852 dataStr.append("],");
2853 dataStr.append("\"links\":[");
2854 for (int i = 0; i < ds.getRowCount(); i++) {
2855 s.append("{ \"source\": "+ ds.getString(i,"source") +" , \"target\":"+ ds.getString(i,"target") +", \"value\":2 }");
2856 if (i < (rowCount-1))
2859 s = new StringBuilder("");
2861 dataStr.append("]}");
2863 String formattedReportName = new HtmlStripper().stripSpecialCharacters(reportRuntime.getReportName());
2864 String formattedDate = new SimpleDateFormat("MMddyyyyHHmm").format(new java.util.Date());
2865 String filename=formattedReportName+formattedDate+user_id+".json";
2866 String filenamepath = AppUtils.getExcelTemplatePath()+"../../json/"+filename;
2867 System.out.println("filenamepath " + filenamepath);
2868 BufferedWriter out = new BufferedWriter(new FileWriter(filenamepath));
2869 out.write(dataStr.toString());
2871 request.getSession().setAttribute("jsonFileName", filename);
2872 } catch (IOException e) {
2873 e.printStackTrace();
2874 System.out.println("Exception ");
2880 try(BufferedWriter out = new BufferedWriter(new FileWriter("test.txt"))) {
2881 out.write(wholeScript.toString());
2882 } catch (IOException e) {
2883 e.printStackTrace();
2884 System.out.println("Exception ");
2886 return wholeScript.toString();
2889 public String nvl(String s) {
2890 return (s == null) ? "" : s;
2893 public String nvl(String s, String sDefault) {
2894 return nvl(s).equals("") ? sDefault : s;
2897 public static String nvls(String s) {
2898 return (s == null) ? "" : s;
2901 public static String nvls(String s, String sDefault) {
2902 return nvls(s).equals("") ? sDefault : s;
2905 public boolean getFlagInBoolean(String s) {
2906 return nvl(s).toUpperCase().startsWith("Y") || nvl(s).toLowerCase().equals("true");
2909 public DataSet loadChartData(String userId, HttpServletRequest request) throws RaptorException {
2910 if (nvl(getChartType()).length() == 0)
2912 //TODO: display chart function to be added.
2913 //if (!getDisplayChart())
2917 sql = generateChartSQL(userId, request);
2918 logger.debug(EELFLoggerDelegate.debugLogger, ("SQL generated " + sql));
2919 String dbInfo = reportRuntime.getDBInfo();
2920 DataSet ds = ConnectionUtils.getDataSet(sql, dbInfo);
2921 if(ds.getRowCount()<=0) {
2922 printDebugLogSeparatorLine();
2923 logger.debug(EELFLoggerDelegate.debugLogger, (getChartType().toUpperCase()+" - " + REPORT_ID + reportRuntime.getReportID() + " DATA IS EMPTY" ));
2924 logger.debug(EELFLoggerDelegate.debugLogger, (QUERY + sql));
2925 printDebugLogSeparatorLine();
2931 public String generateChartSQL(String userId, HttpServletRequest request ) throws RaptorException {
2932 List reportCols = reportRuntime.getAllColumns();
2933 List chartValueCols = getChartValueColumnsList(AppConstants.CHART_ALL_COLUMNS, null); // parameter is 0 has this requires all columns.
2934 String reportSQL = reportRuntime.getWholeSQL();
2936 //Add order by clause
2937 Pattern re1 = Pattern.compile("(^[\r\n]*|([\\s]))[Oo][Rr][Dd][Ee][Rr](.*?[^\r\n]*)[Bb][Yy]",Pattern.DOTALL);
2938 //Pattern re1 = Pattern.compile("order(.*?[^\r\n]*)by", Pattern.DOTALL);
2939 Matcher matcher = re1.matcher(reportSQL);
2940 //Pattern re1 = Pattern.compile("(^[\r\n]*|([\\s]))[Oo][Rr][Dd][Ee][Rr][Tt](.*?[^\r\n]*)[Bb][Yy]",Pattern.DOTALL);
2941 //int startPoint = sql.length()-30;
2943 reportSQL = reportSQL + " ";
2944 reportSQL = Pattern.compile("(^[\r\n]*|([\\s]))[Ss][Ee][Ll][Ee][Cc][Tt]([\r\n]*|[\\s]*)",Pattern.DOTALL).matcher(reportSQL).replaceAll(" SELECT ");
2945 //reportSQL = Pattern.compile("(^[\r\n]*|([\\s]))[Ff][Rr][Oo][Mm]([\r\n]*|[\\s]*)",Pattern.DOTALL).matcher(reportSQL).replaceAll(" FROM ");
2946 reportSQL = Pattern.compile("(^[\r\n]*|([\\s]))[Ww][Hh][Ee][Rr][Ee]([\r\n]*|[\\s]*)",Pattern.DOTALL).matcher(reportSQL).replaceAll(" WHERE ");
2947 reportSQL = Pattern.compile("(^[\r\n]*|([\\s]))[Ww][Hh][Ee][Nn]([\r\n]*|[\\s]*)",Pattern.DOTALL).matcher(reportSQL).replaceAll(" WHEN ");
2948 reportSQL = Pattern.compile("(^[\r\n]*|([\\s]))[Aa][Nn][Dd]([\r\n]*|[\\s]*)",Pattern.DOTALL).matcher(reportSQL).replaceAll(" AND ");
2950 if(!reportRuntime.getReportType().equals(AppConstants.RT_HIVE)) {
2951 int startPoint = reportSQL.lastIndexOf(" FROM ");
2952 if(startPoint <= 0) {
2953 startPoint = reportSQL.lastIndexOf(" from ");
2955 if(startPoint <= 0) {
2956 startPoint = reportSQL.lastIndexOf("from ");
2958 if(startPoint <= 0) {
2959 startPoint = reportSQL.lastIndexOf("FROM ");
2962 if (!matcher.find(startPoint)) {
2963 reportSQL = reportSQL + " ORDER BY 1" ;
2966 reportRuntime.setWholeSQL(reportSQL);
2968 printDebugLogSeparatorLine();
2969 logger.debug(EELFLoggerDelegate.debugLogger, ("WHOLE_SQL" + reportSQL));
2970 printDebugLogSeparatorLine();
2972 if (reportRuntime.getFormFieldList() != null) {
2973 for (Iterator iter = reportRuntime.getFormFieldList().getFormField().iterator(); iter.hasNext();) {
2974 FormFieldType fft = (FormFieldType) iter.next();
2975 String fieldId = fft.getFieldId();
2976 String fieldDisplay = reportRuntime.getFormFieldDisplayName(fft);
2977 String formfield_value = "";
2978 formfield_value = AppUtils.getRequestNvlValue(request, fieldId);
2979 String paramValue = nvl(formfield_value);
2980 if(paramValue.length()>0) {
2981 /*sql = Utils.replaceInString(sql, "'" + fieldDisplay + "'", nvl(
2982 paramValue, "NULL"));*/
2983 reportSQL = Utils.replaceInString(reportSQL, fieldDisplay, nvl(
2984 paramValue, "NULL"));
2986 /*sql = Utils.replaceInString(sql, "'" + fieldDisplay + "'", nvl(
2987 paramValue, "NULL"));*/
2988 reportSQL = Utils.replaceInString(reportSQL, "'" + fieldDisplay + "'", nvl(
2989 paramValue, "NULL"));
2990 reportSQL = Utils.replaceInString(reportSQL, fieldDisplay , nvl(
2991 paramValue, "NULL"));
2994 logger.debug(EELFLoggerDelegate.debugLogger, ("SQL " + reportSQL));
2995 String legendCol = "1 a";
2996 // String valueCol = "1";
2997 StringBuilder groupCol = new StringBuilder();
2998 StringBuilder seriesCol = new StringBuilder();
2999 StringBuilder valueCols = new StringBuilder();
3001 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
3002 DataColumnType dc = (DataColumnType) iter.next();
3003 String colName = getColumnSelectStr(dc, request);
3004 if (nvl(dc.getColOnChart()).equals(AppConstants.GC_LEGEND))
3005 legendCol = getSelectExpr(dc, colName)+" " + dc.getColId();
3006 // if(dc.getChartSeq()>0)
3007 // valueCol = "NVL("+colName+", 0) "+dc.getColId();
3008 if ((!nvl(dc.getColOnChart()).equals(AppConstants.GC_LEGEND))
3009 && (dc.getChartSeq()!=null && dc.getChartSeq().intValue() <= 0) && dc.isGroupBreak()) {
3010 groupCol.append(", ");
3011 groupCol.append(colName + " " + dc.getColId());
3014 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
3015 DataColumnType dc = (DataColumnType) iter.next();
3016 if(dc.isChartSeries()!=null && dc.isChartSeries().booleanValue()) {
3017 //System.out.println("*****************, "+ " " +getColumnSelectStr(dc, paramValues)+ " "+ getSelectExpr(dc,getColumnSelectStr(dc, paramValues)));
3018 seriesCol.append(", "+ getSelectExpr(dc,getColumnSelectStr(dc, request))+ " " + dc.getColId());
3022 /*for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
3023 DataColumnType dc = (DataColumnType) iter.next();
3024 if(!dc.isChartSeries() && !(nvl(dc.getColOnChart()).equals(AppConstants.GC_LEGEND))) {
3025 //System.out.println("*****************, "+ " " +getColumnSelectStr(dc, paramValues)+ " "+ getSelectExpr(dc,getColumnSelectStr(dc, paramValues)));
3026 seriesCol.append(", "+ formatChartColumn(getSelectExpr(dc,getColumnSelectStr(dc, paramValues)))+ " " + dc.getColId());
3030 for (Iterator iter = chartValueCols.iterator(); iter.hasNext();) {
3031 DataColumnType dc = (DataColumnType) iter.next();
3032 String colName = getColumnSelectStr(dc, request);
3033 String paramValue = "";
3034 if(AppUtils.nvl(colName).startsWith("[")) {
3035 if (reportRuntime.getFormFieldList() != null) {
3036 for (Iterator iterC = reportRuntime.getFormFieldList().getFormField().iterator(); iterC.hasNext();) {
3037 FormFieldType fft = (FormFieldType) iterC.next();
3038 String fieldId = fft.getFieldId();
3039 String fieldDisplay = reportRuntime.getFormFieldDisplayName(fft);
3040 String formfield_value = "";
3041 if(AppUtils.nvl(fieldDisplay).equals(colName)) {
3042 formfield_value = AppUtils.getRequestNvlValue(request, fieldId);
3043 paramValue = nvl(formfield_value);
3049 seriesCol.append("," + (AppUtils.nvl(paramValue).length()>0? paramValue:"null") + " " + dc.getColId());
3051 //valueCols.append(", NVL(" + formatChartColumn(colName) + ",0) " + dc.getColId());
3052 seriesCol.append("," + (AppUtils.nvl(paramValue).length()>0? paramValue:formatChartColumn(colName)) + " " + dc.getColId());
3056 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
3057 DataColumnType dc = (DataColumnType) iter.next();
3058 String colName = dc.getDisplayName();
3059 String colValue = getColumnSelectStr(dc, request);
3060 //String colName = getColumnSelectStr(dc, formGrid);
3061 if(colName.equals(AppConstants.RI_CHART_TOTAL_COL))
3062 seriesCol.append(", " + AppConstants.RI_CHART_TOTAL_COL + " " + AppConstants.RI_CHART_TOTAL_COL );
3063 if (colName.equals(AppConstants.RI_CHART_COLOR))
3064 seriesCol.append(", " + colValue + " " + AppConstants.RI_CHART_COLOR );
3065 if(colName.equals(AppConstants.RI_CHART_MARKER_START))
3066 seriesCol.append(", " + AppConstants.RI_CHART_MARKER_START + " " + AppConstants.RI_CHART_MARKER_START );
3067 if(colName.equals(AppConstants.RI_CHART_MARKER_END))
3068 seriesCol.append(", " + AppConstants.RI_CHART_MARKER_END + " " + AppConstants.RI_CHART_MARKER_END );
3069 if(colName.equals(AppConstants.RI_CHART_MARKER_TEXT_LEFT))
3070 seriesCol.append(", " + AppConstants.RI_CHART_MARKER_TEXT_LEFT + " " + AppConstants.RI_CHART_MARKER_TEXT_LEFT );
3071 if(colName.equals(AppConstants.RI_CHART_MARKER_TEXT_RIGHT))
3072 seriesCol.append(", " + AppConstants.RI_CHART_MARKER_TEXT_RIGHT + " " + AppConstants.RI_CHART_MARKER_TEXT_RIGHT );
3073 //if(colName.equals(AppConstants.RI_ANOMALY_TEXT))
3074 //seriesCol.append(", " + AppConstants.RI_ANOMALY_TEXT + " " + AppConstants.RI_ANOMALY_TEXT );
3077 //debugLogger.debug("ReportSQL Chart " + reportSQL );
3078 /*for (Iterator iter = chartValueCols.iterator(); iter.hasNext();) {
3079 DataColumnType dc = (DataColumnType) iter.next();
3080 String colName = getColumnSelectStr(dc, paramValues);
3081 //valueCols.append(", NVL(" + formatChartColumn(colName) + ",0) " + dc.getColId());
3082 valueCols.append("," + formatChartColumn(colName) + " " + dc.getColId());
3084 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
3085 DataColumnType dc = (DataColumnType) iter.next();
3086 String colName = getColumnSelectStr(dc, paramValues);
3087 //if(colName.equals(AppConstants.RI_CHART_TOTAL_COL) || colName.equals(AppConstants.RI_CHART_COLOR)) {
3088 if(colName.equals(AppConstants.RI_CHART_TOTAL_COL))
3089 valueCols.append(", " + AppConstants.RI_CHART_TOTAL_COL + " " + AppConstants.RI_CHART_TOTAL_COL );
3090 if (colName.equals(AppConstants.RI_CHART_COLOR))
3091 valueCols.append(", " + AppConstants.RI_CHART_COLOR + " " + AppConstants.RI_CHART_COLOR );
3092 if (colName.equals(AppConstants.RI_CHART_INCLUDE))
3093 valueCols.append(", " + AppConstants.RI_CHART_INCLUDE + " " + AppConstants.RI_CHART_INCLUDE );
3096 String final_sql = "";
3097 reportSQL = Utils.replaceInString(reportSQL, " from ", " FROM ");
3098 reportSQL = Utils.replaceInString(reportSQL, " From ", " FROM ");
3099 reportSQL = Utils.replaceInString(reportSQL, " select ", " SELECT ");
3100 reportSQL = Utils.replaceInString(reportSQL, " union ", " UNION ");
3101 //reportSQL = reportSQL.replaceAll("[\\s]*\\(", "(");
3102 // if(reportSQL.indexOf("UNION") != -1) {
3103 // if(reportSQL.indexOf("FROM(")!=-1)
3104 // final_sql += " "+reportSQL.substring(reportSQL.indexOf("FROM(") );
3105 // else if (reportSQL.indexOf("FROM (")!=-1)
3106 // final_sql += " "+reportSQL.substring(reportSQL.indexOf("FROM (") );
3107 // //TODO ELSE THROW ERROR
3110 // final_sql += " "+reportSQL.substring(reportSQL.toUpperCase().indexOf(" FROM "));
3113 int pos_first_select = 0;
3114 int pos_dup_select = 0;
3115 int pos_prev_select = 0;
3116 int pos_last_select = 0;
3117 if (reportSQL.indexOf("FROM", pos)!=-1) {
3118 pos = reportSQL.indexOf("FROM", pos);
3119 pos_dup_select = reportSQL.lastIndexOf("SELECT",pos);
3120 pos_first_select = reportSQL.indexOf("SELECT");//,pos);
3121 logger.debug(EELFLoggerDelegate.debugLogger, ("pos_select " + pos_first_select + " " + pos_dup_select));
3122 if(pos_dup_select > pos_first_select) {
3123 logger.debug(EELFLoggerDelegate.debugLogger, ("********pos_dup_select ********" + pos_dup_select));
3124 //pos_dup_select1 = pos_dup_select;
3125 pos_prev_select = pos_first_select;
3126 pos_last_select = pos_dup_select;
3127 while (pos_last_select > pos_prev_select) {
3128 logger.debug(EELFLoggerDelegate.debugLogger, ("pos_last , pos_prev " + pos_last_select + " " + pos_prev_select));
3129 pos = reportSQL.indexOf("FROM", pos+2);
3130 pos_prev_select = pos_last_select;
3131 pos_last_select = reportSQL.lastIndexOf("SELECT",pos);
3132 logger.debug(EELFLoggerDelegate.debugLogger, ("in WHILE LOOP LAST " + pos_last_select));
3137 final_sql += " "+reportSQL.substring(pos);
3138 logger.debug(EELFLoggerDelegate.debugLogger, ("Final SQL " + final_sql));
3139 String sql = "SELECT " + legendCol + ", " + legendCol+"_1" + seriesCol.toString()+ nvl(valueCols.toString(), ", 1")
3140 + groupCol.toString()
3142 logger.debug(EELFLoggerDelegate.debugLogger, ("Final sql in generateChartSQL " +sql));
3145 } // generateChartSQL
3147 private String getColumnSelectStr(DataColumnType dc, HttpServletRequest request) {
3148 //String colName = dc.isCalculated() ? dc.getColName()
3149 // : ((nvl(dc.getTableId()).length() > 0) ? (dc.getTableId() + "." + dc
3150 // .getColName()) : dc.getColName());
3151 String colName = dc.getColName();
3152 String paramValue = null;
3153 //if (dc.isCalculated()) {
3154 if (reportRuntime.getFormFieldList() != null) {
3155 for (Iterator iter = reportRuntime.getFormFieldList().getFormField().iterator(); iter.hasNext();) {
3156 FormFieldType fft = (FormFieldType) iter.next();
3157 String fieldId = fft.getFieldId();
3158 String fieldDisplay = reportRuntime.getFormFieldDisplayName(fft);
3159 String formfield_value = "";
3160 formfield_value = AppUtils.getRequestNvlValue(request, fieldId);
3161 paramValue = nvl(formfield_value);
3162 if(paramValue.length()>0) {
3163 /*sql = Utils.replaceInString(sql, "'" + fieldDisplay + "'", nvl(
3164 paramValue, "NULL"));*/
3165 colName = Utils.replaceInString(colName, "'" + fieldDisplay + "'", "'"+nvl(
3166 paramValue, "NULL")+"'");
3167 colName = Utils.replaceInString(colName, fieldDisplay, nvl(
3168 paramValue, "NULL"));
3175 } // getColumnSelectStr
3179 public String getSelectExpr(DataColumnType dct) {
3181 // dct.isCalculated()?dct.getColName():((nvl(dct.getTableId()).length()>0)?(dct.getTableId()+"."+dct.getColName()):dct.getColName());
3182 return getSelectExpr(dct, dct.getColName() /* colName */);
3185 private String getSelectExpr(DataColumnType dct, String colName) {
3186 String colType = dct.getColType();
3187 if (colType.equals(AppConstants.CT_CHAR)
3188 || ((nvl(dct.getColFormat()).length() == 0) && (!colType
3189 .equals(AppConstants.CT_DATE))))
3192 return "DATE_FORMAT(" + colName + ", '"
3193 + nvl(dct.getColFormat(), AppConstants.DEFAULT_DATE_FORMAT) + "')";
3196 private String formatChartColumn(String colName) {
3197 logger.debug(EELFLoggerDelegate.debugLogger, ("Format Chart Column Input colName " + colName));
3198 colName = colName.trim();
3199 colName = Utils.replaceInString(colName, "TO_CHAR", "to_char");
3200 colName = Utils.replaceInString(colName, "to_number", "TO_NUMBER");
3201 //reportSQL = reportSQL.replaceAll("[\\s]*\\(", "(");
3202 colName = colName.replaceAll(",[\\s]*\\(", ",(");
3203 StringBuilder colNameBuf = new StringBuilder(colName);
3204 int pos = 0, posFormatStart = 0, posFormatEnd = 0;
3207 if(colNameBuf.indexOf("999")==-1 && colNameBuf.indexOf("990")==-1) {
3208 logger.debug(EELFLoggerDelegate.debugLogger, (" return colName " + colNameBuf.toString()));
3209 return colNameBuf.toString();
3212 while (colNameBuf.indexOf("to_char")!=-1) {
3213 if(colNameBuf.indexOf("999")!=-1 || colNameBuf.indexOf("990")!=-1) {
3214 pos = colNameBuf.indexOf("to_char");
3215 colNameBuf.insert(pos, " TO_NUMBER ( CR_RAPTOR.SAFE_TO_NUMBER (");
3216 pos = colNameBuf.indexOf("to_char");
3217 colNameBuf.replace(pos, pos+7, "TO_CHAR");
3218 //colName = Utils.replaceInString(colNameBuf.toString(), "to_char", " TO_NUMBER ( CR_RAPTOR.SAFE_TO_NUMBER ( TO_CHAR ");
3219 logger.debug(EELFLoggerDelegate.debugLogger, ("After adding to_number " + colNameBuf.toString()));
3220 //posFormatStart = colNameBuf.lastIndexOf(",'")+1;
3221 posFormatStart = colNameBuf.indexOf(",'", pos)+1;
3222 posFormatEnd = colNameBuf.indexOf(")",posFormatStart);
3223 logger.debug(EELFLoggerDelegate.debugLogger, (posFormatStart + " " + posFormatEnd + " "+ pos));
3224 format = colNameBuf.substring(posFormatStart, posFormatEnd);
3225 //posFormatEnd = colNameBuf.indexOf(")",posFormatEnd);
3226 colNameBuf.insert(posFormatEnd+1, " ," + format + ") , "+ format + ")");
3227 logger.debug(EELFLoggerDelegate.debugLogger, ("colNameBuf " + colNameBuf.toString()));
3230 logger.debug(EELFLoggerDelegate.debugLogger, (" return colName " + colNameBuf.toString()));
3231 return colNameBuf.toString();
3234 public List getChartValueColumnsList( int filter, HashMap formValues) { /*filter; all=0;create without new chart =1; createNewChart=2 */
3235 List reportCols = reportRuntime.getAllColumns();
3237 ArrayList chartValueCols = new ArrayList();
3239 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
3241 DataColumnType dc = (DataColumnType) iter.next();
3242 // if(filter == 2 || filter == 1) {
3243 flag = reportRuntime.getDependsOnFormFieldFlag(dc, formValues);
3245 if( (dc.getChartSeq()!=null && dc.getChartSeq()> 0) && flag == 0 && !(nvl(dc.getColOnChart()).equals(AppConstants.GC_LEGEND))) {
3246 if(nvl(dc.getChartGroup()).length()<=0) {
3247 if( filter == 2 && (dc.isCreateInNewChart()!=null && dc.isCreateInNewChart().booleanValue())) {
3248 chartValueCols.add(dc);
3249 } else if (filter == 1 && (dc.isCreateInNewChart()==null || !dc.isCreateInNewChart().booleanValue())) {
3250 chartValueCols.add(dc);
3252 else if(filter == 0)
3253 chartValueCols.add(dc);
3254 } else chartValueCols.add(dc);
3257 // chartValueCols.add(dc);
3259 Collections.sort(chartValueCols, new ChartSeqComparator());
3260 return chartValueCols;
3261 } // getChartValueColumnsList
3263 public String parseTitle(String title, HashMap formValues) {
3264 Set set = formValues.entrySet();
3265 for(Iterator iter = set.iterator(); iter.hasNext(); ) {
3266 Map.Entry entry = (Entry<String,String>) iter.next();
3267 if(title.indexOf("["+ entry.getKey() + "]")!= -1) {
3268 title = Utils.replaceInString(title, "["+entry.getKey()+"]", nvl(
3269 (String) entry.getValue(), ""));
3275 public java.util.Date timezoneConversion(SimpleDateFormat sdf, String dateStr) {
3276 // sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
3277 return sdf.parse(dateStr, new ParsePosition(0));
3280 public java.util.Date getDateFromDateStr(String dateStr) {
3281 SimpleDateFormat MMDDYYYYFormat = new SimpleDateFormat("MM/dd/yyyy");
3282 SimpleDateFormat EEEMMDDYYYYFormat = new SimpleDateFormat("EEE, MM/dd/yyyy"); //2012-11-01 00:00:00
3283 SimpleDateFormat YYYYMMDDFormat = new SimpleDateFormat("yyyy/MM/dd");
3284 SimpleDateFormat MONYYYYFormat = new SimpleDateFormat("MMM yyyy");
3285 SimpleDateFormat MMYYYYFormat = new SimpleDateFormat("MM/yyyy");
3286 SimpleDateFormat MMMMMDDYYYYFormat = new SimpleDateFormat("MMMMM dd, yyyy");
3287 SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
3288 SimpleDateFormat timestampHrFormat = new SimpleDateFormat("yyyy-MM-dd HH");
3289 SimpleDateFormat timestampDayFormat = new SimpleDateFormat("yyyy-MM-dd");
3290 SimpleDateFormat DDMONYYYYFormat = new SimpleDateFormat("dd-MMM-yyyy");
3291 SimpleDateFormat MONTHYYYYFormat = new SimpleDateFormat("MMMMM, yyyy");
3292 SimpleDateFormat MMDDYYYYHHFormat = new SimpleDateFormat("MM/dd/yyyy HH");
3293 SimpleDateFormat MMDDYYYYHHMMSSFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
3294 SimpleDateFormat MMDDYYYYHHMMFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm");
3295 SimpleDateFormat YYYYMMDDHHMMSSFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
3296 SimpleDateFormat YYYYMMDDHHMMFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm");
3297 SimpleDateFormat DDMONYYYYHHMMSSFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
3298 SimpleDateFormat DDMONYYYYHHMMFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm");
3299 SimpleDateFormat MMDDYYFormat = new SimpleDateFormat("MM/dd/yy");
3300 SimpleDateFormat MMDDYYHHMMFormat = new SimpleDateFormat("MM/dd/yy HH:mm");
3301 SimpleDateFormat MMDDYYHHMMSSFormat = new SimpleDateFormat("MM/dd/yy HH:mm:ss");
3302 SimpleDateFormat timestampFormat1 = new SimpleDateFormat("yyyy-M-d.HH.mm. s. S");
3303 SimpleDateFormat timestamp_W_dash = new SimpleDateFormat("yyyyMMddHHmmss");
3304 SimpleDateFormat MMDDYYYYHHMMZFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm z");
3305 SimpleDateFormat YYYYFormat = new SimpleDateFormat("yyyy");
3306 java.util.Date date = null;
3310 final int YEARFLAG = 1;
3311 final int MONTHFLAG = 2;
3312 final int DAYFLAG = 3;
3313 final int HOURFLAG = 4;
3314 final int MINFLAG = 5;
3315 final int SECFLAG = 6;
3316 final int MILLISECFLAG = 7;
3317 final int DAYOFTHEWEEKFLAG = 8;
3318 final int FLAGDATE = 9;
3325 int milliSecFlag = 7;
3326 int dayoftheweekFlag = 8;
3330 //date = MMDDYYYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
3331 date = timezoneConversion(MMDDYYYYHHMMSSFormat, dateStr);
3332 if(date!=null) formatFlag = SECFLAG;
3334 //date = EEEMMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
3335 date = timezoneConversion(EEEMMDDYYYYFormat, dateStr);
3336 if(date!=null) formatFlag = DAYOFTHEWEEKFLAG;
3339 //date = MMDDYYYYHHMMFormat.parse(dateStr, new ParsePosition(0));
3340 date = timezoneConversion(MMDDYYYYHHMMFormat, dateStr);
3341 if(date!=null) formatFlag = MINFLAG;
3344 //MMDDYYYYHHFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
3345 //date = MMDDYYYYHHFormat.parse(dateStr, new ParsePosition(0));
3346 date = timezoneConversion(MMDDYYYYHHFormat, dateStr);
3347 if(date!=null) formatFlag = HOURFLAG;
3350 //date = MMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
3351 date = timezoneConversion(MMDDYYYYFormat, dateStr);
3352 if(date!=null) formatFlag = DAYFLAG;
3355 //date = YYYYMMDDFormat.parse(dateStr, new ParsePosition(0));
3356 date = timezoneConversion(YYYYMMDDFormat, dateStr);
3357 if(date!=null) formatFlag = DAYFLAG;
3360 //date = timestampFormat.parse(dateStr, new ParsePosition(0));
3361 date = timezoneConversion(timestampFormat, dateStr);
3362 if(date!=null) formatFlag = SECFLAG;
3365 //date = timestampHrFormat.parse(dateStr, new ParsePosition(0));
3366 date = timezoneConversion(timestampHrFormat, dateStr);
3367 if(date!=null) formatFlag = HOURFLAG;
3370 //date = timestampDayFormat.parse(dateStr, new ParsePosition(0));
3371 date = timezoneConversion(timestampDayFormat, dateStr);
3372 if(date!=null) formatFlag = DAYFLAG;
3376 //date = MONYYYYFormat.parse(dateStr, new ParsePosition(0));
3377 date = timezoneConversion(MONYYYYFormat, dateStr);
3378 if(date!=null) formatFlag = MONTHFLAG;
3381 //date = MMYYYYFormat.parse(dateStr, new ParsePosition(0));
3382 date = timezoneConversion(MMYYYYFormat, dateStr);
3383 if(date!=null) formatFlag = MONTHFLAG;
3386 //date = MMMMMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
3387 date = timezoneConversion(MMMMMDDYYYYFormat, dateStr);
3388 if(date!=null) formatFlag = DAYFLAG;
3391 //date = MONTHYYYYFormat.parse(dateStr, new ParsePosition(0));
3392 date = timezoneConversion(MONTHYYYYFormat, dateStr);
3393 if(date!=null) formatFlag = MONTHFLAG;
3397 //date = YYYYMMDDHHMMSSFormat.parse(dateStr, new ParsePosition(0));
3398 date = timezoneConversion(YYYYMMDDHHMMSSFormat, dateStr);
3399 if(date!=null) formatFlag = SECFLAG;
3403 //date = YYYYMMDDHHMMFormat.parse(dateStr, new ParsePosition(0));
3404 date = timezoneConversion(YYYYMMDDHHMMFormat, dateStr);
3405 if(date!=null) formatFlag = MINFLAG;
3409 //date = DDMONYYYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
3410 date = timezoneConversion(DDMONYYYYHHMMSSFormat, dateStr);
3411 if(date!=null) formatFlag = SECFLAG;
3415 //date = DDMONYYYYHHMMFormat.parse(dateStr, new ParsePosition(0));
3416 date = timezoneConversion(DDMONYYYYHHMMFormat, dateStr);
3417 if(date!=null) formatFlag = MINFLAG;
3421 //date = DDMONYYYYFormat.parse(dateStr, new ParsePosition(0));
3422 date = timezoneConversion(DDMONYYYYFormat, dateStr);
3423 if(date!=null) formatFlag = DAYFLAG;
3427 //date = MMDDYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
3428 date = timezoneConversion(MMDDYYHHMMSSFormat, dateStr);
3429 if(date!=null) formatFlag = SECFLAG;
3433 //date = MMDDYYHHMMFormat.parse(dateStr, new ParsePosition(0));
3434 date = timezoneConversion(MMDDYYHHMMFormat, dateStr);
3435 if(date!=null) formatFlag = MINFLAG;
3439 //date = MMDDYYFormat.parse(dateStr, new ParsePosition(0));
3440 date = timezoneConversion(MMDDYYFormat, dateStr);
3441 if(date!=null) formatFlag = DAYFLAG;
3445 //date = timestampFormat1.parse(dateStr, new ParsePosition(0));
3446 date = timezoneConversion(timestampFormat1, dateStr);
3447 if(date!=null) formatFlag = SECFLAG;
3451 //date = MMDDYYYYHHMMZFormat.parse(dateStr, new ParsePosition(0));
3452 date = timezoneConversion(MMDDYYYYHHMMZFormat, dateStr);
3453 if(date!=null) formatFlag = MINFLAG;
3457 //date = YYYYFormat.parse(dateStr, new ParsePosition(0));
3458 date = timezoneConversion(YYYYFormat, dateStr);
3459 /* Some random numbers should not satisfy this year format. */
3460 if(dateStr.length()>4) date = null;
3461 if(date!=null) formatFlag = YEARFLAG;
3464 //date = timestamp_W_dash.parse(dateStr, new ParsePosition(0));
3465 date = timezoneConversion(timestamp_W_dash, dateStr);
3466 if(date!=null) formatFlag = SECFLAG;
3473 public int getFlagFromDateStr(String dateStr) {
3474 SimpleDateFormat MMDDYYYYFormat = new SimpleDateFormat("MM/dd/yyyy");
3475 SimpleDateFormat EEEMMDDYYYYFormat = new SimpleDateFormat("EEE, MM/dd/yyyy"); //2012-11-01 00:00:00
3476 SimpleDateFormat YYYYMMDDFormat = new SimpleDateFormat("yyyy/MM/dd");
3477 SimpleDateFormat MONYYYYFormat = new SimpleDateFormat("MMM yyyy");
3478 SimpleDateFormat MMYYYYFormat = new SimpleDateFormat("MM/yyyy");
3479 SimpleDateFormat MMMMMDDYYYYFormat = new SimpleDateFormat("MMMMM dd, yyyy");
3480 SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
3481 SimpleDateFormat timestampHrFormat = new SimpleDateFormat("yyyy-MM-dd HH");
3482 SimpleDateFormat timestampDayFormat = new SimpleDateFormat("yyyy-MM-dd");
3483 SimpleDateFormat DDMONYYYYFormat = new SimpleDateFormat("dd-MMM-yyyy");
3484 SimpleDateFormat MONTHYYYYFormat = new SimpleDateFormat("MMMMM, yyyy");
3485 SimpleDateFormat MMDDYYYYHHFormat = new SimpleDateFormat("MM/dd/yyyy HH");
3486 SimpleDateFormat MMDDYYYYHHMMSSFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
3487 SimpleDateFormat MMDDYYYYHHMMFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm");
3488 SimpleDateFormat YYYYMMDDHHMMSSFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
3489 SimpleDateFormat YYYYMMDDHHMMFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm");
3490 SimpleDateFormat DDMONYYYYHHMMSSFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
3491 SimpleDateFormat DDMONYYYYHHMMFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm");
3492 SimpleDateFormat MMDDYYFormat = new SimpleDateFormat("MM/dd/yy");
3493 SimpleDateFormat MMDDYYHHMMFormat = new SimpleDateFormat("MM/dd/yy HH:mm");
3494 SimpleDateFormat MMDDYYHHMMSSFormat = new SimpleDateFormat("MM/dd/yy HH:mm:ss");
3495 SimpleDateFormat timestampFormat1 = new SimpleDateFormat("yyyy-M-d.HH.mm. s. S");
3496 SimpleDateFormat timestamp_W_dash = new SimpleDateFormat("yyyyMMddHHmmss");
3497 SimpleDateFormat MMDDYYYYHHMMZFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm z");
3498 SimpleDateFormat YYYYFormat = new SimpleDateFormat("yyyy");
3499 java.util.Date date = null;
3503 final int YEARFLAG = 1;
3504 final int MONTHFLAG = 2;
3505 final int DAYFLAG = 3;
3506 final int HOURFLAG = 4;
3507 final int MINFLAG = 5;
3508 final int SECFLAG = 6;
3509 final int MILLISECFLAG = 7;
3510 final int DAYOFTHEWEEKFLAG = 8;
3511 final int FLAGDATE = 9;
3518 int milliSecFlag = 7;
3519 int dayoftheweekFlag = 8;
3523 date = MMDDYYYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
3525 formatFlag = SECFLAG;
3527 date = EEEMMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
3529 formatFlag = DAYOFTHEWEEKFLAG;
3532 date = MMDDYYYYHHMMFormat.parse(dateStr, new ParsePosition(0));
3534 formatFlag = MINFLAG;
3537 //MMDDYYYYHHFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
3538 date = MMDDYYYYHHFormat.parse(dateStr, new ParsePosition(0));
3540 formatFlag = HOURFLAG;
3543 date = MMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
3545 formatFlag = DAYFLAG;
3548 date = YYYYMMDDFormat.parse(dateStr, new ParsePosition(0));
3550 formatFlag = DAYFLAG;
3553 date = timestampFormat.parse(dateStr, new ParsePosition(0));
3555 formatFlag = SECFLAG;
3558 date = timestampHrFormat.parse(dateStr, new ParsePosition(0));
3560 formatFlag = HOURFLAG;
3563 date = timestampDayFormat.parse(dateStr, new ParsePosition(0));
3565 formatFlag = DAYFLAG;
3568 date = MONYYYYFormat.parse(dateStr, new ParsePosition(0));
3570 formatFlag = MONTHFLAG;
3573 date = MMYYYYFormat.parse(dateStr, new ParsePosition(0));
3575 formatFlag = MONTHFLAG;
3578 date = MMMMMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
3580 formatFlag = DAYFLAG;
3583 date = MONTHYYYYFormat.parse(dateStr, new ParsePosition(0));
3585 formatFlag = MONTHFLAG;
3589 date = YYYYMMDDHHMMSSFormat.parse(dateStr, new ParsePosition(0));
3591 formatFlag = SECFLAG;
3595 date = YYYYMMDDHHMMFormat.parse(dateStr, new ParsePosition(0));
3597 formatFlag = MINFLAG;
3601 date = DDMONYYYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
3603 formatFlag = SECFLAG;
3607 date = DDMONYYYYHHMMFormat.parse(dateStr, new ParsePosition(0));
3609 formatFlag = MINFLAG;
3613 date = DDMONYYYYFormat.parse(dateStr, new ParsePosition(0));
3615 formatFlag = DAYFLAG;
3619 date = MMDDYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
3621 formatFlag = SECFLAG;
3625 date = MMDDYYHHMMFormat.parse(dateStr, new ParsePosition(0));
3627 formatFlag = MINFLAG;
3631 date = MMDDYYFormat.parse(dateStr, new ParsePosition(0));
3633 formatFlag = DAYFLAG;
3637 date = timestampFormat1.parse(dateStr, new ParsePosition(0));
3639 formatFlag = SECFLAG;
3643 date = MMDDYYYYHHMMZFormat.parse(dateStr, new ParsePosition(0));
3645 formatFlag = MINFLAG;
3649 date = YYYYFormat.parse(dateStr, new ParsePosition(0));
3650 /* Some random numbers should not satisfy this year format. */
3651 if(dateStr.length()>4)
3654 formatFlag = YEARFLAG;
3657 date = timestamp_W_dash.parse(dateStr, new ParsePosition(0));
3659 formatFlag = SECFLAG;
3666 public static String[] reverse(String[] arr) {
3667 List<String> list = Arrays.asList(arr);
3668 Collections.reverse(list);
3669 return (String[])list.toArray();
3672 public int getNumberOfDecimalPlaces(double num) {
3674 String[] splitter = d.toString().split("\\.");
3675 splitter[0].length(); // Before Decimal Count
3676 splitter[1].length(); // After Decimal Count
3677 return splitter[1].length();
3680 public boolean getBooleanValue(String s) {
3681 return getBooleanValue(s,null);
3684 public boolean getBooleanValue(String s, Boolean defaultValue) {
3686 if(s.length()<=0 && defaultValue!=null)
3687 return defaultValue.booleanValue();
3688 else if(s.length()<=0)
3691 if(s.toUpperCase().startsWith("Y") || s.toLowerCase().equals("true"))
3699 public String IntToLetter(int Int) {
3701 return Character.toString((char)(Int+96));
3704 return IntToLetter((Int/26)-1)+IntToLetter((Int%26)+1);
3706 return IntToLetter(Int/26)+IntToLetter(Int%26);
3714 private void clearReportRuntimeBackup(HttpServletRequest request) {
3715 //Session sess = Sessions.getCurrent(true)getCurrent();
3716 //HttpSession session = (HttpSession)sess.getNativeSession();
3717 HttpSession session = request.getSession();
3718 session.removeAttribute(AppConstants.DRILLDOWN_REPORTS_LIST);
3719 request.removeAttribute(AppConstants.DRILLDOWN_INDEX);
3720 session.removeAttribute(AppConstants.DRILLDOWN_INDEX);
3721 request.removeAttribute(AppConstants.FORM_DRILLDOWN_INDEX);
3722 session.removeAttribute(AppConstants.FORM_DRILLDOWN_INDEX);
3723 Enumeration<String> enum1 = session.getAttributeNames();
3724 String attributeName = "";
3725 while(enum1.hasMoreElements()) {
3726 attributeName = enum1.nextElement();
3727 if(attributeName.startsWith("parent_")) {
3728 session.removeAttribute(attributeName);
3731 session.removeAttribute(AppConstants.DRILLDOWN_REPORTS_LIST);
3732 session.removeAttribute(AppConstants.SI_BACKUP_FOR_REP_ID);
3733 session.removeAttribute(AppConstants.SI_COLUMN_LOOKUP);
3734 session.removeAttribute(AppConstants.SI_DASHBOARD_REP_ID);
3735 session.removeAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP);
3736 session.removeAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME);
3737 session.removeAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP);
3738 session.removeAttribute(AppConstants.SI_DASHBOARD_CHARTDATA_MAP);
3739 session.removeAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP);
3740 session.removeAttribute(AppConstants.SI_DATA_SIZE_FOR_TEXTFIELD_POPUP);
3741 session.removeAttribute(AppConstants.SI_MAP);
3742 session.removeAttribute(AppConstants.SI_MAP_OBJECT);
3743 session.removeAttribute(AppConstants.SI_REPORT_DEFINITION);
3744 session.removeAttribute(AppConstants.SI_REPORT_RUNTIME);
3745 session.removeAttribute(AppConstants.SI_REPORT_RUN_BACKUP);
3746 session.removeAttribute(AppConstants.SI_REPORT_SCHEDULE);
3747 session.removeAttribute(AppConstants.RI_REPORT_DATA);
3748 session.removeAttribute(AppConstants.RI_CHART_DATA);
3749 session.removeAttribute(AppConstants.SI_FORMFIELD_INFO);
3750 session.removeAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO);
3752 } // clearReportRuntimeBackup
3755 public static synchronized java.util.HashMap getRequestParametersMap(ReportRuntime rr, HttpServletRequest request)
3757 HashMap valuesMap = new HashMap();
3759 ReportFormFields rff = rr.getReportFormFields();
3762 FormField ff = null;
3764 Map fieldNameMap = new HashMap();
3765 int countOfFields = 0 ;
3768 for(rff.resetNext(); rff.hasNext(); idx++) {
3770 fieldNameMap.put(ff.getFieldName(), ff.getFieldDisplayName());
3774 List formParameter = new ArrayList();
3775 String formField = "";
3776 for(int i = 0 ; i < rff.size(); i++) {
3777 ff = ((FormField)rff.getFormField(i));
3778 formField = ff.getFieldName();
3779 boolean isMultiValue = false;
3780 isMultiValue = ff.getFieldType().equals(FormField.FFT_CHECK_BOX)
3781 || ff.getFieldType().equals(FormField.FFT_LIST_MULTI);
3782 boolean isTextArea = (ff.getFieldType().equals(FormField.FFT_TEXTAREA) && rr.getReportDefType()
3783 .equals(AppConstants.RD_SQL_BASED));
3785 if(request.getParameterValues(formField) != null && isMultiValue ) {
3786 String[] vals = request.getParameterValues(formField);
3787 StringBuilder value = new StringBuilder("");
3788 if(!AppUtils.getRequestFlag(request, AppConstants.RI_RESET_ACTION)) {
3790 if ( isMultiValue ) {
3793 for(int j = 0 ; j < vals.length; j++) {
3797 if(vals[j] !=null && vals[j].length() > 0) {
3798 vals[j] = Utils.oracleSafe(vals[j]);
3799 value.append(java.net.URLDecoder.decode(vals[j], "UTF-8"));// + ",";
3802 value.append(vals[j]);
3803 } catch (UnsupportedEncodingException ex) {value.append(vals[j]);}
3804 catch (IllegalArgumentException ex1){value.append(vals[j]);}
3805 catch (Exception ex2){
3806 value.append(vals[j]);
3813 if(j != vals.length -1) {
3817 if(vals.length > 0) {
3822 //value = value.substring(0 , value.length());
3824 valuesMap.put(fieldNameMap.get(formField), value.toString());
3825 } else if(request.getParameter(formField) != null) {
3828 value = request.getParameter(formField);
3830 value = Utils.oracleSafe(value);
3831 value = "('" + Utils.replaceInString(value, ",", "'|'") + "')";
3832 value = Utils.replaceInString(value, "|", ",");
3833 valuesMap.put(fieldNameMap.get(formField), value);
3837 if(!AppUtils.getRequestFlag(request, AppConstants.RI_RESET_ACTION))
3838 value = request.getParameter(formField);
3839 valuesMap.put(fieldNameMap.get(formField), Utils.oracleSafe(value));
3843 valuesMap.put(fieldNameMap.get(formField), "" );
3852 public static int getCurrentTimezoneOffset() {
3854 TimeZone tz = TimeZone.getDefault();
3855 java.util.Calendar cal = GregorianCalendar.getInstance(tz);
3856 int offsetInMillis = tz.getOffset(cal.getTimeInMillis());
3857 int hourOffset = Math.abs(offsetInMillis / 3600000) * 60;
3858 boolean isDST = tz.inDaylightTime(new java.util.Date());
3862 int offset = hourOffset + Math.abs((offsetInMillis / 60000) % 60);
3863 if (offsetInMillis > 0)
3866 return Globals.getTimezoneOffset();