Drawing plot in real time using Android custom view -


i want make in app simple line plot real time drawing. know there lot of various libraries big or don't have right features or licence.

my idea make custom view , extend view class. using opengl in case shooting duck canon. have view drawing static data - first putting data in float array of plot object , using loop draw in ondraw() method of plotview class.

i have thread provide new data plot. problem how draw while new data added. first thought add new point , draw. add , again. not sure happen @ 100 or 1000 points. adding new point, ask view invalidate still points aren't drawn. in case using queue might difficult because ondraw() start beginning again number of queue elements increase.

what recommend achieve goal?

let me try sketch out problem bit more.

  • you've got surface can draw points , lines to, , know how make how want look.
  • you have data source provides points draw, , data source changed on fly.
  • you want surface accurately reflect incoming data closely possible.

the first question is--what situation slow? know delays coming from? first, sure have problem solve; second, sure know problem coming from.

let's problem in size of data imply. how address complex question. depends on properties of data being graphed--what invariants can assume , forth. you've talked storing data in float[], i'm going assume you've got fixed number of data points change in value. i'm going assume '100 or 1000' meant 'lots , lots', because frankly 1000 floats not lot of data.

when have big array draw, performance limit going come looping on array. performance enhancement going reducing how of array you're looping over. properties of data come play.

one way reduce volume of redraw operation keep 'dirty list' acts queue<int>. every time cell in array changes, enqueue array index, marking 'dirty'. every time draw method comes around, dequeue fixed number of entries in dirty list , update chunk of rendered image corresponding entries--you'll have scaling and/or anti-aliasing or because many data points, you've got more data screen pixels. number of entries redraw in given frame update should bounded desired framerate--you can make adaptive, based on metric of how long previous draw operations took , how deep dirty list getting, maintain balance between frame rate , visible data age.

this particularly suitable if you're trying draw of data on screen @ once. if you're viewing chunk of data (like in scrollable view), , there's kind of correspondence between array positions , window size, can 'window' data--in each draw call, consider subset of data on screen. if you've got 'zoom' thing going on, can mix 2 methods--this can complicated.

if data windowed such value in each array element determines whether data point on or off screen, consider using sorted list of pairs sort key value. let perform windowing optimization outlined above in situation. if windowing taking place in both dimensions, need perform 1 or other optimization, there 2 dimensional range query structures can give well.

let's assumption fixed data size wrong; instead you're adding data end of list, existing data points don't change. in case you're better off linked queue-like structure drops old data points rather array, because growing array tend introduce stutter in application unnecessarily.

in case optimization pre-draw buffer follows queue along--as new elements enter queue, shift whole buffer left , draw region containing new elements.

if it's /rate/ of data entry that's problem, use queued structure , skip elements--either collapse them they're added queue, store/draw every nth element, or similar.

if instead it's rendering process taking of time, consider rendering on background thread , storing rendered image. let take time want doing redraw--the framerate within chart drop not overall application responsiveness.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -