Working with Bubble Tree Data Source

Operating system requirements: iOS 5.0 or later.

Mobile device: iPad.

Description

This example sets and determines bubble tree data source settings. After starting the example the following operations are executed:

Source Code

Executing the example requires to place the following code instead of the executeExample method of the ViewController class (see the Displaying of Express Report section):

-(void)executeExample {
    // Create a bubble tree data source
    BubbleTreeDataViewDataSource *bubbleTreeDatasource = [self createBubbleTreeDataViewDataSource];
    // Display information about bubble tree data source
    [self printDataSourceInfo: bubbleTreeDatasource];
}
// Creates a bubble tree data source
-(BubbleTreeDataViewDataSource *) createBubbleTreeDataViewDataSource {
    // Create a bubble tree data source
    SPPLPivot bubbleTreePivot = PPLPivot::pivot(m_olapReport);
    SPPLPivotTable bubbleTreePivotTable = PPLPivotTable::pivotTable(bubbleTreePivot);
    BubbleTreeDataViewDataSource *bubbleTreeDataSource = [[BubbleTreeDataViewDataSource alloc] initWithPivotTable: bubbleTreePivotTable olapReport: m_olapReport];
    // Get bubble tree data source as PPLib++ library
    SPPLibBubbleTreeDataSource plusplusDataSource = [bubbleTreeDataSource plusplusDataSource];
    
    // Get bubble tree data source dimensions
    SNArray dimensions = m_olapReport->dataSource()->dimensions();
    for (int i = 0; i < dimensions->count(); i++) {
        SPPLDimension dimension = dimensions->objectAtIndex(i)->qClass<PPLDimension>();
        switch (dimension->type()) {
            case PPLDimension::kCalendarDimension: {
                // Sets calendar dimension identifier
                [bubbleTreeDataSource setTimelineDimensionId: dimension->id()->nsString()];
            }
            break;
            case PPLDimension::kStandardDimension: {
                NSString *dimensionId = dimension->id()->nsString();
                NSString *metricsDimensionId = plusplusDataSource->metricsDimension()->id()->nsString();
                NSString *observationDimensionId = plusplusDataSource->observationDimension()->id()->nsString();
                if([dimensionId isEqualToString: metricsDimensionId]) {
                    // Set territory dimension identifier
                    [bubbleTreeDataSource setMetricsDimensionId: dimensionId];
                    // Get dimension elements
                    SPPLDimensionElements elements = dimension->elements();
                    for (int j = 0; j < elements->itemsCount(); j++) {
                        int64 key = elements->itemsKeys()->objectAtIndex(j);
                        SPPLDimensionElement dimensionElement = elements->getElementByKey(key);
                        if (dimensionElement != nil) {
                            switch (j) {
                                case 0:
                                // Set key of metric that determines bubble color
                                [bubbleTreeDataSource setColorMetricsKey: dimensionElement->key()];
                                break;
                                case 1:
                                // Set size of metric that determines bubble color
                                [bubbleTreeDataSource setSizeMetricsKey: dimensionElement->key()];
                                default:
                                break;
                            }
                        }
                    }
                }
                if([dimensionId isEqualToString: observationDimensionId]) {
                    // Sets observation object dimension identifier
                    [bubbleTreeDataSource setObservationDimensionId: dimensionId];
                }
            }
            break;
            default:
            break;
        }
    }
    return bubbleTreeDataSource;
}
// Displays information about bubble tree data source
-(void)printDataSourceInfo: (BubbleTreeDataViewDataSource *)bubbleTreeDatasource {
    // Display data source dimension names
    printf("Observation object dimension name: %s\n", [bubbleTreeDatasource observationDimension]->name()->UTF8String());
    printf("Territory dimension name: %s\n", [bubbleTreeDatasource metricsDimension]->name()->UTF8String());
    printf("Calendar dimension name: %s\n", [bubbleTreeDatasource timelineDimension]->name()->UTF8String());
    // Display key and name of metric that determines bubble color
    PPLDimensionElement *colorMetricsElement = [bubbleTreeDatasource colorMetricsElement];
    if (colorMetricsElement != nil) {
        printf("Key of metric that determines bubble color: %lld\n", colorMetricsElement->key());
        printf("Name of metric that determines bubble color: %s\n", colorMetricsElement->name()->UTF8String());
    }
    // Display key and name of metric that determines bubble size
    PPLDimensionElement *sizeMetricsElement = [bubbleTreeDatasource sizeMetricsElement];
    if (sizeMetricsElement != nil) {
        printf("Key of metric that determines bubble size: %lld\n", sizeMetricsElement->key());
        printf("Name of metric that determines bubble size: %s\n", sizeMetricsElement->name()->UTF8String());
    }
}

After executing the example the development environment console displays names of territory, calendar, observation object dimensions, and also keys and names of the metrics that determine tree bubble color and size:

Observation object dimension name: World

Territory dimension name: Indicators

Calendar dimension name: Calendar

Key of metric that determines bubble color: 1

Name of metric that determines bubble color: Economic Policy & Debt

Key of metric that determines bubble size: 2

Name of metric that determines bubble size: Balance of payments

See also:

Examples of Component Use