Initial Commit

This commit is contained in:
2024-02-23 00:46:06 -05:00
commit 2bbedc0178
470 changed files with 46035 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Research.DynamicDataDisplay.Converters;
using System.Windows.Controls;
using System.Globalization;
namespace Microsoft.Research.DynamicDataDisplay.Charts
{
internal sealed class LegendBottomButtonIsEnabledConverter : ThreeValuesMultiConverter<double, double, double>
{
protected override object ConvertCore(double value1, double value2, double value3, Type targetType, object parameter, CultureInfo culture)
{
double extentHeight = value1;
double viewportHeight = value2;
double offset = value3;
return viewportHeight < (extentHeight - offset);
}
}
}

View File

@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows;
namespace Microsoft.Research.DynamicDataDisplay.Charts.Legend_items
{
public static class LegendItemsHelper
{
public static NewLegendItem BuildDefaultLegendItem(IPlotterElement chart)
{
DependencyObject dependencyChart = (DependencyObject)chart;
NewLegendItem result = new NewLegendItem();
SetCommonBindings(result, chart);
return result;
}
public static void SetCommonBindings(NewLegendItem legendItem, object chart)
{
legendItem.DataContext = chart;
legendItem.SetBinding(NewLegend.VisualContentProperty, new Binding { Path = new PropertyPath("(0)", NewLegend.VisualContentProperty) });
legendItem.SetBinding(NewLegend.DescriptionProperty, new Binding { Path = new PropertyPath("(0)", NewLegend.DescriptionProperty) });
}
}
}

View File

@@ -0,0 +1,128 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Microsoft.Research.DynamicDataDisplay.Charts"
>
<!--NewLegend-->
<Style TargetType="{x:Type local:NewLegend}" BasedOn="{StaticResource {x:Type ItemsControl}}">
<!--<Setter Property="Canvas.Top" Value="10"/>
<Setter Property="Canvas.Right" Value="10"/>-->
<Setter Property="Margin" Value="10,10,10,10"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalAlignment" Value="Top"/>
<Setter Property="Panel.ZIndex" Value="10"/>
<Setter Property="Background" Value="White"/>
<Setter Property="BorderBrush" Value="DarkGray"/>
<!--<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox></CheckBox>
<ContentControl Margin="10" Content="{Binding}"/>
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="ItemContainerStyle">
<Setter.Value>
<Style>
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox></CheckBox>
<ContentControl Margin="10" Background="Orange" Content="{Binding}"/>
<ContentPresenter Content="{Binding}"/>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Setter.Value>
</Setter>-->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:NewLegend}">
<Grid>
<Rectangle Name="backRect" Fill="{TemplateBinding Background}" Stroke="{TemplateBinding BorderBrush}"
RadiusX="10"
RadiusY="10"
StrokeThickness="1"/>
<ScrollViewer CanContentScroll="True" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled"
Margin="5">
<ItemsPresenter/>
</ScrollViewer>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<local:LegendTopButtonToIsEnabledConverter x:Key="legendTopButtonConverter"/>
<local:LegendBottomButtonIsEnabledConverter x:Key="legendBottomButtonConverter"/>
<!--NewLegend No scroll style-->
<Style TargetType="{x:Type local:NewLegend}" BasedOn="{StaticResource {x:Type local:NewLegend}}" x:Key="NoScrollLegendStyle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:NewLegend}">
<Grid>
<Rectangle Name="backRect" Fill="{TemplateBinding Background}" Stroke="{TemplateBinding BorderBrush}"
RadiusX="10"
RadiusY="10"
StrokeThickness="1"/>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<RepeatButton Content="^" Grid.Row="0" Command="{x:Static ScrollBar.LineUpCommand}" CommandTarget="{Binding ElementName=scroll}"
Height="18" VerticalContentAlignment="Center" Padding="0"
IsEnabled="{Binding VerticalOffset, ElementName=scroll, Converter={StaticResource legendTopButtonConverter}}"/>
<ScrollViewer Name="scroll" Grid.Row="1"
CanContentScroll="True" VerticalScrollBarVisibility="Hidden" HorizontalScrollBarVisibility="Disabled"
Margin="5">
<ItemsPresenter/>
</ScrollViewer>
<RepeatButton Content="v" Grid.Row="2" Command="{x:Static ScrollBar.LineDownCommand}" CommandTarget="{Binding ElementName=scroll}"
Height="18" VerticalContentAlignment="Center" Padding="0">
<RepeatButton.IsEnabled>
<MultiBinding Converter="{StaticResource legendBottomButtonConverter}">
<Binding Path="ExtentHeight" ElementName="scroll"/>
<Binding Path="ViewportHeight" ElementName="scroll"/>
<Binding Path="VerticalOffset" ElementName="scroll"/>
</MultiBinding>
</RepeatButton.IsEnabled>
</RepeatButton>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!--NewLegendItem-->
<Style TargetType="{x:Type local:NewLegendItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:NewLegendItem}">
<StackPanel Orientation="Horizontal">
<StackPanel.ToolTip>
<Binding Path="(local:NewLegend.DetailedDescription)"/>
</StackPanel.ToolTip>
<ContentControl Content="{TemplateBinding local:NewLegend.VisualContent}" Margin="2" VerticalAlignment="Center" />
<ContentControl Margin="2" VerticalAlignment="Center">
<ContentControl.Content>
<Binding Path="(local:NewLegend.Description)"/>
</ContentControl.Content>
</ContentControl>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

