This repository has been archived by the owner on Jul 4, 2023. It is now read-only.
forked from ailon/amCharts-Quick-Charts
-
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.
Implemented core Legend functionality
- Loading branch information
Showing
13 changed files
with
217 additions
and
8 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
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
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,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Windows.Media; | ||
|
||
namespace AmCharts.Windows.QuickCharts | ||
{ | ||
public interface ILegendItem | ||
{ | ||
string Title { get; set; } | ||
Brush Brush { get; set; } | ||
} | ||
} |
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,75 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Collections.Specialized; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
|
||
namespace AmCharts.Windows.QuickCharts | ||
{ | ||
public class Legend : ItemsControl | ||
{ | ||
public Legend() | ||
{ | ||
this.DefaultStyleKey = typeof(Legend); | ||
|
||
this.ItemsSource = _itemsSource; | ||
} | ||
|
||
private ObservableCollection<LegendItem> _itemsSource = new ObservableCollection<LegendItem>(); | ||
|
||
private IEnumerable<ILegendItem> _legendItemsSource; | ||
public IEnumerable<ILegendItem> LegendItemsSource | ||
{ | ||
get { return _legendItemsSource; } | ||
set | ||
{ | ||
if (value is INotifyCollectionChanged) | ||
{ | ||
(value as INotifyCollectionChanged).CollectionChanged += new NotifyCollectionChangedEventHandler(LegendItemsSource_CollectionChanged); | ||
} | ||
_legendItemsSource = value; | ||
_itemsSource.Clear(); | ||
AddLegendItems(value.ToList()); | ||
} | ||
} | ||
|
||
void LegendItemsSource_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) | ||
{ | ||
if (e.Action == NotifyCollectionChangedAction.Reset) | ||
{ | ||
_itemsSource.Clear(); | ||
} | ||
else | ||
{ | ||
if (e.OldItems != null) | ||
{ | ||
foreach (ILegendItem item in e.NewItems) | ||
{ | ||
_itemsSource.Remove(_itemsSource.First(p => p.OriginalItem == item)); | ||
} | ||
} | ||
|
||
AddLegendItems(e.NewItems); | ||
} | ||
} | ||
|
||
private void AddLegendItems(IList items) | ||
{ | ||
if (items != null) | ||
{ | ||
foreach (ILegendItem item in items) | ||
{ | ||
_itemsSource.Add(new LegendItem() { | ||
Title = item.Title, | ||
Brush = item.Brush, | ||
OriginalItem = item | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
} |
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,28 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace AmCharts.Windows.QuickCharts | ||
{ | ||
public class LegendItem : ILegendItem | ||
{ | ||
public string Title | ||
{ | ||
get; | ||
set; | ||
} | ||
|
||
public System.Windows.Media.Brush Brush | ||
{ | ||
get; | ||
set; | ||
} | ||
|
||
public ILegendItem OriginalItem | ||
{ | ||
get; | ||
set; | ||
} | ||
} | ||
} |
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
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
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,38 @@ | ||
<ResourceDictionary | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:amq="clr-namespace:AmCharts.Windows.QuickCharts" | ||
> | ||
<Style TargetType="amq:Legend"> | ||
<Setter Property="Template"> | ||
<Setter.Value> | ||
<ControlTemplate TargetType="amq:Legend"> | ||
<Border> | ||
<ItemsPresenter /> | ||
</Border> | ||
</ControlTemplate> | ||
</Setter.Value> | ||
</Setter> | ||
|
||
<!--<Setter Property="ItemsPanel"> | ||
<Setter.Value> | ||
<ItemsPanelTemplate> | ||
<StackPanel /> | ||
</ItemsPanelTemplate> | ||
</Setter.Value> | ||
</Setter>--> | ||
|
||
<Setter Property="ItemTemplate"> | ||
<Setter.Value> | ||
<DataTemplate> | ||
<StackPanel Orientation="Horizontal"> | ||
<Rectangle Fill="{Binding Brush}" Height="10" Width="10" Margin="5" /> | ||
<TextBlock Text="{Binding Title}" VerticalAlignment="Center" /> | ||
</StackPanel> | ||
</DataTemplate> | ||
</Setter.Value> | ||
</Setter> | ||
|
||
|
||
</Style> | ||
</ResourceDictionary> |
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