Setting Resources


Overview

In addition to the built-in resource editor, the resources for objects in the ChartObject library can be set by any of the methods that are available for setting resources in X. The two most common methods are hardcoded resources and resources that are defined in a resource file. One of the benefits in using a resource file is to customize the interface for different end-users.

Using Hardcoded Resources

ChartObject component resources are set in the source code in much the same way as Motif widget resources are specified. The principle difference is that the component object ID must be retrieved through the use of the function, XintChartGetComponent. This function returns the object ID, which is then used in XtSetValues or XtVaSetValues to define the required resource values. These steps are illustrated by the following code segments.


Resource File

A resource file provides a simple, direct means for the application designer to give the end user control over those aspects of the look and behavior of the interface which can be allowed to change without interfering with the function of the application itself.

Chart object resources and chart component resources are set in the same manner as are X resources, using instance names and/or class names. Drop the XmN prefix from the resource names. To set a value to an INT constant, drop the Xint prefix from the constant and convert the remaining term to lower case. For example:

    XintPLACEMENT_LEFT becomes placement_left

Several of the hardcoded resources in the previous section could be defined by resource file entries, as shown by the following example.

    *XintChart.chartType: chart_type_bar
    *XintChart.chartTitle: Yearly Sales

Chart component resources may be identified by their class name in order to specify new values in the resource file. However, this makes changes in all occurrences of the class. The following table lists the object name and the class name for end-user specifiable ChartObject components.

Object NameClass Name
chart_titleXintText
chart_footerXintText
chart_legendXintLegend
plot_haxis
(created for 2D plots only)
XintAxisObject
plot_vaxis
(created for 2D plots only)
XintAxisObject

To change resources for all TextObjects use the class name:

    *XintText.color: cyan
    *XintText.fontFamily: helvetica

To change only the chart title's resources use the object name:

    *chart_title.color: red
    *chart_title.fontFamily: helvetica


Restricted Resources

Not all of the ChartObject's component object resources can be changed by using a resource file. When chart creates these objects, some of their resources are set by the code. These can be changed by using XtSetValues, but not from a resource file. Any resources which are not set by the code are available to the end-user for customization of the interface.

Some of the resources which are set when chart creates its components are listed in the following table. These cannot be changed by the end-user in a resource file.

Object NameResource Name
chart_titleXmNfontSize
XmNfontWeight
XmNtextString
chart_footerXmNfontSize
XmNfontWeight
XmNtextString
plot_haxisXmNtickPlacement
plot_vaxisXmNtickPlacement

The chart resources, XmNchartTitle and XmNchartFooter, can be used to set the title and footer text strings.


Resource File Example

The following example illustrates the use of a resource file to customize a chart. In the first figure, a simple bar chart is displayed. In the second figure, the same bar chart is displayed using a resource file.


Figure 16: Simple Bar Chart Without a Resource File.


Figure 17: Bar Chart With a Resource File.

The resource file listed below contains all of the resource settings that were used to change the display from the one shown in Figure 16 to the one in Figure 17.

    !     resource file example
    !
    !       Chart Class
    !
    *chartTitle: Bar Chart
    *chartFooter: Demonstrates creating \n two footer lines
    *fillColor: gray85
    !
    !       Text Class
    !
    *chart_title.color: red
    *chart_title.fontFamily: helvetica
    *chart_title.dashList: 3,,1
    *chart_title.fillColor: white
    *chart_title.fillStyle: fill_solid
    *chart_title.roundEdge: True
    *chart_footer.color: black
    *chart_footer.fontFamily: times
    !
    !       Legend Class
    !
    *.showLegend: True
    *chart_legend.columns: 1
    *chart_legend.LegendTitle: Cities
    *chart_legend.font: *Helvetica*-120-*
    *chart_legend.highlightMode: highlight_none
    *chart_legend.marginHeight: 10
    *chart_legend.marginWidth: 10
    *chart_legend.color: steel blue
    *chart_legend.fillColor: white
    *chart_legend.fillStyle: fill_solid
    *chart_legend.lineStyle: shadow_out
    *chart_legend.lineThickness: 8
    !
    !       AxisObject
    !
    *XintAxisObject.labelFont: *-Helvetica*-120-*
    *plot_haxis.label: Texas Cities
    *plot_haxis.color: black
    *plot_vaxis.label: Housing Starts (000)
    *plot_vaxis.color: black
    !
    !       BarLine Class
    !
    *XintBarLine.drawShadow: True
    *XintBarLine.inclination: 20
    *XintBarLine.rotation: 10