2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 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============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
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.HashMap;
51 import java.util.Iterator;
52 import java.util.List;
54 import java.util.Map.Entry;
56 import java.util.SortedSet;
57 import java.util.TreeSet;
58 import java.util.regex.Matcher;
59 import java.util.regex.Pattern;
61 import javax.servlet.http.HttpServletRequest;
62 import javax.servlet.http.HttpSession;
64 import org.apache.commons.lang.time.DateUtils;
65 import org.onap.portalsdk.analytics.error.RaptorException;
66 import org.onap.portalsdk.analytics.model.ReportHandler;
67 import org.onap.portalsdk.analytics.model.base.ChartSeqComparator;
68 import org.onap.portalsdk.analytics.system.AppUtils;
69 import org.onap.portalsdk.analytics.system.ConnectionUtils;
70 import org.onap.portalsdk.analytics.util.AppConstants;
71 import org.onap.portalsdk.analytics.util.DataSet;
72 import org.onap.portalsdk.analytics.util.HtmlStripper;
73 import org.onap.portalsdk.analytics.util.Utils;
74 import org.onap.portalsdk.analytics.view.ReportData;
75 import org.onap.portalsdk.analytics.xmlobj.DataColumnType;
76 import org.onap.portalsdk.analytics.xmlobj.FormFieldType;
77 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
78 import org.onap.portalsdk.core.web.support.UserUtils;
80 public class ChartD3Helper {
82 private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ChartD3Helper.class);
84 private ReportRuntime reportRuntime;
85 private String chartType;
87 public static final long HOUR = 3600*1000;
88 public static final long DAY = 3600*1000*24;
89 public static final long MONTH = 3600*1000*24*31;
90 public static final long YEAR = 3600*1000*24*365;
93 public ChartD3Helper() {
98 * @return the chartType
100 public String getChartType() {
105 * @param chartType the chartType to set
107 public void setChartType(String chartType) {
108 this.chartType = chartType;
111 public ChartD3Helper(ReportRuntime rr) {
112 this.reportRuntime = rr;
115 public String createVisualization(String reportID, HttpServletRequest request) throws RaptorException {
116 //From annotations chart
117 clearReportRuntimeBackup(request);
119 //HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()).getRequest();
120 final Long user_id = new Long((long) UserUtils.getUserId(request));
121 //String action = request.getParameter(AppConstants.RI_ACTION);
122 //String reportID = AppUtils.getRequestValue(request, AppConstants.RI_REPORT_ID);
124 ReportHandler rh = new ReportHandler();
125 ReportData reportData = null;
126 HashMap<String, String> chartOptionsMap = new HashMap<String, String>();
128 if(reportID !=null) {
129 reportRuntime = rh.loadReportRuntime(request, reportID, true, 1);
130 setChartType(reportRuntime.getChartType());
131 reportData = reportRuntime.loadReportData(0, user_id.toString(), 10000,request, false);
136 String rotateLabelsStr = "";
137 rotateLabelsStr = AppUtils.nvl(reportRuntime.getLegendLabelAngle());
138 if(rotateLabelsStr.toLowerCase().equals("standard")) {
139 rotateLabelsStr = "0";
140 } else if (rotateLabelsStr.toLowerCase().equals("up45")) {
141 rotateLabelsStr = "45";
142 } else if (rotateLabelsStr.toLowerCase().equals("down45")) {
143 rotateLabelsStr = "-45";
144 } else if (rotateLabelsStr.toLowerCase().equals("up90")) {
145 rotateLabelsStr = "90";
146 } else if (rotateLabelsStr.toLowerCase().equals("down90")) {
147 rotateLabelsStr = "-90";
149 rotateLabelsStr = "0";
151 String width = (AppUtils.getRequestNvlValue(request, "width").length()>0?AppUtils.getRequestNvlValue(request, "width"):(AppUtils.nvl(reportRuntime.getChartWidth()).length()>0?reportRuntime.getChartWidth():"700"));
152 String height = (AppUtils.getRequestNvlValue(request, "height").length()>0?AppUtils.getRequestNvlValue(request, "height"):(AppUtils.nvl(reportRuntime.getChartHeight()).length()>0?reportRuntime.getChartHeight():"300"));
153 String animationStr = (AppUtils.getRequestNvlValue(request, "animation").length()>0?AppUtils.getRequestNvlValue(request, "animation"):new Boolean(reportRuntime.isAnimateAnimatedChart()).toString());
155 String rotateLabels = (AppUtils.getRequestNvlValue(request, "rotateLabels").length()>0?AppUtils.getRequestNvlValue(request, "rotateLabels"):(rotateLabelsStr.length()>0?rotateLabelsStr:"0"));
156 String staggerLabelsStr = (AppUtils.getRequestNvlValue(request, "staggerLabels").length()>0?AppUtils.getRequestNvlValue(request, "staggerLabels"):"false");
157 String showMaxMinStr = (AppUtils.getRequestNvlValue(request, "showMaxMin").length()>0?AppUtils.getRequestNvlValue(request, "showMaxMin"):"false");
158 String showControlsStr = (AppUtils.getRequestNvlValue(request, "showControls").length()>0?AppUtils.getRequestNvlValue(request, "showControls"):new Boolean(reportRuntime.displayBarControls()).toString());
159 String showLegendStr = (AppUtils.getRequestNvlValue(request, "showLegend").length()>0?AppUtils.getRequestNvlValue(request, "showLegend"):new Boolean(!new Boolean(reportRuntime.hideChartLegend())).toString());
160 String topMarginStr = AppUtils.getRequestNvlValue(request, "topMargin");
161 String topMargin = (AppUtils.nvl(topMarginStr).length()<=0)?(reportRuntime.getTopMargin()!=null?reportRuntime.getTopMargin().toString():"30"):topMarginStr;
162 String bottomMarginStr = AppUtils.getRequestNvlValue(request, "bottomMargin");
163 String bottomMargin = (AppUtils.nvl(bottomMarginStr).length()<=0)?(reportRuntime.getBottomMargin()!=null?reportRuntime.getBottomMargin().toString():"50"):bottomMarginStr;
164 String leftMarginStr = AppUtils.getRequestNvlValue(request, "leftMargin");
165 String leftMargin = (AppUtils.nvl(leftMarginStr).length()<=0)?(reportRuntime.getLeftMargin()!=null?reportRuntime.getLeftMargin().toString():"100"):leftMarginStr;
166 String rightMarginStr = AppUtils.getRequestNvlValue(request, "rightMargin");
167 String rightMargin = (AppUtils.nvl(rightMarginStr).length()<=0)?(reportRuntime.getRightMargin()!=null?reportRuntime.getRightMargin().toString():"160"):rightMarginStr;
168 String showTitleStr = (AppUtils.getRequestNvlValue(request, "showTitle").length()>0?AppUtils.getRequestNvlValue(request, "showTitle"):new Boolean(reportRuntime.displayChartTitle()).toString());
169 String subType = AppUtils.getRequestNvlValue(request, "subType").length()>0?AppUtils.getRequestNvlValue(request, "subType"):(AppUtils.nvl(reportRuntime.getTimeSeriesRender()).equals("area")?reportRuntime.getTimeSeriesRender():"");
170 String stackedStr = AppUtils.getRequestNvlValue(request, "stacked").length()>0?AppUtils.getRequestNvlValue(request, "stacked"):new Boolean(reportRuntime.isChartStacked()).toString();
171 String horizontalBar = AppUtils.getRequestNvlValue(request, "horizontalBar").length()>0?AppUtils.getRequestNvlValue(request, "horizontalBar"):new Boolean(reportRuntime.isHorizontalOrientation()).toString();
172 String barRealTimeAxis = AppUtils.getRequestNvlValue(request, "barRealTimeAxis");
173 String barReduceXAxisLabels = AppUtils.getRequestNvlValue(request, "barReduceXAxisLabels").length()>0?AppUtils.getRequestNvlValue(request, "barReduceXAxisLabels"):new Boolean(reportRuntime.isLessXaxisTickers()).toString();;
174 String timeAxis = AppUtils.getRequestNvlValue(request, "timeAxis").length()>0?AppUtils.getRequestNvlValue(request, "timeAxis"):new Boolean(reportRuntime.isTimeAxis()).toString();
175 String logScale = AppUtils.getRequestNvlValue(request, "logScale").length()>0?AppUtils.getRequestNvlValue(request, "logScale"):new Boolean(reportRuntime.isLogScale()).toString();
176 String precision = AppUtils.getRequestNvlValue(request, "precision").length()>0?AppUtils.getRequestNvlValue(request, "precision"):"2";
179 chartOptionsMap.put("width", width);
180 chartOptionsMap.put("height", height);
181 chartOptionsMap.put("animation", animationStr);
182 chartOptionsMap.put("rotateLabels", rotateLabels);
183 chartOptionsMap.put("staggerLabels", staggerLabelsStr);
184 chartOptionsMap.put("showMaxMin", showMaxMinStr);
185 chartOptionsMap.put("showControls", showControlsStr);
186 chartOptionsMap.put("showLegend", showLegendStr);
187 chartOptionsMap.put("topMargin", topMargin);
188 chartOptionsMap.put("bottomMargin", bottomMargin);
189 chartOptionsMap.put("leftMargin", leftMargin);
190 chartOptionsMap.put("rightMargin", rightMargin);
191 chartOptionsMap.put("showTitle", showTitleStr);
192 chartOptionsMap.put("subType", subType);
193 chartOptionsMap.put("stacked", stackedStr);
194 chartOptionsMap.put("horizontalBar", horizontalBar);
195 chartOptionsMap.put("timeAxis", timeAxis);
196 chartOptionsMap.put("barRealTimeAxis", barRealTimeAxis);
197 chartOptionsMap.put("barReduceXAxisLabels", barReduceXAxisLabels);
199 chartOptionsMap.put("logScale", logScale);
200 chartOptionsMap.put("precision", precision);
203 } catch (RaptorException ex) {
204 ex.printStackTrace();
206 return createVisualization(reportRuntime, chartOptionsMap, request);
209 public String createVisualization(ReportRuntime reportRuntime, HttpServletRequest request) throws RaptorException {
211 String rotateLabelsStr = "";
212 rotateLabelsStr = AppUtils.nvl(reportRuntime.getLegendLabelAngle());
213 if(rotateLabelsStr.toLowerCase().equals("standard")) {
214 rotateLabelsStr = "0";
215 } else if (rotateLabelsStr.toLowerCase().equals("up45")) {
216 rotateLabelsStr = "45";
217 } else if (rotateLabelsStr.toLowerCase().equals("down45")) {
218 rotateLabelsStr = "-45";
219 } else if (rotateLabelsStr.toLowerCase().equals("up90")) {
220 rotateLabelsStr = "90";
221 } else if (rotateLabelsStr.toLowerCase().equals("down90")) {
222 rotateLabelsStr = "-90";
224 rotateLabelsStr = "0";
226 HashMap<String,String> chartOptionsMap = new HashMap<String, String>();
227 chartOptionsMap.put("width", reportRuntime.getChartWidth());
228 chartOptionsMap.put("height", reportRuntime.getChartHeight());
229 chartOptionsMap.put("animation", new Boolean(reportRuntime.isAnimateAnimatedChart()).toString());
230 chartOptionsMap.put("rotateLabels", rotateLabelsStr);
231 chartOptionsMap.put("staggerLabels", "false");
232 chartOptionsMap.put("showMaxMin", "false");
233 chartOptionsMap.put("showControls", new Boolean(reportRuntime.displayBarControls()).toString());
234 chartOptionsMap.put("showLegend", new Boolean(!reportRuntime.hideChartLegend()).toString());
235 chartOptionsMap.put("topMargin", reportRuntime.getTopMargin()!=null?reportRuntime.getTopMargin().toString():"30");
236 chartOptionsMap.put("bottomMargin", reportRuntime.getBottomMargin()!=null?reportRuntime.getBottomMargin().toString():"50");
237 chartOptionsMap.put("leftMargin", reportRuntime.getLeftMargin()!=null?reportRuntime.getLeftMargin().toString():"100");
238 chartOptionsMap.put("rightMargin", reportRuntime.getRightMargin()!=null?reportRuntime.getRightMargin().toString():"160");
239 chartOptionsMap.put("showTitle", new Boolean(reportRuntime.displayChartTitle()).toString());
240 chartOptionsMap.put("subType", (AppUtils.nvl(reportRuntime.getTimeSeriesRender()).equals("area")?reportRuntime.getTimeSeriesRender():""));
241 chartOptionsMap.put("stacked", new Boolean(reportRuntime.isChartStacked()).toString());
242 chartOptionsMap.put("horizontalBar", new Boolean(reportRuntime.isHorizontalOrientation()).toString());
243 chartOptionsMap.put("timeAxis", new Boolean(reportRuntime.isTimeAxis()).toString());
244 chartOptionsMap.put("barReduceXAxisLabels", new Boolean(reportRuntime.isLessXaxisTickers()).toString());
246 chartOptionsMap.put("logScale", new Boolean(reportRuntime.isLogScale()).toString());
247 chartOptionsMap.put("precision", "2");
251 return createVisualization(reportRuntime, chartOptionsMap, request);
254 public String createVisualization(ReportRuntime reportRuntime, HashMap<String,String> chartOptionsMap, HttpServletRequest request) throws RaptorException {
256 //String width, String height, boolean animation, String rotateLabels, boolean staggerLabels, boolean showMaxMin, boolean showLegend, boolean showControls, String topMargin, String bottomMargin, boolean showTitle, String subType
258 boolean isEmbedded = false;
259 if(request.getParameter("embedded")!=null) {
262 String width = chartOptionsMap.get("width");
263 String height = chartOptionsMap.get("height");
264 boolean animation = getBooleanValue(chartOptionsMap.get("animation"), true);
265 String rotateLabels = chartOptionsMap.get("rotateLabels");
266 boolean staggerLabels = getBooleanValue(chartOptionsMap.get("staggerLabels"));
267 boolean showMaxMin = getBooleanValue(chartOptionsMap.get("showMaxMin"), false);
268 boolean showLegend = getBooleanValue(chartOptionsMap.get("showLegend"), true);
269 boolean showControls = getBooleanValue(chartOptionsMap.get("showControls"), true);
270 String topMargin = chartOptionsMap.get("topMargin");
271 String bottomMargin = chartOptionsMap.get("bottomMargin");
272 String leftMargin = chartOptionsMap.get("leftMargin");
273 String rightMargin = chartOptionsMap.get("rightMargin");
274 boolean showTitle = getBooleanValue(chartOptionsMap.get("showTitle"), true);
275 String subType = chartOptionsMap.get("subType");
276 boolean stacked = getBooleanValue(chartOptionsMap.get("stacked"), false);
277 boolean horizontalBar = getBooleanValue(chartOptionsMap.get("horizontalBar"), false);
278 boolean barRealTimeAxis = getBooleanValue(chartOptionsMap.get("barRealTimeAxis"), true);
279 boolean barReduceXAxisLabels= getBooleanValue(chartOptionsMap.get("barReduceXAxisLabels"), false);
280 boolean timeAxis = getBooleanValue(chartOptionsMap.get("timeAxis"), true);
283 boolean logScale = getBooleanValue(chartOptionsMap.get("logScale"), false);
288 precision = Integer.parseInt(chartOptionsMap.get("precision"));
289 } catch (NumberFormatException ex) {
293 final Long user_id = new Long((long) UserUtils.getUserId(request));
295 HttpSession session = null;
296 session = request.getSession();
297 String chartType = reportRuntime.getChartType();
298 List l = reportRuntime.getAllColumns();
299 List lGroups = reportRuntime.getAllChartGroups();
300 HashMap mapYAxis = reportRuntime.getAllChartYAxis(reportRuntime.getReportParamValues());
301 //ReportParamValues reportParamValues = reportRuntime.getReportParamValues();
302 String chartLeftAxisLabel = reportRuntime.getFormFieldFilled(nvl(reportRuntime.getChartLeftAxisLabel()));
303 String chartRightAxisLabel = reportRuntime.getFormFieldFilled(nvl(reportRuntime.getChartRightAxisLabel()));
305 boolean multipleSeries = reportRuntime.isMultiSeries();
307 java.util.HashMap formValues = null;
308 formValues = getRequestParametersMap(reportRuntime, request);
311 String legendColumnName = (reportRuntime.getChartLegendColumn()!=null)?reportRuntime.getChartLegendColumn().getDisplayName():"Legend Column";
312 boolean displayChart = (nvl(chartType).length()>0)&&reportRuntime.getDisplayChart();
313 HashMap additionalChartOptionsMap = new HashMap();
315 StringBuffer wholeScript = new StringBuffer("");
317 String title = reportRuntime.getReportTitle();
319 title = parseTitle(title, formValues);
321 String chartScriptsPath = (isEmbedded?AppUtils.getChartScriptsPath(""):AppUtils.getChartScriptsPath());
326 if (!(chartType.equals(AppConstants.GT_HIERARCHICAL) || chartType.equals(AppConstants.GT_HIERARCHICAL_SUNBURST) || chartType.equals(AppConstants.GT_ANNOTATION_CHART))) {
327 ds = (DataSet) loadChartData(new Long(user_id).toString(), request);
328 } else if(chartType.equals(AppConstants.GT_ANNOTATION_CHART)) {
329 String reportSQL = reportRuntime.getWholeSQL();
330 String dbInfo = reportRuntime.getDBInfo();
331 ds = ConnectionUtils.getDataSet(reportSQL, dbInfo);
332 if(ds.getRowCount()<=0) {
333 logger.debug(EELFLoggerDelegate.debugLogger, ("********************************************************************************"));
334 logger.debug(EELFLoggerDelegate.debugLogger, (chartType.toUpperCase()+" - " + "Report ID : " + reportRuntime.getReportID() + " DATA IS EMPTY"));
335 logger.debug(EELFLoggerDelegate.debugLogger, ("QUERY - " + reportSQL));
336 logger.debug(EELFLoggerDelegate.debugLogger, ("********************************************************************************"));
338 } else if(chartType.equals(AppConstants.GT_HIERARCHICAL)||chartType.equals(AppConstants.GT_HIERARCHICAL_SUNBURST)) {
339 String reportSQL = reportRuntime.getWholeSQL();
340 String dbInfo = reportRuntime.getDBInfo();
341 ds = ConnectionUtils.getDataSet(reportSQL, dbInfo);
343 } catch (RaptorException ex) {
344 //throw new RaptorException("Error while loading chart data", ex);
345 logger.error(EELFLoggerDelegate.debugLogger, ("********************************************************************************"));
346 logger.error(EELFLoggerDelegate.debugLogger, (chartType.toUpperCase()+" - " + "Report ID : " + reportRuntime.getReportID() + " ERROR THROWN FOR GIVEN QUERY "));
347 logger.error(EELFLoggerDelegate.debugLogger, ("QUERY - " + reportRuntime.getWholeSQL()));
348 logger.error(EELFLoggerDelegate.debugLogger, ("ERROR STACK TRACE" + ex.getMessage()));
349 logger.error(EELFLoggerDelegate.debugLogger, ("********************************************************************************"));
353 //displayChart = false;
354 if(chartType.equals(AppConstants.GT_ANNOTATION_CHART))
357 displayChart = false;
361 if (chartType.equals(AppConstants.GT_BAR_3D)) {
363 // get category if not give the column name for the data column use this to develop series.
364 boolean hasCategoryAxis = reportRuntime.hasSeriesColumn();
366 boolean hasCustomizedChartColor = false;
368 flag = hasCategoryAxis?1:0;
369 Object uniqueElements [] = null;
370 ArrayList uniqueElementsList = new ArrayList();
371 Object uniqueXAxisElements[] = null;
372 ArrayList ts = new ArrayList();
373 //Set<String> ts1 = new HashSet();
374 ArrayList<String> ts1 = new ArrayList();
375 HashMap<String, String> columnMap = new HashMap();
376 String uniqueXAxisStr = "";
378 for (int i = 0; i < ds.getRowCount(); i++) {
379 uniqueXAxisStr = ds.getString(i, 0);
380 ts1.add(uniqueXAxisStr);
383 uniqueElementsList.addAll(ts1);
384 uniqueXAxisElements = ts1.toArray();
387 StringBuffer catStr = new StringBuffer("");
389 for (int i = 0; i < ds.getRowCount(); i++) {
390 catStr = new StringBuffer("");
391 catStr.append(ds.getString(i, 2));
393 if(ds.getString(i, "chart_color")!=null) {
394 color = ds.getString(i, "chart_color");
395 hasCustomizedChartColor = true;
396 catStr.append("|"+color);
398 } catch (ArrayIndexOutOfBoundsException ex) {
399 //System.out.println("No Chart Color");
402 if(catStr.length()>0) {
403 //duplicates are avoided
404 if(!ts.contains(catStr.toString()))
405 ts.add(catStr.toString());
408 /* Get Chart LeftAxis Label even from Range Axis definition. */
409 DataColumnType dct = null;
410 for (Iterator iter = l.iterator(); iter.hasNext();) {
411 dct = (DataColumnType) iter.next();
412 if(!(nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND))) {
413 if(nvl(chartLeftAxisLabel).length()<=0) {
414 chartLeftAxisLabel = nvl(dct.getYAxis());
415 chartLeftAxisLabel = (chartLeftAxisLabel.indexOf("|")!=-1)?chartLeftAxisLabel.substring(0,chartLeftAxisLabel.indexOf("|")):"";
421 //Object uniqueElements [] = ts.toArray();
422 //SortedSet s = Collections.synchronizedSortedSet(ts);
423 uniqueElements = ts.toArray();
425 DataColumnType dct = null;
426 List yTextSeries = reportRuntime.getChartDisplayNamesList(AppConstants.CHART_ALL_COLUMNS, formValues);
427 //if(columnValuesList.size() == 1) {
428 for (Iterator iter = l.iterator(); iter.hasNext();) {
429 dct = (DataColumnType) iter.next();
431 if(!(nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND))) {
432 if((dct.isChartSeries()!=null && dct.isChartSeries().booleanValue()) || (dct.getChartSeq()!=null && dct.getChartSeq()>0) ) {
434 if(nvl(dct.getChartColor()).length()>0) hasCustomizedChartColor = true;
435 if(hasCustomizedChartColor) {
436 //duplicates are avoided
437 if(!ts.contains(dct.getDisplayName()+"|"+nvl(dct.getChartColor())))
438 ts.add(dct.getDisplayName()+"|"+nvl(dct.getChartColor()));
440 //duplicates are avoided
441 if(!ts.contains(dct.getDisplayName()))
442 ts.add(dct.getDisplayName());
444 if(nvl(chartLeftAxisLabel).length()<=0) {
445 chartLeftAxisLabel = nvl(dct.getYAxis());
446 chartLeftAxisLabel = (chartLeftAxisLabel.indexOf("|")!=-1)?chartLeftAxisLabel.substring(0,chartLeftAxisLabel.indexOf("|")):"";
448 columnMap.put(dct.getDisplayName(), dct.getColId());
450 ts.add(dct.getDisplayName());
451 if(nvl(chartLeftAxisLabel).length()<=0) {
452 chartLeftAxisLabel = nvl(dct.getYAxis());
453 chartLeftAxisLabel = (chartLeftAxisLabel.indexOf("|")!=-1)?chartLeftAxisLabel.substring(0,chartLeftAxisLabel.indexOf("|")):"";
455 columnMap.put(dct.getDisplayName(), dct.getColId());
461 //SortedSet s = Collections.synchronizedSortedSet(ts);
462 uniqueElements = ts.toArray();
466 wholeScript.append("<!DOCTYPE html>\n");
467 wholeScript.append("<html>\n");
468 wholeScript.append("<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF8\">\n");
469 wholeScript.append("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n");
470 wholeScript.append("<link href=\""+ chartScriptsPath +"d3/css/nv.d3.css\" rel=\"stylesheet\" type=\"text/css\">\n");
471 //wholeScript.append("")
472 wholeScript.append("<style>\n " +
474 " overflow-y:scroll; \n" +
477 " font: 12px sans-serif; \n" +
480 " display: block;\n" +
482 " #chart"+reportRuntime.getReportID()+" svg { \n" +
483 " height: "+ (nvl(height).length()>0?(height.endsWith("px")?height:height+"px"):"420px") + "; \n" +
484 " width: "+ (nvl(width).length()>0?(width.endsWith("px")?width:width+"px"):"700px") + "; \n" +
485 " min-width: 100px; \n" +
486 " min-height: 100px; \n" +
488 " tr.z-row-over > td.z-row-inner, tr.z-row-over > .z-cell {" +
489 " background-color: rgb(255, 255, 255); "+
492 wholeScript.append(".nodatadiv {\n");
493 wholeScript.append(" display: table-cell;\n");
494 wholeScript.append(" width: 700px;\n");
495 wholeScript.append(" height:370px;\n");
496 wholeScript.append(" text-align:center;\n");
497 wholeScript.append(" vertical-align: middle;\n");
498 wholeScript.append("}\n");
499 wholeScript.append(".nodatainner {\n");
500 wholeScript.append(" padding: 10px;\n");
501 wholeScript.append("}\n");
503 wholeScript.append(" </style> \n" );
504 wholeScript.append("<body> \n");
506 wholeScript.append("<div align=\"center\"><H3>" + title +"</H3></div>");
508 wholeScript.append("<div id=\"chart"+reportRuntime.getReportID()+"\"> <svg></svg> </div> \n");
510 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/d3.v3.min.js\"></script>");
511 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/nv.d3.min.js\"></script> \n");
512 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/tooltip.js\"></script> \n");
513 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/utils.js\"></script> \n");
514 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/models/axis.min.js\"></script> \n");
515 //wholeScript.append("<script src=\""+ AppUtils.getBaseFolderURL() +"d3/js/models/discreteBar.js\"></script> \n");
516 //wholeScript.append("<script src=\""+ AppUtils.getBaseFolderURL() +"d3/js/models/discreteBarChart.js\"></script> \n");
517 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/models/multiChart.js\"></script> \n");
519 wholeScript.append("<script> \n");
520 wholeScript.append("historicalBarChart = [ \n");
521 //wholeScript.append("{ \n");
523 ArrayList dataSeries = new ArrayList();
525 String uniqueElement = "";
526 for (int i = 0; i < uniqueElements.length; i++) {
527 uniqueElement = (String)uniqueElements[i];
528 if(multipleSeries && (nvl(chartRightAxisLabel).length() > 0))
529 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\": ["));
531 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\": ["));
534 // added to load all date elements
535 HashMap<String, HashMap<String, String>> dataSeriesMap = new HashMap<String, HashMap<String, String>>();
537 for (int i = 0; i < uniqueElements.length; i++) {
538 if(multipleSeries && (nvl(chartRightAxisLabel).length() > 0))
539 dataSeriesMap.put((String) uniqueElements[i], new HashMap<String, String>());
540 //dataSeries.add(new StringBuffer(" { \"type\":\"bar\", \"key\": \""+ uniqueElements[i] +"\", \"yAxis\": \""+(i+1)+"\", \"values\": ["));
542 dataSeriesMap.put((String) uniqueElements[i], new HashMap<String, String>());
544 //dataSeries.add(new StringBuffer(" { \"type\":\"bar\", \"key\": \""+ uniqueElements[i] +"\", \"yAxis\": \""+(1)+"\", \"values\": ["));
547 String dateStr = null;
548 java.util.Date date = null;
550 final int YEARFLAG = 1;
551 final int MONTHFLAG = 2;
552 final int DAYFLAG = 3;
553 final int HOURFLAG = 4;
554 final int MINFLAG = 5;
555 final int SECFLAG = 6;
556 final int MILLISECFLAG = 7;
557 final int DAYOFTHEWEEKFLAG = 8;
558 final int FLAGDATE = 9;
566 double YAXISDOUBLENUM = 0.0;
567 double MAXDOUBLENUM = 0.0;
568 int MAXNUMDECIMALPLACES = 0;
572 TreeSet<String> dateStrList = new TreeSet<String>();
573 // added to store all date elements
574 SortedSet<String> sortSet = new TreeSet<String>();
577 HashMap dataSeriesStrMap = new HashMap();
578 HashMap dataSeriesOverAllMap = new HashMap();
579 String valueDataSeries = "";
581 for (int j = 0; j < uniqueElements.length; j++) {
582 dataSeriesStrMap = new HashMap();
583 for (int i = 0; i < ds.getRowCount(); i++) {
586 YAXISDOUBLENUM = 0.0;
588 dateStr = ds.getString(i, 1);
590 date = getDateFromDateStr(dateStr);
591 formatFlag = getFlagFromDateStr(dateStr);
593 uniqueElement = (String)uniqueElements[j];
598 //if(!((String)uniqueElementsList.get(i)).equals(dateStr)) {
599 for (int f=0 ; f< uniqueXAxisElements.length; f++) {
600 if(uniqueXAxisElements[f].equals(dateStr)){
605 /*for(int f=0; f<uniqueElementsList.size() && f < pos; f++)
607 StringBuffer strBuf = ((StringBuffer)dataSeries.get(j));
608 if(strBuf.indexOf((String)uniqueElementsList.get(f)) < 0 ) {
609 dataSeriesStrMap.put((String)uniqueElementsList.get(f), value);
610 //((StringBuffer) dataSeries.get(j)).append ("{ \"x\":\"" + (String)uniqueElementsList.get(f) + "\" , \"y\": null },");
615 dateStrList.add("'"+dateStr+"'");
616 //uniqueElement = (String)uniqueElements[j];
618 YAXISNUM = Integer.parseInt(ds.getString(i, columnMap.get((hasCustomizedChartColor?(uniqueElement.indexOf("|")!=-1?uniqueElement.substring(0, uniqueElement.indexOf("|")):uniqueElement):uniqueElement))));
619 //if(MAXNUM < YAXISNUM) MAXNUM = YAXISNUM;
620 if(MAXDOUBLENUM < YAXISNUM) MAXDOUBLENUM = YAXISNUM;
621 } catch (NumberFormatException ex) {
623 YAXISDOUBLENUM = Double.parseDouble(ds.getString(i, columnMap.get((hasCustomizedChartColor?(uniqueElement.indexOf("|")!=-1?uniqueElement.substring(0, uniqueElement.indexOf("|")):uniqueElement):uniqueElement))));
624 MAXNUMDECIMALPLACES = getNumberOfDecimalPlaces(YAXISDOUBLENUM);
625 if(MAXDOUBLENUM < YAXISDOUBLENUM) MAXDOUBLENUM = YAXISDOUBLENUM;
626 } catch (NumberFormatException ex1) {
631 /* For Non-date type value enclose with double quotes */
632 // ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":\"" + dateStr + "\" , \"y\":" + (flagNull==0?(YAXISDOUBLENUM>0?YAXISDOUBLENUM:YAXISNUM):null) +"}, ");
634 // ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":\"" + dateStr + "\" , \"y\":" + (flagNull==0?(YAXISDOUBLENUM>0?new Double(Math.log10(YAXISDOUBLENUM)).toString():(YAXISNUM>0?new Double(Math.log10(new Integer(YAXISNUM).doubleValue())).toString():null)):null) +"}, ");
635 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) +"}, ";
636 dataSeriesStrMap.put(dateStr, valueDataSeries);
638 //((StringBuffer) dataSeries.get(j)).append ("{ \"x\":\"" + dateStr + "\" , \"y\":" + (flagNull==0?(YAXISDOUBLENUM>0?YAXISDOUBLENUM:YAXISNUM):null) +"}, ");
639 valueDataSeries = "{ \"x\":\"" + dateStr + "\" , \"y\":" + (flagNull == 0 ? (YAXISDOUBLENUM>0?YAXISDOUBLENUM:YAXISNUM): null) +"}, ";
640 dataSeriesStrMap.put(dateStr, valueDataSeries);
644 dataSeriesOverAllMap.put(uniqueElements[j], dataSeriesStrMap);
646 //((StringBuffer) dataSeries.get(j)).append ("{ \"x\":\"" + dateStr + "\" , \"y\":\"" + ds.getString(i, columnMap.get((String)uniqueElements[j])) +"\"}, ");
649 if(!barRealTimeAxis) { // true - non-time
650 if(!dateStrList.contains(new Long(date.getTime()).toString())) {
651 dateStrList.add(new Long(date.getTime()).toString());
652 for (int k = 0; k < uniqueElements.length; k++) {
653 //((StringBuffer) dataSeries.get(k)).append ("{ \"x\":" + date.getTime() + " , \"y\":null}, ");
654 HashMap<String, String> dataMap = dataSeriesMap.get((String) uniqueElements[k]);
655 dataMap.put(date.getTime()+"", "null");
660 //if(ds.getString(i, 2).equals(uniqueElements[j])) {
661 /*if(!dateStrList.contains(new Long(date.getTime()).toString())) {
662 for (int k = 0; k < uniqueElements.length; k++) {
663 ((StringBuffer) dataSeries.get(k)).append ("{ \"x\":" + date.getTime() + " , \"y\":null}, ");
666 //dateStrList.add(new Long(date.getTime()).toString());
668 YAXISNUM = Integer.parseInt(ds.getString(i, columnMap.get(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1)?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))));
669 dateStrList.add(new Long(date.getTime()).toString());
670 //if(MAXNUM < YAXISNUM) MAXNUM = YAXISNUM;
671 if(MAXDOUBLENUM < YAXISNUM) MAXDOUBLENUM = YAXISNUM;
672 } catch (NumberFormatException ex) {
674 YAXISDOUBLENUM = Double.parseDouble(ds.getString(i, columnMap.get(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1) ?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))));
675 MAXNUMDECIMALPLACES = getNumberOfDecimalPlaces(YAXISDOUBLENUM);
676 if(MAXDOUBLENUM < YAXISDOUBLENUM) MAXDOUBLENUM = YAXISDOUBLENUM;
677 } catch (NumberFormatException ex1) {
683 HashMap<String, String> dataMap = dataSeriesMap.get((String) uniqueElements[j]);
685 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"));
687 dataMap.put(date.getTime()+"", (flagNull == 0 ? (YAXISDOUBLENUM>0?new Double(YAXISDOUBLENUM).toString():new Integer(YAXISNUM).toString()): "null"));
691 // ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime() + " , \"y\":" + (flagNull==0?(YAXISDOUBLENUM>0?YAXISDOUBLENUM:YAXISNUM):null) +"}, ");
693 //((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime() + " , \"y\":" + ds.getString(i, columnMap.get((String)uniqueElements[j])) +"}, ");
698 for(int kI = 0; kI < uniqueElements.length; kI++) {
699 HashMap dataSeriesStrMap1 = (HashMap) dataSeriesOverAllMap.get(uniqueElements[kI]);
700 for (int kL = 0; kL < uniqueXAxisElements.length; kL++) {
701 if(dataSeriesStrMap1.containsKey(uniqueXAxisElements[kL])) {
702 ((StringBuffer) dataSeries.get(kI)).append ((String)dataSeriesStrMap1.get(uniqueXAxisElements[kL]));
704 ((StringBuffer) dataSeries.get(kI)).append ("{ \"x\":\"" + uniqueXAxisElements[kL] + "\" , \"y\": null }, ");
710 HashMap dataSeriesStrMap = new HashMap();
711 HashMap dataSeriesOverAllMap = new HashMap();
712 String valueDataSeries = "";
713 for (int j = 0; j < uniqueElements.length; j++) {
714 dataSeriesStrMap = new HashMap();
716 for (int i = 0; i < ds.getRowCount(); i++) {
719 YAXISDOUBLENUM = 0.0;
721 //flagSecondNull = 0;
722 dateStr = ds.getString(i, 1);
724 date = getDateFromDateStr(dateStr);
725 formatFlag = getFlagFromDateStr(dateStr);
727 uniqueElement = (String)uniqueElements[j];
732 //if(!((String)uniqueElementsList.get(i)).equals(dateStr)) {
733 for (int f=0 ; f< uniqueXAxisElements.length; f++) {
734 if(uniqueXAxisElements[f].equals(dateStr)){
739 /*for(int f=0; f<uniqueElementsList.size() && f < pos; f++)
741 StringBuffer strBuf = ((StringBuffer)dataSeries.get(j));
742 if(strBuf.indexOf((String)uniqueElementsList.get(f)) < 0 ) {
743 dataSeriesStrMap.put((String)uniqueElementsList.get(f), value);
744 //((StringBuffer) dataSeries.get(j)).append ("{ \"x\":\"" + (String)uniqueElementsList.get(f) + "\" , \"y\": null },");
749 if(ds.getString(i, 2).equals(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1) ?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))) {
750 dateStrList.add("'"+dateStr+"'");
752 YAXISNUM = Integer.parseInt(ds.getString(i, 3));
753 if(MAXDOUBLENUM < YAXISNUM) MAXDOUBLENUM = YAXISNUM;
754 } catch (NumberFormatException ex) {
756 YAXISDOUBLENUM = Double.parseDouble(ds.getString(i, 3));
757 MAXNUMDECIMALPLACES = getNumberOfDecimalPlaces(YAXISDOUBLENUM);
758 if(MAXDOUBLENUM < YAXISDOUBLENUM) MAXDOUBLENUM = YAXISDOUBLENUM;
759 } catch (NumberFormatException ex1) {
768 //((StringBuffer) dataSeries.get(j)).append ("{ \"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) +"}, ");
769 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) +"}, ";
770 dataSeriesStrMap.put(dateStr, valueDataSeries);
772 // ((StringBuffer) dataSeries.get(j)).append ("{ \"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) +"}, ");
773 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) +"}, ";
774 dataSeriesStrMap.put(dateStr, valueDataSeries);
778 //((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + dateStr + " , \"y\":" + (flagNull == 0 ? (YAXISDOUBLENUM>0?YAXISDOUBLENUM:YAXISNUM): null) +"}, ");
779 valueDataSeries = "{ \"x\":" + dateStr + " , \"y\":" + (flagNull == 0 ? (YAXISDOUBLENUM>0?YAXISDOUBLENUM:YAXISNUM): null) +"}, ";
780 dataSeriesStrMap.put(dateStr, valueDataSeries);
783 //((StringBuffer) dataSeries.get(j)).append ("{ \"x\":\"" + dateStr + "\" , \"y\":" + (flagNull == 0 ? (YAXISDOUBLENUM>0?YAXISDOUBLENUM:YAXISNUM): null) +"}, ");
784 valueDataSeries = "{ \"x\":\"" + dateStr + "\" , \"y\":" + (flagNull == 0 ? (YAXISDOUBLENUM>0?YAXISDOUBLENUM:YAXISNUM): null) +"}, ";
785 dataSeriesStrMap.put(dateStr, valueDataSeries);
790 /*if(ds.getString(i, 2).equals(uniqueElements[j])) {
791 dateStrList.add("'"+dateStr+"'");
792 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":\"" + dateStr + "\" , \"y\":\"" + ds.getString(i, 3) +"\"}, ");
795 dataSeriesOverAllMap.put(uniqueElements[j], dataSeriesStrMap);
797 //date = MMDDYYYYFormat.parse(ds.getString(i, 1), new ParsePosition(0));
798 if(!barRealTimeAxis) { // true - non-time
799 if(!dateStrList.contains(new Long(date.getTime()).toString())) {
800 dateStrList.add(new Long(date.getTime()).toString());
801 for (int k = 0; k < uniqueElements.length; k++) {
802 //((StringBuffer) dataSeries.get(k)).append ("{ \"x\":" + date.getTime() + " , \"y\":null}, ");
803 HashMap<String, String> dataMap = dataSeriesMap.get((String) uniqueElements[k]);
804 dataMap.put(date.getTime()+"", "null");
809 if(ds.getString(i, 2).equals(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1) ?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))) {
810 dateStrList.add(new Long(date.getTime()).toString());
812 YAXISNUM = Integer.parseInt(ds.getString(i, 3));
813 if(MAXDOUBLENUM < YAXISNUM) MAXDOUBLENUM = YAXISNUM;
814 } catch (NumberFormatException ex) {
816 YAXISDOUBLENUM = Double.parseDouble(ds.getString(i, 3));
817 MAXNUMDECIMALPLACES = getNumberOfDecimalPlaces(YAXISDOUBLENUM);
818 if(MAXDOUBLENUM < YAXISDOUBLENUM) MAXDOUBLENUM = YAXISDOUBLENUM;
819 } catch (NumberFormatException ex1) {
826 //if(ds.getString(i, 2).equals(uniqueElements[j])) {
827 // dateStrList.add("'"+dateStr+"'");
828 HashMap<String, String> dataMap = dataSeriesMap.get((String) uniqueElements[j]);
830 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"));
832 if(dataMap.containsKey(new String(""+date.getTime())) && dataMap.get(new String(""+date.getTime())).equals("null")) {
833 dataMap.remove(date.getTime());
835 dataMap.put(date.getTime()+"", (flagNull == 0 ? (YAXISDOUBLENUM>0?new Double(YAXISDOUBLENUM).toString():new Integer(YAXISNUM).toString()): "null"));
837 // .println(dataMap + " " + dataSeriesMap);
840 // ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime() + " , \"y\":" + (flagNull == 0 ? (YAXISDOUBLENUM>0?YAXISDOUBLENUM:YAXISNUM): null) +"}, ");
843 //((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime() + " , \"y\":" + ds.getString(i, 3) +"}, ");
844 } else if (AppUtils.nvl(ds.getString(i, 2)).length()<=0) {
845 dateStrList.add(new Long(date.getTime()).toString());
846 HashMap<String, String> dataMap1 = null;
847 String uniqueElement1 = "";
848 for (int j1 = 0; j1 < uniqueElements.length; j1++) {
849 uniqueElement1 = (String)uniqueElements[j];
850 if(ds.getString(i, 2).equals(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement1.lastIndexOf("|") != -1) ?uniqueElement1.substring(0, uniqueElement1.lastIndexOf("|")):uniqueElement1))) {
851 dataMap1 = dataSeriesMap.get((String) uniqueElements[j1]);
852 if(!dataMap1.containsKey(new String(""+date.getTime())))
853 dataMap1.put(date.getTime()+"", "null");
858 // dataSeriesOverAllMap.put(uniqueElements[j], dataSeriesMap);
862 for(int kI = 0; kI < uniqueElements.length; kI++) {
863 HashMap dataSeriesStrMap1 = (HashMap) dataSeriesOverAllMap.get(uniqueElements[kI]);
864 for (int kL = 0; kL < uniqueXAxisElements.length; kL++) {
865 if(dataSeriesStrMap1.containsKey(uniqueXAxisElements[kL])) {
866 ((StringBuffer) dataSeries.get(kI)).append ((String)dataSeriesStrMap1.get(uniqueXAxisElements[kL]));
868 ((StringBuffer) dataSeries.get(kI)).append ("{ \"x\":\"" + uniqueXAxisElements[kL] + "\" , \"y\": null }, ");
874 StringBuffer dateStrBuf = new StringBuffer("");
876 Long initialDate = Long.parseLong((String)ds.getString(0, 0));
877 Long endDate = Long.parseLong((String) ds.getString(ds.getRowCount(), 0));
878 java.util.Date date1 = null;
880 while ( initialDate <= endDate) {
881 //System.out.println("********** " + df.format(initialDate));
882 date1 = new java.util.Date(initialDate.longValue() * 1000);
883 initialDate = initialDate + HOUR;
885 dateStrBuf.append(initialDate+",");
886 sortSet.add(""+initialDate);
887 //DateUtils.addHours(date1, 1);
891 if(dateStrList.size()>0) {
892 SortedSet<String> s = Collections.synchronizedSortedSet(dateStrList);
893 Object[] dateElements = (Object[]) s.toArray();
896 /* if not date value */
898 for (int i = 0; i < dateElements.length; i++) {
899 dateStrBuf.append(dateElements[i]+",");
902 if(!barRealTimeAxis || (flagNoDate == 1)) { // non-time
903 for (int i = 0; i < dateElements.length; i++) {
904 dateStrBuf.append(dateElements[i]+",");
907 Long initialDate = Long.parseLong((String)dateElements[0]);
908 Long endDate = Long.parseLong((String) dateElements[dateElements.length-1]);
909 java.util.Date date1 = null;
911 date1 = new java.util.Date(initialDate.longValue());
912 /* DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss Z");
913 System.out.println(formatter.format(new java.util.Date(initialDate.longValue())));
914 */ //initialDate = initialDate + HOUR;
916 dateStrBuf.append(initialDate+",");
917 sortSet.add(""+initialDate);
921 while ( initialDate <= endDate) {
922 //System.out.println("********** " + df.format(initialDate));
923 //date1 = new java.util.Date(initialDate.longValue() * 1000);
924 date1 = new java.util.Date(initialDate.longValue());
925 if(formatFlag==HOURFLAG)
926 date1 = DateUtils.addHours(date1, 1);
927 else if(formatFlag==MINFLAG)
928 date1 = DateUtils.addMinutes(date1, 30);
929 else if (formatFlag == DAYFLAG)
930 date1 = DateUtils.addDays(date1, 1);
931 else if (formatFlag == MONTHFLAG)
932 date1 = DateUtils.addMonths(date1, 1);
933 else if (formatFlag == YEARFLAG)
934 date1 = DateUtils.addMonths(date1, 1);
935 initialDate = date1.getTime();
937 if(initialDate <= endDate) {
938 dateStrBuf.append(initialDate+",");
939 sortSet.add(""+initialDate);
941 //DateUtils.addHours(date1, 1);
943 //DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);
944 //df.setTimeZone(TimeZone.getTimeZone("UTC"));
945 //java.util.Date date1 = new java.util.Date(initialDate.longValue() * 1000);
946 //java.util.Date d = df.
950 dateStrBuf.deleteCharAt(dateStrBuf.length()-1);
954 //if(!barRealTimeAxis) { // false - non-time
955 Object[] dateAllElements = (Object[]) sortSet.toArray();
957 for (int i = 0; i < uniqueElements.length; i++) {
958 HashMap<String, String> dataMap = dataSeriesMap.get((String)uniqueElements[i]);
959 for (int j=0; j<dateAllElements.length;j++) {
960 //if(strBuf.toString().indexOf((String) dateAllElements[j]) == -1) {
961 if(!dataMap.containsKey((String) dateAllElements[j])) {
962 dataMap.put((String) dateAllElements[j], "null");
963 //((StringBuffer) dataSeries.get(i)).append ("{ \"x\":" + dateAllElements[j] + " , \"y\":null}, ");
969 String valueStr = "";
970 for (int i = 0; i < uniqueElements.length; i++) {
971 HashMap<String, String> dataMap = dataSeriesMap.get((String)uniqueElements[i]);
972 Set<String> keySet = dataMap.keySet();
973 ArrayList<String> keySortedList = new ArrayList<String>(new TreeSet<String>(keySet));
975 for (int k=0; k < keySortedList.size(); k++) {
976 valueStr = dataSeriesMap.get((String)uniqueElements[i]).get(keySortedList.get(k));
977 if(valueStr.equals("null"))
981 //valueStr = new Double(Math.log10(new Double(valueStr).doubleValue())).toString();
983 ((StringBuffer) dataSeries.get(i)).append ("{ \"x\":" + keySortedList.get(k) + " , \"y\":" + valueStr +"}, ");
984 // ((StringBuffer) dataSeries.get(i)).append ("{ \"x\":" + keySortedList.get(k) + " , \"y\":" + valueStr +"}, ");
987 // ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime() + " , \"y\":" + (flagNull == 0 ? (YAXISDOUBLENUM>0?YAXISDOUBLENUM:YAXISNUM): null) +"}, ");
990 for (int i = 0; i < uniqueElements.length; i++) {
991 StringBuffer strBuf = ((StringBuffer) dataSeries.get(i));
992 ((StringBuffer) dataSeries.get(i)).deleteCharAt(((StringBuffer) dataSeries.get(i)).lastIndexOf(","));
993 if(i < (uniqueElements.length -1) ) {
994 ((StringBuffer) dataSeries.get(i)).append("] } , \n");
997 ((StringBuffer) dataSeries.get(i)).append("] } \n");
1000 if(ds.getRowCount() > 0) {
1001 for (int i = 0; i < uniqueElements.length; i++) {
1002 wholeScript.append((StringBuffer)dataSeries.get(i));
1007 wholeScript.append("]; \n");
1009 //add global variable
1010 wholeScript.append("var chart; \n");
1011 //javascript to create Bar Chart
1012 wholeScript.append("nv.addGraph(function() { \n");
1013 if(horizontalBar /*&& flagNoDate == 1*/)
1014 wholeScript.append(" chart = nv.models.multiBarHorizontalChart() \n");
1015 else /*if (flagNoDate == 1)*/
1016 wholeScript.append(" chart = nv.models.multiBarChart() \n");
1018 wholeScript.append(" var chart = nv.models.multiBarTimeSeriesChart() \n");*/
1020 wholeScript.append(" .margin({top: "+ topMargin +", right: "+ rightMargin +", bottom: "+ bottomMargin +", left: " + leftMargin +"}) \n");
1022 wholeScript.append(" .showLegend(true) \n ");
1024 wholeScript.append(" .showLegend(false) \n ");
1026 if(!horizontalBar && barReduceXAxisLabels)
1027 wholeScript.append(" .reduceXTicks(true) \n ");
1028 else if (!horizontalBar) {
1029 wholeScript.append(" .reduceXTicks(false) \n ");
1030 //wholeScript.append(" chart.lines1.forceY(["+(nvl(reportRuntime.getRangeAxisLowerLimit()).length()<=0?"0":reportRuntime.getRangeAxisLowerLimit()) +", "+ (nvl(reportRuntime.getRangeAxisUpperLimit()).length()<=0?UPPER_RANGE:reportRuntime.getRangeAxisUpperLimit()) + "]); \n" +
1031 double UPPER_RANGE = 0;
1032 if(Math.ceil((MAXDOUBLENUM+(MAXDOUBLENUM*25/100))/100) * 100 >= 1) {
1033 UPPER_RANGE = Math.ceil(MAXDOUBLENUM+(MAXDOUBLENUM*25/100));
1034 } else UPPER_RANGE = 1;
1035 wholeScript.append(" .forceY(["+(nvl(reportRuntime.getRangeAxisLowerLimit()).length()<=0?"0":reportRuntime.getRangeAxisLowerLimit()) +", "+ (nvl(reportRuntime.getRangeAxisUpperLimit()).length()<=0?UPPER_RANGE:reportRuntime.getRangeAxisUpperLimit()) + "])\n");
1038 wholeScript.append(" .delay(0) \n ");
1041 wholeScript.append(" .showControls(true) \n ");
1042 } else if (!showControls){
1043 wholeScript.append(" .showControls(false) \n ");
1045 if(stacked && !logScale)
1046 wholeScript.append(" .stacked(true)\n ");
1047 else if(!stacked || logScale)
1048 wholeScript.append(" .stacked(false)\n ");
1050 wholeScript.append(" .logScale(true)\n ");
1052 wholeScript.append(" .logScale(false)\n ");
1055 if(AppUtils.nvl(reportRuntime.getLegendPosition()).length()>=0 && reportRuntime.getLegendPosition().equals("right")) {
1056 wholeScript.append(" .legendPos('right')\n" );
1058 wholeScript.append(" .legendPos('top')\n" );
1060 if(uniqueElements.length <= 10) {
1061 wholeScript.append(" .color(d3.scale.category10().range()); \n" +
1063 } else if (uniqueElements.length <= 20) {
1064 wholeScript.append(" .color(d3.scale.category50().range()); \n" +
1067 wholeScript.append(" .color(d3.scale.category50().range()); \n" +
1073 wholeScript.append(" .tickValues(["+ dateStrBuf.toString() + "])\n ");
1075 wholeScript.append(" .tickValues(["+ dateStrBuf.toString() + "])\n ");
1078 wholeScript.append(" .staggerLabels(true) \n");
1080 wholeScript.append(" .staggerLabels(false) \n");
1082 if(!horizontalBar) {
1084 wholeScript.append(" .showMaxMin(true) \n ");
1086 wholeScript.append(" .showMaxMin(false) \n ");
1089 if(nvl(rotateLabels).length()>0) {
1090 wholeScript.append(" .rotateLabels("+ rotateLabels+ ") \n ");
1092 wholeScript.append(" .rotateLabels(\"0\") \n ");
1094 wholeScript.append(" .axisLabel('" + legendColumnName + "')");
1095 if(flagNoDate == 1 || !timeAxis) {
1096 wholeScript.append(";\n");
1098 wholeScript.append("\n .tickFormat(function(d) { \n");
1100 if(formatFlag==HOURFLAG)
1101 wholeScript.append(" return d3.time.format('%x %H')(new Date(d)) }); \n");
1102 else if(formatFlag==MINFLAG)
1103 wholeScript.append(" return d3.time.format('%x %H:%M')(new Date(d)) }); \n");
1104 else if(formatFlag==SECFLAG)
1105 wholeScript.append(" return d3.time.format('%X')(new Date(d)) }); \n");
1106 else if(formatFlag==MONTHFLAG)
1107 wholeScript.append(" return d3.time.format('%b %y')(new Date(d)) }); \n");
1109 wholeScript.append(" return d3.time.format('%x')(new Date(d)) }); \n");
1112 wholeScript.append(" return d; }); \n");
1116 if(nvl(chartRightAxisLabel).length() > 0) {
1117 //if(flagNoDate == 1)
1118 wholeScript.append(" chart.yAxis\n");
1120 // wholeScript.append(" chart.yAxis1\n");
1122 wholeScript.append(" .logScale(true)\n ");
1124 wholeScript.append(" .logScale(false)\n ");
1127 wholeScript.append(" .axisLabel('" + chartLeftAxisLabel + "') \n" +
1128 " .tickFormat(d3.format(',.0f')); \n");
1129 /*" chart.yAxis2\n " +
1130 " .axisLabel('" + chartRightAxisLabel + "') \n" +
1131 " .tickFormat(d3.format(',.0f')); \n");*/
1135 //if(flagNoDate == 1)
1136 wholeScript.append(" chart.yAxis\n");
1138 // wholeScript.append(" chart.yAxis1\n");
1140 wholeScript.append(" .logScale(true)\n ");
1142 wholeScript.append(" .logScale(false)\n ");
1144 wholeScript.append(" .axisLabel('" + chartLeftAxisLabel + "') \n");
1146 if(MAXDOUBLENUM <=5 && MAXNUMDECIMALPLACES == 0 ) MAXNUMDECIMALPLACES = 2;
1147 if( MAXNUMDECIMALPLACES >=3 ) MAXNUMDECIMALPLACES = 2;
1149 wholeScript.append(" .tickFormat(d3.format(',."+MAXNUMDECIMALPLACES+"f')); \n");
1151 wholeScript.append(" .tickFormat(d3.format(',." + precision + "f')); \n");
1152 //" .tickFormat(d3.format(',.0f')); \n");
1154 wholeScript.append(" d3.select('#chart"+reportRuntime.getReportID()+" svg') \n" +
1155 " .datum(historicalBarChart) \n" );
1157 wholeScript.append(" .transition().duration(1000) \n" );
1159 wholeScript.append(" .transition().duration(0) \n" );
1160 wholeScript.append(" .call(chart); \n" +
1161 "nv.utils.windowResize(chart.update); \n" +
1162 "return chart; \n" +
1164 wholeScript.append("function redraw() { \n");
1165 //wholeScript.append(" nv.utils.windowResize(chart.update); \n");
1166 wholeScript.append(" d3.select('#chart"+reportRuntime.getReportID()+" svg') \n") ;
1167 wholeScript.append(" .datum(historicalBarChart) \n");
1168 wholeScript.append(" .transition().duration(500) \n");
1169 wholeScript.append(" .call(chart); \n");
1170 wholeScript.append("} \n");
1171 wholeScript.append("\n");
1172 wholeScript.append(" setInterval(function () { \n");
1173 wholeScript.append(" redraw(); \n");
1174 wholeScript.append(" }, 1500) \n");
1176 wholeScript.append("if(historicalBarChart.length <= 0 ) {\n");
1177 wholeScript.append(" document.getElementById(\"chart"+reportRuntime.getReportID()+"\").innerHTML = \"<div id='noData'><b>No Data Available</b></div>\";\n");
1178 wholeScript.append(" document.getElementById(\"chart"+reportRuntime.getReportID()+"\").className=\"nodatadiv\";\n");
1179 wholeScript.append(" document.getElementById(\"nodata\").className=\"nodatainner\";\n");
1180 wholeScript.append("}\n");
1181 wholeScript.append("</script> </body></html> \n");
1183 } else if (chartType.equals(AppConstants.GT_TIME_SERIES)) {
1185 // get category if not give the column name for the data column use this to develop series.
1186 boolean hasCategoryAxis = reportRuntime.hasSeriesColumn();
1189 final int YEARFLAG = 1;
1190 final int MONTHFLAG = 2;
1191 final int DAYFLAG = 3;
1192 final int HOURFLAG = 4;
1193 final int MINFLAG = 5;
1194 final int SECFLAG = 6;
1195 final int MILLISECFLAG = 7;
1196 final int DAYOFTHEWEEKFLAG = 8;
1197 final int FLAGDATE = 9;
1200 flag = hasCategoryAxis?1:0;
1201 String uniqueElements [] = null;
1202 //TreeSet ts = new TreeSet();
1203 ArrayList ts = new ArrayList<String>();
1204 HashMap<String, String> columnMap = new HashMap();
1206 String dateStr = null;
1207 java.util.Date date = null;
1208 if( ds.getRowCount() > 0) {
1209 dateStr = ds.getString(0, 1);
1211 date = getDateFromDateStr(dateStr);
1213 reportRuntime.setTimeAxis(true);
1214 timeAxis = reportRuntime.isTimeAxis();
1221 ArrayList<String> ts1 = new ArrayList();
1222 ArrayList uniqueElementsList = new ArrayList();
1223 Object uniqueXAxisElements[] = null;
1224 String uniqueXAxisStr = "";
1226 for (int i = 0; i < ds.getRowCount(); i++) {
1227 uniqueXAxisStr = ds.getString(i, 0);
1228 ts1.add(uniqueXAxisStr);
1231 uniqueElementsList.addAll(ts1);
1232 uniqueXAxisElements = ts1.toArray();
1239 TreeSet<String> colorList = new TreeSet<String>();
1240 for (int i = 0; i < ds.getRowCount(); i++) {
1243 VALUE = Integer.parseInt(ds.getString(i, 2));
1244 TOTAL = TOTAL+VALUE;
1245 } catch (NumberFormatException ex) {
1248 KEY = ds.getString(i, 0);
1250 if(ds.getString(i, "chart_color")!=null) {
1251 colorList.add(KEY+"|"+ds.getString(i, "chart_color"));
1253 } catch (ArrayIndexOutOfBoundsException ex) {
1254 System.out.println("No Chart Color");
1256 wholeScript.append("{ \""+ "key" +"\":\""+ KEY+"\", \""+ "y" +"\":"+VALUE+"}, \n");
1259 StringBuffer color = new StringBuffer("");
1260 if(colorList.size()>0) {
1261 SortedSet<String> s = Collections.synchronizedSortedSet(colorList);
1262 Object[] colorElements = (Object[]) s.toArray();
1264 String element = "";
1266 for (int i = 0; i < colorElements.length; i++) {
1267 element = ((String)colorElements[i]);
1268 color.append("'"+element.substring(element.indexOf("|")+1)+"',");
1270 color.deleteCharAt(color.length()-1);
1274 boolean hasCustomizedChartColor = false;
1276 StringBuffer catStr = new StringBuffer("");
1278 for (int i = 0; i < ds.getRowCount(); i++) {
1279 catStr = new StringBuffer("");
1280 catStr.append(ds.getString(i, 2));
1282 if(ds.getString(i, "chart_color")!=null) {
1283 color = ds.getString(i, "chart_color");
1284 hasCustomizedChartColor = true;
1285 catStr.append("|"+color);
1287 } catch (ArrayIndexOutOfBoundsException ex) {
1288 //System.out.println("No Chart Color");
1291 if(catStr.length()>0) {
1292 //duplicates are avoided
1293 if(!ts.contains(catStr.toString()))
1294 ts.add(catStr.toString());
1298 //Object uniqueElements [] = ts.toArray();
1299 //SortedSet s = Collections.synchronizedSortedSet(ts);
1300 //uniqueElements = (String[]) ts.toArray();
1301 DataColumnType dct = null;
1302 List yTextSeries = reportRuntime.getChartDisplayNamesList(AppConstants.CHART_ALL_COLUMNS, formValues);
1303 if(yTextSeries.size()==1) {
1304 for (Iterator iter = l.iterator(); iter.hasNext();) {
1305 dct = (DataColumnType) iter.next();
1306 //System.out.println(dct.getDisplayName() + " " + yText);
1307 if(!(nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND))) {
1308 if(nvl(chartLeftAxisLabel).length()<=0) {
1309 chartLeftAxisLabel = nvl(dct.getYAxis());
1310 chartLeftAxisLabel = (chartLeftAxisLabel.indexOf("|")!=-1)?chartLeftAxisLabel.substring(0,chartLeftAxisLabel.indexOf("|")):"";
1315 Object tempArray[] = ts.toArray();
1316 uniqueElements = Arrays.copyOf(tempArray, tempArray.length, String[].class);
1319 DataColumnType dct = null;
1321 List yTextSeries = reportRuntime.getChartDisplayNamesList(AppConstants.CHART_ALL_COLUMNS, formValues);
1322 //if(columnValuesList.size() == 1) {
1324 for (Iterator iter = l.iterator(); iter.hasNext();) {
1325 dct = (DataColumnType) iter.next();
1326 //System.out.println(dct.getDisplayName() + " " + yText);
1327 if(!(nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND))) {
1328 if(yTextSeries.contains((String)dct.getDisplayName())) {
1329 if(nvl(dct.getChartColor()).length()>0) hasCustomizedChartColor = true;
1330 if(hasCustomizedChartColor) {
1331 //duplicates are avoided
1332 if(!ts.contains(dct.getDisplayName()+"|"+nvl(dct.getChartColor())))
1333 ts.add(dct.getDisplayName()+"|"+nvl(dct.getChartColor()));
1335 //duplicates are avoided
1336 if(!ts.contains(dct.getDisplayName()))
1337 ts.add(dct.getDisplayName());
1339 if(nvl(chartLeftAxisLabel).length()<=0) {
1340 chartLeftAxisLabel = nvl(dct.getYAxis());
1341 chartLeftAxisLabel = (chartLeftAxisLabel.indexOf("|")!=-1)?chartLeftAxisLabel.substring(0,chartLeftAxisLabel.indexOf("|")):"";
1343 if(nvl(chartRightAxisLabel).length()>0) {
1344 String dctYAxis = nvl(dct.getYAxis());
1345 String yAxis = (dctYAxis.indexOf("|")!=-1)?dctYAxis.substring(0,dctYAxis.indexOf("|")):dctYAxis;
1346 if(chartRightAxisLabel.equals(yAxis)) {
1347 if(ts.contains(dct.getDisplayName())) {
1348 if(hasCustomizedChartColor) {
1349 ts.set(dctIndex, dct.getDisplayName()+"|R|"+nvl(dct.getChartColor()));
1351 ts.set(dctIndex, dct.getDisplayName()+"|R");
1356 columnMap.put(dct.getDisplayName(), dct.getColId());
1363 //SortedSet s = Collections.synchronizedSortedSet(ts);
1364 Object tempArray[] = ts.toArray();
1365 uniqueElements = Arrays.copyOf(tempArray, tempArray.length, String[].class);
1366 //uniqueElements = (String[]) ts.toArray();
1370 wholeScript.append("<!DOCTYPE html>\n");
1371 wholeScript.append("<html>\n");
1372 wholeScript.append("<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF8\">\n");
1373 wholeScript.append("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n");
1374 wholeScript.append("<link href=\""+ chartScriptsPath +"d3/css/nv.d3.css\" rel=\"stylesheet\" type=\"text/css\">\n");
1375 wholeScript.append("<style>\n " +
1377 " overflow-y:scroll; \n" +
1380 " font: 12px sans-serif; \n" +
1383 " display: block;\n" +
1385 " #chart"+reportRuntime.getReportID()+" svg { \n" +
1386 " height: "+ (nvl(height).length()>0?(height.endsWith("px")?height:height+"px"):"420px") + "; \n" +
1387 " width: "+ (nvl(width).length()>0?(width.endsWith("px")?width:width+"px"):"700px") + "; \n" +
1388 " min-width: 100px; \n" +
1389 " min-height: 100px; \n" +
1391 " tr.z-row-over > td.z-row-inner, tr.z-row-over > .z-cell {" +
1392 " background-color: rgb(255, 255, 255); "+
1394 wholeScript.append(".nodatadiv {\n");
1395 wholeScript.append(" display: table-cell;\n");
1396 wholeScript.append(" width: 700px;\n");
1397 wholeScript.append(" height:370px;\n");
1398 wholeScript.append(" text-align:center;\n");
1399 wholeScript.append(" vertical-align: middle;\n");
1400 wholeScript.append("}\n");
1401 wholeScript.append(".nodatainner {\n");
1402 wholeScript.append(" padding: 10px;\n");
1403 wholeScript.append("}\n");
1405 wholeScript.append(" </style> \n" );
1407 wholeScript.append("<body> \n");
1410 wholeScript.append("<div align=\"center\"><H3>" + title +"</H3></div>");
1413 wholeScript.append("<div id=\"chart"+reportRuntime.getReportID()+"\"> <svg></svg> </div> \n");
1415 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/d3.v3.min.js\"></script>\n");
1416 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/nv.d3.min.js\"></script> \n");
1417 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/models/axis.min.js\"></script> \n");
1418 //wholeScript.append("<script src=\""+ AppUtils.getBaseFolderURL() +"d3/js/models/cumulativeLineChart.js\"></script> \n");
1419 //if(multipleSeries)
1420 //wholeScript.append("<script src=\""+ AppUtils.getBaseFolderURL() +"d3/js/models/multiChart.js\"></script> \n");
1423 wholeScript.append("<script> \n");
1425 wholeScript.append("historicalBarChart = [ \n");
1426 //wholeScript.append("{ \n");
1427 ArrayList dataSeries = new ArrayList();
1428 String uniqueElement = "";
1430 String [] uniqueRevElements = null;
1431 //Added to make sure order appears same as legend
1432 /*if(nvl(subType).length() > 0 && subType.equals("area")) {
1433 uniqueRevElements = reverse((String[])uniqueElements);
1435 uniqueRevElements = (String[])uniqueElements;
1438 int RIGHTAXISSERIES = 0;
1439 for (int i = 0; i < uniqueRevElements.length; i++) {
1440 //element.substring(element.indexOf("|")+1)
1441 uniqueElement = (String)uniqueRevElements[i];
1442 if(multipleSeries && (nvl(chartRightAxisLabel).length() > 0)) {
1443 if(nvl(subType).length() > 0 && subType.equals("area")) {
1444 if(nvl(uniqueElement).indexOf("|R") !=-1)
1445 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\": ["));
1447 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\": ["));
1449 if(nvl(uniqueElement).indexOf("|R") !=-1)
1450 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\": ["));
1452 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\": ["));
1454 RIGHTAXISSERIES = dataSeries.size()-1;
1455 //dataSeries.add(new StringBuffer(" { \"type\":\"line\", \"key\": \""+ ((DataColumnType)columnMap.get(i)).getDisplayName() +"\", \"yAxis\": \""+(i+1)+"\", \"values\": ["));
1458 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\": ["));
1462 /*StringBuffer dataSeries1 = new StringBuffer("");
1463 dataSeries1.append(" { key: \"Series1\",values: [");
1464 StringBuffer dataSeries2 = new StringBuffer("");
1465 dataSeries2.append(" { key: \"Series2\", values: [");
1466 StringBuffer dataSeries3 = new StringBuffer("");
1467 dataSeries3.append(" { key: \"Series3\", values: [");
1471 //long minTime = 1000000000000000L;
1473 double MAXDOUBLENUM = 0.0;
1475 double YAXISDOUBLENUM = 0.0;
1476 int MAXNUMDECIMALPLACES = 0;
1478 int flagSecondNull = 0;
1479 TreeSet dateList = new TreeSet();
1482 for (int j = 0; j < uniqueRevElements.length; j++) {
1483 for (int i = 0; i < ds.getRowCount(); i++) {
1487 YAXISDOUBLENUM = 0.0;
1490 dateStr = ds.getString(i, 1);
1492 date = getDateFromDateStr(dateStr);
1493 formatFlag = getFlagFromDateStr(dateStr);
1495 if(date==null && timeAxis) continue;
1498 //if(ds.getString(i, 2).equals(uniqueElements[j])) {
1499 //if(minTime > date.getTime())
1500 // minTime = date.getTime();
1501 uniqueElement = (String)uniqueRevElements[j];
1503 YAXISNUM = Integer.parseInt(ds.getString(i, columnMap.get(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1)?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))));
1504 if(MAXDOUBLENUM < YAXISNUM) MAXDOUBLENUM = YAXISNUM;
1505 } catch (NumberFormatException ex) {
1507 YAXISDOUBLENUM = Double.parseDouble(ds.getString(i, columnMap.get(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1) ?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))));
1508 if(RIGHTAXISSERIES!=j) {
1509 MAXNUMDECIMALPLACES = getNumberOfDecimalPlaces(YAXISDOUBLENUM);
1510 if(MAXDOUBLENUM < YAXISDOUBLENUM) MAXDOUBLENUM = YAXISDOUBLENUM;
1512 } catch (NumberFormatException ex1) {
1518 dateList.add(dateStr);
1519 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":\"" + dateStr + "\" , \"y\":" + (flagNull==0?(YAXISDOUBLENUM>0?YAXISDOUBLENUM:YAXISNUM):null) +"}, ");
1521 dateList.add(new Long(date.getTime()).toString());
1522 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime() + " , \"y\":" + (flagNull==0?(YAXISDOUBLENUM>0?YAXISDOUBLENUM:YAXISNUM):null) +"}, ");
1527 if(nvl(subType).length() > 0 && subType.equals("area")) {
1530 if(i<ds.getRowCount()-1) {
1532 YAXISNUM = Integer.parseInt(ds.getString(i+1, columnMap.get(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1)?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))));
1533 if(MAXDOUBLENUM < YAXISNUM) MAXDOUBLENUM = YAXISNUM;
1534 } catch (NumberFormatException ex) {
1536 YAXISDOUBLENUM = Double.parseDouble(ds.getString(i+1, columnMap.get(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1) ?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))));
1537 if(RIGHTAXISSERIES!=j) {
1538 MAXNUMDECIMALPLACES = getNumberOfDecimalPlaces(YAXISDOUBLENUM);
1539 if(MAXDOUBLENUM < YAXISDOUBLENUM) MAXDOUBLENUM = YAXISDOUBLENUM;
1541 } catch (NumberFormatException ex1) {
1546 if(flagSecondNull==1 && date == null) {
1547 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":\"" + dateStr + "\" , \"y\":" + null +"}, ");
1548 } else if( flagSecondNull == 1){
1549 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime() + " , \"y\":" + null +"}, ");
1553 if(i<ds.getRowCount()-1) {
1554 dateStr = ds.getString(i+1, 1);
1557 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":\"" + dateStr + "\" , \"y\":" + null +"}, ");
1559 date = getDateFromDateStr(dateStr);
1560 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime() + " , \"y\":" + null +"}, ");
1562 //((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime() + " , \"y\":" + null +"}, ");
1571 //((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + minTime + " , \"y\":" + 0 +"}, ");
1575 for (int j = 0; j < uniqueRevElements.length; j++) {
1576 for (int i = 0; i < ds.getRowCount(); i++) {
1578 YAXISDOUBLENUM = 0.0;
1581 dateStr = ds.getString(i, 1);
1583 date = getDateFromDateStr(dateStr);
1584 formatFlag = getFlagFromDateStr(dateStr);
1587 if(date==null && timeAxis) continue;
1589 uniqueElement = (String)uniqueRevElements[j];
1590 //date = MMDDYYYYFormat.parse(ds.getString(i, 1), new ParsePosition(0));
1591 if(ds.getString(i, 2).equals(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1) ?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))) {
1592 //if(minTime > date.getTime())
1593 // minTime = date.getTime();
1595 YAXISNUM = Integer.parseInt(ds.getString(i, 3));
1596 if(MAXDOUBLENUM < YAXISNUM) MAXDOUBLENUM = YAXISNUM;
1597 } catch (NumberFormatException ex) {
1599 YAXISDOUBLENUM = Double.parseDouble(ds.getString(i, 3));
1600 if(RIGHTAXISSERIES!=j) {
1601 MAXNUMDECIMALPLACES = getNumberOfDecimalPlaces(YAXISDOUBLENUM);
1602 if(MAXDOUBLENUM < YAXISDOUBLENUM) MAXDOUBLENUM = YAXISDOUBLENUM;
1605 } catch (NumberFormatException ex1) {
1611 dateList.add(dateStr);
1612 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + dateStr + " , \"y\":" + (flagNull==0?(YAXISDOUBLENUM!=0.0?YAXISDOUBLENUM:YAXISNUM):null) +"}, ");
1614 dateList.add(new Long(date.getTime()).toString());
1615 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime() + " , \"y\":" + (flagNull==0?(YAXISDOUBLENUM!=0.0?YAXISDOUBLENUM:YAXISNUM):null) +"}, ");
1619 if(nvl(subType).length() > 0 && subType.equals("area")) {
1622 if(i<ds.getRowCount()-1) {
1623 for (int k = i+1; k < ds.getRowCount(); k++) {
1624 if (ds.getString(k, 2).equals(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1) ?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))) {
1626 YAXISNUM = Integer.parseInt(ds.getString(k, 3));
1627 if(MAXDOUBLENUM < YAXISNUM) MAXDOUBLENUM = YAXISNUM;
1628 } catch (NumberFormatException ex) {
1630 YAXISDOUBLENUM = Double.parseDouble(ds.getString(k, 3));
1631 if(RIGHTAXISSERIES!=j) {
1632 MAXNUMDECIMALPLACES = getNumberOfDecimalPlaces(YAXISDOUBLENUM);
1633 if(MAXDOUBLENUM < YAXISDOUBLENUM) MAXDOUBLENUM = YAXISDOUBLENUM;
1635 } catch (NumberFormatException ex1) {
1643 if(date==null && flagSecondNull==1){
1644 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + dateStr + " , \"y\":" + null +"}, ");
1645 } else if(flagSecondNull == 1){
1646 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime() + " , \"y\":" + null +"}, ");
1651 if(i<ds.getRowCount()-1) {
1652 for (int k = i+1; k < ds.getRowCount(); k++) {
1653 if (ds.getString(k, 2).equals(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1) ?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))) {
1654 dateStr = ds.getString(k, 1);
1656 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime() + " , \"y\":" + null +"}, ");
1659 date = getDateFromDateStr(dateStr);
1660 ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime() + " , \"y\":" + null +"}, ");
1671 // ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + minTime + " , \"y\":" + 0 +"}, ");
1674 /* if(ds.getString(i, 2).equals("Series1")) {
1675 dataSeries1.append("[ " + date.getTime() + " , " + ds.getString(i, 3) +"], ");
1676 } else if (ds.getString(i, 2).equals("Series2")) {
1677 dataSeries2.append("[ " + date.getTime() + " , " + ds.getString(i, 3) +"], ");
1678 } else if (ds.getString(i, 2).equals("Series3")) {
1679 dataSeries3.append("[ " + date.getTime() + " , " + ds.getString(i, 3) +"], ");
1683 for (int i = 0; i < uniqueRevElements.length; i++) {
1684 StringBuffer strBuf = ((StringBuffer) dataSeries.get(i));
1685 ((StringBuffer) dataSeries.get(i)).deleteCharAt(((StringBuffer) dataSeries.get(i)).lastIndexOf(","));
1686 if(i < (uniqueRevElements.length -1) ) {
1687 ((StringBuffer) dataSeries.get(i)).append("] } , \n");
1690 ((StringBuffer) dataSeries.get(i)).append("] } \n");
1694 for (int i = 0; i < uniqueRevElements.length; i++) {
1695 wholeScript.append((StringBuffer)dataSeries.get(i));
1697 /* wholeScript.append(dataSeries1);
1698 wholeScript.append(dataSeries2);
1699 wholeScript.append(dataSeries3);
1700 */ wholeScript.append("];\n");
1702 /* Sorting is commented out.*/
1703 StringBuffer dateStrBuf = new StringBuffer("");
1704 if(dateList.size()>0) {
1705 //SortedSet<String> s = Collections.synchronizedSortedSet(dateList);
1706 Object[] dateElements = (Object[]) dateList.toArray();
1708 String element = "";
1710 for (int i = 0; i < dateElements.length; i++) {
1711 dateStrBuf.append(dateElements[i]+",");
1713 dateStrBuf.deleteCharAt(dateStrBuf.length()-1);
1716 wholeScript.append(" var chart;\n");
1717 wholeScript.append("nv.addGraph(function() { \n");
1718 //" var chart = nv.models.cumulativeLineChart() \n" + nv.models.lineWithFocusChart()
1719 // " chart = nv.models.lineChart() \n" +
1720 if(nvl(subType).length() > 0 && subType.equals("area")) {
1721 wholeScript.append(" chart = nv.models.stackedAreaChart() \n");
1723 wholeScript.append(" .showControls(true) \n ");
1725 wholeScript.append(" .showControls(false) \n ");
1728 wholeScript.append(" chart = nv.models.multiChart() \n");
1729 if(nvl(chartRightAxisLabel).length() > 0) {
1730 wholeScript.append(" .dualaxis(true) \n ");
1732 wholeScript.append(" .dualaxis(false) \n ");
1735 if(AppUtils.nvl(reportRuntime.getLegendPosition()).length()>=0 && reportRuntime.getLegendPosition().equals("right")) {
1736 wholeScript.append(" .legendPos('right')\n" );
1738 wholeScript.append(" .legendPos('top')\n" );
1744 wholeScript.append(" .margin({top: "+ topMargin +", right: "+ rightMargin +", bottom: "+ bottomMargin +", left: " + leftMargin +"}) \n");
1746 wholeScript.append(" .showLegend(true) \n ");
1748 wholeScript.append(" .showLegend(false) \n ");
1751 if(nvl(subType).length() > 0 && subType.equals("area")) {
1752 if( MAXNUMDECIMALPLACES >=3 ) {
1753 wholeScript.append(" .yAxisTooltipFormat(d3.format(',.3f')) \n");
1755 wholeScript.append(" .yAxisTooltipFormat(d3.format(',."+MAXNUMDECIMALPLACES+ "f')) \n");
1758 wholeScript.append(".x (function(d) {return d.x;}) \n" +
1759 ".y (function(d) {return d.y;}) \n");
1762 //" .x(function(d) { return d[0] }) \n" +
1763 //" .y(function(d) { return d[1] }) \n" +
1764 //" .forceY("+(nvl(reportRuntime.getRangeAxisLowerLimit()).length()<=0?"0":reportRuntime.getRangeAxisLowerLimit()) +", "+ Math.ceil((MAXNUM+(MAXNUM*25/100))/100) * 100 + ") \n" + // reportRuntime.getRangeAxisUpperLimit()+") \n" +
1765 wholeScript.append(" .color(d3.scale.category10().range()); \n");
1766 if(!(nvl(subType).length() > 0 && subType.equals("area"))) {
1767 double UPPER_RANGE = 0;
1768 if(Math.ceil((MAXDOUBLENUM+(MAXDOUBLENUM*25/100))/100) * 100 >= 1) {
1769 UPPER_RANGE = Math.ceil(MAXDOUBLENUM+(MAXDOUBLENUM*25/100));
1770 } else UPPER_RANGE = 1;
1772 wholeScript.append(" chart.lines1.forceY(["+(nvl(reportRuntime.getRangeAxisLowerLimit()).length()<=0?"0":reportRuntime.getRangeAxisLowerLimit()) +", "+ (nvl(reportRuntime.getRangeAxisUpperLimit()).length()<=0?UPPER_RANGE:reportRuntime.getRangeAxisUpperLimit()) + "]); \n" +
1773 " chart.lines2.forceY([0,1]); \n");
1775 wholeScript.append(" chart.xAxis\n");
1776 if(reportRuntime.isShowXaxisLabel()) {
1777 // X axis label is commented for time-being. This should be derived from request parameter.
1778 //" .axisLabel('" + legendColumnName + "') \n" +
1779 wholeScript.append(" .axisLabel('" + legendColumnName + "') \n");
1781 wholeScript.append(" .axisLabel('') \n");
1783 if(reportRuntime.isAddXAxisTickers()) {
1784 wholeScript.append(" .tickValues(["+ dateStrBuf.toString()+ "])\n ");
1786 //wholeScript.append(" .tickValues([])\n ");
1789 wholeScript.append(" .staggerLabels(true) \n");
1791 wholeScript.append(" .staggerLabels(false) \n");
1794 wholeScript.append(" .showMaxMin(true) \n ");
1796 wholeScript.append(" .showMaxMin(false) \n ");
1799 if(nvl(rotateLabels).length()>0) {
1800 wholeScript.append(" .rotateLabels("+ rotateLabels+ ") \n ");
1802 wholeScript.append(" .rotateLabels(\"0\") \n ");
1805 wholeScript.append(" .tickFormat(function(d) { \n");
1806 if(formatFlag==DAYFLAG)
1807 wholeScript.append(" return d3.time.format('%m/%d/%Y')(new Date(d)) }); \n");
1808 else if(formatFlag==HOURFLAG)
1809 wholeScript.append(" return d3.time.format('%x %H')(new Date(d)) }); \n");
1810 else if(formatFlag==MINFLAG)
1811 wholeScript.append(" return d3.time.format('%x %H:%M')(new Date(d)) }); \n");
1812 else if(formatFlag==SECFLAG)
1813 wholeScript.append(" return d3.time.format('%x %X')(new Date(d)) }); \n");
1814 else if(formatFlag==MONTHFLAG)
1815 wholeScript.append(" return d3.time.format('%b %y')(new Date(d)) }); \n");
1818 wholeScript.append(" return d3.time.format('%x')(new Date(d)) }); \n");
1820 wholeScript.append(" return d; }); \n");
1821 if(nvl(chartRightAxisLabel).length() > 0) {
1822 if(nvl(subType).length() > 0 && subType.equals("area")) {
1823 wholeScript.append(" chart.yAxis\n");
1825 wholeScript.append(" chart.yAxis1\n");
1827 wholeScript.append(" .axisLabel('" + chartLeftAxisLabel + "') \n");
1828 //if(nvl(subType).length() > 0 && subType.equals("area")) {
1829 if(MAXDOUBLENUM <=5 && MAXNUMDECIMALPLACES == 0 ) MAXNUMDECIMALPLACES = 2;
1830 if( MAXNUMDECIMALPLACES >=3 ) MAXNUMDECIMALPLACES = 2;
1831 wholeScript.append(" .tickFormat(d3.format(',."+MAXNUMDECIMALPLACES+"f')); \n");
1833 wholeScript.append(" .tickFormat(d3.format(',.2f')); \n");
1835 // " .tickFormat(function (d) {return d;} ); \n");
1836 //" .tickFormat(function(d) {if (d >= 1000) return Math.round(d/1000)+\"K\"; else return d;}); \n");
1837 if(!(nvl(subType).length() > 0 && subType.equals("area"))) {
1838 wholeScript.append(" chart.yAxis2\n " +
1839 " .axisLabel('" + chartRightAxisLabel + "') \n" +
1840 " .tickFormat(d3.format(',.02f')); \n");
1841 //" .tickFormat(function(d) {if (d >= 1000) return Math.round(d/1000)+\"K\"; else return d;}); \n");
1842 //" .tickFormat(function(d) {if( d <= 1) return Math.round(d*100)+\"%\"; else return d;}); \n");
1843 // " .tickFormat(function(d) { return d;}); \n");
1848 if(nvl(subType).length() > 0 && subType.equals("area")) {
1849 wholeScript.append(" chart.yAxis\n");
1851 wholeScript.append(" chart.yAxis1\n");
1853 wholeScript.append(" .axisLabel('" + chartLeftAxisLabel + "') \n");
1854 //if(nvl(subType).length() > 0 && subType.equals("area")) {
1855 if(MAXDOUBLENUM <=5 && MAXNUMDECIMALPLACES == 0 ) MAXNUMDECIMALPLACES = 2;
1856 if( MAXNUMDECIMALPLACES >=3 ) {
1857 MAXNUMDECIMALPLACES = 2;
1859 wholeScript.append(" .tickFormat(d3.format(',."+MAXNUMDECIMALPLACES+"f')); \n");
1861 wholeScript.append(" .tickFormat(d3.format(',.2f')); \n");
1863 //" .tickFormat(function(d) {if (d >= 1000) return Math.round(d/1000)+\"K\"; else return d;}); \n");
1865 wholeScript.append(" d3.select('#chart"+reportRuntime.getReportID()+" svg') \n" +
1866 " .datum(historicalBarChart) \n" );
1868 wholeScript.append(" .transition().duration(1000) \n" );
1869 wholeScript.append(" .call(chart); \n" +
1870 "nv.utils.windowResize(chart.update); \n" +
1871 "return chart; \n" +
1874 wholeScript.append("function redraw() { \n");
1875 //wholeScript.append(" nv.utils.windowResize(chart.update); \n");
1876 wholeScript.append(" d3.select('#chart"+reportRuntime.getReportID()+" svg') \n") ;
1877 wholeScript.append(" .datum(historicalBarChart) \n");
1878 wholeScript.append(" .transition().duration(500) \n");
1879 wholeScript.append(" .call(chart); \n");
1880 wholeScript.append("} \n");
1881 wholeScript.append("\n");
1882 wholeScript.append(" setInterval(function () { \n");
1883 wholeScript.append(" redraw(); \n");
1884 wholeScript.append(" }, 1500) \n");
1886 wholeScript.append("if(historicalBarChart.length <= 0 ) {\n");
1887 wholeScript.append(" document.getElementById(\"chart"+reportRuntime.getReportID()+"\").innerHTML = \"<div id='noData'><b>No Data Available</b></div>\";\n");
1888 wholeScript.append(" document.getElementById(\"chart"+reportRuntime.getReportID()+"\").className=\"nodatadiv\";\n");
1889 wholeScript.append(" document.getElementById(\"nodata\").className=\"nodatainner\";\n");
1890 wholeScript.append("}\n");
1892 wholeScript.append("</script> </body> </html> \n");
1894 } else if (chartType.equals(AppConstants.GT_PIE) || chartType.equals(AppConstants.GT_PIE_3D)) {
1895 wholeScript.append("<!DOCTYPE html>\n");
1896 wholeScript.append("<html>\n");
1897 wholeScript.append("<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF8\">\n");
1898 wholeScript.append("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n");
1899 wholeScript.append("<link href=\""+ AppUtils.getBaseFolderURL() +"d3/css/nv.d3.css\" rel=\"stylesheet\" type=\"text/css\">\n");
1900 wholeScript.append("<style>\n " +
1902 " overflow-y:scroll; \n" +
1905 " font: 12px sans-serif; \n" +
1907 " tr.z-row-over > td.z-row-inner, tr.z-row-over > .z-cell {" +
1908 " background-color: rgb(255, 255, 255); "+
1910 " svg { display: block; } " +
1911 " #chart"+reportRuntime.getReportID()+" svg { \n" +
1912 " height: "+ (nvl(height).length()>0?(height.endsWith("px")?height:height+"px"):"420px") + "; \n" +
1913 " width: "+ (nvl(width).length()>0?(width.endsWith("px")?width:width+"px"):"700px") + "; \n" +
1914 " min-width: 100px; \n" +
1915 " min-height: 100px; \n" +
1918 wholeScript.append("<body> \n");
1921 wholeScript.append("<div align=\"center\"><H3>" + title +"</H3></div>");
1923 wholeScript.append("<div id=\"chart"+reportRuntime.getReportID()+"\"><svg></svg></div>");
1924 //"<svg id=\"test2\"></svg>\n");
1926 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/d3.v3.min.js\"></script>\n");
1927 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/nv.d3.min.js\"></script> \n");
1928 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/models/legend.js\"></script> \n");
1929 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/models/pie.js\"></script> \n");
1930 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/models/pieChart.js\"></script> \n");
1931 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/utils.js\"></script> \n");
1932 wholeScript.append("<script> \n");
1934 wholeScript.append("historicalBarChart = [ \n");
1940 TreeSet<String> colorList = new TreeSet<String>();
1941 for (int i = 0; i < ds.getRowCount(); i++) {
1944 VALUE = Double.parseDouble(ds.getString(i, 2));
1945 TOTAL = TOTAL+VALUE;
1946 } catch (NumberFormatException ex) {
1949 KEY = ds.getString(i, 0);
1951 if(ds.getString(i, "chart_color")!=null) {
1952 colorList.add(KEY+"|"+ds.getString(i, "chart_color"));
1954 } catch (ArrayIndexOutOfBoundsException ex) {
1955 //System.out.println("No Chart Color");
1957 wholeScript.append("{ \""+ "key" +"\":\""+ KEY+"\", \""+ "y" +"\":"+VALUE+"}, \n");
1960 StringBuffer color = new StringBuffer("");
1961 if(colorList.size()>0) {
1962 SortedSet<String> s = Collections.synchronizedSortedSet(colorList);
1963 Object[] colorElements = (Object[]) s.toArray();
1965 String element = "";
1967 for (int i = 0; i < colorElements.length; i++) {
1968 element = ((String)colorElements[i]);
1969 color.append("'"+element.substring(element.lastIndexOf("|")+1)+"',");
1971 color.deleteCharAt(color.length()-1);
1974 wholeScript.append("];\n");
1977 wholeScript.append("var chart; \n");
1978 wholeScript.append("nv.addGraph(function() { \n" +
1979 " var width1= 700, height1=720; \n" +
1980 " chart = nv.models.pieChart() \n" +
1981 " .margin({top: "+ topMargin +", right: "+ rightMargin +", bottom: "+ bottomMargin +", left: " + leftMargin +"}) \n" +
1983 //" .x(function(d) { return d.key +\" \"+ Math.round(d.y/"+TOTAL+" *100) + \"%\" }) \n" +
1984 " .x(function(d) { return d.key }) \n" +
1985 " .y(function(d) { return d.y }) \n");
1986 if(colorList.size()>0) {
1987 wholeScript.append(" .color(["+ color.toString() + "] ) \n");
1989 //wholeScript.append(" .values(function(d) { return d }) \n");
1990 //" .color(d3.scale.category10().range()); \n" +
1992 wholeScript.append(" chart.showLegend(true);\n ");
1994 wholeScript.append(" chart.showLegend(false);\n ");
1997 //wholeScript.append("chart.showLegend(false);\n" +
1998 //" .width(width1) \n" +
1999 //" .height(height1); \n" +
2000 wholeScript.append(" d3.select('#chart"+reportRuntime.getReportID()+" svg') \n" +
2001 " .datum(historicalBarChart) \n");
2003 wholeScript.append(" .transition().duration(1200) \n" );
2004 /* " .attr(\"width\", width1) \n" +
2005 " .attr(\"height\", height1) \n" +
2006 */ wholeScript.append(" .call(chart); \n" +
2007 " nv.utils.windowResize(chart.update);\n"+
2008 "return chart; \n" +
2011 wholeScript.append("function redraw() { \n");
2012 //wholeScript.append(" nv.utils.windowResize(chart.update); \n");
2013 wholeScript.append(" d3.select('#chart"+reportRuntime.getReportID()+" svg') \n") ;
2014 wholeScript.append(" .datum(historicalBarChart) \n");
2015 wholeScript.append(" .transition().duration(500) \n");
2016 wholeScript.append(" .call(chart); \n");
2017 wholeScript.append("} \n");
2018 wholeScript.append("\n");
2019 wholeScript.append(" setInterval(function () { \n");
2020 wholeScript.append(" redraw(); \n");
2021 wholeScript.append(" }, 1500) \n");
2025 wholeScript.append("if(historicalBarChart.length <= 0 ) {\n");
2026 wholeScript.append(" document.getElementById(\"chart"+reportRuntime.getReportID()+"\").innerHTML = \"<div id='noData'><b>No Data Available</b></div>\";\n");
2027 wholeScript.append(" document.getElementById(\"chart"+reportRuntime.getReportID()+"\").className=\"nodatadiv\";\n");
2028 wholeScript.append(" document.getElementById(\"nodata\").className=\"nodatainner\";\n");
2029 wholeScript.append("}\n");
2031 wholeScript.append("</script> </body> </html> \n");
2033 } else if (chartType.equals(AppConstants.GT_ANNOTATION_CHART) || chartType.equals(AppConstants.GT_FLEX_TIME_CHARTS)) {
2035 boolean timeCharts = chartType.equals(AppConstants.GT_FLEX_TIME_CHARTS);
2037 String dateStr = null;
2038 java.util.Date date = null;
2040 final int YEARFLAG = 1;
2041 final int MONTHFLAG = 2;
2042 final int DAYFLAG = 3;
2043 final int HOURFLAG = 4;
2044 final int MINFLAG = 5;
2045 final int SECFLAG = 6;
2046 final int MILLISECFLAG = 7;
2047 final int DAYOFTHEWEEKFLAG = 8;
2048 final int FLAGDATE = 9;
2056 double YAXISDOUBLENUM = 0.0;
2057 double MAXDOUBLENUM = 0.0;
2058 int MAXNUMDECIMALPLACES = 0;
2062 TreeSet<String> dateStrList = new TreeSet<String>();
2063 // added to store all date elements
2064 SortedSet<String> sortSet = new TreeSet<String>();
2068 boolean hasCategoryAxis = reportRuntime.hasSeriesColumn();
2069 flag = hasCategoryAxis?1:0;
2072 String anomalyText = "";
2074 StringBuffer dataStrBuf = new StringBuffer("");
2075 StringBuffer annotationsStrBuf = new StringBuffer("");
2077 String xAxisLabel = (reportRuntime.getChartLegendColumn()!=null)?reportRuntime.getChartLegendColumn().getDisplayName():"";
2079 //finding actual string
2080 String actualText = "";
2081 DataColumnType dct = null;
2082 for (Iterator iter = l.iterator(); iter.hasNext();) {
2083 dct = (DataColumnType) iter.next();
2084 if((dct.getChartSeq()!=null && dct.getChartSeq() >=0) && !AppUtils.nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND)) {
2085 //if(AppUtils.nvl(dct.getDisplayName()).toLowerCase().contains("actual")) {
2086 actualText = dct.getDisplayName();
2093 int columnIndex = 1;
2094 ArrayList columnNames = new ArrayList();
2095 ArrayList columnValues = new ArrayList();
2097 String columnName = "";
2098 String columnValue = "";
2101 StringBuffer seriesBuffer = new StringBuffer("");
2103 for (int i = 0; i < ds.getRowCount(); i++) {
2104 columnNames = new ArrayList();
2105 columnValues = new ArrayList();
2110 dateStr = ds.getString(i, 0);
2111 date = getDateFromDateStr(dateStr);
2112 if(date.getTime() > maxDate )
2113 maxDate = date.getTime();
2115 formatFlag = getFlagFromDateStr(dateStr);
2118 for (;columnIndex<ds.getColumnCount();columnIndex++) {
2119 columnName = ds.getColumnName(columnIndex);
2120 if(!timeCharts && !columnName.toLowerCase().equals("anomaly_text")) {
2121 columnNames.add(columnName);
2122 columnValues.add(AppUtils.nvls(ds.getString(i, columnIndex), "null"));
2123 } else if (timeCharts) {
2124 columnNames.add(columnName);
2125 columnValues.add(AppUtils.nvls(ds.getString(i, columnIndex), "null"));
2128 /* actual = ds.getString(i, "actual");
2129 //forecast = ds.getString(i, "forecast");
2130 upperBound = ds.getString(i, "upperBound");
2131 lowerBound = ds.getString(i, "lowerBound");
2134 anomalyText = ds.getString(i, "anomaly_text");
2135 //dataStrBuf.append(" [new Date(moment(\""+dateStr+"\")),"+ actual /*+","+ forecast*/+","+ lowerBound +","+ upperBound +"],\n");
2136 dataStrBuf.append(" [new Date(moment(\""+dateStr+"\"))");
2137 for(int c=0; c< columnNames.size(); c++ ) {
2138 columnName = (String) columnNames.get(c);
2139 columnValue = (String) columnValues.get(c);
2140 for (Iterator iter1 = l.iterator(); iter1.hasNext();) {
2141 dct = (DataColumnType) iter1.next();
2142 if((dct.getChartSeq()!=null && dct.getChartSeq() >=0) && !AppUtils.nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND)) {
2143 if((!timeCharts && !AppUtils.nvl(dct.getColId()).toLowerCase().equals("anomaly_text")) && AppUtils.nvl(dct.getColId()).toLowerCase().equals(columnName.toLowerCase())) {
2144 dataStrBuf.append(","+columnValue);
2146 } else if(timeCharts && AppUtils.nvl(dct.getColId()).toLowerCase().equals(columnName.toLowerCase())){
2147 dataStrBuf.append(","+columnValue);
2154 dataStrBuf.append("],\n");
2156 if(AppUtils.nvl(anomalyText).length()>0) {
2158 annotationsStrBuf.append("anns.push( {\n");
2159 annotationsStrBuf.append(" series: '"+actualText+"',\n");
2160 annotationsStrBuf.append(" x: moment(\""+dateStr+"\"),\n");
2161 annotationsStrBuf.append(" shortText: '"+ IntToLetter(anomalyRec).toUpperCase() +"',\n");
2162 annotationsStrBuf.append(" text: '"+ anomalyText + "'\n");
2163 annotationsStrBuf.append("});\n");
2171 //anomalyRec = anomalyRec - 1;
2173 minDate = maxDate - (new Long(reportRuntime.getZoomIn()).longValue()*60*60*1000);
2174 System.out.println(new java.util.Date(maxDate) + " " + new java.util.Date(minDate) + " " + reportRuntime.getZoomIn());
2175 if(dataStrBuf.lastIndexOf(",")!= -1)
2176 dataStrBuf.deleteCharAt(dataStrBuf.lastIndexOf(","));
2178 wholeScript = new StringBuffer("");
2179 wholeScript.append("<!DOCTYPE html>\n");
2180 wholeScript.append("<html>\n");
2181 wholeScript.append(" <head>\n");
2182 //wholeScript.append("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=EmulateIE7; IE=EmulateIE9\">\n");
2183 wholeScript.append("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n");
2184 wholeScript.append("<script type=\"text/javascript\" src=\""+ chartScriptsPath +"dy3/js/dygraph-combined.js\"></script>\n");
2185 wholeScript.append("<script type=\"text/javascript\" src=\""+ chartScriptsPath +"dy3/js/moment.min.js\"></script>\n");
2186 wholeScript.append("<script type=\"text/javascript\" src=\""+ chartScriptsPath +"dy3/js/interaction.min.js\"></script>\n");
2188 wholeScript.append("<script type=\"text/javascript\">\n");
2189 if(AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("30min")) {
2190 wholeScript.append("var click=2;\n");
2191 } else if (AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("hourly")) {
2192 wholeScript.append("var click=3;\n");
2193 } else if (AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("daily")) {
2194 wholeScript.append("var click=3;\n");
2196 wholeScript.append("var click=3;\n");
2197 //wholeScript.append(" var click=0;\n");
2198 wholeScript.append(" function downV3(event, g, context) { \n");
2199 wholeScript.append(" context.initializeMouseDown(event, g, context); \n");
2200 wholeScript.append(" if (event.altKey || event.shiftKey) { \n");
2201 wholeScript.append(" var minDate = g.xAxisRange()[0]; \n");
2202 wholeScript.append(" var maxDate = g.xAxisRange()[1]; \n");
2203 if(AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("daily")) {
2204 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60*24)) > 6) \n");
2205 wholeScript.append(" Dygraph.startZoom(event, g, context); \n");
2206 } else if(AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("hourly")) {
2207 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60)) > 6) \n");
2208 wholeScript.append(" Dygraph.startZoom(event, g, context); \n");
2209 } else if(AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("30min")) {
2210 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60*2)) > 6) \n");
2211 wholeScript.append(" Dygraph.startZoom(event, g, context); \n");
2214 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60)) > 6) \n");
2215 wholeScript.append(" Dygraph.startZoom(event, g, context); \n");
2217 if(AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("30min")) {
2218 wholeScript.append(" click=2;\n");
2219 } else if (AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("hourly")) {
2220 wholeScript.append(" click=3;\n");
2221 } else if (AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("daily")) {
2222 wholeScript.append(" click=3;\n");
2224 wholeScript.append(" click=3;\n");
2225 wholeScript.append(" } else if (event.ctrlKey) {\n");
2228 wholeScript.append(" click++;\n");
2229 wholeScript.append(" if(click == 1)\n");
2230 wholeScript.append(" zoom_custom(3600);\n");
2231 wholeScript.append(" else if(click == 2)\n");
2232 wholeScript.append(" zoom_custom(12*3600);\n");
2233 wholeScript.append(" else if(click == 3)\n");
2234 wholeScript.append(" zoom_custom(86400);\n");
2235 wholeScript.append(" else if (click == 4)\n");
2236 wholeScript.append(" zoom_custom(7*86400);\n");
2237 wholeScript.append(" else if (click == 5)\n");
2238 wholeScript.append(" zoom_custom(30*86400);\n");
2239 wholeScript.append(" else if (click == 6)\n");
2240 wholeScript.append(" zoom_custom(90*86400);\n");
2241 wholeScript.append(" else if (click == 7)\n");
2242 wholeScript.append(" zoom_custom(180*86400);\n");
2243 wholeScript.append(" else if (click == 8)\n");
2244 wholeScript.append(" zoom_custom(365*86400);\n");
2245 wholeScript.append(" else if (click == 10)\n");
2246 wholeScript.append(" zoom_custom(5*365*86400);\n");
2247 wholeScript.append(" else { \n");
2248 wholeScript.append(" reset();\n");
2249 wholeScript.append(" }\n");
2250 //wholeScript.append(" \n");
2251 wholeScript.append(" } else {\n");
2252 wholeScript.append(" Dygraph.startPan(event, g, context); \n");
2253 wholeScript.append(" } \n");
2254 wholeScript.append(" } \n");
2255 wholeScript.append("</script>\n ");
2256 wholeScript.append("<style type=\"text/css\">\n");
2257 wholeScript.append(".annotation {\n");
2258 wholeScript.append("}");
2259 wholeScript.append(".dygraph-title {\n");
2260 wholeScript.append("color: black;\n");
2261 wholeScript.append("font-weight:bold; \n");
2262 wholeScript.append("}\n");
2263 wholeScript.append(".dygraph-axis-label-x { ");
2264 wholeScript.append("-webkit-transform:rotate(-0deg);");
2265 wholeScript.append("display:block;");
2266 /*position:absolute;
2269 wholeScript.append("}\n");
2272 if(nvl(width).length() > 0) {
2274 widthInt = new Integer(width).intValue();
2275 } catch(Exception ex) {
2276 if(width.endsWith("px")) {
2278 widthInt = new Integer(width.substring(0, width.indexOf("px")));
2279 } catch (Exception ex1) {
2286 } else widthInt = 700;
2288 wholeScript.append(".dygraph-legend {\n");
2289 wholeScript.append(" left: "+(widthInt-200)+"px !important;\n");
2290 wholeScript.append(" top: 5px !important;\n");
2291 wholeScript.append("}\n");
2293 wholeScript.append(".nodatadiv {\n");
2294 wholeScript.append(" display: table-cell;\n");
2295 wholeScript.append(" width: 700px;\n");
2296 wholeScript.append(" height:370px;\n");
2297 wholeScript.append(" text-align:center;\n");
2298 wholeScript.append(" vertical-align: middle;\n");
2299 wholeScript.append("}\n");
2300 wholeScript.append(".nodatainner {\n");
2301 wholeScript.append(" padding: 10px;\n");
2302 wholeScript.append("}\n");
2304 wholeScript.append("canvas {\n");
2305 wholeScript.append(" -webkit-touch-callout: none; \n");
2306 wholeScript.append(" -webkit-user-select: none;\n");
2307 wholeScript.append(" -khtml-user-select: none;\n");
2308 wholeScript.append(" -moz-user-select: none;\n");
2309 wholeScript.append(" user-select: none;\n");
2310 wholeScript.append(" user-select: none;\n");
2311 wholeScript.append(" outline: none;\n");
2312 wholeScript.append(" -webkit-tap-highlight-color: rgba(255, 255, 255, 0); /* mobile webkit */\n");
2313 wholeScript.append("}\n");
2314 wholeScript.append("</style>\n");
2315 wholeScript.append("</head>\n");
2316 wholeScript.append("<body> \n");
2319 wholeScript.append(" <p align=\"center\"><b> " + (AppUtils.nvl(reportRuntime.getReportTitle()).length()>0?reportRuntime.getReportTitle():reportRuntime.getReportName()) + "</b></p>\n");
2321 wholeScript.append(" <table>\n");
2323 wholeScript.append(" <tr> \n ");
2324 wholeScript.append(" <td> \n ");
2325 wholeScript.append(" <div class=\"dygraph-label dygraph-title\" align=\"center\">"+title+"</div> \n");
2326 wholeScript.append(" </td> \n ");
2329 wholeScript.append(" </tr> \n ");
2331 wholeScript.append(" <tr> \n ");
2332 wholeScript.append(" <td> \n ");
2333 if(AppUtils.nvl(reportRuntime.getLegendPosition()).length()<=0 || reportRuntime.getLegendPosition().equals("top")) {
2334 wholeScript.append(" <div id=\"labelDiv"+reportRuntime.getReportID()+"\"></div>\n");
2336 wholeScript.append(" <div id=\"message"+reportRuntime.getReportID()+"\"></div> \n");
2337 wholeScript.append(" </td> \n ");
2339 wholeScript.append(" </tr> \n ");
2340 wholeScript.append(" <tr>\n");
2341 wholeScript.append(" <td>\n");
2344 if(nvl(height).length() > 0) {
2346 heightInt = new Integer(height).intValue();
2348 } catch(Exception ex) {
2349 if(height.endsWith("px")) {
2351 heightInt = new Integer(height.substring(0, height.indexOf("px")));
2353 } catch (Exception ex1) {
2360 } else heightInt = 420;
2361 if(AppUtils.nvl(reportRuntime.getLegendPosition()).length()>=0 && reportRuntime.getLegendPosition().equals("right")) {
2362 wholeScript.append(" <div id=\"div_g"+reportRuntime.getReportID()+"\" style=\"width:"+ (widthInt-250)+ "px; \n" );
2364 wholeScript.append(" <div id=\"div_g"+reportRuntime.getReportID()+"\" style=\"width:"+ (widthInt)+ "px; \n" );
2366 wholeScript.append(" height:"+ heightInt +"px;\"></div> \n");
2367 wholeScript.append(" </td>\n");
2368 if(AppUtils.nvl(reportRuntime.getLegendPosition()).length()>=0 && reportRuntime.getLegendPosition().equals("right")) {
2369 wholeScript.append(" <td valign=\"top\">\n");
2370 wholeScript.append(" <div id=\"labelDiv3716\" valign=\"top\" style=\"width:250px;height:"+ heightInt +"px;\"></div>\n");
2371 wholeScript.append(" </td>\n");
2373 wholeScript.append(" </tr>\n");
2374 if(anomalyRec > 0) {
2375 wholeScript.append(" <tr>\n");
2376 wholeScript.append(" <td>\n");
2377 wholeScript.append(" <table>\n");
2378 wholeScript.append(" <tr>\n");
2379 wholeScript.append(" <td align=\"center\"><font size=\"2px\"><B><align=\"center\">Anomaly Description</align></B></font></td>\n");
2380 wholeScript.append(" </tr>\n");
2381 wholeScript.append(" <tr>\n");
2382 wholeScript.append(" <td><div id=\"list"+reportRuntime.getReportID()+"\" style=\"width:" + widthInt + "px; height:50px;\"></div></td>\n" );
2383 wholeScript.append(" </tr>\n");
2384 wholeScript.append(" </table>\n");
2385 wholeScript.append(" </td>\n");
2386 wholeScript.append(" </tr>\n");
2388 wholeScript.append(" </table>\n");
2390 wholeScript.append(" <script type=\"text/javascript\">\n");
2391 wholeScript.append(" Dygraph.addEvent(document, \"mousewheel\", function() { lastClickedGraph = null; });\n");
2392 wholeScript.append(" Dygraph.addEvent(document, \"click\", function() { lastClickedGraph = null; });\n");
2393 wholeScript.append(" var data = []; \n");
2394 wholeScript.append(" data = [\n ");
2395 wholeScript.append( dataStrBuf.toString());
2396 wholeScript.append(" ];\n");
2397 wholeScript.append(" if(data.length > 0 ) { \n");
2398 wholeScript.append(" var orig_range = [ data[0][0].valueOf(), data[data.length - 1][0].valueOf() ];\n");
2400 wholeScript.append(" function nameAnnotation(ann) { \n");
2401 wholeScript.append(" return ann.shortText; \n");
2402 //wholeScript.append(" var m = moment(ann.x);\n");
2403 //wholeScript.append(" return \"(\" + ann.series + \", \" + m.format(\"YYYY-MM-DD HH\"); + \")\"; \n");
2404 wholeScript.append(" }\n");
2405 wholeScript.append(" anns = [];\n");
2407 wholeScript.append(" var graph_initialized = false;\n");
2408 wholeScript.append(" if(navigator.platform == 'iPad') { ");
2409 wholeScript.append(" g = new Dygraph(\n");
2410 wholeScript.append(" document.getElementById(\"div_g"+reportRuntime.getReportID()+"\"),\n");
2412 /*wholeScript.append(" [\n");
2413 wholeScript.append(dataStrBuf.toString());
2414 wholeScript.append(" ],\n");*/
2415 wholeScript.append(" data , \n");
2416 wholeScript.append(" {\n");
2421 StringBuffer labelStrBuf = new StringBuffer("");
2422 StringBuffer colorsStrBuf = new StringBuffer("");
2423 StringBuffer visibilityStrBuf = new StringBuffer("");
2424 int countChartValues = 0;
2425 for (Iterator iter = l.iterator(); iter.hasNext();) {
2426 dct = (DataColumnType) iter.next();
2427 if((dct.getChartSeq()!=null && dct.getChartSeq() >=0) || AppUtils.nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND)) {
2428 if(!AppUtils.nvl(dct.getDisplayName()).toLowerCase().equals("anomaly_text")) {
2430 labelStrBuf.append("'"+ dct.getDisplayName()+"',");
2431 if(!AppUtils.nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND))
2432 colorsStrBuf.append("'"+ AppUtils.nvl(dct.getChartColor())+"',");
2433 visibilityStrBuf.append("true,");
2437 if(labelStrBuf.indexOf(",")!=-1) {
2438 labelStrBuf.deleteCharAt(labelStrBuf.lastIndexOf(","));
2439 visibilityStrBuf.deleteCharAt(visibilityStrBuf.lastIndexOf(","));
2441 if(colorsStrBuf.indexOf(",")!=-1)
2442 colorsStrBuf.deleteCharAt(colorsStrBuf.lastIndexOf(","));
2444 //wholeScript.append("title: '" + (AppUtils.nvl(reportRuntime.getReportTitle()).length()>0?reportRuntime.getReportTitle():reportRuntime.getReportName()) + "',\n");
2445 wholeScript.append("maxNumberWidth:6,\n");
2446 wholeScript.append("xAxisHeight: 70,\n");
2447 wholeScript.append("yAxisLabelWidth: 70,\n");
2448 wholeScript.append("xAxisLabelWidth: 45,\n");
2449 wholeScript.append("axes: {\n");
2450 wholeScript.append("x: {\n");
2451 wholeScript.append(" axisLabelFormatter: function(d, gran) {\n");
2452 wholeScript.append(" var month = d.getMonth()+1;\n");
2453 wholeScript.append(" var day = d.getDate();\n");
2454 wholeScript.append(" var year = d.getFullYear();\n");
2455 wholeScript.append(" var hour = d.getHours();\n");
2456 wholeScript.append(" var minutes = d.getMinutes();\n");
2457 wholeScript.append(" var seconds = d.getSeconds();\n");
2458 wholeScript.append(" var wholeString = Dygraph.zeropad(month)+'/'+Dygraph.zeropad(day);\n");
2459 // wholeScript.append(" if(hour >= 0 && minutes > 0 && seconds > 0) {\n");
2460 //wholeScript.append(" wholeString += ' ' + Dygraph.zeropad(hour) + ':'+Dygraph.zeropad(minutes)+':'+Dygraph.zeropad(seconds);\n");
2461 //wholeScript.append(" } else if (hour >= 0 && minutes > 0 && seconds == 0) {\n");
2462 if(AppUtils.nvl(reportRuntime.getTimeAxisType()).length()==0 || AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("hourly"))
2463 wholeScript.append(" wholeString += ' ' + Dygraph.zeropad(hour) + ':'+Dygraph.zeropad(minutes);\n");
2464 //wholeScript.append(" } else if (hour >= 0 && (minutes >= 0 && seconds > 0)) {\n");
2465 //wholeScript.append(" wholeString += ' ' + Dygraph.zeropad(hour) + ':'+Dygraph.zeropad(minutes)+':'+Dygraph.zeropad(seconds);\n");
2466 //wholeScript.append(" } else if (hour >= 0) { \n");
2467 //wholeScript.append(" wholeString += ' ' + Dygraph.zeropad(hour); \n");
2468 //wholeScript.append(" } \n");
2469 wholeScript.append(" return wholeString; \n");
2470 wholeScript.append(" },\n");
2471 wholeScript.append(" ticker: function (a, b, pixels, opts, dygraph, vals) { \n ");
2472 wholeScript.append(" if(((b-a)/(1000*60*60)) <= 6) { \n");
2473 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.THIRTY_MINUTELY, opts, dygraph); \n");
2474 wholeScript.append(" } else if(((b-a)/(1000*60*60)) <= 12) { \n");
2475 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.HOURLY, opts, dygraph); \n");
2476 wholeScript.append(" } else if (((b-a)/(1000*60*60)) <= 25) \n ");
2477 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.TWO_HOURLY, opts, dygraph); \n ");
2478 wholeScript.append(" else if(((b-a)/(1000*60*60)) <= 78) \n ");
2479 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.SIX_HOURLY, opts, dygraph); \n ");
2480 wholeScript.append(" else if(((b-a)/(1000*60*60*24)) <= 12)\n");
2481 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.DAILY, opts, dygraph); \n");
2482 wholeScript.append(" else if(((b-a)/(1000*60*60*24)) <= 90) \n");
2483 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.WEEKLY, opts, dygraph); \n");
2484 wholeScript.append(" else \n");
2485 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.MONTHLY, opts, dygraph); \n");
2486 wholeScript.append(" }, \n");
2487 wholeScript.append(" valueFormatter: function(ms) { \n");
2488 wholeScript.append(" return new Date(ms).strftime(\"%m/%d/%Y %H:%M\"); \n");
2489 wholeScript.append( " }\n" );
2490 wholeScript.append(" }\n");
2491 wholeScript.append("},\n");
2492 wholeScript.append(" interactionModel : { \n");
2493 wholeScript.append(" 'mousedown' : downV4,\n");
2494 wholeScript.append(" touchstart : newDygraphTouchstart,\n");
2495 wholeScript.append(" touchend : Dygraph.defaultInteractionModel.touchend,\n");
2496 wholeScript.append(" touchmove : Dygraph.defaultInteractionModel.touchmove\n");
2497 //wholeScript.append(" 'dblclick' : dblClickV3,\n");
2498 //wholeScript.append(" 'mousewheel' : scrollV3\n");
2500 /*wholeScript.append(" 'mousedown' : downV3,\n");
2501 wholeScript.append(" 'mousemove' : moveV3,\n");
2502 wholeScript.append(" 'mouseup' : upV3,\n");
2503 wholeScript.append(" 'click' : clickV3,\n");
2504 wholeScript.append(" 'dblclick' : dblClickV3,\n");
2505 wholeScript.append(" 'mousewheel' : scrollV3\n");*/
2506 wholeScript.append("},\n");
2507 /*wholeScript.append(" zoomCallback: function(minDate, maxDate, yRanges) { \n");
2508 if(AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("daily")) {
2509 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60*24)) < 6) { \n");
2510 wholeScript.append(" maxDate = new Date(minDate).setMinutes(6*24*60);\n");
2511 wholeScript.append(" g.updateOptions({\n");
2512 wholeScript.append(" interactionModel: {},\n");
2513 wholeScript.append(" dateWindow: [minDate, maxDate]\n");
2514 wholeScript.append(" });\n");
2515 } else if (AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("hourly")) {
2516 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60)) <= 6) { \n");
2517 wholeScript.append(" maxDate = new Date(minDate).setMinutes(360);\n");
2518 wholeScript.append(" g.updateOptions({\n");
2519 wholeScript.append(" interactionModel: {},\n");
2520 wholeScript.append(" dateWindow: [minDate, maxDate]\n");
2521 wholeScript.append(" });\n");
2522 } else if (AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("30min")) {
2523 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60)) <= 3) { \n");
2524 wholeScript.append(" maxDate = new Date(minDate).setMinutes(180);\n");
2525 wholeScript.append(" g.updateOptions({\n");
2526 wholeScript.append(" interactionModel: {},\n");
2527 wholeScript.append(" dateWindow: [minDate, maxDate]\n");
2528 wholeScript.append(" });\n");
2529 } else if (AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("weekly")) {
2530 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60*24)) < 7) { \n");
2531 wholeScript.append(" maxDate = new Date(minDate).setMinutes(7*24*60);\n");
2532 wholeScript.append(" g.updateOptions({\n");
2533 wholeScript.append(" interactionModel: {},\n");
2534 wholeScript.append(" dateWindow: [minDate, maxDate]\n");
2535 wholeScript.append(" });\n");
2537 wholeScript.append(" } else {\n");
2538 wholeScript.append(" g.updateOptions({\n");
2539 wholeScript.append(" interactionModel : {\n");
2540 wholeScript.append(" 'mousedown' : downV3,\n");
2541 wholeScript.append(" 'mousemove' : moveV3,\n");
2542 wholeScript.append(" 'mouseup' : upV3,\n");
2543 wholeScript.append(" 'click' : clickV3,\n");
2544 wholeScript.append(" 'dblclick' : dblClickV3,\n");
2545 wholeScript.append(" 'mousewheel' : scrollV3\n");
2546 wholeScript.append(" }\n");
2547 wholeScript.append(" });\n");
2548 wholeScript.append(" } \n");
2549 wholeScript.append(" } ,\n");*/
2550 wholeScript.append("dateWindow: ["+minDate+", "+maxDate+"],\n");
2551 wholeScript.append("labels: ["+ labelStrBuf +"],\n");
2552 wholeScript.append("labelsDiv: \"labelDiv"+reportRuntime.getReportID()+"\",\n");
2553 wholeScript.append("labelsShowZeroValues: true,\n");
2554 if(AppUtils.nvl(reportRuntime.getLegendPosition()).length()>=0 && reportRuntime.getLegendPosition().equals("right")) {
2555 wholeScript.append("labelsSeparateLines: true,\n");
2557 wholeScript.append("labelsDivWidth: 200,\n");
2559 wholeScript.append("animatedZooms: true,\n");
2560 wholeScript.append("strokeWidth: 3.0,\n");
2561 wholeScript.append("strokeBorderWidth: 2.0,\n");
2562 /*wholeScript.append(" labelsDivStyles: { \n");
2563 wholeScript.append(" 'backgroundColor': 'rgba(200, 200, 255, 0.75)',\n");
2564 wholeScript.append(" 'padding': '4px',\n");
2565 wholeScript.append(" 'border': '1px solid black',\n");
2566 wholeScript.append(" 'borderRadius': '10px',\n");
2567 wholeScript.append(" 'boxShadow': '4px 4px 4px #888',\n");
2568 wholeScript.append(" 'width': '50px'\n");
2569 wholeScript.append("}, \n");
2571 wholeScript.append("visibility: ["+ visibilityStrBuf +"],\n");
2572 if(colorsStrBuf.length() > 0 && colorsStrBuf.length()>=(countChartValues*3+5))
2573 wholeScript.append("colors: ["+ colorsStrBuf +"],\n");
2575 wholeScript.append(" legend: 'always', \n");
2577 wholeScript.append(" ylabel: '"+ chartLeftAxisLabel +"' , \n");
2580 wholeScript.append(" xlabel: '"+ xAxisLabel +"' , \n");
2583 wholeScript.append(" drawPoints: true, \n");
2586 wholeScript.append(" stackedGraph: false, \n");
2589 for (Iterator iter = l.iterator(); iter.hasNext();) {
2590 dct = (DataColumnType) iter.next();
2591 if(!(nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND))) {
2592 if(!AppUtils.nvl(dct.getDisplayName()).toLowerCase().equals("anomaly_text")) {
2593 if(dct.getChartSeq()!=null && dct.getChartSeq() >=0) {
2594 wholeScript.append(" '"+ dct.getDisplayName() + "': {\n");
2595 if(AppUtils.nvl(dct.getChartLineType()).length()>0)
2596 wholeScript.append(" strokePattern: Dygraph.DASHED_LINE,\n");
2597 if(dct.isIsRangeAxisFilled()!=null && dct.isIsRangeAxisFilled().booleanValue()) {
2598 wholeScript.append(" fillGraph: true\n");
2600 wholeScript.append(" },\n");
2607 wholeScript.append(" 'Forecast': {\n");
2610 wholeScript.append(" strokePattern: Dygraph.DASHED_LINE,\n");
2613 wholeScript.append(" fillGraph: true\n");
2615 // close each labels
2616 wholeScript.append(" }\n");
2619 if(anomalyRec > 0) {
2620 wholeScript.append(" drawCallback: function(g, is_initial) { \n");
2621 wholeScript.append(" if (is_initial) { \n");
2622 wholeScript.append(" graph_initialized = true; \n");
2623 wholeScript.append(" if (anns.length > 0) { \n");
2624 wholeScript.append(" g.setAnnotations(anns); \n");
2625 wholeScript.append(" }\n");
2626 wholeScript.append(" }\n");
2628 wholeScript.append(" var anns1 = g.annotations();\n");
2629 //wholeScript.append(" var html = \"\";\n");
2630 wholeScript.append(" var html = \"<select id='x' size='1' style='width: "+ widthInt +"px; font-family : courier; font-size:8pt; font-weight:bold;'>\";\n");
2631 wholeScript.append(" for (var i = anns1.length-1; i >= 0 ; i--) {\n");
2632 wholeScript.append(" var name = nameAnnotation(anns1[i]);\n");
2633 //wholeScript.append(" html += \"<span id='\" + name + \"'>\"\n");
2634 wholeScript.append(" if(i==anns1.length-1)\n");
2635 wholeScript.append(" html += \"<option value='\" + name + \"' selected ><font size=1>\" \n");
2636 wholeScript.append(" else \n");
2637 wholeScript.append(" html += \"<option value='\" + name + \"'><font size=1>\" \n");
2638 wholeScript.append(" html += name \n");
2639 //wholeScript.append(" html += name + \": \" + (anns1[i].shortText || '(icon)')\n");
2640 //wholeScript.append(" html += \" -> \" + anns1[i].text + \"</span><br/>\";\n");
2641 wholeScript.append(" html += \" : \" + anns1[i].text + \"</font></option>\";\n");
2642 wholeScript.append(" }\n");
2643 wholeScript.append(" html += \"</select>\" \n");
2644 wholeScript.append(" document.getElementById(\"list"+reportRuntime.getReportID()+"\").innerHTML = html;\n");
2645 wholeScript.append(" }\n");
2648 wholeScript.append(" }\n");
2649 wholeScript.append(" )\n");
2652 wholeScript.append(annotationsStrBuf.toString());
2654 wholeScript.append(" if (graph_initialized) {\n");
2655 wholeScript.append(" g.setAnnotations(anns);\n");
2656 wholeScript.append(" } \n");
2657 //upate handler script
2659 wholeScript.append(" var saveBg = '';\n");
2660 wholeScript.append(" var num = 0;\n");
2661 wholeScript.append(" g.updateOptions( {\n");
2662 wholeScript.append(" annotationMouseOverHandler: function(ann) { \n");
2663 //wholeScript.append(" document.getElementById(nameAnnotation(ann)).style.fontWeight = 'bold';\n");
2664 //wholeScript.append(" saveBg = ann.div.style.backgroundColor;\n");
2665 //wholeScript.append(" ann.div.style.backgroundColor = '#ddd';\n");
2666 wholeScript.append(" var selectobject = document.getElementById(\"x\");\n");
2667 wholeScript.append(" for(var i=0; i<selectobject.length;i++) {\n ");
2668 wholeScript.append(" if(selectobject.options[i].value == nameAnnotation(ann)) {\n ");
2669 wholeScript.append(" selectobject.options[i].selected = true; \n ");
2670 wholeScript.append(" } ");
2671 wholeScript.append(" } ");
2673 wholeScript.append(" },\n");
2674 wholeScript.append(" annotationMouseOutHandler: function(ann) {\n");
2675 wholeScript.append(" document.getElementById(nameAnnotation(ann)).style.fontWeight = 'normal';\n");
2676 wholeScript.append(" ann.div.style.backgroundColor = saveBg;\n");
2677 //wholeScript.append(" var selectobject = document.getElementById(\"x\");\n");
2678 //wholeScript.append(" for(var i=0; i<selectobject.length;i++) {\n ");
2679 //wholeScript.append(" if(selectobject.options[i].value == nameAnnotation(ann)) {\n ");
2680 //wholeScript.append(" selectobject.options[i].selected = false; \n ");
2681 //wholeScript.append(" } ");
2682 //wholeScript.append(" } ");
2684 wholeScript.append(" }\n");
2686 wholeScript.append(" });\n");
2689 wholeScript.append("} else { \n");
2691 wholeScript.append(" g = new Dygraph(\n");
2692 wholeScript.append(" document.getElementById(\"div_g"+reportRuntime.getReportID()+"\"),\n");
2694 /*wholeScript.append(" [\n");
2695 wholeScript.append(dataStrBuf.toString());
2696 wholeScript.append(" ],\n");*/
2697 wholeScript.append(" data , \n");
2698 wholeScript.append(" {\n");
2703 labelStrBuf = new StringBuffer("");
2704 colorsStrBuf = new StringBuffer("");
2705 visibilityStrBuf = new StringBuffer("");
2706 countChartValues = 0;
2707 for (Iterator iter = l.iterator(); iter.hasNext();) {
2708 dct = (DataColumnType) iter.next();
2709 if((dct.getChartSeq()!=null && dct.getChartSeq() >=0) || AppUtils.nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND)) {
2710 if(!AppUtils.nvl(dct.getDisplayName()).toLowerCase().equals("anomaly_text")) {
2712 labelStrBuf.append("'"+ dct.getDisplayName()+"',");
2713 if(!AppUtils.nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND))
2714 colorsStrBuf.append("'"+ AppUtils.nvl(dct.getChartColor())+"',");
2715 visibilityStrBuf.append("true,");
2719 if(labelStrBuf.indexOf(",")!=-1) {
2720 labelStrBuf.deleteCharAt(labelStrBuf.lastIndexOf(","));
2721 visibilityStrBuf.deleteCharAt(visibilityStrBuf.lastIndexOf(","));
2723 if(colorsStrBuf.indexOf(",")!=-1)
2724 colorsStrBuf.deleteCharAt(colorsStrBuf.lastIndexOf(","));
2726 //wholeScript.append("title: '" + (AppUtils.nvl(reportRuntime.getReportTitle()).length()>0?reportRuntime.getReportTitle():reportRuntime.getReportName()) + "',\n");
2727 wholeScript.append("maxNumberWidth:6,\n");
2728 wholeScript.append("xAxisHeight: 70,\n");
2729 wholeScript.append("yAxisLabelWidth: 70,\n");
2730 wholeScript.append("xAxisLabelWidth: 45,\n");
2731 wholeScript.append("axes: {\n");
2732 wholeScript.append("x: {\n");
2733 wholeScript.append(" axisLabelFormatter: function(d, gran) {\n");
2734 wholeScript.append(" var month = d.getMonth()+1;\n");
2735 wholeScript.append(" var day = d.getDate();\n");
2736 wholeScript.append(" var year = d.getFullYear();\n");
2737 wholeScript.append(" var hour = d.getHours();\n");
2738 wholeScript.append(" var minutes = d.getMinutes();\n");
2739 wholeScript.append(" var seconds = d.getSeconds();\n");
2740 wholeScript.append(" var wholeString = Dygraph.zeropad(month)+'/'+Dygraph.zeropad(day);\n");
2741 // wholeScript.append(" if(hour >= 0 && minutes > 0 && seconds > 0) {\n");
2742 //wholeScript.append(" wholeString += ' ' + Dygraph.zeropad(hour) + ':'+Dygraph.zeropad(minutes)+':'+Dygraph.zeropad(seconds);\n");
2743 //wholeScript.append(" } else if (hour >= 0 && minutes > 0 && seconds == 0) {\n");
2744 if(AppUtils.nvl(reportRuntime.getTimeAxisType()).length()==0 || AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("hourly"))
2745 wholeScript.append(" wholeString += ' ' + Dygraph.zeropad(hour) + ':'+Dygraph.zeropad(minutes);\n");
2746 //wholeScript.append(" } else if (hour >= 0 && (minutes >= 0 && seconds > 0)) {\n");
2747 //wholeScript.append(" wholeString += ' ' + Dygraph.zeropad(hour) + ':'+Dygraph.zeropad(minutes)+':'+Dygraph.zeropad(seconds);\n");
2748 //wholeScript.append(" } else if (hour >= 0) { \n");
2749 //wholeScript.append(" wholeString += ' ' + Dygraph.zeropad(hour); \n");
2750 //wholeScript.append(" } \n");
2751 wholeScript.append(" return wholeString; \n");
2752 wholeScript.append(" },\n");
2753 wholeScript.append(" ticker: function (a, b, pixels, opts, dygraph, vals) { \n ");
2754 wholeScript.append(" if(((b-a)/(1000*60*60)) <= 6) { \n");
2755 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.THIRTY_MINUTELY, opts, dygraph); \n");
2756 wholeScript.append(" } else if(((b-a)/(1000*60*60)) <= 12) { \n");
2757 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.HOURLY, opts, dygraph); \n");
2758 wholeScript.append(" } else if (((b-a)/(1000*60*60)) <= 25) \n ");
2759 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.TWO_HOURLY, opts, dygraph); \n ");
2760 wholeScript.append(" else if(((b-a)/(1000*60*60)) <= 78) \n ");
2761 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.SIX_HOURLY, opts, dygraph); \n ");
2762 wholeScript.append(" else if(((b-a)/(1000*60*60*24)) <= 12)\n");
2763 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.DAILY, opts, dygraph); \n");
2764 wholeScript.append(" else if(((b-a)/(1000*60*60*24)) <= 90) \n");
2765 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.WEEKLY, opts, dygraph); \n");
2766 wholeScript.append(" else \n");
2767 wholeScript.append(" return Dygraph.getDateAxis(a, b, Dygraph.MONTHLY, opts, dygraph); \n");
2768 wholeScript.append(" }, \n");
2769 wholeScript.append(" valueFormatter: function(ms) { \n");
2770 wholeScript.append(" return new Date(ms).strftime(\"%m/%d/%Y %H:%M\"); \n");
2771 wholeScript.append( " }\n" );
2772 wholeScript.append(" }\n");
2773 wholeScript.append("},\n");
2774 wholeScript.append(" interactionModel : { \n");
2776 wholeScript.append(" 'mousedown' : downV3,\n");
2777 wholeScript.append(" 'mousemove' : moveV3,\n");
2778 wholeScript.append(" 'mouseup' : upV3,\n");
2779 wholeScript.append(" 'click' : clickV3,\n");
2780 wholeScript.append(" 'dblclick' : dblClickV3,\n");
2781 wholeScript.append(" 'mousewheel' : scrollV3\n");
2782 wholeScript.append("},\n");
2783 wholeScript.append(" zoomCallback: function(minDate, maxDate, yRanges) { \n");
2784 if(AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("daily")) {
2785 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60*24)) < 6) { \n");
2786 wholeScript.append(" maxDate = new Date(minDate).setMinutes(6*24*60);\n");
2787 wholeScript.append(" g.updateOptions({\n");
2788 wholeScript.append(" interactionModel: {},\n");
2789 wholeScript.append(" dateWindow: [minDate, maxDate]\n");
2790 wholeScript.append(" });\n");
2791 } else if (AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("hourly")) {
2792 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60)) <= 6) { \n");
2793 wholeScript.append(" maxDate = new Date(minDate).setMinutes(360);\n");
2794 wholeScript.append(" g.updateOptions({\n");
2795 wholeScript.append(" interactionModel: {},\n");
2796 wholeScript.append(" dateWindow: [minDate, maxDate]\n");
2797 wholeScript.append(" });\n");
2798 } else if (AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("30min")) {
2799 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60)) <= 3) { \n");
2800 wholeScript.append(" maxDate = new Date(minDate).setMinutes(180);\n");
2801 wholeScript.append(" g.updateOptions({\n");
2802 wholeScript.append(" interactionModel: {},\n");
2803 wholeScript.append(" dateWindow: [minDate, maxDate]\n");
2804 wholeScript.append(" });\n");
2805 } else if (AppUtils.nvl(reportRuntime.getTimeAxisType()).equals("weekly")) {
2806 wholeScript.append(" if(((maxDate-minDate)/(1000*60*60*24)) < 7) { \n");
2807 wholeScript.append(" maxDate = new Date(minDate).setMinutes(7*24*60);\n");
2808 wholeScript.append(" g.updateOptions({\n");
2809 wholeScript.append(" interactionModel: {},\n");
2810 wholeScript.append(" dateWindow: [minDate, maxDate]\n");
2811 wholeScript.append(" });\n");
2813 wholeScript.append(" } else {\n");
2814 wholeScript.append(" g.updateOptions({\n");
2815 wholeScript.append(" interactionModel : {\n");
2816 wholeScript.append(" 'mousedown' : downV3,\n");
2817 wholeScript.append(" 'mousemove' : moveV3,\n");
2818 wholeScript.append(" 'mouseup' : upV3,\n");
2819 wholeScript.append(" 'click' : clickV3,\n");
2820 wholeScript.append(" 'dblclick' : dblClickV3,\n");
2821 wholeScript.append(" 'mousewheel' : scrollV3\n");
2822 wholeScript.append(" }\n");
2823 wholeScript.append(" });\n");
2824 wholeScript.append(" } \n");
2825 wholeScript.append(" } ,\n");
2826 wholeScript.append("dateWindow: ["+minDate+", "+maxDate+"],\n");
2827 wholeScript.append("labels: ["+ labelStrBuf +"],\n");
2828 wholeScript.append("labelsDiv: \"labelDiv"+reportRuntime.getReportID()+"\",\n");
2829 wholeScript.append("labelsShowZeroValues: true,\n");
2830 if(AppUtils.nvl(reportRuntime.getLegendPosition()).length()>=0 && reportRuntime.getLegendPosition().equals("right")) {
2831 wholeScript.append("labelsSeparateLines: true,\n");
2833 wholeScript.append("labelsDivWidth: 200,\n");
2836 wholeScript.append("animatedZooms: true,\n");
2837 wholeScript.append("strokeWidth: 3.0,\n");
2838 wholeScript.append("strokeBorderWidth: 2.0,\n");
2840 /*wholeScript.append(" labelsDivStyles: { \n");
2841 wholeScript.append(" 'backgroundColor': 'rgba(200, 200, 255, 0.75)',\n");
2842 wholeScript.append(" 'padding': '4px',\n");
2843 wholeScript.append(" 'border': '1px solid black',\n");
2844 wholeScript.append(" 'borderRadius': '10px',\n");
2845 wholeScript.append(" 'boxShadow': '4px 4px 4px #888',\n");
2846 wholeScript.append(" 'width': '50px'\n");
2847 wholeScript.append("}, \n");
2849 wholeScript.append("visibility: ["+ visibilityStrBuf +"],\n");
2850 if(colorsStrBuf.length() > 0 && colorsStrBuf.length()>=(countChartValues*3+5))
2851 wholeScript.append("colors: ["+ colorsStrBuf +"],\n");
2853 wholeScript.append(" legend: 'always', \n");
2855 wholeScript.append(" ylabel: '"+ chartLeftAxisLabel +"' , \n");
2858 wholeScript.append(" xlabel: '"+ xAxisLabel +"' , \n");
2862 wholeScript.append(" drawPoints: true, \n");
2865 wholeScript.append(" stackedGraph: false, \n");
2868 for (Iterator iter = l.iterator(); iter.hasNext();) {
2869 dct = (DataColumnType) iter.next();
2870 if(!(nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND))) {
2871 if(!AppUtils.nvl(dct.getDisplayName()).toLowerCase().equals("anomaly_text")) {
2872 if(dct.getChartSeq()!=null && dct.getChartSeq() >=0) {
2873 wholeScript.append(" '"+ dct.getDisplayName() + "': {\n");
2874 if(AppUtils.nvl(dct.getChartLineType()).length()>0)
2875 wholeScript.append(" strokePattern: Dygraph.DASHED_LINE,\n");
2876 if(dct.isIsRangeAxisFilled()!=null && dct.isIsRangeAxisFilled().booleanValue()) {
2877 wholeScript.append(" fillGraph: true\n");
2879 wholeScript.append(" },\n");
2886 wholeScript.append(" 'Forecast': {\n");
2889 wholeScript.append(" strokePattern: Dygraph.DASHED_LINE,\n");
2892 wholeScript.append(" fillGraph: true\n");
2894 // close each labels
2895 wholeScript.append(" }\n");
2898 if(anomalyRec > 0) {
2899 wholeScript.append(" drawCallback: function(g, is_initial) { \n");
2900 wholeScript.append(" if (is_initial) { \n");
2901 wholeScript.append(" graph_initialized = true; \n");
2902 wholeScript.append(" if (anns.length > 0) { \n");
2903 wholeScript.append(" g.setAnnotations(anns); \n");
2904 wholeScript.append(" }\n");
2905 wholeScript.append(" }\n");
2907 wholeScript.append(" var anns1 = g.annotations();\n");
2908 //wholeScript.append(" var html = \"\";\n");
2909 wholeScript.append(" var html = \"<select id='x' size='1' style='width: "+ widthInt +"px; font-family : courier; font-size:8pt; font-weight:bold;'>\";\n");
2910 wholeScript.append(" for (var i = anns1.length-1; i >= 0 ; i--) {\n");
2911 wholeScript.append(" var name = nameAnnotation(anns1[i]);\n");
2912 //wholeScript.append(" html += \"<span id='\" + name + \"'>\"\n");
2913 wholeScript.append(" if(i==anns1.length-1)\n");
2914 wholeScript.append(" html += \"<option value='\" + name + \"' selected ><font size=1>\" \n");
2915 wholeScript.append(" else \n");
2916 wholeScript.append(" html += \"<option value='\" + name + \"'><font size=1>\" \n");
2917 wholeScript.append(" html += name \n");
2918 //wholeScript.append(" html += name + \": \" + (anns1[i].shortText || '(icon)')\n");
2919 //wholeScript.append(" html += \" -> \" + anns1[i].text + \"</span><br/>\";\n");
2920 wholeScript.append(" html += \" : \" + anns1[i].text + \"</font></option>\";\n");
2921 wholeScript.append(" }\n");
2922 wholeScript.append(" html += \"</select>\" \n");
2923 wholeScript.append(" document.getElementById(\"list"+reportRuntime.getReportID()+"\").innerHTML = html;\n");
2924 wholeScript.append(" }\n");
2927 wholeScript.append(" }\n");
2928 wholeScript.append(" )\n");
2931 wholeScript.append(annotationsStrBuf.toString());
2933 wholeScript.append(" if (graph_initialized) {\n");
2934 wholeScript.append(" g.setAnnotations(anns);\n");
2935 wholeScript.append(" } \n");
2936 //upate handler script
2938 wholeScript.append(" var saveBg = '';\n");
2939 wholeScript.append(" var num = 0;\n");
2940 wholeScript.append(" g.updateOptions( {\n");
2941 wholeScript.append(" annotationMouseOverHandler: function(ann) { \n");
2942 //wholeScript.append(" document.getElementById(nameAnnotation(ann)).style.fontWeight = 'bold';\n");
2943 //wholeScript.append(" saveBg = ann.div.style.backgroundColor;\n");
2944 //wholeScript.append(" ann.div.style.backgroundColor = '#ddd';\n");
2945 wholeScript.append(" var selectobject = document.getElementById(\"x\");\n");
2946 wholeScript.append(" for(var i=0; i<selectobject.length;i++) {\n ");
2947 wholeScript.append(" if(selectobject.options[i].value == nameAnnotation(ann)) {\n ");
2948 wholeScript.append(" selectobject.options[i].selected = true; \n ");
2949 wholeScript.append(" } ");
2950 wholeScript.append(" } ");
2952 wholeScript.append(" },\n");
2953 wholeScript.append(" annotationMouseOutHandler: function(ann) {\n");
2954 //wholeScript.append(" document.getElementById(nameAnnotation(ann)).style.fontWeight = 'normal';\n");
2955 wholeScript.append(" ann.div.style.backgroundColor = saveBg;\n");
2956 //wholeScript.append(" var selectobject = document.getElementById(\"x\");\n");
2957 //wholeScript.append(" for(var i=0; i<selectobject.length;i++) {\n ");
2958 //wholeScript.append(" if(selectobject.options[i].value == nameAnnotation(ann)) {\n ");
2959 //wholeScript.append(" selectobject.options[i].selected = false; \n ");
2960 //wholeScript.append(" } ");
2961 //wholeScript.append(" } ");
2963 wholeScript.append(" }\n");
2965 wholeScript.append(" });\n");
2968 wholeScript.append("} \n");
2970 wholeScript.append("} else {\n");
2971 wholeScript.append("document.getElementById(\"message"+ reportRuntime.getReportID()+"\").display = \"none\";\n");
2972 wholeScript.append("document.getElementById(\"labelDiv"+ reportRuntime.getReportID()+"\").display=\"none\";\n");
2973 wholeScript.append("document.getElementById(\"div_g"+reportRuntime.getReportID()+"\").display=\"none\";\n");
2975 wholeScript.append("document.getElementById(\"div_g"+reportRuntime.getReportID()+"\").innerHTML = \"<div id='noData'><b>No Data Available</b></div>\";\n");
2976 wholeScript.append("document.getElementById(\"div_g"+reportRuntime.getReportID()+"\").className=\"nodatadiv\";\n");
2977 wholeScript.append("document.getElementById(\"nodata\").className=\"nodatainner\";\n");
2979 wholeScript.append("document.getElementById(\"list"+reportRuntime.getReportID()+"\").display=\"none\";\n");
2980 wholeScript.append("}\n");
2981 wholeScript.append(" </script>\n");
2982 wholeScript.append(" </body>\n");
2983 wholeScript.append("</html>");
2986 } else if (chartType.equals(AppConstants.GT_SCATTER)) {
2988 wholeScript.append("<link href=\""+ chartScriptsPath +"d3/css/nv.d3.css\" rel=\"stylesheet\" type=\"text/css\">\n");
2989 wholeScript.append("<style>\n " +
2991 " overflow-y:scroll; \n" +
2994 " font: 12px sans-serif; \n" +
2996 " tr.z-row-over > td.z-row-inner, tr.z-row-over > .z-cell {" +
2997 " background-color: rgb(255, 255, 255); "+
2999 " svg { display: block; } " +
3000 " #chart1 svg { \n" +
3001 " height: 420px; \n" +
3002 " width: 800px; \n" +
3003 " min-width: 100px; \n" +
3004 " min-height: 100px; \n" +
3008 wholeScript.append("<body> \n");
3009 wholeScript.append("<div id=\"chart1\"><svg></svg></div>");
3011 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/d3.v2.js\"></script>\n");
3012 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/nv.d3.js\"></script> \n");
3013 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/tooltip.js\"></script> \n");
3014 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/utils.js\"></script> \n");
3015 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/models/legend.js\"></script> \n");
3016 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/models/axis.js\"></script> \n");
3017 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/models/distribution.js\"></script> \n");
3018 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/models/scatter.js\"></script> \n");
3019 wholeScript.append("<script src=\""+ chartScriptsPath +"d3/js/models/scatterChart.js\"></script> \n");
3020 wholeScript.append("<script> \n");
3021 wholeScript.append("nv.addGraph(function() { \n" +
3022 " var width1=900, height1=220; \n" +
3023 " var chart = nv.models.scatterChart() \n" +
3024 " .showDistX(true) \n" +
3025 " .showDistY(true) \n" +
3026 " .useVoronoi(true) \n" +
3027 " .color(d3.scale.category10().range()); \n" +
3028 /* " .width(width1) \n" +
3029 " .height(height1); \n" +
3030 */ " chart.xAxis\n" +
3031 " .axisLabel('" +legendColumnName + "')\n" +
3032 " .tickFormat(d3.format('.02f'));\n" +
3034 " .axisLabel('" + chartLeftAxisLabel + "')\n" +
3035 " .tickFormat(d3.format('.02f'));\n" +
3036 " d3.select('#chart1 svg') \n" +
3037 " .datum(getData()) \n" );
3039 wholeScript.append(" .transition().duration(1200) \n" );
3040 /* " .attr(\"width\", width1) \n" +
3041 " .attr(\"height\", height1) \n" +
3042 */ wholeScript.append(" .call(chart); \n" +
3043 " nv.utils.windowResize(chart.update);\n"+
3044 "return chart; \n" +
3047 String dateStr = "";
3048 Object uniqueElements [] = null;
3049 TreeSet ts = new TreeSet();
3050 for (int i = 0; i < ds.getRowCount(); i++) {
3051 dateStr = ds.getString(i, 2);
3052 if(dateStr.length()>0)
3055 SortedSet s = Collections.synchronizedSortedSet(ts);
3056 uniqueElements = s.toArray();
3058 wholeScript.append(" function getData() { \n " +
3059 " var data = [];\n ");
3060 for (int i = 0; i < uniqueElements.length; i++) {
3061 wholeScript.append(" data.push( {key:'"+ uniqueElements[i]+ "', values:[]})\n");
3065 for (int i = 0; i < ds.getRowCount(); i++) {
3066 for (int k = 0; k < uniqueElements.length; k++) {
3067 if(ds.getString(i, 2).equals(uniqueElements[k])) {
3068 wholeScript.append("data["+k+"].values.push({x:"+ ds.getString(i, 1) +",y:"+ds.getString(i, 3) + ", size: Math.random() });\n");
3073 wholeScript.append("return data; } </script></body>\n");
3074 } else if (chartType.equals(AppConstants.GT_HIERARCHICAL_SUNBURST)) {
3076 StringBuffer dataStr = new StringBuffer("");
3077 StringBuffer groupBuffer = new StringBuffer("");
3078 StringBuffer s = new StringBuffer("");
3079 dataStr.append("{");
3080 dataStr.append(" \"ss4262\":{\n");
3082 String mid_old = "";
3083 String level = "-1";
3084 String level_old = "-1";
3086 for (int i = 0; i < ds.getRowCount(); i++) {
3087 mid = ds.getString(i, "mid");
3088 level = ds.getString(i, "level1");
3089 eid = ds.getString(i, "eid");
3090 if(mid.equals(mid_old)) {
3091 dataStr.append("\""+ eid +"\": 9956,\n");
3093 if(dataStr.lastIndexOf(",")!= -1)
3094 dataStr.deleteCharAt(dataStr.lastIndexOf(","));
3095 //if(Integer.parseInt(level_old)==Integer.parseInt(level))
3096 //dataStr.append("},\n");
3097 if (Integer.parseInt(level_old)<Integer.parseInt(level))
3098 dataStr.append("},\n");
3099 dataStr.append("\""+ mid +"\": { \n");
3105 if(dataStr.toString().endsWith(","))
3106 dataStr.deleteCharAt(dataStr.lastIndexOf(","));
3107 dataStr.append("}\n");
3108 dataStr.append("}\n");
3110 String formattedReportName = new HtmlStripper().stripSpecialCharacters(reportRuntime.getReportName());
3111 String formattedDate = new SimpleDateFormat("MMddyyyyHHmm").format(new java.util.Date());
3112 String filename=formattedReportName+formattedDate+user_id+".json";
3113 String filenamepath = AppUtils.getExcelTemplatePath()+"../../json/"+filename;
3114 System.out.println("filenamepath " + filenamepath);
3115 BufferedWriter out = new BufferedWriter(new FileWriter(filenamepath));
3116 out.write(dataStr.toString());
3118 request.getSession().setAttribute("jsonFileName", filename);
3119 } catch (IOException e) {
3120 e.printStackTrace();
3121 System.out.println("Exception ");
3123 } else if (chartType.equals(AppConstants.GT_HIERARCHICAL)) {
3125 StringBuffer dataStr = new StringBuffer("");
3126 StringBuffer groupBuffer = new StringBuffer("");
3127 StringBuffer s = new StringBuffer("");
3128 dataStr.append("{");
3129 dataStr.append(" \"groups\":[");
3131 for (int i = 0; i < ds.getRowCount(); i++) {
3132 if(ds.getString(i,"group_ind").equals("Y")) {
3133 groupBuffer.append(" { \"name\": \""+ ds.getString(i,"ei1") +"\" },\n");
3137 groupBuffer.deleteCharAt(groupBuffer.lastIndexOf(","));
3138 dataStr.append(groupBuffer.toString());
3139 dataStr.append("],");
3140 dataStr.append("\"nodes\":[");
3141 int rowCount = ds.getRowCount();
3142 for (int i = 0; i < ds.getRowCount(); i++) {
3143 s.append("{ \"name\": \""+ ds.getString(i,"ei1") +"\" , \"group\":"+ ds.getString(i,"groups") +", \"level\":2 }");
3144 if (i < (rowCount-1)) s.append(",");
3146 s = new StringBuffer("");
3149 dataStr.append("],");
3150 dataStr.append("\"links\":[");
3151 for (int i = 0; i < ds.getRowCount(); i++) {
3152 s.append("{ \"source\": "+ ds.getString(i,"source") +" , \"target\":"+ ds.getString(i,"target") +", \"value\":2 }");
3153 if (i < (rowCount-1)) s.append(",");
3155 s = new StringBuffer("");
3157 dataStr.append("]}");
3159 String formattedReportName = new HtmlStripper().stripSpecialCharacters(reportRuntime.getReportName());
3160 String formattedDate = new SimpleDateFormat("MMddyyyyHHmm").format(new java.util.Date());
3161 String filename=formattedReportName+formattedDate+user_id+".json";
3162 String filenamepath = AppUtils.getExcelTemplatePath()+"../../json/"+filename;
3163 System.out.println("filenamepath " + filenamepath);
3164 BufferedWriter out = new BufferedWriter(new FileWriter(filenamepath));
3165 out.write(dataStr.toString());
3167 request.getSession().setAttribute("jsonFileName", filename);
3168 } catch (IOException e) {
3169 e.printStackTrace();
3170 System.out.println("Exception ");
3177 BufferedWriter out = new BufferedWriter(new FileWriter("test.txt"));
3178 out.write(wholeScript.toString());
3180 } catch (IOException e) {
3181 e.printStackTrace();
3182 System.out.println("Exception ");
3184 return wholeScript.toString();
3187 public String nvl(String s) {
3188 return (s == null) ? "" : s;
3191 public String nvl(String s, String sDefault) {
3192 return nvl(s).equals("") ? sDefault : s;
3195 public static String nvls(String s) {
3196 return (s == null) ? "" : s;
3199 public static String nvls(String s, String sDefault) {
3200 return nvls(s).equals("") ? sDefault : s;
3203 public boolean getFlagInBoolean(String s) {
3204 return nvl(s).toUpperCase().startsWith("Y") || nvl(s).toLowerCase().equals("true");
3207 public DataSet loadChartData(String userId, HttpServletRequest request) throws RaptorException {
3208 if (nvl(getChartType()).length() == 0)
3210 //TODO: display chart function to be added.
3211 //if (!getDisplayChart())
3215 sql = generateChartSQL(userId, request);
3216 logger.debug(EELFLoggerDelegate.debugLogger, ("SQL generated " + sql));
3217 String dbInfo = reportRuntime.getDBInfo();
3218 DataSet ds = ConnectionUtils.getDataSet(sql, dbInfo);
3219 if(ds.getRowCount()<=0) {
3220 logger.debug(EELFLoggerDelegate.debugLogger, ("********************************************************************************"));
3221 logger.debug(EELFLoggerDelegate.debugLogger, (getChartType().toUpperCase()+" - " + "Report ID : " + reportRuntime.getReportID() + " DATA IS EMPTY" ));
3222 logger.debug(EELFLoggerDelegate.debugLogger, ("QUERY - " + sql));
3223 logger.debug(EELFLoggerDelegate.debugLogger, ("********************************************************************************"));
3229 public String generateChartSQL(String userId, HttpServletRequest request ) throws RaptorException {
3230 List reportCols = reportRuntime.getAllColumns();
3231 List chartValueCols = getChartValueColumnsList(AppConstants.CHART_ALL_COLUMNS, null); // parameter is 0 has this requires all columns.
3232 String reportSQL = reportRuntime.getWholeSQL();
3234 //Add order by clause
3235 Pattern re1 = Pattern.compile("(^[\r\n]*|([\\s]))[Oo][Rr][Dd][Ee][Rr](.*?[^\r\n]*)[Bb][Yy]",Pattern.DOTALL);
3236 //Pattern re1 = Pattern.compile("order(.*?[^\r\n]*)by", Pattern.DOTALL);
3237 Matcher matcher = re1.matcher(reportSQL);
3238 //Pattern re1 = Pattern.compile("(^[\r\n]*|([\\s]))[Oo][Rr][Dd][Ee][Rr][Tt](.*?[^\r\n]*)[Bb][Yy]",Pattern.DOTALL);
3239 //int startPoint = sql.length()-30;
3241 reportSQL = reportSQL + " ";
3242 reportSQL = Pattern.compile("(^[\r\n]*|([\\s]))[Ss][Ee][Ll][Ee][Cc][Tt]([\r\n]*|[\\s]*)",Pattern.DOTALL).matcher(reportSQL).replaceAll(" SELECT ");
3243 //reportSQL = Pattern.compile("(^[\r\n]*|([\\s]))[Ff][Rr][Oo][Mm]([\r\n]*|[\\s]*)",Pattern.DOTALL).matcher(reportSQL).replaceAll(" FROM ");
3244 reportSQL = Pattern.compile("(^[\r\n]*|([\\s]))[Ww][Hh][Ee][Rr][Ee]([\r\n]*|[\\s]*)",Pattern.DOTALL).matcher(reportSQL).replaceAll(" WHERE ");
3245 reportSQL = Pattern.compile("(^[\r\n]*|([\\s]))[Ww][Hh][Ee][Nn]([\r\n]*|[\\s]*)",Pattern.DOTALL).matcher(reportSQL).replaceAll(" WHEN ");
3246 reportSQL = Pattern.compile("(^[\r\n]*|([\\s]))[Aa][Nn][Dd]([\r\n]*|[\\s]*)",Pattern.DOTALL).matcher(reportSQL).replaceAll(" AND ");
3248 if(!reportRuntime.getReportType().equals(AppConstants.RT_HIVE)) {
3249 int startPoint = reportSQL.lastIndexOf(" FROM ");
3250 if(startPoint <= 0) {
3251 startPoint = reportSQL.lastIndexOf(" from ");
3253 if(startPoint <= 0) {
3254 startPoint = reportSQL.lastIndexOf("from ");
3256 if(startPoint <= 0) {
3257 startPoint = reportSQL.lastIndexOf("FROM ");
3260 if (!matcher.find(startPoint)) {
3261 reportSQL = reportSQL + " ORDER BY 1" ;
3264 reportRuntime.setWholeSQL(reportSQL);
3266 logger.debug(EELFLoggerDelegate.debugLogger, (" *************************************************************************************** "));
3267 logger.debug(EELFLoggerDelegate.debugLogger, ("WHOLE_SQL" + reportSQL));
3268 logger.debug(EELFLoggerDelegate.debugLogger, (" *************************************************************************************** "));
3270 if (reportRuntime.getFormFieldList() != null) {
3271 for (Iterator iter = reportRuntime.getFormFieldList().getFormField().iterator(); iter.hasNext();) {
3272 FormFieldType fft = (FormFieldType) iter.next();
3273 String fieldId = fft.getFieldId();
3274 String fieldDisplay = reportRuntime.getFormFieldDisplayName(fft);
3275 String formfield_value = "";
3276 formfield_value = AppUtils.getRequestNvlValue(request, fieldId);
3277 String paramValue = nvl(formfield_value);
3278 if(paramValue.length()>0) {
3279 /*sql = Utils.replaceInString(sql, "'" + fieldDisplay + "'", nvl(
3280 paramValue, "NULL"));*/
3281 reportSQL = Utils.replaceInString(reportSQL, fieldDisplay, nvl(
3282 paramValue, "NULL"));
3284 /*sql = Utils.replaceInString(sql, "'" + fieldDisplay + "'", nvl(
3285 paramValue, "NULL"));*/
3286 reportSQL = Utils.replaceInString(reportSQL, "'" + fieldDisplay + "'", nvl(
3287 paramValue, "NULL"));
3288 reportSQL = Utils.replaceInString(reportSQL, fieldDisplay , nvl(
3289 paramValue, "NULL"));
3292 logger.debug(EELFLoggerDelegate.debugLogger, ("SQL " + reportSQL));
3293 String legendCol = "1 a";
3294 // String valueCol = "1";
3295 StringBuffer groupCol = new StringBuffer();
3296 StringBuffer seriesCol = new StringBuffer();
3297 StringBuffer valueCols = new StringBuffer();
3299 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
3300 DataColumnType dc = (DataColumnType) iter.next();
3301 String colName = getColumnSelectStr(dc, request);
3302 if (nvl(dc.getColOnChart()).equals(AppConstants.GC_LEGEND))
3303 legendCol = getSelectExpr(dc, colName)+" " + dc.getColId();
3304 // if(dc.getChartSeq()>0)
3305 // valueCol = "NVL("+colName+", 0) "+dc.getColId();
3306 if ((!nvl(dc.getColOnChart()).equals(AppConstants.GC_LEGEND))
3307 && (dc.getChartSeq()!=null && dc.getChartSeq().intValue() <= 0) && dc.isGroupBreak()) {
3308 groupCol.append(", ");
3309 groupCol.append(colName + " " + dc.getColId());
3312 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
3313 DataColumnType dc = (DataColumnType) iter.next();
3314 if(dc.isChartSeries()!=null && dc.isChartSeries().booleanValue()) {
3315 //System.out.println("*****************, "+ " " +getColumnSelectStr(dc, paramValues)+ " "+ getSelectExpr(dc,getColumnSelectStr(dc, paramValues)));
3316 seriesCol.append(", "+ getSelectExpr(dc,getColumnSelectStr(dc, request))+ " " + dc.getColId());
3320 /*for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
3321 DataColumnType dc = (DataColumnType) iter.next();
3322 if(!dc.isChartSeries() && !(nvl(dc.getColOnChart()).equals(AppConstants.GC_LEGEND))) {
3323 //System.out.println("*****************, "+ " " +getColumnSelectStr(dc, paramValues)+ " "+ getSelectExpr(dc,getColumnSelectStr(dc, paramValues)));
3324 seriesCol.append(", "+ formatChartColumn(getSelectExpr(dc,getColumnSelectStr(dc, paramValues)))+ " " + dc.getColId());
3328 for (Iterator iter = chartValueCols.iterator(); iter.hasNext();) {
3329 DataColumnType dc = (DataColumnType) iter.next();
3330 String colName = getColumnSelectStr(dc, request);
3331 String paramValue = "";
3332 if(AppUtils.nvl(colName).startsWith("[")) {
3333 if (reportRuntime.getFormFieldList() != null) {
3334 for (Iterator iterC = reportRuntime.getFormFieldList().getFormField().iterator(); iterC.hasNext();) {
3335 FormFieldType fft = (FormFieldType) iterC.next();
3336 String fieldId = fft.getFieldId();
3337 String fieldDisplay = reportRuntime.getFormFieldDisplayName(fft);
3338 String formfield_value = "";
3339 if(AppUtils.nvl(fieldDisplay).equals(colName)) {
3340 formfield_value = AppUtils.getRequestNvlValue(request, fieldId);
3341 paramValue = nvl(formfield_value);
3347 seriesCol.append("," + (AppUtils.nvl(paramValue).length()>0? paramValue:"null") + " " + dc.getColId());
3349 //valueCols.append(", NVL(" + formatChartColumn(colName) + ",0) " + dc.getColId());
3350 seriesCol.append("," + (AppUtils.nvl(paramValue).length()>0? paramValue:formatChartColumn(colName)) + " " + dc.getColId());
3354 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
3355 DataColumnType dc = (DataColumnType) iter.next();
3356 String colName = dc.getDisplayName();
3357 String colValue = getColumnSelectStr(dc, request);
3358 //String colName = getColumnSelectStr(dc, formGrid);
3359 if(colName.equals(AppConstants.RI_CHART_TOTAL_COL))
3360 seriesCol.append(", " + AppConstants.RI_CHART_TOTAL_COL + " " + AppConstants.RI_CHART_TOTAL_COL );
3361 if (colName.equals(AppConstants.RI_CHART_COLOR))
3362 seriesCol.append(", " + colValue + " " + AppConstants.RI_CHART_COLOR );
3363 if(colName.equals(AppConstants.RI_CHART_MARKER_START))
3364 seriesCol.append(", " + AppConstants.RI_CHART_MARKER_START + " " + AppConstants.RI_CHART_MARKER_START );
3365 if(colName.equals(AppConstants.RI_CHART_MARKER_END))
3366 seriesCol.append(", " + AppConstants.RI_CHART_MARKER_END + " " + AppConstants.RI_CHART_MARKER_END );
3367 if(colName.equals(AppConstants.RI_CHART_MARKER_TEXT_LEFT))
3368 seriesCol.append(", " + AppConstants.RI_CHART_MARKER_TEXT_LEFT + " " + AppConstants.RI_CHART_MARKER_TEXT_LEFT );
3369 if(colName.equals(AppConstants.RI_CHART_MARKER_TEXT_RIGHT))
3370 seriesCol.append(", " + AppConstants.RI_CHART_MARKER_TEXT_RIGHT + " " + AppConstants.RI_CHART_MARKER_TEXT_RIGHT );
3371 //if(colName.equals(AppConstants.RI_ANOMALY_TEXT))
3372 //seriesCol.append(", " + AppConstants.RI_ANOMALY_TEXT + " " + AppConstants.RI_ANOMALY_TEXT );
3375 //debugLogger.debug("ReportSQL Chart " + reportSQL );
3376 /*for (Iterator iter = chartValueCols.iterator(); iter.hasNext();) {
3377 DataColumnType dc = (DataColumnType) iter.next();
3378 String colName = getColumnSelectStr(dc, paramValues);
3379 //valueCols.append(", NVL(" + formatChartColumn(colName) + ",0) " + dc.getColId());
3380 valueCols.append("," + formatChartColumn(colName) + " " + dc.getColId());
3382 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
3383 DataColumnType dc = (DataColumnType) iter.next();
3384 String colName = getColumnSelectStr(dc, paramValues);
3385 //if(colName.equals(AppConstants.RI_CHART_TOTAL_COL) || colName.equals(AppConstants.RI_CHART_COLOR)) {
3386 if(colName.equals(AppConstants.RI_CHART_TOTAL_COL))
3387 valueCols.append(", " + AppConstants.RI_CHART_TOTAL_COL + " " + AppConstants.RI_CHART_TOTAL_COL );
3388 if (colName.equals(AppConstants.RI_CHART_COLOR))
3389 valueCols.append(", " + AppConstants.RI_CHART_COLOR + " " + AppConstants.RI_CHART_COLOR );
3390 if (colName.equals(AppConstants.RI_CHART_INCLUDE))
3391 valueCols.append(", " + AppConstants.RI_CHART_INCLUDE + " " + AppConstants.RI_CHART_INCLUDE );
3394 String final_sql = "";
3395 reportSQL = Utils.replaceInString(reportSQL, " from ", " FROM ");
3396 reportSQL = Utils.replaceInString(reportSQL, " From ", " FROM ");
3397 reportSQL = Utils.replaceInString(reportSQL, " select ", " SELECT ");
3398 reportSQL = Utils.replaceInString(reportSQL, " union ", " UNION ");
3399 //reportSQL = reportSQL.replaceAll("[\\s]*\\(", "(");
3400 // if(reportSQL.indexOf("UNION") != -1) {
3401 // if(reportSQL.indexOf("FROM(")!=-1)
3402 // final_sql += " "+reportSQL.substring(reportSQL.indexOf("FROM(") );
3403 // else if (reportSQL.indexOf("FROM (")!=-1)
3404 // final_sql += " "+reportSQL.substring(reportSQL.indexOf("FROM (") );
3405 // //TODO ELSE THROW ERROR
3408 // final_sql += " "+reportSQL.substring(reportSQL.toUpperCase().indexOf(" FROM "));
3411 int pos_first_select = 0;
3412 int pos_dup_select = 0;
3413 int pos_prev_select = 0;
3414 int pos_last_select = 0;
3415 if (reportSQL.indexOf("FROM", pos)!=-1) {
3416 pos = reportSQL.indexOf("FROM", pos);
3417 pos_dup_select = reportSQL.lastIndexOf("SELECT",pos);
3418 pos_first_select = reportSQL.indexOf("SELECT");//,pos);
3419 logger.debug(EELFLoggerDelegate.debugLogger, ("pos_select " + pos_first_select + " " + pos_dup_select));
3420 if(pos_dup_select > pos_first_select) {
3421 logger.debug(EELFLoggerDelegate.debugLogger, ("********pos_dup_select ********" + pos_dup_select));
3422 //pos_dup_select1 = pos_dup_select;
3423 pos_prev_select = pos_first_select;
3424 pos_last_select = pos_dup_select;
3425 while (pos_last_select > pos_prev_select) {
3426 logger.debug(EELFLoggerDelegate.debugLogger, ("pos_last , pos_prev " + pos_last_select + " " + pos_prev_select));
3427 pos = reportSQL.indexOf("FROM", pos+2);
3428 pos_prev_select = pos_last_select;
3429 pos_last_select = reportSQL.lastIndexOf("SELECT",pos);
3430 logger.debug(EELFLoggerDelegate.debugLogger, ("in WHILE LOOP LAST " + pos_last_select));
3435 final_sql += " "+reportSQL.substring(pos);
3436 logger.debug(EELFLoggerDelegate.debugLogger, ("Final SQL " + final_sql));
3437 String sql = "SELECT " + legendCol + ", " + legendCol+"_1" + seriesCol.toString()+ nvl(valueCols.toString(), ", 1")
3438 + groupCol.toString()
3440 logger.debug(EELFLoggerDelegate.debugLogger, ("Final sql in generateChartSQL " +sql));
3443 } // generateChartSQL
3445 private String getColumnSelectStr(DataColumnType dc, HttpServletRequest request) {
3446 //String colName = dc.isCalculated() ? dc.getColName()
3447 // : ((nvl(dc.getTableId()).length() > 0) ? (dc.getTableId() + "." + dc
3448 // .getColName()) : dc.getColName());
3449 String colName = dc.getColName();
3450 String paramValue = null;
3451 //if (dc.isCalculated()) {
3452 if (reportRuntime.getFormFieldList() != null) {
3453 for (Iterator iter = reportRuntime.getFormFieldList().getFormField().iterator(); iter.hasNext();) {
3454 FormFieldType fft = (FormFieldType) iter.next();
3455 String fieldId = fft.getFieldId();
3456 String fieldDisplay = reportRuntime.getFormFieldDisplayName(fft);
3457 String formfield_value = "";
3458 formfield_value = AppUtils.getRequestNvlValue(request, fieldId);
3459 paramValue = nvl(formfield_value);
3460 if(paramValue.length()>0) {
3461 /*sql = Utils.replaceInString(sql, "'" + fieldDisplay + "'", nvl(
3462 paramValue, "NULL"));*/
3463 colName = Utils.replaceInString(colName, "'" + fieldDisplay + "'", "'"+nvl(
3464 paramValue, "NULL")+"'");
3465 colName = Utils.replaceInString(colName, fieldDisplay, nvl(
3466 paramValue, "NULL"));
3473 } // getColumnSelectStr
3477 public String getSelectExpr(DataColumnType dct) {
3479 // dct.isCalculated()?dct.getColName():((nvl(dct.getTableId()).length()>0)?(dct.getTableId()+"."+dct.getColName()):dct.getColName());
3480 return getSelectExpr(dct, dct.getColName() /* colName */);
3483 private String getSelectExpr(DataColumnType dct, String colName) {
3484 String colType = dct.getColType();
3485 if (colType.equals(AppConstants.CT_CHAR)
3486 || ((nvl(dct.getColFormat()).length() == 0) && (!colType
3487 .equals(AppConstants.CT_DATE))))
3490 return "DATE_FORMAT(" + colName + ", '"
3491 + nvl(dct.getColFormat(), AppConstants.DEFAULT_DATE_FORMAT) + "')";
3494 private String formatChartColumn(String colName) {
3495 logger.debug(EELFLoggerDelegate.debugLogger, ("Format Chart Column Input colName " + colName));
3496 colName = colName.trim();
3497 colName = Utils.replaceInString(colName, "TO_CHAR", "to_char");
3498 colName = Utils.replaceInString(colName, "to_number", "TO_NUMBER");
3499 //reportSQL = reportSQL.replaceAll("[\\s]*\\(", "(");
3500 colName = colName.replaceAll(",[\\s]*\\(", ",(");
3501 StringBuffer colNameBuf = new StringBuffer(colName);
3502 int pos = 0, posFormatStart = 0, posFormatEnd = 0;
3505 if(colNameBuf.indexOf("999")==-1 && colNameBuf.indexOf("990")==-1) {
3506 logger.debug(EELFLoggerDelegate.debugLogger, (" return colName " + colNameBuf.toString()));
3507 return colNameBuf.toString();
3510 while (colNameBuf.indexOf("to_char")!=-1) {
3511 if(colNameBuf.indexOf("999")!=-1 || colNameBuf.indexOf("990")!=-1) {
3512 pos = colNameBuf.indexOf("to_char");
3513 colNameBuf.insert(pos, " TO_NUMBER ( CR_RAPTOR.SAFE_TO_NUMBER (");
3514 pos = colNameBuf.indexOf("to_char");
3515 colNameBuf.replace(pos, pos+7, "TO_CHAR");
3516 //colName = Utils.replaceInString(colNameBuf.toString(), "to_char", " TO_NUMBER ( CR_RAPTOR.SAFE_TO_NUMBER ( TO_CHAR ");
3517 logger.debug(EELFLoggerDelegate.debugLogger, ("After adding to_number " + colNameBuf.toString()));
3518 //posFormatStart = colNameBuf.lastIndexOf(",'")+1;
3519 posFormatStart = colNameBuf.indexOf(",'", pos)+1;
3520 posFormatEnd = colNameBuf.indexOf(")",posFormatStart);
3521 logger.debug(EELFLoggerDelegate.debugLogger, (posFormatStart + " " + posFormatEnd + " "+ pos));
3522 format = colNameBuf.substring(posFormatStart, posFormatEnd);
3523 //posFormatEnd = colNameBuf.indexOf(")",posFormatEnd);
3524 colNameBuf.insert(posFormatEnd+1, " ," + format + ") , "+ format + ")");
3525 logger.debug(EELFLoggerDelegate.debugLogger, ("colNameBuf " + colNameBuf.toString()));
3528 logger.debug(EELFLoggerDelegate.debugLogger, (" return colName " + colNameBuf.toString()));
3529 return colNameBuf.toString();
3532 public List getChartValueColumnsList( int filter, HashMap formValues) { /*filter; all=0;create without new chart =1; createNewChart=2 */
3533 List reportCols = reportRuntime.getAllColumns();
3535 ArrayList chartValueCols = new ArrayList();
3537 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
3539 DataColumnType dc = (DataColumnType) iter.next();
3540 // if(filter == 2 || filter == 1) {
3541 flag = reportRuntime.getDependsOnFormFieldFlag(dc, formValues);
3543 if( (dc.getChartSeq()!=null && dc.getChartSeq()> 0) && flag == 0 && !(nvl(dc.getColOnChart()).equals(AppConstants.GC_LEGEND))) {
3544 if(nvl(dc.getChartGroup()).length()<=0) {
3545 if( filter == 2 && (dc.isCreateInNewChart()!=null && dc.isCreateInNewChart().booleanValue())) {
3546 chartValueCols.add(dc);
3547 } else if (filter == 1 && (dc.isCreateInNewChart()==null || !dc.isCreateInNewChart().booleanValue())) {
3548 chartValueCols.add(dc);
3550 else if(filter == 0) chartValueCols.add(dc);
3551 } else chartValueCols.add(dc);
3554 // chartValueCols.add(dc);
3556 Collections.sort(chartValueCols, new ChartSeqComparator());
3557 return chartValueCols;
3558 } // getChartValueColumnsList
3560 public String parseTitle(String title, HashMap formValues) {
3561 Set set = formValues.entrySet();
3562 for(Iterator iter = set.iterator(); iter.hasNext(); ) {
3563 Map.Entry entry = (Entry<String,String>) iter.next();
3564 if(title.indexOf("["+ entry.getKey() + "]")!= -1) {
3565 title = Utils.replaceInString(title, "["+entry.getKey()+"]", nvl(
3566 (String) entry.getValue(), ""));
3572 public java.util.Date getDateFromDateStr(String dateStr) {
3573 SimpleDateFormat MMDDYYYYFormat = new SimpleDateFormat("MM/dd/yyyy");
3574 SimpleDateFormat EEEMMDDYYYYFormat = new SimpleDateFormat("EEE, MM/dd/yyyy"); //2012-11-01 00:00:00
3575 SimpleDateFormat YYYYMMDDFormat = new SimpleDateFormat("yyyy/MM/dd");
3576 SimpleDateFormat MONYYYYFormat = new SimpleDateFormat("MMM yyyy");
3577 SimpleDateFormat MMYYYYFormat = new SimpleDateFormat("MM/yyyy");
3578 SimpleDateFormat MMMMMDDYYYYFormat = new SimpleDateFormat("MMMMM dd, yyyy");
3579 SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
3580 SimpleDateFormat timestampHrFormat = new SimpleDateFormat("yyyy-MM-dd HH");
3581 SimpleDateFormat timestampDayFormat = new SimpleDateFormat("yyyy-MM-dd");
3582 SimpleDateFormat DDMONYYYYFormat = new SimpleDateFormat("dd-MMM-yyyy");
3583 SimpleDateFormat MONTHYYYYFormat = new SimpleDateFormat("MMMMM, yyyy");
3584 SimpleDateFormat MMDDYYYYHHFormat = new SimpleDateFormat("MM/dd/yyyy HH");
3585 SimpleDateFormat MMDDYYYYHHMMSSFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
3586 SimpleDateFormat MMDDYYYYHHMMFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm");
3587 SimpleDateFormat YYYYMMDDHHMMSSFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
3588 SimpleDateFormat YYYYMMDDHHMMFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm");
3589 SimpleDateFormat DDMONYYYYHHMMSSFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
3590 SimpleDateFormat DDMONYYYYHHMMFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm");
3591 SimpleDateFormat MMDDYYFormat = new SimpleDateFormat("MM/dd/yy");
3592 SimpleDateFormat MMDDYYHHMMFormat = new SimpleDateFormat("MM/dd/yy HH:mm");
3593 SimpleDateFormat MMDDYYHHMMSSFormat = new SimpleDateFormat("MM/dd/yy HH:mm:ss");
3594 SimpleDateFormat timestampFormat1 = new SimpleDateFormat("yyyy-M-d.HH.mm. s. S");
3595 SimpleDateFormat timestamp_W_dash = new SimpleDateFormat("yyyyMMddHHmmss");
3596 SimpleDateFormat MMDDYYYYHHMMZFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm z");
3597 SimpleDateFormat YYYYFormat = new SimpleDateFormat("yyyy");
3598 java.util.Date date = null;
3602 final int YEARFLAG = 1;
3603 final int MONTHFLAG = 2;
3604 final int DAYFLAG = 3;
3605 final int HOURFLAG = 4;
3606 final int MINFLAG = 5;
3607 final int SECFLAG = 6;
3608 final int MILLISECFLAG = 7;
3609 final int DAYOFTHEWEEKFLAG = 8;
3610 final int FLAGDATE = 9;
3617 int milliSecFlag = 7;
3618 int dayoftheweekFlag = 8;
3622 date = MMDDYYYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
3623 if(date!=null) formatFlag = SECFLAG;
3625 date = EEEMMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
3626 if(date!=null) formatFlag = DAYOFTHEWEEKFLAG;
3629 date = MMDDYYYYHHMMFormat.parse(dateStr, new ParsePosition(0));
3630 if(date!=null) formatFlag = MINFLAG;
3633 //MMDDYYYYHHFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
3634 date = MMDDYYYYHHFormat.parse(dateStr, new ParsePosition(0));
3635 if(date!=null) formatFlag = HOURFLAG;
3638 date = MMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
3639 if(date!=null) formatFlag = DAYFLAG;
3642 date = YYYYMMDDFormat.parse(dateStr, new ParsePosition(0));
3643 if(date!=null) formatFlag = DAYFLAG;
3646 date = timestampFormat.parse(dateStr, new ParsePosition(0));
3647 if(date!=null) formatFlag = SECFLAG;
3650 date = timestampHrFormat.parse(dateStr, new ParsePosition(0));
3651 if(date!=null) formatFlag = HOURFLAG;
3654 date = timestampDayFormat.parse(dateStr, new ParsePosition(0));
3655 if(date!=null) formatFlag = DAYFLAG;
3659 date = MONYYYYFormat.parse(dateStr, new ParsePosition(0));
3660 if(date!=null) formatFlag = MONTHFLAG;
3663 date = MMYYYYFormat.parse(dateStr, new ParsePosition(0));
3664 if(date!=null) formatFlag = MONTHFLAG;
3667 date = MMMMMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
3668 if(date!=null) formatFlag = DAYFLAG;
3671 date = MONTHYYYYFormat.parse(dateStr, new ParsePosition(0));
3672 if(date!=null) formatFlag = MONTHFLAG;
3676 date = YYYYMMDDHHMMSSFormat.parse(dateStr, new ParsePosition(0));
3677 if(date!=null) formatFlag = SECFLAG;
3681 date = YYYYMMDDHHMMFormat.parse(dateStr, new ParsePosition(0));
3682 if(date!=null) formatFlag = MINFLAG;
3686 date = DDMONYYYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
3687 if(date!=null) formatFlag = SECFLAG;
3691 date = DDMONYYYYHHMMFormat.parse(dateStr, new ParsePosition(0));
3692 if(date!=null) formatFlag = MINFLAG;
3696 date = DDMONYYYYFormat.parse(dateStr, new ParsePosition(0));
3697 if(date!=null) formatFlag = DAYFLAG;
3701 date = MMDDYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
3702 if(date!=null) formatFlag = SECFLAG;
3706 date = MMDDYYHHMMFormat.parse(dateStr, new ParsePosition(0));
3707 if(date!=null) formatFlag = MINFLAG;
3711 date = MMDDYYFormat.parse(dateStr, new ParsePosition(0));
3712 if(date!=null) formatFlag = DAYFLAG;
3716 date = timestampFormat1.parse(dateStr, new ParsePosition(0));
3717 if(date!=null) formatFlag = SECFLAG;
3721 date = MMDDYYYYHHMMZFormat.parse(dateStr, new ParsePosition(0));
3722 if(date!=null) formatFlag = MINFLAG;
3726 date = YYYYFormat.parse(dateStr, new ParsePosition(0));
3727 /* Some random numbers should not satisfy this year format. */
3728 if(dateStr.length()>4) date = null;
3729 if(date!=null) formatFlag = YEARFLAG;
3732 date = timestamp_W_dash.parse(dateStr, new ParsePosition(0));
3733 if(date!=null) formatFlag = SECFLAG;
3740 public int getFlagFromDateStr(String dateStr) {
3741 SimpleDateFormat MMDDYYYYFormat = new SimpleDateFormat("MM/dd/yyyy");
3742 SimpleDateFormat EEEMMDDYYYYFormat = new SimpleDateFormat("EEE, MM/dd/yyyy"); //2012-11-01 00:00:00
3743 SimpleDateFormat YYYYMMDDFormat = new SimpleDateFormat("yyyy/MM/dd");
3744 SimpleDateFormat MONYYYYFormat = new SimpleDateFormat("MMM yyyy");
3745 SimpleDateFormat MMYYYYFormat = new SimpleDateFormat("MM/yyyy");
3746 SimpleDateFormat MMMMMDDYYYYFormat = new SimpleDateFormat("MMMMM dd, yyyy");
3747 SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
3748 SimpleDateFormat timestampHrFormat = new SimpleDateFormat("yyyy-MM-dd HH");
3749 SimpleDateFormat timestampDayFormat = new SimpleDateFormat("yyyy-MM-dd");
3750 SimpleDateFormat DDMONYYYYFormat = new SimpleDateFormat("dd-MMM-yyyy");
3751 SimpleDateFormat MONTHYYYYFormat = new SimpleDateFormat("MMMMM, yyyy");
3752 SimpleDateFormat MMDDYYYYHHFormat = new SimpleDateFormat("MM/dd/yyyy HH");
3753 SimpleDateFormat MMDDYYYYHHMMSSFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
3754 SimpleDateFormat MMDDYYYYHHMMFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm");
3755 SimpleDateFormat YYYYMMDDHHMMSSFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
3756 SimpleDateFormat YYYYMMDDHHMMFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm");
3757 SimpleDateFormat DDMONYYYYHHMMSSFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
3758 SimpleDateFormat DDMONYYYYHHMMFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm");
3759 SimpleDateFormat MMDDYYFormat = new SimpleDateFormat("MM/dd/yy");
3760 SimpleDateFormat MMDDYYHHMMFormat = new SimpleDateFormat("MM/dd/yy HH:mm");
3761 SimpleDateFormat MMDDYYHHMMSSFormat = new SimpleDateFormat("MM/dd/yy HH:mm:ss");
3762 SimpleDateFormat timestampFormat1 = new SimpleDateFormat("yyyy-M-d.HH.mm. s. S");
3763 SimpleDateFormat timestamp_W_dash = new SimpleDateFormat("yyyyMMddHHmmss");
3764 SimpleDateFormat MMDDYYYYHHMMZFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm z");
3765 SimpleDateFormat YYYYFormat = new SimpleDateFormat("yyyy");
3766 java.util.Date date = null;
3770 final int YEARFLAG = 1;
3771 final int MONTHFLAG = 2;
3772 final int DAYFLAG = 3;
3773 final int HOURFLAG = 4;
3774 final int MINFLAG = 5;
3775 final int SECFLAG = 6;
3776 final int MILLISECFLAG = 7;
3777 final int DAYOFTHEWEEKFLAG = 8;
3778 final int FLAGDATE = 9;
3785 int milliSecFlag = 7;
3786 int dayoftheweekFlag = 8;
3790 date = MMDDYYYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
3791 if(date!=null) formatFlag = SECFLAG;
3793 date = EEEMMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
3794 if(date!=null) formatFlag = DAYOFTHEWEEKFLAG;
3797 date = MMDDYYYYHHMMFormat.parse(dateStr, new ParsePosition(0));
3798 if(date!=null) formatFlag = MINFLAG;
3801 //MMDDYYYYHHFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
3802 date = MMDDYYYYHHFormat.parse(dateStr, new ParsePosition(0));
3803 if(date!=null) formatFlag = HOURFLAG;
3806 date = MMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
3807 if(date!=null) formatFlag = DAYFLAG;
3810 date = YYYYMMDDFormat.parse(dateStr, new ParsePosition(0));
3811 if(date!=null) formatFlag = DAYFLAG;
3814 date = timestampFormat.parse(dateStr, new ParsePosition(0));
3815 if(date!=null) formatFlag = SECFLAG;
3818 date = timestampHrFormat.parse(dateStr, new ParsePosition(0));
3819 if(date!=null) formatFlag = HOURFLAG;
3822 date = timestampDayFormat.parse(dateStr, new ParsePosition(0));
3823 if(date!=null) formatFlag = DAYFLAG;
3826 date = MONYYYYFormat.parse(dateStr, new ParsePosition(0));
3827 if(date!=null) formatFlag = MONTHFLAG;
3830 date = MMYYYYFormat.parse(dateStr, new ParsePosition(0));
3831 if(date!=null) formatFlag = MONTHFLAG;
3834 date = MMMMMDDYYYYFormat.parse(dateStr, new ParsePosition(0));
3835 if(date!=null) formatFlag = DAYFLAG;
3838 date = MONTHYYYYFormat.parse(dateStr, new ParsePosition(0));
3839 if(date!=null) formatFlag = MONTHFLAG;
3843 date = YYYYMMDDHHMMSSFormat.parse(dateStr, new ParsePosition(0));
3844 if(date!=null) formatFlag = SECFLAG;
3848 date = YYYYMMDDHHMMFormat.parse(dateStr, new ParsePosition(0));
3849 if(date!=null) formatFlag = MINFLAG;
3853 date = DDMONYYYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
3854 if(date!=null) formatFlag = SECFLAG;
3858 date = DDMONYYYYHHMMFormat.parse(dateStr, new ParsePosition(0));
3859 if(date!=null) formatFlag = MINFLAG;
3863 date = DDMONYYYYFormat.parse(dateStr, new ParsePosition(0));
3864 if(date!=null) formatFlag = DAYFLAG;
3868 date = MMDDYYHHMMSSFormat.parse(dateStr, new ParsePosition(0));
3869 if(date!=null) formatFlag = SECFLAG;
3873 date = MMDDYYHHMMFormat.parse(dateStr, new ParsePosition(0));
3874 if(date!=null) formatFlag = MINFLAG;
3878 date = MMDDYYFormat.parse(dateStr, new ParsePosition(0));
3879 if(date!=null) formatFlag = DAYFLAG;
3883 date = timestampFormat1.parse(dateStr, new ParsePosition(0));
3884 if(date!=null) formatFlag = SECFLAG;
3888 date = MMDDYYYYHHMMZFormat.parse(dateStr, new ParsePosition(0));
3889 if(date!=null) formatFlag = MINFLAG;
3893 date = YYYYFormat.parse(dateStr, new ParsePosition(0));
3894 /* Some random numbers should not satisfy this year format. */
3895 if(dateStr.length()>4) date = null;
3896 if(date!=null) formatFlag = YEARFLAG;
3899 date = timestamp_W_dash.parse(dateStr, new ParsePosition(0));
3900 if(date!=null) formatFlag = SECFLAG;
3907 public static String[] reverse(String[] arr) {
3908 List<String> list = Arrays.asList(arr);
3909 Collections.reverse(list);
3910 return (String[])list.toArray();
3913 public int getNumberOfDecimalPlaces(double num) {
3915 String[] splitter = d.toString().split("\\.");
3916 splitter[0].length(); // Before Decimal Count
3917 splitter[1].length(); // After Decimal Count
3918 return splitter[1].length();
3921 public boolean getBooleanValue(String s) {
3922 return getBooleanValue(s,null);
3925 public boolean getBooleanValue(String s, Boolean defaultValue) {
3927 if(s.length()<=0 && defaultValue!=null) return defaultValue.booleanValue();
3928 else if(s.length()<=0) return false;
3930 if(s.toUpperCase().startsWith("Y") || s.toLowerCase().equals("true"))
3938 public String IntToLetter(int Int) {
3940 return Character.toString((char)(Int+96));
3943 return IntToLetter((Int/26)-1)+IntToLetter((Int%26)+1);
3945 return IntToLetter(Int/26)+IntToLetter(Int%26);
3953 private void clearReportRuntimeBackup(HttpServletRequest request) {
3954 //Session sess = Sessions.getCurrent(true)getCurrent();
3955 //HttpSession session = (HttpSession)sess.getNativeSession();
3956 HttpSession session = request.getSession();
3957 session.removeAttribute(AppConstants.DRILLDOWN_REPORTS_LIST);
3958 request.removeAttribute(AppConstants.DRILLDOWN_INDEX);
3959 session.removeAttribute(AppConstants.DRILLDOWN_INDEX);
3960 request.removeAttribute(AppConstants.FORM_DRILLDOWN_INDEX);
3961 session.removeAttribute(AppConstants.FORM_DRILLDOWN_INDEX);
3962 Enumeration<String> enum1 = session.getAttributeNames();
3963 String attributeName = "";
3964 while(enum1.hasMoreElements()) {
3965 attributeName = enum1.nextElement();
3966 if(attributeName.startsWith("parent_")) {
3967 session.removeAttribute(attributeName);
3970 session.removeAttribute(AppConstants.DRILLDOWN_REPORTS_LIST);
3971 session.removeAttribute(AppConstants.SI_BACKUP_FOR_REP_ID);
3972 session.removeAttribute(AppConstants.SI_COLUMN_LOOKUP);
3973 session.removeAttribute(AppConstants.SI_DASHBOARD_REP_ID);
3974 session.removeAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP);
3975 session.removeAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME);
3976 session.removeAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP);
3977 session.removeAttribute(AppConstants.SI_DASHBOARD_CHARTDATA_MAP);
3978 session.removeAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP);
3979 session.removeAttribute(AppConstants.SI_DATA_SIZE_FOR_TEXTFIELD_POPUP);
3980 session.removeAttribute(AppConstants.SI_MAP);
3981 session.removeAttribute(AppConstants.SI_MAP_OBJECT);
3982 session.removeAttribute(AppConstants.SI_REPORT_DEFINITION);
3983 session.removeAttribute(AppConstants.SI_REPORT_RUNTIME);
3984 session.removeAttribute(AppConstants.SI_REPORT_RUN_BACKUP);
3985 session.removeAttribute(AppConstants.SI_REPORT_SCHEDULE);
3986 session.removeAttribute(AppConstants.RI_REPORT_DATA);
3987 session.removeAttribute(AppConstants.RI_CHART_DATA);
3988 session.removeAttribute(AppConstants.SI_FORMFIELD_INFO);
3989 session.removeAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO);
3991 } // clearReportRuntimeBackup
3994 public static synchronized java.util.HashMap getRequestParametersMap(ReportRuntime rr, HttpServletRequest request)
3996 HashMap valuesMap = new HashMap();
3998 ReportFormFields rff = rr.getReportFormFields();
4001 FormField ff = null;
4003 Map fieldNameMap = new HashMap();
4004 int countOfFields = 0 ;
4007 for(rff.resetNext(); rff.hasNext(); idx++) {
4009 fieldNameMap.put(ff.getFieldName(), ff.getFieldDisplayName());
4013 List formParameter = new ArrayList();
4014 String formField = "";
4015 for(int i = 0 ; i < rff.size(); i++) {
4016 ff = ((FormField)rff.getFormField(i));
4017 formField = ff.getFieldName();
4018 boolean isMultiValue = false;
4019 isMultiValue = ff.getFieldType().equals(FormField.FFT_CHECK_BOX)
4020 || ff.getFieldType().equals(FormField.FFT_LIST_MULTI);
4021 boolean isTextArea = (ff.getFieldType().equals(FormField.FFT_TEXTAREA) && rr.getReportDefType()
4022 .equals(AppConstants.RD_SQL_BASED));
4024 if(request.getParameterValues(formField) != null && isMultiValue ) {
4025 String[] vals = request.getParameterValues(formField);
4026 StringBuffer value = new StringBuffer("");
4027 if(!AppUtils.getRequestFlag(request, AppConstants.RI_RESET_ACTION)) {
4029 if ( isMultiValue ) {
4032 for(int j = 0 ; j < vals.length; j++) {
4033 if(isMultiValue) value.append("'");
4035 if(vals[j] !=null && vals[j].length() > 0) {
4036 vals[j] = Utils.oracleSafe(vals[j]);
4037 value.append(java.net.URLDecoder.decode(vals[j], "UTF-8"));// + ",";
4040 value.append(vals[j]);
4041 } catch (UnsupportedEncodingException ex) {value.append(vals[j]);}
4042 catch (IllegalArgumentException ex1){value.append(vals[j]);}
4043 catch (Exception ex2){
4044 value.append(vals[j]);
4048 if(isMultiValue) value.append("'");
4050 if(j != vals.length -1) {
4054 if(vals.length > 0) {
4059 //value = value.substring(0 , value.length());
4061 valuesMap.put(fieldNameMap.get(formField), value.toString());
4062 value = new StringBuffer("");
4063 } else if(request.getParameter(formField) != null) {
4066 value = request.getParameter(formField);
4068 value = Utils.oracleSafe(value);
4069 value = "('" + Utils.replaceInString(value, ",", "'|'") + "')";
4070 value = Utils.replaceInString(value, "|", ",");
4071 valuesMap.put(fieldNameMap.get(formField), value);
4075 if(!AppUtils.getRequestFlag(request, AppConstants.RI_RESET_ACTION))
4076 value = request.getParameter(formField);
4077 valuesMap.put(fieldNameMap.get(formField), Utils.oracleSafe(value));
4081 valuesMap.put(fieldNameMap.get(formField), "" );