Skip to content

Commit 13d6497

Browse files
authored
Merge pull request #1 from SVRagul/main
MAUI-1626: How to add a logarithmic scale in .NET MAUI Radial Gauge control.
2 parents 1d4053c + 7014b7d commit 13d6497

30 files changed

+685
-2
lines changed

App.xaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version = "1.0" encoding = "UTF-8" ?>
2+
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:local="clr-namespace:CustomScale"
5+
x:Class="CustomScale.App">
6+
<Application.Resources>
7+
<ResourceDictionary>
8+
9+
<Color x:Key="PrimaryColor">#512bdf</Color>
10+
<Color x:Key="SecondaryColor">White</Color>
11+
12+
<Style TargetType="Label">
13+
<Setter Property="TextColor" Value="{DynamicResource PrimaryColor}" />
14+
<Setter Property="FontFamily" Value="OpenSansRegular" />
15+
</Style>
16+
17+
<Style TargetType="Button">
18+
<Setter Property="TextColor" Value="{DynamicResource SecondaryColor}" />
19+
<Setter Property="FontFamily" Value="OpenSansRegular" />
20+
<Setter Property="BackgroundColor" Value="{DynamicResource PrimaryColor}" />
21+
<Setter Property="Padding" Value="14,10" />
22+
</Style>
23+
24+
</ResourceDictionary>
25+
</Application.Resources>
26+
</Application>

App.xaml.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace CustomScale;
2+
3+
public partial class App : Application
4+
{
5+
public App()
6+
{
7+
InitializeComponent();
8+
9+
MainPage = new MainPage();
10+
}
11+
}

CustomScale.csproj

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
5+
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows')) and '$(MSBuildRuntimeType)' == 'Full'">$(TargetFrameworks);net6.0-windows10.0.19041</TargetFrameworks>
6+
<OutputType>Exe</OutputType>
7+
<RootNamespace>CustomScale</RootNamespace>
8+
<UseMaui>true</UseMaui>
9+
<SingleProject>true</SingleProject>
10+
<ImplicitUsings>enable</ImplicitUsings>
11+
<EnablePreviewMsixTooling>true</EnablePreviewMsixTooling>
12+
13+
<!-- Display name -->
14+
<ApplicationTitle>CustomScale</ApplicationTitle>
15+
16+
<!-- App Identifier -->
17+
<ApplicationId>com.companyname.customscale</ApplicationId>
18+
<ApplicationId Condition="$(TargetFramework.Contains('-windows'))">DBD6E274-ABA5-4BC1-959D-6F82973EE57D</ApplicationId>
19+
20+
<!-- Versions -->
21+
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
22+
<ApplicationVersion>1</ApplicationVersion>
23+
24+
<!-- Required for C# Hot Reload -->
25+
<UseInterpreter Condition="'$(Configuration)' == 'Debug'">True</UseInterpreter>
26+
27+
<SupportedOSPlatformVersion Condition="'$(TargetFramework)' == 'net6.0-ios'">14.2</SupportedOSPlatformVersion>
28+
<SupportedOSPlatformVersion Condition="'$(TargetFramework)' == 'net6.0-maccatalyst'">14.0</SupportedOSPlatformVersion>
29+
<SupportedOSPlatformVersion Condition="'$(TargetFramework)' == 'net6.0-android'">21.0</SupportedOSPlatformVersion>
30+
<SupportedOSPlatformVersion Condition="$(TargetFramework.Contains('-windows'))">10.0.17763.0</SupportedOSPlatformVersion>
31+
<TargetPlatformMinVersion Condition="$(TargetFramework.Contains('-windows'))">10.0.17763.0</TargetPlatformMinVersion>
32+
</PropertyGroup>
33+
34+
<ItemGroup>
35+
<!-- App Icon -->
36+
<MauiIcon Include="Resources\appicon.svg" ForegroundFile="Resources\appiconfg.svg" Color="#512BD4" />
37+
38+
<!-- Splash Screen -->
39+
<MauiSplashScreen Include="Resources\appiconfg.svg" Color="#512BD4" BaseSize="128,128" />
40+
41+
<!-- Images -->
42+
<MauiImage Include="Resources\Images\*" />
43+
<MauiImage Update="Resources\Images\dotnet_bot.svg" BaseSize="168,208" />
44+
45+
<!-- Custom Fonts -->
46+
<MauiFont Include="Resources\Fonts\*" />
47+
48+
<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
49+
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
50+
</ItemGroup>
51+
52+
<ItemGroup Condition="$(TargetFramework.Contains('-windows'))">
53+
<!-- Required - WinUI does not yet have buildTransitive for everything -->
54+
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.0.0" />
55+
<PackageReference Include="Microsoft.Graphics.Win2D" Version="1.0.0.30" />
56+
</ItemGroup>
57+
58+
<ItemGroup>
59+
<PackageReference Include="Syncfusion.Maui.Core" Version="*" />
60+
<PackageReference Include="Syncfusion.Maui.Gauges" Version="*" />
61+
</ItemGroup>
62+
63+
<PropertyGroup Condition="$(TargetFramework.Contains('-windows'))">
64+
<OutputType>WinExe</OutputType>
65+
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
66+
</PropertyGroup>
67+
68+
</Project>

