How to fix a gap between the x and y axes in core plot - ios

I am using [_graph.defaultPlotSpace scaleToFitPlots:[_graph allPlots]];
and if where none of the plots has a y value of 0, there is a gap between the bottom of the Y axis and the X axis.
I've tried using _graph.axisSet.xAxis.orthogonalCoordinateDecimal = CPTDecimalFromDouble(0.0);
as well as a calculated yMin instead of 0.0.
Yet, I still get this:
I've also tried to rescale the plot space, thus:
[_graph.defaultPlotSpace setPlotRange:r forCoordinate:CPTCoordinateY];
but couldn't figure out how to set a new minLimit for r.

Use the axisConstraints to position the x-axis at the lower edge of the plot area:
x.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];

Related

SCNNode direction issue

I put a SCNNode to a scene. I want to provide proper rotation in space, because this node is a pyramid. I want Z axis to be pointed to V2 point, and X axis to be pointed to V1 point (these V2 and V1 point are calculated dynamically, and of course in this case the angle between axis will be 90 degrees, because I calculate them properly).
The problem: I can't point X axis, because SCNLookAtConstraint(target: nodeWithV2) points only Z axis, and what I see is that Z axis is OK, but X axis is always random, that's why my Pyramid orientation is always wrong. How can I point X axis?
Here is my code:
let pyramidGeometry = SCNPyramid(width: 0.1, height: 0.2, length: 0.001)
pyramidGeometry.firstMaterial?.diffuse.contents = UIColor.white
pyramidGeometry.firstMaterial?.lightingModel = .constant
pyramidGeometry.firstMaterial?.isDoubleSided = true
let nodePyramid = SCNNode(geometry: pyramidGeometry)
nodePyramid.position = SCNVector3(2, 1, 2)
parent.addChildNode(nodePyramid)
let nodeZToLookAt = SCNNode()
nodeZToLookAt.position = v2
parent.addChildNode(nodeZToLookAt)
let constraint = SCNLookAtConstraint(target: nodeZToLookAt)
nodePyramid.constraints = [constraint]
But that only sets the direction for Z axis, that's why X axis is always random, so the rotation is always random. How can I set X axis direction to my point V1?
starting iOS 11 SCNLookAtConstraint has a localFront property that allows you to change which axis is used to orientate the constrained node.

How to get coordinate on the chart

I have used following way to get x-axis and y-axis co-ordinate. But I'm unable to get y axis co-ordinates.
**/*X axis max*/**
double xMaxAxisBottom = m_Chart.GetAxis().GetBottom().GetMaximum();// try to get x axis
double xMaxAxisBottomPixelPos = m_Chart.GetAxis().GetBottom().CalcXPosValue(xMaxAxisBottom); // Here trying to position based on x-axis co-ordinate
**/*X axis min*/**
double xMinAxisBottom = m_reschedChart.GetAxis().GetBottom().GetMinimum();//// try to get x axis minimum
double xMinAxisBottomPixelPos = m_Chart.GetAxis().GetBottom().MinXValue();
**/*Y axis max*/**
double xMaxAxisLeft = m_reschedChart.GetAxis().GetLeft().GetMaximum();
double xMaxAxisLeftPixelPos = m_reschedChart.GetAxis().GetLeft().MaxXValue();
**/*Y axis min*/**
double xMinAxisLeft = m_Chart.GetAxis().GetLeft().GetMinimum();
double xMinAxisLeftPixelPos = m_Chart.GetAxis().GetLeft().MinXValue();
**/*X axis length*/**
double xAxisBottomLen = m_Chart.GetAxis().GetBottom().GetEndPosition() - m_Chart.GetAxis().GetBottom().GetStartPosition();
double xAxisBottomLenPixelPos = m_Chart.GetAxis().GetBottom().CalcXPosValue(xAxisBottomLen);
**/*Y axis length*/**
double yAxisLeftLen = m_Chart.GetAxis().GetLeft().GetEndPosition() - m_Chart.GetAxis().GetLeft().GetStartPosition();
double xAxisLeftLenPixelPos = m_Chart.GetAxis().GetBottom().CalcXPosValue(yAxisLeftLen);
**/*X origin*/**
double dXstartPos = m_Chart.GetAxis().GetBottom().GetStartPosition();
double dXstartPixelPos = m_reschedChart.GetAxis().GetBottom().CalcXPosValue(dXstartPos);
**/*Y origin*/**
double dYStartPos = m_Chart.GetAxis().GetLeft().GetStartPosition();
double dYStartPixelPos = m_Chart.GetAxis().GetLeft().CalcXPosValue(dYStartPos);
let me know if i am making any mistake to find the co-ordinates.
I wanted to find below mention co-ordinated using above code.
1 X axis max
2 X axis min
3 Y axis max
4 Y axis min
5 X axis length
6 Y axis length
7 X origin
8 Y origin
9 Label font size
Please let me know your view.
Thanks
The chart needs to be drawn to use these methods. They need some internal properties to be initialized to work as expected.
You can force a chart repaint before calling them with:
m_Chart.GetEnvironment().InternalRepaint();
EDIT:
Since you seem to be calling these functions at OnAfterDraw event, you don't need to force a chart repaint. However, I'd suggest you some modifications in your code.
I see you are using m_Chart and also m_reschedChart. Make sure you are using the correct TChart variable.
Your variables start with x and y but thay also include Bottom or Left depending on the axis they refer. This is redundant and increments the chances to write a mistake (ie xMaxAxisLeft).
CalcXPosValue has to be used with Horizontal axes and CalcYPosValue with Vertical axes. So you shouldn't call GetLeft().CalcXPosValue.
CalcXPosValue and CalcYPosValue are functions to convert axis values to screen pixels.
MinXValue and MaxXValue are to be used with Horizontal Axes while MinYValue and MaxYValue are to be used with Vertical Axes.
GetMinimum returns the same than MinXValue/MinYValue, and GetMaximum returns the same than MaxXValue/MaxYValue. All these functions return Axis values, not screen pixels.
GetStartPosition and EndStartPosition are thought to modify the Axis length and by default they use percentages as explained here, so GetStartPosition - EndStartPosition is always zero. And I think CalcXPosValue(GetStartPosition - EndStartPosition) is conceptually wrong too. Note IStartPos and IEndPos give you the Start and End positions in pixels. See the TeeChart ActiveX Tutorials here.
Find below the modified code I suggest you:
**/*X axis max*/**
double maxAxisBottom = m_Chart.GetAxis().GetBottom().GetMaximum();// try to get x axis
double maxAxisBottomPixelPos = m_Chart.GetAxis().GetBottom().CalcXPosValue(xMaxAxisBottom); // Here trying to position based on x-axis co-ordinate
**/*X axis min*/**
double minAxisBottom = m_Chart.GetAxis().GetBottom().GetMinimum();//// try to get x axis minimum
double minAxisBottomPixelPos = m_Chart.GetAxis().GetBottom().CalcXPosValue(minAxisBottom);
**/*Y axis max*/**
double maxAxisLeft = m_Chart.GetAxis().GetLeft().GetMaximum();
double maxAxisLeftPixelPos = m_Chart.GetAxis().GetLeft().CalcYPosValue(maxAxisLeft);
**/*Y axis min*/**
double minAxisLeft = m_Chart.GetAxis().GetLeft().GetMinimum();
double minAxisLeftPixelPos = m_Chart.GetAxis().GetLeft().CalcYPosValue(minAxisLeft);
Now you already know the position of the four squares in screen pixels so you can ie draw a rectangle using them to check it:
m_Chart.getCanvas().Rectangle(minAxisBottomPixelPos, minAxisLeftPixelPos, maxAxisBottomPixelPos, maxAxisLeftPixelPos);
If you also want or need the sizes of the axes in pixels, you can do:
**/*X axis length*/**
double axisBottomLenPixelPos = m_Chart.GetAxis().GetBottom().GetIEndPos() - m_Chart.GetAxis().GetBottom().GetIStartPos();
**/*Y axis length*/**
double axisLeftLenPixelPos = m_Chart.GetAxis().GetLeft().GetIEndPos() - m_Chart.GetAxis().GetLeft().GetIStartPos();
And you can check they are correctly calculated:
m_Chart.getCanvas().Rectangle minAxisBottomPixelPos, maxAxisLeftPixelPos, minAxisBottomPixelPos + axisBottomLenPixelPos, maxAxisLeftPixelPos + axisLeftLenPixelPos

