samuelltk / core-plot

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

Custom Labels on CPTXYAxisSet - CPTAxisLabelingPolicyNone #410

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. set CPTAxisLabelingPolicyNone on xAxis
2. generate axisLabels with NSMutableSet with tickLocation and offset properties
3. first and last tickLocation outside plotSpace.xRange but CPTAxisLabel text 
value should be partly visible - I use date formatter for xAxis labels

What is the expected output? What do you see instead?
Expected output should be partly generated label text (the part that should be 
visible)
Current status: in case of tickLocation outside plotSpace.xRange, label text is 
not generated

What version of the product are you using? On what operating system?
core-plot 1.0, iOS, static library

Please provide any additional information below.
In case that tickLocation is exactly on border of graph.plotAreaFrame, text 
labels are generated properly.
see code snippet:

        axisSet.xAxis.labelingPolicy = CPTAxisLabelingPolicyNone;
        NSMutableSet *newAxisLabels = [NSMutableSet set];
        NSMutableSet *majorTickLocations = [NSMutableSet set];

        int jMin = midnightTimeInterval-ScatterPlotXAxisMajorIntervalLength;
        int jMax = xAxisMax - xAxisMin + ScatterPlotXAxisMajorIntervalLength;
        int jStep = ScatterPlotXAxisMajorIntervalLength;

        for (j=jMin;j<jMax;j+=jStep) {

            NSLog(@"tickLocation: %i", j);
            [majorTickLocations addObject:[NSDecimalNumber numberWithUnsignedInteger:j]];

            NSDate *majorLabelTickTime = [firstTime dateByAddingTimeInterval:j];

            NSString *labelText = [NSString stringWithFormat:@"%@, %@",[formatter stringLocalDay:majorLabelTickTime], [formatter stringLocalShortDate:majorLabelTickTime]];

            CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText:labelText textStyle:textStyle];
            newLabel.tickLocation = CPTDecimalFromUnsignedInteger(j + ScatterPlotXAxisMajorIntervalLength / 2);

            newLabel.offset = 5.0;
             NSLog(@"majorLabelTick: %i, %@, %@", (j + ScatterPlotXAxisMajorIntervalLength / 2), [formatter stringLocalDay:majorLabelTickTime], [formatter stringLocalShortDate:majorLabelTickTime]);
            [newAxisLabels addObject:newLabel];

        }

        axisSet.xAxis.axisLabels = newAxisLabels;
        axisSet.xAxis.majorTickLocations = majorTickLocations;
        //axisSet.xAxis.visibleRange = [CPTPlotRange plotRangeWithLocation: CPTDecimalFromInteger(jMin) length:CPTDecimalFromInteger(jMax-jMin)];

Original issue reported on code.google.com by kucera.l...@gmail.com on 19 Mar 2012 at 8:41

Attachments:

GoogleCodeExporter commented 9 years ago
The reason of required functionality is the this graph is generated on 
scrollView. Next two pages pages with forthcoming weather data are generated on 
following pages. Graphs should appear joined.

Original comment by kucera.l...@gmail.com on 19 Mar 2012 at 8:45

Attachments:

GoogleCodeExporter commented 9 years ago
This behavior is related to the problem fixed in issue #104. Since you're 
placing a series of graphs next to each other, can't you just place the label 
on the next graph? You probably don't want labels from both graphs to overlap 
each other anyway. If there are any slight alignment problems, the overlapping 
labels will be blurry.

Original comment by eskr...@mac.com on 20 Mar 2012 at 12:05

GoogleCodeExporter commented 9 years ago
Yes, I would appreciate exactly such a behavior, probably switchable with some 
property. As you can see on third screen shot, there is border between pages. 
Graphs are continually joined, but labels are not drawn correctly. You are sure 
I can place the label on second screen, od at least in the middle, which works. 
I my opinion is that this behavior is correct, to draw everything what should 
be drawn. If you would limit some values, you can use visibleRange. Libor

Original comment by kucera.l...@gmail.com on 20 Mar 2012 at 6:45

GoogleCodeExporter commented 9 years ago
There are other artifacts in the third image besides the cutoff label. The 
gradient fill doesn't match up, either. I would recommend that you adjust the 
size of the individual graphs so that they join between days. That way you 
don't have to worry about breaking the labels and gradients across the joint.

Original comment by eskr...@mac.com on 21 Mar 2012 at 12:32

GoogleCodeExporter commented 9 years ago
Well this sounds correct :) 
I see the source code of CPTAxis.m
Just for my orientation, the condition, that prevents drawing "outsider" labels 
is on line 1284?:

-(void)updateAxisLabelsAtLocations:(NSSet *)locations inRange:(CPTPlotRange 
*)labeledRange useMajorAxisLabels:(BOOL)useMajorAxisLabels;

if ( labeledRange && ![labeledRange contains:locationDecimal] ) {
            continue;
        }

is that right? Are there any other dependencies?
Thank you for your inspirations and thank you for nice job (y)

Original comment by kucera.l...@gmail.com on 21 Mar 2012 at 8:51

GoogleCodeExporter commented 9 years ago
OK I see, this is for the CPTAxisLabelingPolicyProvided :)
-(void)updateCustomTickLabels method handles NONE policy :)
looks like ivar visible holds the ontormation about label visibility, isn't it?
Thank you

Original comment by kucera.l...@gmail.com on 21 Mar 2012 at 8:57

GoogleCodeExporter commented 9 years ago
So I made a Category to CPTAxis class and rewrote updateCustomTickLabels 
method, disabling test for label visibility. Then I set offset for all data in 
value of 86400 to prevent negative values in label.tickLocation.
Now it works as I need. Drawing is not 100% precise but for my purposes is 
acceptable. Thank you for your help :)

Original comment by kucera.l...@gmail.com on 21 Mar 2012 at 2:08

GoogleCodeExporter commented 9 years ago

Original comment by kucera.l...@gmail.com on 21 Mar 2012 at 4:27

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by eskr...@mac.com on 21 Mar 2012 at 11:19