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;
62 import javax.servlet.http.HttpServletRequest;
63 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 //Object uniqueElements [] = ts.toArray();
282 //SortedSet s = Collections.synchronizedSortedSet(ts);
283 uniqueElements = ts.toArray();
285 DataColumnType dct = null;
286 List yTextSeries = reportRuntime.getChartDisplayNamesList(AppConstants.CHART_ALL_COLUMNS, formValues);
287 //if(columnValuesList.size() == 1) {
288 for (Iterator iter = l.iterator(); iter.hasNext();) {
289 dct = (DataColumnType) iter.next();
291 if(!(nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND))) {
292 if((dct.isChartSeries()!=null && dct.isChartSeries().booleanValue()) || (dct.getChartSeq()!=null && dct.getChartSeq()>0) ) {
294 if(nvl(dct.getChartColor()).length()>0)
295 hasCustomizedChartColor = true;
296 if(hasCustomizedChartColor) {
297 //duplicates are avoided
298 if(!ts.contains(dct.getDisplayName()+"|"+nvl(dct.getChartColor())))
299 ts.add(dct.getDisplayName()+"|"+nvl(dct.getChartColor()));
301 //duplicates are avoided
302 if(!ts.contains(dct.getDisplayName()))
303 ts.add(dct.getDisplayName());
305 if(nvl(chartLeftAxisLabel).length()<=0) {
306 chartLeftAxisLabel = nvl(dct.getYAxis());
307 chartLeftAxisLabel = (chartLeftAxisLabel.indexOf("|")!=-1)?chartLeftAxisLabel.substring(0,chartLeftAxisLabel.indexOf("|")):"";
309 columnMap.put(dct.getDisplayName(), dct.getColId());
311 ts.add(dct.getDisplayName());
312 if(nvl(chartLeftAxisLabel).length()<=0) {
313 chartLeftAxisLabel = nvl(dct.getYAxis());
314 chartLeftAxisLabel = (chartLeftAxisLabel.indexOf("|")!=-1)?chartLeftAxisLabel.substring(0,chartLeftAxisLabel.indexOf("|")):"";
316 columnMap.put(dct.getDisplayName(), dct.getColId());
322 //SortedSet s = Collections.synchronizedSortedSet(ts);
323 uniqueElements = ts.toArray();
327 wholeScript.append("<!DOCTYPE html>\n");
328 wholeScript.append("<html>\n");
329 wholeScript.append("<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF8\">\n");
330 wholeScript.append("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n");
331 wholeScript.append("<link href=\""+ chartScriptsPath +"d3/css/nv.d3.css\" rel=\"stylesheet\" type=\"text/css\">\n");
332 //wholeScript.append("")
333 wholeScript.append("<style>\n " +
335 " overflow-y:scroll; \n" +
338 " font: 12px sans-serif; \n" +
341 " display: block;\n" +
343 " #chart"+reportRuntime.getReportID()+" svg { \n" +
344 " height: "+ (nvl(height).length()>0?(height.endsWith("px")?height:height+"px"):"420px") + "; \n" +
345 " width: "+ (nvl(width).length()>0?(width.endsWith("px")?width:width+"px"):"700px") + "; \n" +
346 " min-width: 100px; \n" +
347 " min-height: 100px; \n" +
349 " tr.z-row-over > td.z-row-inner, tr.z-row-over > .z-cell {" +
350 " background-color: rgb(255, 255, 255); "+
353 wholeScript.append(".nodatadiv {\n");
354 wholeScript.append(" display: table-cell;\n");
355 wholeScript.append(" width: 700px;\n");
356 wholeScript.append(" height:370px;\n");
357 wholeScript.append(" text-align:center;\n");
358 wholeScript.append(" vertical-align: middle;\n");
359 wholeScript.append("}\n");
360 wholeScript.append(".nodatainner {\n");
361 wholeScript.append(" padding: 10px;\n");
362 wholeScript.append("}\n");
364 wholeScript.append(" </style> \n" );
365 wholeScript.append("<body> \n");
367 wholeScript.append("<div align=\"center\"><H3>" + title +"</H3></div>");
369 wholeScript.append("<div id=\"chart"+reportRuntime.getReportID()+"\"> <svg></svg> </div> \n");
371 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/d3.v3.min.js\"></script>");
372 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/nv.d3.min.js\"></script> \n");
373 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/tooltip.js\"></script> \n");
374 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/utils.js\"></script> \n");
375 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/models/axis.min.js\"></script> \n");
376 //wholeScript.append("<script src=\""+ AppUtils.getBaseFolderURL() +"d3/js/models/discreteBar.js\"></script> \n");
377 //wholeScript.append("<script src=\""+ AppUtils.getBaseFolderURL() +"d3/js/models/discreteBarChart.js\"></script> \n");
378 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/models/multiChart.js\"></script> \n");
380 wholeScript.append("<script> \n");
381 wholeScript.append("historicalBarChart = [ \n");
382 //wholeScript.append("{ \n");
384 ArrayList dataSeries = new ArrayList();
386 String uniqueElement = "";
387 for (int i = 0; i < uniqueElements.length; i++) {
388 uniqueElement = (String)uniqueElements[i];
389 if(multipleSeries && (nvl(chartRightAxisLabel).length() > 0))
390 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\": ["));
392 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\": ["));
395 // added to load all date elements
396 HashMap<String, HashMap<String, String>> dataSeriesMap = new HashMap<>();
398 for (int i = 0; i < uniqueElements.length; i++) {
399 if(multipleSeries && (nvl(chartRightAxisLabel).length() > 0))
400 dataSeriesMap.put((String) uniqueElements[i], new HashMap<String, String>());
402 dataSeriesMap.put((String) uniqueElements[i], new HashMap<String, String>());
405 String dateStr = null;
406 java.util.Date date = null;
408 final int YEARFLAG = 1;
409 final int MONTHFLAG = 2;
410 final int DAYFLAG = 3;
411 final int HOURFLAG = 4;
412 final int MINFLAG = 5;
413 final int SECFLAG = 6;
414 final int MILLISECFLAG = 7;
415 final int DAYOFTHEWEEKFLAG = 8;
416 final int FLAGDATE = 9;
424 double YAXISDOUBLENUM = 0.0;
425 double MAXDOUBLENUM = 0.0;
426 int MAXNUMDECIMALPLACES = 0;
430 TreeSet<String> dateStrList = new TreeSet<>();
431 // added to store all date elements
432 SortedSet<String> sortSet = new TreeSet<>();
435 HashMap dataSeriesStrMap = new HashMap();
436 HashMap dataSeriesOverAllMap = new HashMap();
437 String valueDataSeries = "";
439 for (int j = 0; j < uniqueElements.length; j++) {
440 dataSeriesStrMap = new HashMap();
441 for (int i = 0; i < ds.getRowCount(); i++) {
444 YAXISDOUBLENUM = 0.0;
446 dateStr = ds.getString(i, 1);
448 date = getDateFromDateStr(dateStr);
449 formatFlag = getFlagFromDateStr(dateStr);
451 uniqueElement = (String)uniqueElements[j];
456 //if(!((String)uniqueElementsList.get(i)).equals(dateStr)) {
457 for (int f=0 ; f< uniqueXAxisElements.length; f++) {
458 if(uniqueXAxisElements[f].equals(dateStr)){
464 dateStrList.add("'"+dateStr+"'");
465 //uniqueElement = (String)uniqueElements[j];
467 YAXISNUM = Integer.parseInt(ds.getString(i, columnMap.get((hasCustomizedChartColor?(uniqueElement.indexOf("|")!=-1?uniqueElement.substring(0, uniqueElement.indexOf("|")):uniqueElement):uniqueElement))));
468 //if(MAXNUM < YAXISNUM) MAXNUM = YAXISNUM;
469 if(MAXDOUBLENUM < YAXISNUM)
470 MAXDOUBLENUM = YAXISNUM;
471 } catch (NumberFormatException ex) {
473 YAXISDOUBLENUM = Double.parseDouble(ds.getString(i, columnMap.get((hasCustomizedChartColor?(uniqueElement.indexOf("|")!=-1?uniqueElement.substring(0, uniqueElement.indexOf("|")):uniqueElement):uniqueElement))));
474 MAXNUMDECIMALPLACES = getNumberOfDecimalPlaces(YAXISDOUBLENUM);
475 if(MAXDOUBLENUM < YAXISDOUBLENUM)
476 MAXDOUBLENUM = YAXISDOUBLENUM;
477 } catch (NumberFormatException ex1) {
482 /* For Non-date type value enclose with double quotes */
486 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) +"}, ";
487 dataSeriesStrMap.put(dateStr, valueDataSeries);
489 valueDataSeries = "{ \"x\":\"" + dateStr + "\" , \"y\":" + (flagNull == 0 ? (YAXISDOUBLENUM>0?YAXISDOUBLENUM:YAXISNUM): null) +"}, ";
490 dataSeriesStrMap.put(dateStr, valueDataSeries);
494 dataSeriesOverAllMap.put(uniqueElements[j], dataSeriesStrMap);
498 if(!barRealTimeAxis) { // true - non-time
499 if(!dateStrList.contains(new Long(date.getTime()).toString())) {
500 dateStrList.add(new Long(date.getTime()).toString());
501 for (int k = 0; k < uniqueElements.length; k++) {
502 HashMap<String, String> dataMap = dataSeriesMap.get((String) uniqueElements[k]);
503 dataMap.put(date.getTime()+"", "null");
510 YAXISNUM = Integer.parseInt(ds.getString(i, columnMap.get(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1)?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))));
511 dateStrList.add(new Long(date.getTime()).toString());
513 if(MAXDOUBLENUM < YAXISNUM)
514 MAXDOUBLENUM = YAXISNUM;
515 } catch (NumberFormatException ex) {
517 YAXISDOUBLENUM = Double.parseDouble(ds.getString(i, columnMap.get(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1) ?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))));
518 MAXNUMDECIMALPLACES = getNumberOfDecimalPlaces(YAXISDOUBLENUM);
519 if(MAXDOUBLENUM < YAXISDOUBLENUM)
520 MAXDOUBLENUM = YAXISDOUBLENUM;
521 } catch (NumberFormatException ex1) {
527 HashMap<String, String> dataMap = dataSeriesMap.get((String) uniqueElements[j]);
529 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"));
531 dataMap.put(date.getTime()+"", (flagNull == 0 ? (YAXISDOUBLENUM>0?new Double(YAXISDOUBLENUM).toString():new Integer(YAXISNUM).toString()): "null"));
540 for(int kI = 0; kI < uniqueElements.length; kI++) {
541 HashMap dataSeriesStrMap1 = (HashMap) dataSeriesOverAllMap.get(uniqueElements[kI]);
542 for (int kL = 0; kL < uniqueXAxisElements.length; kL++) {
543 if(dataSeriesStrMap1.containsKey(uniqueXAxisElements[kL])) {
544 ((StringBuffer) dataSeries.get(kI)).append ((String)dataSeriesStrMap1.get(uniqueXAxisElements[kL]));
546 ((StringBuffer) dataSeries.get(kI)).append ("{ \"x\":\"" + uniqueXAxisElements[kL] + "\" , \"y\": null }, ");
552 HashMap dataSeriesStrMap = new HashMap();
553 HashMap dataSeriesOverAllMap = new HashMap();
554 String valueDataSeries = "";
555 for (int j = 0; j < uniqueElements.length; j++) {
556 dataSeriesStrMap = new HashMap();
558 for (int i = 0; i < ds.getRowCount(); i++) {
561 YAXISDOUBLENUM = 0.0;
563 //flagSecondNull = 0;
564 dateStr = ds.getString(i, 1);
566 date = getDateFromDateStr(dateStr);
567 formatFlag = getFlagFromDateStr(dateStr);
569 uniqueElement = (String)uniqueElements[j];
574 //if(!((String)uniqueElementsList.get(i)).equals(dateStr)) {
575 for (int f=0 ; f< uniqueXAxisElements.length; f++) {
576 if(uniqueXAxisElements[f].equals(dateStr)){
583 if(ds.getString(i, 2).equals(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1) ?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))) {
584 dateStrList.add("'"+dateStr+"'");
586 YAXISNUM = Integer.parseInt(ds.getString(i, 3));
587 if(MAXDOUBLENUM < YAXISNUM)
588 MAXDOUBLENUM = YAXISNUM;
589 } catch (NumberFormatException ex) {
591 YAXISDOUBLENUM = Double.parseDouble(ds.getString(i, 3));
592 MAXNUMDECIMALPLACES = getNumberOfDecimalPlaces(YAXISDOUBLENUM);
593 if(MAXDOUBLENUM < YAXISDOUBLENUM)
594 MAXDOUBLENUM = YAXISDOUBLENUM;
595 } catch (NumberFormatException ex1) {
604 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) +"}, ";
605 dataSeriesStrMap.put(dateStr, valueDataSeries);
607 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) +"}, ";
608 dataSeriesStrMap.put(dateStr, valueDataSeries);
612 valueDataSeries = "{ \"x\":" + dateStr + " , \"y\":" + (flagNull == 0 ? (YAXISDOUBLENUM>0?YAXISDOUBLENUM:YAXISNUM): null) +"}, ";
613 dataSeriesStrMap.put(dateStr, valueDataSeries);
616 valueDataSeries = "{ \"x\":\"" + dateStr + "\" , \"y\":" + (flagNull == 0 ? (YAXISDOUBLENUM>0?YAXISDOUBLENUM:YAXISNUM): null) +"}, ";
617 dataSeriesStrMap.put(dateStr, valueDataSeries);
623 dataSeriesOverAllMap.put(uniqueElements[j], dataSeriesStrMap);
625 //date = MMDDYYYYFormat.parse(ds.getString(i, 1), new ParsePosition(0));
626 if(!barRealTimeAxis) { // true - non-time
627 if(!dateStrList.contains(new Long(date.getTime()).toString())) {
628 dateStrList.add(new Long(date.getTime()).toString());
629 for (int k = 0; k < uniqueElements.length; k++) {
630 HashMap<String, String> dataMap = dataSeriesMap.get((String) uniqueElements[k]);
631 dataMap.put(date.getTime()+"", "null");
636 if(ds.getString(i, 2).equals(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1) ?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))) {
637 dateStrList.add(new Long(date.getTime()).toString());
639 YAXISNUM = Integer.parseInt(ds.getString(i, 3));
640 if(MAXDOUBLENUM < YAXISNUM)
641 MAXDOUBLENUM = YAXISNUM;
642 } catch (NumberFormatException ex) {
644 YAXISDOUBLENUM = Double.parseDouble(ds.getString(i, 3));
645 MAXNUMDECIMALPLACES = getNumberOfDecimalPlaces(YAXISDOUBLENUM);
646 if(MAXDOUBLENUM < YAXISDOUBLENUM)
647 MAXDOUBLENUM = YAXISDOUBLENUM;
648 } catch (NumberFormatException ex1) {
655 //if(ds.getString(i, 2).equals(uniqueElements[j])) {
656 // dateStrList.add("'"+dateStr+"'");
657 HashMap<String, String> dataMap = dataSeriesMap.get((String) uniqueElements[j]);
659 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"));
661 if(dataMap.containsKey(new String(""+date.getTime())) && dataMap.get(new String(""+date.getTime())).equals("null")) {
662 dataMap.remove(date.getTime());
664 dataMap.put(date.getTime()+"", (flagNull == 0 ? (YAXISDOUBLENUM>0?new Double(YAXISDOUBLENUM).toString():new Integer(YAXISNUM).toString()): "null"));
666 // .println(dataMap + " " + dataSeriesMap);
670 } else if (AppUtils.nvl(ds.getString(i, 2)).length()<=0) {
671 dateStrList.add(new Long(date.getTime()).toString());
672 HashMap<String, String> dataMap1 = null;
673 String uniqueElement1 = "";
674 for (int j1 = 0; j1 < uniqueElements.length; j1++) {
675 uniqueElement1 = (String)uniqueElements[j];
676 if(ds.getString(i, 2).equals(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement1.lastIndexOf("|") != -1) ?uniqueElement1.substring(0, uniqueElement1.lastIndexOf("|")):uniqueElement1))) {
677 dataMap1 = dataSeriesMap.get((String) uniqueElements[j1]);
678 if(!dataMap1.containsKey(new String(""+date.getTime())))
679 dataMap1.put(date.getTime()+"", "null");
684 // dataSeriesOverAllMap.put(uniqueElements[j], dataSeriesMap);
688 for(int kI = 0; kI < uniqueElements.length; kI++) {
689 HashMap dataSeriesStrMap1 = (HashMap) dataSeriesOverAllMap.get(uniqueElements[kI]);
690 for (int kL = 0; kL < uniqueXAxisElements.length; kL++) {
691 if(dataSeriesStrMap1.containsKey(uniqueXAxisElements[kL])) {
692 ((StringBuffer) dataSeries.get(kI)).append ((String)dataSeriesStrMap1.get(uniqueXAxisElements[kL]));
694 ((StringBuffer) dataSeries.get(kI)).append ("{ \"x\":\"" + uniqueXAxisElements[kL] + "\" , \"y\": null }, ");
700 StringBuilder dateStrBuf = new StringBuilder("");
702 if(dateStrList.size()>0) {
703 SortedSet<String> s = Collections.synchronizedSortedSet(dateStrList);
704 Object[] dateElements = (Object[]) s.toArray();
707 /* if not date value */
709 for (int i = 0; i < dateElements.length; i++) {
710 dateStrBuf.append(dateElements[i]+",");
713 if(!barRealTimeAxis || (flagNoDate == 1)) { // non-time
714 for (int i = 0; i < dateElements.length; i++) {
715 dateStrBuf.append(dateElements[i]+",");
718 Long initialDate = Long.parseLong((String)dateElements[0]);
719 Long endDate = Long.parseLong((String) dateElements[dateElements.length-1]);
720 java.util.Date date1 = null;
722 date1 = new java.util.Date(initialDate.longValue());
723 /* DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss Z");
724 System.out.println(formatter.format(new java.util.Date(initialDate.longValue())));
725 */ //initialDate = initialDate + HOUR;
727 dateStrBuf.append(initialDate+",");
728 sortSet.add(""+initialDate);
732 while ( initialDate <= endDate) {
733 //System.out.println("********** " + df.format(initialDate));
734 //date1 = new java.util.Date(initialDate.longValue() * 1000);
735 date1 = new java.util.Date(initialDate.longValue());
736 if(formatFlag==HOURFLAG)
737 date1 = DateUtils.addHours(date1, 1);
738 else if(formatFlag==MINFLAG)
739 date1 = DateUtils.addMinutes(date1, 30);
740 else if (formatFlag == DAYFLAG)
741 date1 = DateUtils.addDays(date1, 1);
742 else if (formatFlag == MONTHFLAG)
743 date1 = DateUtils.addMonths(date1, 1);
744 else if (formatFlag == YEARFLAG)
745 date1 = DateUtils.addMonths(date1, 1);
746 initialDate = date1.getTime();
748 if(initialDate <= endDate) {
749 dateStrBuf.append(initialDate+",");
750 sortSet.add(""+initialDate);
752 //DateUtils.addHours(date1, 1);
754 //DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);
755 //df.setTimeZone(TimeZone.getTimeZone("UTC"));
756 //java.util.Date date1 = new java.util.Date(initialDate.longValue() * 1000);
757 //java.util.Date d = df.
761 dateStrBuf.deleteCharAt(dateStrBuf.length()-1);
765 //if(!barRealTimeAxis) { // false - non-time
766 Object[] dateAllElements = (Object[]) sortSet.toArray();
768 for (int i = 0; i < uniqueElements.length; i++) {
769 HashMap<String, String> dataMap = dataSeriesMap.get((String)uniqueElements[i]);
770 for (int j=0; j<dateAllElements.length;j++) {
771 //if(strBuf.toString().indexOf((String) dateAllElements[j]) == -1) {
772 if(!dataMap.containsKey((String) dateAllElements[j])) {
773 dataMap.put((String) dateAllElements[j], "null");
779 String valueStr = "";
780 for (int i = 0; i < uniqueElements.length; i++) {
781 HashMap<String, String> dataMap = dataSeriesMap.get((String)uniqueElements[i]);
782 Set<String> keySet = dataMap.keySet();
783 ArrayList<String> keySortedList = new ArrayList<>(new TreeSet<String>(keySet));
785 for (int k=0; k < keySortedList.size(); k++) {
786 valueStr = dataSeriesMap.get((String)uniqueElements[i]).get(keySortedList.get(k));
787 if(valueStr.equals("null"))
790 ((StringBuffer) dataSeries.get(i)).append ("{ \"x\":" + keySortedList.get(k) + " , \"y\":" + valueStr +"}, ");
796 for (int i = 0; i < uniqueElements.length; i++) {
797 ((StringBuffer) dataSeries.get(i)).deleteCharAt(((StringBuffer) dataSeries.get(i)).lastIndexOf(","));
798 if(i < (uniqueElements.length -1) ) {
799 ((StringBuffer) dataSeries.get(i)).append("] } , \n");
802 ((StringBuffer) dataSeries.get(i)).append("] } \n");
805 if(ds.getRowCount() > 0) {
806 for (int i = 0; i < uniqueElements.length; i++) {
807 wholeScript.append((StringBuffer)dataSeries.get(i));
812 wholeScript.append("]; \n");
814 //add global variable
815 wholeScript.append("var chart; \n");
816 //javascript to create Bar Chart
817 wholeScript.append("nv.addGraph(function() { \n");
818 if(horizontalBar /*&& flagNoDate == 1*/)
819 wholeScript.append(" chart = nv.models.multiBarHorizontalChart() \n");
820 else /*if (flagNoDate == 1)*/
821 wholeScript.append(" chart = nv.models.multiBarChart() \n");
823 wholeScript.append(" var chart = nv.models.multiBarTimeSeriesChart() \n");*/
825 wholeScript.append(" .margin({top: "+ topMargin +", right: "+ rightMargin +", bottom: "+ bottomMargin +", left: " + leftMargin +"}) \n");
827 wholeScript.append(" .showLegend(true) \n ");
829 wholeScript.append(" .showLegend(false) \n ");
831 if(!horizontalBar && barReduceXAxisLabels)
832 wholeScript.append(" .reduceXTicks(true) \n ");
833 else if (!horizontalBar) {
834 wholeScript.append(" .reduceXTicks(false) \n ");
835 //wholeScript.append(" chart.lines1.forceY(["+(nvl(reportRuntime.getRangeAxisLowerLimit()).length()<=0?"0":reportRuntime.getRangeAxisLowerLimit()) +", "+ (nvl(reportRuntime.getRangeAxisUpperLimit()).length()<=0?UPPER_RANGE:reportRuntime.getRangeAxisUpperLimit()) + "]); \n" +
836 double UPPER_RANGE = 0;
837 if(Math.ceil((MAXDOUBLENUM+(MAXDOUBLENUM*25/100))/100) * 100 >= 1) {
838 UPPER_RANGE = Math.ceil(MAXDOUBLENUM+(MAXDOUBLENUM*25/100));
839 } else UPPER_RANGE = 1;
840 wholeScript.append(" .forceY(["+(nvl(reportRuntime.getRangeAxisLowerLimit()).length()<=0?"0":reportRuntime.getRangeAxisLowerLimit()) +", "+ (nvl(reportRuntime.getRangeAxisUpperLimit()).length()<=0?UPPER_RANGE:reportRuntime.getRangeAxisUpperLimit()) + "])\n");
843 wholeScript.append(" .delay(0) \n ");
846 wholeScript.append(" .showControls(true) \n ");
847 } else if (!showControls){
848 wholeScript.append(" .showControls(false) \n ");
850 if(stacked && !logScale)
851 wholeScript.append(" .stacked(true)\n ");
852 else if(!stacked || logScale)
853 wholeScript.append(" .stacked(false)\n ");
855 wholeScript.append(" .logScale(true)\n ");
857 wholeScript.append(" .logScale(false)\n ");
860 if(AppUtils.nvl(reportRuntime.getLegendPosition()).length()>=0 && reportRuntime.getLegendPosition().equals("right")) {
861 wholeScript.append(" .legendPos('right')\n" );
863 wholeScript.append(" .legendPos('top')\n" );
865 if(uniqueElements.length <= 10) {
866 wholeScript.append(" .color(d3.scale.category10().range()); \n" +
868 } else if (uniqueElements.length <= 20) {
869 wholeScript.append(" .color(d3.scale.category50().range()); \n" +
872 wholeScript.append(" .color(d3.scale.category50().range()); \n" +
878 wholeScript.append(" .tickValues(["+ dateStrBuf.toString() + "])\n ");
880 wholeScript.append(" .tickValues(["+ dateStrBuf.toString() + "])\n ");
883 wholeScript.append(" .staggerLabels(true) \n");
885 wholeScript.append(" .staggerLabels(false) \n");
889 wholeScript.append(" .showMaxMin(true) \n ");
891 wholeScript.append(" .showMaxMin(false) \n ");
894 if(nvl(rotateLabels).length()>0) {
895 wholeScript.append(" .rotateLabels("+ rotateLabels+ ") \n ");
897 wholeScript.append(" .rotateLabels(\"0\") \n ");
899 wholeScript.append(" .axisLabel('" + legendColumnName + "')");
900 if(flagNoDate == 1 || !timeAxis) {
901 wholeScript.append(";\n");
903 wholeScript.append("\n .tickFormat(function(d) { \n");
905 if(formatFlag==HOURFLAG)
906 wholeScript.append(" return d3.time.format('%x %H')(new Date(d)) }); \n");
907 else if(formatFlag==MINFLAG)
908 wholeScript.append(" return d3.time.format('%x %H:%M')(new Date(d)) }); \n");
909 else if(formatFlag==SECFLAG)
910 wholeScript.append(" return d3.time.format('%X')(new Date(d)) }); \n");
911 else if(formatFlag==MONTHFLAG)
912 wholeScript.append(" return d3.time.format('%b %y')(new Date(d)) }); \n");
914 wholeScript.append(" return d3.time.format('%x')(new Date(d)) }); \n");
917 wholeScript.append(" return d; }); \n");
921 if(nvl(chartRightAxisLabel).length() > 0) {
922 //if(flagNoDate == 1)
923 wholeScript.append(" chart.yAxis\n");
925 // wholeScript.append(" chart.yAxis1\n");
927 wholeScript.append(" .logScale(true)\n ");
929 wholeScript.append(" .logScale(false)\n ");
932 wholeScript.append(" .axisLabel('" + chartLeftAxisLabel + "') \n" +
933 " .tickFormat(d3.format(',.0f')); \n");
934 /*" chart.yAxis2\n " +
935 " .axisLabel('" + chartRightAxisLabel + "') \n" +
936 " .tickFormat(d3.format(',.0f')); \n");*/
940 //if(flagNoDate == 1)
941 wholeScript.append(" chart.yAxis\n");
943 // wholeScript.append(" chart.yAxis1\n");
945 wholeScript.append(" .logScale(true)\n ");
947 wholeScript.append(" .logScale(false)\n ");
949 wholeScript.append(" .axisLabel('" + chartLeftAxisLabel + "') \n");
951 if(MAXDOUBLENUM <=5 && MAXNUMDECIMALPLACES == 0 )
952 MAXNUMDECIMALPLACES = 2;
953 if( MAXNUMDECIMALPLACES >=3 )
954 MAXNUMDECIMALPLACES = 2;
956 wholeScript.append(" .tickFormat(d3.format(',."+MAXNUMDECIMALPLACES+"f')); \n");
958 wholeScript.append(" .tickFormat(d3.format(',." + precision + "f')); \n");
959 //" .tickFormat(d3.format(',.0f')); \n");
961 wholeScript.append(" d3.select('#chart"+reportRuntime.getReportID()+" svg') \n" +
962 " .datum(historicalBarChart) \n" );
964 wholeScript.append(" .transition().duration(1000) \n" );
966 wholeScript.append(" .transition().duration(0) \n" );
967 wholeScript.append(" .call(chart); \n" +
968 "nv.utils.windowResize(chart.update); \n" +
971 wholeScript.append("function redraw() { \n");
972 //wholeScript.append(" nv.utils.windowResize(chart.update); \n");
973 wholeScript.append(" d3.select('#chart"+reportRuntime.getReportID()+" svg') \n") ;
974 wholeScript.append(" .datum(historicalBarChart) \n");
975 wholeScript.append(" .transition().duration(500) \n");
976 wholeScript.append(" .call(chart); \n");
977 wholeScript.append("} \n");
978 wholeScript.append("\n");
979 wholeScript.append(" setInterval(function () { \n");
980 wholeScript.append(" redraw(); \n");
981 wholeScript.append(" }, 1500) \n");
983 wholeScript.append("if(historicalBarChart.length <= 0 ) {\n");
984 wholeScript.append(" document.getElementById(\"chart"+reportRuntime.getReportID()+"\").innerHTML = \"<div id='noData'><b>No Data Available</b></div>\";\n");
985 wholeScript.append(" document.getElementById(\"chart"+reportRuntime.getReportID()+"\").className=\"nodatadiv\";\n");
986 wholeScript.append(" document.getElementById(\"nodata\").className=\"nodatainner\";\n");
987 wholeScript.append("}\n");
988 wholeScript.append("</script> </body></html> \n");
990 } else if (chartType.equals(AppConstants.GT_TIME_SERIES)) {
992 // get category if not give the column name for the data column use this to develop series.
993 boolean hasCategoryAxis = reportRuntime.hasSeriesColumn();
996 final int YEARFLAG = 1;
997 final int MONTHFLAG = 2;
998 final int DAYFLAG = 3;
999 final int HOURFLAG = 4;
1000 final int MINFLAG = 5;
1001 final int SECFLAG = 6;
1002 final int MILLISECFLAG = 7;
1003 final int DAYOFTHEWEEKFLAG = 8;
1004 final int FLAGDATE = 9;
1007 flag = hasCategoryAxis?1:0;
1008 String uniqueElements [] = null;
1009 //TreeSet ts = new TreeSet();
1010 ArrayList ts = new ArrayList<String>();
1011 HashMap<String, String> columnMap = new HashMap();
1013 String dateStr = null;
1014 java.util.Date date = null;
1015 if( ds.getRowCount() > 0) {
1016 dateStr = ds.getString(0, 1);
1018 date = getDateFromDateStr(dateStr);
1020 reportRuntime.setTimeAxis(true);
1021 timeAxis = reportRuntime.isTimeAxis();
1028 ArrayList<String> ts1 = new ArrayList();
1029 ArrayList uniqueElementsList = new ArrayList();
1030 Object uniqueXAxisElements[] = null;
1031 String uniqueXAxisStr = "";
1033 for (int i = 0; i < ds.getRowCount(); i++) {
1034 uniqueXAxisStr = ds.getString(i, 0);
1035 ts1.add(uniqueXAxisStr);
1038 uniqueElementsList.addAll(ts1);
1039 uniqueXAxisElements = ts1.toArray();
1044 boolean hasCustomizedChartColor = false;
1046 StringBuffer catStr = new StringBuffer("");
1048 for (int i = 0; i < ds.getRowCount(); i++) {
1049 catStr = new StringBuffer("");
1050 catStr.append(ds.getString(i, 2));
1052 if(ds.getString(i, "chart_color")!=null) {
1053 color = ds.getString(i, "chart_color");
1054 hasCustomizedChartColor = true;
1055 catStr.append("|"+color);
1057 } catch (ArrayIndexOutOfBoundsException ex) {
1058 //System.out.println("No Chart Color");
1061 if(catStr.length()>0) {
1062 //duplicates are avoided
1063 if(!ts.contains(catStr.toString()))
1064 ts.add(catStr.toString());
1068 //Object uniqueElements [] = ts.toArray();
1069 //SortedSet s = Collections.synchronizedSortedSet(ts);
1070 //uniqueElements = (String[]) ts.toArray();
1071 DataColumnType dct = null;
1072 List yTextSeries = reportRuntime.getChartDisplayNamesList(AppConstants.CHART_ALL_COLUMNS, formValues);
1073 if(yTextSeries.size()==1) {
1074 for (Iterator iter = l.iterator(); iter.hasNext();) {
1075 dct = (DataColumnType) iter.next();
1076 //System.out.println(dct.getDisplayName() + " " + yText);
1077 if(!(nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND))) {
1078 if(nvl(chartLeftAxisLabel).length()<=0) {
1079 chartLeftAxisLabel = nvl(dct.getYAxis());
1080 chartLeftAxisLabel = (chartLeftAxisLabel.indexOf("|")!=-1)?chartLeftAxisLabel.substring(0,chartLeftAxisLabel.indexOf("|")):"";
1085 Object tempArray[] = ts.toArray();
1086 uniqueElements = Arrays.copyOf(tempArray, tempArray.length, String[].class);
1089 DataColumnType dct = null;
1091 List yTextSeries = reportRuntime.getChartDisplayNamesList(AppConstants.CHART_ALL_COLUMNS, formValues);
1092 //if(columnValuesList.size() == 1) {
1094 for (Iterator iter = l.iterator(); iter.hasNext();) {
1095 dct = (DataColumnType) iter.next();
1096 //System.out.println(dct.getDisplayName() + " " + yText);
1097 if(!(nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND))) {
1098 if(yTextSeries.contains((String)dct.getDisplayName())) {
1099 if(nvl(dct.getChartColor()).length()>0)
1100 hasCustomizedChartColor = true;
1101 if(hasCustomizedChartColor) {
1102 //duplicates are avoided
1103 if(!ts.contains(dct.getDisplayName()+"|"+nvl(dct.getChartColor())))
1104 ts.add(dct.getDisplayName()+"|"+nvl(dct.getChartColor()));
1106 //duplicates are avoided
1107 if(!ts.contains(dct.getDisplayName()))
1108 ts.add(dct.getDisplayName());
1110 if(nvl(chartLeftAxisLabel).length()<=0) {
1111 chartLeftAxisLabel = nvl(dct.getYAxis());
1112 chartLeftAxisLabel = (chartLeftAxisLabel.indexOf("|")!=-1)?chartLeftAxisLabel.substring(0,chartLeftAxisLabel.indexOf("|")):"";
1114 if(nvl(chartRightAxisLabel).length()>0) {
1115 String dctYAxis = nvl(dct.getYAxis());
1116 String yAxis = (dctYAxis.indexOf("|")!=-1)?dctYAxis.substring(0,dctYAxis.indexOf("|")):dctYAxis;
1117 if(chartRightAxisLabel.equals(yAxis)) {
1118 if(ts.contains(dct.getDisplayName())) {
1119 if(hasCustomizedChartColor) {
1120 ts.set(dctIndex, dct.getDisplayName()+"|R|"+nvl(dct.getChartColor()));
1122 ts.set(dctIndex, dct.getDisplayName()+"|R");
1127 columnMap.put(dct.getDisplayName(), dct.getColId());
1134 //SortedSet s = Collections.synchronizedSortedSet(ts);
1135 Object tempArray[] = ts.toArray();
1136 uniqueElements = Arrays.copyOf(tempArray, tempArray.length, String[].class);
1137 //uniqueElements = (String[]) ts.toArray();
1141 wholeScript.append("<!DOCTYPE html>\n");
1142 wholeScript.append("<html>\n");
1143 wholeScript.append("<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF8\">\n");
1144 wholeScript.append("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n");
1145 wholeScript.append("<link href=\""+ chartScriptsPath +"d3/css/nv.d3.css\" rel=\"stylesheet\" type=\"text/css\">\n");
1146 wholeScript.append("<style>\n " +
1148 " overflow-y:scroll; \n" +
1151 " font: 12px sans-serif; \n" +
1154 " display: block;\n" +
1156 " #chart"+reportRuntime.getReportID()+" svg { \n" +
1157 " height: "+ (nvl(height).length()>0?(height.endsWith("px")?height:height+"px"):"420px") + "; \n" +
1158 " width: "+ (nvl(width).length()>0?(width.endsWith("px")?width:width+"px"):"700px") + "; \n" +
1159 " min-width: 100px; \n" +
1160 " min-height: 100px; \n" +
1162 " tr.z-row-over > td.z-row-inner, tr.z-row-over > .z-cell {" +
1163 " background-color: rgb(255, 255, 255); "+
1165 wholeScript.append(".nodatadiv {\n");
1166 wholeScript.append(" display: table-cell;\n");
1167 wholeScript.append(" width: 700px;\n");
1168 wholeScript.append(" height:370px;\n");
1169 wholeScript.append(" text-align:center;\n");
1170 wholeScript.append(" vertical-align: middle;\n");
1171 wholeScript.append("}\n");
1172 wholeScript.append(".nodatainner {\n");
1173 wholeScript.append(" padding: 10px;\n");
1174 wholeScript.append("}\n");
1176 wholeScript.append(" </style> \n" );
1178 wholeScript.append("<body> \n");
1181 wholeScript.append("<div align=\"center\"><H3>" + title +"</H3></div>");
1184 wholeScript.append("<div id=\"chart"+reportRuntime.getReportID()+"\"> <svg></svg> </div> \n");
1186 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/d3.v3.min.js\"></script>\n");
1187 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/nv.d3.min.js\"></script> \n");
1188 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/models/axis.min.js\"></script> \n");
1189 //wholeScript.append("<script src=\""+ AppUtils.getBaseFolderURL() +"d3/js/models/cumulativeLineChart.js\"></script> \n");
1190 //if(multipleSeries)
1191 //wholeScript.append("<script src=\""+ AppUtils.getBaseFolderURL() +"d3/js/models/multiChart.js\"></script> \n");
1194 wholeScript.append("<script> \n");
1196 wholeScript.append("historicalBarChart = [ \n");
1197 //wholeScript.append("{ \n");
1198 ArrayList dataSeries = new ArrayList();
1199 String uniqueElement = "";
1201 String [] uniqueRevElements = null;
1202 //Added to make sure order appears same as legend
1203 /*if(nvl(subType).length() > 0 && subType.equals("area")) {
1204 uniqueRevElements = reverse((String[])uniqueElements);
1206 uniqueRevElements = (String[])uniqueElements;
1209 int RIGHTAXISSERIES = 0;
1210 for (int i = 0; i < uniqueRevElements.length; i++) {
1211 //element.substring(element.indexOf("|")+1)
1212 uniqueElement = (String)uniqueRevElements[i];
1213 if(multipleSeries && (nvl(chartRightAxisLabel).length() > 0)) {
1214 if(nvl(subType).length() > 0 && subType.equals("area")) {
1215 if(nvl(uniqueElement).indexOf("|R") !=-1)
1216 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\": ["));
1218 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\": ["));
1220 if(nvl(uniqueElement).indexOf("|R") !=-1)
1221 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\": ["));
1223 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\": ["));
1225 RIGHTAXISSERIES = dataSeries.size()-1;
1226 //dataSeries.add(new StringBuffer(" { \"type\":\"line\", \"key\": \""+ ((DataColumnType)columnMap.get(i)).getDisplayName() +"\", \"yAxis\": \""+(i+1)+"\", \"values\": ["));
1229 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\": ["));
1233 /*StringBuffer dataSeries1 = new StringBuffer("");
1234 dataSeries1.append(" { key: \"Series1\",values: [");
1235 StringBuffer dataSeries2 = new StringBuffer("");
1236 dataSeries2.append(" { key: \"Series2\", values: [");
1237 StringBuffer dataSeries3 = new StringBuffer("");
1238 dataSeries3.append(" { key: \"Series3\", values: [");
1242 //long minTime = 1000000000000000L;
1244 double MAXDOUBLENUM = 0.0;
1246 double YAXISDOUBLENUM = 0.0;
1247 int MAXNUMDECIMALPLACES = 0;
1249 int flagSecondNull = 0;
1250 TreeSet dateList = new TreeSet();
1253 for (int j = 0; j < uniqueRevElements.length; j++) {
1254 for (int i = 0; i < ds.getRowCount(); i++) {
1258 YAXISDOUBLENUM = 0.0;
1261 dateStr = ds.getString(i, 1);
1263 date = getDateFromDateStr(dateStr);
1264 formatFlag = getFlagFromDateStr(dateStr);
1266 if(date==null && timeAxis)
1270 //if(ds.getString(i, 2).equals(uniqueElements[j])) {
1271 //if(minTime > date.getTime())
1272 // minTime = date.getTime();
1273 uniqueElement = (String)uniqueRevElements[j];
1275 YAXISNUM = Integer.parseInt(ds.getString(i, columnMap.get(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1)?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))));
1276 if(MAXDOUBLENUM < YAXISNUM)
1277 MAXDOUBLENUM = YAXISNUM;
1278 } catch (NumberFormatException ex) {
1280 YAXISDOUBLENUM = Double.parseDouble(ds.getString(i, columnMap.get(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1) ?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))));
1281 if(RIGHTAXISSERIES!=j) {
1282 MAXNUMDECIMALPLACES = getNumberOfDecimalPlaces(YAXISDOUBLENUM);
1283 if(MAXDOUBLENUM < YAXISDOUBLENUM)
1284 MAXDOUBLENUM = YAXISDOUBLENUM;
1286 } catch (NumberFormatException ex1) {
1292 dateList.add(dateStr);
1293 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":\"" + dateStr + "\" , \"y\":" + (flagNull==0?(YAXISDOUBLENUM>0?YAXISDOUBLENUM:YAXISNUM):null) +"}, ");
1295 dateList.add(new Long(date.getTime()).toString());
1296 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime() + " , \"y\":" + (flagNull==0?(YAXISDOUBLENUM>0?YAXISDOUBLENUM:YAXISNUM):null) +"}, ");
1301 if(nvl(subType).length() > 0 && subType.equals("area")) {
1304 if(i<ds.getRowCount()-1) {
1306 YAXISNUM = Integer.parseInt(ds.getString(i+1, columnMap.get(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1)?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))));
1307 if(MAXDOUBLENUM < YAXISNUM)
1308 MAXDOUBLENUM = YAXISNUM;
1309 } catch (NumberFormatException ex) {
1311 YAXISDOUBLENUM = Double.parseDouble(ds.getString(i+1, columnMap.get(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1) ?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))));
1312 if(RIGHTAXISSERIES!=j) {
1313 MAXNUMDECIMALPLACES = getNumberOfDecimalPlaces(YAXISDOUBLENUM);
1314 if(MAXDOUBLENUM < YAXISDOUBLENUM)
1315 MAXDOUBLENUM = YAXISDOUBLENUM;
1317 } catch (NumberFormatException ex1) {
1322 if(flagSecondNull==1 && date == null) {
1323 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":\"" + dateStr + "\" , \"y\":" + null +"}, ");
1324 } else if( flagSecondNull == 1){
1325 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime() + " , \"y\":" + null +"}, ");
1329 if(i<ds.getRowCount()-1) {
1330 dateStr = ds.getString(i+1, 1);
1333 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":\"" + dateStr + "\" , \"y\":" + null +"}, ");
1335 date = getDateFromDateStr(dateStr);
1336 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime() + " , \"y\":" + null +"}, ");
1338 //((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime() + " , \"y\":" + null +"}, ");
1347 //((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + minTime + " , \"y\":" + 0 +"}, ");
1351 for (int j = 0; j < uniqueRevElements.length; j++) {
1352 for (int i = 0; i < ds.getRowCount(); i++) {
1354 YAXISDOUBLENUM = 0.0;
1357 dateStr = ds.getString(i, 1);
1359 date = getDateFromDateStr(dateStr);
1360 formatFlag = getFlagFromDateStr(dateStr);
1363 if(date==null && timeAxis)
1366 uniqueElement = (String)uniqueRevElements[j];
1367 //date = MMDDYYYYFormat.parse(ds.getString(i, 1), new ParsePosition(0));
1368 if(ds.getString(i, 2).equals(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1) ?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))) {
1369 //if(minTime > date.getTime())
1370 // minTime = date.getTime();
1372 YAXISNUM = Integer.parseInt(ds.getString(i, 3));
1373 if(MAXDOUBLENUM < YAXISNUM)
1374 MAXDOUBLENUM = YAXISNUM;
1375 } catch (NumberFormatException ex) {
1377 YAXISDOUBLENUM = Double.parseDouble(ds.getString(i, 3));
1378 if(RIGHTAXISSERIES!=j) {
1379 MAXNUMDECIMALPLACES = getNumberOfDecimalPlaces(YAXISDOUBLENUM);
1380 if(MAXDOUBLENUM < YAXISDOUBLENUM)
1381 MAXDOUBLENUM = YAXISDOUBLENUM;
1384 } catch (NumberFormatException ex1) {
1390 dateList.add(dateStr);
1391 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + dateStr + " , \"y\":" + (flagNull==0?(YAXISDOUBLENUM!=0.0?YAXISDOUBLENUM:YAXISNUM):null) +"}, ");
1393 dateList.add(new Long(date.getTime()).toString());
1394 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime() + " , \"y\":" + (flagNull==0?(YAXISDOUBLENUM!=0.0?YAXISDOUBLENUM:YAXISNUM):null) +"}, ");
1398 if(nvl(subType).length() > 0 && subType.equals("area")) {
1401 if(i<ds.getRowCount()-1) {
1402 for (int k = i+1; k < ds.getRowCount(); k++) {
1403 if (ds.getString(k, 2).equals(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1) ?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))) {
1405 YAXISNUM = Integer.parseInt(ds.getString(k, 3));
1406 if(MAXDOUBLENUM < YAXISNUM)
1407 MAXDOUBLENUM = YAXISNUM;
1408 } catch (NumberFormatException ex) {
1410 YAXISDOUBLENUM = Double.parseDouble(ds.getString(k, 3));
1411 if(RIGHTAXISSERIES!=j) {
1412 MAXNUMDECIMALPLACES = getNumberOfDecimalPlaces(YAXISDOUBLENUM);
1413 if(MAXDOUBLENUM < YAXISDOUBLENUM)
1414 MAXDOUBLENUM = YAXISDOUBLENUM;
1416 } catch (NumberFormatException ex1) {
1424 if(date==null && flagSecondNull==1){
1425 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + dateStr + " , \"y\":" + null +"}, ");
1426 } else if(flagSecondNull == 1){
1427 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime() + " , \"y\":" + null +"}, ");
1432 if(i<ds.getRowCount()-1) {
1433 for (int k = i+1; k < ds.getRowCount(); k++) {
1434 if (ds.getString(k, 2).equals(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1) ?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))) {
1435 dateStr = ds.getString(k, 1);
1437 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime() + " , \"y\":" + null +"}, ");
1440 date = getDateFromDateStr(dateStr);
1441 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime() + " , \"y\":" + null +"}, ");
1452 // ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + minTime + " , \"y\":" + 0 +"}, ");
1455 /* if(ds.getString(i, 2).equals("Series1")) {
1456 dataSeries1.append("[ " + date.getTime() + " , " + ds.getString(i, 3) +"], ");
1457 } else if (ds.getString(i, 2).equals("Series2")) {
1458 dataSeries2.append("[ " + date.getTime() + " , " + ds.getString(i, 3) +"], ");
1459 } else if (ds.getString(i, 2).equals("Series3")) {
1460 dataSeries3.append("[ " + date.getTime() + " , " + ds.getString(i, 3) +"], ");
1464 for (int i = 0; i < uniqueRevElements.length; i++) {
1465 StringBuffer strBuf = ((StringBuffer) dataSeries.get(i));
1466 ((StringBuffer) dataSeries.get(i)).deleteCharAt(((StringBuffer) dataSeries.get(i)).lastIndexOf(","));
1467 if(i < (uniqueRevElements.length -1) ) {
1468 ((StringBuffer) dataSeries.get(i)).append("] } , \n");
1471 ((StringBuffer) dataSeries.get(i)).append("] } \n");
1475 for (int i = 0; i < uniqueRevElements.length; i++) {
1476 wholeScript.append((StringBuffer)dataSeries.get(i));
1478 /* wholeScript.append(dataSeries1);
1479 wholeScript.append(dataSeries2);
1480 wholeScript.append(dataSeries3);
1481 */ wholeScript.append("];\n");
1483 /* Sorting is commented out.*/
1484 StringBuffer dateStrBuf = new StringBuffer("");
1485 if(dateList.size()>0) {
1486 //SortedSet<String> s = Collections.synchronizedSortedSet(dateList);
1487 Object[] dateElements = (Object[]) dateList.toArray();
1489 String element = "";
1491 for (int i = 0; i < dateElements.length; i++) {
1492 dateStrBuf.append(dateElements[i]+",");
1494 dateStrBuf.deleteCharAt(dateStrBuf.length()-1);
1497 wholeScript.append(" var chart;\n");
1498 wholeScript.append("nv.addGraph(function() { \n");
1499 //" var chart = nv.models.cumulativeLineChart() \n" + nv.models.lineWithFocusChart()
1500 // " chart = nv.models.lineChart() \n" +
1501 if(nvl(subType).length() > 0 && subType.equals("area")) {
1502 wholeScript.append(" chart = nv.models.stackedAreaChart() \n");
1504 wholeScript.append(" .showControls(true) \n ");
1506 wholeScript.append(" .showControls(false) \n ");
1509 wholeScript.append(" chart = nv.models.multiChart() \n");
1510 if(nvl(chartRightAxisLabel).length() > 0) {
1511 wholeScript.append(" .dualaxis(true) \n ");
1513 wholeScript.append(" .dualaxis(false) \n ");
1516 if(AppUtils.nvl(reportRuntime.getLegendPosition()).length()>=0 && reportRuntime.getLegendPosition().equals("right")) {
1517 wholeScript.append(" .legendPos('right')\n" );
1519 wholeScript.append(" .legendPos('top')\n" );
1525 wholeScript.append(" .margin({top: "+ topMargin +", right: "+ rightMargin +", bottom: "+ bottomMargin +", left: " + leftMargin +"}) \n");
1527 wholeScript.append(" .showLegend(true) \n ");
1529 wholeScript.append(" .showLegend(false) \n ");
1532 if(nvl(subType).length() > 0 && subType.equals("area")) {
1533 if( MAXNUMDECIMALPLACES >=3 ) {
1534 wholeScript.append(" .yAxisTooltipFormat(d3.format(',.3f')) \n");
1536 wholeScript.append(" .yAxisTooltipFormat(d3.format(',."+MAXNUMDECIMALPLACES+ "f')) \n");
1539 wholeScript.append(".x (function(d) {return d.x;}) \n" +
1540 ".y (function(d) {return d.y;}) \n");
1543 //" .x(function(d) { return d[0] }) \n" +
1544 //" .y(function(d) { return d[1] }) \n" +
1545 //" .forceY("+(nvl(reportRuntime.getRangeAxisLowerLimit()).length()<=0?"0":reportRuntime.getRangeAxisLowerLimit()) +", "+ Math.ceil((MAXNUM+(MAXNUM*25/100))/100) * 100 + ") \n" + // reportRuntime.getRangeAxisUpperLimit()+") \n" +
1546 wholeScript.append(" .color(d3.scale.category10().range()); \n");
1547 if(!(nvl(subType).length() > 0 && subType.equals("area"))) {
1548 double UPPER_RANGE = 0;
1549 if(Math.ceil((MAXDOUBLENUM+(MAXDOUBLENUM*25/100))/100) * 100 >= 1) {
1550 UPPER_RANGE = Math.ceil(MAXDOUBLENUM+(MAXDOUBLENUM*25/100));
1551 } else UPPER_RANGE = 1;
1553 wholeScript.append(" chart.lines1.forceY(["+(nvl(reportRuntime.getRangeAxisLowerLimit()).length()<=0?"0":reportRuntime.getRangeAxisLowerLimit()) +", "+ (nvl(reportRuntime.getRangeAxisUpperLimit()).length()<=0?UPPER_RANGE:reportRuntime.getRangeAxisUpperLimit()) + "]); \n" +
1554 " chart.lines2.forceY([0,1]); \n");
1556 wholeScript.append(" chart.xAxis\n");
1557 if(reportRuntime.isShowXaxisLabel()) {
1558 // X axis label is commented for time-being. This should be derived from request parameter.
1559 //" .axisLabel('" + legendColumnName + "') \n" +
1560 wholeScript.append(" .axisLabel('" + legendColumnName + "') \n");
1562 wholeScript.append(" .axisLabel('') \n");
1564 if(reportRuntime.isAddXAxisTickers()) {
1565 wholeScript.append(" .tickValues(["+ dateStrBuf.toString()+ "])\n ");
1567 //wholeScript.append(" .tickValues([])\n ");
1570 wholeScript.append(" .staggerLabels(true) \n");
1572 wholeScript.append(" .staggerLabels(false) \n");
1575 wholeScript.append(" .showMaxMin(true) \n ");
1577 wholeScript.append(" .showMaxMin(false) \n ");
1580 if(nvl(rotateLabels).length()>0) {
1581 wholeScript.append(" .rotateLabels("+ rotateLabels+ ") \n ");
1583 wholeScript.append(" .rotateLabels(\"0\") \n ");
1586 wholeScript.append(" .tickFormat(function(d) { \n");
1587 wholeScript.append(" var local_dt = new Date(); \n var utc = d + (local_dt.getTimezoneOffset() * 60000);\n");
1588 wholeScript.append(" var nd = new Date(utc + (3600000*"+getCurrentTimezoneOffset()+")); ");
1590 if(formatFlag==DAYFLAG)
1591 wholeScript.append(" return d3.time.format('%m/%d/%Y')(new Date(d)) }); \n");
1592 else if(formatFlag==HOURFLAG)
1593 wholeScript.append(" return d3.time.format('%x %H')(new Date(d)) }); \n");
1594 else if(formatFlag==MINFLAG)
1595 wholeScript.append(" return d3.time.format('%x %H:%M')(new Date(d)) }); \n");
1596 else if(formatFlag==SECFLAG)
1597 wholeScript.append(" return d3.time.format('%x %X')(new Date(d)) }); \n");
1598 else if(formatFlag==MONTHFLAG)
1599 wholeScript.append(" return d3.time.format('%b %y')(new Date(d)) }); \n");
1602 wholeScript.append(" return d3.time.format('%x')(new Date(d)) }); \n");
1604 wholeScript.append(" return d; }); \n");
1605 if(nvl(chartRightAxisLabel).length() > 0) {
1606 if(nvl(subType).length() > 0 && subType.equals("area")) {
1607 wholeScript.append(" chart.yAxis\n");
1609 wholeScript.append(" chart.yAxis1\n");
1611 wholeScript.append(" .axisLabel('" + chartLeftAxisLabel + "') \n");
1612 //if(nvl(subType).length() > 0 && subType.equals("area")) {
1613 if(MAXDOUBLENUM <=5 && MAXNUMDECIMALPLACES == 0 )
1614 MAXNUMDECIMALPLACES = 2;
1615 if( MAXNUMDECIMALPLACES >=3 )
1616 MAXNUMDECIMALPLACES = 2;
1617 wholeScript.append(" .tickFormat(d3.format(',."+MAXNUMDECIMALPLACES+"f')); \n");
1619 wholeScript.append(" .tickFormat(d3.format(',.2f')); \n");
1621 // " .tickFormat(function (d) {return d;} ); \n");
1622 //" .tickFormat(function(d) {if (d >= 1000) return Math.round(d/1000)+\"K\"; else return d;}); \n");
1623 if(!(nvl(subType).length() > 0 && subType.equals("area"))) {
1624 wholeScript.append(" chart.yAxis2\n " +
1625 " .axisLabel('" + chartRightAxisLabel + "') \n" +
1626 " .tickFormat(d3.format(',.02f')); \n");
1627 //" .tickFormat(function(d) {if (d >= 1000) return Math.round(d/1000)+\"K\"; else return d;}); \n");
1628 //" .tickFormat(function(d) {if( d <= 1) return Math.round(d*100)+\"%\"; else return d;}); \n");
1629 // " .tickFormat(function(d) { return d;}); \n");
1634 if(nvl(subType).length() > 0 && subType.equals("area")) {
1635 wholeScript.append(" chart.yAxis\n");
1637 wholeScript.append(" chart.yAxis1\n");
1639 wholeScript.append(" .axisLabel('" + chartLeftAxisLabel + "') \n");
1640 //if(nvl(subType).length() > 0 && subType.equals("area")) {
1641 if(MAXDOUBLENUM <=5 && MAXNUMDECIMALPLACES == 0 )
1642 MAXNUMDECIMALPLACES = 2;
1643 if( MAXNUMDECIMALPLACES >=3 ) {
1644 MAXNUMDECIMALPLACES = 2;
1646 wholeScript.append(" .tickFormat(d3.format(',."+MAXNUMDECIMALPLACES+"f')); \n");
1648 wholeScript.append(" .tickFormat(d3.format(',.2f')); \n");
1650 //" .tickFormat(function(d) {if (d >= 1000) return Math.round(d/1000)+\"K\"; else return d;}); \n");
1652 wholeScript.append(" d3.select('#chart"+reportRuntime.getReportID()+" svg') \n" +
1653 " .datum(historicalBarChart) \n" );
1655 wholeScript.append(" .transition().duration(1000) \n" );
1656 wholeScript.append(" .call(chart); \n" +
1657 "nv.utils.windowResize(chart.update); \n" +
1658 "return chart; \n" +
1661 wholeScript.append("function redraw() { \n");
1662 //wholeScript.append(" nv.utils.windowResize(chart.update); \n");
1663 wholeScript.append(" d3.select('#chart"+reportRuntime.getReportID()+" svg') \n") ;
1664 wholeScript.append(" .datum(historicalBarChart) \n");
1665 wholeScript.append(" .transition().duration(500) \n");
1666 wholeScript.append(" .call(chart); \n");
1667 wholeScript.append("} \n");
1668 wholeScript.append("\n");
1669 wholeScript.append(" setInterval(function () { \n");
1670 wholeScript.append(" redraw(); \n");
1671 wholeScript.append(" }, 1500) \n");
1673 wholeScript.append("if(historicalBarChart.length <= 0 ) {\n");
1674 wholeScript.append(" document.getElementById(\"chart"+reportRuntime.getReportID()+"\").innerHTML = \"<div id='noData'><b>No Data Available</b></div>\";\n");
1675 wholeScript.append(" document.getElementById(\"chart"+reportRuntime.getReportID()+"\").className=\"nodatadiv\";\n");
1676 wholeScript.append(" document.getElementById(\"nodata\").className=\"nodatainner\";\n");
1677 wholeScript.append("}\n");
1679 wholeScript.append("</script> </body> </html> \n");
1681 } else if (chartType.equals(AppConstants.GT_PIE) || chartType.equals(AppConstants.GT_PIE_3D)) {
1682 wholeScript.append("<!DOCTYPE html>\n");
1683 wholeScript.append("<html>\n");
1684 wholeScript.append("<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF8\">\n");
1685 wholeScript.append("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n");
1686 wholeScript.append("<link href=\""+ AppUtils.getBaseFolderURL() +"d3/css/nv.d3.css\" rel=\"stylesheet\" type=\"text/css\">\n");
1687 wholeScript.append("<style>\n " +
1689 " overflow-y:scroll; \n" +
1692 " font: 12px sans-serif; \n" +
1694 " tr.z-row-over > td.z-row-inner, tr.z-row-over > .z-cell {" +
1695 " background-color: rgb(255, 255, 255); "+
1697 " svg { display: block; } " +
1698 " #chart"+reportRuntime.getReportID()+" svg { \n" +
1699 " height: "+ (nvl(height).length()>0?(height.endsWith("px")?height:height+"px"):"420px") + "; \n" +
1700 " width: "+ (nvl(width).length()>0?(width.endsWith("px")?width:width+"px"):"700px") + "; \n" +
1701 " min-width: 100px; \n" +
1702 " min-height: 100px; \n" +
1705 wholeScript.append("<body> \n");
1708 wholeScript.append("<div align=\"center\"><H3>" + title +"</H3></div>");
1710 wholeScript.append("<div id=\"chart"+reportRuntime.getReportID()+"\"><svg></svg></div>");
1711 //"<svg id=\"test2\"></svg>\n");
1713 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/d3.v3.min.js\"></script>\n");
1714 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/nv.d3.min.js\"></script> \n");
1715 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/models/legend.js\"></script> \n");
1716 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/models/pie.js\"></script> \n");
1717 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/models/pieChart.js\"></script> \n");
1718 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/utils.js\"></script> \n");
1719 wholeScript.append("<script> \n");
1721 wholeScript.append("historicalBarChart = [ \n");
1726 TreeSet<String> colorList = new TreeSet<>();
1727 for (int i = 0; i < ds.getRowCount(); i++) {
1730 value = Double.parseDouble(ds.getString(i, 2));
1731 total = total+value;
1732 } catch (NumberFormatException ex) {
1735 String key = ds.getString(i, 0);
1737 if(ds.getString(i, "chart_color")!=null) {
1738 colorList.add(key+"|"+ds.getString(i, "chart_color"));
1740 } catch (ArrayIndexOutOfBoundsException ex) {
1741 //System.out.println("No Chart Color");
1743 wholeScript.append("{ \""+ "key" +"\":\""+ key+"\", \""+ "y" +"\":"+value+"}, \n");
1746 StringBuffer color = new StringBuffer("");
1747 if(colorList.size()>0) {
1748 SortedSet<String> s = Collections.synchronizedSortedSet(colorList);
1749 Object[] colorElements = (Object[]) s.toArray();
1751 String element = "";
1753 for (int i = 0; i < colorElements.length; i++) {
1754 element = ((String)colorElements[i]);
1755 color.append("'"+element.substring(element.lastIndexOf("|")+1)+"',");
1757 color.deleteCharAt(color.length()-1);
1760 wholeScript.append("];\n");
1763 wholeScript.append("var chart; \n");
1764 wholeScript.append("nv.addGraph(function() { \n" +
1765 " var width1= 700, height1=720; \n" +
1766 " chart = nv.models.pieChart() \n" +
1767 " .margin({top: "+ topMargin +", right: "+ rightMargin +", bottom: "+ bottomMargin +", left: " + leftMargin +"}) \n" +
1769 //" .x(function(d) { return d.key +\" \"+ Math.round(d.y/"+TOTAL+" *100) + \"%\" }) \n" +
1770 " .x(function(d) { return d.key }) \n" +
1771 " .y(function(d) { return d.y }) \n");
1772 if(colorList.size()>0) {
1773 wholeScript.append(" .color(["+ color.toString() + "] ) \n");
1775 //wholeScript.append(" .values(function(d) { return d }) \n");
1776 //" .color(d3.scale.category10().range()); \n" +
1778 wholeScript.append(" chart.showLegend(true);\n ");
1780 wholeScript.append(" chart.showLegend(false);\n ");
1783 //wholeScript.append("chart.showLegend(false);\n" +
1784 //" .width(width1) \n" +
1785 //" .height(height1); \n" +
1786 wholeScript.append(" d3.select('#chart"+reportRuntime.getReportID()+" svg') \n" +
1787 " .datum(historicalBarChart) \n");
1789 wholeScript.append(" .transition().duration(1200) \n" );
1790 /* " .attr(\"width\", width1) \n" +
1791 " .attr(\"height\", height1) \n" +
1792 */ wholeScript.append(" .call(chart); \n" +
1793 " nv.utils.windowResize(chart.update);\n"+
1794 "return chart; \n" +
1797 wholeScript.append("function redraw() { \n");
1798 //wholeScript.append(" nv.utils.windowResize(chart.update); \n");
1799 wholeScript.append(" d3.select('#chart"+reportRuntime.getReportID()+" svg') \n") ;
1800 wholeScript.append(" .datum(historicalBarChart) \n");
1801 wholeScript.append(" .transition().duration(500) \n");
1802 wholeScript.append(" .call(chart); \n");
1803 wholeScript.append("} \n");
1804 wholeScript.append("\n");
1805 wholeScript.append(" setInterval(function () { \n");
1806 wholeScript.append(" redraw(); \n");
1807 wholeScript.append(" }, 1500) \n");
1811 wholeScript.append("if(historicalBarChart.length <= 0 ) {\n");
1812 wholeScript.append(" document.getElementById(\"chart"+reportRuntime.getReportID()+"\").innerHTML = \"<div id='noData'><b>No Data Available</b></div>\";\n");
1813 wholeScript.append(" document.getElementById(\"chart"+reportRuntime.getReportID()+"\").className=\"nodatadiv\";\n");
1814 wholeScript.append(" document.getElementById(\"nodata\").className=\"nodatainner\";\n");
1815 wholeScript.append("}\n");
1817 wholeScript.append("</script> </body> </html> \n");
1819 } else if (chartType.equals(AppConstants.GT_ANNOTATION_CHART) || chartType.equals(AppConstants.GT_FLEX_TIME_CHARTS)) {
1821 boolean timeCharts = chartType.equals(AppConstants.GT_FLEX_TIME_CHARTS);
1823 String dateStr = null;
1824 java.util.Date date = null;
1826 final int YEARFLAG = 1;
1827 final int MONTHFLAG = 2;
1828 final int DAYFLAG = 3;
1829 final int HOURFLAG = 4;
1830 final int MINFLAG = 5;
1831 final int SECFLAG = 6;
1832 final int MILLISECFLAG = 7;
1833 final int DAYOFTHEWEEKFLAG = 8;
1834 final int FLAGDATE = 9;
1842 double YAXISDOUBLENUM = 0.0;
1843 double MAXDOUBLENUM = 0.0;
1844 int MAXNUMDECIMALPLACES = 0;
1848 TreeSet<String> dateStrList = new TreeSet<>();
1849 // added to store all date elements
1850 SortedSet<String> sortSet = new TreeSet<>();
1854 boolean hasCategoryAxis = reportRuntime.hasSeriesColumn();
1855 flag = hasCategoryAxis?1:0;
1858 String anomalyText = "";
1860 StringBuffer dataStrBuf = new StringBuffer("");
1861 StringBuffer annotationsStrBuf = new StringBuffer("");
1863 String xAxisLabel = (reportRuntime.getChartLegendColumn()!=null)?reportRuntime.getChartLegendColumn().getDisplayName():"";
1865 //finding actual string
1866 String actualText = "";
1867 DataColumnType dct = null;
1868 for (Iterator iter = l.iterator(); iter.hasNext();) {
1869 dct = (DataColumnType) iter.next();
1870 if((dct.getChartSeq()!=null && dct.getChartSeq() >=0) && !AppUtils.nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND)) {
1871 //if(AppUtils.nvl(dct.getDisplayName()).toLowerCase().contains("actual")) {
1872 actualText = dct.getDisplayName();
1879 int columnIndex = 1;
1880 ArrayList columnNames = new ArrayList();
1881 ArrayList columnValues = new ArrayList();
1883 String columnName = "";
1884 String columnValue = "";
1887 StringBuffer seriesBuffer = new StringBuffer("");
1889 for (int i = 0; i < ds.getRowCount(); i++) {
1890 columnNames = new ArrayList();
1891 columnValues = new ArrayList();
1896 dateStr = ds.getString(i, 0);
1897 date = getDateFromDateStr(dateStr);
1898 if(date.getTime() > maxDate )
1899 maxDate = date.getTime();
1901 formatFlag = getFlagFromDateStr(dateStr);
1904 for (;columnIndex<ds.getColumnCount();columnIndex++) {
1905 columnName = ds.getColumnName(columnIndex);
1906 if(!timeCharts && !columnName.toLowerCase().equals("anomaly_text")) {
1907 columnNames.add(columnName);
1908 columnValues.add(AppUtils.nvls(ds.getString(i, columnIndex), "null"));
1909 } else if (timeCharts) {
1910 columnNames.add(columnName);
1911 columnValues.add(AppUtils.nvls(ds.getString(i, columnIndex), "null"));
1914 /* actual = ds.getString(i, "actual");
1915 //forecast = ds.getString(i, "forecast");
1916 upperBound = ds.getString(i, "upperBound");
1917 lowerBound = ds.getString(i, "lowerBound");
1920 anomalyText = ds.getString(i, "anomaly_text");
1921 //dataStrBuf.append(" [new Date(moment(\""+dateStr+"\")),"+ actual /*+","+ forecast*/+","+ lowerBound +","+ upperBound +"],\n");
1922 dataStrBuf.append(" [new Date(moment(\""+dateStr+"\"))");
1923 for(int c=0; c< columnNames.size(); c++ ) {
1924 columnName = (String) columnNames.get(c);
1925 columnValue = (String) columnValues.get(c);
1926 for (Iterator iter1 = l.iterator(); iter1.hasNext();) {
1927 dct = (DataColumnType) iter1.next();
1928 if((dct.getChartSeq()!=null && dct.getChartSeq() >=0) && !AppUtils.nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND)) {
1929 if((!timeCharts && !AppUtils.nvl(dct.getColId()).toLowerCase().equals("anomaly_text")) && AppUtils.nvl(dct.getColId()).toLowerCase().equals(columnName.toLowerCase())) {
1930 dataStrBuf.append(","+columnValue);
1932 } else if(timeCharts && AppUtils.nvl(dct.getColId()).toLowerCase().equals(columnName.toLowerCase())){
1933 dataStrBuf.append(","+columnValue);
1940 dataStrBuf.append("],\n");
1942 if(AppUtils.nvl(anomalyText).length()>0) {
1944 annotationsStrBuf.append("anns.push( {\n");
1945 annotationsStrBuf.append(" series: '"+actualText+"',\n");
1946 annotationsStrBuf.append(" x: moment(\""+dateStr+"\"),\n");
1947 annotationsStrBuf.append(" shortText: '"+ IntToLetter(anomalyRec).toUpperCase() +"',\n");
1948 annotationsStrBuf.append(" text: '"+ anomalyText + "'\n");
1949 annotationsStrBuf.append("});\n");
1957 //anomalyRec = anomalyRec - 1;
1959 minDate = maxDate - (new Long(reportRuntime.getZoomIn()).longValue()*60*60*1000);
1960 System.out.println(new java.util.Date(maxDate) + " " + new java.util.Date(minDate) + " " + reportRuntime.getZoomIn());
1961 if(dataStrBuf.lastIndexOf(",")!= -1)
1962 dataStrBuf.deleteCharAt(dataStrBuf.lastIndexOf(","));
1964 wholeScript = new StringBuilder("");
1965 wholeScript.append("<!DOCTYPE html>\n");
1966 wholeScript.append("<html>\n");
1967 wholeScript.append(" <head>\n");
1968 //wholeScript.append("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=EmulateIE7; IE=EmulateIE9\">\n");
1969 wholeScript.append("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n");
1970 wholeScript.append("<script type=\"text/javascript\" src=\""+ chartScriptsPath +"dy3/js/dygraph-combined.js\"></script>\n");
1971 wholeScript.append("<script type=\"text/javascript\" src=\""+ chartScriptsPath +"dy3/js/moment.min.js\"></script>\n");
1972 wholeScript.append("<script type=\"text/javascript\" src=\""+ chartScriptsPath +"dy3/js/interaction.min.js\"></script>\n");
1974 wholeScript.append("<script type=\"text/javascript\">\n");
1975 if(AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("30min")) {
1976 wholeScript.append("var click=2;\n");
1977 } else if (AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("hourly")) {
1978 wholeScript.append("var click=3;\n");
1979 } else if (AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("daily")) {
1980 wholeScript.append("var click=3;\n");
1982 wholeScript.append("var click=3;\n");
1983 //wholeScript.append(" var click=0;\n");
1984 wholeScript.append(" function downV3(event, g, context) { \n");
1985 wholeScript.append(" context.initializeMouseDown(event, g, context); \n");
1986 wholeScript.append(" if (event.altKey || event.shiftKey) { \n");
1987 wholeScript.append(" var minDate = g.xAxisRange()[0]; \n");
1988 wholeScript.append(" var maxDate = g.xAxisRange()[1]; \n");
1989 if(AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("daily")) {
1990 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60*24)) > 6) \n");
1991 wholeScript.append(" Dygraph.startZoom(event, g, context); \n");
1992 } else if(AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("hourly")) {
1993 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60)) > 6) \n");
1994 wholeScript.append(" Dygraph.startZoom(event, g, context); \n");
1995 } else if(AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("30min")) {
1996 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60*2)) > 6) \n");
1997 wholeScript.append(" Dygraph.startZoom(event, g, context); \n");
2000 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60)) > 6) \n");
2001 wholeScript.append(" Dygraph.startZoom(event, g, context); \n");
2003 if(AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("30min")) {
2004 wholeScript.append(" click=2;\n");
2005 } else if (AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("hourly")) {
2006 wholeScript.append(" click=3;\n");
2007 } else if (AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("daily")) {
2008 wholeScript.append(" click=3;\n");
2010 wholeScript.append(" click=3;\n");
2011 wholeScript.append(" } else if (event.ctrlKey) {\n");
2014 wholeScript.append(" click++;\n");
2015 wholeScript.append(" if(click == 1)\n");
2016 wholeScript.append(" zoom_custom(3600);\n");
2017 wholeScript.append(" else if(click == 2)\n");
2018 wholeScript.append(" zoom_custom(12*3600);\n");
2019 wholeScript.append(" else if(click == 3)\n");
2020 wholeScript.append(" zoom_custom(86400);\n");
2021 wholeScript.append(" else if (click == 4)\n");
2022 wholeScript.append(" zoom_custom(7*86400);\n");
2023 wholeScript.append(" else if (click == 5)\n");
2024 wholeScript.append(" zoom_custom(30*86400);\n");
2025 wholeScript.append(" else if (click == 6)\n");
2026 wholeScript.append(" zoom_custom(90*86400);\n");
2027 wholeScript.append(" else if (click == 7)\n");
2028 wholeScript.append(" zoom_custom(180*86400);\n");
2029 wholeScript.append(" else if (click == 8)\n");
2030 wholeScript.append(" zoom_custom(365*86400);\n");
2031 wholeScript.append(" else if (click == 10)\n");
2032 wholeScript.append(" zoom_custom(5*365*86400);\n");
2033 wholeScript.append(" else { \n");
2034 wholeScript.append(" reset();\n");
2035 wholeScript.append(" }\n");
2036 //wholeScript.append(" \n");
2037 wholeScript.append(" } else {\n");
2038 wholeScript.append(" Dygraph.startPan(event, g, context); \n");
2039 wholeScript.append(" } \n");
2040 wholeScript.append(" } \n");
2041 wholeScript.append("</script>\n ");
2042 wholeScript.append("<style type=\"text/css\">\n");
2043 wholeScript.append(".annotation {\n");
2044 wholeScript.append("}");
2045 wholeScript.append(".dygraph-title {\n");
2046 wholeScript.append("color: black;\n");
2047 wholeScript.append("font-weight:bold; \n");
2048 wholeScript.append("}\n");
2049 wholeScript.append(".dygraph-axis-label-x { ");
2050 wholeScript.append("-webkit-transform:rotate(-0deg);");
2051 wholeScript.append("display:block;");
2052 /*position:absolute;
2055 wholeScript.append("}\n");
2058 if(nvl(width).length() > 0) {
2060 widthInt = new Integer(width).intValue();
2061 } catch(Exception ex) {
2062 if(width.endsWith("px")) {
2064 widthInt = new Integer(width.substring(0, width.indexOf("px")));
2065 } catch (Exception ex1) {
2072 } else widthInt = 700;
2074 wholeScript.append(".dygraph-legend {\n");
2075 wholeScript.append(" left: "+(widthInt-200)+"px !important;\n");
2076 wholeScript.append(" top: 5px !important;\n");
2077 wholeScript.append("}\n");
2079 wholeScript.append(".nodatadiv {\n");
2080 wholeScript.append(" display: table-cell;\n");
2081 wholeScript.append(" width: 700px;\n");
2082 wholeScript.append(" height:370px;\n");
2083 wholeScript.append(" text-align:center;\n");
2084 wholeScript.append(" vertical-align: middle;\n");
2085 wholeScript.append("}\n");
2086 wholeScript.append(".nodatainner {\n");
2087 wholeScript.append(" padding: 10px;\n");
2088 wholeScript.append("}\n");
2090 wholeScript.append("canvas {\n");
2091 wholeScript.append(" -webkit-touch-callout: none; \n");
2092 wholeScript.append(" -webkit-user-select: none;\n");
2093 wholeScript.append(" -khtml-user-select: none;\n");
2094 wholeScript.append(" -moz-user-select: none;\n");
2095 wholeScript.append(" user-select: none;\n");
2096 wholeScript.append(" user-select: none;\n");
2097 wholeScript.append(" outline: none;\n");
2098 wholeScript.append(" -webkit-tap-highlight-color: rgba(255, 255, 255, 0); /* mobile webkit */\n");
2099 wholeScript.append("}\n");
2100 wholeScript.append("</style>\n");
2101 wholeScript.append("</head>\n");
2102 wholeScript.append("<body> \n");
2105 wholeScript.append(" <p align=\"center\"><b> " + (AppUtils.nvl(reportRuntime.getReportTitle()).length()>0?reportRuntime.getReportTitle():reportRuntime.getReportName()) + "</b></p>\n");
2107 wholeScript.append(" <table>\n");
2109 wholeScript.append(" <tr> \n ");
2110 wholeScript.append(" <td> \n ");
2111 wholeScript.append(" <div class=\"dygraph-label dygraph-title\" align=\"center\">"+title+"</div> \n");
2112 wholeScript.append(" </td> \n ");
2115 wholeScript.append(" </tr> \n ");
2117 wholeScript.append(" <tr> \n ");
2118 wholeScript.append(" <td> \n ");
2119 if(AppUtils.nvl(reportRuntime.getLegendPosition()).length()<=0 || reportRuntime.getLegendPosition().equals("top")) {
2120 wholeScript.append(" <div id=\"labelDiv"+reportRuntime.getReportID()+"\"></div>\n");
2122 wholeScript.append(" <div id=\"message"+reportRuntime.getReportID()+"\"></div> \n");
2123 wholeScript.append(" </td> \n ");
2125 wholeScript.append(" </tr> \n ");
2126 wholeScript.append(" <tr>\n");
2127 wholeScript.append(" <td>\n");
2130 if(nvl(height).length() > 0) {
2132 heightInt = new Integer(height).intValue();
2134 } catch(Exception ex) {
2135 if(height.endsWith("px")) {
2137 heightInt = new Integer(height.substring(0, height.indexOf("px")));
2139 } catch (Exception ex1) {
2146 } else heightInt = 420;
2147 if(AppUtils.nvl(reportRuntime.getLegendPosition()).length()>=0 && reportRuntime.getLegendPosition().equals("right")) {
2148 wholeScript.append(" <div id=\"div_g"+reportRuntime.getReportID()+"\" style=\"width:"+ (widthInt-250)+ "px; \n" );
2150 wholeScript.append(" <div id=\"div_g"+reportRuntime.getReportID()+"\" style=\"width:"+ (widthInt)+ "px; \n" );
2152 wholeScript.append(" height:"+ heightInt +"px;\"></div> \n");
2153 wholeScript.append(" </td>\n");
2154 if(AppUtils.nvl(reportRuntime.getLegendPosition()).length()>=0 && reportRuntime.getLegendPosition().equals("right")) {
2155 wholeScript.append(" <td valign=\"top\">\n");
2156 wholeScript.append(" <div id=\"labelDiv3716\" valign=\"top\" style=\"width:250px;height:"+ heightInt +"px;\"></div>\n");
2157 wholeScript.append(" </td>\n");
2159 wholeScript.append(" </tr>\n");
2160 if(anomalyRec > 0) {
2161 wholeScript.append(" <tr>\n");
2162 wholeScript.append(" <td>\n");
2163 wholeScript.append(" <table>\n");
2164 wholeScript.append(" <tr>\n");
2165 wholeScript.append(" <td align=\"center\"><font size=\"2px\"><B><align=\"center\">Anomaly Description</align></B></font></td>\n");
2166 wholeScript.append(" </tr>\n");
2167 wholeScript.append(" <tr>\n");
2168 wholeScript.append(" <td><div id=\"list"+reportRuntime.getReportID()+"\" style=\"width:" + widthInt + "px; height:50px;\"></div></td>\n" );
2169 wholeScript.append(" </tr>\n");
2170 wholeScript.append(" </table>\n");
2171 wholeScript.append(" </td>\n");
2172 wholeScript.append(" </tr>\n");
2174 wholeScript.append(" </table>\n");
2176 wholeScript.append(" <script type=\"text/javascript\">\n");
2177 wholeScript.append(" Dygraph.addEvent(document, \"mousewheel\", function() { lastClickedGraph = null; });\n");
2178 wholeScript.append(" Dygraph.addEvent(document, \"click\", function() { lastClickedGraph = null; });\n");
2179 wholeScript.append(" var data = []; \n");
2180 wholeScript.append(" data = [\n ");
2181 wholeScript.append( dataStrBuf.toString());
2182 wholeScript.append(" ];\n");
2183 wholeScript.append(" if(data.length > 0 ) { \n");
2184 wholeScript.append(" var orig_range = [ data[0][0].valueOf(), data[data.length - 1][0].valueOf() ];\n");
2186 wholeScript.append(" function nameAnnotation(ann) { \n");
2187 wholeScript.append(" return ann.shortText; \n");
2188 //wholeScript.append(" var m = moment(ann.x);\n");
2189 //wholeScript.append(" return \"(\" + ann.series + \", \" + m.format(\"YYYY-MM-DD HH\"); + \")\"; \n");
2190 wholeScript.append(" }\n");
2191 wholeScript.append(" anns = [];\n");
2193 wholeScript.append(" var graph_initialized = false;\n");
2194 wholeScript.append(" if(navigator.platform == 'iPad') { ");
2195 wholeScript.append(" g = new Dygraph(\n");
2196 wholeScript.append(" document.getElementById(\"div_g"+reportRuntime.getReportID()+"\"),\n");
2198 /*wholeScript.append(" [\n");
2199 wholeScript.append(dataStrBuf.toString());
2200 wholeScript.append(" ],\n");*/
2201 wholeScript.append(" data , \n");
2202 wholeScript.append(" {\n");
2207 StringBuilder labelStrBuf = new StringBuilder("");
2208 StringBuilder colorsStrBuf = new StringBuilder("");
2209 StringBuilder visibilityStrBuf = new StringBuilder("");
2210 int countChartValues = 0;
2211 for (Iterator iter = l.iterator(); iter.hasNext();) {
2212 dct = (DataColumnType) iter.next();
2213 if((dct.getChartSeq()!=null && dct.getChartSeq() >=0) || AppUtils.nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND)) {
2214 if(!AppUtils.nvl(dct.getDisplayName()).toLowerCase().equals("anomaly_text")) {
2216 labelStrBuf.append("'"+ dct.getDisplayName()+"',");
2217 if(!AppUtils.nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND))
2218 colorsStrBuf.append("'"+ AppUtils.nvl(dct.getChartColor())+"',");
2219 visibilityStrBuf.append("true,");
2223 if(labelStrBuf.indexOf(",")!=-1) {
2224 labelStrBuf.deleteCharAt(labelStrBuf.lastIndexOf(","));
2225 visibilityStrBuf.deleteCharAt(visibilityStrBuf.lastIndexOf(","));
2227 if(colorsStrBuf.indexOf(",")!=-1)
2228 colorsStrBuf.deleteCharAt(colorsStrBuf.lastIndexOf(","));
2230 //wholeScript.append("title: '" + (AppUtils.nvl(reportRuntime.getReportTitle()).length()>0?reportRuntime.getReportTitle():reportRuntime.getReportName()) + "',\n");
2231 wholeScript.append("maxNumberWidth:6,\n");
2232 wholeScript.append("xAxisHeight: 70,\n");
2233 wholeScript.append("yAxisLabelWidth: 70,\n");
2234 wholeScript.append("xAxisLabelWidth: 45,\n");
2235 wholeScript.append("axes: {\n");
2236 wholeScript.append("x: {\n");
2237 wholeScript.append(" axisLabelFormatter: function(d, gran) {\n");
2238 wholeScript.append(" var month = d.getMonth()+1;\n");
2239 wholeScript.append(" var day = d.getDate();\n");
2240 wholeScript.append(" var year = d.getFullYear();\n");
2241 wholeScript.append(" var hour = d.getHours();\n");
2242 wholeScript.append(" var minutes = d.getMinutes();\n");
2243 wholeScript.append(" var seconds = d.getSeconds();\n");
2244 wholeScript.append(" var wholeString = Dygraph.zeropad(month)+'/'+Dygraph.zeropad(day);\n");
2245 // wholeScript.append(" if(hour >= 0 && minutes > 0 && seconds > 0) {\n");
2246 //wholeScript.append(" wholeString += ' ' + Dygraph.zeropad(hour) + ':'+Dygraph.zeropad(minutes)+':'+Dygraph.zeropad(seconds);\n");
2247 //wholeScript.append(" } else if (hour >= 0 && minutes > 0 && seconds == 0) {\n");
2248 if(AppUtils.nvl(reportRuntime.getTimeAxisType()).length()==0 || AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("hourly"))
2249 wholeScript.append(" wholeString += ' ' + Dygraph.zeropad(hour) + ':'+Dygraph.zeropad(minutes);\n");
2250 //wholeScript.append(" } else if (hour >= 0 && (minutes >= 0 && seconds > 0)) {\n");
2251 //wholeScript.append(" wholeString += ' ' + Dygraph.zeropad(hour) + ':'+Dygraph.zeropad(minutes)+':'+Dygraph.zeropad(seconds);\n");
2252 //wholeScript.append(" } else if (hour >= 0) { \n");
2253 //wholeScript.append(" wholeString += ' ' + Dygraph.zeropad(hour); \n");
2254 //wholeScript.append(" } \n");
2255 wholeScript.append(" return wholeString; \n");
2256 wholeScript.append(" },\n");
2257 wholeScript.append(" ticker: function (a, b, pixels, opts, dygraph, vals) { \n ");
2258 wholeScript.append(" if(((b-a)/(1000*60*60)) <= 6) { \n");
2259 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.THIRTY_MINUTELY, opts, dygraph); \n");
2260 wholeScript.append(" } else if(((b-a)/(1000*60*60)) <= 12) { \n");
2261 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.HOURLY, opts, dygraph); \n");
2262 wholeScript.append(" } else if (((b-a)/(1000*60*60)) <= 25) \n ");
2263 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.TWO_HOURLY, opts, dygraph); \n ");
2264 wholeScript.append(" else if(((b-a)/(1000*60*60)) <= 78) \n ");
2265 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.SIX_HOURLY, opts, dygraph); \n ");
2266 wholeScript.append(" else if(((b-a)/(1000*60*60*24)) <= 12)\n");
2267 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.DAILY, opts, dygraph); \n");
2268 wholeScript.append(" else if(((b-a)/(1000*60*60*24)) <= 90) \n");
2269 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.WEEKLY, opts, dygraph); \n");
2270 wholeScript.append(" else \n");
2271 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.MONTHLY, opts, dygraph); \n");
2272 wholeScript.append(" }, \n");
2273 wholeScript.append(" valueFormatter: function(ms) { \n");
2274 wholeScript.append(" return new Date(ms).strftime(\"%m/%d/%Y %H:%M\"); \n");
2275 wholeScript.append( " }\n" );
2276 wholeScript.append(" }\n");
2277 wholeScript.append("},\n");
2278 wholeScript.append(" interactionModel : { \n");
2279 wholeScript.append(" 'mousedown' : downV4,\n");
2280 wholeScript.append(" touchstart : newDygraphTouchstart,\n");
2281 wholeScript.append(" touchend : Dygraph.defaultInteractionModel.touchend,\n");
2282 wholeScript.append(" touchmove : Dygraph.defaultInteractionModel.touchmove\n");
2283 //wholeScript.append(" 'dblclick' : dblClickV3,\n");
2284 //wholeScript.append(" 'mousewheel' : scrollV3\n");
2286 /*wholeScript.append(" 'mousedown' : downV3,\n");
2287 wholeScript.append(" 'mousemove' : moveV3,\n");
2288 wholeScript.append(" 'mouseup' : upV3,\n");
2289 wholeScript.append(" 'click' : clickV3,\n");
2290 wholeScript.append(" 'dblclick' : dblClickV3,\n");
2291 wholeScript.append(" 'mousewheel' : scrollV3\n");*/
2292 wholeScript.append("},\n");
2293 /*wholeScript.append(" zoomCallback: function(minDate, maxDate, yRanges) { \n");
2294 if(AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("daily")) {
2295 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60*24)) < 6) { \n");
2296 wholeScript.append(" maxDate = new Date(minDate).setMinutes(6*24*60);\n");
2297 wholeScript.append(" g.updateOptions({\n");
2298 wholeScript.append(" interactionModel: {},\n");
2299 wholeScript.append(" dateWindow: [minDate, maxDate]\n");
2300 wholeScript.append(" });\n");
2301 } else if (AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("hourly")) {
2302 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60)) <= 6) { \n");
2303 wholeScript.append(" maxDate = new Date(minDate).setMinutes(360);\n");
2304 wholeScript.append(" g.updateOptions({\n");
2305 wholeScript.append(" interactionModel: {},\n");
2306 wholeScript.append(" dateWindow: [minDate, maxDate]\n");
2307 wholeScript.append(" });\n");
2308 } else if (AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("30min")) {
2309 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60)) <= 3) { \n");
2310 wholeScript.append(" maxDate = new Date(minDate).setMinutes(180);\n");
2311 wholeScript.append(" g.updateOptions({\n");
2312 wholeScript.append(" interactionModel: {},\n");
2313 wholeScript.append(" dateWindow: [minDate, maxDate]\n");
2314 wholeScript.append(" });\n");
2315 } else if (AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("weekly")) {
2316 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60*24)) < 7) { \n");
2317 wholeScript.append(" maxDate = new Date(minDate).setMinutes(7*24*60);\n");
2318 wholeScript.append(" g.updateOptions({\n");
2319 wholeScript.append(" interactionModel: {},\n");
2320 wholeScript.append(" dateWindow: [minDate, maxDate]\n");
2321 wholeScript.append(" });\n");
2323 wholeScript.append(" } else {\n");
2324 wholeScript.append(" g.updateOptions({\n");
2325 wholeScript.append(" interactionModel : {\n");
2326 wholeScript.append(" 'mousedown' : downV3,\n");
2327 wholeScript.append(" 'mousemove' : moveV3,\n");
2328 wholeScript.append(" 'mouseup' : upV3,\n");
2329 wholeScript.append(" 'click' : clickV3,\n");
2330 wholeScript.append(" 'dblclick' : dblClickV3,\n");
2331 wholeScript.append(" 'mousewheel' : scrollV3\n");
2332 wholeScript.append(" }\n");
2333 wholeScript.append(" });\n");
2334 wholeScript.append(" } \n");
2335 wholeScript.append(" } ,\n");*/
2336 wholeScript.append("dateWindow: ["+minDate+", "+maxDate+"],\n");
2337 wholeScript.append("labels: ["+ labelStrBuf +"],\n");
2338 wholeScript.append("labelsDiv: \"labelDiv"+reportRuntime.getReportID()+"\",\n");
2339 wholeScript.append("labelsShowZeroValues: true,\n");
2340 if(AppUtils.nvl(reportRuntime.getLegendPosition()).length()>=0 && reportRuntime.getLegendPosition().equals("right")) {
2341 wholeScript.append("labelsSeparateLines: true,\n");
2343 wholeScript.append("labelsDivWidth: 200,\n");
2345 wholeScript.append("animatedZooms: true,\n");
2346 wholeScript.append("strokeWidth: 3.0,\n");
2347 wholeScript.append("strokeBorderWidth: 2.0,\n");
2348 /*wholeScript.append(" labelsDivStyles: { \n");
2349 wholeScript.append(" 'backgroundColor': 'rgba(200, 200, 255, 0.75)',\n");
2350 wholeScript.append(" 'padding': '4px',\n");
2351 wholeScript.append(" 'border': '1px solid black',\n");
2352 wholeScript.append(" 'borderRadius': '10px',\n");
2353 wholeScript.append(" 'boxShadow': '4px 4px 4px #888',\n");
2354 wholeScript.append(" 'width': '50px'\n");
2355 wholeScript.append("}, \n");
2357 wholeScript.append("visibility: ["+ visibilityStrBuf +"],\n");
2358 if(colorsStrBuf.length() > 0 && colorsStrBuf.length()>=(countChartValues*3+5))
2359 wholeScript.append("colors: ["+ colorsStrBuf +"],\n");
2361 wholeScript.append(" legend: 'always', \n");
2363 wholeScript.append(" ylabel: '"+ chartLeftAxisLabel +"' , \n");
2366 wholeScript.append(" xlabel: '"+ xAxisLabel +"' , \n");
2369 wholeScript.append(" drawPoints: true, \n");
2372 wholeScript.append(" stackedGraph: false, \n");
2375 for (Iterator iter = l.iterator(); iter.hasNext();) {
2376 dct = (DataColumnType) iter.next();
2377 if(!(nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND))) {
2378 if(!AppUtils.nvl(dct.getDisplayName()).toLowerCase().equals("anomaly_text")) {
2379 if(dct.getChartSeq()!=null && dct.getChartSeq() >=0) {
2380 wholeScript.append(" '"+ dct.getDisplayName() + "': {\n");
2381 if(AppUtils.nvl(dct.getChartLineType()).length()>0)
2382 wholeScript.append(" strokePattern: Dygraph.DASHED_LINE,\n");
2383 if(dct.isIsRangeAxisFilled()!=null && dct.isIsRangeAxisFilled().booleanValue()) {
2384 wholeScript.append(" fillGraph: true\n");
2386 wholeScript.append(" },\n");
2393 wholeScript.append(" 'Forecast': {\n");
2396 wholeScript.append(" strokePattern: Dygraph.DASHED_LINE,\n");
2399 wholeScript.append(" fillGraph: true\n");
2401 // close each labels
2402 wholeScript.append(" }\n");
2405 if(anomalyRec > 0) {
2406 wholeScript.append(" drawCallback: function(g, is_initial) { \n");
2407 wholeScript.append(" if (is_initial) { \n");
2408 wholeScript.append(" graph_initialized = true; \n");
2409 wholeScript.append(" if (anns.length > 0) { \n");
2410 wholeScript.append(" g.setAnnotations(anns); \n");
2411 wholeScript.append(" }\n");
2412 wholeScript.append(" }\n");
2414 wholeScript.append(" var anns1 = g.annotations();\n");
2415 //wholeScript.append(" var html = \"\";\n");
2416 wholeScript.append(" var html = \"<select id='x' size='1' style='width: "+ widthInt +"px; font-family : courier; font-size:8pt; font-weight:bold;'>\";\n");
2417 wholeScript.append(" for (var i = anns1.length-1; i >= 0 ; i--) {\n");
2418 wholeScript.append(" var name = nameAnnotation(anns1[i]);\n");
2419 //wholeScript.append(" html += \"<span id='\" + name + \"'>\"\n");
2420 wholeScript.append(" if(i==anns1.length-1)\n");
2421 wholeScript.append(" html += \"<option value='\" + name + \"' selected ><font size=1>\" \n");
2422 wholeScript.append(" else \n");
2423 wholeScript.append(" html += \"<option value='\" + name + \"'><font size=1>\" \n");
2424 wholeScript.append(" html += name \n");
2425 //wholeScript.append(" html += name + \": \" + (anns1[i].shortText || '(icon)')\n");
2426 //wholeScript.append(" html += \" -> \" + anns1[i].text + \"</span><br/>\";\n");
2427 wholeScript.append(" html += \" : \" + anns1[i].text + \"</font></option>\";\n");
2428 wholeScript.append(" }\n");
2429 wholeScript.append(" html += \"</select>\" \n");
2430 wholeScript.append(" document.getElementById(\"list"+reportRuntime.getReportID()+"\").innerHTML = html;\n");
2431 wholeScript.append(" }\n");
2434 wholeScript.append(" }\n");
2435 wholeScript.append(" )\n");
2438 wholeScript.append(annotationsStrBuf.toString());
2440 wholeScript.append(" if (graph_initialized) {\n");
2441 wholeScript.append(" g.setAnnotations(anns);\n");
2442 wholeScript.append(" } \n");
2443 //upate handler script
2445 wholeScript.append(" var saveBg = '';\n");
2446 wholeScript.append(" var num = 0;\n");
2447 wholeScript.append(" g.updateOptions( {\n");
2448 wholeScript.append(" annotationMouseOverHandler: function(ann) { \n");
2449 //wholeScript.append(" document.getElementById(nameAnnotation(ann)).style.fontWeight = 'bold';\n");
2450 //wholeScript.append(" saveBg = ann.div.style.backgroundColor;\n");
2451 //wholeScript.append(" ann.div.style.backgroundColor = '#ddd';\n");
2452 wholeScript.append(" var selectobject = document.getElementById(\"x\");\n");
2453 wholeScript.append(" for(var i=0; i<selectobject.length;i++) {\n ");
2454 wholeScript.append(" if(selectobject.options[i].value == nameAnnotation(ann)) {\n ");
2455 wholeScript.append(" selectobject.options[i].selected = true; \n ");
2456 wholeScript.append(" } ");
2457 wholeScript.append(" } ");
2459 wholeScript.append(" },\n");
2460 wholeScript.append(" annotationMouseOutHandler: function(ann) {\n");
2461 wholeScript.append(" document.getElementById(nameAnnotation(ann)).style.fontWeight = 'normal';\n");
2462 wholeScript.append(" ann.div.style.backgroundColor = saveBg;\n");
2463 //wholeScript.append(" var selectobject = document.getElementById(\"x\");\n");
2464 //wholeScript.append(" for(var i=0; i<selectobject.length;i++) {\n ");
2465 //wholeScript.append(" if(selectobject.options[i].value == nameAnnotation(ann)) {\n ");
2466 //wholeScript.append(" selectobject.options[i].selected = false; \n ");
2467 //wholeScript.append(" } ");
2468 //wholeScript.append(" } ");
2470 wholeScript.append(" }\n");
2472 wholeScript.append(" });\n");
2475 wholeScript.append("} else { \n");
2477 wholeScript.append(" g = new Dygraph(\n");
2478 wholeScript.append(" document.getElementById(\"div_g"+reportRuntime.getReportID()+"\"),\n");
2480 /*wholeScript.append(" [\n");
2481 wholeScript.append(dataStrBuf.toString());
2482 wholeScript.append(" ],\n");*/
2483 wholeScript.append(" data , \n");
2484 wholeScript.append(" {\n");
2489 labelStrBuf = new StringBuilder("");
2490 colorsStrBuf = new StringBuilder("");
2491 visibilityStrBuf = new StringBuilder("");
2492 countChartValues = 0;
2493 for (Iterator iter = l.iterator(); iter.hasNext();) {
2494 dct = (DataColumnType) iter.next();
2495 if((dct.getChartSeq()!=null && dct.getChartSeq() >=0) || AppUtils.nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND)) {
2496 if(!AppUtils.nvl(dct.getDisplayName()).toLowerCase().equals("anomaly_text")) {
2498 labelStrBuf.append("'"+ dct.getDisplayName()+"',");
2499 if(!AppUtils.nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND))
2500 colorsStrBuf.append("'"+ AppUtils.nvl(dct.getChartColor())+"',");
2501 visibilityStrBuf.append("true,");
2505 if(labelStrBuf.indexOf(",")!=-1) {
2506 labelStrBuf.deleteCharAt(labelStrBuf.lastIndexOf(","));
2507 visibilityStrBuf.deleteCharAt(visibilityStrBuf.lastIndexOf(","));
2509 if(colorsStrBuf.indexOf(",")!=-1)
2510 colorsStrBuf.deleteCharAt(colorsStrBuf.lastIndexOf(","));
2512 //wholeScript.append("title: '" + (AppUtils.nvl(reportRuntime.getReportTitle()).length()>0?reportRuntime.getReportTitle():reportRuntime.getReportName()) + "',\n");
2513 wholeScript.append("maxNumberWidth:6,\n");
2514 wholeScript.append("xAxisHeight: 70,\n");
2515 wholeScript.append("yAxisLabelWidth: 70,\n");
2516 wholeScript.append("xAxisLabelWidth: 45,\n");
2517 wholeScript.append("axes: {\n");
2518 wholeScript.append("x: {\n");
2519 wholeScript.append(" axisLabelFormatter: function(d, gran) {\n");
2520 wholeScript.append(" var month = d.getMonth()+1;\n");
2521 wholeScript.append(" var day = d.getDate();\n");
2522 wholeScript.append(" var year = d.getFullYear();\n");
2523 wholeScript.append(" var hour = d.getHours();\n");
2524 wholeScript.append(" var minutes = d.getMinutes();\n");
2525 wholeScript.append(" var seconds = d.getSeconds();\n");
2526 wholeScript.append(" var wholeString = Dygraph.zeropad(month)+'/'+Dygraph.zeropad(day);\n");
2527 // wholeScript.append(" if(hour >= 0 && minutes > 0 && seconds > 0) {\n");
2528 //wholeScript.append(" wholeString += ' ' + Dygraph.zeropad(hour) + ':'+Dygraph.zeropad(minutes)+':'+Dygraph.zeropad(seconds);\n");
2529 //wholeScript.append(" } else if (hour >= 0 && minutes > 0 && seconds == 0) {\n");
2530 if(AppUtils.nvl(reportRuntime.getTimeAxisType()).length()==0 || AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("hourly"))
2531 wholeScript.append(" wholeString += ' ' + Dygraph.zeropad(hour) + ':'+Dygraph.zeropad(minutes);\n");
2532 //wholeScript.append(" } else if (hour >= 0 && (minutes >= 0 && seconds > 0)) {\n");
2533 //wholeScript.append(" wholeString += ' ' + Dygraph.zeropad(hour) + ':'+Dygraph.zeropad(minutes)+':'+Dygraph.zeropad(seconds);\n");
2534 //wholeScript.append(" } else if (hour >= 0) { \n");
2535 //wholeScript.append(" wholeString += ' ' + Dygraph.zeropad(hour); \n");
2536 //wholeScript.append(" } \n");
2537 wholeScript.append(" return wholeString; \n");
2538 wholeScript.append(" },\n");
2539 wholeScript.append(" ticker: function (a, b, pixels, opts, dygraph, vals) { \n ");
2540 wholeScript.append(" if(((b-a)/(1000*60*60)) <= 6) { \n");
2541 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.THIRTY_MINUTELY, opts, dygraph); \n");
2542 wholeScript.append(" } else if(((b-a)/(1000*60*60)) <= 12) { \n");
2543 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.HOURLY, opts, dygraph); \n");
2544 wholeScript.append(" } else if (((b-a)/(1000*60*60)) <= 25) \n ");
2545 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.TWO_HOURLY, opts, dygraph); \n ");
2546 wholeScript.append(" else if(((b-a)/(1000*60*60)) <= 78) \n ");
2547 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.SIX_HOURLY, opts, dygraph); \n ");
2548 wholeScript.append(" else if(((b-a)/(1000*60*60*24)) <= 12)\n");
2549 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.DAILY, opts, dygraph); \n");
2550 wholeScript.append(" else if(((b-a)/(1000*60*60*24)) <= 90) \n");
2551 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.WEEKLY, opts, dygraph); \n");
2552 wholeScript.append(" else \n");
2553 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.MONTHLY, opts, dygraph); \n");
2554 wholeScript.append(" }, \n");
2555 wholeScript.append(" valueFormatter: function(ms) { \n");
2556 wholeScript.append(" return new Date(ms).strftime(\"%m/%d/%Y %H:%M\"); \n");
2557 wholeScript.append( " }\n" );
2558 wholeScript.append(" }\n");
2559 wholeScript.append("},\n");
2560 wholeScript.append(" interactionModel : { \n");
2562 wholeScript.append(" 'mousedown' : downV3,\n");
2563 wholeScript.append(" 'mousemove' : moveV3,\n");
2564 wholeScript.append(" 'mouseup' : upV3,\n");
2565 wholeScript.append(" 'click' : clickV3,\n");
2566 wholeScript.append(" 'dblclick' : dblClickV3,\n");
2567 wholeScript.append(" 'mousewheel' : scrollV3\n");
2568 wholeScript.append("},\n");
2569 wholeScript.append(" zoomCallback: function(minDate, maxDate, yRanges) { \n");
2570 if(AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("daily")) {
2571 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60*24)) < 6) { \n");
2572 wholeScript.append(" maxDate = new Date(minDate).setMinutes(6*24*60);\n");
2573 wholeScript.append(" g.updateOptions({\n");
2574 wholeScript.append(" interactionModel: {},\n");
2575 wholeScript.append(" dateWindow: [minDate, maxDate]\n");
2576 wholeScript.append(" });\n");
2577 } else if (AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("hourly")) {
2578 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60)) <= 6) { \n");
2579 wholeScript.append(" maxDate = new Date(minDate).setMinutes(360);\n");
2580 wholeScript.append(" g.updateOptions({\n");
2581 wholeScript.append(" interactionModel: {},\n");
2582 wholeScript.append(" dateWindow: [minDate, maxDate]\n");
2583 wholeScript.append(" });\n");
2584 } else if (AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("30min")) {
2585 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60)) <= 3) { \n");
2586 wholeScript.append(" maxDate = new Date(minDate).setMinutes(180);\n");
2587 wholeScript.append(" g.updateOptions({\n");
2588 wholeScript.append(" interactionModel: {},\n");
2589 wholeScript.append(" dateWindow: [minDate, maxDate]\n");
2590 wholeScript.append(" });\n");
2591 } else if (AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("weekly")) {
2592 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60*24)) < 7) { \n");
2593 wholeScript.append(" maxDate = new Date(minDate).setMinutes(7*24*60);\n");
2594 wholeScript.append(" g.updateOptions({\n");
2595 wholeScript.append(" interactionModel: {},\n");
2596 wholeScript.append(" dateWindow: [minDate, maxDate]\n");
2597 wholeScript.append(" });\n");
2599 wholeScript.append(" } else {\n");
2600 wholeScript.append(" g.updateOptions({\n");
2601 wholeScript.append(" interactionModel : {\n");
2602 wholeScript.append(" 'mousedown' : downV3,\n");
2603 wholeScript.append(" 'mousemove' : moveV3,\n");
2604 wholeScript.append(" 'mouseup' : upV3,\n");
2605 wholeScript.append(" 'click' : clickV3,\n");
2606 wholeScript.append(" 'dblclick' : dblClickV3,\n");
2607 wholeScript.append(" 'mousewheel' : scrollV3\n");
2608 wholeScript.append(" }\n");
2609 wholeScript.append(" });\n");
2610 wholeScript.append(" } \n");
2611 wholeScript.append(" } ,\n");
2612 wholeScript.append("dateWindow: ["+minDate+", "+maxDate+"],\n");
2613 wholeScript.append("labels: ["+ labelStrBuf +"],\n");
2614 wholeScript.append("labelsDiv: \"labelDiv"+reportRuntime.getReportID()+"\",\n");
2615 wholeScript.append("labelsShowZeroValues: true,\n");
2616 if(AppUtils.nvl(reportRuntime.getLegendPosition()).length()>=0 && reportRuntime.getLegendPosition().equals("right")) {
2617 wholeScript.append("labelsSeparateLines: true,\n");
2619 wholeScript.append("labelsDivWidth: 200,\n");
2622 wholeScript.append("animatedZooms: true,\n");
2623 wholeScript.append("strokeWidth: 3.0,\n");
2624 wholeScript.append("strokeBorderWidth: 2.0,\n");
2626 /*wholeScript.append(" labelsDivStyles: { \n");
2627 wholeScript.append(" 'backgroundColor': 'rgba(200, 200, 255, 0.75)',\n");
2628 wholeScript.append(" 'padding': '4px',\n");
2629 wholeScript.append(" 'border': '1px solid black',\n");
2630 wholeScript.append(" 'borderRadius': '10px',\n");
2631 wholeScript.append(" 'boxShadow': '4px 4px 4px #888',\n");
2632 wholeScript.append(" 'width': '50px'\n");
2633 wholeScript.append("}, \n");
2635 wholeScript.append("visibility: ["+ visibilityStrBuf +"],\n");
2636 if(colorsStrBuf.length() > 0 && colorsStrBuf.length()>=(countChartValues*3+5))
2637 wholeScript.append("colors: ["+ colorsStrBuf +"],\n");
2639 wholeScript.append(" legend: 'always', \n");
2641 wholeScript.append(" ylabel: '"+ chartLeftAxisLabel +"' , \n");
2644 wholeScript.append(" xlabel: '"+ xAxisLabel +"' , \n");
2648 wholeScript.append(" drawPoints: true, \n");
2651 wholeScript.append(" stackedGraph: false, \n");
2654 for (Iterator iter = l.iterator(); iter.hasNext();) {
2655 dct = (DataColumnType) iter.next();
2656 if(!(nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND))) {
2657 if(!AppUtils.nvl(dct.getDisplayName()).toLowerCase().equals("anomaly_text")) {
2658 if(dct.getChartSeq()!=null && dct.getChartSeq() >=0) {
2659 wholeScript.append(" '"+ dct.getDisplayName() + "': {\n");
2660 if(AppUtils.nvl(dct.getChartLineType()).length()>0)
2661 wholeScript.append(" strokePattern: Dygraph.DASHED_LINE,\n");
2662 if(dct.isIsRangeAxisFilled()!=null && dct.isIsRangeAxisFilled().booleanValue()) {
2663 wholeScript.append(" fillGraph: true\n");
2665 wholeScript.append(" },\n");
2672 wholeScript.append(" 'Forecast': {\n");
2675 wholeScript.append(" strokePattern: Dygraph.DASHED_LINE,\n");
2678 wholeScript.append(" fillGraph: true\n");
2680 // close each labels
2681 wholeScript.append(" }\n");
2684 if(anomalyRec > 0) {
2685 wholeScript.append(" drawCallback: function(g, is_initial) { \n");
2686 wholeScript.append(" if (is_initial) { \n");
2687 wholeScript.append(" graph_initialized = true; \n");
2688 wholeScript.append(" if (anns.length > 0) { \n");
2689 wholeScript.append(" g.setAnnotations(anns); \n");
2690 wholeScript.append(" }\n");
2691 wholeScript.append(" }\n");
2693 wholeScript.append(" var anns1 = g.annotations();\n");
2694 //wholeScript.append(" var html = \"\";\n");
2695 wholeScript.append(" var html = \"<select id='x' size='1' style='width: "+ widthInt +"px; font-family : courier; font-size:8pt; font-weight:bold;'>\";\n");
2696 wholeScript.append(" for (var i = anns1.length-1; i >= 0 ; i--) {\n");
2697 wholeScript.append(" var name = nameAnnotation(anns1[i]);\n");
2698 //wholeScript.append(" html += \"<span id='\" + name + \"'>\"\n");
2699 wholeScript.append(" if(i==anns1.length-1)\n");
2700 wholeScript.append(" html += \"<option value='\" + name + \"' selected ><font size=1>\" \n");
2701 wholeScript.append(" else \n");
2702 wholeScript.append(" html += \"<option value='\" + name + \"'><font size=1>\" \n");
2703 wholeScript.append(" html += name \n");
2704 //wholeScript.append(" html += name + \": \" + (anns1[i].shortText || '(icon)')\n");
2705 //wholeScript.append(" html += \" -> \" + anns1[i].text + \"</span><br/>\";\n");
2706 wholeScript.append(" html += \" : \" + anns1[i].text + \"</font></option>\";\n");
2707 wholeScript.append(" }\n");
2708 wholeScript.append(" html += \"</select>\" \n");
2709 wholeScript.append(" document.getElementById(\"list"+reportRuntime.getReportID()+"\").innerHTML = html;\n");
2710 wholeScript.append(" }\n");
2713 wholeScript.append(" }\n");
2714 wholeScript.append(" )\n");
2717 wholeScript.append(annotationsStrBuf.toString());
2719 wholeScript.append(" if (graph_initialized) {\n");
2720 wholeScript.append(" g.setAnnotations(anns);\n");
2721 wholeScript.append(" } \n");
2722 //upate handler script
2724 wholeScript.append(" var saveBg = '';\n");
2725 wholeScript.append(" var num = 0;\n");
2726 wholeScript.append(" g.updateOptions( {\n");
2727 wholeScript.append(" annotationMouseOverHandler: function(ann) { \n");
2728 //wholeScript.append(" document.getElementById(nameAnnotation(ann)).style.fontWeight = 'bold';\n");
2729 //wholeScript.append(" saveBg = ann.div.style.backgroundColor;\n");
2730 //wholeScript.append(" ann.div.style.backgroundColor = '#ddd';\n");
2731 wholeScript.append(" var selectobject = document.getElementById(\"x\");\n");
2732 wholeScript.append(" for(var i=0; i<selectobject.length;i++) {\n ");
2733 wholeScript.append(" if(selectobject.options[i].value == nameAnnotation(ann)) {\n ");
2734 wholeScript.append(" selectobject.options[i].selected = true; \n ");
2735 wholeScript.append(" } ");
2736 wholeScript.append(" } ");
2738 wholeScript.append(" },\n");
2739 wholeScript.append(" annotationMouseOutHandler: function(ann) {\n");
2740 //wholeScript.append(" document.getElementById(nameAnnotation(ann)).style.fontWeight = 'normal';\n");
2741 wholeScript.append(" ann.div.style.backgroundColor = saveBg;\n");
2742 //wholeScript.append(" var selectobject = document.getElementById(\"x\");\n");
2743 //wholeScript.append(" for(var i=0; i<selectobject.length;i++) {\n ");
2744 //wholeScript.append(" if(selectobject.options[i].value == nameAnnotation(ann)) {\n ");
2745 //wholeScript.append(" selectobject.options[i].selected = false; \n ");
2746 //wholeScript.append(" } ");
2747 //wholeScript.append(" } ");
2749 wholeScript.append(" }\n");
2751 wholeScript.append(" });\n");
2754 wholeScript.append("} \n");
2756 wholeScript.append("} else {\n");
2757 wholeScript.append("document.getElementById(\"message"+ reportRuntime.getReportID()+"\").display = \"none\";\n");
2758 wholeScript.append("document.getElementById(\"labelDiv"+ reportRuntime.getReportID()+"\").display=\"none\";\n");
2759 wholeScript.append("document.getElementById(\"div_g"+reportRuntime.getReportID()+"\").display=\"none\";\n");
2761 wholeScript.append("document.getElementById(\"div_g"+reportRuntime.getReportID()+"\").innerHTML = \"<div id='noData'><b>No Data Available</b></div>\";\n");
2762 wholeScript.append("document.getElementById(\"div_g"+reportRuntime.getReportID()+"\").className=\"nodatadiv\";\n");
2763 wholeScript.append("document.getElementById(\"nodata\").className=\"nodatainner\";\n");
2765 wholeScript.append("document.getElementById(\"list"+reportRuntime.getReportID()+"\").display=\"none\";\n");
2766 wholeScript.append("}\n");
2767 wholeScript.append(" </script>\n");
2768 wholeScript.append(" </body>\n");
2769 wholeScript.append("</html>");
2772 } else if (chartType.equals(AppConstants.GT_SCATTER)) {
2774 wholeScript.append("<link href=\""+ chartScriptsPath +"d3/css/nv.d3.css\" rel=\"stylesheet\" type=\"text/css\">\n");
2775 wholeScript.append("<style>\n " +
2777 " overflow-y:scroll; \n" +
2780 " font: 12px sans-serif; \n" +
2782 " tr.z-row-over > td.z-row-inner, tr.z-row-over > .z-cell {" +
2783 " background-color: rgb(255, 255, 255); "+
2785 " svg { display: block; } " +
2786 " #chart1 svg { \n" +
2787 " height: 420px; \n" +
2788 " width: 800px; \n" +
2789 " min-width: 100px; \n" +
2790 " min-height: 100px; \n" +
2794 wholeScript.append("<body> \n");
2795 wholeScript.append("<div id=\"chart1\"><svg></svg></div>");
2797 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/d3.v2.js\"></script>\n");
2798 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/nv.d3.js\"></script> \n");
2799 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/tooltip.js\"></script> \n");
2800 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/utils.js\"></script> \n");
2801 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/models/legend.js\"></script> \n");
2802 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/models/axis.js\"></script> \n");
2803 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/models/distribution.js\"></script> \n");
2804 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/models/scatter.js\"></script> \n");
2805 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/models/scatterChart.js\"></script> \n");
2806 wholeScript.append("<script> \n");
2807 wholeScript.append("nv.addGraph(function() { \n" +
2808 " var width1=900, height1=220; \n" +
2809 " var chart = nv.models.scatterChart() \n" +
2810 " .showDistX(true) \n" +
2811 " .showDistY(true) \n" +
2812 " .useVoronoi(true) \n" +
2813 " .color(d3.scale.category10().range()); \n" +
2814 /* " .width(width1) \n" +
2815 " .height(height1); \n" +
2816 */ " chart.xAxis\n" +
2817 " .axisLabel('" +legendColumnName + "')\n" +
2818 " .tickFormat(d3.format('.02f'));\n" +
2820 " .axisLabel('" + chartLeftAxisLabel + "')\n" +
2821 " .tickFormat(d3.format('.02f'));\n" +
2822 " d3.select('#chart1 svg') \n" +
2823 " .datum(getData()) \n" );
2825 wholeScript.append(" .transition().duration(1200) \n" );
2826 /* " .attr(\"width\", width1) \n" +
2827 " .attr(\"height\", height1) \n" +
2828 */ wholeScript.append(" .call(chart); \n" +
2829 " nv.utils.windowResize(chart.update);\n"+
2830 "return chart; \n" +
2833 String dateStr = "";
2834 Object uniqueElements [] = null;
2835 TreeSet ts = new TreeSet();
2836 for (int i = 0; i < ds.getRowCount(); i++) {
2837 dateStr = ds.getString(i, 2);
2838 if(dateStr.length()>0)
2841 SortedSet s = Collections.synchronizedSortedSet(ts);
2842 uniqueElements = s.toArray();
2844 wholeScript.append(" function getData() { \n " +
2845 " var data = [];\n ");
2846 for (int i = 0; i < uniqueElements.length; i++) {
2847 wholeScript.append(" data.push( {key:'"+ uniqueElements[i]+ "', values:[]})\n");
2851 for (int i = 0; i < ds.getRowCount(); i++) {
2852 for (int k = 0; k < uniqueElements.length; k++) {
2853 if(ds.getString(i, 2).equals(uniqueElements[k])) {
2854 wholeScript.append("data["+k+"].values.push({x:"+ ds.getString(i, 1) +",y:"+ds.getString(i, 3) + ", size: Math.random() });\n");
2859 wholeScript.append("return data; } </script></body>\n");
2860 } else if (chartType.equals(AppConstants.GT_HIERARCHICAL_SUNBURST)) {
2862 StringBuilder dataStr = new StringBuilder("");
2863 StringBuilder groupBuffer = new StringBuilder("");
2864 StringBuilder s = new StringBuilder("");
2865 dataStr.append("{");
2866 dataStr.append(" \"xxxxxx\":{\n");
2869 String level = "-1";
2870 String levelOld = "-1";
2872 for (int i = 0; i < ds.getRowCount(); i++) {
2873 mid = ds.getString(i, "mid");
2874 level = ds.getString(i, "level1");
2875 eid = ds.getString(i, "eid");
2876 if(mid.equals(midOld)) {
2877 dataStr.append("\""+ eid +"\": 9956,\n");
2879 if(dataStr.lastIndexOf(",")!= -1)
2880 dataStr.deleteCharAt(dataStr.lastIndexOf(","));
2881 //if(Integer.parseInt(levelOld)==Integer.parseInt(level))
2882 //dataStr.append("},\n");
2883 if (Integer.parseInt(levelOld)<Integer.parseInt(level))
2884 dataStr.append("},\n");
2885 dataStr.append("\""+ mid +"\": { \n");
2891 if(dataStr.toString().endsWith(","))
2892 dataStr.deleteCharAt(dataStr.lastIndexOf(","));
2893 dataStr.append("}\n");
2894 dataStr.append("}\n");
2896 String formattedReportName = new HtmlStripper().stripSpecialCharacters(reportRuntime.getReportName());
2897 String formattedDate = new SimpleDateFormat("MMddyyyyHHmm").format(new java.util.Date());
2898 String filename=formattedReportName+formattedDate+user_id+".json";
2899 String filenamepath = AppUtils.getExcelTemplatePath()+"../../json/"+filename;
2900 System.out.println("filenamepath " + filenamepath);
2901 BufferedWriter out = new BufferedWriter(new FileWriter(filenamepath));
2902 out.write(dataStr.toString());
2904 request.getSession().setAttribute("jsonFileName", filename);
2905 } catch (IOException e) {
2906 e.printStackTrace();
2907 System.out.println("Exception ");
2909 } else if (chartType.equals(AppConstants.GT_HIERARCHICAL)) {
2911 StringBuilder dataStr = new StringBuilder("");
2912 StringBuilder groupBuffer = new StringBuilder("");
2913 StringBuilder s = new StringBuilder("");
2914 dataStr.append("{");
2915 dataStr.append(" \"groups\":[");
2917 for (int i = 0; i < ds.getRowCount(); i++) {
2918 if(ds.getString(i,"group_ind").equals("Y")) {
2919 groupBuffer.append(" { \"name\": \""+ ds.getString(i,"ei1") +"\" },\n");
2923 groupBuffer.deleteCharAt(groupBuffer.lastIndexOf(","));
2924 dataStr.append(groupBuffer.toString());
2925 dataStr.append("],");
2926 dataStr.append("\"nodes\":[");
2927 int rowCount = ds.getRowCount();
2928 for (int i = 0; i < ds.getRowCount(); i++) {
2929 s.append("{ \"name\": \""+ ds.getString(i,"ei1") +"\" , \"group\":"+ ds.getString(i,"groups") +", \"level\":2 }");
2930 if (i < (rowCount-1))
2933 s = new StringBuilder("");
2936 dataStr.append("],");
2937 dataStr.append("\"links\":[");
2938 for (int i = 0; i < ds.getRowCount(); i++) {
2939 s.append("{ \"source\": "+ ds.getString(i,"source") +" , \"target\":"+ ds.getString(i,"target") +", \"value\":2 }");
2940 if (i < (rowCount-1))
2943 s = new StringBuilder("");
2945 dataStr.append("]}");
2947 String formattedReportName = new HtmlStripper().stripSpecialCharacters(reportRuntime.getReportName());
2948 String formattedDate = new SimpleDateFormat("MMddyyyyHHmm").format(new java.util.Date());
2949 String filename=formattedReportName+formattedDate+user_id+".json";
2950 String filenamepath = AppUtils.getExcelTemplatePath()+"../../json/"+filename;
2951 System.out.println("filenamepath " + filenamepath);
2952 BufferedWriter out = new BufferedWriter(new FileWriter(filenamepath));
2953 out.write(dataStr.toString());
2955 request.getSession().setAttribute("jsonFileName", filename);
2956 } catch (IOException e) {
2957 e.printStackTrace();
2958 System.out.println("Exception ");
2964 try(BufferedWriter out = new BufferedWriter(new FileWriter("test.txt"))) {
2965 out.write(wholeScript.toString());
2966 } catch (IOException e) {
2967 e.printStackTrace();
2968 System.out.println("Exception ");
2970 return wholeScript.toString();
2973 public String nvl(String s) {
2974 return (s == null) ? "" : s;
2977 public String nvl(String s, String sDefault) {
2978 return nvl(s).equals("") ? sDefault : s;
2981 public static String nvls(String s) {
2982 return (s == null) ? "" : s;
2985 public static String nvls(String s, String sDefault) {
2986 return nvls(s).equals("") ? sDefault : s;
2989 public boolean getFlagInBoolean(String s) {
2990 return nvl(s).toUpperCase().startsWith("Y") || nvl(s).toLowerCase().equals("true");
2993 public DataSet loadChartData(String userId, HttpServletRequest request) throws RaptorException {
2994 if (nvl(getChartType()).length() == 0)
2996 //TODO: display chart function to be added.
2997 //if (!getDisplayChart())
3001 sql = generateChartSQL(userId, request);
3002 logger.debug(EELFLoggerDelegate.debugLogger, ("SQL generated " + sql));
3003 String dbInfo = reportRuntime.getDBInfo();
3004 DataSet ds = ConnectionUtils.getDataSet(sql, dbInfo);
3005 if(ds.getRowCount()<=0) {
3006 printDebugLogSeparatorLine();
3007 logger.debug(EELFLoggerDelegate.debugLogger, (getChartType().toUpperCase()+" - " + REPORT_ID + reportRuntime.getReportID() + " DATA IS EMPTY" ));
3008 logger.debug(EELFLoggerDelegate.debugLogger, (QUERY + sql));
3009 printDebugLogSeparatorLine();
3015 public String generateChartSQL(String userId, HttpServletRequest request ) throws RaptorException {
3016 List reportCols = reportRuntime.getAllColumns();
3017 List chartValueCols = getChartValueColumnsList(AppConstants.CHART_ALL_COLUMNS, null); // parameter is 0 has this requires all columns.
3018 String reportSQL = reportRuntime.getWholeSQL();
3020 //Add order by clause
3021 Pattern re1 = Pattern.compile("(^[\r\n]*|([\\s]))[Oo][Rr][Dd][Ee][Rr](.*?[^\r\n]*)[Bb][Yy]",Pattern.DOTALL);
3022 //Pattern re1 = Pattern.compile("order(.*?[^\r\n]*)by", Pattern.DOTALL);
3023 Matcher matcher = re1.matcher(reportSQL);
3024 //Pattern re1 = Pattern.compile("(^[\r\n]*|([\\s]))[Oo][Rr][Dd][Ee][Rr][Tt](.*?[^\r\n]*)[Bb][Yy]",Pattern.DOTALL);
3025 //int startPoint = sql.length()-30;
3027 reportSQL = reportSQL + " ";
3028 reportSQL = Pattern.compile("(^[\r\n]*|([\\s]))[Ss][Ee][Ll][Ee][Cc][Tt]([\r\n]*|[\\s]*)",Pattern.DOTALL).matcher(reportSQL).replaceAll(" SELECT ");
3029 //reportSQL = Pattern.compile("(^[\r\n]*|([\\s]))[Ff][Rr][Oo][Mm]([\r\n]*|[\\s]*)",Pattern.DOTALL).matcher(reportSQL).replaceAll(" FROM ");
3030 reportSQL = Pattern.compile("(^[\r\n]*|([\\s]))[Ww][Hh][Ee][Rr][Ee]([\r\n]*|[\\s]*)",Pattern.DOTALL).matcher(reportSQL).replaceAll(" WHERE ");
3031 reportSQL = Pattern.compile("(^[\r\n]*|([\\s]))[Ww][Hh][Ee][Nn]([\r\n]*|[\\s]*)",Pattern.DOTALL).matcher(reportSQL).replaceAll(" WHEN ");
3032 reportSQL = Pattern.compile("(^[\r\n]*|([\\s]))[Aa][Nn][Dd]([\r\n]*|[\\s]*)",Pattern.DOTALL).matcher(reportSQL).replaceAll(" AND ");
3034 if(!reportRuntime.getReportType().equals(AppConstants.RT_HIVE)) {
3035 int startPoint = reportSQL.lastIndexOf(" FROM ");
3036 if(startPoint <= 0) {
3037 startPoint = reportSQL.lastIndexOf(" from ");
3039 if(startPoint <= 0) {
3040 startPoint = reportSQL.lastIndexOf("from ");
3042 if(startPoint <= 0) {
3043 startPoint = reportSQL.lastIndexOf("FROM ");
3046 if (!matcher.find(startPoint)) {
3047 reportSQL = reportSQL + " ORDER BY 1" ;
3050 reportRuntime.setWholeSQL(reportSQL);
3052 printDebugLogSeparatorLine();
3053 logger.debug(EELFLoggerDelegate.debugLogger, ("WHOLE_SQL" + reportSQL));
3054 printDebugLogSeparatorLine();
3056 if (reportRuntime.getFormFieldList() != null) {
3057 for (Iterator iter = reportRuntime.getFormFieldList().getFormField().iterator(); iter.hasNext();) {
3058 FormFieldType fft = (FormFieldType) iter.next();
3059 String fieldId = fft.getFieldId();
3060 String fieldDisplay = reportRuntime.getFormFieldDisplayName(fft);
3061 String formfield_value = "";
3062 formfield_value = AppUtils.getRequestNvlValue(request, fieldId);
3063 String paramValue = nvl(formfield_value);
3064 if(paramValue.length()>0) {
3065 /*sql = Utils.replaceInString(sql, "'" + fieldDisplay + "'", nvl(
3066 paramValue, "NULL"));*/
3067 reportSQL = Utils.replaceInString(reportSQL, fieldDisplay, nvl(
3068 paramValue, "NULL"));
3070 /*sql = Utils.replaceInString(sql, "'" + fieldDisplay + "'", nvl(
3071 paramValue, "NULL"));*/
3072 reportSQL = Utils.replaceInString(reportSQL, "'" + fieldDisplay + "'", nvl(
3073 paramValue, "NULL"));
3074 reportSQL = Utils.replaceInString(reportSQL, fieldDisplay , nvl(
3075 paramValue, "NULL"));
3078 logger.debug(EELFLoggerDelegate.debugLogger, ("SQL " + reportSQL));
3079 String legendCol = "1 a";
3080 // String valueCol = "1";
3081 StringBuilder groupCol = new StringBuilder();
3082 StringBuilder seriesCol = new StringBuilder();
3083 StringBuilder valueCols = new StringBuilder();
3085 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
3086 DataColumnType dc = (DataColumnType) iter.next();
3087 String colName = getColumnSelectStr(dc, request);
3088 if (nvl(dc.getColOnChart()).equals(AppConstants.GC_LEGEND))
3089 legendCol = getSelectExpr(dc, colName)+" " + dc.getColId();
3090 // if(dc.getChartSeq()>0)
3091 // valueCol = "NVL("+colName+", 0) "+dc.getColId();
3092 if ((!nvl(dc.getColOnChart()).equals(AppConstants.GC_LEGEND))
3093 && (dc.getChartSeq()!=null && dc.getChartSeq().intValue() <= 0) && dc.isGroupBreak()) {
3094 groupCol.append(", ");
3095 groupCol.append(colName + " " + dc.getColId());
3098 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
3099 DataColumnType dc = (DataColumnType) iter.next();
3100 if(dc.isChartSeries()!=null && dc.isChartSeries().booleanValue()) {
3101 //System.out.println("*****************, "+ " " +getColumnSelectStr(dc, paramValues)+ " "+ getSelectExpr(dc,getColumnSelectStr(dc, paramValues)));
3102 seriesCol.append(", "+ getSelectExpr(dc,getColumnSelectStr(dc, request))+ " " + dc.getColId());
3106 /*for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
3107 DataColumnType dc = (DataColumnType) iter.next();
3108 if(!dc.isChartSeries() && !(nvl(dc.getColOnChart()).equals(AppConstants.GC_LEGEND))) {
3109 //System.out.println("*****************, "+ " " +getColumnSelectStr(dc, paramValues)+ " "+ getSelectExpr(dc,getColumnSelectStr(dc, paramValues)));
3110 seriesCol.append(", "+ formatChartColumn(getSelectExpr(dc,getColumnSelectStr(dc, paramValues)))+ " " + dc.getColId());
3114 for (Iterator iter = chartValueCols.iterator(); iter.hasNext();) {
3115 DataColumnType dc = (DataColumnType) iter.next();
3116 String colName = getColumnSelectStr(dc, request);
3117 String paramValue = "";
3118 if(AppUtils.nvl(colName).startsWith("[")) {
3119 if (reportRuntime.getFormFieldList() != null) {
3120 for (Iterator iterC = reportRuntime.getFormFieldList().getFormField().iterator(); iterC.hasNext();) {
3121 FormFieldType fft = (FormFieldType) iterC.next();
3122 String fieldId = fft.getFieldId();
3123 String fieldDisplay = reportRuntime.getFormFieldDisplayName(fft);
3124 String formfield_value = "";
3125 if(AppUtils.nvl(fieldDisplay).equals(colName)) {
3126 formfield_value = AppUtils.getRequestNvlValue(request, fieldId);
3127 paramValue = nvl(formfield_value);
3133 seriesCol.append("," + (AppUtils.nvl(paramValue).length()>0? paramValue:"null") + " " + dc.getColId());
3135 //valueCols.append(", NVL(" + formatChartColumn(colName) + ",0) " + dc.getColId());
3136 seriesCol.append("," + (AppUtils.nvl(paramValue).length()>0? paramValue:formatChartColumn(colName)) + " " + dc.getColId());
3140 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
3141 DataColumnType dc = (DataColumnType) iter.next();
3142 String colName = dc.getDisplayName();
3143 String colValue = getColumnSelectStr(dc, request);
3144 //String colName = getColumnSelectStr(dc, formGrid);
3145 if(colName.equals(AppConstants.RI_CHART_TOTAL_COL))
3146 seriesCol.append(", " + AppConstants.RI_CHART_TOTAL_COL + " " + AppConstants.RI_CHART_TOTAL_COL );
3147 if (colName.equals(AppConstants.RI_CHART_COLOR))
3148 seriesCol.append(", " + colValue + " " + AppConstants.RI_CHART_COLOR );
3149 if(colName.equals(AppConstants.RI_CHART_MARKER_START))
3150 seriesCol.append(", " + AppConstants.RI_CHART_MARKER_START + " " + AppConstants.RI_CHART_MARKER_START );
3151 if(colName.equals(AppConstants.RI_CHART_MARKER_END))
3152 seriesCol.append(", " + AppConstants.RI_CHART_MARKER_END + " " + AppConstants.RI_CHART_MARKER_END );
3153 if(colName.equals(AppConstants.RI_CHART_MARKER_TEXT_LEFT))
3154 seriesCol.append(", " + AppConstants.RI_CHART_MARKER_TEXT_LEFT + " " + AppConstants.RI_CHART_MARKER_TEXT_LEFT );
3155 if(colName.equals(AppConstants.RI_CHART_MARKER_TEXT_RIGHT))
3156 seriesCol.append(", " + AppConstants.RI_CHART_MARKER_TEXT_RIGHT + " " + AppConstants.RI_CHART_MARKER_TEXT_RIGHT );
3157 //if(colName.equals(AppConstants.RI_ANOMALY_TEXT))
3158 //seriesCol.append(", " + AppConstants.RI_ANOMALY_TEXT + " " + AppConstants.RI_ANOMALY_TEXT );
3161 //debugLogger.debug("ReportSQL Chart " + reportSQL );
3162 /*for (Iterator iter = chartValueCols.iterator(); iter.hasNext();) {
3163 DataColumnType dc = (DataColumnType) iter.next();
3164 String colName = getColumnSelectStr(dc, paramValues);
3165 //valueCols.append(", NVL(" + formatChartColumn(colName) + ",0) " + dc.getColId());
3166 valueCols.append("," + formatChartColumn(colName) + " " + dc.getColId());
3168 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
3169 DataColumnType dc = (DataColumnType) iter.next();
3170 String colName = getColumnSelectStr(dc, paramValues);
3171 //if(colName.equals(AppConstants.RI_CHART_TOTAL_COL) || colName.equals(AppConstants.RI_CHART_COLOR)) {
3172 if(colName.equals(AppConstants.RI_CHART_TOTAL_COL))
3173 valueCols.append(", " + AppConstants.RI_CHART_TOTAL_COL + " " + AppConstants.RI_CHART_TOTAL_COL );
3174 if (colName.equals(AppConstants.RI_CHART_COLOR))
3175 valueCols.append(", " + AppConstants.RI_CHART_COLOR + " " + AppConstants.RI_CHART_COLOR );
3176 if (colName.equals(AppConstants.RI_CHART_INCLUDE))
3177 valueCols.append(", " + AppConstants.RI_CHART_INCLUDE + " " + AppConstants.RI_CHART_INCLUDE );
3180 String final_sql = "";
3181 reportSQL = Utils.replaceInString(reportSQL, " from ", " FROM ");
3182 reportSQL = Utils.replaceInString(reportSQL, " From ", " FROM ");
3183 reportSQL = Utils.replaceInString(reportSQL, " select ", " SELECT ");
3184 reportSQL = Utils.replaceInString(reportSQL, " union ", " UNION ");
3185 //reportSQL = reportSQL.replaceAll("[\\s]*\\(", "(");
3186 // if(reportSQL.indexOf("UNION") != -1) {
3187 // if(reportSQL.indexOf("FROM(")!=-1)
3188 // final_sql += " "+reportSQL.substring(reportSQL.indexOf("FROM(") );
3189 // else if (reportSQL.indexOf("FROM (")!=-1)
3190 // final_sql += " "+reportSQL.substring(reportSQL.indexOf("FROM (") );
3191 // //TODO ELSE THROW ERROR
3194 // final_sql += " "+reportSQL.substring(reportSQL.toUpperCase().indexOf(" FROM "));
3197 int pos_first_select = 0;
3198 int pos_dup_select = 0;
3199 int pos_prev_select = 0;
3200 int pos_last_select = 0;
3201 if (reportSQL.indexOf("FROM", pos)!=-1) {
3202 pos = reportSQL.indexOf("FROM", pos);
3203 pos_dup_select = reportSQL.lastIndexOf("SELECT",pos);
3204 pos_first_select = reportSQL.indexOf("SELECT");//,pos);
3205 logger.debug(EELFLoggerDelegate.debugLogger, ("pos_select " + pos_first_select + " " + pos_dup_select));
3206 if(pos_dup_select > pos_first_select) {
3207 logger.debug(EELFLoggerDelegate.debugLogger, ("********pos_dup_select ********" + pos_dup_select));
3208 //pos_dup_select1 = pos_dup_select;
3209 pos_prev_select = pos_first_select;
3210 pos_last_select = pos_dup_select;
3211 while (pos_last_select > pos_prev_select) {
3212 logger.debug(EELFLoggerDelegate.debugLogger, ("pos_last , pos_prev " + pos_last_select + " " + pos_prev_select));
3213 pos = reportSQL.indexOf("FROM", pos+2);
3214 pos_prev_select = pos_last_select;
3215 pos_last_select = reportSQL.lastIndexOf("SELECT",pos);
3216 logger.debug(EELFLoggerDelegate.debugLogger, ("in WHILE LOOP LAST " + pos_last_select));
3221 final_sql += " "+reportSQL.substring(pos);
3222 logger.debug(EELFLoggerDelegate.debugLogger, ("Final SQL " + final_sql));
3223 String sql = "SELECT " + legendCol + ", " + legendCol+"_1" + seriesCol.toString()+ nvl(valueCols.toString(), ", 1")
3224 + groupCol.toString()
3226 logger.debug(EELFLoggerDelegate.debugLogger, ("Final sql in generateChartSQL " +sql));
3229 } // generateChartSQL
3231 private String getColumnSelectStr(DataColumnType dc, HttpServletRequest request) {
3232 //String colName = dc.isCalculated() ? dc.getColName()
3233 // : ((nvl(dc.getTableId()).length() > 0) ? (dc.getTableId() + "." + dc
3234 // .getColName()) : dc.getColName());
3235 String colName = dc.getColName();
3236 String paramValue = null;
3237 //if (dc.isCalculated()) {
3238 if (reportRuntime.getFormFieldList() != null) {
3239 for (Iterator iter = reportRuntime.getFormFieldList().getFormField().iterator(); iter.hasNext();) {
3240 FormFieldType fft = (FormFieldType) iter.next();
3241 String fieldId = fft.getFieldId();
3242 String fieldDisplay = reportRuntime.getFormFieldDisplayName(fft);
3243 String formfield_value = "";
3244 formfield_value = AppUtils.getRequestNvlValue(request, fieldId);
3245 paramValue = nvl(formfield_value);
3246 if(paramValue.length()>0) {
3247 /*sql = Utils.replaceInString(sql, "'" + fieldDisplay + "'", nvl(
3248 paramValue, "NULL"));*/
3249 colName = Utils.replaceInString(colName, "'" + fieldDisplay + "'", "'"+nvl(
3250 paramValue, "NULL")+"'");
3251 colName = Utils.replaceInString(colName, fieldDisplay, nvl(
3252 paramValue, "NULL"));
3259 } // getColumnSelectStr
3263 public String getSelectExpr(DataColumnType dct) {
3265 // dct.isCalculated()?dct.getColName():((nvl(dct.getTableId()).length()>0)?(dct.getTableId()+"."+dct.getColName()):dct.getColName());
3266 return getSelectExpr(dct, dct.getColName() /* colName */);
3269 private String getSelectExpr(DataColumnType dct, String colName) {
3270 String colType = dct.getColType();
3271 if (colType.equals(AppConstants.CT_CHAR)
3272 || ((nvl(dct.getColFormat()).length() == 0) && (!colType
3273 .equals(AppConstants.CT_DATE))))
3276 return "DATE_FORMAT(" + colName + ", '"
3277 + nvl(dct.getColFormat(), AppConstants.DEFAULT_DATE_FORMAT) + "')";
3280 private String formatChartColumn(String colName) {
3281 logger.debug(EELFLoggerDelegate.debugLogger, ("Format Chart Column Input colName " + colName));
3282 colName = colName.trim();
3283 colName = Utils.replaceInString(colName, "TO_CHAR", "to_char");
3284 colName = Utils.replaceInString(colName, "to_number", "TO_NUMBER");
3285 //reportSQL = reportSQL.replaceAll("[\\s]*\\(", "(");
3286 colName = colName.replaceAll(",[\\s]*\\(", ",(");
3287 StringBuilder colNameBuf = new StringBuilder(colName);
3288 int pos = 0, posFormatStart = 0, posFormatEnd = 0;
3291 if(colNameBuf.indexOf("999")==-1 && colNameBuf.indexOf("990")==-1) {
3292 logger.debug(EELFLoggerDelegate.debugLogger, (" return colName " + colNameBuf.toString()));
3293 return colNameBuf.toString();
3296 while (colNameBuf.indexOf("to_char")!=-1) {
3297 if(colNameBuf.indexOf("999")!=-1 || colNameBuf.indexOf("990")!=-1) {
3298 pos = colNameBuf.indexOf("to_char");
3299 colNameBuf.insert(pos, " TO_NUMBER ( CR_RAPTOR.SAFE_TO_NUMBER (");
3300 pos = colNameBuf.indexOf("to_char");
3301 colNameBuf.replace(pos, pos+7, "TO_CHAR");
3302 //colName = Utils.replaceInString(colNameBuf.toString(), "to_char", " TO_NUMBER ( CR_RAPTOR.SAFE_TO_NUMBER ( TO_CHAR ");
3303 logger.debug(EELFLoggerDelegate.debugLogger, ("After adding to_number " + colNameBuf.toString()));
3304 //posFormatStart = colNameBuf.lastIndexOf(",'")+1;
3305 posFormatStart = colNameBuf.indexOf(",'", pos)+1;
3306 posFormatEnd = colNameBuf.indexOf(")",posFormatStart);
3307 logger.debug(EELFLoggerDelegate.debugLogger, (posFormatStart + " " + posFormatEnd + " "+ pos));
3308 format = colNameBuf.substring(posFormatStart, posFormatEnd);
3309 //posFormatEnd = colNameBuf.indexOf(")",posFormatEnd);
3310 colNameBuf.insert(posFormatEnd+1, " ," + format + ") , "+ format + ")");
3311 logger.debug(EELFLoggerDelegate.debugLogger, ("colNameBuf " + colNameBuf.toString()));
3314 logger.debug(EELFLoggerDelegate.debugLogger, (" return colName " + colNameBuf.toString()));
3315 return colNameBuf.toString();
3318 public List getChartValueColumnsList( int filter, HashMap formValues) { /*filter; all=0;create without new chart =1; createNewChart=2 */
3319 List reportCols = reportRuntime.getAllColumns();
3321 ArrayList chartValueCols = new ArrayList();
3323 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
3325 DataColumnType dc = (DataColumnType) iter.next();
3326 // if(filter == 2 || filter == 1) {
3327 flag = reportRuntime.getDependsOnFormFieldFlag(dc, formValues);
3329 if( (dc.getChartSeq()!=null && dc.getChartSeq()> 0) && flag == 0 && !(nvl(dc.getColOnChart()).equals(AppConstants.GC_LEGEND))) {
3330 if(nvl(dc.getChartGroup()).length()<=0) {
3331 if( filter == 2 && (dc.isCreateInNewChart()!=null && dc.isCreateInNewChart().booleanValue())) {
3332 chartValueCols.add(dc);
3333 } else if (filter == 1 && (dc.isCreateInNewChart()==null || !dc.isCreateInNewChart().booleanValue())) {
3334 chartValueCols.add(dc);
3336 else if(filter == 0)
3337 chartValueCols.add(dc);
3338 } else chartValueCols.add(dc);
3341 // chartValueCols.add(dc);
3343 Collections.sort(chartValueCols, new ChartSeqComparator());
3344 return chartValueCols;
3345 } // getChartValueColumnsList
3347 public String parseTitle(String title, HashMap formValues) {
3348 Set set = formValues.entrySet();
3349 for(Iterator iter = set.iterator(); iter.hasNext(); ) {
3350 Map.Entry entry = (Entry<String,String>) iter.next();
3351 if(title.indexOf("["+ entry.getKey() + "]")!= -1) {
3352 title = Utils.replaceInString(title, "["+entry.getKey()+"]", nvl(
3353 (String) entry.getValue(), ""));
3359 public java.util.Date timezoneConversion(SimpleDateFormat sdf, String dateStr) {
3360 // sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
3361 return sdf.parse(dateStr, new ParsePosition(0));
3364 public java.util.Date getDateFromDateStr(String dateStr) {
3365 SimpleDateFormat MMDDYYYYFormat = new SimpleDateFormat("MM/dd/yyyy");
3366 SimpleDateFormat EEEMMDDYYYYFormat = new SimpleDateFormat("EEE, MM/dd/yyyy"); //2012-11-01 00:00:00
3367 SimpleDateFormat YYYYMMDDFormat = new SimpleDateFormat("yyyy/MM/dd");
3368 SimpleDateFormat MONYYYYFormat = new SimpleDateFormat("MMM yyyy");
3369 SimpleDateFormat MMYYYYFormat = new SimpleDateFormat("MM/yyyy");
3370 SimpleDateFormat MMMMMDDYYYYFormat = new SimpleDateFormat("MMMMM dd, yyyy");
3371 SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
3372 SimpleDateFormat timestampHrFormat = new SimpleDateFormat("yyyy-MM-dd HH");
3373 SimpleDateFormat timestampDayFormat = new SimpleDateFormat("yyyy-MM-dd");
3374 SimpleDateFormat DDMONYYYYFormat = new SimpleDateFormat("dd-MMM-yyyy");
3375 SimpleDateFormat MONTHYYYYFormat = new SimpleDateFormat("MMMMM, yyyy");
3376 SimpleDateFormat MMDDYYYYHHFormat = new SimpleDateFormat("MM/dd/yyyy HH");
3377 SimpleDateFormat MMDDYYYYHHMMSSFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
3378 SimpleDateFormat MMDDYYYYHHMMFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm");
3379 SimpleDateFormat YYYYMMDDHHMMSSFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
3380 SimpleDateFormat YYYYMMDDHHMMFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm");
3381 SimpleDateFormat DDMONYYYYHHMMSSFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
3382 SimpleDateFormat DDMONYYYYHHMMFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm");
3383 SimpleDateFormat MMDDYYFormat = new SimpleDateFormat("MM/dd/yy");
3384 SimpleDateFormat MMDDYYHHMMFormat = new SimpleDateFormat("MM/dd/yy HH:mm");
3385 SimpleDateFormat MMDDYYHHMMSSFormat = new SimpleDateFormat("MM/dd/yy HH:mm:ss");
3386 SimpleDateFormat timestampFormat1 = new SimpleDateFormat("yyyy-M-d.HH.mm. s. S");
3387 SimpleDateFormat timestamp_W_dash = new SimpleDateFormat("yyyyMMddHHmmss");
3388 SimpleDateFormat MMDDYYYYHHMMZFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm z");
3389 SimpleDateFormat YYYYFormat = new SimpleDateFormat("yyyy");
3390 java.util.Date date = null;
3394 final int YEARFLAG = 1;
3395 final int MONTHFLAG = 2;
3396 final int DAYFLAG = 3;
3397 final int HOURFLAG = 4;
3398 final int MINFLAG = 5;
3399 final int SECFLAG = 6;
3400 final int MILLISECFLAG = 7;
3401 final int DAYOFTHEWEEKFLAG = 8;
3402 final int FLAGDATE = 9;
3409 int milliSecFlag = 7;
3410 int dayoftheweekFlag = 8;
3414 //date = MMDDYYYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
3415 date = timezoneConversion(MMDDYYYYHHMMSSFormat, dateStr);
3416 if(date!=null) formatFlag = SECFLAG;
3418 //date = EEEMMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
3419 date = timezoneConversion(EEEMMDDYYYYFormat, dateStr);
3420 if(date!=null) formatFlag = DAYOFTHEWEEKFLAG;
3423 //date = MMDDYYYYHHMMFormat.parse(dateStr, new ParsePosition(0));
3424 date = timezoneConversion(MMDDYYYYHHMMFormat, dateStr);
3425 if(date!=null) formatFlag = MINFLAG;
3428 //MMDDYYYYHHFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
3429 //date = MMDDYYYYHHFormat.parse(dateStr, new ParsePosition(0));
3430 date = timezoneConversion(MMDDYYYYHHFormat, dateStr);
3431 if(date!=null) formatFlag = HOURFLAG;
3434 //date = MMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
3435 date = timezoneConversion(MMDDYYYYFormat, dateStr);
3436 if(date!=null) formatFlag = DAYFLAG;
3439 //date = YYYYMMDDFormat.parse(dateStr, new ParsePosition(0));
3440 date = timezoneConversion(YYYYMMDDFormat, dateStr);
3441 if(date!=null) formatFlag = DAYFLAG;
3444 //date = timestampFormat.parse(dateStr, new ParsePosition(0));
3445 date = timezoneConversion(timestampFormat, dateStr);
3446 if(date!=null) formatFlag = SECFLAG;
3449 //date = timestampHrFormat.parse(dateStr, new ParsePosition(0));
3450 date = timezoneConversion(timestampHrFormat, dateStr);
3451 if(date!=null) formatFlag = HOURFLAG;
3454 //date = timestampDayFormat.parse(dateStr, new ParsePosition(0));
3455 date = timezoneConversion(timestampDayFormat, dateStr);
3456 if(date!=null) formatFlag = DAYFLAG;
3460 //date = MONYYYYFormat.parse(dateStr, new ParsePosition(0));
3461 date = timezoneConversion(MONYYYYFormat, dateStr);
3462 if(date!=null) formatFlag = MONTHFLAG;
3465 //date = MMYYYYFormat.parse(dateStr, new ParsePosition(0));
3466 date = timezoneConversion(MMYYYYFormat, dateStr);
3467 if(date!=null) formatFlag = MONTHFLAG;
3470 //date = MMMMMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
3471 date = timezoneConversion(MMMMMDDYYYYFormat, dateStr);
3472 if(date!=null) formatFlag = DAYFLAG;
3475 //date = MONTHYYYYFormat.parse(dateStr, new ParsePosition(0));
3476 date = timezoneConversion(MONTHYYYYFormat, dateStr);
3477 if(date!=null) formatFlag = MONTHFLAG;
3481 //date = YYYYMMDDHHMMSSFormat.parse(dateStr, new ParsePosition(0));
3482 date = timezoneConversion(YYYYMMDDHHMMSSFormat, dateStr);
3483 if(date!=null) formatFlag = SECFLAG;
3487 //date = YYYYMMDDHHMMFormat.parse(dateStr, new ParsePosition(0));
3488 date = timezoneConversion(YYYYMMDDHHMMFormat, dateStr);
3489 if(date!=null) formatFlag = MINFLAG;
3493 //date = DDMONYYYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
3494 date = timezoneConversion(DDMONYYYYHHMMSSFormat, dateStr);
3495 if(date!=null) formatFlag = SECFLAG;
3499 //date = DDMONYYYYHHMMFormat.parse(dateStr, new ParsePosition(0));
3500 date = timezoneConversion(DDMONYYYYHHMMFormat, dateStr);
3501 if(date!=null) formatFlag = MINFLAG;
3505 //date = DDMONYYYYFormat.parse(dateStr, new ParsePosition(0));
3506 date = timezoneConversion(DDMONYYYYFormat, dateStr);
3507 if(date!=null) formatFlag = DAYFLAG;
3511 //date = MMDDYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
3512 date = timezoneConversion(MMDDYYHHMMSSFormat, dateStr);
3513 if(date!=null) formatFlag = SECFLAG;
3517 //date = MMDDYYHHMMFormat.parse(dateStr, new ParsePosition(0));
3518 date = timezoneConversion(MMDDYYHHMMFormat, dateStr);
3519 if(date!=null) formatFlag = MINFLAG;
3523 //date = MMDDYYFormat.parse(dateStr, new ParsePosition(0));
3524 date = timezoneConversion(MMDDYYFormat, dateStr);
3525 if(date!=null) formatFlag = DAYFLAG;
3529 //date = timestampFormat1.parse(dateStr, new ParsePosition(0));
3530 date = timezoneConversion(timestampFormat1, dateStr);
3531 if(date!=null) formatFlag = SECFLAG;
3535 //date = MMDDYYYYHHMMZFormat.parse(dateStr, new ParsePosition(0));
3536 date = timezoneConversion(MMDDYYYYHHMMZFormat, dateStr);
3537 if(date!=null) formatFlag = MINFLAG;
3541 //date = YYYYFormat.parse(dateStr, new ParsePosition(0));
3542 date = timezoneConversion(YYYYFormat, dateStr);
3543 /* Some random numbers should not satisfy this year format. */
3544 if(dateStr.length()>4) date = null;
3545 if(date!=null) formatFlag = YEARFLAG;
3548 //date = timestamp_W_dash.parse(dateStr, new ParsePosition(0));
3549 date = timezoneConversion(timestamp_W_dash, dateStr);
3550 if(date!=null) formatFlag = SECFLAG;
3557 public int getFlagFromDateStr(String dateStr) {
3558 SimpleDateFormat MMDDYYYYFormat = new SimpleDateFormat("MM/dd/yyyy");
3559 SimpleDateFormat EEEMMDDYYYYFormat = new SimpleDateFormat("EEE, MM/dd/yyyy"); //2012-11-01 00:00:00
3560 SimpleDateFormat YYYYMMDDFormat = new SimpleDateFormat("yyyy/MM/dd");
3561 SimpleDateFormat MONYYYYFormat = new SimpleDateFormat("MMM yyyy");
3562 SimpleDateFormat MMYYYYFormat = new SimpleDateFormat("MM/yyyy");
3563 SimpleDateFormat MMMMMDDYYYYFormat = new SimpleDateFormat("MMMMM dd, yyyy");
3564 SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
3565 SimpleDateFormat timestampHrFormat = new SimpleDateFormat("yyyy-MM-dd HH");
3566 SimpleDateFormat timestampDayFormat = new SimpleDateFormat("yyyy-MM-dd");
3567 SimpleDateFormat DDMONYYYYFormat = new SimpleDateFormat("dd-MMM-yyyy");
3568 SimpleDateFormat MONTHYYYYFormat = new SimpleDateFormat("MMMMM, yyyy");
3569 SimpleDateFormat MMDDYYYYHHFormat = new SimpleDateFormat("MM/dd/yyyy HH");
3570 SimpleDateFormat MMDDYYYYHHMMSSFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
3571 SimpleDateFormat MMDDYYYYHHMMFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm");
3572 SimpleDateFormat YYYYMMDDHHMMSSFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
3573 SimpleDateFormat YYYYMMDDHHMMFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm");
3574 SimpleDateFormat DDMONYYYYHHMMSSFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
3575 SimpleDateFormat DDMONYYYYHHMMFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm");
3576 SimpleDateFormat MMDDYYFormat = new SimpleDateFormat("MM/dd/yy");
3577 SimpleDateFormat MMDDYYHHMMFormat = new SimpleDateFormat("MM/dd/yy HH:mm");
3578 SimpleDateFormat MMDDYYHHMMSSFormat = new SimpleDateFormat("MM/dd/yy HH:mm:ss");
3579 SimpleDateFormat timestampFormat1 = new SimpleDateFormat("yyyy-M-d.HH.mm. s. S");
3580 SimpleDateFormat timestamp_W_dash = new SimpleDateFormat("yyyyMMddHHmmss");
3581 SimpleDateFormat MMDDYYYYHHMMZFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm z");
3582 SimpleDateFormat YYYYFormat = new SimpleDateFormat("yyyy");
3583 java.util.Date date = null;
3587 final int YEARFLAG = 1;
3588 final int MONTHFLAG = 2;
3589 final int DAYFLAG = 3;
3590 final int HOURFLAG = 4;
3591 final int MINFLAG = 5;
3592 final int SECFLAG = 6;
3593 final int MILLISECFLAG = 7;
3594 final int DAYOFTHEWEEKFLAG = 8;
3595 final int FLAGDATE = 9;
3602 int milliSecFlag = 7;
3603 int dayoftheweekFlag = 8;
3607 date = MMDDYYYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
3609 formatFlag = SECFLAG;
3611 date = EEEMMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
3613 formatFlag = DAYOFTHEWEEKFLAG;
3616 date = MMDDYYYYHHMMFormat.parse(dateStr, new ParsePosition(0));
3618 formatFlag = MINFLAG;
3621 //MMDDYYYYHHFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
3622 date = MMDDYYYYHHFormat.parse(dateStr, new ParsePosition(0));
3624 formatFlag = HOURFLAG;
3627 date = MMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
3629 formatFlag = DAYFLAG;
3632 date = YYYYMMDDFormat.parse(dateStr, new ParsePosition(0));
3634 formatFlag = DAYFLAG;
3637 date = timestampFormat.parse(dateStr, new ParsePosition(0));
3639 formatFlag = SECFLAG;
3642 date = timestampHrFormat.parse(dateStr, new ParsePosition(0));
3644 formatFlag = HOURFLAG;
3647 date = timestampDayFormat.parse(dateStr, new ParsePosition(0));
3649 formatFlag = DAYFLAG;
3652 date = MONYYYYFormat.parse(dateStr, new ParsePosition(0));
3654 formatFlag = MONTHFLAG;
3657 date = MMYYYYFormat.parse(dateStr, new ParsePosition(0));
3659 formatFlag = MONTHFLAG;
3662 date = MMMMMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
3664 formatFlag = DAYFLAG;
3667 date = MONTHYYYYFormat.parse(dateStr, new ParsePosition(0));
3669 formatFlag = MONTHFLAG;
3673 date = YYYYMMDDHHMMSSFormat.parse(dateStr, new ParsePosition(0));
3675 formatFlag = SECFLAG;
3679 date = YYYYMMDDHHMMFormat.parse(dateStr, new ParsePosition(0));
3681 formatFlag = MINFLAG;
3685 date = DDMONYYYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
3687 formatFlag = SECFLAG;
3691 date = DDMONYYYYHHMMFormat.parse(dateStr, new ParsePosition(0));
3693 formatFlag = MINFLAG;
3697 date = DDMONYYYYFormat.parse(dateStr, new ParsePosition(0));
3699 formatFlag = DAYFLAG;
3703 date = MMDDYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
3705 formatFlag = SECFLAG;
3709 date = MMDDYYHHMMFormat.parse(dateStr, new ParsePosition(0));
3711 formatFlag = MINFLAG;
3715 date = MMDDYYFormat.parse(dateStr, new ParsePosition(0));
3717 formatFlag = DAYFLAG;
3721 date = timestampFormat1.parse(dateStr, new ParsePosition(0));
3723 formatFlag = SECFLAG;
3727 date = MMDDYYYYHHMMZFormat.parse(dateStr, new ParsePosition(0));
3729 formatFlag = MINFLAG;
3733 date = YYYYFormat.parse(dateStr, new ParsePosition(0));
3734 /* Some random numbers should not satisfy this year format. */
3735 if(dateStr.length()>4)
3738 formatFlag = YEARFLAG;
3741 date = timestamp_W_dash.parse(dateStr, new ParsePosition(0));
3743 formatFlag = SECFLAG;
3750 public static String[] reverse(String[] arr) {
3751 List<String> list = Arrays.asList(arr);
3752 Collections.reverse(list);
3753 return (String[])list.toArray();
3756 public int getNumberOfDecimalPlaces(double num) {
3758 String[] splitter = d.toString().split("\\.");
3759 splitter[0].length(); // Before Decimal Count
3760 splitter[1].length(); // After Decimal Count
3761 return splitter[1].length();
3764 public boolean getBooleanValue(String s) {
3765 return getBooleanValue(s,null);
3768 public boolean getBooleanValue(String s, Boolean defaultValue) {
3770 if(s.length()<=0 && defaultValue!=null)
3771 return defaultValue.booleanValue();
3772 else if(s.length()<=0)
3775 if(s.toUpperCase().startsWith("Y") || s.toLowerCase().equals("true"))
3783 public String IntToLetter(int Int) {
3785 return Character.toString((char)(Int+96));
3788 return IntToLetter((Int/26)-1)+IntToLetter((Int%26)+1);
3790 return IntToLetter(Int/26)+IntToLetter(Int%26);
3798 private void clearReportRuntimeBackup(HttpServletRequest request) {
3799 //Session sess = Sessions.getCurrent(true)getCurrent();
3800 //HttpSession session = (HttpSession)sess.getNativeSession();
3801 HttpSession session = request.getSession();
3802 session.removeAttribute(AppConstants.DRILLDOWN_REPORTS_LIST);
3803 request.removeAttribute(AppConstants.DRILLDOWN_INDEX);
3804 session.removeAttribute(AppConstants.DRILLDOWN_INDEX);
3805 request.removeAttribute(AppConstants.FORM_DRILLDOWN_INDEX);
3806 session.removeAttribute(AppConstants.FORM_DRILLDOWN_INDEX);
3807 Enumeration<String> enum1 = session.getAttributeNames();
3808 String attributeName = "";
3809 while(enum1.hasMoreElements()) {
3810 attributeName = enum1.nextElement();
3811 if(attributeName.startsWith("parent_")) {
3812 session.removeAttribute(attributeName);
3815 session.removeAttribute(AppConstants.DRILLDOWN_REPORTS_LIST);
3816 session.removeAttribute(AppConstants.SI_BACKUP_FOR_REP_ID);
3817 session.removeAttribute(AppConstants.SI_COLUMN_LOOKUP);
3818 session.removeAttribute(AppConstants.SI_DASHBOARD_REP_ID);
3819 session.removeAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP);
3820 session.removeAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME);
3821 session.removeAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP);
3822 session.removeAttribute(AppConstants.SI_DASHBOARD_CHARTDATA_MAP);
3823 session.removeAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP);
3824 session.removeAttribute(AppConstants.SI_DATA_SIZE_FOR_TEXTFIELD_POPUP);
3825 session.removeAttribute(AppConstants.SI_MAP);
3826 session.removeAttribute(AppConstants.SI_MAP_OBJECT);
3827 session.removeAttribute(AppConstants.SI_REPORT_DEFINITION);
3828 session.removeAttribute(AppConstants.SI_REPORT_RUNTIME);
3829 session.removeAttribute(AppConstants.SI_REPORT_RUN_BACKUP);
3830 session.removeAttribute(AppConstants.SI_REPORT_SCHEDULE);
3831 session.removeAttribute(AppConstants.RI_REPORT_DATA);
3832 session.removeAttribute(AppConstants.RI_CHART_DATA);
3833 session.removeAttribute(AppConstants.SI_FORMFIELD_INFO);
3834 session.removeAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO);
3836 } // clearReportRuntimeBackup
3839 public static synchronized java.util.HashMap getRequestParametersMap(ReportRuntime rr, HttpServletRequest request)
3841 HashMap valuesMap = new HashMap();
3843 ReportFormFields rff = rr.getReportFormFields();
3846 FormField ff = null;
3848 Map fieldNameMap = new HashMap();
3849 int countOfFields = 0 ;
3852 for(rff.resetNext(); rff.hasNext(); idx++) {
3854 fieldNameMap.put(ff.getFieldName(), ff.getFieldDisplayName());
3858 List formParameter = new ArrayList();
3859 String formField = "";
3860 for(int i = 0 ; i < rff.size(); i++) {
3861 ff = ((FormField)rff.getFormField(i));
3862 formField = ff.getFieldName();
3863 boolean isMultiValue = false;
3864 isMultiValue = ff.getFieldType().equals(FormField.FFT_CHECK_BOX)
3865 || ff.getFieldType().equals(FormField.FFT_LIST_MULTI);
3866 boolean isTextArea = (ff.getFieldType().equals(FormField.FFT_TEXTAREA) && rr.getReportDefType()
3867 .equals(AppConstants.RD_SQL_BASED));
3869 if(request.getParameterValues(formField) != null && isMultiValue ) {
3870 String[] vals = request.getParameterValues(formField);
3871 StringBuilder value = new StringBuilder("");
3872 if(!AppUtils.getRequestFlag(request, AppConstants.RI_RESET_ACTION)) {
3874 if ( isMultiValue ) {
3877 for(int j = 0 ; j < vals.length; j++) {
3881 if(vals[j] !=null && vals[j].length() > 0) {
3882 vals[j] = Utils.oracleSafe(vals[j]);
3883 value.append(java.net.URLDecoder.decode(vals[j], "UTF-8"));// + ",";
3886 value.append(vals[j]);
3887 } catch (UnsupportedEncodingException ex) {value.append(vals[j]);}
3888 catch (IllegalArgumentException ex1){value.append(vals[j]);}
3889 catch (Exception ex2){
3890 value.append(vals[j]);
3897 if(j != vals.length -1) {
3901 if(vals.length > 0) {
3906 //value = value.substring(0 , value.length());
3908 valuesMap.put(fieldNameMap.get(formField), value.toString());
3909 } else if(request.getParameter(formField) != null) {
3912 value = request.getParameter(formField);
3914 value = Utils.oracleSafe(value);
3915 value = "('" + Utils.replaceInString(value, ",", "'|'") + "')";
3916 value = Utils.replaceInString(value, "|", ",");
3917 valuesMap.put(fieldNameMap.get(formField), value);
3921 if(!AppUtils.getRequestFlag(request, AppConstants.RI_RESET_ACTION))
3922 value = request.getParameter(formField);
3923 valuesMap.put(fieldNameMap.get(formField), Utils.oracleSafe(value));
3927 valuesMap.put(fieldNameMap.get(formField), "" );
3936 public static int getCurrentTimezoneOffset() {
3938 TimeZone tz = TimeZone.getDefault();
3939 java.util.Calendar cal = GregorianCalendar.getInstance(tz);
3940 int offsetInMillis = tz.getOffset(cal.getTimeInMillis());
3941 int hourOffset = Math.abs(offsetInMillis / 3600000) * 60;
3942 boolean isDST = tz.inDaylightTime(new java.util.Date());
3946 int offset = hourOffset + Math.abs((offsetInMillis / 60000) % 60);
3947 if (offsetInMillis > 0)
3950 return Globals.getTimezoneOffset();