Vvidget Code Reference Manual

Vvidget Code > Programming > Cocoa > Annotated Fragments

The best desktop application documentation is a project that compiles out of the box. For that see the Xcode projects on your disk at:

/Library/Vvidget/Examples/VvidgetCode

But before seeing those projects you may want to read the following annotated code fragments.

Method Blocks

To make a graph, follow these steps:

The rest of this example section details those steps in code.

The following method starts the whole process of displaying a graph. The actual graph generation is deferred until myGraphView is displayed. myGraphView is assigned using the Interface Builder Plugin.

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
/*
A very simple controller is a delegate of the NSApplication instance defined in the main
nib file. This method gets called when the app launches and is what initializes the graphing.

The variable "myGraphView" is a graph view instance from the interface builder graph plugin
defined and connected as an outlet in the nib file.
*/

// First update the graph (see the method below):
[self EX_update_graph];

// Then display the graph window in the center of the screen:
[[myGraphView window] center];
[myGraphView setNeedsDisplay:YES];
[[myGraphView window] makeKeyAndOrderFront:nil];

return;
}

The following method updates the Line Graph parameters.

- (void)EX_update_graph
{
/*
Updates the graph using the entries contained in the input string constructor.
The graph view is not displayed or marked for display by this method, rather that
must be explicitly done after this call.

This method assigns key value pairs for a Line Graph.
*/

id input_string_constructor;

input_string_constructor = [myGraphView get_VC_input_string_constructor];

// Reset the input string constructor for new key value pairs:
[input_string_constructor VC_reset];

// Set a bunch of standard line graph key value pairs:
[input_string_constructor VC_append_key:"chart_type" unsigned_value:1U];
[input_string_constructor VC_append_key:"chart_subtype" unsigned_value:0];
[input_string_constructor VC_append_key:"chart_format_type" unsigned_value:0];
[input_string_constructor VC_append_key:"title" string_value:@"Example Graph"];
[input_string_constructor VC_append_key:"x_title" string_value:@"Time"];
[input_string_constructor VC_append_key:"y_title" string_value:@"Amplitude"];

// This is taken out so lines have different colors:
//[self EX_append_line_color];

// This sets the actual data values:
[self EX_append_data_points];

// This is only used if you have a custom template:
[self EX_append_my_templates];

// After defining all the dictionary entries call this method on the graph view:
[myGraphView VCN_update_using_input_string_constructor];

return;
}

The following method updates the data values for one curve on the graph. You can set multiple curves using data_I keys and make curve values dynamic with normal programming and encoding into the string. This example just hardwires 3 data point values for one curve.

- (void)EX_append_data_points
{
/*
This is a very simple example of forming data for one curve.
*/

id input_string_constructor;
NSString *a_string;
double x_value_1, y_value_1;
double x_value_2, y_value_2;
double x_value_3, y_value_3;

input_string_constructor = [myGraphView get_VC_input_string_constructor];

data_c_string = malloc(6 * 30 * sizeof(char));

x_value_1 = 1.0;
y_value_1 = 5.0;

x_value_2 = 2.0;
y_value_2 = 10.0;

x_value_2 = 3.0;
y_value_2 = 15.0;

sprintf(data_c_string, "%g %g %g %g %g %g"
, x_value_1 , y_value_1 , x_value_2 , y_value_2 , x_value_3 , y_value_3);

a_string = [NSString stringWithCString:data_c_string];

[input_string_constructor VC_append_key:"data_1" string_value:a_string];

free(data_c_string);

return;
}

The following method defines a custom template directory.

- (void)EX_append_my_templates
{
/*
If you want to have a customized look for your graph then define the
"templates" directory and add a template document inside that directory.
*/

id input_string_constructor;
NSString *my_templates_path;

my_templates_path = [[NSBundle mainBundle] resourcePath];
my_templates_path = [my_templates_path stringByAppendingPathComponent:@"my_templates"];

input_string_constructor = [myGraphView get_VC_input_string_constructor];

[input_string_constructor VC_append_key:"templates" string_value:my_templates_path];

return;
}

The following method defines a line color.

- (void)EX_append_line_color
{
/*
Use this if you want all the lines to be one color
*/

id input_string_constructor;
unsigned red_hex, green_hex, blue_hex, alpha_hex;
NSString *line_color_string;

input_string_constructor = [myGraphView get_VC_input_string_constructor];

red_hex = 0;
green_hex = 0;
blue_hex = 0;
alpha_hex = 255;

line_color_string = [NSString stringWithFormat:@"%02X%02X%02X%02X"
, red_hex , green_hex , blue_hex , alpha_hex];

[input_string_constructor VC_append_key:"line_color" string_value:line_color_string];

return;
}

When executed, the following method will send the graph to Vvidget Builder.

- (void) EX_export_to_vvidget_builder:(id)sender
{
/*
Exports the graph to Vvidget Builder.
This is the action to a button or some other UI controller.
*/

[myGraphView VCN_export_to_vvidget_builder];
return;
}

Please help improve this documentation. If a section is hard to understand, there is a typo, you would like a new section added, or you detect any other improvement that can be made then please email support@vvi.com with your information.




© Copyright 1993-2011 by VVimaging, Inc. (VVI); All Rights Reserved. Please email support@vvi.com with any comments you have concerning this documentation. See Legal for trademark and legal information.