]> git.ipfire.org Git - thirdparty/AWStats.git/commitdiff
Added experimental graphapplet plugin.
authoreldy <>
Tue, 18 Nov 2003 23:25:23 +0000 (23:25 +0000)
committereldy <>
Tue, 18 Nov 2003 23:25:23 +0000 (23:25 +0000)
wwwroot/cgi-bin/plugins/graphapplet.pm
wwwroot/classes/awgraphapplet.jar
wwwroot/classes/src/AWGraphApplet.java

index 9d036021c669a36a97c84b5cf0750ce1065cb6e7..cbf1eb1d949d5dbc1fffb1225ceba8f21be89d14 100644 (file)
@@ -81,7 +81,7 @@ sub ShowGraph_graphapplet() {
        print "<applet name=\"$type\" archive=\"awgraphapplet.jar\" code=\"AWGraphApplet.class\" codebase=\"/classes\" width=\"$graphwidth\" height=\"$graphheight\" alt= \"Your browser does not support Java correctly. Change browser or disable AWStats graphapplet plugin.\">\n";
 print <<EOF;
 <param name="title" value="$title" />
-<param name="awstats_type" value="$type" />
+<param name="special" value="$type" />
 <param name="orientation" value="vertical" />
 <param name="barsize" value="$barsize" />
 <param name="background_color" value="$color_Background" />
index 26b25060de6805fb4f8168597a2029ca09346cb4..f0219363fbcf9920d09ad9dc7e1c5cf69e25af2a 100644 (file)
Binary files a/wwwroot/classes/awgraphapplet.jar and b/wwwroot/classes/awgraphapplet.jar differ
index 78d61a052c50d2f278339f450f877892d82647b6..58a0e5e9768b35a5fd2c55bd535d9d29afa3f563 100644 (file)
@@ -1,93 +1,76 @@
 /*
- * @(#)Graph3Dapplet.java 1.0 03/11/03
+ * @(#)AWGraphApplet.java 1.0 03/11/03
  *
  */
 
+import java.applet.Applet;\r
 import java.awt.*;
-import java.applet.*;
-//import awgraphapplet.logs.*;
+import java.util.Vector;
 
 
-public class AWGraphApplet extends java.applet.Applet {
+public class AWGraphApplet extends Applet
+{
        
-    private static final int VERTICAL = 0;
-    private static final int HORIZONTAL = 1;
-    private static final int SOLID = 0;
-    private static final int STRIPED = 1;
+    public AWGraphApplet()\r
+    {\r
+        special = "Not yet defined";
+        b_fontsize = 11;\r
+        blockSpacing = 5;\r
+        valSpacing = 0;\r
+        valWidth = 5;\r
+        maxLabelWidth = 0;\r
+        background_color = Color.white;\r
+        border_color = Color.white;\r
+        backgraph_colorl = Color.decode("#F6F6F6");\r
+        backgraph_colorm = Color.decode("#EDEDED");\r
+        backgraph_colorh = Color.decode("#E0E0E0");\r
+    }\r
 
-       private static final int DEBUG=3;
-       private static final int SHIFTBAR=3;
+//    public synchronized void init() {
+    public synchronized void start()
+    {
+        special = getParameter("special");
+        if (special == null) { special = ""; }
 
-    private String title;
-    private Font font;
-    private FontMetrics metrics;
-    private int orientation;
-    private int barsize;
+        Log("Applet "+VERSION+" ($Revision$) init");
 
-    private int nbblocks;
-    private String blabels[];
-       private int b_fontsize=11;
-    private int blockSpacing = 5;
-       
-    private int nbvalues;
-    private Color colors[];
-    private String vlabels[];
-    private int styles[];
-    private float max[];
-    private int valSpacing = 0;
-    private int valWidth = 5;
+        String s = getParameter("b_fontsize");
+        if (s != null) { b_fontsize = Integer.parseInt(s); }
 
-    private float values[][];
+        title = getParameter("title");
+        if (title == null) { title = "Chart"; }
 
-    private int maxLabelWidth = 0;
-       private Color background_color = Color.white;
-       private Color border_color = Color.white;
-       private Color backgraph_colorl = Color.decode("#F6F6F6");
-       private Color backgraph_colorm = Color.decode("#EDEDED");
-       private Color backgraph_colorh = Color.decode("#E0E0E0");
+        s = getParameter("nbblocks");
+        if (s != null) { nbblocks = Integer.parseInt(s); }
 
+        s = getParameter("nbvalues");
+        if (s != null) { nbvalues = Integer.parseInt(s); }
 
-//    public synchronized void init() {
-    public synchronized void start() {
-        Log("Applet init");
-  
-        String temp = getParameter("b_fontsize");
-        if (temp != null) { b_fontsize = Integer.parseInt(temp); }
-               
-        title = getParameter("title");
-        if (title == null) { title = "Chart"; }
-        
-        temp = getParameter("nbblocks");
-        if (temp != null) { nbblocks = Integer.parseInt(temp); }
+        s = getParameter("blockspacing");
+        if (s != null) { blockSpacing = Integer.parseInt(s); }
+        s = getParameter("valspacing");
+        if (s != null) { valSpacing = Integer.parseInt(s); }
+        s = getParameter("valwidth");
+        if (s != null) { valWidth = Integer.parseInt(s); }
 
-        temp = getParameter("nbvalues");
-        if (temp != null) { nbvalues = Integer.parseInt(temp); }
-        
-        temp = getParameter("blockspacing");
-        if (temp != null) { blockSpacing = Integer.parseInt(temp); }
-        temp = getParameter("valspacing");
-        if (temp != null) { valSpacing = Integer.parseInt(temp); }
-        temp = getParameter("valwidth");
-        if (temp != null) { valWidth = Integer.parseInt(temp); }
-
-        temp = getParameter("orientation");
-        if (temp == null) { orientation = VERTICAL; }
-        else if (temp.equalsIgnoreCase("horizontal")) { orientation = HORIZONTAL; }
+        s = getParameter("orientation");
+        if (s == null) { orientation = VERTICAL; }
+        else if (s.equalsIgnoreCase("horizontal")) { orientation = HORIZONTAL; }
         else { orientation = VERTICAL; }
-        temp = getParameter("barsize");
-        if (temp != null) { barsize = Integer.parseInt(temp); }
+        s = getParameter("barsize");
+        if (s != null) { barsize = Integer.parseInt(s); }
 
-               temp = getParameter("background_color");
-        if (temp != null) { background_color = Color.decode("#"+temp); }
-               temp = getParameter("border_color");
-        if (temp != null) { border_color = Color.decode("#"+temp); }
+               s = getParameter("background_color");
+        if (s != null) { background_color = Color.decode("#"+s); }
+               s = getParameter("border_color");
+        if (s != null) { border_color = Color.decode("#"+s); }
 
         Log("bblocks "+nbblocks);
         Log("nbvalues "+nbvalues);
         Log("barsize "+barsize);
         
-        font = new java.awt.Font("Verdana", 0, b_fontsize);
-        metrics = getFontMetrics(font);
+               font = new Font("Verdana", 0, b_fontsize);\r
+        fontmetrics = getFontMetrics(font);
         
         blabels = new String[nbblocks];
         vlabels = new String[nbvalues];
@@ -107,150 +90,246 @@ public class AWGraphApplet extends java.applet.Applet {
             parseValue(j);
                }
         for (int i=0; i < nbvalues; i++) {
-                       if (max[i]<=0) { max[i]=1; }
+                       if (max[i]<=0.0F) { max[i]=1.0F; }
                        Log("max["+i+"]="+max[i]);
                }
     }
             
-       private synchronized void Log(String s) {
-//                     Trace.debug(1,s);
-               System.out.println(s);
+       private synchronized void Log(String s)
+       {
+               System.out.println(getClass().getName()+" ("+special+"): "+s);
        }
                
-    private synchronized void parsebLabel(int i) {
-        String temp = getParameter("b" + (i+1) + "_label");
-        if (temp==null) {
+    private synchronized void parsebLabel(int i)
+    {
+        String s = getParameter("b" + (i+1) + "_label");
+        if (s==null) {
             blabels[i] = "";
         } else {
-            blabels[i] = temp;
+            blabels[i] = s;
         }
-        maxLabelWidth = Math.max(metrics.stringWidth ((String) (blabels[i])), maxLabelWidth);
+        maxLabelWidth = Math.max(fontmetrics.stringWidth(blabels[i]), maxLabelWidth);
     }
 
-    private synchronized void parseLabel(int i) {
-        String temp = getParameter("v" + (i+1) + "_label");
-        if (temp==null) {
+    private synchronized void parseLabel(int i)
+    {
+        String s = getParameter("v" + (i+1) + "_label");
+        if (s==null) {
             vlabels[i] = "";
         } else {
-            vlabels[i] = temp;
+            vlabels[i] = s;
         }
     }
 
-    private synchronized void parseStyle(int i) {
-        String temp = getParameter("v" + (i+1) + "_style");
-        if (temp == null || temp.equalsIgnoreCase("solid")) {
+    private synchronized void parseStyle(int i)
+    {
+        String s = getParameter("v" + (i+1) + "_style");
+        if (s == null || s.equalsIgnoreCase("solid")) {
             styles[i] = SOLID;
-        } else if (temp.equalsIgnoreCase("striped")) {
+        } else if (s.equalsIgnoreCase("striped")) {
             styles[i] = STRIPED;
         } else {
             styles[i] = SOLID;
         }
     }
     
-    private synchronized void parseColor(int i) {
-        String temp = getParameter("v" + (i+1) + "_color");
-        if (temp != null) {
-            colors[i] = Color.decode("#"+temp);
+    private synchronized void parseColor(int i)
+    {
+        String s = getParameter("v" + (i+1) + "_color");
+        if (s != null) {
+            colors[i] = Color.decode("#"+s);
         } else {
             colors[i] = Color.gray;
         }
     }
 
-    private synchronized void parseMax(int i) {
-        String temp = getParameter("v" + (i+1) + "_max");
-        if (temp != null) {
-            max[i] = Float.parseFloat(temp);
+    private synchronized void parseMax(int i)
+    {
+        String s = getParameter("v" + (i+1) + "_max");
+        if (s != null) {
+                       max[i] = Float.valueOf(s).floatValue();
         } else {
-            max[i] = 1;
+            max[i] = 1.0F;
         }
     }
 
-    private synchronized void parseValue(int j) {
-        String temp = getParameter("b" + (j+1));
-               if (temp != null) {
-               String[] ss=temp.split(" ",0);
-               for (int i=0; i<ss.length; i++) {
-//                             Log("ss="+ss[i]);
-                   values[j][i] = Float.parseFloat(ss[i]);
-//                             Log("values["+j+"]["+i+"]="+values[j][i]);
+    private synchronized void parseValue(int i)
+    {
+        String s = getParameter("b" + (i+1));
+               if (s != null) {
+               String[] as=split(s," ",0);
+               for (int j=0; j<as.length; j++) {
+//                             Log("as="+as[j]);
+                   values[i][j] = Float.parseFloat(as[j]);
+//                             Log("values["+i+"]["+j+"]="+values[i][j]);
                        }
            }
     }
 
-    
-    public synchronized void paint(Graphics g) {
-
+       private String[] split(String s, String c, int iStart)
+       {\r
+               Vector v = new Vector();\r
+               boolean bFin = false;\r
+               String sub = "";\r
+               int i=iStart-1;\r
+               int iOld = i;\r
+               //System.out.println("s = " + s);\r
+               while (!bFin) {\r
+                       iOld = i;\r
+                       i = s.indexOf(c, iOld+1);\r
+                       if (i!=-1) {\r
+                               //System.out.println("i = " + i);\r
+                               sub = s.substring(iOld+1, i);\r
+                       } else {\r
+                               sub = s.substring(iOld+1, s.length());\r
+                               bFin=true;\r
+                       }\r
+                       //System.out.println("sub = " + sub);\r
+                       v.addElement(sub);\r
+               }\r
+               String[] tabS = new String[v.size()];\r
+               for (i=0 ; i<v.size() ; i++) {\r
+                       tabS[i] = (String)v.elementAt(i);\r
+               }\r
+               return tabS;\r
+       }\r
+
+       private String remove(String s, String c)
+       {\r
+               Vector v = new Vector();\r
+               boolean bFin = false;\r
+               String sub = "";\r
+               int i=-1;\r
+               int iOld = i;\r
+               //System.out.println("s = " + s);\r
+               while (!bFin) {\r
+                       iOld = i;\r
+                       i = s.indexOf(c, iOld+1);\r
+                       if (i!=-1) {\r
+                               //System.out.println("i = " + i);\r
+                               sub = s.substring(iOld+1, i);\r
+                       } else {\r
+                               sub = s.substring(iOld+1, s.length());\r
+                               bFin=true;\r
+                       }\r
+                       //System.out.println("sub = " + sub);\r
+                       v.addElement(sub);\r
+               }\r
+               sub = "";
+               for (i=0 ; i<v.size() ; i++) {\r
+                       sub += (String)v.elementAt(i);\r
+               }\r
+               return sub;\r
+       }\r
+
+       private Graphics bfr;\r
+       private Image img;\r
+\r
+       public void init()
+       {\r
+               img = createImage(this.getSize().width, this.getSize().height);\r
+               bfr = img.getGraphics();\r
+       }\r
+
+    public synchronized void paint(Graphics g)
+    {
                // background and border
-               g.setColor(background_color);
-               g.fillRect(0,0,getSize().width-1,getSize().height-1);
-               g.setColor(border_color);
-               g.drawRect(0,0,getSize().width-1,getSize().height-1);
-               
+        bfr.setColor(background_color);\r
+        bfr.fillRect(0, 0, getSize().width - 1, getSize().height - 1);\r
+        bfr.setColor(border_color);\r
+        bfr.drawRect(0, 0, getSize().width - 1, getSize().height - 1);\r
+
                // draw the bars and their titles
-               if(orientation == HORIZONTAL) { paintHorizontal(g); }
-               else { paintVertical(g); }
+               if(orientation == HORIZONTAL) { paintHorizontal(bfr); }
+               else { paintVertical(bfr); }
+
+               g.drawImage(this.img, 0, 0, this);\r
     }
         
-       private synchronized void draw3DBar(Graphics g,int x, int y, float w, float h, int shift, Color c) {
+       private synchronized void draw3DBar(Graphics g,int x, int y, float w, float h, int shift, Color color)
+       {
                // Draw a 3D bar at pos (x,y)
-               Polygon p = new Polygon();
+               Polygon polygon = new Polygon();
                int width=new Float(w).intValue();
                int height=new Float(h).intValue();
 //             Log("draw3DBar "+x+","+y+","+w+"=>"+width+","+h+"=>"+height);
-               
-               p.addPoint(x,y);p.addPoint(x+width,y);
-               p.addPoint(x+width,y-height);p.addPoint(x,y-height);
-               g.setColor(c); g.fillPolygon(p); g.setColor(c.darker());
-               g.drawPolygon(p);
-               Polygon p2 = new Polygon();
-               p2.addPoint(x+width,y);p2.addPoint(x+width+shift,y-shift);
-               p2.addPoint(x+width+shift,y-shift-height);p2.addPoint(x+width,y-height);
-               g.setColor(c.darker()); g.fillPolygon(p2); g.setColor(c.darker().darker());
-               g.drawPolygon(p2);
-               Polygon p3 = new Polygon();
-               p3.addPoint(x,y-height);p3.addPoint(x+width,y-height);
-               p3.addPoint(x+width+shift,y-height-shift);p3.addPoint(x+shift,y-height-shift);
-               g.setColor(c); g.fillPolygon(p3); g.setColor(c.darker());
-               g.drawPolygon(p3);
-       }
 
-    private synchronized void paintHorizontal(Graphics g) {
+               polygon.addPoint(x,y);
+               polygon.addPoint(x+width,y);
+               polygon.addPoint(x+width,y-height);
+               polygon.addPoint(x,y-height);
+               g.setColor(color);
+               g.fillPolygon(polygon);
+               g.setColor(color.darker());
+               g.drawPolygon(polygon);
+               Polygon polygon2 = new Polygon();
+               polygon2.addPoint(x+width,y);
+               polygon2.addPoint(x+width+shift,y-shift);
+               polygon2.addPoint(x+width+shift,y-shift-height);
+               polygon2.addPoint(x+width,y-height);
+               g.setColor(color.darker());
+               g.fillPolygon(polygon2);
+               g.setColor(color.darker().darker());
+               g.drawPolygon(polygon2);
+               Polygon polygon3 = new Polygon();
+               polygon3.addPoint(x,y-height);
+               polygon3.addPoint(x+width,y-height);
+               polygon3.addPoint(x+width+shift,y-height-shift);
+               polygon3.addPoint(x+shift,y-height-shift);
+               g.setColor(color);
+               g.fillPolygon(polygon3);
+               g.setColor(color.darker());
+               g.drawPolygon(polygon3);
+       }
 
-    }
-    
-    private synchronized void paintVertical(Graphics g) {
+    private synchronized void paintHorizontal(Graphics g)\r
+    {\r
+    }\r
 
-               Font font = new java.awt.Font("Verdana", 0, b_fontsize);
-               FontMetrics metrics = getFontMetrics(font);
+    private synchronized void paintVertical(Graphics g)
+    {
+               Font font1 = new java.awt.Font("Verdana", 0, b_fontsize);
+               FontMetrics fontmetrics = getFontMetrics(font1);
                g.setColor(Color.black);
-               g.setFont(font);
+               g.setFont(font1);
 
                int shift=10;
                int allbarwidth=(((nbvalues*(valWidth+valSpacing))+blockSpacing)*nbblocks);
                int allbarheight=barsize;
                int axepointx=(getSize().width-allbarwidth)/2 - 2*shift;
-        int axepointy = getSize().height - (2*metrics.getHeight()) - metrics.getDescent();
+        int axepointy = getSize().height - (2*fontmetrics.getHeight()) - fontmetrics.getDescent();
 
                int cx=axepointx;
                int cy=axepointy;
 
                // Draw axes
-               Polygon p = new Polygon();
-               p.addPoint(cx,cy);p.addPoint(cx+allbarwidth+3*shift,cy);
-               p.addPoint(cx+allbarwidth+4*shift,cy-shift);p.addPoint(cx+shift,cy-shift);
-               g.setColor(backgraph_colorl); g.fillPolygon(p); g.setColor(Color.LIGHT_GRAY);
-               g.drawPolygon(p);
-               Polygon p2 = new Polygon();
-               p2.addPoint(cx,cy);p2.addPoint(cx+shift,cy-shift);
-               p2.addPoint(cx+shift,cy-shift-barsize);p2.addPoint(cx,cy-barsize);
-               g.setColor(backgraph_colorh); g.fillPolygon(p2); g.setColor(Color.LIGHT_GRAY);
-               g.drawPolygon(p2);
-               Polygon p3 = new Polygon();
-               p3.addPoint(cx+shift,cy-shift);p3.addPoint(cx+allbarwidth+4*shift,cy-shift);
-               p3.addPoint(cx+allbarwidth+4*shift,cy-shift-barsize);p3.addPoint(cx+shift,cy-shift-barsize);
-               g.setColor(backgraph_colorm); g.fillPolygon(p3); g.setColor(Color.LIGHT_GRAY);
-               g.drawPolygon(p3);
-
+               Polygon polygon = new Polygon();
+               polygon.addPoint(cx,cy);
+               polygon.addPoint(cx+allbarwidth+3*shift,cy);
+               polygon.addPoint(cx+allbarwidth+4*shift,cy-shift);
+               polygon.addPoint(cx+shift,cy-shift);
+               g.setColor(backgraph_colorl);
+               g.fillPolygon(polygon);
+               g.setColor(Color.lightGray);
+               g.drawPolygon(polygon);
+               Polygon polygon2 = new Polygon();
+               polygon2.addPoint(cx,cy);
+               polygon2.addPoint(cx+shift,cy-shift);
+               polygon2.addPoint(cx+shift,cy-shift-barsize);
+               polygon2.addPoint(cx,cy-barsize);
+               g.setColor(backgraph_colorh);
+               g.fillPolygon(polygon2);
+               g.setColor(Color.lightGray);
+               g.drawPolygon(polygon2);
+               Polygon polygon3 = new Polygon();
+               polygon3.addPoint(cx+shift,cy-shift);
+               polygon3.addPoint(cx+allbarwidth+4*shift,cy-shift);
+               polygon3.addPoint(cx+allbarwidth+4*shift,cy-shift-barsize);
+               polygon3.addPoint(cx+shift,cy-shift-barsize);
+               g.setColor(backgraph_colorm);
+               g.fillPolygon(polygon3);
+               g.setColor(Color.lightGray);
+               g.drawPolygon(polygon3);
 
                cx+=2*shift;
                
@@ -259,31 +338,31 @@ public class AWGraphApplet extends java.applet.Applet {
 
             // Draw the block label
 //                     Log("Write block j="+j+" with cx="+cx);
-            cy = getSize().height - metrics.getHeight() - metrics.getDescent();
+            cy = getSize().height - fontmetrics.getHeight() - fontmetrics.getDescent();
             g.setColor(Color.black);
                        // Check if bold or highlight
                        int bold=0; int highlight=0;
-                       if (blabels[j].indexOf(":")>0) { bold=1; blabels[j]=blabels[j].replaceAll(":",""); }
-                       if (blabels[j].indexOf("!")>0) { highlight=1; blabels[j]=blabels[j].replaceAll("!",""); }
+                       if (blabels[j].indexOf(":")>0) { bold=1; blabels[j]=remove(blabels[j],":"); }
+                       if (blabels[j].indexOf("!")>0) { highlight=1; blabels[j]=remove(blabels[j],"!"); }
 
-            String[] ss=blabels[j].split("ยง",0);
-            for (int i=0; i<ss.length; i++) {
-                   int cxoffset=((nbvalues*(valWidth+valSpacing))-metrics.stringWidth(ss[i]))>>1;
+                       String as[] = split(blabels[j], "\247", 0);\r
+            for (int i=0; i<as.length; i++) {
+                   int cxoffset=((nbvalues*(valWidth+valSpacing))-fontmetrics.stringWidth(as[i]))>>1;
                    if (cxoffset<0) { cxoffset=0; }
-                   g.drawString(ss[i], cx+cxoffset, cy);
-                               cy+=metrics.getHeight()-2;
+                   g.drawString(as[i], cx+cxoffset, cy);
+                               cy+=fontmetrics.getHeight()-2;
                        }
 
                        // Loop on each value
                for (int i = 0; i < nbvalues; i++) {
        
-                   cy = getSize().height - metrics.getHeight() - metrics.getDescent() - 4;
-                   cy -= metrics.getHeight() - 4;
+                   cy = getSize().height - fontmetrics.getHeight() - fontmetrics.getDescent() - 4;
+                   cy -= fontmetrics.getHeight() - 4;
        
                    // draw the shadow and bar
-                               draw3DBar(g,cx,cy,valWidth,values[j][i]*barsize/max[i],SHIFTBAR,colors[i]);
+                               draw3DBar(g,cx,cy,valWidth,(values[j][i]*(float)barsize)/max[i],SHIFTBAR,colors[i]);
 
-                   cy -= values[j][i] + 5;
+                               cy = (int)((float)cy - (values[j][i] + 5F));\r
                    cx += (valWidth + valSpacing);
                        }
 
@@ -291,16 +370,57 @@ public class AWGraphApplet extends java.applet.Applet {
         }
     }    
     
-    public synchronized String getAppletInfo() {
-        return "Title: "+title+"\n";
+    public synchronized String getAppletInfo()
+    {
+        return "Title: " + title + "\n";
     }
     
-    public synchronized String[][] getParameterInfo() {
-        String[][] info = {
-            {"title", "string", "The title of bar graph."}
+    public synchronized String[][] getParameterInfo()
+    {
+        String[][] as = {
+            {"version", "string", "AWGraphApplet 1.0"},
+            {"copyright", "string", "GPL"},
+            {"title", "string", title}
         };
-        return info;
+        return as;
     }
+
+    private static final int VERTICAL = 0;
+    private static final int HORIZONTAL = 1;
+    private static final int SOLID = 0;
+    private static final int STRIPED = 1;
+       private static final int DEBUG = 3;
+       private static final int SHIFTBAR = 3;
+       private static final String VERSION = "1.0";
+
+    private String title;
+    private String special;
+    private Font font;
+    private FontMetrics fontmetrics;
+    private int orientation;
+    private int barsize;
+
+    private int nbblocks;
+    private String blabels[];
+       private int b_fontsize;
+    private int blockSpacing;
+       
+    private int nbvalues;
+    private Color colors[];
+    private String vlabels[];
+    private int styles[];
+    private float max[];
+    private int valSpacing;
+    private int valWidth;
+
+    private float values[][];
+
+    private int maxLabelWidth;
+       private Color background_color;
+       private Color border_color;
+       private Color backgraph_colorl;
+       private Color backgraph_colorm;
+       private Color backgraph_colorh;
 }