Core Plot - Bar plot automatic initial zooming

How do I set an initial zoom based the maximum value of the x-axis and y-axis?
Example:
Plot 1:
Maximum value:
x-axis = 100;
y-axis = 110;
Plot 2:
Maximum value:
x-axis = 180;
y-axis = 230;
I need to the initial zoom be equal to two plots.
Regards
This will adjust the plot space to fit the plot data for two plots:
[plotSpace scaleToFitPlots:#[plot1, plot2]];
You can use this shortcut to scale the plot space to fit all of the plots in a graph:
[plotSpace scaleToFitPlots:[graph allPlots]];

Kivy garden-Graph absolute position of 0,0 on the graph

I'd like to find the relative position of the graph origin in order to display the correct mouse position when it's inside it. But the size and pos property of the graph class are relative to the labels too.
How can I find the absolute position of the point 0,0 on the graph?
There is a member Graph._plot_area. It is a StencilView and it's position and size are equal to the plot area of the graph, meaning it ranges from the start of the xmin, ymin to xmax, ymax in pixel position.
If graph point x,y = 0,0 is in view, it should be equal to _plot_area.pos, however if 0,0 is not in view, you will have to calculate where it is expected to be using a ratio for the x and y axis, they can be calculated by:
x_ratio = (xmax - xmin) / _plot_area.width
y_ratio = (ymax - ymin) / _plot_area.height
and the point calculated by:
x = xmin + x_ratio * ( x - xmin)
y = ymin + y_ratio * ( y - ymin)
Hope this helps!

Core-Plot : y Axis labels should start from 60

I need to draw a scatter plot, in which the x axis should intersect with y axis at (0,60).
I also need interval of 20 on the y Axis.
The problems I am facing right now are:
y axis is starting from 0
The gap between y axis labels example, from 60 - 80 is too much.
What I have done so far:
To set the intersection points:
x.orthogonalCoordinateDecimal = CPTDecimalFromString(#"60");
To set the major tick locations:
NSSet *majorTickLocations = [NSSet setWithObjects:[NSDecimalNumber zero],
[NSDecimalNumber numberWithUnsignedInteger:60],
[NSDecimalNumber numberWithUnsignedInteger:80],
[NSDecimalNumber numberWithUnsignedInteger:100],
[NSDecimalNumber numberWithUnsignedInteger:120],
nil];
y.majorTickLocations = majorTickLocations;
Any pointer in the direction will be helpful.
Regards,
Ishan
To make the axes cross at (0, 60), set the orthogonalCoordinateDecimal of each axis:
x.orthogonalCoordinateDecimal = CPTDecimalFromDouble(60.0);
y.orthogonalCoordinateDecimal = CPTDecimalFromDouble(0.0);
The axis labeling policy determines how the tick marks and labels are positioned. If you are providing the tick and label positions yourself (CPTAxisLabelingPolicyNone), you can put them anywhere you want. See the "Axis Labeling Policies" demo in the Plot Gallery example app for samples of each available labeling policy.

Resources