@@ -89,6 +89,12 @@ @implementation CPTRangePlot
8989@dynamic rightValues;
9090@dynamic barLineStyles;
9191
92+ /* * @property CPTRangePlotFillDirection fillDirection
93+ * @brief Fill the range in a horizontal or vertical direction.
94+ * Default is CPTRangePlotFillHorizontal.
95+ **/
96+ @synthesize fillDirection;
97+
9298/* * @property CPTFill *areaFill
9399 * @brief The fill used to render the area.
94100 * Set to @nil to have no fill. Default is @nil.
@@ -174,6 +180,7 @@ -(nonnull instancetype)initWithFrame:(CGRect)newFrame
174180{
175181 if ((self = [super initWithFrame: newFrame])) {
176182 barLineStyle = [[CPTLineStyle alloc ] init ];
183+ fillDirection = CPTRangePlotFillHorizontal;
177184 areaFill = nil ;
178185 areaBorderLineStyle = nil ;
179186
@@ -194,6 +201,7 @@ -(nonnull instancetype)initWithLayer:(nonnull id)layer
194201 CPTRangePlot *theLayer = (CPTRangePlot *)layer;
195202
196203 barLineStyle = theLayer->barLineStyle ;
204+ fillDirection = theLayer->fillDirection ;
197205 areaFill = theLayer->areaFill ;
198206 areaBorderLineStyle = theLayer->areaBorderLineStyle ;
199207
@@ -217,6 +225,7 @@ -(void)encodeWithCoder:(nonnull NSCoder *)coder
217225 [coder encodeCGFloat: self .barWidth forKey: @" CPTRangePlot.barWidth" ];
218226 [coder encodeCGFloat: self .gapHeight forKey: @" CPTRangePlot.gapHeight" ];
219227 [coder encodeCGFloat: self .gapWidth forKey: @" CPTRangePlot.gapWidth" ];
228+ [coder encodeInteger: self .fillDirection forKey: @" CPTRangePlot.fillDirection" ];
220229 [coder encodeObject: self .areaFill forKey: @" CPTRangePlot.areaFill" ];
221230 [coder encodeObject: self .areaBorderLineStyle forKey: @" CPTRangePlot.areaBorderLineStyle" ];
222231
@@ -229,11 +238,12 @@ -(nullable instancetype)initWithCoder:(nonnull NSCoder *)coder
229238 if ((self = [super initWithCoder: coder])) {
230239 barLineStyle = [[coder decodeObjectOfClass: [CPTLineStyle class ]
231240 forKey: @" CPTRangePlot.barLineStyle" ] copy ];
232- barWidth = [coder decodeCGFloatForKey: @" CPTRangePlot.barWidth" ];
233- gapHeight = [coder decodeCGFloatForKey: @" CPTRangePlot.gapHeight" ];
234- gapWidth = [coder decodeCGFloatForKey: @" CPTRangePlot.gapWidth" ];
235- areaFill = [[coder decodeObjectOfClass: [CPTFill class ]
236- forKey: @" CPTRangePlot.areaFill" ] copy ];
241+ barWidth = [coder decodeCGFloatForKey: @" CPTRangePlot.barWidth" ];
242+ gapHeight = [coder decodeCGFloatForKey: @" CPTRangePlot.gapHeight" ];
243+ gapWidth = [coder decodeCGFloatForKey: @" CPTRangePlot.gapWidth" ];
244+ fillDirection = [coder decodeIntegerForKey: @" CPTRangePlot.fillDirection" ];
245+ areaFill = [[coder decodeObjectOfClass: [CPTFill class ]
246+ forKey: @" CPTRangePlot.areaFill" ] copy ];
237247 areaBorderLineStyle = [[coder decodeObjectOfClass: [CPTLineStyle class ]
238248 forKey: @" CPTRangePlot.areaBorderLineStyle" ] copy ];
239249
@@ -669,39 +679,80 @@ -(void)renderAsVectorInContext:(nonnull CGContextRef)context
669679 if ( self.areaFill ) {
670680 CGMutablePathRef fillPath = CGPathCreateMutable ();
671681
672- // First do the top points
673- for ( NSUInteger i = (NSUInteger )firstDrawnPointIndex; i <= (NSUInteger )lastDrawnPointIndex; i++ ) {
674- CGFloat x = viewPoints[i].x ;
675- CGFloat y = viewPoints[i].high ;
676- if ( isnan (y)) {
677- y = viewPoints[i].y ;
678- }
679-
680- if ( !isnan (x) && !isnan (y)) {
681- if ( i == (NSUInteger )firstDrawnPointIndex ) {
682- CGPathMoveToPoint (fillPath, NULL , x, y);
682+ switch ( self.fillDirection ) {
683+ case CPTRangePlotFillHorizontal:
684+ // First do the top points
685+ for ( NSUInteger i = (NSUInteger )firstDrawnPointIndex; i <= (NSUInteger )lastDrawnPointIndex; i++ ) {
686+ CGFloat x = viewPoints[i].x ;
687+ CGFloat y = viewPoints[i].high ;
688+ if ( isnan (y)) {
689+ y = viewPoints[i].y ;
690+ }
691+
692+ if ( !isnan (x) && !isnan (y)) {
693+ if ( i == (NSUInteger )firstDrawnPointIndex ) {
694+ CGPathMoveToPoint (fillPath, NULL , x, y);
695+ }
696+ else {
697+ CGPathAddLineToPoint (fillPath, NULL , x, y);
698+ }
699+ }
683700 }
684- else {
685- CGPathAddLineToPoint (fillPath, NULL , x, y);
701+
702+ // Then reverse over bottom points
703+ for ( NSUInteger j = (NSUInteger )lastDrawnPointIndex; j >= (NSUInteger )firstDrawnPointIndex; j-- ) {
704+ CGFloat x = viewPoints[j].x ;
705+ CGFloat y = viewPoints[j].low ;
706+ if ( isnan (y)) {
707+ y = viewPoints[j].y ;
708+ }
709+
710+ if ( !isnan (x) && !isnan (y)) {
711+ CGPathAddLineToPoint (fillPath, NULL , x, y);
712+ }
713+ if ( j == (NSUInteger )firstDrawnPointIndex ) {
714+ // This could be done a bit more elegant
715+ break ;
716+ }
686717 }
687- }
688- }
718+ break ;
689719
690- // Then reverse over bottom points
691- for ( NSUInteger j = (NSUInteger )lastDrawnPointIndex; j >= (NSUInteger )firstDrawnPointIndex; j-- ) {
692- CGFloat x = viewPoints[j].x ;
693- CGFloat y = viewPoints[j].low ;
694- if ( isnan (y)) {
695- y = viewPoints[j].y ;
696- }
720+ case CPTRangePlotFillVertical:
721+ // First do the left points
722+ for ( NSUInteger i = (NSUInteger )firstDrawnPointIndex; i <= (NSUInteger )lastDrawnPointIndex; i++ ) {
723+ CGFloat x = viewPoints[i].left ;
724+ CGFloat y = viewPoints[i].y ;
725+ if ( isnan (x)) {
726+ y = viewPoints[i].x ;
727+ }
728+
729+ if ( !isnan (x) && !isnan (y)) {
730+ if ( i == (NSUInteger )firstDrawnPointIndex ) {
731+ CGPathMoveToPoint (fillPath, NULL , x, y);
732+ }
733+ else {
734+ CGPathAddLineToPoint (fillPath, NULL , x, y);
735+ }
736+ }
737+ }
697738
698- if ( !isnan (x) && !isnan (y)) {
699- CGPathAddLineToPoint (fillPath, NULL , x, y);
700- }
701- if ( j == (NSUInteger )firstDrawnPointIndex ) {
702- // This could be done a bit more elegant
739+ // Then reverse over right points
740+ for ( NSUInteger j = (NSUInteger )lastDrawnPointIndex; j >= (NSUInteger )firstDrawnPointIndex; j-- ) {
741+ CGFloat x = viewPoints[j].right ;
742+ CGFloat y = viewPoints[j].y ;
743+ if ( isnan (x)) {
744+ y = viewPoints[j].x ;
745+ }
746+
747+ if ( !isnan (x) && !isnan (y)) {
748+ CGPathAddLineToPoint (fillPath, NULL , x, y);
749+ }
750+ if ( j == (NSUInteger )firstDrawnPointIndex ) {
751+ // This could be done a bit more elegant
752+ break ;
753+ }
754+ }
703755 break ;
704- }
705756 }
706757
707758 // Close the path to have a closed loop
0 commit comments