Search code examples
cocoansarraycocoa-bindingsquartz-composer

How do I draw a shape in Quartz Composer for every element in an NSArray?


I have an XML file that I have parsed and have put the information I want into several NSArray objects. I want to be able to draw them in a QuartzView (anything better?) to visualize the data. The arrays should all hypothetically contain the same amount of info. I want one array to represent the x axis and another the y. It took long enough to get quartz composer to bind to my array code, but I can only get it to draw either one sphere with unique coordinates or a sphere for every index with same. So basically I need help making a plot in QC based off of array data. The code looks something like this:

- (IBAction) setup:(id)sender {
    BlastParser *bp = [[BlastParser alloc] init];
    NSString *hit_idString = @".//hit_id";
    NSString *evalueString = @".//Hsp_evalue";
    NSString *hsp_align_lenString = @".//Hsp_align-len";

    NSArray *hit_id = [bp getArrayForNode:hit_idString];
    NSArray *evalue = [bp getArrayForNode:evalueString];
    NSArray *hsp_align_len = [bp getArrayForNode:hsp_align_lenString];

    NSLog(@"nodes: %@", Hsp_align_len);
    int i;
    for (i = 0; i < [evalue count]; ++i){
        [qcView setValue:[NSNumber numberWithInt:i] forInputKey:@"iter"];
    }
}

Thanks in advance.


Solution

  • It sounds like it might be easier to just use a regular NSView and draw your shapes (in the view's drawRect: method) with something like:

    int radius = 4;
    NSBezierPath *circle = [NSBezierPath bezierPathWithOvalInRect:NSMakeRect(xPos-radius, yPos-radius, 2*radius, 2*radius)];
    [circle fill];
    

    Where xPos and yPos are the coordinates of the point you want to draw.

    However, maybe there is some other reason you want to use Quartz Composer?