CustomScale.csproj.user

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<ActiveDebugFramework>net6.0-windows10.0.19041</ActiveDebugFramework>
5+
<IsFirstTimeProjectOpen>False</IsFirstTimeProjectOpen>
6+
<ActiveDebugProfile>Windows Machine</ActiveDebugProfile>
7+
</PropertyGroup>
8+
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net6.0-android|AnyCPU'">
9+
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
10+
</PropertyGroup>
11+
</Project>

CustomScale.sln

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31611.283
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CustomScale", "CustomScale.csproj", "{87B1A2E3-29C4-4C06-ACBA-8616ADBE2F75}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{87B1A2E3-29C4-4C06-ACBA-8616ADBE2F75}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{87B1A2E3-29C4-4C06-ACBA-8616ADBE2F75}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{87B1A2E3-29C4-4C06-ACBA-8616ADBE2F75}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
17+
{87B1A2E3-29C4-4C06-ACBA-8616ADBE2F75}.Release|Any CPU.ActiveCfg = Release|Any CPU
18+
{87B1A2E3-29C4-4C06-ACBA-8616ADBE2F75}.Release|Any CPU.Build.0 = Release|Any CPU
19+
{87B1A2E3-29C4-4C06-ACBA-8616ADBE2F75}.Release|Any CPU.Deploy.0 = Release|Any CPU
20+
EndGlobalSection
21+
GlobalSection(SolutionProperties) = preSolution
22+
HideSolutionNode = FALSE
23+
EndGlobalSection
24+
GlobalSection(ExtensibilityGlobals) = postSolution
25+
SolutionGuid = {61F7FB11-1E47-470C-91E2-47F8143E1572}
26+
EndGlobalSection
27+
EndGlobal

MainPage.xaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
x:Class="CustomScale.MainPage"
5+
xmlns:gauge="clr-namespace:Syncfusion.Maui.Gauges;assembly=Syncfusion.Maui.Gauges"
6+
xmlns:local="clr-namespace:CustomScale"
7+
BackgroundColor="{DynamicResource SecondaryColor}">
8+
9+
<gauge:SfRadialGauge>
10+
<gauge:SfRadialGauge.Axes>
11+
<local:RadialAxisExt Minimum="1" Maximum="10000">
12+
<local:RadialAxisExt.Pointers>
13+
<gauge:NeedlePointer Value="1000"/>
14+
</local:RadialAxisExt.Pointers>
15+
</local:RadialAxisExt>
16+
</gauge:SfRadialGauge.Axes>
17+
</gauge:SfRadialGauge>
18+
19+
</ContentPage>

MainPage.xaml.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using Syncfusion.Maui.Gauges;
2+
3+
namespace CustomScale;
4+
5+
public partial class MainPage : ContentPage
6+
{
7+
public MainPage()
8+
{
9+
InitializeComponent();
10+
}
11+
}
12+
13+
public class RadialAxisExt : RadialAxis
14+
{
15+
int labelsCount = 0;
16+
protected override List<GaugeLabelInfo> GenerateVisibleLabels()
17+
{
18+
List<GaugeLabelInfo> customLabels = new List<GaugeLabelInfo>();
19+
20+
var _minimum = (int)logBase(this.Minimum, 10);
21+
var _maximum = (int)logBase(this.Minimum, 10);
22+
for (var i = _minimum; i <= _maximum; i++)
23+
{
24+
int value = (int)Math.Floor(Math.Pow(10, i));// logBase value is 10
25+
GaugeLabelInfo label = new GaugeLabelInfo
26+
{
27+
Value = value,
28+
Text = value.ToString()
29+
};
30+
customLabels.Add(label);
31+
}
32+
33+
labelsCount = customLabels.Count;
34+
return customLabels;
35+
}
36+
37+
double logBase(double value, double baseValue)
38+
{
39+
return Math.Log(value) / Math.Log(baseValue);
40+
}
41+
42+
public override double ValueToFactor(double value)
43+
{
44+
return logBase(value, 10) / (labelsCount - 1);
45+
}
46+
47+
}
48+

MauiProgram.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Syncfusion.Maui.Core.Hosting;
2+
3+
namespace CustomScale;
4+
5+
public static class MauiProgram
6+
{
7+
public static MauiApp CreateMauiApp()
8+
{
9+
var builder = MauiApp.CreateBuilder();
10+
builder
11+
.UseMauiApp<App>()
12+
.ConfigureSyncfusionCore()
13+
.ConfigureFonts(fonts =>
14+
{
15+
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
16+
});
17+
18+
return builder.Build();
19+
}
20+
}

Output.png

18.2 KB
Loading
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="31" />
4+
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
5+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
6+
</manifest>

0 commit comments

Comments
 (0)