Big time ActionScript question. (not for the faint of heart)
|
|
Thread rating:  |
Mark Pusateri - 06 Feb 2005 03:10 GMT I'm working on a Radar that will dynamically place objects (spheres) at different places inside a circle with a couple inner rings depending on dates from a dB. We still have to iron out all the variables for placing them but for now it's date. So let's say the center of the radar is today's date with a few rings making up the radar and the last ring is 3 or 4 years out. Is it possible, and how difficult will it be to write something like this to work?
Here's a pretty good sample of what we were looking to do:
http://www.intronetworks.com/introNetworks.html Click Demos then the 3rd one "Santa Barbara County..." do a search and you'll see something like what we're trying to accomplish.
This one sets the pins by zip codes and I "think" this is dynamic so I'm sure we can do what we want. But I need a sanity check here from you pros before we get too far with this.
Thanks a lot for giving this question some of your time.
MP
NSurveyor - 06 Feb 2005 04:38 GMT First, create a movieclip and draw a circle in it. Give it the instance name, myCircle. Then create a movieclip, to act as the "pins". (Don't put it on the stage though). Now open the library, right click your pin, and select linkage. Check off Export for ActionScript. Type in myPoint as identifier. Finally add this script to the frame that holds your circle:
circle = myCircle; pointer = 'myPoint'; years = 4; dates = [ new Date(2004,9,10), new Date(2005,1,12), new Date(2003,9,2), new Date(), new Date(2004,4,21) ]
counter = 0; today = new Date(); edge = new Date(today.getFullYear()+4,today.getMonth(),today.getDate(),today.getHours(),tod ay.getMinutes(),today.getSeconds(),today.getMilliseconds()) pdates = dates.slice(0); plotter = setInterval(plotPoints,100); function plotPoints(){ var cIndex = random(pdates.length); var cDate = pdates[cIndex]; pdates.splice(cIndex,1); var percentage = (today.getTime()-cDate.getTime())/(today.getTime()-edge.getTime()); var dist = circle._width/2*percentage; var angle = random(360); var rads = angle/(Math.PI/180); var sin = Math.sin(rads); var cos = Math.cos(rads); var y = sin*dist; var x = cos*dist; var centerX = (circle.getBounds(circle._parent).xMin+circle.getBounds(circle._parent).xMax)/2 var centerY = (circle.getBounds(circle._parent).yMin+circle.getBounds(circle._parent).yMax)/2 cPoint = circle._parent.attachMovie(pointer,'point'+(++counter),circle._parent.getNextHig hestDepth(),{_x:centerX+x,_y:centerY+y,date:cDate}); cPoint.onRollOver = function(){ _root.createTextField('tooltip',_root.getNextHighestDepth(),_root._xmouse,_roo t._ymouse,0,0); _root.tooltip.border = true; _root.tooltip.background = true; _root.tooltip.backgroundColor = 0xFFFFCC; _root.tooltip.selectable = false; _root.tooltip.autoSize = 'left'; _root.tooltip.text = this.date; cPoint.onEnterFrame = function(){ _root.tooltip._y = _root._ymouse-_root.tooltip._height; _root.tooltip._x = _root._xmouse; updateAfterEvent(); } } cPoint.onRollOut = function(){ _root.tooltip.removeTextField(); delete this.onEnterFrame; } if(pdates.length==0){ clearInterval(plotter); } }
Is that the kind of effect you want?
Mark Pusateri - 06 Feb 2005 13:40 GMT NSurveyor,
I'm speechless... I never thought in a million years I explained it well enough let along have someone hit the nail on the head the first time out. This is exactly what we need to do. The SetInterval is very cool - that was a nice bonus. I'll make sure I mention you in the presentation next week!
So the stupid questions I have to ask are:
The dates Array can be dynamically generated from dates within a SQL dB or XML file, right?
I know this will be asked in the meeting - can we track back as well? I noticed if you enter a date prior to today it plots into the circle as well. I'm wondering if we can either set it so it doesn't plot points prior to today's date... OR... make today's date halfway from the center to the outer most circle so that way the closer the plots are to the center the closer you are to 4 years prior to today. Just like the close you are to the outer most ring, the closer you are to 4 years out.
Again... Thank you so much, this is FANTASTIC! It really is!
MP
On 2/5/05 11:38 PM, in article cu46vq$30p$1@forums.macromedia.com,
> First, create a movieclip and draw a circle in it. Give it the instance name, > myCircle. Then create a movieclip, to act as the "pins". (Don't put it on the [quoted text clipped - 35 lines] > var x = cos*dist; > var centerX = (circle.getBounds(circle._parent).xMin+circle.getBounds(circle._parent).xMax)/> 2
> var centerY = (circle.getBounds(circle._parent).yMin+circle.getBounds(circle._parent).yMax)/> 2
> cPoint = > circle._parent.attachMovie(pointer,'point'+(++counter),circle._parent.getNextH [quoted text clipped - 26 lines] > > Is that the kind of effect you want? Rothrock - 06 Feb 2005 17:03 GMT I'm really quite interested in this project. I have a few questions. Since you are plotting in two dimensions - distance from center and rotation around the circle ? what is the other dimension for? Or is it just to look pretty? I also have a couple of suggestions ? none of which I have worked through, so they might not be helpful. I might look at recentering the myCircle clip. That should make the math easier. You would just use polar coordinates ? radius for time and angle for whatever that is for. Also in the tool tip part of the code, NSurveyor, I don't think you need the updateAfterEvent. Since that code is in an onEnterFrame it will only be executed once every frame and will be redrawn anyways. Also I would redesign this in two ways. One I would get rid of all the _root references, if you try and load this into another swf or move it from one file to another (and it seems like something you might want to reuse) you will probably have difficulties. Finally the points are not being added inside the circle movie clip. If you attach them inside the clip you will then be able to move, scale, hide, fade, etc. the circle and all the clips inside it. Oh yeah and one last thought, time closer to the present will have less area to receive plots, whereas time in the distant past will be a lot more spread out. So if you expect to have a lot more points in more recent times you might want to turn that around and have the outer ring indicate today and the center indicate the past.
Mark.P. - 07 Feb 2005 13:33 GMT Glad to hear there?s a little interest, maybe I can get some good ideas if I explain it a bit. It?s really pretty simple what we?re looking to accomplish. We have 3 groups in my organization that works on ?technology? projects within the firm.
1. Group 1 - Finds it, studies it and does all the prelim researching. Such as watching Windows XP and determining when is the best time to switch the firm over. 2. Group 2 - does the work of making Windows XP firm compliant with all the necessary security, software, etc. 3. Group 3 ? deploys the job and follows it for some time afterwards.
What we?re building is basically a ?radar? view of the projects for each of the 3 groups plus an overall view (a project timeline). Like I said, it?s a pretty basic thing that we wanted to take one step further with Flash. We need to show when projects will be looked at (group 1 may not get to one for 2 to 3 years), where they are in the process once they start, and when handoff to the next group will take place. So that?s really it in a nutshell. We started with an idea for just a straight timeline, but realized it was too linear. We have been using the term radar, for what projects are on the radar, (in sight) so we took it to the literal sense.
You brought up a good point about the closer you get to the center the more condensed the points will be. That?s one reason for bringing ?today?s date? out about half way. We also need to show the overflow ?handoff? which could spill into the other groups radar, so that?s another reason to push the dates out.
I have taken and added the code, for now, into another movieClip so I can do all the scaling and what-have-yous. Being able to scale this is pretty vital giving the grouping that may take place in the center.
Mark.P. - 30 Jul 2005 13:42 GMT After months of creating business cases, going over and approving budgets, and all the other corporate mumbo-jumbo one must go through to start a project of this size, we finally got the OK to start. ?
I?m a little nervous (I have to do all the Flash) and a whole lot excited (it should set a new standard for how we do things within the organization. Part of the reason for the nervousness comes from a new request. We now have 4 phases that need to be separated on the Radar. In other words, the circle the points sit on needs to be split into 4 sections (like a pie chart). Then I need to plot the points from the center, which is a date in time. The code above works very well for random placement around the entire diameter, but I now need to modify that or rewrite it so each point can fall within a section. I?m guessing some math code needs to written in order to plot out each of the four sections, then I can tell it to plot the points within that section depending on the org it belongs to. I?m a math idiot with anything over 2+2.
Does anyone have any thoughts, reference, anything on this?
Help?
Thanks
Rothrock - 30 Jul 2005 18:06 GMT I kind of remember this. Glad it has finally moved forward for you. I guess before I can really help I would need to understand what you are trying to do again.
So distance from the center is time, but I'm not understanding what the angle or rotation will represent. So for each of the 4 phases it should be restricted to a 90 degree wedge or do different phases take up a different amount of the pie.
Also the example you provided seems to be reflecting a geographic reality, which really makes sense to display on a plane. But yours seems to be 4 timelines. A one dimensional plot seems to make more sense here, but maybe I'm missing something. If you randomly place the points in the circle (or a wedge) what does that randomness represent?
Mark.P. - 31 Jul 2005 04:22 GMT You?re right; it really is 4 separate timelines, one timeline (circle) for each phase of the project. Let me try to explain how we go here and what we?re trying to accomplish.
We?re actually trying to provide many different ways to view the same information about a project to the Business Line Leaders, their boss, and on up the ladder. So one view will be by date - a calendar view, one will be by a list of project names, one by the project owner, and more. They?ll then be able to dig deeper to get more info. The ?Radar View? is just another ?View? for the user to see their project(s), other projects or the life of a project over a certain time frame. We found the radar to be an excellent way to get the quick snapshot of what?s going on over a given timeframe.
The original idea was to have a drop down box allowing the user to select the phase of the radar then be taken to that radar view. When we showed a demo to the folks they liked it a lot but wanted to see all phases right up front in one overall radar view. So the thought was to split up the circle into 4 equal 90 degree sections each representing a different phase.
Plotting the points from the center does indeed represent time. So 100 pixel diameter could represent 1 year, 200 would be 2 years and so on. You can see that NSurveyor hit the mark with his script. His script places the points randomly around the center but that doesn?t have to be a random number, in fact, now that I have to place the points within a slice of the pie, it can?t be too random. There really isn?t any reason for them being random with the exception of it doesn?t have to be in the same spot around the diameter within that pie slice. I?m not even sure how that can be done without storing that info in a database with each project.
I think I?m rambling at this point (it's late) so I hope this cleared some things up. If not, I?ll keep trying so I can get the help.
Rothrock - 31 Jul 2005 16:57 GMT Well if you randomly place them. Just change it so the angle is randomly between 0 and 90. You will also have to keep track of which of the 4 tracks something is in. You would then multiply the angle by the number of the track.
If you have very many points or they will often need to be updated, you will probably want to load this from an XML file. You can then either use the XML class to get at the data. I've found working with the XML class a bit clunky, so I prefer to take the XML data and parse it once into some custom objects.
If you follow this idea you could count up how many points there were for each track. You could then have each track start at one of the cardinal points and each additional point move a proportional fraction of the 90 degree wedge. This could make some nice looking spiral galaxy type of plots.
|
|
|