PowerPlotPercolation logo

Value creation Graph

This is a graph with non-uniform appearance. The nodes have white shadows and individual style properties, i.e., different sizes and colors.

This page describes the class “CreateValue” in the PowerPlot demo app.

Value creation model graph

We first create the graph by a factory method and then individually configure the style properties of some of the nodes. Note that the line with [graph distributeDefaultPropertiesToAllCustomDatum]: This method copies the default style properties to all nodes in the graph; this command is necessary since the style property slot (named customDatum) of a node is originally set to nil and thus the commands setting the style would have no effect otherwise!

    // Create the chart.
    WSChart *gChart = [WSChart graphPlotWithFrame:[self.view bounds]
                                            graph:myGraph
                                      colorScheme:kColorDark];
    WSPlotGraph *graph = (WSPlotGraph *)[[gChart plotAtIndex:0] view];
    [[graph propDefault] setShadowEnabled:YES];
    [[graph propDefault] setOutlineStroke:0];
    [graph setStyle:kCustomStyleIndividual];
    [graph distributeDefaultPropertiesToAllCustomDatum];
    [(WSNodeProperties *)[[graphTest datumAtIndex:0] customDatum] setNodeColor:[UIColor darkGrayColor]];
    [(WSNodeProperties *)[[graphTest datumAtIndex:3] customDatum] setNodeColor:[UIColor darkGrayColor]];
    [(WSNodeProperties *)[[graphTest datumAtIndex:5] customDatum] setNodeColor:[UIColor redColor]];
    [(WSNodeProperties *)[[graphTest datumAtIndex:6] customDatum] setNodeColor:[UIColor CSSColorGreen]];
    [(WSNodeProperties *)[[graphTest datumAtIndex:6] customDatum] setSize:CGSizeMake(200, 40)];

In the demo app the nodes and connections that make up the instance of WSGraph are provided by the DemoData class that only contains factory methods for the demo data. Creating the graph is thus straightforward:

    // Get the nodes and connections of the graph.
    WSData *graphTest = [DemoData valueGraphNodes];
    WSGraphConnections *connections = [DemoData valueGraphConnections];
    WSGraph *myGraph = [WSGraph graphWithNodes:graphTest
                                   connections:connections];