Time lines

Sometimes people ask about how to display a time line. One possibility is to use a GoInstruments.GraduatedScaleLinear, representing date (or time) values as doubles using OLE Automation's date/time convention. The following example is not quite as general as it could be, but I hope you find it a useful start. [Serializable] public class Timeline : GraduatedScaleLinear { public Timeline() { this.Selectable = false; this.Resizable = false; this.Minimum = 38005; // OLE Automation date value (a double-precision floating point number) for Monday 19 Jan 2004 this.Maximum = this.Minimum + 7*24; // 24 weeks later this.TickBase = this.Minimum; this.TickUnit = 7; // each week this.TickMajorFrequency = 1; this.LabelStyle = GraduatedScaleLabelStyle.Left; this.TickMajorLengthRatio = 1; this.TickLengthLeft = 1000; // LONG lines off to the left (on the right when going down) this.TickLengthRight = 0; this.TickMajorWidth = 0; // LONG thin lines this.LabelTemplate.AutoResizes = false; this.LabelTemplate.Size = new SizeF(100, 18); this.LabelTemplate.Bold = true; this.StartPoint = new PointF(100, 100); this.EndPoint = new PointF(100, 1000); } public override String GetLabelString(double val) { if (val == this.Maximum) // skip last label return ""; else return DateTime.FromOADate(val).ToShortDateString(); } public override PointF GetLabelCenter(double val, bool drawLeft) { PointF p = GetPointForValue(val); p.X += this.LabelTemplate.Width/2 + 4; // add some spacing p.Y += this.LabelTemplate.Height/2 + 2; // add some spacing return p; } }

How do I convert a date in Ole Automation Date Value?
Is there some function I can use?
Thanx,
Bernardo Heynemann

DateTime.ToOADate and DateTime.FromOADate

There is no such method as Datetime.ToOADate…
How can I convert a datetime to OADate?
Thanks again.

Sorry, already got it
DateTime.ToOaDate is not a static method.
It must be called from within an instance of a Datetime object.
Thank you very much.

I got it.
But I’m having a little problem.
When two events are in the same datetime they get on top of each other.
For layout I used ForceDigraphLayout, but it messed the Y-axis of my nodes, so after the forcedlayout I arranged the Y’s of the nodes one by one. That works great if two events don’t happen at the same time.
I want to change my vertical timeline to a horizontal timeline, but I’m looking for some way that the Goview diagram will autolayout my events even if they happen at the same time. HELP ANYONE? PLEASE? hehehehe I’m desperate.
Thank you very much all for the help,
Bernardo Heynemann

I’m not familiar with your application, but it seems unlikely that you would want to use GoLayoutForceDirected instead of GoLayoutLayeredDigraph.
To change the timeline class to work horizontally, you’ll need to change the value of GetLabelCenter. Depending on which way you want to go, you may also need to reverse the direction of the long tick marks, swapping Right and Left.

Sorry, i’m using GolayoutLayeredDigraph.
But anyway, i’m creating a regular timeline. And i want the nodes to be added based on a date.
How can I make sure that even if two nodes are added on the same datetime they don’t get on top of each other…
Thanks for the quick help,
Bernardo Heynemann

If two nodes have the same date, aren’t they in the same (layered-digraph) layer? If they are, the autolayout will position them with the same Y coordinate if you are doing a vertical layout.
If you do allow two (or more) nodes have the same date but also have a source/destination relationship between each other, then you will have multiple nodes on the same date, but in different (layout) layers. Basically, each date is going to need a different height, because there could be arbitrarily complex and large graphs for one date, whereas other dates might have one or even no nodes. Furthermore there can no longer be a simple one-to-one relationship between layout layers and your application-specific dates.
When you can’t guarantee the vertical spacing for the dates will be uniform, you can’t use a GraduatedScale, since GraduatedScale assumes a linear scale (simple distance for GraduatedScaleLinear and angle for GraduatedScaleElliptical). You’ll need to calculate the actual date demarcations and paint or generate background rectangles correspondingly.