Skip to content
This repository has been archived by the owner on Jul 31, 2019. It is now read-only.

Commit

Permalink
Added options to draw a background fill behind and a border line arou…
Browse files Browse the repository at this point in the history
…nd each legend entry. Fixed issue 597.
  • Loading branch information
eskroch committed Dec 21, 2013
1 parent 7abda0d commit 89599d4
Show file tree
Hide file tree
Showing 4 changed files with 287 additions and 13 deletions.
1 change: 1 addition & 0 deletions documentation/changelog.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ To be determined.
- **New**: Animations can now start when the value of the animated property enters the animated range.
- **New**: Added legend delegate methods to customize the swatch fill and border line style for each legend entry.
- **New**: Added a plot property to control drawing of the legend entry swatch.
- **New**: Added options to draw a background fill behind and a border line around each legend entry.
- **Changed**: Switched to a new algorithm for computing curved scatter plots.
- **Changed**: Miscellaneous bug fixes and cleanup.
- **Removed**: Removed the elastic global range properties from `CPTXYPlotSpace`. Turning on momentum scrolling now automatically allows elastic ranges, too.
Expand Down
13 changes: 11 additions & 2 deletions examples/CorePlotGallery/src/plots/SimplePieChart.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,17 @@ -(void)renderInLayer:(CPTGraphHostingView *)layerHostingView withTheme:(CPTTheme
theLegend.numberOfColumns = 1;
theLegend.fill = [CPTFill fillWithColor:[CPTColor whiteColor]];
theLegend.borderLineStyle = [CPTLineStyle lineStyle];
theLegend.cornerRadius = 5.0;
theLegend.delegate = self;

theLegend.entryFill = [CPTFill fillWithColor:[CPTColor lightGrayColor]];
theLegend.entryBorderLineStyle = [CPTLineStyle lineStyle];
theLegend.entryCornerRadius = CPTFloat(3.0);
theLegend.entryPaddingLeft = CPTFloat(3.0);
theLegend.entryPaddingTop = CPTFloat(3.0);
theLegend.entryPaddingRight = CPTFloat(3.0);
theLegend.entryPaddingBottom = CPTFloat(3.0);

theLegend.cornerRadius = 5.0;
theLegend.delegate = self;

graph.legend = theLegend;

Expand Down
31 changes: 31 additions & 0 deletions framework/Source/CPTLegend.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ extern NSString *const CPTLegendNeedsReloadEntriesForPlotNotification;
/// @name Drawing
/// @{

/** @brief @optional This method gives the delegate a chance to provide a background fill for each legend entry.
* @param legend The legend.
* @param idx The zero-based index of the legend entry for the given plot.
* @param plot The plot.
* @return The fill for the legend entry background or @nil to use the default @link CPTLegend::entryFill entryFill @endlink .
**/
-(CPTFill *)legend:(CPTLegend *)legend fillForEntryAtIndex:(NSUInteger)idx forPlot:(CPTPlot *)plot;

/** @brief @optional This method gives the delegate a chance to provide a border line style for each legend entry.
* @param legend The legend.
* @param idx The zero-based index of the legend entry for the given plot.
* @param plot The plot.
* @return The line style for the legend entry border or @nil to use the default @link CPTLegend::entryBorderLineStyle entryBorderLineStyle @endlink .
**/
-(CPTLineStyle *)legend:(CPTLegend *)legend lineStyleForEntryAtIndex:(NSUInteger)idx forPlot:(CPTPlot *)plot;

/** @brief @optional This method gives the delegate a chance to provide a custom swatch fill for each legend entry.
* @param legend The legend.
* @param idx The zero-based index of the legend entry for the given plot.
Expand Down Expand Up @@ -112,6 +128,13 @@ extern NSString *const CPTLegendNeedsReloadEntriesForPlotNotification;
CPTLineStyle *swatchBorderLineStyle;
CGFloat swatchCornerRadius;
CPTFill *swatchFill;
CPTLineStyle *entryBorderLineStyle;
CGFloat entryCornerRadius;
CPTFill *entryFill;
CGFloat entryPaddingLeft;
CGFloat entryPaddingTop;
CGFloat entryPaddingRight;
CGFloat entryPaddingBottom;
NSUInteger numberOfRows;
NSUInteger numberOfColumns;
BOOL equalRows;
Expand All @@ -132,6 +155,14 @@ extern NSString *const CPTLegendNeedsReloadEntriesForPlotNotification;
@property (nonatomic, readwrite, copy) CPTLineStyle *swatchBorderLineStyle;
@property (nonatomic, readwrite, assign) CGFloat swatchCornerRadius;
@property (nonatomic, readwrite, copy) CPTFill *swatchFill;

@property (nonatomic, readwrite, copy) CPTLineStyle *entryBorderLineStyle;
@property (nonatomic, readwrite, assign) CGFloat entryCornerRadius;
@property (nonatomic, readwrite, copy) CPTFill *entryFill;
@property (nonatomic, readwrite, assign) CGFloat entryPaddingLeft;
@property (nonatomic, readwrite, assign) CGFloat entryPaddingTop;
@property (nonatomic, readwrite, assign) CGFloat entryPaddingRight;
@property (nonatomic, readwrite, assign) CGFloat entryPaddingBottom;
/// @}

/// @name Layout
Expand Down
Loading

0 comments on commit 89599d4

Please sign in to comment.