Skip to content

Commit 3c61816

Browse files
authored
Merge pull request #1 from Shalini-Ashokan/master
MAUI-3273: How to add progressive (non-linear) scale in .NET MAUI Radial Gauge (SfRadialGauge)
2 parents b8cbfa4 + 426358c commit 3c61816

35 files changed

+1154
-0
lines changed
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}") = "ProgressiveScale", "ProgressiveScale\ProgressiveScale.csproj", "{3FB11BC5-68B5-413F-85EC-49A65CFA9C6E}"
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+
{3FB11BC5-68B5-413F-85EC-49A65CFA9C6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{3FB11BC5-68B5-413F-85EC-49A65CFA9C6E}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{3FB11BC5-68B5-413F-85EC-49A65CFA9C6E}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
17+
{3FB11BC5-68B5-413F-85EC-49A65CFA9C6E}.Release|Any CPU.ActiveCfg = Release|Any CPU
18+
{3FB11BC5-68B5-413F-85EC-49A65CFA9C6E}.Release|Any CPU.Build.0 = Release|Any CPU
19+
{3FB11BC5-68B5-413F-85EC-49A65CFA9C6E}.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
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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:ProgressiveScale"
5+
x:Class="ProgressiveScale.App">
6+
<Application.Resources>
7+
<ResourceDictionary>
8+
<ResourceDictionary.MergedDictionaries>
9+
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
10+
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
11+
</ResourceDictionary.MergedDictionaries>
12+
</ResourceDictionary>
13+
</Application.Resources>
14+
</Application>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace ProgressiveScale;
2+
3+
public partial class App : Application
4+
{
5+
public App()
6+
{
7+
InitializeComponent();
8+
9+
MainPage = new AppShell();
10+
}
11+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<Shell
3+
x:Class="ProgressiveScale.AppShell"
4+
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6+
xmlns:local="clr-namespace:ProgressiveScale"
7+
Shell.FlyoutBehavior="Disabled">
8+
9+
<ShellContent
10+
Title="Home"
11+
ContentTemplate="{DataTemplate local:MainPage}"
12+
Route="MainPage" />
13+
14+
</Shell>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace ProgressiveScale;
2+
3+
public partial class AppShell : Shell
4+
{
5+
public AppShell()
6+
{
7+
InitializeComponent();
8+
}
9+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
xmlns:gauge="clr-namespace:Syncfusion.Maui.Gauges;assembly=Syncfusion.Maui.Gauges"
5+
xmlns:local="clr-namespace:ProgressiveScale"
6+
x:Class="ProgressiveScale.MainPage">
7+
8+
<gauge:SfRadialGauge x:Name="customScaleGauge"
9+
HorizontalOptions="Center">
10+
<gauge:SfRadialGauge.Axes>
11+
<local:RadialAxisExt Minimum="0"
12+
Maximum="150"
13+
ShowTicks="False"
14+
EnableLoadingAnimation="True">
15+
<gauge:RadialAxis.AxisLineStyle>
16+
<gauge:RadialLineStyle ThicknessUnit="Factor"
17+
Thickness="0.15" />
18+
</gauge:RadialAxis.AxisLineStyle>
19+
<gauge:RadialAxis.Pointers>
20+
<gauge:NeedlePointer Value="60"
21+
NeedleLengthUnit="Factor"
22+
NeedleLength="0.8"
23+
NeedleStartWidth="10"
24+
NeedleEndWidth="15"
25+
KnobRadius="0">
26+
<gauge:NeedlePointer.NeedleFill>
27+
<LinearGradientBrush StartPoint="0.5,0"
28+
EndPoint="0.5,1">
29+
<GradientStop Color="#CB7BDF"
30+
Offset="0.25" />
31+
<GradientStop Color="#77CB7EDF"
32+
Offset="0.75" />
33+
</LinearGradientBrush>
34+
</gauge:NeedlePointer.NeedleFill>
35+
</gauge:NeedlePointer>
36+
<gauge:RangePointer Value="60"
37+
PointerWidth="0.15"
38+
WidthUnit="Factor">
39+
<gauge:RangePointer.GradientStops>
40+
<gauge:GaugeGradientStop Value="5"
41+
Color="#FF9E40DC" />
42+
<gauge:GaugeGradientStop Value="45"
43+
Color="#FFE63B86" />
44+
</gauge:RangePointer.GradientStops>
45+
</gauge:RangePointer>
46+
</gauge:RadialAxis.Pointers>
47+
</local:RadialAxisExt>
48+
</gauge:SfRadialGauge.Axes>
49+
</gauge:SfRadialGauge>
50+
</ContentPage>
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
using Syncfusion.Maui.Gauges;
2+
3+
namespace ProgressiveScale;
4+
5+
public partial class MainPage : ContentPage
6+
{
7+
public MainPage()
8+
{
9+
InitializeComponent();
10+
}
11+
}
12+
public class RadialAxisExt : RadialAxis
13+
{
14+
15+
// Generated the 9 non-linear interval labels from 0 to 150
16+
// instead of actual generated labels.
17+
protected override List<GaugeLabelInfo> GenerateVisibleLabels()
18+
{
19+
List<GaugeLabelInfo> customLabels = new List<GaugeLabelInfo>();
20+
21+
for (int i = 0; i < 9; i++)
22+
{
23+
double value = CalculateLabelValue(i);
24+
GaugeLabelInfo label = new GaugeLabelInfo
25+
{
26+
Value = value,
27+
Text = value.ToString()
28+
};
29+
customLabels.Add(label);
30+
}
31+
32+
return customLabels;
33+
}
34+
35+
// To return the label value based on interval
36+
double CalculateLabelValue(double value)
37+
{
38+
if (value == 0)
39+
{
40+
return 0;
41+
}
42+
else if (value == 1)
43+
{
44+
return 2;
45+
}
46+
else if (value == 2)
47+
{
48+
return 5;
49+
}
50+
else if (value == 3)
51+
{
52+
return 10;
53+
}
54+
else if (value == 4)
55+
{
56+
return 20;
57+
}
58+
else if (value == 5)
59+
{
60+
return 30;
61+
}
62+
else if (value == 6)
63+
{
64+
return 50;
65+
}
66+
else if (value == 7)
67+
{
68+
return 100;
69+
}
70+
else
71+
{
72+
return 150;
73+
}
74+
}
75+
public override double ValueToFactor(double value)
76+
{
77+
if (value >= 0 && value <= 2)
78+
{
79+
return (value * 0.125) / 2;
80+
}
81+
else if (value > 2 && value <= 5)
82+
{
83+
return (((value - 2) * 0.125) / (5 - 2)) + (1 * 0.125);
84+
}
85+
else if (value > 5 && value <= 10)
86+
{
87+
return (((value - 5) * 0.125) / (10 - 5)) + (2 * 0.125);
88+
}
89+
else if (value > 10 && value <= 20)
90+
{
91+
return (((value - 10) * 0.125) / (20 - 10)) + (3 * 0.125);
92+
}
93+
else if (value > 20 && value <= 30)
94+
{
95+
return (((value - 20) * 0.125) / (30 - 20)) + (4 * 0.125);
96+
}
97+
else if (value > 30 && value <= 50)
98+
{
99+
return (((value - 30) * 0.125) / (50 - 30)) + (5 * 0.125);
100+
}
101+
else if (value > 50 && value <= 100)
102+
{
103+
return (((value - 50) * 0.125) / (100 - 50)) + (6 * 0.125);
104+
}
105+
else if (value > 100 && value <= 150)
106+
{
107+
return (((value - 100) * 0.125) / (150 - 100)) + (7 * 0.125);
108+
}
109+
else
110+
{
111+
return 1;
112+
}
113+
}
114+
115+
116+
}
117+
118+
119+
120+
121+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Syncfusion.Maui.Core.Hosting;
2+
3+
namespace ProgressiveScale;
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+
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
17+
});
18+
19+
return builder.Build();
20+
}
21+
}
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+
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
4+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
5+
<uses-permission android:name="android.permission.INTERNET" />
6+
</manifest>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Android.App;
2+
using Android.Content.PM;
3+
using Android.OS;
4+
5+
namespace ProgressiveScale;
6+
7+
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
8+
public class MainActivity : MauiAppCompatActivity
9+
{
10+
}

0 commit comments

Comments
 (0)