Skip to content

Commit 034074c

Browse files
committed
Bugfixes: allow reloading the time line, and disappearing labels when using animations.
Previously, label factories were specified in XAML. This turned out not to be possible, since it are common resources used by all instances of the control. The disappearing labels were due to newly initialized labels not being updated in AbstractTimeLinePushLabelFactory.
1 parent e067424 commit 034074c

7 files changed

Lines changed: 50 additions & 47 deletions

File tree

Binary file not shown.

Whathecode.TimeLine/LabelFactories/AbstractTimeIntervalLabelFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ protected override IEnumerable<DateTime> GetXValues( AxesIntervals<DateTime, Tim
7575
}
7676

7777
DateTime last = xInterval.End.Round( TimeStepSize.Value );
78-
while ( current != last )
78+
while ( current < last )
7979
{
8080
switch ( TimeStepSize )
8181
{

Whathecode.TimeLine/LabelFactories/TimeLinePushLabelFactory.cs renamed to Whathecode.TimeLine/LabelFactories/AbstractTimeLinePushLabelFactory.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ protected override void InitializeLabel( PositionedElement positioned, AxesInter
1515
// Actual X position is changed for the label to be 'pushed off' the screen by the next label.
1616
TimeLineItem header = (TimeLineItem)positioned.Element;
1717
header.Occurance = (DateTime)header.GetValue( TimePanel.XProperty );
18+
19+
UpdateLabel( positioned, visible, panelSize );
1820
}
1921

2022
protected override void UpdateLabel( PositionedElement label, AxesIntervals<DateTime, TimeSpan, double, double> visible, Size panelSize )

Whathecode.TimeLine/LabelFactories/TimeLineHeaderFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Whathecode.TimeLine.LabelFactories
55
{
6-
public class AbstractTimeLineHeaderFactory : AbstractTimeLinePushLabelFactory
6+
public class TimeLineHeaderFactory : AbstractTimeLinePushLabelFactory
77
{
88
protected override FrameworkElement CreateLabel()
99
{

Whathecode.TimeLine/Themes/Generic.xaml

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
xmlns:converters="clr-namespace:Whathecode.System.Windows.Data;assembly=Whathecode.PresentationFramework"
77
xmlns:wtc="clr-namespace:Whathecode.System.Windows.Controls;assembly=Whathecode.PresentationFramework"
88
xmlns:controls="clr-namespace:Whathecode.TimeLine"
9-
xmlns:factories="clr-namespace:Whathecode.TimeLine.LabelFactories"
109
mc:Ignorable="d">
1110

1211
<!-- TimeControl -->
@@ -65,44 +64,6 @@
6564
<!-- TimeLine -->
6665
<Style TargetType="{x:Type controls:TimeLine}" BasedOn="{StaticResource {x:Type controls:TimeControl}}">
6766

68-
<Setter Property="LabelFactories">
69-
<Setter.Value>
70-
<factories:TimeLineLabelFactories>
71-
<!-- Ticks, from quarters to years. -->
72-
<factories:TimeLineTickFactory Name="Quarters" StepSize="00:15:00" MinimumPixelsBetweenLabels="60" OverrideGroup="Ticks" />
73-
<factories:TimeLineTickFactory Name="Hours" TimeStepSize="Hour" MinimumPixelsBetweenLabels="60" OverrideGroup="Ticks" />
74-
<factories:TimeLineTickFactory Name="DayQuarters" StepSize="06:00:00" MinimumPixelsBetweenLabels="60" OverrideGroup="Ticks" />
75-
<factories:TimeLineTickFactory Name="Days" TimeStepSize="Day" MinimumPixelsBetweenLabels="50" OverrideGroup="Ticks" />
76-
<factories:TimeLineTickFactory Name="Weeks" StepSize="7.00:00:00" MinimumPixelsBetweenLabels="60" OverrideGroup="Ticks" />
77-
<factories:TimeLineTickFactory Name="Months" TimeStepSize="Month" MinimumPixelsBetweenLabels="50" OverrideGroup="Ticks" />
78-
<factories:TimeLineTickFactory Name="Years" TimeStepSize="Year" MinimumPixelsBetweenLabels="60" OverrideGroup="Ticks" />
79-
<!-- Additional context labels at bottom. -->
80-
<factories:TimeLineContextLabelFactory Name="DayContext" TimeStepSize="Day" MinimumPixelsBetweenLabels="50" FixedY="100" />
81-
<factories:TimeLineContextLabelFactory Name="MonthContext" TimeStepSize="Month" MinimumPixelsBetweenLabels="100" FixedY="100" />
82-
<factories:TimeLineContextLabelFactory Name="YearContext" TimeStepSize="Year" MinimumPixelsBetweenLabels="100" FixedY="100" />
83-
<!-- Header labels. -->
84-
<factories:AbstractTimeLineHeaderFactory Name="YearHeader" TimeStepSize="Year" MinimumPixelsBetweenLabels="200" />
85-
<factories:AbstractTimeLineHeaderFactory Name="MonthHeader" TimeStepSize="Month" MinimumPixelsBetweenLabels="200" />
86-
<factories:AbstractTimeLineHeaderFactory Name="WeekHeader" StepSize="7.00:00:00" MinimumPixelsBetweenLabels="200" />
87-
<factories:AbstractTimeLineHeaderFactory Name="DayHeader" TimeStepSize="Day" MinimumPixelsBetweenLabels="200" />
88-
<factories:AbstractTimeLineHeaderFactory Name="DayQuarterHeader" StepSize="06:00:00" MinimumPixelsBetweenLabels="200" />
89-
<factories:AbstractTimeLineHeaderFactory Name="HourHeader" TimeStepSize="Hour" MinimumPixelsBetweenLabels="200" />
90-
<factories:AbstractTimeLineHeaderFactory Name="QuarterHeader" StepSize="00:15:00" MinimumPixelsBetweenLabels="200" />
91-
<!-- Breadcrumb labels underneath headers. -->
92-
<factories:TimeLineBreadcrumbFactory Name="YearBreadcrumbs" TimeStepSize="Year" MinimumPixelsBetweenLabels="200" />
93-
<factories:TimeLineBreadcrumbFactory Name="MonthBreadcrumbs" TimeStepSize="Month" MinimumPixelsBetweenLabels="200" />
94-
<factories:TimeLineBreadcrumbFactory Name="WeekBreadcrumbs" StepSize="7.00:00:00" MinimumPixelsBetweenLabels="200" />
95-
<factories:TimeLineBreadcrumbFactory Name="DayBreadcrumbs" TimeStepSize="Day" MinimumPixelsBetweenLabels="200" />
96-
<factories:TimeLineBreadcrumbFactory Name="DayQuarterBreadcrumbs" StepSize="06:00:00" MinimumPixelsBetweenLabels="200" />
97-
<factories:TimeLineBreadcrumbFactory Name="HourBreadcrumbs" TimeStepSize="Hour" MinimumPixelsBetweenLabels="200" />
98-
<factories:TimeLineBreadcrumbFactory Name="QuarterBreadcrumbs" StepSize="00:15:00" MinimumPixelsBetweenLabels="200" />
99-
<!-- Fixed elements. -->
100-
<factories:TimeLineLabelCollection>
101-
<controls:TimeIndicator />
102-
</factories:TimeLineLabelCollection>
103-
</factories:TimeLineLabelFactories>
104-
</Setter.Value>
105-
</Setter>
10667
<Setter Property="Template">
10768
<Setter.Value>
10869
<ControlTemplate TargetType="{x:Type controls:TimeLine}">

Whathecode.TimeLine/TimeLine.cs

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Linq;
33
using System.Windows;
4+
using Whathecode.System;
45
using Whathecode.System.Linq;
56
using Whathecode.System.Windows.Controls;
67
using Whathecode.System.Windows.DependencyPropertyFactory;
@@ -36,21 +37,21 @@ public TimeLineLabelFactories LabelFactories
3637
set { Factory.SetValue( this, TimeLineProperties.LabelFactories, value ); }
3738
}
3839

39-
[DependencyProperty( TimeLineProperties.DominantTickFactory )]
40+
[DependencyProperty( TimeLineProperties.DominantTickFactory, DefaultValue = "" )]
4041
public string DominantTickFactory
4142
{
4243
get { return (string)Factory.GetValue( this, TimeLineProperties.DominantTickFactory ); }
4344
private set { Factory.SetValue( this,TimeLineProperties.DominantTickFactory, value ); }
4445
}
4546

46-
[DependencyProperty( TimeLineProperties.DominantHeaderFactory )]
47+
[DependencyProperty( TimeLineProperties.DominantHeaderFactory, DefaultValue = "" )]
4748
public string DominantHeaderFactory
4849
{
4950
get { return (string)Factory.GetValue( this, TimeLineProperties.DominantHeaderFactory ); }
5051
private set { Factory.SetValue( this,TimeLineProperties.DominantHeaderFactory, value ); }
5152
}
5253

53-
[DependencyProperty( TimeLineProperties.DominantBreadcrumbFactory )]
54+
[DependencyProperty( TimeLineProperties.DominantBreadcrumbFactory, DefaultValue = "" )]
5455
public string DominantBreadcrumbFactory
5556
{
5657
get { return (string)Factory.GetValue( this, TimeLineProperties.DominantBreadcrumbFactory ); }
@@ -61,8 +62,47 @@ public string DominantBreadcrumbFactory
6162
static TimeLine()
6263
{
6364
DefaultStyleKeyProperty.OverrideMetadata( Type, new FrameworkPropertyMetadata( Type ) );
65+
VisibleIntervalProperty.AddOwner( typeof( TimeLine ) );
6466
}
6567

68+
public TimeLine()
69+
{
70+
LabelFactories = new TimeLineLabelFactories
71+
{
72+
// Ticks, from quarters to years.
73+
new TimeLineTickFactory { Name="Quarters", StepSize = TimeSpan.FromMinutes( 15 ), MinimumPixelsBetweenLabels = 60, OverrideGroup = "Ticks" },
74+
new TimeLineTickFactory { Name="Hours", TimeStepSize = DateTimePart.Hour, MinimumPixelsBetweenLabels = 60, OverrideGroup = "Ticks" },
75+
new TimeLineTickFactory { Name="DayQuarters", StepSize = TimeSpan.FromHours( 6 ), MinimumPixelsBetweenLabels = 60, OverrideGroup = "Ticks" },
76+
new TimeLineTickFactory { Name="Days", TimeStepSize = DateTimePart.Day, MinimumPixelsBetweenLabels = 50, OverrideGroup = "Ticks" },
77+
new TimeLineTickFactory { Name="Weeks", StepSize = TimeSpan.FromDays( 7 ), MinimumPixelsBetweenLabels = 60, OverrideGroup = "Ticks" },
78+
new TimeLineTickFactory { Name="Months", TimeStepSize = DateTimePart.Month, MinimumPixelsBetweenLabels = 50, OverrideGroup = "Ticks" },
79+
new TimeLineTickFactory { Name="Years", TimeStepSize = DateTimePart.Year, MinimumPixelsBetweenLabels = 60, OverrideGroup = "Ticks" },
80+
// Additional context labels at bottom.
81+
new TimeLineContextLabelFactory { Name = "DayContext", TimeStepSize = DateTimePart.Day, MinimumPixelsBetweenLabels = 50, FixedY = 100 },
82+
new TimeLineContextLabelFactory { Name = "MonthContext", TimeStepSize = DateTimePart.Month, MinimumPixelsBetweenLabels = 100, FixedY = 100 },
83+
new TimeLineContextLabelFactory { Name = "YearContext", TimeStepSize = DateTimePart.Year, MinimumPixelsBetweenLabels = 100, FixedY = 100 },
84+
// Header labels.
85+
new TimeLineHeaderFactory { Name = "YearHeader", TimeStepSize = DateTimePart.Year, MinimumPixelsBetweenLabels = 200 },
86+
new TimeLineHeaderFactory { Name = "MonthHeader", TimeStepSize = DateTimePart.Month, MinimumPixelsBetweenLabels = 200 },
87+
new TimeLineHeaderFactory { Name = "WeekHeader", StepSize = TimeSpan.FromDays( 7 ), MinimumPixelsBetweenLabels = 200 },
88+
new TimeLineHeaderFactory { Name = "DayHeader", TimeStepSize = DateTimePart.Day, MinimumPixelsBetweenLabels = 200 },
89+
new TimeLineHeaderFactory { Name = "DayQuarterHeader", StepSize = TimeSpan.FromHours( 6 ), MinimumPixelsBetweenLabels = 200 },
90+
new TimeLineHeaderFactory { Name = "HourHeader", TimeStepSize = DateTimePart.Hour, MinimumPixelsBetweenLabels = 200 },
91+
new TimeLineHeaderFactory { Name = "QuarterHeader", StepSize = TimeSpan.FromMinutes( 15 ), MinimumPixelsBetweenLabels = 200 },
92+
// Breadcrumb labels underneath headers.
93+
new TimeLineBreadcrumbFactory { Name = "YearBreadcrumbs", TimeStepSize = DateTimePart.Year, MinimumPixelsBetweenLabels = 200 },
94+
new TimeLineBreadcrumbFactory { Name = "MonthBreadcrumbs", TimeStepSize = DateTimePart.Month, MinimumPixelsBetweenLabels = 200 },
95+
new TimeLineBreadcrumbFactory { Name = "WeekBreadcrumbs", StepSize = TimeSpan.FromDays( 7 ), MinimumPixelsBetweenLabels = 200 },
96+
new TimeLineBreadcrumbFactory { Name = "DayBreadcrumbs", TimeStepSize = DateTimePart.Day, MinimumPixelsBetweenLabels = 200 },
97+
new TimeLineBreadcrumbFactory { Name = "DayQuarterBreadcrumbs", StepSize = TimeSpan.FromHours( 6 ), MinimumPixelsBetweenLabels = 200 },
98+
new TimeLineBreadcrumbFactory { Name = "HourBreadcrumbs", TimeStepSize = DateTimePart.Hour, MinimumPixelsBetweenLabels = 200 },
99+
new TimeLineBreadcrumbFactory { Name = "QuarterBreadcrumbs", StepSize = TimeSpan.FromMinutes( 15 ), MinimumPixelsBetweenLabels = 200 },
100+
// Fixed elements.
101+
new TimeLineLabelCollection { new TimeIndicator() }
102+
};
103+
}
104+
105+
66106
public override void OnApplyTemplate()
67107
{
68108
base.OnApplyTemplate();
@@ -84,10 +124,10 @@ public override void OnApplyTemplate()
84124

85125
// Get dominant header and breadcrumb factories.
86126
var dontFit = LabelFactories
87-
.OfType<AbstractTimeLineHeaderFactory>() // Get the smallest interval which is too large to fit the screen vertically.
127+
.OfType<TimeLineHeaderFactory>() // Get the smallest interval which is too large to fit the screen vertically.
88128
.Where( f => ( (double)f.MaximumLabelSize.Ticks / VisibleInterval.Size.Ticks ) * ActualWidth > ActualHeight )
89129
.ToList();
90-
AbstractTimeLineHeaderFactory currentHeaderFactory = dontFit.Count == 0 ? null : dontFit.MinBy( f => f.MaximumLabelSize );
130+
TimeLineHeaderFactory currentHeaderFactory = dontFit.Count == 0 ? null : dontFit.MinBy( f => f.MaximumLabelSize );
91131
if ( currentHeaderFactory != null )
92132
{
93133
DominantHeaderFactory = currentHeaderFactory.Name;

Whathecode.TimeLine/Whathecode.TimeLine.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
<Compile Include="TimeLineContextLabel.cs" />
6161
<Compile Include="LabelFactories\TimeLineContextLabelFactory.cs" />
6262
<Compile Include="LabelFactories\TimeLineHeaderFactory.cs" />
63-
<Compile Include="LabelFactories\TimeLinePushLabelFactory.cs" />
63+
<Compile Include="LabelFactories\AbstractTimeLinePushLabelFactory.cs" />
6464
<Compile Include="LabelFactories\TimeLineTickFactory.cs" />
6565
<Compile Include="TimeLineTick.cs" />
6666
<Compile Include="LabelFactories\TimeLineLabelCollection.cs" />

0 commit comments

Comments
 (0)