From: eldy <> Date: Tue, 18 Nov 2003 23:25:23 +0000 (+0000) Subject: Added experimental graphapplet plugin. X-Git-Tag: AWSTATS_6_0_BETA~96 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3c473746074c36c8c64e098bad67bf5ba8afe407;p=thirdparty%2FAWStats.git Added experimental graphapplet plugin. --- diff --git a/wwwroot/cgi-bin/plugins/graphapplet.pm b/wwwroot/cgi-bin/plugins/graphapplet.pm index 9d036021..cbf1eb1d 100644 --- a/wwwroot/cgi-bin/plugins/graphapplet.pm +++ b/wwwroot/cgi-bin/plugins/graphapplet.pm @@ -81,7 +81,7 @@ sub ShowGraph_graphapplet() { print "\n"; print < - + diff --git a/wwwroot/classes/awgraphapplet.jar b/wwwroot/classes/awgraphapplet.jar index 26b25060..f0219363 100644 Binary files a/wwwroot/classes/awgraphapplet.jar and b/wwwroot/classes/awgraphapplet.jar differ diff --git a/wwwroot/classes/src/AWGraphApplet.java b/wwwroot/classes/src/AWGraphApplet.java index 78d61a05..58a0e5e9 100644 --- a/wwwroot/classes/src/AWGraphApplet.java +++ b/wwwroot/classes/src/AWGraphApplet.java @@ -1,93 +1,76 @@ /* - * @(#)Graph3Dapplet.java 1.0 03/11/03 + * @(#)AWGraphApplet.java 1.0 03/11/03 * */ +import java.applet.Applet; 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() + { + special = "Not yet defined"; + b_fontsize = 11; + blockSpacing = 5; + valSpacing = 0; + valWidth = 5; + maxLabelWidth = 0; + background_color = Color.white; + border_color = Color.white; + backgraph_colorl = Color.decode("#F6F6F6"); + backgraph_colorm = Color.decode("#EDEDED"); + backgraph_colorh = Color.decode("#E0E0E0"); + } - 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); + 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"+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) + { + } - 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>1; + String as[] = split(blabels[j], "\247", 0); + for (int i=0; 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)); 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; }