Author: neildhruva
Date: 2012-07-20 08:41:35 -0700 (Fri, 20 Jul 2012)
New Revision: 29939

Modified:
   
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/ChartAppFactoryImpl.java
   
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/CytoChart.java
   
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/PanelComponents.java
   
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/PanelLayout.java
Log:
Added a sample histogram. Restructured some code as well.

Modified: 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/ChartAppFactoryImpl.java
===================================================================
--- 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/ChartAppFactoryImpl.java
       2012-07-20 12:41:43 UTC (rev 29938)
+++ 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/ChartAppFactoryImpl.java
       2012-07-20 15:41:35 UTC (rev 29939)
@@ -1,16 +1,12 @@
 package org.cytoscape.neildhruva.chartapp.impl;
 
-import java.util.ArrayList;
-
 import javax.swing.JCheckBox;
 import javax.swing.JComboBox;
 import javax.swing.JPanel;
 import javax.swing.JTable;
 
-import org.cytoscape.model.CyIdentifiable;
 import org.cytoscape.model.CyNetwork;
 import org.cytoscape.model.CyNetworkTableManager;
-import org.cytoscape.model.CyRow;
 import org.cytoscape.model.CyTable;
 import org.cytoscape.model.CyTableFactory;
 import org.cytoscape.model.CyTableManager;
@@ -22,9 +18,6 @@
 
        private JPanel jpanel;
        private int tableColumnCount;
-       private CyTableFactory tableFactory;
-       private CyNetworkTableManager cyNetworkTableMgr;
-       private CyTableManager cyTableManager;
        private PanelComponents panelComponents;
        private PanelLayout panelLayout;
        
@@ -32,16 +25,13 @@
                                                                
CyNetworkTableManager cyNetworkTableMgr,
                                                                CyTableManager 
cyTableManager) {
 
-               this.tableFactory = tableFactory;
-               this.cyNetworkTableMgr = cyNetworkTableMgr;
-               this.cyTableManager = cyTableManager;
                this.panelLayout = new PanelLayout();
                this.panelComponents = new PanelComponents(tableFactory, 
cyNetworkTableMgr, cyTableManager);
        }
        
        public JPanel createPanel(CyNetwork currentNetwork, CyTable cyTable) {
                
-               
System.out.println(currentNetwork.NAME+"------"+cyTable.getTitle());
+       //      
System.out.println(currentNetwork.NAME+"------"+cyTable.getTitle());
                JTable table = new JTable(new MyTableModel(cyTable));
                tableColumnCount = table.getColumnCount();
                

Modified: 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/CytoChart.java
===================================================================
--- 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/CytoChart.java
 2012-07-20 12:41:43 UTC (rev 29938)
+++ 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/CytoChart.java
 2012-07-20 15:41:35 UTC (rev 29939)
@@ -1,5 +1,6 @@
 package org.cytoscape.neildhruva.chartapp.impl;
 
+import java.util.Random;
 import java.util.Vector;
 
 import javax.swing.JTable;
@@ -10,6 +11,8 @@
 import org.jfree.chart.JFreeChart;
 import org.jfree.chart.plot.PlotOrientation;
 import org.jfree.data.category.DefaultCategoryDataset;
+import org.jfree.data.statistics.HistogramDataset;
+import org.jfree.data.statistics.HistogramType;
 
 public class CytoChart {
 
@@ -29,7 +32,11 @@
         * @return The <code>ChartPanel</code> that contains the newly created 
chart.
         */
        public JFreeChart createChart(String chartType){
-               return XYChart();
+               if(chartType.equals("Line Chart")){
+                       return XYChart();
+               } else {
+                       return plotHistogram();
+               }
        }
        
        /**
@@ -38,7 +45,6 @@
         */
        public JFreeChart XYChart() {
                
-               
            // create the dataset...
         final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
         int rowCount = table.getRowCount();
@@ -54,10 +60,9 @@
                }
         }
         
-        
         // create the chart...
         chart = ChartFactory.createLineChart(
-            "Line Chart Demo 1",       // chart title
+            cyTable.getTitle(),       // chart title
             "NAME",                    // domain axis label
             "Value",                   // range axis label
             dataset,                   // data
@@ -66,11 +71,34 @@
             true,                      // tooltips
             false                      // urls
         );
-        
+        chart.getCategoryPlot().setNoDataMessage("Please select a column");
                return chart;
-               
        }
        
        
-       
+       /**
+        * Creates a Histogram.
+        * @return A <code>JFreeChart</code> containing the histogram.
+        */
+       public JFreeChart plotHistogram() {
+               
+               double[] value = new double[100];
+              Random generator = new Random();
+              for (int i=1; i < 100; i++) {
+              value[i] = generator.nextDouble();
+                  int number = 10;
+              HistogramDataset dataset = new HistogramDataset();
+              dataset.setType(HistogramType.RELATIVE_FREQUENCY);
+              dataset.addSeries("Histogram",value,number);
+              
+              String plotTitle = "Sample Random Number Histogram"; 
+              String xaxis = "number";
+              String yaxis = "value"; 
+              PlotOrientation orientation = PlotOrientation.VERTICAL; 
+              chart = ChartFactory.createHistogram( plotTitle, xaxis, yaxis, 
+                                                                               
         dataset, orientation, true, 
+                                                                               
         true, false);
+               }
+              return chart;
+       }
 }

Modified: 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/PanelComponents.java
===================================================================
--- 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/PanelComponents.java
   2012-07-20 12:41:43 UTC (rev 29938)
+++ 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/PanelComponents.java
   2012-07-20 15:41:35 UTC (rev 29939)
@@ -47,6 +47,11 @@
                    public String toString() {
                        return "Line Chart";
                    }
+               },
+               HISTOGRAM {
+                   public String toString() {
+                       return "Histogram";
+                   }
                }
        }
        
@@ -97,7 +102,7 @@
                        CyRow cyrow = 
myCyTable.getRow(currentNetwork.getSUID());
                        cyrow.set("Names", columnNamesList);
                        cyrow.set("States", checkBoxState);
-                       cyrow.set("ChartType", "Bar Chart"); //default value is 
"Bar Chart"
+                       cyrow.set("ChartType", "Line Chart"); //default value 
is "Line Chart"
                
                        //associate myCyTable with this network 
                        cyNetworkTableMgr.setTable(currentNetwork, 
CyNetwork.class, "PrintTable "+cyTable.getTitle(), myCyTable);
@@ -145,8 +150,8 @@
                                                
showColumn(checkBoxArray[j].getText());
                                        }
                                        
-                                       refreshChartPanel("Line Chart");
-                       updateChartType("Line Chart");
+                                       
refreshChartPanel(myCyTable.getAllRows().get(0).get("ChartType", String.class));
+                       
updateChartType(myCyTable.getAllRows().get(0).get("ChartType", String.class));
                                }
                });
         }

Modified: 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/PanelLayout.java
===================================================================
--- 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/PanelLayout.java
       2012-07-20 12:41:43 UTC (rev 29938)
+++ 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/PanelLayout.java
       2012-07-20 15:41:35 UTC (rev 29939)
@@ -14,7 +14,6 @@
 import javax.swing.LayoutStyle;
 
 import org.jfree.chart.ChartPanel;
-import org.jfree.chart.JFreeChart;
 
 public class PanelLayout {
 

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to