2009-12-14 6 views
0

c'est le code dans la suite de cette question .... Allow horizontal scrolling only in the core-plot barchart?Garder l'axe Y fixé à sa place?

-(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; 
} 

maintenant du code que vous les gens peuvent voir que je suis en mesure d'arrêter le défilement de la carte uniquement dans le sens horizontal, mais je Je ne suis pas capable de garder l'axe Y fixe. J'ai écrit du code pour ça dans cette méthode aussi, mais ça ne semble pas fonctionner.

+0

Peut-être que la mise 'interactionPoint.y = 0.F,' au début de cette méthode fonctionnerait? – Pascal

+0

Bonjour, j'ai essayé votre code mais j'ai un problème avec les propriétés plotArea et isDragging, il semble qu'ils ne puissent plus être accédés comme ça. Avez-vous des indices sur ce qu'il faut changer? Merci – Luc

Répondre

0

La question originale a maintenant deux solutions viables qui fonctionnent pour le code le plus récent, à ce jour, dans le dépôt.

Allow horizontal scrolling only in the core-plot barchart?

Pour garder le graphique que dans un quadrant:

Allow horizontal scrolling only in the core-plot barchart?

Pour ne permettre le défilement dans le sens horizontal:

Allow horizontal scrolling only in the core-plot barchart?

J'ai utilisé les deux solutions avec un nuage de points et cela fonctionne très bien.

4

si vous voulez fixer l'axe lors du défilement ajouter ces lignes

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

axisSet.xAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0]; 
axisSet.yAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0]; 
Questions connexes