Keeping the y-axis fixed at place?
Asked Answered
I

2

0

this is the code in the continuation of this question....Allow horizontal scrolling only in the core-plot barchart?

-(BOOL)pointingDeviceDraggedAtPoint:(CGPoint)interactionPoint
{
    if ( !self.allowsUserInteraction || !self.graph.plotArea ) {
        return NO;
    }
    CGPoint pointInPlotArea = [self.graph.plotArea convertPoint:interactionPoint toLayer:self.graph.plotArea];

    if ( isDragging ) {

        pointInPlotArea.y = lastDragPoint.y;//-- Madhup Changed it for allwoing scrolling only in horizontal direction --//




        //-- Madhup Changed it for allwoing scrolling only in horizontal direction --//

        //CGPoint displacement = CGPointMake(pointInPlotArea.x-lastDragPoint.x, pointInPlotArea.y-lastDragPoint.y);
        CGPoint displacement = CGPointMake(pointInPlotArea.x-lastDragPoint.x, 0);
          //--******************************--//
        CGPoint pointToUse = pointInPlotArea;

        // Allow delegate to override
        if ( [self.delegate respondsToSelector:@selector(plotSpace:willDisplaceBy:)] ) {
            displacement = [self.delegate plotSpace:self willDisplaceBy:displacement];
            pointToUse = CGPointMake(lastDragPoint.x+displacement.x, lastDragPoint.y+displacement.y);
        }

        NSDecimal lastPoint[2], newPoint[2];
        [self plotPoint:lastPoint forPlotAreaViewPoint:lastDragPoint];
        [self plotPoint:newPoint forPlotAreaViewPoint:pointToUse];

        CPPlotRange *newRangeX = [[self.xRange copy] autorelease];
        CPPlotRange *newRangeY = [[self.yRange copy] autorelease];
        NSDecimal shiftX = CPDecimalSubtract(lastPoint[0], newPoint[0]);
        NSDecimal shiftY = CPDecimalSubtract(lastPoint[1], newPoint[1]);
        newRangeX.location = CPDecimalAdd(newRangeX.location, shiftX);
        newRangeY.location = CPDecimalAdd(newRangeY.location, shiftY);

        // Delegate override
        if ( [self.delegate respondsToSelector:@selector(plotSpace:willChangePlotRangeTo:forCoordinate:)] ) {
            newRangeX = [self.delegate plotSpace:self willChangePlotRangeTo:newRangeX forCoordinate:CPCoordinateX];
            newRangeY = [self.delegate plotSpace:self willChangePlotRangeTo:newRangeY forCoordinate:CPCoordinateY];
        }

        self.xRange = newRangeX;
        self.yRange = newRangeY;

        //-- Madhup Changed it for keeping y axis fixed  --//
        NSLog(@"%@",self.graph.axisSet.axes);

        NSMutableArray *axisArr= [[NSMutableArray alloc] initWithArray:self.graph.axisSet.axes];
        CPXYAxis *yAxis = [axisArr objectAtIndex:1];
        CGPoint point = yAxis.position;
        point.y -= lastDragPoint.x;
        yAxis.position = point;
        [axisArr replaceObjectAtIndex:1 withObject:yAxis];
        self.graph.axisSet.axes = axisArr;
        [axisArr release];

        NSLog(@"%@",self.graph.axisSet.axes);
            //--******************************--//

        lastDragPoint = pointInPlotArea;



        return YES;
    }

    return NO;
}

Now from the code you people can see that i am able to stop the scrolling of map only in horizontal direction, but still I am not able to keep the y-axis fixed. I have written some code for that in this method too but it does not seem to be working.

Implosion answered 14/12, 2009 at 7:58 Comment(2)
Maybe just setting interactionPoint.y = 0.f; at the very beginning of this method would work?Inception
Hello, I tried your code but have problem with plotArea and isDragging properties, seems they cannot be accessed like this anymore. Do you have some hints of what to change ? ThanksConic
W
4

if you want to fix axis when scrolling add this lines

CPTXYAxisSet *axisSet = (CPTXYAxisSet *)_graph.axisSet;

axisSet.xAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];
axisSet.yAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];
Walton answered 17/6, 2016 at 10:15 Comment(0)
B
0

The original question now has two viable solutions that work for the latest, as of this date, code in the repository.

Allow horizontal scrolling only in the core-plot barchart?

To keep the graph only in quadrant one:

Allow horizontal scrolling only in the core-plot barchart?

To only allow scrolling in the horizontal:

Allow horizontal scrolling only in the core-plot barchart?

I've used both solutions with a scatter plot and it works great.

Brierroot answered 27/2, 2011 at 19:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.