incubator-adffaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mat...@apache.org
Subject svn commit: r524095 - in /incubator/adffaces/trunk/trinidad: trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/ trinidad-demo/src/main/webapp/components/ trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/desktop/ ...
Date Fri, 30 Mar 2007 14:14:07 GMT
Author: matzew
Date: Fri Mar 30 07:14:04 2007
New Revision: 524095

URL: http://svn.apache.org/viewvc?view=rev&rev=524095
Log:
ADFFACES-430 Chart Component Not Working if there is no editableValue component on the page


thx to Venkata Guddanti for providing the patch !

Modified:
    incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/ChartBean.java
    incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/components/chart.jspx
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/desktop/ChartRenderer.java
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/ApacheChart.js

Modified: incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/ChartBean.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/ChartBean.java?view=diff&rev=524095&r1=524094&r2=524095
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/ChartBean.java
(original)
+++ incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/ChartBean.java
Fri Mar 30 07:14:04 2007
@@ -62,6 +62,16 @@
     return null;
   }
   
+  public String nextChartType()
+  {
+    _currentTypeIndex++;
+    if(_currentTypeIndex >= _chartTypes.length)
+      _currentTypeIndex = 0;
+    CoreChart chart = (CoreChart)_editorBean.getComponent();
+    chart.setType(_chartTypes[_currentTypeIndex]);
+    return null;
+  }
+  
   public boolean isLargerDataSet()
   {
     return _largerDataSet;
@@ -363,6 +373,12 @@
   } 
   
   private boolean _largerDataSet = false;
+  private int     _currentTypeIndex = 0;
+  private static final String[] _chartTypes = 
+        new String[]{"verticalBar", "horizontalBar", "stackedVerticalBar","stackedHorizontalBar",

+        "pie", "area", "stackedArea", "line", "barLine", "XYLine", "scatterPlot", "radar",
+        "radarArea", "funnel", "circularGauge", "semiCircularGauge"};
+
   private final ChartModel _chartModel = new MyChartModel(); 
   private final ComponentEditorHandler _editorBean = new ComponentEditorHandler();
 }

Modified: incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/components/chart.jspx
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/components/chart.jspx?view=diff&rev=524095&r1=524094&r2=524095
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/components/chart.jspx
(original)
+++ incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/components/chart.jspx
Fri Mar 30 07:14:04 2007
@@ -34,17 +34,21 @@
           <tr:commandLink immediate="true" text="Component Guide"
               action="guide"/>
           <tr:outputFormatted styleUsage="instruction" value="&lt;b>Chart&lt;/b>"/>
-          <tr:chart chartDrillDownListener="#{chart.drillDown}" id="chart" YMajorGridLineCount="7"
value="#{chart.value}" inlineStyle="width:680px; height:400px;" 
+          <tr:chart chartDrillDownListener="#{chart.drillDown}" id="chart" 
+            YMajorGridLineCount="7" value="#{chart.value}" 
+            inlineStyle="width:680px; height:400px;" 
+            partialTriggers="nextChartType"
             binding="#{chart.editor.component}"/>
           <tr:panelGroupLayout layout="horizontal">
+            <tr:commandButton id="nextChartType" partialSubmit="true" text="Next Chart
Type"
+                              action="#{chart.nextChartType}"/>
             <tr:commandButton  text="Update"
                               action="#{chart.editor.update}"/>
             <tr:commandButton id="partialButton" partialSubmit="true" text="Update Partial"
                               action="#{chart.updatePartial}"/>
             
             <tr:selectBooleanCheckbox immediate="true" label="Larger Data Set"
