A
Timeline that implements a "segmented" timeline with included,
excluded and exception segments.
A Timeline will present a series of values to be used for an axis. Each
Timeline must provide transformation methods between domain values and
timeline values.
A timeline can be used as parameter to a
org.jfree.chart.axis.DateAxis to define the values that this axis
supports. This class implements a timeline formed by segments of equal
length (ex. days, hours, minutes) where some segments can be included in the
timeline and others excluded. Therefore timelines like "working days" or
"working hours" can be created where non-working days or non-working hours
respectively can be removed from the timeline, and therefore from the axis.
This creates a smooth plot with equal separation between all included
segments.
Because Timelines were created mainly for Date related axis, values are
represented as longs instead of doubles. In this case, the domain value is
just the number of milliseconds since January 1, 1970, 00:00:00 GMT as
defined by the getTime() method of
java.util.Date .
In this class, a segment is defined as a unit of time of fixed length.
Examples of segments are: days, hours, minutes, etc. The size of a segment
is defined as the number of milliseconds in the segment. Some useful segment
sizes are defined as constants in this class: DAY_SEGMENT_SIZE,
HOUR_SEGMENT_SIZE, FIFTEEN_MINUTE_SEGMENT_SIZE and MINUTE_SEGMENT_SIZE.
Segments are group together to form a Segment Group. Each Segment Group will
contain a number of Segments included and a number of Segments excluded. This
Segment Group structure will repeat for the whole timeline.
For example, a working days SegmentedTimeline would be formed by a group of
7 daily segments, where there are 5 included (Monday through Friday) and 2
excluded (Saturday and Sunday) segments.
Following is a diagram that explains the major attributes that define a
segment. Each box is one segment and must be of fixed length (ms, second,
hour, day, etc).
start time
|
v
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ...
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+...
| | | | | |EE|EE| | | | | |EE|EE| | | | | |EE|EE|
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+...
\____________/ \___/ \_/
\/ | |
included excluded segment
segments segments size
\_________ _______/
\/
segment group
Legend:
<space> = Included segment
EE = Excluded segments in the base timeline
In the example, the following segment attributes are presented:
- segment size: the size of each segment in ms.
- start time: the start of the first segment of the first segment group to
consider.
- included segments: the number of segments to include in the group.
- excluded segments: the number of segments to exclude in the group.
Exception Segments are allowed. These exception segments are defined as
segments that would have been in the included segments of the Segment Group,
but should be excluded for special reasons. In the previous working days
SegmentedTimeline example, holidays would be considered exceptions.
Additionally the startTime , or start of the first Segment of
the smallest segment group needs to be defined. This startTime could be
relative to January 1, 1970, 00:00:00 GMT or any other date. This creates a
point of reference to start counting Segment Groups. For example, for the
working days SegmentedTimeline, the startTime could be
00:00:00 GMT of the first Monday after January 1, 1970. In this class, the
constant FIRST_MONDAY_AFTER_1900 refers to a reference point of the first
Monday of the last century.
A SegmentedTimeline can include a baseTimeline. This combination of
timelines allows the creation of more complex timelines. For example, in
order to implement a SegmentedTimeline for an intraday stock trading
application, where the trading period is defined as 9:00 AM through 4:00 PM
Monday through Friday, two SegmentedTimelines are used. The first one (the
baseTimeline) would be a working day SegmentedTimeline (daily timeline
Monday through Friday). On top of this baseTimeline, a second one is defined
that maps the 9:00 AM to 4:00 PM period. Because the baseTimeline defines a
timeline of Monday through Friday, the resulting (combined) timeline will
expose the period 9:00 AM through 4:00 PM only on Monday through Friday,
and will remove all other intermediate intervals.
Two factory methods newMondayThroughFridayTimeline() and
newFifteenMinuteTimeline() are provided as examples to create special
SegmentedTimelines.
See Also: org.jfree.chart.axis.DateAxis |