Source Code Cross Referenced for StackedChartDataModelConstraints.java in  » Chart » charting-0.94 » de » progra » charting » model » 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 » Chart » charting 0.94 » de.progra.charting.model 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:            JOpenChart Java Charting Library and Toolkit
003:            Copyright (C) 2001  Sebastian Müller
004:            http://jopenchart.sourceforge.net
005:
006:            This library is free software; you can redistribute it and/or
007:            modify it under the terms of the GNU Lesser General Public
008:            License as published by the Free Software Foundation; either
009:            version 2.1 of the License, or (at your option) any later version.
010:
011:            This library is distributed in the hope that it will be useful,
012:            but WITHOUT ANY WARRANTY; without even the implied warranty of
013:            MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:            Lesser General Public License for more details.
015:
016:            You should have received a copy of the GNU Lesser General Public
017:            License along with this library; if not, write to the Free Software
018:            Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:
020:            StackedChartDataModelConstraints.java
021:            Created on 26. Sept. 2002
022:         */
023:
024:        package de.progra.charting.model;
025:
026:        import de.progra.charting.ChartUtilities;
027:        import de.progra.charting.CoordSystem;
028:        import java.util.TreeSet;
029:
030:        /**
031:         * Implementing the ChartDataModelConstraints this class provides an implementation
032:         * for the data model constraints where the maximum value is the sum of all 
033:         * positive values and the minimum value is the sum of all negative values.
034:         * @author  smueller
035:         */
036:        public class StackedChartDataModelConstraints implements 
037:                ChartDataModelConstraints {
038:
039:            /** The model for which to calculate the constraints. */
040:            protected AbstractChartDataModel model;
041:
042:            /** The axis to compute the constraints. */
043:            protected int axis;
044:
045:            /** A flag which determines if column values should be manually scalable. */
046:            protected boolean allowManualColScale = true;
047:
048:            /** Creates a new instance of DefaultChartDataModelConstraints */
049:            public StackedChartDataModelConstraints(
050:                    AbstractChartDataModel model, int axis) {
051:                this .model = model;
052:                this .axis = axis;
053:            }
054:
055:            /** Creates a new instance of DefaultChartDataModelConstraints
056:             * @param model the AbstractDataModel for which constraints will be computed
057:             * @param axis the y-axis which will be considered
058:             * @param allowManualScale a flag which triggers if column values should 
059:             * be allowed to be scaled manually (default is yes)
060:             */
061:            public StackedChartDataModelConstraints(
062:                    AbstractChartDataModel model, int axis,
063:                    boolean allowManualColScale) {
064:                this (model, axis);
065:                this .allowManualColScale = allowManualColScale;
066:            }
067:
068:            /** Returns the maximum value of all datasets.  */
069:            public Number getMaximumValue() {
070:                int minimumDataSetLength = Integer.MAX_VALUE;
071:                double maxvalue = 0.0;
072:                double minvalue = 0.0;
073:
074:                double columnminvalue = Double.MAX_VALUE;
075:                double columnmaxvalue = Double.MIN_VALUE;
076:
077:                for (int i = 0; i < model.getDataSetNumber(); i++) {
078:                    minimumDataSetLength = Math.min(minimumDataSetLength, model
079:                            .getDataSetLength(i));
080:                }
081:
082:                double value = 0.0;
083:
084:                for (int i = 0; i < minimumDataSetLength; i++) {
085:                    for (int j = 0; j < model.getDataSetNumber(); j++) {
086:                        value = model.getValueAt(j, i).doubleValue();
087:                        if (value < 0)
088:                            columnminvalue += value;
089:                        else
090:                            columnmaxvalue += value;
091:                    }
092:                    minvalue = Math.min(columnminvalue, minvalue);
093:                    columnminvalue = 0.0;
094:                    maxvalue = Math.max(columnmaxvalue, maxvalue);
095:                    columnmaxvalue = 0.0;
096:                }
097:
098:                if (model.getOrderedValues(CoordSystem.FIRST_YAXIS).size() == 0
099:                        || (maxvalue == 0.0 && minvalue == 0.0))
100:                    return new Integer(1);
101:                else if (model.isManualScale()) {
102:                    return new Double(Math.max(model.getManualMaximumValue()
103:                            .doubleValue(), maxvalue));
104:                } else if (model.isAutoScale()) {
105:                    if (minvalue / maxvalue > 0.95) {
106:                        //System.out.println("** ChartUtilities.performAutoScale(min/2, 2 * max)[1]"+ChartUtilities.performAutoScale(min/2, 2 * max)[1]);
107:                        return new Double(ChartUtilities.performAutoScale(
108:                                minvalue / 2, 2 * maxvalue)[1]);
109:                    } else {
110:                        //System.out.println("** ChartUtilities.performAutoScale(min, max)[1]"+ChartUtilities.performAutoScale(min, max)[1]);
111:                        return new Double(ChartUtilities.performAutoScale(
112:                                minvalue, maxvalue)[1]);
113:                    }
114:                } else
115:                    return new Double(maxvalue);
116:            }
117:
118:            /** Returns the minimum value of all datasets.  */
119:            public Number getMinimumValue() {
120:                int minimumDataSetLength = Integer.MAX_VALUE;
121:                double maxvalue = 0.0;
122:                double minvalue = 0.0;
123:                double columnmaxvalue = 0.0;
124:                double columnminvalue = 0.0;
125:
126:                for (int i = 0; i < model.getDataSetNumber(); i++) {
127:                    minimumDataSetLength = Math.min(minimumDataSetLength, model
128:                            .getDataSetLength(i));
129:                }
130:
131:                double value = 0.0;
132:
133:                for (int i = 0; i < minimumDataSetLength; i++) {
134:                    for (int j = 0; j < model.getDataSetNumber(); j++) {
135:                        value = model.getValueAt(j, i).doubleValue();
136:                        if (value < 0)
137:                            columnminvalue += value;
138:                        else
139:                            columnmaxvalue += value;
140:                    }
141:                    minvalue = Math.min(columnminvalue, minvalue);
142:                    columnminvalue = 0.0;
143:                    maxvalue = Math.max(columnmaxvalue, maxvalue);
144:                    columnmaxvalue = 0.0;
145:                }
146:
147:                if (model.getOrderedValues(CoordSystem.FIRST_YAXIS).size() == 0
148:                        || (maxvalue == 0.0 && minvalue == 0.0))
149:                    return new Integer(0);
150:                else if (model.isManualScale()) {
151:                    //System.out.println("** model.getManualMinimumValue() = "+model.getManualMinimumValue());
152:                    return new Double(Math.min(model.getManualMinimumValue()
153:                            .doubleValue(), minvalue));
154:                } else if (model.isAutoScale()) {
155:                    //System.out.println("** min = "+min+"  max = "+max);
156:
157:                    if (minvalue / maxvalue > 0.95) {
158:                        //System.out.println("** ChartUtilities.performAutoScale(min/2, 2 * max)[0]"+ChartUtilities.performAutoScale(min/2, 2 * max)[0]);
159:                        return new Double(ChartUtilities.performAutoScale(
160:                                minvalue / 2, 2 * maxvalue)[0]);
161:                    } else {
162:                        //System.out.println("** ChartUtilities.performAutoScale(min, max)[0]"+ChartUtilities.performAutoScale(min, max)[0]);
163:                        return new Double(ChartUtilities.performAutoScale(
164:                                minvalue, maxvalue)[0]);
165:                    }
166:                } else
167:                    return new Double(minvalue);
168:            }
169:
170:            /** Returns the minimum column value. 
171:             * @throws ArrayIndexOutOfBoundsException if the Model is empty
172:             */
173:            public double getMinimumColumnValue() {
174:                if (model.isManualScale() && allowManualColScale) {
175:                    return model.getManualMinimumColumnValue();
176:                }
177:                if (model.isAutoScale())
178:                    return ChartUtilities.performAutoScale(model
179:                            .getFirstColumnValue(), model.getLastColumnValue())[0];
180:                else
181:                    return model.getFirstColumnValue();
182:            }
183:
184:            /** Returns the maximum column value. 
185:             * @throws ArrayIndexOutOfBoundsException if the model is empty
186:             */
187:            public double getMaximumColumnValue() {
188:                if (model.isManualScale() && allowManualColScale) {
189:                    return model.getManualMaximumColumnValue();
190:                }
191:                if (model.isAutoScale())
192:                    return ChartUtilities.performAutoScale(model
193:                            .getFirstColumnValue(), model.getLastColumnValue())[1];
194:                else
195:                    return model.getLastColumnValue();
196:            }
197:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.