I am drawing shapes from a JSON using Coregraphics and the co-ordinates span from -ve to +ve axis. I am able to draw it properly using translation, but as my co-ordinates are pretty large, the drawing goes out of bounds of the view. is there a way to shrink and fit the drawing to the view bounds? I tried some scaling but didn't work. ( I cant use an image context as it will become blurr when zoomed, I am trying to get some vector).
Please find below the sample project
DrawShapes from JSON
In the shapes.json I have points like below and the points 500,....570 are drawn out of bounds, I want to fit the entire drawing with in the view bounds after the drawing is completed.
"X": -200.07484,
"Y": 50.60354
},
{
"X": -500.07484,
"Y": 400.95078
},
{
"X": 570.77671,
"Y": 400.95078
},
{
"X": 570.77671,
"Y": 100.70688
Ok, After a lot of trials, I am finally able to fix the problem. I got a nice utility from MMScalableVectorView, where in which there was a method to adjust the content mode according to the entire drawing size and the actual view size.
More details: MMScalableVectorView Site
I am not posting the code here as it is his code. Look for the below method in the code
- (void)applyCTMTransformsForContext:(CGContextRef)context frame:(CGRect)frame
I have updated my code which now fits according to the graphic size.
Related
I'm creating a game that takes an image represented by a 16x16 array of html color codes and creates a 3D object made out of rectangular cuboids. Like taking the Paint program on Windows and extruding your image into the Z axis.
// An image containing 16 columns and 16 rows of hexcodes for 256 total hexcodes
[ [ "#FF5733", "#FF5733", "#FF5733", "#FF5733", ... ], [ "#FF5733", ... ] ]
How can I create the smallest possible array of rectangles that would cover the image without creating overlapping rectangles?
// Rectangles that represent the 2D image, a blank image would have only one rectangle
rectangles = [{
color = "#FF5733",
x = 5,
y = 3,
width = 5,
height = 5,
}, ... ]
My first attempt at a solution --- every single pixel in the 16x16 image getting a cube (256 cubes) --- created huge load times (30 seconds) for loading 500x 3D images.
One improvement I was able to make was "reading on" past the current color in the row until I hit a different color or the end of the row in order to create long rectangular cuboids across the row. This improvement cut the cuboid count in half. Extending this trick across the y axis has proven difficult. Overlapping rectangles look really ugly.
My understanding is that this problem is NP Hard. I'd be happy if we had a solution that had fewer rectangles even if its not provably the fewest rectangles.
The Wiki Article on the problem does not give any concrete suggestions.
I’m using 3D Highcharts. Data labels works fine for 2D charts but I’m facing issue with data label positioning after 3D projection.I’ve attached the screenshot and code snippet here for your reference.
Expected behaviour:
Data labels should be properly positioned appropriate to x-axis values.It should not go out of chart for extremely low values of series data.
Actual behaviour:
options3d = {
enabled: true,
alpha: 15,
beta: 15,
depth: 40
};
Description:
Consider the above screenshot having series data=[1,37,790,1962] and [4,2130,342,1302].Placement of datalabels for data ‘1’ and ‘1302’ are not aligned properly.We can achieve proper alignment of datalabels by changing alpha and beta values.But I’m looking for a proper fix that will allow me to achieve this.Thanks in advance.
Using the Highcharts example posted here how can you ensure that the Font Awesome icons will be positioned exactly in the middle of the data point like the native symbols/markers are? It gets called like this in the data series and uses the "plugin" that is found in that same Fiddle:
marker: {
symbol: 'text:\uf183' // fa-male
}
Using that example, if you toggle the series on/off a couple of times or zoom in/out the icons are no longer visually accurate, often displaying above the actual coordinate. In the image below you'd believe that data point had a value >50 based on where the icon is.
Their SVGRenderer example here doesn't seem to be effected.
It looks like problem with re-rendering icons later - height of the marker isn't considered. I suggest to change a bit logic for rendering icon:
var text = symbol.split(':')[1],
svgElem = this.text(text, x, y)
.attr({
translateY: h, // translate marker
translateX: -1
})
.css({
fontFamily: 'FontAwesome',
fontSize: h * 2
});
See demo: http://jsfiddle.net/2A7Zf/29/
If you want to use the markers XL-sized (i.e larger radius) for a custom chart (e.g. a Yes/No prevalence chart using the x and check icons, circle empty for the less prevalent one and circle filled for the more prevalent one and data labels showing counts/%s), then I'd recommend this tweak to center the symbols:
translateX: -w/2 + options.radius/4 - 3
I have one shape
var a = paper.rect(10,10,50,20);
I want to transform this shape into
var b = paper.circle(10,10,20);
Is there any way to transform these inbuilt shapes into one another. I know paths can be transformed anyhow you want them to but can shapes also be transformed?
You can do this if with a little creativity. A rectangle can be a circle if width, height and r (radius) are all the same. Then transforming a rect to a "circle" becomes:
p=Raphael(10, 50, 600, 300);
myrect=p.rect(50,50, 300,150,0).attr({"fill":"cyan"});
myrect.animate({"width":25,"height":25, "r":25}, 3000);
JSfiddle: http://jsfiddle.net/s1pz6Lzc/30/
I don't think that is possible, except if you simply fade out one shape and fade in the other one. The reason for this is that at some point in time during the conversion the shape is neither a rectangle nor a circle, while any single animated shape in SVG has to remain the same kind of shape throughout the animation, I believe.
My chart is ugly and I'm not sure what to do about it. It's ugly because the labels overlap and are barely readable. Ideas I've already considered:
Hide labels for small slices. This has the obvious negative of less information visible, especially when the page is printed. Our users print a lot.
Alternate big slices and little slices. Not ideal as it reduces the organization of the information and may suffer occasionally from the same issue.
Manually place each label with fixed positions. Expensive solution with regards to implementation time and code maintenance.
Anyone have a better idea? I wish highcharts was able to detect overlap and do something about it automatically. Here's the pic:
There is a new option in Highcharts to set the startAngle of the pie chart. You can use the startAngle to arrange all the small slices on the right side of the chart, allowing more of the labels to fit.
series: [{
startAngle: 90
}]
JSFiddle demo here: http://jsfiddle.net/highcharts/dK9CD/
I found a highcharts forum topic related to rotating the pie chart to better distribute labels in this sort of case, but it involves modifying the source to find the following line and change the cumulative reference to zero:
cumulative = -0.25, // start at top
One option that is not optimal but might work is to rotate the data labels a few degrees so that they don't overlap, like so:
{
plotOptions : {
pie : {
dataLabels : {
rotation : 15
}
}
}
}
I also come across the same issue. I fixed the issue with below code.
plotOptions : {
pie : {
dataLabels : {
whiteSpace: 'nowrap',
overflow: 'hidden',
textOverflow: 'ellipsis'
}
}
}