Source Code Cross Referenced for AxisGraph.java in  » Testing » jakarta-jmeter » org » apache » jmeter » visualizers » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » jakarta jmeter » org.apache.jmeter.visualizers 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         * http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
013:         * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
014:         * License for the specific language governing permissions and limitations
015:         * under the License.
016:         *  
017:         */
018:        package org.apache.jmeter.visualizers;
019:
020:        import java.awt.Color;
021:        import java.awt.Dimension;
022:        import java.awt.Graphics;
023:        import java.awt.Graphics2D;
024:        import java.awt.LayoutManager;
025:        import java.awt.Paint;
026:        import java.math.BigDecimal;
027:
028:        import javax.swing.JPanel;
029:
030:        import org.apache.jorphan.logging.LoggingManager;
031:        import org.apache.log.Logger;
032:        import org.jCharts.axisChart.AxisChart;
033:        import org.jCharts.axisChart.customRenderers.axisValue.renderers.ValueLabelPosition;
034:        import org.jCharts.axisChart.customRenderers.axisValue.renderers.ValueLabelRenderer;
035:        import org.jCharts.chartData.AxisChartDataSet;
036:        import org.jCharts.chartData.ChartDataException;
037:        import org.jCharts.chartData.DataSeries;
038:        import org.jCharts.properties.AxisProperties;
039:        import org.jCharts.properties.BarChartProperties;
040:        import org.jCharts.properties.ChartProperties;
041:        import org.jCharts.properties.DataAxisProperties;
042:        import org.jCharts.properties.LabelAxisProperties;
043:        import org.jCharts.properties.LegendProperties;
044:        import org.jCharts.properties.PropertyException;
045:        import org.jCharts.types.ChartType;
046:
047:        /**
048:         *
049:         * Axis graph is used by StatGraphVisualizer, which generates bar graphs
050:         * from the statistical data.
051:         */
052:        public class AxisGraph extends JPanel {
053:
054:            private static final Logger log = LoggingManager
055:                    .getLoggerForClass();
056:
057:            private static final String ELLIPSIS = "..."; //$NON-NLS-1$
058:            private static final int ELLIPSIS_LEN = ELLIPSIS.length();
059:
060:            protected double[][] data = null;
061:            protected String title, xAxisTitle, yAxisTitle, yAxisLabel;
062:            protected int maxLength;
063:            protected String[] xAxisLabels;
064:            protected int width, height;
065:
066:            /**
067:             * 
068:             */
069:            public AxisGraph() {
070:                super ();
071:            }
072:
073:            /**
074:             * @param layout
075:             */
076:            public AxisGraph(LayoutManager layout) {
077:                super (layout);
078:            }
079:
080:            /**
081:             * @param layout
082:             * @param isDoubleBuffered
083:             */
084:            public AxisGraph(LayoutManager layout, boolean isDoubleBuffered) {
085:                super (layout, isDoubleBuffered);
086:            }
087:
088:            public void setData(double[][] data) {
089:                this .data = data;
090:            }
091:
092:            public void setTitle(String title) {
093:                this .title = title;
094:            }
095:
096:            public void setMaxLength(int maxLength) {
097:                this .maxLength = maxLength;
098:            }
099:
100:            public void setXAxisTitle(String title) {
101:                this .xAxisTitle = title;
102:            }
103:
104:            public void setYAxisTitle(String title) {
105:                this .yAxisTitle = title;
106:            }
107:
108:            public void setXAxisLabels(String[] labels) {
109:                this .xAxisLabels = labels;
110:            }
111:
112:            public void setYAxisLabels(String label) {
113:                this .yAxisLabel = label;
114:            }
115:
116:            public void setWidth(int w) {
117:                this .width = w;
118:            }
119:
120:            public void setHeight(int h) {
121:                this .height = h;
122:            }
123:
124:            public void paintComponent(Graphics g) {
125:                if (data != null && this .title != null
126:                        && this .xAxisLabels != null && this .xAxisTitle != null
127:                        && this .yAxisLabel != null && this .yAxisTitle != null) {
128:                    drawSample(this .title, this .maxLength, this .xAxisLabels,
129:                            this .xAxisTitle, this .yAxisTitle, this .data,
130:                            this .width, this .height, g);
131:                }
132:            }
133:
134:            private double findMax(double _data[][]) {
135:                double max = 0;
136:                max = _data[0][0];
137:                for (int i = 0; i < _data.length; i++) {
138:                    for (int j = 0; j < _data[i].length; j++) {
139:                        if (_data[i][j] > max) {
140:                            max = _data[i][j];
141:                        }
142:                    }
143:                }
144:                return max;
145:            }
146:
147:            private String squeeze(String input, int _maxLength) {
148:                if (input.length() > _maxLength) {
149:                    String output = input.substring(0, _maxLength
150:                            - ELLIPSIS_LEN)
151:                            + ELLIPSIS;
152:                    return output;
153:                }
154:                return input;
155:            }
156:
157:            private void drawSample(String _title, int _maxLength,
158:                    String[] _xAxisLabels, String _xAxisTitle,
159:                    String _yAxisTitle, double[][] _data, int _width,
160:                    int _height, Graphics g) {
161:                double max = findMax(_data);
162:                try {
163:                    /** These controls are already done in StatGraphVisualizer
164:                    if (_width == 0) {
165:                        _width = 450;
166:                    }
167:                    if (_height == 0) {
168:                        _height = 250;
169:                    }
170:                     **/
171:                    if (_maxLength < 3) {
172:                        _maxLength = 3;
173:                    }
174:                    // if the "Title of Graph" is empty, we can assume some default
175:                    if (_title.length() == 0) {
176:                        _title = "Graph";
177:                    }
178:                    // if the labels are too long, they'll be "squeezed" to make the chart viewable.
179:                    for (int i = 0; i < _xAxisLabels.length; i++) {
180:                        String label = _xAxisLabels[i];
181:                        _xAxisLabels[i] = squeeze(label, _maxLength);
182:                    }
183:                    this .setPreferredSize(new Dimension(_width, _height));
184:                    DataSeries dataSeries = new DataSeries(_xAxisLabels,
185:                            _xAxisTitle, _yAxisTitle, _title);
186:
187:                    String[] legendLabels = { yAxisLabel };
188:                    Paint[] paints = new Paint[] { Color.yellow };
189:                    BarChartProperties barChartProperties = new BarChartProperties();
190:                    ValueLabelRenderer valueLabelRenderer = new ValueLabelRenderer(
191:                            false, false, true, 0);
192:                    valueLabelRenderer
193:                            .setValueLabelPosition(ValueLabelPosition.AT_TOP);
194:                    valueLabelRenderer.useVerticalLabels(true);
195:                    barChartProperties
196:                            .addPostRenderEventListener(valueLabelRenderer);
197:                    AxisChartDataSet axisChartDataSet = new AxisChartDataSet(
198:                            _data, legendLabels, paints, ChartType.BAR,
199:                            barChartProperties);
200:                    dataSeries.addIAxisPlotDataSet(axisChartDataSet);
201:
202:                    ChartProperties chartProperties = new ChartProperties();
203:                    LabelAxisProperties xaxis = new LabelAxisProperties();
204:                    DataAxisProperties yaxis = new DataAxisProperties();
205:
206:                    try {
207:                        BigDecimal round = new BigDecimal(max / 1000d);
208:                        round = round.setScale(0, BigDecimal.ROUND_UP);
209:                        double topValue = round.doubleValue() * 1000;
210:                        yaxis.setUserDefinedScale(0, 500);
211:                        yaxis.setNumItems((int) (topValue / 500) + 1);
212:                        yaxis.setShowGridLines(1);
213:                    } catch (PropertyException e) {
214:                        log.warn("", e);
215:                    }
216:
217:                    AxisProperties axisProperties = new AxisProperties(xaxis,
218:                            yaxis);
219:                    axisProperties.setXAxisLabelsAreVertical(true);
220:                    LegendProperties legendProperties = new LegendProperties();
221:                    AxisChart axisChart = new AxisChart(dataSeries,
222:                            chartProperties, axisProperties, legendProperties,
223:                            _width, _height);
224:                    axisChart.setGraphics2D((Graphics2D) g);
225:                    axisChart.render();
226:                } catch (ChartDataException e) {
227:                    log.warn("", e);
228:                } catch (PropertyException e) {
229:                    log.warn("", e);
230:                }
231:            }
232:
233:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.