I working with highcharts in angularjs and I want to change the background like in the picture. Also, I want to be able to specify dimentions of rectangles
UPDATE
The problem is when I give the parameters to draw my rectangles, it's affecting all the div and what I want is to draw the rectangles on my chart surface only. The problem is because of "this" which I'm using in my code and I want now to replace it with chart.
You can use the renderer to draw arbritary squares on a chart. You can also use the Axis function toPixels to convert values to pixels. I have a function that takes x and y values and draws a square. If you butted those squares together you could have your regions.
var drawSquare = function(x1,x2,y1,y2,color) {
x1 = chart.xAxis[0].toPixels(x1);
x2 = chart.xAxis[0].toPixels(x2);
y1 = chart.yAxis[0].toPixels(y1);
y2 = chart.yAxis[0].toPixels(y2);
var width = x2 - x1;
var height = y1 - y2;
chart.renderer.rect(x1,y2,width, height, 0)
.attr({
fill: color,
zIndex: 0
})
.add();
};
drawSquare(0,40,0,35,'rgba(129,184,222,.5)');
drawSquare(40,100,0,35,'rgba(255,223,134,.5)');
drawSquare(0,40,35,150,'rgba(130,215,169,.5)');
drawSquare(40,100,35,150,'rgba(183,153,206,.5)');
http://jsfiddle.net/Lh74L8vu/1/
Related
I have 100 .png images loaded into a Godot 3.5.1 array of objects (named splash_planets) as StreamTextures. I need to know how to reference them to allow scaling. I am able to draw them using the following:
for splash_planet in splash_planets:
center = Vector2(splash_planet._x, splash_planet._y)
draw_texture(splash_planet._texture, center)
Now I want to do something like:
draw_texture(splash_planet._texture, center, (scale_x, scale_y))
Thanks in advance for any advice.
First of all, in this line:
draw_texture(splash_planet._texture, center)
You would be drawing the texture with the upper left corner on the coordinates of center. If you want to draw the texture with the center on center, you do this:
var texture := splash_planet._texture
var size := texture.get_size()
draw_texture(texture, center - size * 0.5)
Since you are using draw_texture and you want to scale, you can use draw_set_transform:
draw_set_transform(Vector2.ZERO, 0.0, Vector2(scale_x, scale_y))
As you can see the third parameter is the scale. The first two parameters are translation and rotation. Once you have set the transform you can do the draw call as usual:
draw_set_transform(Vector2.ZERO, 0.0, Vector2(scale_x, scale_y))
var texture := splash_planet._texture
var size := texture.get_size()
draw_texture(texture, center - size * 0.5)
Calling draw_set_transform again (or calling draw_set_transform_matrix) will overwrite the previos transform.
Alternatively you can use draw_texture_rect:
var texture := splash_planet._texture
var size := texture.get_size() * Vector2(scale_x, scale_y)
var rect := Rect2(center - size * 0.5, size)
draw_texture_rect(texture, rect, false)
In this case we compute the rectangle where to draw the texture. We also specify we don't want to tile it (the false as third argument), so Godot will stretch it.
You might also be interested in draw_texture_rect_region, which allows you to draw a rectangular region of the source texture.
Working on a private stock chart where I use a rendering rectangle with an origin at lower left and inverted y axis, scale factor y is negative. Y axis ticks render nicely but drawing text (drawstring) is where I run into problems.
using (Pen pen = new Pen(_color))
using (Font drawFont = new Font("Arial", 16))
using (SolidBrush drawBrush = new SolidBrush(Color.Black))
{
pen.Width = 1F / e.Graphics.DpiX;
foreach (float tick in this.TimeSeriesPanelControl.YTicks)
{
e.Graphics.DrawLine(pen, right, tick, right + 10, tick);
// this is not producing text to the right of the tick that renders properly.
e.Graphics.DrawString(tick.ToString("F2"), drawFont, drawBrush, right + 15, tick);
}
}
I have seen that the text is upside down caused by the negative scale factor on the y coordinate.
The question is how to make drawstring render the text to the right of the tick?
Lets say I have a map in Mercator projection, and I know top and bottom latitudes:
topLatitude = 80; bottomLatitude = -55;
I also know width and height of a map:
width = 800; height = 500;
I want to rescale the map to Equirectangular projection, keeping the same width.
How can I calculate new height of a map?
I came up with a solution.
This is formula to calculate x and y of Mercator projected map:
Here is function for y:
function degreesToRadians(degrees){
return degrees / 180 * Math.PI;
}
function mercatorLatitudeToY(latitude){
return Math.log(Math.tan(Math.PI / 4 + degreesToRadians(latitude) / 2));
}
When R=1 the result you get is radians. So I calculate y for top and bottom latitudes.
Next, I calculate the same radians if the projection is Equirectangular - I simply need to convert top and bottom latitude to radians. And last thing - I just need to find aspect ratio of differences:
var scale = (mercatorLatitudeToY(topLatitude) - mercatorLatitudeToY(bottomLatitude))/ (degreesToRadians(topLatitude) - degreesToRadians(bottomLatitude));
For map without Antarctica, aspect ratio is ~1.5
Hi would it be possible to text or label to an Shape object in silverlight like an arc? Currently I created a chart compose of multiple arcs, I need to set a label on top of the arc to identify whose data it is.
You can use a PathListBox if you want to place the text on an arc. See text along curvature path like circular or arc in silverlight
Alternatively, you can position your own TextBlock object. Use the Polar to Rectangular conversion http://www.teacherschoice.com.au/maths_library/coordinates/polar_-_rectangular_conversion.htm
For instance if the center of your circle is 10,20 and the radius is 30 and the angle where you want to place the textblock is 45, then
double DegreeToRadian(double degree) { return Math.PI / 180 * degree; }
x = 30 * Math.Cos(DegreeToRadian(45)) + 10
y = 30 * Math.Sin(DegreeToRadian(45)) + 20
I have a grid with 100 columns and 100 rows. I want to draw a line between the centre of one of those grid squares and another, say 45,25 to 75,38.
I am happy with being able to draw a line, but how can i find the x and y pos of the centre of the two grid squares? Or is there a better approach i have missed
Your presentation should work with the grid you define. It seems the issue is that the representation of the thing you are trying to join is not centred on the grid location you specified. Your line should be drawn from 45,25 to 75,38. If that appears to not draw from the centres, then the things drawn at 45,25 and 75,38 are not drawn on the centre of the grid location.
If your display is grid based, then finding the centre of the screen grid from your theoretical 45,25 location would be something along these lines:
screenXcentre = ((xPos-1)*CellWidth)-(CellWidth/2);
screenYcentre = ((yPos-1)*CellHeight)-(CellHeight/2);
The coordinates of the center of the line is (center_x, center_y) where:
center_x = x1 + (x2 - x1/2)
center_y = y1 + (y2 - y1/2)
when x2 > x1 and y2 > y1.
So for your example:
center_x = 45 + ((75 - 45) / 2)
center_y = 25 + ((38 - 25) / 2)
HTH.