-                value="#{chart.largerDataSet}"/>
-
+                value="#{chart.largerDataSet}"/>            
           </tr:panelGroupLayout>
           <tr:table var="row" rows="100" value="#{chart.editor.attributes}" 
                     summary="Attributes">

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/desktop/ChartRenderer.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/desktop/ChartRenderer.java?view=diff&rev=524095&r1=524094&r2=524095
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/desktop/ChartRenderer.java
(original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/desktop/ChartRenderer.java
Fri Mar 30 07:14:04 2007
@@ -48,6 +48,7 @@
 import org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.SkinSelectors;
 import org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.XhtmlConstants;
 import org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.XhtmlRenderer;
+import org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.XhtmlUtils;
 import org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.jsLibs.LibraryScriptlet;
 import org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.jsLibs.Scriptlet;
 
@@ -187,6 +188,8 @@
     rw.startElement(XhtmlConstants.DIV_ELEMENT, component); 
     renderId(context, component);
     renderStyleAttributes(context, arc, bean, SkinSelectors.AF_CHART_STYLE_CLASS);
+    // We need the number convertor so that we can format numbers on the client
+    XhtmlUtils.addLib(context, arc, _NUMBER_CONVERTER_SCRIPTLET);
     // output the chart javascript library
     chartLib.outputScriptlet(context, arc);
 
@@ -708,6 +711,7 @@
   private static final String _DELIMITER = "\\$adf\\$";
   private static final String _TEMPLATE_DOC = "/adf/svg/chart.svg";
   private static final String _TEMPLATE_DOC_NOGRADIENT = "/adf/svg/chartNoGradient.svg";
+  private static final String _NUMBER_CONVERTER_SCRIPTLET = "TrNumberConverter()";
   private static final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(ChartRenderer.class);
 
   private static final Map<String, Integer>_typeToJSTypeMap = new HashMap<String,
Integer>();

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/ApacheChart.js
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/ApacheChart.js?view=diff&rev=524095&r1=524094&r2=524095
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/ApacheChart.js
(original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/ApacheChart.js
Fri Mar 30 07:14:04 2007
@@ -78,21 +78,21 @@
 */
 function ApacheChartBuffer(size)
 {
-	this.maxStreamLength = document.all?5000:100000;	
-	this.data = new Array(size?size:100);
-	this.iStr = 0;
+  this.maxStreamLength = document.all?5000:100000;	
+  this.data = new Array(size?size:100);
+  this.iStr = 0;
 }
 
 ApacheChartBuffer.prototype.append = function(obj)
 {
-	this.data[this.iStr++] = obj;
-	if (this.data.length > this.maxStreamLength)
-	{
-		this.data = [this.data.join("")];
-		this.data.length = 100;
-		this.iStr = 1;
-	}
-	return this;  
+  this.data[this.iStr++] = obj;
+  if (this.data.length > this.maxStreamLength)
+  {
+    this.data = [this.data.join("")];
+    this.data.length = 100;
+    this.iStr = 1;
+  }
+  return this;  
 }
 
 ApacheChartBuffer.prototype.toString = function()
@@ -118,18 +118,18 @@
   this._seriesColors = seriesColors;
   
   // the maximum value used to display the y-axis. 
-  // Default is 20% of maximum of the yValues
+  // Default is 120% of maximum of the yValues
   //this._maxYValue = undefined;
   
-  // the minimum value used to display the y-axis. Default is 0
-  this._minYValue = 0;
+  // the minimum value used to display the y-axis. Default is 80% of minimum of values
+  //this._minYValue = undefined;
 
   // the maximum value used to display the X-axis. 
-  // Default is 20% of maximum of the xValues
+  // Default is 120% of maximum of the xValues
   //this._maxXValue = undefined;
   
-  // the minimum value used to display the y-axis. Default is 0
-  this._minXValue = 0;
+  // the minimum value used to display the y-axis. Default is 80% of minimum of values 
+  //this._minXValue = undefined;
     
   // The title for the graph
   //this._title = undefined;
@@ -421,7 +421,7 @@
     this._errorHtml = "<H4>This component needs an SVG enabled browser like Internet
Explorer, Firefox 1.5+ or Opera 9.0+<H4>";
   
   this._statusHtml = "<H4>Please Wait. Attempting to load SVG document...</H4>";
-  this.ComputeMaxValues();
+  this.ComputeMinMaxValues();
 }
 
 /**
@@ -503,22 +503,34 @@
   this._toolTip = tt;
 }
 
-ApacheChart.prototype.ComputeMaxValues = function()
+ApacheChart.prototype.ComputeMinMaxValues = function()
 {
   var model = this._model, yValues = model.getYValues(), xValues = model.getXValues(),
       maxYValue = model.getMaxYValue(), maxXValue = model.getMaxXValue(),
+      minYValue = model.getMinYValue(), minXValue = model.getMinXValue(),
       seriesLabels = model.getSeriesLabels();
-  if(yValues != null && maxYValue == null)
-    model.setMaxYValue(this._computeAxisMaxValues(yValues, seriesLabels.length));
-  
-  if(xValues != null && maxXValue == null)
-    model.setMaxXValue(this._computeAxisMaxValues(xValues, seriesLabels.length));
+  if(yValues != null && (maxYValue == null || minYValue == null))
+  {
+    var minMax = this._computeAxisMinMaxValues(yValues, seriesLabels.length);
+    if(maxYValue == null)
+      model.setMaxYValue(minMax.max);
+    if(minYValue == null)
+      model.setMinYValue(minMax.min);
+  }
+  if(xValues != null && (maxXValue == null || minXValue == null))
+  {
+    var minMax = this._computeAxisMinMaxValues(xValues, seriesLabels.length);
+    if(maxXValue == null)
+      model.setMaxXValue(minMax.max);
+    if(minXValue == null)
+      model.setMinXValue(minMax.min);
+  }
 }
 
-ApacheChart.prototype._computeAxisMaxValues = function(values, seriesSize)
+ApacheChart.prototype._computeAxisMinMaxValues = function(values, seriesSize)
 {
-  var stackedTotal, maxValue = 0, type = this._type, 
-      isStacked = false, groupsCount = values.length;
+  var stackedTotal, value, maxValue = Number.NEGATIVE_INFINITY, minValue = Number.POSITIVE_INFINITY,

+      type = this._type, isStacked = false, groupsCount = values.length;
   
   if(type == ApacheChart.TYPE_VBAR_STACKED || type == ApacheChart.TYPE_HBAR_STACKED || 
      type == ApacheChart.TYPE_AREA_STACKED)
@@ -530,15 +542,24 @@
     stackedTotal = 0;
     for (var j = 0; j < seriesSize; ++j)
     {
+      value = values[i][j];
       if (isStacked)
-        stackedTotal += values[i][j];
+        stackedTotal += value;
       else
-        maxValue = Math.max(maxValue, values[i][j]);
+      {
+        maxValue = Math.max(maxValue, value);
+        minValue = Math.min(minValue, value);
+      }
     }
     if (isStacked)
+    {
       maxValue = Math.max(maxValue, stackedTotal);
+      minValue = Math.min(minValue, stackedTotal);
+    }
   }
-  return maxValue*ApacheChart._MAX_MULTIPLIER;
+  var maxMult = maxValue>0?ApacheChart._MAX_MULTIPLIER:ApacheChart._MIN_MULTIPLIER,
+      minMult = minValue>0?ApacheChart._MIN_MULTIPLIER:ApacheChart._MAX_MULTIPLIER;
+  return {max: maxValue*maxMult, min: minValue*minMult};
 }
 
 ApacheChart.TYPE_VBAR = 1;
@@ -565,6 +586,7 @@
 ApacheChart.LEGEND_LOCATION_START = "start";
 
 ApacheChart._MAX_MULTIPLIER = 1.2;
+ApacheChart._MIN_MULTIPLIER = .8;
 ApacheChart._XOFFSET_PERSPECTIVE = 10;
 ApacheChart._YOFFSET_PERSPECTIVE = 5;
 // margin generally used around text
@@ -2346,7 +2368,7 @@
   }  
 }
 
-ApachePieChart.prototype.ComputeMaxValues = function()
+ApachePieChart.prototype.ComputeMinMaxValues = function()
 {
 
 }
@@ -4662,7 +4684,7 @@
   }  
 }
 
-ApacheFunnelChart.prototype.ComputeMaxValues = function()
+ApacheFunnelChart.prototype.ComputeMinMaxValues = function()
 {
 
 }
@@ -4991,7 +5013,7 @@
   // Legend does not make sense for a gauge
 }
 
-ApacheGaugeChart.prototype.ComputeMaxValues = function()
+ApacheGaugeChart.prototype.ComputeMinMaxValues = function()
 {
 
 }
@@ -5331,4 +5353,4 @@
   var tx = (quadWidth<=gaugeWidth)?0:(quadWidth-gaugeWidth)/2,
       ty = (quadHeight<=gaugeHeight)?0:(quadHeight-gaugeHeight)/2;
   gauge.setAttribute("transform","translate("+tx+","+ty+") scale("+scale+","+scale+")");
-}
\ No newline at end of file
+}



Mime
View raw message