Dynamically repainting part of Chart.js background - chart.js2

I have a graph, constructed in Chart.js, which displays a certain performance metric that it dynamically receives. One of the things I was asked to do was to draw three bands on the background - red, yellow and green, that give a user a visual clue as to whether the metrics value is good, bad or average. I did it by extending a line version of chart.js and in the draw function of it painting my bands of colors in canvas.
It works well, if I know what the largest possible value is. Then I can define the max tick as that value and use that same value as a top point to draw my red band. However, if I don't know what the largest value would be, as soon as something larger arrives, the chart automatically scales to accommodate it, and I end up getting a white band above the red one.
Is there some way to dynamically redraw parts of the background after it was instantiated? The only thing I was able to think of was to add an "animation.onComplete" handler to repaint the background then. The problem, however, is that on the next value received, my newly painted background vanishes, so I assume I go about it the wrong way.

I am not sure if this may help, but the approach i have used that worked for me based on my experience with Chat.js is that, i create my Chat.js options once and only once, and then the chat data object is recreated every time i have new records. This actually works for me tho, i hope it works for you.

Related

know object behind another object is fully visible

I have developed scratch card effect.I am stuck at logic of how can I know object got visible which is behind the scratch card image? So that I can show reward screen.
PS: with modifications in this link I able to work this scratch card effect in uGUI.
There are many ways you could go about this. Assuming you know the dimensions of the red "target image" that the user is trying to uncover, you could take a fixed number of samples from the area that the target is under. Once, say, 80% of those samples are transparent (i.e. the target is visible at those positions), you can consider the object visible and show the reward screen.
You can use GetPixel to get the individual samples from the scratch texture.

progress circle UIControll iPhone

Anybody know how to make progress indicator of doing something like on a screenshot?
There are mainly two way to do this:
Create and save many images with the progress indicator in various positions. Then use UIImageView to display it, changing the image accordingly to the current progress. This is a easy solution, however it requires you to create (manually) the various images. Besides it's not continuos (even if it can be smooth enough, according to the number of images you save). However, it can give a good effect (according to your needs).
Draw the indicator at runtime. In your case it should not be so hard since your progress indicator is very simple. Take a look at CGContext, it will provide all the method to draw a circle, draw lines and fill a path with a color. This will give a better result than the previous solution, however it requires the indicator to be redrawn every time.
Check out TKAProgressCircleView. Does exactly what you need, I use it myself in couple of apps.

Page Flashing On Scroll

Any ideas why this page: http://mpdteam.net/projects.html is flashing when it scrolls? I've determined it's due to the background of the main content container, but why? is it a eye-trick, an image flaw, a browser flaw, or a code flaw? The code is easily viewable with view source or dev tools.
Let me know if you need anymore info. thanks.
(also, feel free to re-tag. i'm having a mind-blank for good tags)
It's because it uses finely spaced grey and white lines.
It is perhaps an example of the Moiré pattern, although this is more typically reserved for two overlapping grids at different angles.
I always assumed on a PC this occurred because of the redraw time between the two colours, and how finely spaced the lines are. The lines not perfectly aligning with pixels (e.g. anti-aliasing) would further enhance the flickering effect.
To fix it, try changing the size of the bands (e.g. try zooming out or in on the current page, and moving the browser, and note how you get reduced and even none of the described flickering effect).
Alternatively, you may want to apply a blur such that the difference between bands was softened (not sure if this would necessarily help).
Another suggestion that research yields is that it is due to background redrawing/scaling. However, a fixed background (as compared to a repeating one) isn't particularly applicable to your page.
In any case, for an in-depth discussion of some of the concepts involved, check out this awesome page (http://www.techmind.org/lcd/)

Cocos2D changes the colours in the last row of pixles in a sprite?

I have never seen this issue before, its very strange. Just wondering if anyone else has come across this too.
I have added a sprite to my game, its supposed to be the top left corner of a box to put text on to. I want to make it scalable without loosing anything so i have it broken up into sections. In the image above the one on top is the image itself, and then the one on the bottom is the image when its being drawn in the iPhone simulator.
Any idea why the last column of pixels on the right are altered? I have not scaled the image at all.
I don't know about Cocos2D, but in general terms what you've done here is to draw the image at a position that isn't an exact multiple of one pixel.
Consequently even without scaling you have resampled the image across a grid that doesn't coincide with the original image data, causing all pixels to be a bit off. It's just the right-hand edge is the most obvious case, since the resampling leaves you with a partial transparency here. But look at eg the two rows of purple pixels in the border: they're not the same, because your vertical alignment is off as well, causing a small amount of colour from the grey border below it to bleed into the lower row of purple.
Ok I actually figured it out this time. Cocos2D adds a bit of antialiasing to CCTextures. To stop it from doing this you need to call this:
[[mySprite texture] setAliasTexParameters];
to turn it back on you call this:
[[mySprite texture] setAntiAliasTexParameters];

iphone app developement: How to manipulate a selected area of an image?

The function I need to implement is like this:
1> select an small area of an image. This small area could be various shape, not only rectangle.
2> manipulate this area. for example: blurring
Is there any way to do it?
Thanks.
You've got your work cut out for you. Here is one way to do it. Make the selection. Whether you do it with CG paths, or some other way, you want to take the selected image, and make all the unselected area have an alpha of zero. YOu can accomplish this with blendmodes.
Then get the pixel data. See: http://developer.apple.com/mac/library/qa/qa2007/qa1509.html
Then you go through the data and anywhere where your alpha isn't zero, you average the pixel with the pixel one before it, one after it, one above it, and one below it. Of course there are many different ways to blur and this is a poor man's routine.