gujjula / core-plot

Automatically exported from code.google.com/p/core-plot
0 stars 0 forks source link

Adjust CPXYGraph´s framesize without allocating new object? #281

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
Changing the hosting view´s size doesn´t make the graph adjust  it´s plots 
dimensions.
Changing view´s size affects graph´s size but not the plots.
Reallocating the Graph will bring the expected size but seems to be much 
overhead.

What is the expected output? What do you see instead?
Changing the hosting view´s (and graph´s frame) should make the plots adjust 
it´s dimensions.

What version of the product are you using? On what operating system?
Cocoa Touch API, MacOS 10.6

Original issue reported on code.google.com by Wrede....@gmail.com on 29 Apr 2011 at 9:30

GoogleCodeExporter commented 9 years ago
I'm not sure I understand this. Take a look at CPTestApp. You can change the 
window/host view size and the graph changes too. Are you sure you are really 
changing the size of the host view?

Drew

Original comment by drewmcco...@mac.com on 29 Apr 2011 at 9:43

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
When i initially create the graph everything looks fine; the bars are well 
proportioned. When i then update the view´s frame size and do things like 
adjusting the bar´s width .. the graph is too big for the view. Some bars are 
cut off and others out of (right hand) bounds. It´s hard to say due to the 
method being called for initiall configuration is the same!

    //define x and y axis dimensions
    int numberOfSections = [self numberOfRecordsForPlot:nil];
    CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
    plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0.0f) length:CPDecimalFromFloat(numberOfSections)];

    float maxheight = self.maxHeight;
    plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0.0f) length:CPDecimalFromFloat(maxheight)];// + maxheight/8)];

    //Create Labels for xAxis at respective ticklocation with Name of Section
    CPXYAxisSet* axisSet = (CPXYAxisSet*)graph.axisSet;    
    CPTextStyle* textStyle = [CPTextStyle textStyle];
    textStyle.color = [CPColor blackColor];
    textStyle.fontSize = 14.0;

    NSMutableArray* axisLabels = [[NSMutableArray alloc] init];
    for (int i = 0; i < numberOfSections; i++) {

        NSString* name = [[[[conv sections] objectAtIndex:i]sectionHeader]name];
        int length = [name length];
        length = length >= 14 ? 14 : length;
        NSString* sectionName = [name substringWithRange:NSMakeRange(0, length)];
        sectionName = [sectionName stringByAppendingString:@"..."];
        CPAxisLabel* label = [[CPAxisLabel alloc] initWithText:sectionName 
                                                     textStyle:textStyle];
        label.rotation = M_PI*1.96;
        // position label under respective bar
        label.tickLocation = [[NSNumber numberWithFloat:i+0.5] decimalValue];
        [axisLabels addObject:label];
        [label release];
    }
    NSSet* labelSet = [NSSet setWithArray:axisLabels];
    axisSet.xAxis.axisLabels = labelSet;
    [axisLabels release]; 

    //recalculate bar width of bars
    float barWidth = (graph.bounds.size.width - 2*padding) / ([self numberOfRecordsForPlot:nil]*2+1);
    openBarPlot.barWidth  = barWidth;
    failBarPlot.barWidth = barWidth;
    doneBarPlot.barWidth = barWidth;

    //tell the graph to reload from datasource and draw all it´s plots
    [graph reloadData];

}

Original comment by Wrede....@gmail.com on 29 Apr 2011 at 11:12

GoogleCodeExporter commented 9 years ago
It looks like you are setting the bar widths in view coordinates, right?
I think the default is plot coordinates. You need to set the property 
barWidthsAreInViewCoordinates on CPBarPlot to YES.

Original comment by drewmcco...@mac.com on 29 Apr 2011 at 1:24

GoogleCodeExporter commented 9 years ago
Well the issue is not about the width but the height. It seems to me that the 
space the graph is drawn doesn´t change. The bar width is an independent 
property of the plots not the graph. That´s why changing the width works.I 
change the view´s size like this (self is the superview´s controller).

[self updateGraphsDimensions];
-> [graphViewController.view setFrame:[self.view.frame]];
[graphViewController configureGraph];
-> the method posted above..

But thank´s for your reply: Setting the barwidth in axis ranges would require 
barWidthsAreInViewCoordinates to be set to FALSE ? (default must be YES since i 
already work with view dimensions)

Original comment by Wrede....@gmail.com on 29 Apr 2011 at 2:24

GoogleCodeExporter commented 9 years ago
If you change the frame of your graph hosting view, all Core Plot graph 
elements should resize correctly. In your code above, which view is the hosting 
view?

Original comment by eskr...@mac.com on 29 Apr 2011 at 9:05

GoogleCodeExporter commented 9 years ago
Yes i know this behavior from other applications but unfortunately not in this 
one. The graphhostingview is the view of the graphViewController. It´s frame 
is changed within the detailviewcontroller which adds the hostingview to his 
subviews from time to time.

Original comment by Wrede....@gmail.com on 29 Apr 2011 at 9:26

GoogleCodeExporter commented 9 years ago
Issue 299 has been merged into this issue.

Original comment by eskr...@mac.com on 1 Jul 2011 at 1:39

GoogleCodeExporter commented 9 years ago
This issue was closed by revision 211c3eb41a4f.

Original comment by eskr...@mac.com on 1 Jul 2011 at 3:05

GoogleCodeExporter commented 9 years ago
Issue 424 has been merged into this issue.

Original comment by eskr...@mac.com on 11 Apr 2012 at 9:47