Core Plot padding left making some part of graph invisible while scrolling left - core-plot

When I try to scroll left of the axis, the x-axis is invisible to some extent because of setting left padding. Could someone help me on it ?
"This is the actual graph initially"
"This is when scrolled to left"
Same image with red circle identify the spot of the issue

Use axisConstraints to fix the axis in place even when scrolling the graph.
y.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];

Related

Core Plot horizontal bar chart on negative y-axis

I have a requirement to draw Core Plot horizontal bar chart with everything on the negative y-axis. I.e. the first index should appear at -1, like below:
I have figured out how to draw horizontal Bar Chart. But figuring out how to draw them in an "inverted" manner (to let user scroll downward with the tallest bar on top). My thought:
1) Convert the Y-index to negative
2) offset the Y-axis to the top of the graph instead of bottom
Is there any better way to do it?
I have found a historical article that's similar to my request (core-plot iOS reversed Y axis).
I have got what I needed after using this:
CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-yMax-1) length:CPTDecimalFromFloat(yMax)
P.S. you need to add the -1 to the Location parameter (-yMax-1) otherwise the horizontal bar at index 0 will not be shown clearly.

How to determine/calculate where the Y axis tick marks are being plotted in CorePlot?

I'm working with CorePlot to generate a bar graph with horizontal bars (CPTXYGraph and CPTBarPlot).
There are only 10 bars being plotted at any given time, but the labels for them are arbitrarily long. As a result of that the Y axis labels rotation is set to 0.5. For the longest labels there are clipping issues with the label going outside of the left and/or bottom of the plot area.
I've fixed this in the X direction by determining the width of the longest label (as rendered in the appropriate font) and rotated the appropriate way to set the left padding in the plotAreaFrame.
Due to the rotation of the labels, if the plot at the bottom of the graph has a long name it can still extend off the bottom edge of the graph and get clipped there.
I know how tall vertically the rotated label is, but where I'm stuck is trying to determine where in the plot area the axis label is being plotted so that I can determine how much bottom padding is required.
I'm not sure if I should be trying to determine how tall the X axis label section is and then subdividing the remaining height to determine where the ticks should fall, or if there's some other better way to go about it.
The label is offset from end of the nearest tick mark by the labelOffset. The position of the end of the tick mark depends on the tickDirection, tickLabelDirection, and majorTickLength.
There are methods that allow you to convert a point from the plot space coordinate system to the view coordinate system. I've ended up solving the problem with code like the following:
// Tell the graph to lay itself out if it needs to.
[self.graph layoutIfNeeded];
// Create a point that represents 0,1 as plotted on the graph.
NSDecimal plotPoint[2];
plotPoint[CPTCoordinateX] = CPTDecimalFromInt (0);
plotPoint[CPTCoordinateY] = CPTDecimalFromInt (1);
// Convert that point from the plot coordinate system to the view coordinate system
CGPoint point = [self.graph.defaultPlotSpace plotAreaViewPointForPlotPoint: plotPoint];
// If the difference between the height of the rotated label and the position that it
// will be plotted at is at least the bottom padding, then the height is too large,
// so fix the padding.
if (labelHeight - point.y >= self.graph.plotAreaFrame.paddingBottom)
[self.graph.plotAreaFrame setPaddingBottom: (labelHeight - point.y)];
My graphs have a default bottom padding already set as a minimum, allowing this code to bump it up if there isn't enough already.

Coreplot: Axis Labels Fixed Location

I'm trying to customize a Coreplot graph in many ways I can and the next thing I would like to do is place the X Axis Labels (one that is custom as well) at the bottom of the graph, independent of the X axis' position (whether it's scrolled up or down).
To make it clear, it is similar to giving the labels an offset value of something like 50.0. But offset is not the property I'm looking for since it fixes the labels location relative to the X axis.
Any way this can be done? Or do I have to skip the axisLabels property and place and layer or something manually at the bottom of the graph?
EDIT: Alright, I managed to place an axis on the bottom with CPTConstraints. But it's not on the bottommost. If a plot point is on those levels, the plot line overlaps the labels. I tired padding of the graph but of course, it moves the whole graph, hence the issue persists.
Thanks in advance
Make a second x-axis. Have the first one draw the axis line, tick marks, etc., as normal but no labels. Label the second one and set all of the line style properties to nil so it doesn't draw any of the lines.
Turns out that aside from the graph, the plotAreaFrame property of the CPTGrpah also has paddings. If you give more paddings to plotAreaFrame than that of the graph, the plot will be drawn in a smaller frame and the rest of the graph area will be for you to add what you want (i.e., a second Axis).
Big thanks to #Eric, for trying to answer Every single CorePlot question as soon as possible.
CorePlot does have a lot of customisation than I thought.

CorePlot axisLine and gridLine length too long

I'm using CorePlot for my current project and its amazing.
The only problem I came across is the length of the axis and grids.
I'm only using a positiv coordinate system with labels on the left and bottom side.
And my problem is the length of the axis and grids in direction to my labels.
I tried to use:
axisSet.xAxis.orthogonalCoordinateDecimal = CPTDecimalFromString(#"-value");
axisSet.yAxis.orthogonalCoordinateDecimal = CPTDecimalFromString(#"-value");
or
x.labelOffset = value;
y.labelOffset = value;
but this is only setting the distance of my labels different and not affecting the grids length.
In my example the y-axis and there grid overlaps my label:#{1,2,3,4,5,6,7,8}
Did somebody dealed with the same problem? THX for all answer to the right way!
Use the visibleRange and gridLinesRange to limit the axes and grid lines, respectively. See the "Control Chart" in the Plot Gallery example app for sample code.

Core plot floating y axis

On iOS core plot, my data comes in real time and I want it to scroll to the left while the data is ticking in. I also would want user to be able to pan horizontally while always seeing the y-axis visible on the left. From some googling it seems like there used to be isFloatingAxis property on CPTAxis but that's no longer there. What should I do? I don't think setting constraint is what I need because I do want free horizontal scrolling to see some data to the right and left.
OK I do see that constraint is just what I need. In CorePlotGallery under example directory there is a CurvedScatterPlot example which shows how to do it. I can get CPTXYAxis off the axisSet and set axisConstraints:
CPTXYAxis *y = axisSet.yAxis;
y.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];
And it will work.

Resources