View File

@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
namespace Microsoft.Research.DynamicDataDisplay.Charts
{
public static class LegendStyles
{
private static Style defaultStyle;
public static Style Default
{
get
{
if (defaultStyle == null)
{
var legendStyles = GetLegendStyles();
defaultStyle = (Style)legendStyles[typeof(NewLegend)];
}
return defaultStyle;
}
}
private static Style noScrollStyle;
public static Style NoScroll
{
get
{
if (noScrollStyle == null)
{
var legendStyles = GetLegendStyles();
noScrollStyle = (Style)legendStyles["NoScrollLegendStyle"];
}
return noScrollStyle;
}
}
private static ResourceDictionary GetLegendStyles()
{
var legendStyles = (ResourceDictionary)Application.LoadComponent(new Uri("/DynamicDataDisplay;component/Charts/Legend items/LegendResources.xaml", UriKind.Relative));
return legendStyles;
}
}
}

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Research.DynamicDataDisplay.Converters;
namespace Microsoft.Research.DynamicDataDisplay.Charts
{
internal sealed class LegendTopButtonToIsEnabledConverter : GenericValueConverter<double>
{
public override object ConvertCore(double value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
double verticalOffset = value;
return verticalOffset > 0;
}
}
}

View File

@@ -0,0 +1,342 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Data;
using System.Windows.Shapes;
using System.Windows.Media.Effects;
using System.Collections.Specialized;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Collections;
using System.Windows.Media;
using Microsoft.Research.DynamicDataDisplay.Charts.Legend_items;
namespace Microsoft.Research.DynamicDataDisplay.Charts
{
public delegate IEnumerable<FrameworkElement> LegendItemsBuilder(IPlotterElement element);
public class NewLegend : ItemsControl, IPlotterElement
{
static NewLegend()
{
Type thisType = typeof(NewLegend);
DefaultStyleKeyProperty.OverrideMetadata(thisType, new FrameworkPropertyMetadata(thisType));
Plotter.PlotterProperty.OverrideMetadata(thisType, new FrameworkPropertyMetadata(OnPlotterChanged));
}
private readonly ObservableCollection<FrameworkElement> legendItems = new ObservableCollection<FrameworkElement>();
public NewLegend()
{
ItemsSource = legendItems;
}
#region IPlotterElement Members
private static void OnPlotterChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
NewLegend legend = (NewLegend)d;
if (e.OldValue != null)
{
legend.DetachFromPlotter((Plotter)e.OldValue);
}
if (e.NewValue != null)
{
legend.AttachToPlotter((Plotter)e.NewValue);
}
}
private Plotter plotter;
public void OnPlotterAttached(Plotter plotter)
{
plotter.CentralGrid.Children.Add(this);
AttachToPlotter(plotter);
}
private void AttachToPlotter(Plotter plotter)
{
if (plotter != this.plotter)
{
this.plotter = plotter;
plotter.Children.CollectionChanged += PlotterChildren_CollectionChanged;
PopulateLegend();
}
}
public void OnPlotterDetaching(Plotter plotter)
{
plotter.CentralGrid.Children.Remove(this);
DetachFromPlotter(plotter);
}
private void DetachFromPlotter(Plotter plotter)
{
if (plotter != null)
{
plotter.Children.CollectionChanged -= PlotterChildren_CollectionChanged;
this.plotter = null;
CleanLegend();
}
}
public Plotter Plotter
{
get { return plotter; }
}
#endregion
private void PlotterChildren_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
PopulateLegend();
}
public void PopulateLegend()
{
legendItems.Clear();
// smk if (!LegendVisible) return;
foreach (var chart in plotter.Children.OfType<DependencyObject>())
{
var legendItemsBuilder = NewLegend.GetLegendItemsBuilder(chart);
if (legendItemsBuilder != null)
{
foreach (var legendItem in legendItemsBuilder((IPlotterElement)chart))
{
legendItems.Add(legendItem);
}
}
//var controller = LegendItemControllersStore.Current.GetController(chart.GetType());
//if (controller != null)
//{
// controller.ProcessChart(chart, this);
//}
}
// smk UpdateVisibility();
}
private void UpdateVisibility()
{
if (legendItems.Count > 0)
Visibility = Visibility.Visible;
else
Visibility = Visibility.Hidden;
}
private void CleanLegend()
{
foreach (var legendItem in legendItems)
{
BindingOperations.ClearAllBindings(legendItem);
}
legendItems.Clear();
UpdateVisibility();
}
#region Attached Properties
#region Description
public static object GetDescription(DependencyObject obj)
{
return obj.GetValue(DescriptionProperty);
}
public static void SetDescription(DependencyObject obj, object value)
{
obj.SetValue(DescriptionProperty, value);
}
public static readonly DependencyProperty DescriptionProperty = DependencyProperty.RegisterAttached(
"Description",
typeof(object),
typeof(NewLegend),
new FrameworkPropertyMetadata(null));
#endregion // end of Description
#region Detailed description
public static object GetDetailedDescription(DependencyObject obj)
{
return (object)obj.GetValue(DetailedDescriptionProperty);
}
public static void SetDetailedDescription(DependencyObject obj, object value)
{
obj.SetValue(DetailedDescriptionProperty, value);
}
public static readonly DependencyProperty DetailedDescriptionProperty = DependencyProperty.RegisterAttached(
"DetailedDescription",
typeof(object),
typeof(NewLegend),
new FrameworkPropertyMetadata(null));
#endregion // end of Detailed description
#region VisualContent
public static object GetVisualContent(DependencyObject obj)
{
return (object)obj.GetValue(VisualContentProperty);
}
public static void SetVisualContent(DependencyObject obj, object value)
{
obj.SetValue(VisualContentProperty, value);
}
public static readonly DependencyProperty VisualContentProperty = DependencyProperty.RegisterAttached(
"VisualContent",
typeof(object),
typeof(NewLegend),
new FrameworkPropertyMetadata(null));
#endregion // end of VisualContent
#region SampleData
public static object GetSampleData(DependencyObject obj)
{
return (object)obj.GetValue(SampleDataProperty);
}
public static void SetSampleData(DependencyObject obj, object value)
{
obj.SetValue(SampleDataProperty, value);
}
public static readonly DependencyProperty SampleDataProperty = DependencyProperty.RegisterAttached(
"SampleData",
typeof(object),
typeof(NewLegend),
new FrameworkPropertyMetadata(null));
#endregion // end of SampleData
#region ShowInLegend
public static bool GetShowInLegend(DependencyObject obj)
{
return (bool)obj.GetValue(ShowInLegendProperty);
}
public static void SetShowInLegend(DependencyObject obj, bool value)
{
obj.SetValue(ShowInLegendProperty, value);
}
public static readonly DependencyProperty ShowInLegendProperty = DependencyProperty.RegisterAttached(
"ShowInLegend",
typeof(bool),
typeof(NewLegend),
new FrameworkPropertyMetadata(true, OnShowInLegendChanged));
private static void OnShowInLegendChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
NewLegend legend = (NewLegend)d;
legend.PopulateLegend();
}
#endregion // end of ShowInLegend
#region LegendItemsBuilder
public static LegendItemsBuilder GetLegendItemsBuilder(DependencyObject obj)
{
return (LegendItemsBuilder)obj.GetValue(LegendItemsBuilderProperty);
}
public static void SetLegendItemsBuilder(DependencyObject obj, LegendItemsBuilder value)
{
obj.SetValue(LegendItemsBuilderProperty, value);
}
public static readonly DependencyProperty LegendItemsBuilderProperty = DependencyProperty.RegisterAttached(
"LegendItemsBuilder",
typeof(LegendItemsBuilder),
typeof(NewLegend),
new FrameworkPropertyMetadata(null, OnLegendItemsBuilderChanged));
private static void OnLegendItemsBuilderChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
IPlotterElement plotterElement = d as IPlotterElement;
if (plotterElement != null && plotterElement.Plotter != null)
{
ChartPlotter plotter = plotterElement.Plotter as ChartPlotter;
if (plotter != null)
{
plotter.NewLegend.PopulateLegend();
}
}
}
#endregion // end of LegendItemsBuilder
#endregion // end of Attached Properties
#region Properties
public bool LegendVisible
{
get { return (bool)GetValue(LegendVisibleProperty); }
set { SetValue(LegendVisibleProperty, value); }
}
public static readonly DependencyProperty LegendVisibleProperty = DependencyProperty.Register(
"LegendVisible",
typeof(bool),
typeof(NewLegend),
new FrameworkPropertyMetadata(true, OnLegendVisibleChanged));
private static void OnLegendVisibleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
NewLegend owner = (NewLegend)d;
var visible = (bool)e.NewValue;
owner.OnLegendVisibleChanged(visible);
}
private void OnLegendVisibleChanged(bool visible)
{
if (visible && legendItems.Count > 0)
{
Visibility = Visibility.Visible;
}
else
{
Visibility = Visibility.Collapsed;
}
}
#endregion // end of Properties
#region Overrides
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
#if !RELEASEXBAP
var rect = (Rectangle)Template.FindName("backRect", this);
if (rect != null)
{
rect.Effect = new DropShadowEffect { Direction = 300, ShadowDepth = 3, Opacity = 0.4 };
}
#endif
}
#endregion // end of Overrides
}
}

View File

@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Media.Animation;
using System.ComponentModel;
namespace Microsoft.Research.DynamicDataDisplay.Charts
{
public class NewLegendItem : Control
{
static NewLegendItem()
{
var thisType = typeof(NewLegendItem);
DefaultStyleKeyProperty.OverrideMetadata(thisType, new FrameworkPropertyMetadata(thisType));
}
//public object VisualContent
//{
// get { return NewLegend.GetVisualContent(this); }
// set { NewLegend.SetVisualContent(this, value); }
//}
//[Bindable(true)]
//public object Description
//{
// get { return NewLegend.GetDescription(this); }
// set { NewLegend.SetDescription(this, value); }
//}
}
}