6
Advanced JClass Chart 3D Programming
4D Surface Graphs 4D Bar Charts Customizing the Contour Levels
Customizing Contour Styles Internationalization Support
All elements mentioned in this chapter refer to both the Java 2 API and the
Java 3D API, unless specifically noted.This section covers topics that programmers of advanced JClass Chart 3D applications will find useful. It assumes that you are already familiar with JClass Chart 3D.
6.1 4D Surface Graphs
For surface and bar charts, JClass Chart 3D can be used to display 4D charts using color as a fourth dimension. The additional color information is provided to JClass Chart 3D as a second data source using the
Chart3dDataView
class'zoneDataSource
property.A full description of data sources, including grid data sources, is provided in Data Sources, in Chapter 5.
For zone data, use the
Chart3dGridDataModel
interface. TheChart3dGridDataModel
interface, which extendsChart3dDataModel
, is the core grid data model interface. In JClass Chart 3D, grid data is specified in terms of an X-array of grid values, a Y-array of grid values, and a doubly subscripted array of z data values.
- Set the
Zoned
property of theJCContour
class and theShaded
property of theJCElevation
class totrue
.- Set a grid data source in the
Chart3dDataView
'selevationDataSource
property.- Set a grid data source in the
Chart3dDataView
'szoneDataSource
property; this will be used for deriving the zoning and contouring colors as zone data.- Ensure that the data array sizes of the two data sources match up. The xGrid and yGrid arrays of the two data sources should be identical. The zValues array should have exactly the same number of values in both the X- and Y-dimensions (that is, the same number of rows and columns).
Note: If any of these conditions are not met, a 4D chart will not be displayed.
If the zone data has a hole that is not in the surface data, the surface in the region of the hole will be displayed as if the zone data were not attached.
Figure 21 : 4D chart - zone/contour data is different from surface data.
6.2 4D Bar Charts
When a zone data source is supplied for a bar chart, the values in the zone data are used in conjunction with the contour levels to apply zone colors to the bars in the grid.
When zone data is supplied and the
Zoned
property of theJCContour
class istrue
, the bar is not broken up into separate colored segments. Rather, each bar is individually colored according to the zoned height of the bar. Contours are never drawn when zone data is supplied. Figure 22 gives an example of a 4D bar chart.
Figure 22 : A 4D Bar Chart.
In a bar chart, the zone data structure is only referenced when
Zoned
istrue
. A legend is generated based on the contour levels. The legend labels can be replaced by supplying a list of labels to theJCChart3dLegend
class via its labels property.Please see Legends, in Chapter 2 for full details on legend Strings.
6.3 Customizing the Contour Levels
To customize contour levels, manipulate the
JCContourLevels
class. This object deals with contour levels; it calculates default levels (ifisDefault
istrue
) but also allows users to set their own levels.The
JCContourLevels
class has five properties:
isDefault
- ascertains whether linear contour levels are generated automatically (based on numLevels)levels
- a strictly increasing array of contour levelsmax
- the contour maximum, calculated from the data (read only)min
- the contour minimum, calculated from the data (read only)numLevels
- the number of contour levelsTo specify your own contour levels, set the levels property to a new array of doubles. This array must be in strictly increasing order. You can also manipulate the levels using the
addlevel()
andremoveLevel()
methods. Changing the levels in any of the above ways has the side effect of setting theisDefault
property tofalse
. WhenisDefault
isfalse
, thenumLevels
property automatically takes on the value of the length of the levels array and hence becomes read only. IfisDefault
is set totrue
, thenumLevels
property can be changed to specify the number of default levels to calculate.In user-specified contour levels, the default is to display just the range of data that is spanned by the data (
JCChart3dLegend.RANGE_DATA
). If thedistributionRange
property of theJCChart3dLegend
class is set toJCChart3dLegend.Range_ALL
, the entire contour level array is shown in the legend.
6.4 Customizing Contour Styles
To customize contour styles, manipulate the
contourStyles
property of theJCContour
class. ThecontourStyles
property reference anArrayList
ofJCContourStyle
objects. TheJCContourStyle
class defines the style used to draw contours and zones.The
JCContourStyle
class has three properties:
fillStyle
- theJCFillStyle
object to be used for this contour style; used to draw the contour zoneslineStyle
- theJCLineStyle
object to be used for this contour style; used to draw the contour linessymbolStyle
- theJCSymbolStyle
object to be used for this contour style; used to draw symbols for contoured grid scatter plots
6.4.1 Default Contour Styles
By default, for surface and bar charts, JClass Chart 3D provides an array of 100 contour styles. By default, the fill styles are solid, the contour lines are black lines of width 1, and the symbols are of type
JCSymbolStyle.DOT
of size 6. The fill colors and symbol colors are chosen from a predefined array of colors chosen to provide a pleasing color distribution.You will need to provide custom contour styles if:
- it is important to your application to specify the precise contour style for any particular level;
- you want to display more than 100 levels; or
- you want to uniquely identify contour lines. The JClass Chart 3D default contour styles use only black solid lines of width 1.
It is usually easiest to specify more contour styles than will be needed for the number of contour levels. If nstyles contour styles are provided, and the number of contour levels is nlevels, JClass Chart 3D will calculate the index into the contour styles array for level i (0 £ i £ nlevels) as follows:
(int)Math.round(i * (nstyles - 1)/nlevels)
If you wish to change this index calculation, implement the
public int contourIndex(int level);JCContourMapping
interface by creating the method:Then set the object that implements the interface on the
contourMapping
property of theJCContour
class.The
JCContourStyle
class contains information about how JClass Chart 3D should display contour style objects. The fields are broken down as follows:
The pattern used to fill the zones. Valid values include
JCLineStyle.NONE
,JCLineStyle.SOLID
,JCLineStyle.LONG_DASH
,JCLineStyle.SHORT_DASH
,JCLineStyle.LSL_DASH
, andJCLineStyle.DASH_DOT
.The color used to demarcate the level's contour line when
contoured
istrue
.The line width used to demarcate the level's contour line when
contoured
istrue
. Must be greater than or equal to 0. Whenlinewidth
is zero, no line is drawn.The line pattern used to demarcate the level's contour line when
contoured
istrue
. Line patterns are only honored for surface plots that are 2D projections (available in the Java 2 API version of JClass Chart 3D by setting the meshed and shaded properties of theJCElevation
class tofalse
). The line pattern must be one of the patterns listed in Figure 23.
Figure 23 : Different Line Patterns.
Here is a code sample that doubles the line width of the 50th contour style.
JCContour contour=dataView.getContour();
ArrayList contourStyles=getContourStyles();
JContourStyle style=(JCContourStyle)contourStyles.get(49);
style.setLineWidth(2*style.getLineWidth());
6.5 Internationalization Support
6.5.1 Internationalization
Internationalization is the process of making software that is ready for adaptation to various languages and regions without engineering changes. JClass products have been internationalized.
Localization is the process of making internationalized software run appropriately in a particular environment. All Strings used by JClass that need to be localized (that is, Strings that will be seen by a typical user) have been internationalized and are ready for localization. Thus, while localization stubs are in place for JClass, this step must be implemented by the developer of the localized software. These Strings are in resource bundles in every package that requires them. Therefore, the developer of the localized software who has purchased source code should augment all .java files within the /resource/ directory with the .java file specific for the relevant region; for example, for France, LocaleInfo.java becomes LocaleInfo_fr.java, and needs to contain the translated French versions of the Strings in the source LocaleInfo.java file. (Usually the file is called LocaleInfo.java, but can also have another name, such as LocaleBeanInfo.java or BeanLocaleInfo.java.)
Essentially, developers of the localized software create their own resource bundles for their own locale. Developers should check every package for a /resources/ directory; if one is found, then the .java files in it will need to be localized.
For more information on internationalization, go to: http://java.sun.com/j2se/1.4.2/docs/guide/intl/index.html.