kaiserfarrell / core-plot

Automatically exported from code.google.com/p/core-plot
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Easy way to show/hide all labels in a plot #468

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I need to show or hide all labels in a plot, but there's no easy way to do this 
in the current API. For example, I would like to do:

  plot.showLabels = NO;

I've attached a patch that adds this property to CPTPlot. Please review and 
apply. Thanks

Original issue reported on code.google.com by tre...@vocaro.com on 30 Oct 2012 at 2:35

Attachments:

GoogleCodeExporter commented 8 years ago
I don't see why this is needed. Setting either the labelTextStyle or 
labelFormatter to nil will remove the data labels. Both properties default to 
nil, so you have to explicitly set them to get labels to appear in the first 
place.

Original comment by eskr...@mac.com on 31 Oct 2012 at 1:19

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Setting labelTextStyle to nil does not remove the data labels. The labels are 
drawn anyway. I verified this with CPTPieChart in the Plot Gallery and my own 
app. It appears that the style set in the layer returned by dataLabelForPlot: 
is used regardless of the labelTextStyle value.

The showLabels property is better because it overrides all other label-related 
properties when determining whether or not to draw the labels. It is also more 
intuitive (since it's not obvious that changing the text style is the way to 
show/hide labels). It's slightly easier to use, too -- for instance, 
temporarily hiding the labels does not require saving/restoring the text style.

Original comment by tre...@vocaro.com on 31 Oct 2012 at 6:38

GoogleCodeExporter commented 8 years ago
If you're providing labels (or anything else) via the datasource, you have to 
call -reloadData on the plot and return new labels or nil to hide them.

Original comment by eskr...@mac.com on 31 Oct 2012 at 11:43

GoogleCodeExporter commented 8 years ago
Yes, that would achieve the same effect, but I wouldn't call it easy (see 
title). You'd have to add a "showLabels" flag to the data source, plus some 
additional logic to test it and optionally call reloadData. And there'd also 
have to be some communication path between the view controller and the data 
source to change this flag. It gets messy. I'm proposing this showLabels 
property as a way to push that extra complexity into Core Plot and thereby 
simplify the client code.

Original comment by tre...@vocaro.com on 2 Nov 2012 at 2:14

GoogleCodeExporter commented 8 years ago

Original comment by eskr...@mac.com on 28 Apr 2013 at 4:26

GoogleCodeExporter commented 8 years ago
This issue was closed by revision f4270c45ba49.

Original comment by eskr...@mac.com on 28 Apr 2013 at 5:14