Skip to content

Commit

Permalink
Added EntryImages example doc.
Browse files Browse the repository at this point in the history
  • Loading branch information
DashTheDev committed Jul 8, 2024
1 parent b21deb6 commit c67e98d
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,6 @@ FodyWeavers.xsd

# JetBrains Rider
*.sln.iml

# MacOS
**/.DS_Store
44 changes: 44 additions & 0 deletions Docs/Examples/EntryImages.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# [](../README.md) Setting Entry Images
Once you've [setup](../../README.md#-setting-up) your [`DonutChartView`](../Reference/DonutChartView.md) there's a property called [`EntryIconTemplate`](../Reference/DonutChartView.md) that you can populate to render icons for each entry. This property expects a [`DataTemplate`](https://learn.microsoft.com/en-us/dotnet/api/microsoft.maui.controls.datatemplate?view=net-maui-8.0) that creates a [`FileImageSource`](https://learn.microsoft.com/en-us/dotnet/api/microsoft.maui.controls.fileimagesource?view=net-maui-8.0).

## Static Image
So if your MAUI project had an image file called `baseball.png`, to render every entry with that image you'd populate the property as follows:

```xaml
<donut:DonutChartView.EntryIconTemplate>
<DataTemplate>
<FileImageSource File="baseball.png" />
</DataTemplate>
</donut:DonutChartView.EntryIconTemplate>
```

Which might look something like this:

<img src="../../Media/EntryImages-1.png" alt="Example Image #1" width="75%"/>
<br/><br/>

> [!NOTE]
> If your images are rendering too large or too small, set the [`EntryImageScale`](../Reference/DonutChartView.md) on your [`DonutChartView`](../Reference/DonutChartView.md) accordingly.
## Dynamic Image
In most scenarios you're going to want to set each entry's image depending on a condition. To allow for this the [`EntryIconTemplate`](../Reference/DonutChartView.md) that you set is provided the original entry object as its binding context, meaning you can handle the image selection however you'd like.

Say your [`EntriesSource`](../Reference/DonutChartView.md) entries are of type `TestResult`, you can setup your [`EntryIconTemplate`](../Reference/DonutChartView.md) with the `x:DataType` tag to allow for compiled bindings and then bind the image file on the [`FileImageSource`](https://learn.microsoft.com/en-us/dotnet/api/microsoft.maui.controls.fileimagesource?view=net-maui-8.0).

In the following example, we bind to a property called `Category` on the `TestResult` model which is an [`enum`](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/enum). Then we use a [binding value converter](https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/data-binding/converters?view=net-maui-8.0) to convert the `TestResult`'s `Category` to the image file we want to display.

```xaml
<donut:DonutChartView.EntryIconTemplate>
<DataTemplate x:DataType="m:TestResult">
<FileImageSource File="{Binding Category, Converter={StaticResource ResultCategoryImageConverter}}" />
</DataTemplate>
</donut:DonutChartView.EntryIconTemplate>
```

Which might look something like this:

<img src="../../Media/EntryImages-2.png" alt="Example Image #2" width="75%"/>
<br/><br/>

> [!NOTE]
> If your images are rendering too large or too small, set the [`EntryImageScale`](../Reference/DonutChartView.md) on your [`DonutChartView`](../Reference/DonutChartView.md) accordingly.
6 changes: 6 additions & 0 deletions Docs/Examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# [](../README.md) Examples
Want to see some code in action? Check the links below to help you get started.

## Links
- [Quick Setup](../../README.md#-setting-up)
- [Setting Entry Images](EntryImages.md)
2 changes: 1 addition & 1 deletion Docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ These docs are your one stop shop for everything you'll need to know about EZCha

## Links
- [API Reference](Reference/README.md)
- [Samples](Samples/README.md)
- [Examples](Examples/README.md)
- [FAQ](FAQ/README.md)
5 changes: 0 additions & 5 deletions Docs/Samples/README.md

This file was deleted.

7 changes: 5 additions & 2 deletions EZCharts.Maui.Donut.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Media", "Media", "{F4FE4592-8236-48E1-BAC8-B2294FE11E3B}"
ProjectSection(SolutionItems) = preProject
Media\Icon.png = Media\Icon.png
Media\EntryImages-1.png = Media\EntryImages-1.png
Media\EntryImages-2.png = Media\EntryImages-2.png
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EZCharts.Maui.Donut", "EZCharts.Maui.Donut\EZCharts.Maui.Donut.csproj", "{179B7EC9-C912-4F1E-8B49-098663FA22F5}"
Expand Down Expand Up @@ -48,9 +50,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Reference", "Reference", "{
Docs\Reference\README.md = Docs\Reference\README.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{B45E2321-2EAD-47F8-9EA0-8ED63E5A2B2B}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Examples", "Examples", "{B45E2321-2EAD-47F8-9EA0-8ED63E5A2B2B}"
ProjectSection(SolutionItems) = preProject
Docs\Samples\README.md = Docs\Samples\README.md
Docs\Examples\EntryImages.md = Docs\Examples\EntryImages.md
Docs\Examples\README.md = Docs\Examples\README.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "FAQ", "FAQ", "{816B3877-AE4B-4C30-AB71-4EDE4C6DAF97}"
Expand Down
Binary file added Media/EntryImages-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Media/EntryImages-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The goal is to provide developers with a highly customizable, efficient, and vis
## 🖼️ Samples
A [sample project](https://github.com/DashTheDev/EZCharts.Maui.Donut/tree/master/EZCharts.Maui.Donut.Samples) can be found in the repository where you can dive deeper into setup, customisation and how to use the library in a typical MAUI application. There are samples for MVVM, code behind and XAML setups.

More detailed samples and documentation coming soon!
If you want more specific examples or code snippets, check out the [examples documentation](https://github.com/DashTheDev/EZCharts.Maui.Donut/tree/master/Docs/Examples)!

![Sample Animation](https://raw.githubusercontent.com/DashTheDev/EZCharts.Maui.Donut/master/Media/Sample.gif)

Expand Down

0 comments on commit c67e98d

Please sign in to comment.