forked from telerik/xaml-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
793d979
commit 2399d32
Showing
140 changed files
with
5,714 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Application x:Class="AxisLikeAnnotations.App" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="clr-namespace:AxisLikeAnnotations" | ||
StartupUri="MainWindow.xaml"> | ||
<Application.Resources> | ||
|
||
</Application.Resources> | ||
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Configuration; | ||
using System.Data; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
|
||
namespace AxisLikeAnnotations | ||
{ | ||
/// <summary> | ||
/// Interaction logic for App.xaml | ||
/// </summary> | ||
public partial class App : Application | ||
{ | ||
} | ||
} |
142 changes: 142 additions & 0 deletions
142
ChartView/WPF/AxisLikeAnnotations/AxisLikeAnnotations.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{756BE61D-5852-47FE-893D-78B06A605BF1}</ProjectGuid> | ||
<OutputType>WinExe</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>AxisLikeAnnotations</RootNamespace> | ||
<AssemblyName>AxisLikeAnnotations</AssemblyName> | ||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> | ||
<WarningLevel>4</WarningLevel> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
|
||
|
||
|
||
|
||
<TargetFrameworkProfile /> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xaml"> | ||
<RequiredTargetFramework>4.0</RequiredTargetFramework> | ||
</Reference> | ||
<Reference Include="Telerik.Windows.Controls, Version=2017.3.1018.45, Culture=neutral, PublicKeyToken=5803cfa389c90ce7, processorArchitecture=MSIL"> | ||
<SpecificVersion>False</SpecificVersion> | ||
<HintPath>$(TELERIKWPFDIR)\Binaries\WPF40\Telerik.Windows.Controls.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Telerik.Windows.Controls.Chart, Version=2017.3.1305.40, Culture=neutral, PublicKeyToken=5803cfa389c90ce7, processorArchitecture=MSIL"> | ||
<SpecificVersion>False</SpecificVersion> | ||
<HintPath>$(TELERIKWPFDIR)\Binaries\WPF40\Telerik.Windows.Controls.Chart.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Telerik.Windows.Data, Version=2017.3.1018.45, Culture=neutral, PublicKeyToken=5803cfa389c90ce7, processorArchitecture=MSIL"> | ||
<SpecificVersion>False</SpecificVersion> | ||
<HintPath>$(TELERIKWPFDIR)\Binaries\WPF40\Telerik.Windows.Data.dll</HintPath> | ||
</Reference> | ||
<Reference Include="WindowsBase" /> | ||
<Reference Include="PresentationCore" /> | ||
<Reference Include="PresentationFramework" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ApplicationDefinition Include="App.xaml"> | ||
<Generator>MSBuild:Compile</Generator> | ||
<SubType>Designer</SubType> | ||
</ApplicationDefinition> | ||
<Compile Include="Helpers\CategoryToBrushConverter.cs" /> | ||
<Compile Include="Helpers\CustomAxisLabelTemplateSelector.cs" /> | ||
<Compile Include="Helpers\ValueToBrushConverter.cs" /> | ||
<Page Include="CategoricalAxisExample.xaml"> | ||
<SubType>Designer</SubType> | ||
<Generator>MSBuild:Compile</Generator> | ||
</Page> | ||
<Page Include="MainWindow.xaml"> | ||
<Generator>MSBuild:Compile</Generator> | ||
<SubType>Designer</SubType> | ||
</Page> | ||
<Compile Include="App.xaml.cs"> | ||
<DependentUpon>App.xaml</DependentUpon> | ||
<SubType>Code</SubType> | ||
</Compile> | ||
<Compile Include="CategoricalAxisExample.xaml.cs"> | ||
<DependentUpon>CategoricalAxisExample.xaml</DependentUpon> | ||
</Compile> | ||
<Compile Include="MainWindow.xaml.cs"> | ||
<DependentUpon>MainWindow.xaml</DependentUpon> | ||
<SubType>Code</SubType> | ||
</Compile> | ||
<Page Include="NumericAxisExample.xaml"> | ||
<SubType>Designer</SubType> | ||
<Generator>MSBuild:Compile</Generator> | ||
</Page> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="NumericAxisExample.xaml.cs"> | ||
<DependentUpon>NumericAxisExample.xaml</DependentUpon> | ||
</Compile> | ||
<Compile Include="PlotInfo.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs"> | ||
<SubType>Code</SubType> | ||
</Compile> | ||
<Compile Include="Properties\Resources.Designer.cs"> | ||
<AutoGen>True</AutoGen> | ||
<DesignTime>True</DesignTime> | ||
<DependentUpon>Resources.resx</DependentUpon> | ||
</Compile> | ||
<Compile Include="Properties\Settings.Designer.cs"> | ||
<AutoGen>True</AutoGen> | ||
<DependentUpon>Settings.settings</DependentUpon> | ||
<DesignTimeSharedInput>True</DesignTimeSharedInput> | ||
</Compile> | ||
<EmbeddedResource Include="Properties\Resources.resx"> | ||
<Generator>ResXFileCodeGenerator</Generator> | ||
<LastGenOutput>Resources.Designer.cs</LastGenOutput> | ||
</EmbeddedResource> | ||
<None Include="Properties\Settings.settings"> | ||
<Generator>SettingsSingleFileGenerator</Generator> | ||
<LastGenOutput>Settings.Designer.cs</LastGenOutput> | ||
</None> | ||
<AppDesigner Include="Properties\" /> | ||
<Resource Include="Readme.md" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
36 changes: 36 additions & 0 deletions
36
ChartView/WPF/AxisLikeAnnotations/CategoricalAxisExample.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<UserControl x:Class="AxisLikeAnnotations.CategoricalAxisExample" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="clr-namespace:AxisLikeAnnotations" | ||
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" | ||
mc:Ignorable="d" | ||
d:DesignHeight="300" d:DesignWidth="300"> | ||
<UserControl.Resources> | ||
<local:ValueToBrushConverter x:Key="ValueToBrushConverter" /> | ||
</UserControl.Resources> | ||
<telerik:RadCartesianChart x:Name="chart"> | ||
<telerik:RadCartesianChart.VerticalAxis> | ||
<telerik:CategoricalAxis x:Name="verticalAxis" Visibility="Hidden" /> | ||
</telerik:RadCartesianChart.VerticalAxis> | ||
<telerik:RadCartesianChart.HorizontalAxis> | ||
<telerik:LinearAxis x:Name="horizontalAxis" Minimum="-350" Maximum="350"/> | ||
</telerik:RadCartesianChart.HorizontalAxis> | ||
<telerik:RadCartesianChart.Series> | ||
<telerik:BarSeries ValueBinding="Value" | ||
CategoryBinding="Category" | ||
ItemsSource="{Binding}" | ||
OriginValue="0"> | ||
<telerik:BarSeries.DefaultVisualStyle> | ||
<Style TargetType="Border"> | ||
<Setter Property="Background" Value="{Binding Value, Converter={StaticResource ValueToBrushConverter}, ConverterParameter=Green;LightGray}" /> | ||
</Style> | ||
</telerik:BarSeries.DefaultVisualStyle> | ||
</telerik:BarSeries> | ||
</telerik:RadCartesianChart.Series> | ||
<telerik:RadCartesianChart.Grid> | ||
<telerik:CartesianChartGrid MajorLinesVisibility="Y"/> | ||
</telerik:RadCartesianChart.Grid> | ||
</telerik:RadCartesianChart> | ||
</UserControl> |
136 changes: 136 additions & 0 deletions
136
ChartView/WPF/AxisLikeAnnotations/CategoricalAxisExample.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
using System; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Media; | ||
using System.Windows.Shapes; | ||
using Telerik.Charting; | ||
using Telerik.Windows.Controls.ChartView; | ||
|
||
namespace AxisLikeAnnotations | ||
{ | ||
public partial class CategoricalAxisExample : UserControl | ||
{ | ||
public CategoricalAxisExample() | ||
{ | ||
InitializeComponent(); | ||
this.DataContext = GetData(); | ||
this.horizontalAxis.ActualRangeChanged += HorizontalAxis_ActualRangeChanged; | ||
this.chart.SizeChanged += Chart_SizeChanged; | ||
} | ||
|
||
private void Chart_SizeChanged(object sender, SizeChangedEventArgs e) | ||
{ | ||
Dispatcher.BeginInvoke(new Action(() => { | ||
UpdateAxis(); | ||
})); | ||
} | ||
|
||
private void HorizontalAxis_ActualRangeChanged(object sender, NumericalRangeChangedEventArgs e) | ||
{ | ||
UpdateAxis(); | ||
} | ||
|
||
private void UpdateAxis() | ||
{ | ||
ClearCustomAxis(); | ||
|
||
var line = CreateLine(); | ||
this.chart.Annotations.Add(line); | ||
|
||
if (this.verticalAxis.PlotMode == AxisPlotMode.OnTicks) | ||
{ | ||
GenerateLabelsOnTicks(); | ||
} | ||
else | ||
{ | ||
GenerateLabelsBetweenTicks(); | ||
} | ||
} | ||
|
||
private void GenerateLabelsBetweenTicks() | ||
{ | ||
var count = this.verticalAxis.Categories.Count(); | ||
var slotSize = this.chart.PlotAreaClip.Height / count; | ||
for (int i = 0; i < count; i++) | ||
{ | ||
var category = this.verticalAxis.Categories.ElementAt(i); | ||
var tick = CreateTick(category, -slotSize); | ||
this.chart.Annotations.Add(tick); | ||
} | ||
} | ||
|
||
private void GenerateLabelsOnTicks() | ||
{ | ||
foreach (var category in this.verticalAxis.Categories) | ||
{ | ||
var tick = CreateTick(category); | ||
this.chart.Annotations.Add(tick); | ||
} | ||
} | ||
|
||
private CartesianCustomAnnotation CreateTick(ChartAxisCategoryInfo item, double verticalOffset = 0) | ||
{ | ||
var tick = new CartesianCustomAnnotation(); | ||
tick.Content = CreateTickVisual(item.Category, verticalOffset); | ||
tick.VerticalValue = item.Category; | ||
tick.HorizontalValue = GetAxisCenter(); | ||
tick.HorizontalAlignment = HorizontalAlignment.Left; | ||
tick.VerticalAlignment = VerticalAlignment.Center; | ||
tick.Tag = "CustomAxisElement"; | ||
return tick; | ||
} | ||
|
||
private UIElement CreateTickVisual(object category, double verticalOffset = 0) | ||
{ | ||
var tickVisual = new Rectangle() { Fill = Brushes.Black, Width = 5, Height = 1, Margin = new Thickness(3, verticalOffset, 0, 0) }; | ||
var label = new TextBlock() { Text = category.ToString() }; | ||
var panel = new StackPanel() { Orientation = Orientation.Horizontal }; | ||
panel.Children.Add(label); | ||
panel.Children.Add(tickVisual); | ||
return panel; | ||
} | ||
|
||
public CartesianGridLineAnnotation CreateLine() | ||
{ | ||
var annotation = new CartesianGridLineAnnotation(); | ||
annotation.Stroke = Brushes.Black; | ||
annotation.Axis = this.horizontalAxis; | ||
annotation.Value = GetAxisCenter(); | ||
annotation.Tag = "CustomAxisElement"; | ||
return annotation; | ||
} | ||
|
||
private double GetAxisCenter() | ||
{ | ||
var min = this.horizontalAxis.ActualRange.Minimum; | ||
var max = this.horizontalAxis.ActualRange.Maximum; | ||
var delta = max - min; | ||
var center = min + (delta / 2); | ||
return center; | ||
} | ||
|
||
private void ClearCustomAxis() | ||
{ | ||
var axisElements = this.chart.Annotations.Where(x => x.Tag != null && x.Tag.Equals("CustomAxisElement")).ToList(); | ||
foreach (var item in axisElements) | ||
{ | ||
this.chart.Annotations.Remove(item); | ||
} | ||
} | ||
|
||
public ObservableCollection<PlotInfo> GetData() | ||
{ | ||
var data = new ObservableCollection<PlotInfo>(); | ||
for (int i = 0; i < 10; i++) | ||
{ | ||
var value = i % 2 == 0 ? | ||
PlotInfo.RandomNumberGenerator.Next(100, 300) : | ||
PlotInfo.RandomNumberGenerator.Next(-300, -100); | ||
data.Add(new PlotInfo() { Value = value, Category = "C" + i }); | ||
} | ||
return data; | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
ChartView/WPF/AxisLikeAnnotations/Helpers/CategoryToBrushConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Windows.Data; | ||
using System.Windows.Media; | ||
|
||
namespace AxisLikeAnnotations | ||
{ | ||
public class CategoryToBrushConverter : IValueConverter | ||
{ | ||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
var colors = parameter.ToString().Split(';'); | ||
if (value.ToString().Contains("A")) | ||
{ | ||
return new SolidColorBrush((Color)ColorConverter.ConvertFromString(colors[1])); | ||
} | ||
return new SolidColorBrush((Color)ColorConverter.ConvertFromString(colors[0])); | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
ChartView/WPF/AxisLikeAnnotations/Helpers/CustomAxisLabelTemplateSelector.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using Telerik.Charting; | ||
|
||
namespace AxisLikeAnnotations | ||
{ | ||
public class CustomAxisLabelTemplateSelector : DataTemplateSelector | ||
{ | ||
public override DataTemplate SelectTemplate(object item, DependencyObject container) | ||
{ | ||
var dp = (AxisLabelModel)item; | ||
if (dp.Content.Equals(NumericAxisExample.CustomAxisPositionKey)) | ||
{ | ||
return new DataTemplate(); | ||
} | ||
return base.SelectTemplate(item, container); | ||
} | ||
} | ||
} |
Oops, something went wrong.