Change origin position in ios-charts - ios-charts

Has anyone tried setting a custom origin (0,0) for ios-charts?
The default origin is at the bottom left corner, I want my origin at the top left corner, is this possible? (see images for reference)
default
what i want to achieve

You can change label position for XAxis instance object using your chartView object.
//self.chartView is the ChartView instance.
let xAxis : XAxis = self.chartView.xAxis
xAxis.labelPosition = .top

It's quite simple.
First, as another answer said, change xAxis.labelPosition = .top.
Then, set Y axis self.chartView.leftAxis.inverted = true.
That`s all!

Related

Loop to change block position

I have a Matlab script that creates a Model Block for each element i found in a text file.
The problem is that all Models are created on each other in the window. So i'm trying to make a loop like:
for each element in text file
I add a Model block
I place right to the previous one
end
So it can look like this:
As you can see on the left, all models are on each other and I would like to place them like the one on the right.
I tried this:
m = mdlrefCountBlocks(diagrammeName)+500;
add_block('simulink/Ports & Subsystems/Model',[diagrammeName '/' component_NameValue]);
set_param(sprintf('%s/%s',diagrammeName,component_NameValue), 'ModelFile',component_NameValue);
size_blk = get_param(sprintf('%s/%s',diagrammeName,component_NameValue),'Position');
X = size_blk(1,1);
Y = size_blk(1,2);
Width = size_blk(1,3);
Height = size_blk(1,4);
set_param(sprintf('%s/%s',diagrammeName,component_NameValue),'Position',[X+m Y X+Width Y+Height]);
Inside the loop but it returns an error Invalid definition of rectangle. Width and height should be positive.
Thanks for helping!
The position property of a block does actually not contain its width and height, but the positions of the corners on the canvas (see Common Block Properties):
vector of coordinates, in pixels: [left top right bottom]
The origin is the upper-left corner of the Simulink Editor canvas before any canvas resizing. Supported coordinates are between -1073740824 and 1073740823, inclusive. Positive values are to the right of and down from the origin. Negative values are to the left of and up from the origin.
So change your code to e.g.:
size_blk = get_param(sprintf('%s/%s',diagrammeName,component_NameValue),'Position');
set_param(sprintf('%s/%s',diagrammeName,component_NameValue),'Position', size_blk + [m 0 0 0]);

How to rotated left axis label in stack bar charts?

I am using Charts library. I want to rotate left axis label to 90 degrees. How can I do that? Please help me.
I am able to rotate xAxis label. This is how I rotate xAxis:
barChart.xAxis.labelPosition = XAxis.LabelPosition.topInside
barChart.xAxis.labelRotationAngle = kXAxisLabelRotationAngleForShareOfVoiceByDrugs
And for leftAxis:
barChart.leftAxis.valueFormatter = IndexAxisValueFormatter(values:hotTopicsAndWeakSignalsModel.barChartDrugNames)
barChart.leftAxis.labelPosition = .outsideChartr
How can set rotation to leftAxis?
To rotate the xAxis Label, you need to do this:
barChart.xAxis.labelRotationAngle = YOUR_ANGLE
like
barChart.xAxis.labelRotationAngle = 90.0

How do I complete remove the draw value on bar chart using iOS charts with swift 3

I am trying to remove the bottom draw values (in black) on my X axis. I tried self.chartActual.drawValueAboveBarEnabled = false but all that does is move the values to below the top of the bar. I also tried self.chartActual.xAxis.drawLabelsEnabled = false but that hides my top labels.
How do I remove the drawvalue on the X axis using ios-charts?
let datamore = BarChartData()
let ds12 = BarChartDataSet(values: dataEntries, label: nil)
datamore.addDataSet(ds12)
datamore.setDrawValues(false)
I needed the last line AFTER adding the data.

How do I add a units label to a ILNumerics Colorbar

I would like to display the units in text for the values displayed on the colorbar. I have a colorbar added to my ILSurface and I'd like to show my units in text on the color bar along with the range.
Edit: I want to display text at the bottom of the color bar below the bottom tick just the one label.
I was able to get this to work this way
new ILColorbar()
{
Children = { new ILLabel("nm") {Position = new Vector3(.2f,.98f,0) } }
}
I have to say the Position coordinates are not very intuitive. I had to basically adjust the numbers by trial and error until it fit. I knew that the values range 0..1 so the X value was 1 at the bottom but I wanted it up from the border. And the Y value would need to be indented in some but I wasn't sure what was a good value but .2 works.
You can access the axis of ILColorbar and configure it in the usual way. Use the LabelTransformFunc on the ticks to set your own label text. You can use the default transform func and add your unit string.
Example:
var cb = scene.First<ILColorbar>();
cb.Axis.Ticks.LabelTransformFunc = (ind, val) =>
{
return ILTickCollection.DefaultLabelTransformFunc(ind, val) + "nm";
};
You can read more about the axis configuration here:
Axis Configuration
LabelTransformFunc in ApiDoc
Edit:
If only one label is needed, then add a new ILLabel object in ILColorbar group as follows:
new ILColorbar() {
new ILLabel("z(nm)") {
Position = new Vector3(0.5,1,0),
Anchor = new PointF(0.5f,0)
}
}
The ILColorbar area have the relative coordinates 0..1 over the width and the height of the color bar. So we set position x in the middle of the ILColorbar, and position y at the bottom.
The Anchor position is used as relative position in relation to the Position point.
ILLabel Documentation

SpriteKit bodyInRect finding node when it shouldn't

I'm attempting to detect if there's a sprite node immediately to the left or right of the current sprite node.
This seems straightforward, but I'm seeing an odd behaviour.
I've created a thin rect (width = 1point) that's the same height as the current node and with the same origin as the current node.
e.g:
// Create a thin rect that's aligned to the left edge of 'block'
CGRect adjacentFrame;
adjacentFrame = CGRectMake(block.frame.origin.x,
block.frame.origin.y,
1,
block.frame.size.height);
// Shift the rect left a few points to position it to the left of 'block'
adjacentFrame.origin.x -= 10;
Then I test to see if that rect (adjacentFrame) is intersecting a node:
SKPhysicsBody* obstructingBody;
obstructingBody = [self.physicsWorld bodyInRect:adjacentFrame];
Now, the weird thing is, obstructingBody contains 'block' itself!
I've even added code to add a SpriteNode to the scene with a frame of adjacentFrame so I can check the rect's positioning. It's clearly displaying a few points left of 'block' and is clearly not touching it!
Any ideas what could be going on here?
Thanks,
Chris
bodyInRect needs scene coordinates. You provide coordinates in the coordinate space of block.parent. Unless block.parent is the scene itself, you need to convert origin with:
CGRect blockFrame = block.frame;
blockFrame.origin = [self convertPoint:blockFrame.origin toNode:self.scene];
Also block's width must be less than 10 otherwise your -10 offset isn't enough to move the frame outside the block's frame.