Author Topic: Graphing  (Read 15934 times)

EToreo

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 88
    • View Profile
Graphing
« on: January 01, 2013, 02:38:55 AM »
I need to create a (very simple) line graph in a pane.  I was wondering what the best way to do that would be inside NGUI?  It's a static graph - no need to up date it once I draw it, but it does need to be dynamic - meaning a different set of values each time I display it.  And there might be more than one graph on the screen at a time (with different data).

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Graphing
« Reply #1 on: January 01, 2013, 12:56:20 PM »
I'm not sure there's' a very good way to do it.

You could position line sprites correctly, but there would be some weird overlaps where the joints would meet.

Alternatively, you can create a mesh dynamically and use that, but I can't say I have much experience with that.

JRoch

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 140
    • View Profile
Re: Graphing
« Reply #2 on: January 01, 2013, 04:03:40 PM »
This is one of those areas where you have to embrace one of the various ugly options.  NGUI isn't going to hold your hand here much at all... you'll either have to go vector or bitmap.  If you go vector you have to figure out your data points relative to an arbitrary scale that you decide, then create quads that are the lines... getting proper butt and corner junctions is... a non-trivial math exercise.  Alternatively you can blit your data to a texture that is appropriately sized/scaled and then just display that texture as a UITexture.  However, compositing bitmap data is always a barrel of laughs as well.

In short, there is no easy way to accomplish this without cooking up your own custom solution depending upon what type of graph you want to display.  Like you, I really wish there were something like the DevExpress ultimate library that gives you a metric shit-ton of widgets, graphs, controls, and containers to deal with, but when dealing with low-level frameworks that are primarily intended to create games, having a good graph library is hard to come by.

EToreo

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 88
    • View Profile
Re: Graphing
« Reply #3 on: January 01, 2013, 05:06:48 PM »
Thanks for the replies.  I didn't expect it to be easy or have much hand holding from Unity or NGUI.

My idea was to render to a texture after setting a camera up to look at a graph background and drawing a Unity LineRenderer over the points I needed.  I'm not sure if this would work though, because I would need to capture just one frame and then permanently aplly that frame to a UITexture.  Can that be done?

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Graphing
« Reply #4 on: January 02, 2013, 04:14:16 PM »
Well, you could manually create a Texture2D dynamically and fill in the pixels with SetPixel() and use that texture in a UITexture.

EToreo

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 88
    • View Profile
Re: Graphing
« Reply #5 on: January 02, 2013, 04:35:34 PM »
Can I get the data for SetPixels() from a camera?  If so, that might be the easiest way.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Graphing
« Reply #6 on: January 02, 2013, 08:32:50 PM »
Hmm, if you want it from the Camera, you have to use a RenderTexture and grab it from there.

EToreo

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 88
    • View Profile
Re: Graphing
« Reply #7 on: January 02, 2013, 09:18:40 PM »
Do you know if I can capture just one frame to the rendertexture?

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Graphing
« Reply #8 on: January 02, 2013, 11:19:13 PM »
You can just turn off the camera, then the rendertexture will contain the data from the last frame that was sent to it.