Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core plot disable y axes scaling, scrolling

I want to make a thing like this: http://youtu.be/PeRhxSCx2xM

I try to implement this method:

//viewDidLoad
//plotSpace.delegate = self;

- (CPTPlotRange *)plotSpace:(CPTPlotSpace *)space
     willChangePlotRangeTo:(CPTPlotRange *)newRange
             forCoordinate:(CPTCoordinate)coordinate {

    NSLog(@"WillChangePlotRangeTo");

    // only allows scrolling to the right
    // remove this to have scrolling in both directions
    if (newRange.locationDouble < 0.0F) {
        newRange.location = CPTDecimalFromFloat(0.0);
    }

    // Adjust axis to keep them in view at the left and bottom;
    // adjust scale-labels to match the scroll.
    CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
    if (coordinate == CPTCoordinateX) {
        axisSet.yAxis.orthogonalCoordinateDecimal = newRange.location;
        axisSet.xAxis.titleLocation = CPTDecimalFromFloat(newRange.locationDouble +
                                                         (newRange.lengthDouble / 2.0F));
    } else {
        axisSet.xAxis.orthogonalCoordinateDecimal = newRange.location;
        axisSet.yAxis.titleLocation = CPTDecimalFromFloat(newRange.locationDouble +
                                                         (newRange.lengthDouble / 2.0F));
    }

    return newRange;
}

And i try this to, this solution works when i zoom-out, but not work when i zoom in.

plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(1.0) length:CPTDecimalFromFloat(3.0)];
plotSpace.globalYRange = plotSpace.yRange;

anyone please explain me, what is the correct result, and how its work actually.

Thanks the replies

like image 692
flatronka Avatar asked Dec 09 '22 02:12

flatronka


2 Answers

The easiest way is to just ignore the newRange and return the existing yRange for the y-coordinate. You don't need to bother with updating the axis properties here, either. There are easier ways to do that.

Graph setup:

// leave the titleLocation for both axes at the default (NAN) to center the titles
xAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];
yAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];

Plot space delegate:

- (CPTPlotRange *)plotSpace:(CPTPlotSpace *)space
      willChangePlotRangeTo:(CPTPlotRange *)newRange
              forCoordinate:(CPTCoordinate)coordinate {

    CPTPlotRange *updatedRange = nil;

    switch ( coordinate ) {
    case CPTCoordinateX:
        if (newRange.locationDouble < 0.0F) {
            CPTMutablePlotRange *mutableRange = [[newRange mutableCopy] autorelease];
            mutableRange.location = CPTDecimalFromFloat(0.0);
            updatedRange = mutableRange;
        }
        else {
            updatedRange = newRange;
        }
        break;
    case CPTCoordinateY:
        updatedRange = ((CPTXYPlotSpace *)space).yRange;
        break;
    }
    return updatedRange;
}
like image 171
Eric Skroch Avatar answered Dec 22 '22 00:12

Eric Skroch


I had the similar situation and the problem and it drove me crazy because I forgot to set delegate:

plotSpace.delegate = self;
like image 38
veich Avatar answered Dec 21 '22 22:12

veich