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
aaeaa6e
commit 2047d43
Showing
56 changed files
with
2,819 additions
and
10 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
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="DataVirtualization.App" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="clr-namespace:DataVirtualization" | ||
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,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Configuration; | ||
using System.Data; | ||
using System.Linq; | ||
using System.Windows; | ||
|
||
namespace DataVirtualization | ||
{ | ||
/// <summary> | ||
/// Interaction logic for App.xaml | ||
/// </summary> | ||
public partial class App : Application | ||
{ | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
ChartView/WPF/DataVirtualization/ChartDataVirtualizationViewModel.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,105 @@ | ||
using System; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using Telerik.Windows.Controls; | ||
|
||
namespace DataVirtualization | ||
{ | ||
public class ChartDataVirtualizationViewModel : ViewModelBase | ||
{ | ||
private const int FullDataCount = 1000000; | ||
private const double RangeOffset = 0.01; | ||
private static Random randomNumberGenerator = new Random(); | ||
|
||
private ObservableCollection<PlotInfo> fullData; | ||
private ObservableCollection<PlotInfo> visibleData; | ||
private double minimumX; | ||
private double maximumX; | ||
|
||
public ChartDataVirtualizationViewModel() | ||
{ | ||
this.fullData = this.GenerateFullData(); | ||
this.MinimumX = this.fullData.FirstOrDefault().XValue; | ||
this.MaximumX = this.fullData.LastOrDefault().XValue; | ||
this.visibleData = new ObservableCollection<PlotInfo>(); | ||
} | ||
|
||
public double MinimumX | ||
{ | ||
get { return this.minimumX; } | ||
set | ||
{ | ||
if (this.minimumX != value) | ||
{ | ||
this.minimumX = value; | ||
this.OnPropertyChanged("MinimumX"); | ||
} | ||
} | ||
} | ||
|
||
public double MaximumX | ||
{ | ||
get { return this.maximumX; } | ||
set | ||
{ | ||
if (this.maximumX != value) | ||
{ | ||
this.maximumX = value; | ||
this.OnPropertyChanged("MaximumX"); | ||
} | ||
} | ||
} | ||
|
||
public ObservableCollection<PlotInfo> FullData | ||
{ | ||
get { return this.fullData; } | ||
} | ||
|
||
public ObservableCollection<PlotInfo> VisibleData | ||
{ | ||
get { return this.visibleData; } | ||
private set | ||
{ | ||
if (this.visibleData != value) | ||
{ | ||
this.visibleData = value; | ||
this.OnPropertyChanged("VisibleData"); | ||
} | ||
} | ||
} | ||
|
||
public void UpdateVisibleData(double minimum, double maximum) | ||
{ | ||
double delta = maximum - minimum; | ||
double offset = delta * RangeOffset; | ||
double offsetMinimum = minimum - offset; | ||
double offsetMaximum = maximum + offset; | ||
|
||
this.VisibleData = this.GetVisibleItems(offsetMinimum, offsetMaximum); | ||
} | ||
|
||
private ObservableCollection<PlotInfo> GetVisibleItems(double minimum, double maximum) | ||
{ | ||
ObservableCollection<PlotInfo> result = new ObservableCollection<PlotInfo>(); | ||
for (int i = 0; i < this.fullData.Count; i++) | ||
{ | ||
PlotInfo info = this.fullData[i]; | ||
if (minimum <= info.XValue && info.XValue <= maximum) | ||
{ | ||
result.Add(info); | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
private ObservableCollection<PlotInfo> GenerateFullData() | ||
{ | ||
ObservableCollection<PlotInfo> result = new ObservableCollection<PlotInfo>(); | ||
for (int i = 0; i < FullDataCount; i++) | ||
{ | ||
result.Add(new PlotInfo() { XValue = i, YValue = randomNumberGenerator.Next(100, 300) }); | ||
} | ||
return result; | ||
} | ||
} | ||
} |
Oops, something went wrong.