Initial Commit
This commit is contained in:
86
Descriptions/Description.cs
Normal file
86
Descriptions/Description.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
|
||||
namespace Microsoft.Research.DynamicDataDisplay
|
||||
{
|
||||
public class ResolveLegendItemEventArgs : EventArgs
|
||||
{
|
||||
public ResolveLegendItemEventArgs(LegendItem legendItem)
|
||||
{
|
||||
LegendItem = legendItem;
|
||||
}
|
||||
|
||||
public LegendItem LegendItem { get; set; }
|
||||
}
|
||||
|
||||
public abstract class Description : FrameworkElement
|
||||
{
|
||||
|
||||
private LegendItem legendItem;
|
||||
public LegendItem LegendItem
|
||||
{
|
||||
get
|
||||
{
|
||||
if (legendItem == null)
|
||||
{
|
||||
legendItem = CreateLegendItem();
|
||||
}
|
||||
return legendItem;
|
||||
}
|
||||
}
|
||||
|
||||
private LegendItem CreateLegendItem()
|
||||
{
|
||||
LegendItem item = CreateLegendItemCore();
|
||||
return RaiseResolveLegendItem(item);
|
||||
}
|
||||
|
||||
protected virtual LegendItem CreateLegendItemCore()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public event EventHandler<ResolveLegendItemEventArgs> ResolveLegendItem;
|
||||
private LegendItem RaiseResolveLegendItem(LegendItem uncustomizedLegendItem)
|
||||
{
|
||||
if (ResolveLegendItem != null)
|
||||
{
|
||||
ResolveLegendItemEventArgs e = new ResolveLegendItemEventArgs(uncustomizedLegendItem);
|
||||
ResolveLegendItem(this, e);
|
||||
return e.LegendItem;
|
||||
}
|
||||
else
|
||||
{
|
||||
return uncustomizedLegendItem;
|
||||
}
|
||||
}
|
||||
|
||||
private UIElement viewportElement;
|
||||
public UIElement ViewportElement
|
||||
{
|
||||
get { return viewportElement; }
|
||||
}
|
||||
|
||||
internal void Attach(UIElement element)
|
||||
{
|
||||
this.viewportElement = element;
|
||||
AttachCore(element);
|
||||
}
|
||||
|
||||
protected virtual void AttachCore(UIElement element) { }
|
||||
|
||||
internal void Detach()
|
||||
{
|
||||
viewportElement = null;
|
||||
}
|
||||
|
||||
public abstract string Brief { get; }
|
||||
|
||||
public abstract string Full { get; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Brief;
|
||||
}
|
||||
}
|
||||
}
|
||||
64
Descriptions/PenDescription.cs
Normal file
64
Descriptions/PenDescription.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace Microsoft.Research.DynamicDataDisplay
|
||||
{
|
||||
public sealed class PenDescription : StandardDescription
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PenDescription"/> class.
|
||||
/// </summary>
|
||||
public PenDescription() { }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PenDescription"/> class.
|
||||
/// </summary>
|
||||
/// <param name="description">Custom description.</param>
|
||||
public PenDescription(string description) : base(description) { }
|
||||
|
||||
protected override LegendItem CreateLegendItemCore()
|
||||
{
|
||||
return new LineLegendItem(this);
|
||||
}
|
||||
|
||||
protected override void AttachCore(UIElement graph)
|
||||
{
|
||||
base.AttachCore(graph);
|
||||
LineGraph g = graph as LineGraph;
|
||||
if (g == null)
|
||||
{
|
||||
throw new ArgumentException("Pen description can only be attached to PointsGraph", "graph");
|
||||
}
|
||||
|
||||
SetBinding(StrokeProperty, new Binding("Stroke") { Source = g });
|
||||
SetBinding(StrokeThicknessProperty, new Binding("StrokeThickness") { Source = g });
|
||||
}
|
||||
|
||||
public Brush Stroke
|
||||
{
|
||||
get { return (Brush)GetValue(StrokeProperty); }
|
||||
set { SetValue(StrokeProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty StrokeProperty = DependencyProperty.Register(
|
||||
"Stroke",
|
||||
typeof(Brush),
|
||||
typeof(PenDescription),
|
||||
new FrameworkPropertyMetadata(null));
|
||||
|
||||
public double StrokeThickness
|
||||
{
|
||||
get { return (double)GetValue(StrokeThicknessProperty); }
|
||||
set { SetValue(StrokeThicknessProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty StrokeThicknessProperty = DependencyProperty.Register(
|
||||
"StrokeThickness",
|
||||
typeof(double),
|
||||
typeof(PenDescription),
|
||||
new FrameworkPropertyMetadata(0.0));
|
||||
|
||||
}
|
||||
}
|
||||
42
Descriptions/StandardDescription.cs
Normal file
42
Descriptions/StandardDescription.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
|
||||
namespace Microsoft.Research.DynamicDataDisplay
|
||||
{
|
||||
public class StandardDescription : Description
|
||||
{
|
||||
public StandardDescription() { }
|
||||
public StandardDescription(string description)
|
||||
{
|
||||
if (description == null)
|
||||
throw new ArgumentNullException("description");
|
||||
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
protected override void AttachCore(UIElement element)
|
||||
{
|
||||
if (description == null)
|
||||
{
|
||||
string str = element.GetType().Name;
|
||||
description = str;
|
||||
}
|
||||
}
|
||||
|
||||
private string description;
|
||||
public string DescriptionString {
|
||||
get { return description; }
|
||||
set { description = value; }
|
||||
}
|
||||
|
||||
public sealed override string Brief
|
||||
{
|
||||
get { return description; }
|
||||
}
|
||||
|
||||
public sealed override string Full
|
||||
{
|
||||
get { return description; }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user