Mini Kabibi Habibi

Current Path : C:/Users/Public/Documents/DXperience 13.1 Demos/ASP.NET/VB/ChartsWebDemo/App_Code/
Upload File :
Current File : C:/Users/Public/Documents/DXperience 13.1 Demos/ASP.NET/VB/ChartsWebDemo/App_Code/ChartUtils.vb

Imports Microsoft.VisualBasic
Imports System
Imports System.Collections
Imports System.Drawing
Imports System.Globalization
Imports DevExpress.Web.ASPxEditors
Imports DevExpress.XtraCharts

Public NotInheritable Class ComboBoxHelper
	Private Const defaultMarker As String = "Default"
	Private Const percentMarker As String = "%"
	Private Const defaultDoughnutHole As Integer = 60
	Private Shared ReadOnly markerKinds As MarkerKindItemCollection = MarkerKindItemCollection.CreateCollection()

	Private Sub New()
	End Sub
	Private Shared Function AppendPercentMarker(ByVal items() As String) As String()
		Return AppendPercentMarker(items, 0)
	End Function
	Private Shared Function AppendPercentMarker(ByVal items() As String, ByVal startIndex As Integer) As String()
		Dim result(items.Length - 1) As String
		For i As Integer = 0 To startIndex - 1
			result(i) = items(i)
		Next i
		For i As Integer = startIndex To items.Length - 1
			result(i) = items(i) & percentMarker
		Next i
		Return result
	End Function
	Private Shared Function DeletePercentMarker(ByVal item As String) As String
		Return item.TrimEnd(New Char() { percentMarker.Chars(0) })
	End Function
	Public Shared Sub PrepareComboBox(ByVal comboBox As ASPxComboBox, ByVal items() As String)
		PrepareComboBox(comboBox, items, Nothing)
	End Sub
	Public Shared Sub PrepareComboBox(ByVal comboBox As ASPxComboBox, ByVal items() As String, ByVal defaultItem As Object)
		comboBox.Items.AddRange(items)
		If defaultItem IsNot Nothing Then
			comboBox.SelectedIndex = comboBox.Items.IndexOfText(defaultItem.ToString())
		Else
			comboBox.SelectedIndex = 0
		End If
	End Sub
	Public Shared Sub PrepareComboBox(ByVal comboBox As ASPxComboBox, ByVal items() As Double, ByVal defaultItem As Double)
		comboBox.Items.AddRange(items)
		comboBox.SelectedIndex = comboBox.Items.IndexOfText(defaultItem.ToString())
	End Sub
	Public Shared Sub PrepareComboBox(ByVal comboBox As ASPxComboBox, ByVal defaultValue As System.Enum)
		PrepareComboBox(comboBox, System.Enum.GetNames(defaultValue.GetType()), defaultValue)
	End Sub
	Public Shared Sub PrepareComboBox(ByVal comboBox As ASPxComboBox, ByVal dictionary As IDictionary)
		PrepareComboBox(comboBox, dictionary, 0)
	End Sub
	Public Shared Sub PrepareComboBox(ByVal comboBox As ASPxComboBox, ByVal dictionary As IDictionary, ByVal selectedIndex As Integer)
		For Each entry As DictionaryEntry In dictionary
			comboBox.Items.Add(CStr(entry.Key), entry.Value)
		Next entry
		comboBox.SelectedIndex = selectedIndex
	End Sub
	Public Shared Sub PrepareLabelAngleComboBox(ByVal comboBox As ASPxComboBox, ByVal defaultAngle As Integer)
		Dim items() As String = { "0", "45", "90", "135", "180", "225", "270", "315" }
		PrepareComboBox(comboBox, items, defaultAngle)
	End Sub
	Public Shared Sub PrepareTransparencyComboBox(ByVal comboBox As ASPxComboBox, ByVal defaultTransparency As Integer)
		Dim items() As String = { "0", "45", "90", "135", "180", "225", "255" }
		PrepareComboBox(comboBox, items, defaultTransparency)
	End Sub
	Public Shared Sub PrepareZoomPercentComboBox(ByVal comboBox As ASPxComboBox, ByVal defaultZoomPercent As Integer)
		Dim items() As String = { "50", "75", "100", "120", "140", "170", "200", "250", "300" }
		PrepareComboBox(comboBox, items, defaultZoomPercent)
	End Sub
	Public Shared Sub PreparePerspectiveAngleComboBox(ByVal comboBox As ASPxComboBox)
		Dim items() As String = { defaultMarker, "0", "30", "45", "60", "90", "120", "135", "150" }
		PrepareComboBox(comboBox, items)
	End Sub
	Public Shared Sub PrepareBar3DModelComboBox(ByVal comboBox As ASPxComboBox)
		Dim items() As String = { "Box", "Cylinder", "Cone", "Pyramid" }
		PrepareComboBox(comboBox, items)
	End Sub
	Public Shared Sub PrepareRegressionLineColorComboBox(ByVal comboBox As ASPxComboBox)
		comboBox.Items.Add("Default")
		Dim colors() As Color = { Color.Black, Color.Red, Color.Green, Color.Blue, Color.Yellow }
		For Each color As Color In colors
			comboBox.Items.Add(color.Name)
		Next color
		comboBox.SelectedIndex = 0
	End Sub
	Public Shared Sub PrepareDashStyleCombobox(ByVal comboBox As ASPxComboBox, ByVal defaultDashStyle As DashStyle)
		For Each dashStyle As DashStyle In System.Enum.GetValues(defaultDashStyle.GetType())
			If dashStyle <> DashStyle.Empty Then
				comboBox.Items.Add(dashStyle.ToString())
			End If
		Next dashStyle
		comboBox.SelectedIndex = comboBox.Items.IndexOfText(defaultDashStyle.ToString())
	End Sub
	Public Shared Sub PrepareLogarithmicBaseComboBox(ByVal comboBox As ASPxComboBox, ByVal defaultLogarithmicBase As Double)
		Dim items() As String = { "2", "5", "10", "20", "50", "100" }
		PrepareComboBox(comboBox, items, defaultLogarithmicBase)
	End Sub
	Public Shared Sub PrepareFunctionTypeComboBox(ByVal comboBox As ASPxComboBox)
		Const lemniscate As String = "Lemniscate"
		Dim items() As String = { "Circles", "Cardioid", lemniscate }
		PrepareComboBox(comboBox, items, lemniscate)
	End Sub
	Public Shared Sub PrepareFunctionTypeScatterLineComboBox(ByVal comboBox As ASPxComboBox)
		Const archimedianSpiral As String = "Archimedian Spiral"
		Dim items() As String = { archimedianSpiral, "Cardioid", "Cartesian Folium" }
		PrepareComboBox(comboBox, items, archimedianSpiral)
	End Sub
	Public Shared Sub PrepareChartTypeComboBox(ByVal comboBox As ASPxComboBox)
		Const line As String = "Line"
		Dim items() As String = { line, "Bar" }
		PrepareComboBox(comboBox, items, line)
	End Sub
	Public Shared Sub PrepareSeriesAxisXComboBox(ByVal comboBox As ASPxComboBox)
		Const primaryAxis As String = "Primary Axis X"
		Dim items() As String = { primaryAxis, "Secondary Axis X" }
		PrepareComboBox(comboBox, items, primaryAxis)
	End Sub
	Public Shared Sub PrepareSeriesAxisYComboBox(ByVal comboBox As ASPxComboBox)
		Const secondaryAxisY As String = "Secondary Axis Y"
		Dim items() As String = { "Primary Axis Y", secondaryAxisY }
		PrepareComboBox(comboBox, items, secondaryAxisY)
	End Sub
	Public Shared Sub PrepareViewTypeComboBox(ByVal comboBox As ASPxComboBox)
		Dim items() As String = { "Lines", "Stacked Lines", "Full-Stacked Lines", "Step Lines", "Areas", "Step Areas", "Stacked Areas", "Full-Stacked Areas", "3D Lines", "3D Stacked Lines", "3D Full-Stacked Lines", "3D Step Lines", "3D Areas", "3D Stacked Areas", "3D Full-Stacked Areas", "3D Step Areas", "Spline", "Spline Area", "Stacked Spline", "Full-Stacked Spline", "Spline 3D", "Spline Area 3D", "Stacked Spline 3D", "Full-Stacked Spline 3D" }
		PrepareComboBox(comboBox, items)
	End Sub
	Public Shared Sub PreparePieViewTypeComboBox(ByVal comboBox As ASPxComboBox)
		Dim items() As String = { "Pie", "Pie 3D", "Doughnut", "Doughnut 3D" }
		PrepareComboBox(comboBox, items)
	End Sub
	Public Shared Sub PrepareMarkerKindComboBox(ByVal comboBox As ASPxComboBox, ByVal defaultKind As MarkerKind, ByVal defaultStarPointCount As Integer)
		PrepareComboBox(comboBox, markerKinds.GetNames(), markerKinds.FindName(defaultKind, defaultStarPointCount))
	End Sub
	Public Shared Sub PrepareMarkerSizeComboBox(ByVal comboBox As ASPxComboBox, ByVal defaultSize As Integer)
		PrepareComboBox(comboBox, MarkerKindItemCollection.GetSizeArray(), defaultSize)
	End Sub
	Public Shared Sub PrepareLegendPercentComboBox(ByVal comboBox As ASPxComboBox, ByVal defaultPercent As Double)
		Dim items() As String = AppendPercentMarker(New String() { "25", "50", "75", "100" })
		PrepareComboBox(comboBox, items, defaultPercent.ToString() & percentMarker)
	End Sub
	Public Shared Sub PrepareLineTensionComboBox(ByVal comboBox As ASPxComboBox, ByVal defaultLineTension As Integer)
		Dim items() As String = AppendPercentMarker(New String() { "0", "10", "20", "30", "40", "50", "60", "70", "80", "90", "100" })
		PrepareComboBox(comboBox, items, defaultLineTension.ToString() & percentMarker)
	End Sub
	Public Shared Sub PreparePieLabelsComboBox(ByVal comboBox As ASPxComboBox)
		Dim items() As String = { "Inside", "Outside", "TwoColumns", "Radial" }
		PrepareComboBox(comboBox, items)
	End Sub
	Public Shared Sub PrepareDoughnutHolePercentComboBox(ByVal comboBox As ASPxComboBox)
		Dim defaultHoleString As String = defaultMarker & " (" & defaultDoughnutHole.ToString() & "%)"
		Dim items() As String = AppendPercentMarker(New String() { defaultHoleString, "0", "15", "30", "50", "75", "90", "100" }, 1)
		PrepareComboBox(comboBox, items)
	End Sub
	Public Shared Sub PrepareExplodedPointsComboBox(ByVal comboBox As ASPxComboBox, ByVal points As SeriesPointCollection, ByVal supportCustom As Boolean)
		Dim items() As String = PieExplodingHelper.GetNames(points, supportCustom)
		PrepareComboBox(comboBox, items)
	End Sub
	Public Shared Sub PrepareSummaryFunctionsComboBox(ByVal comboBox As ASPxComboBox)
		Dim items() As String = { "SUM", "MIN", "MAX", "AVERAGE", "COUNT", "STDDEV (Custom)" }
		PrepareComboBox(comboBox, items)
	End Sub
	Public Shared Sub PrepareResolveOverlappingModeComboBox(ByVal comboBox As ASPxComboBox, ByVal defaultMode As ResolveOverlappingMode)
		PrepareComboBox(comboBox, defaultMode)
	End Sub
	Public Shared Function GetSelectedItem(ByVal comboBox As ASPxComboBox, ByVal enumType As Type) As System.Enum
		If (Not enumType.IsEnum) Then
			Throw New ArgumentException()
		End If
		Try
			Return CType(System.Enum.Parse(enumType, comboBox.SelectedItem.Text), [Enum])
		Catch
		End Try
		Return CType(System.Enum.Parse(enumType, CStr(comboBox.SelectedItem.Value)), [Enum])
	End Function
	Public Shared Function GetSelectedResolveOverlappingMode(ByVal comboBox As ASPxComboBox) As ResolveOverlappingMode
		Return CType(GetSelectedItem(comboBox, GetType(ResolveOverlappingMode)), ResolveOverlappingMode)
	End Function
	Public Shared Function GetSelectedPerspectiveAngle(ByVal comboBox As ASPxComboBox) As Integer
		If comboBox.SelectedItem.Text = defaultMarker Then
			Return 50
		Else
			Return Int32.Parse(comboBox.SelectedItem.Text)
		End If
	End Function
	Public Shared Function GetSelectedMarkerKindItem(ByVal comboBox As ASPxComboBox) As MarkerKindItem
		Return markerKinds.Find(comboBox.SelectedItem.Text)
	End Function
	Public Shared Function GetSelectedLegendPercent(ByVal comboBox As ASPxComboBox) As Double
		Return Double.Parse(DeletePercentMarker(comboBox.SelectedItem.Text))
	End Function
	Public Shared Function GetSelectedLineTension(ByVal comboBox As ASPxComboBox) As Integer
		Return Convert.ToInt32(DeletePercentMarker(comboBox.SelectedItem.Text))
	End Function
	Public Shared Function GetSelectedDoughnutHolePercent(ByVal comboBox As ASPxComboBox) As Integer
		Dim selectedText As String = comboBox.SelectedItem.Text
		If selectedText.StartsWith(defaultMarker) Then
			Return defaultDoughnutHole
		Else
			Return Convert.ToInt32(DeletePercentMarker(selectedText))
		End If
	End Function
	Public Shared Sub ApplySelectedExplodingMode(ByVal comboBox As ASPxComboBox, ByVal view As PieSeriesViewBase)
		PieExplodingHelper.ApplyMode(view, comboBox.SelectedItem.Text)
	End Sub
	Public Shared Function GetSelectedRegressionLineColor(ByVal comboBox As ASPxComboBox) As Color
		If comboBox.SelectedItem.Text = "Default" Then
			Return Color.Empty
		Else
			Return Color.FromName(comboBox.SelectedItem.Text)
		End If
	End Function
End Class

Public NotInheritable Class NumericOptionsHelper
	Private Sub New()
	End Sub
	Public Shared Sub CalcNumericFormat(ByVal valueAsPercent As Boolean, <System.Runtime.InteropServices.Out()> ByRef format As NumericFormat, <System.Runtime.InteropServices.Out()> ByRef precision As Integer)
		If valueAsPercent Then
			format = NumericFormat.Percent
			precision = 0
		Else
			format = NumericFormat.FixedPoint
			precision = 1
		End If
	End Sub
	Public Shared Sub SetNumericOptions(ByVal series As Series, ByVal format As NumericFormat, ByVal precision As Integer)
		series.Label.PointOptions.ValueNumericOptions.Format = format
		series.Label.PointOptions.ValueNumericOptions.Precision = precision
	End Sub
End Class

Public NotInheritable Class DataHelper
	Private Sub New()
	End Sub
	Private Shared Function StringToDateTime(ByVal str As String) As DateTime
		Return DateTime.Parse(str, CultureInfo.InvariantCulture)
	End Function
	Public Shared Sub AddPoint(ByVal series As Series, ByVal argument As String, ByVal value As Double)
		Dim argumentDT As DateTime = StringToDateTime(argument)
		series.Points.Add(New SeriesPoint(argumentDT, New Double() { value }))
	End Sub
	Public Shared Sub AddPoint(ByVal series As Series, ByVal argument As String, ByVal value1 As Double, ByVal value2 As Double)
		Dim argumentDT As DateTime = StringToDateTime(argument)
		series.Points.Add(New SeriesPoint(argumentDT, New Double() { value1, value2 }))
	End Sub
End Class

Public NotInheritable Class PieExplodingHelper
	Public Const None As String = "None"
	Public Const All As String = "All"
	Public Const MinValue As String = "Min Value"
	Public Const MaxValue As String = "Max Value"
	Public Const Custom As String = "Custom"
	Private Sub New()
	End Sub
	Public Shared Sub ApplyMode(ByVal view As PieSeriesViewBase, ByVal mode As String)
		Select Case mode
			Case Custom
				view.ExplodeMode = PieExplodeMode.UsePoints
			Case None
				view.ExplodeMode = PieExplodeMode.None
			Case All
				view.ExplodeMode = PieExplodeMode.All
			Case MinValue
				view.ExplodeMode = PieExplodeMode.MinValue
			Case MaxValue
				view.ExplodeMode = PieExplodeMode.MaxValue
			Case Else
				view.ExplodedPointsFilters.Clear()
				view.ExplodedPointsFilters.Add(New SeriesPointFilter(SeriesPointKey.Argument, DataFilterCondition.Equal, mode))
				view.ExplodeMode = PieExplodeMode.UseFilters
		End Select
	End Sub
	Public Shared Function GetNames(ByVal points As SeriesPointCollection, ByVal supportCustom As Boolean) As String()
		Dim itemsCount As Integer = points.Count + 4
		If supportCustom Then
			itemsCount += 1
		End If
		Dim items(itemsCount - 1) As String
		items(0) = None
		items(1) = All
		items(2) = MinValue
		items(3) = MaxValue
		For i As Integer = 0 To points.Count - 1
			items(i + 4) = points(i).Argument
		Next i
		If supportCustom Then
			items(points.Count + 4) = Custom
		End If
		Return items
	End Function
End Class

Public NotInheritable Class PolarFunctionCalculator
	Private Sub New()
	End Sub
	Private Shared Function GetLineFactor(ByVal index As Integer) As Double
		Select Case index
			Case 0
				Return 1
			Case 1
				Return 0.5
			Case 2
				Return 2
			Case Else
				Return 2
		End Select
	End Function
	Private Shared Function ToRadian(ByVal angle As Double) As Double
		Return angle * Math.PI / 180.0
	End Function
	Private Shared Function [Function](ByVal m As Double, ByVal angle As Double) As Double
		Dim cos As Double = Math.Cos(m * ToRadian(90.0 + angle))
		Return Math.Pow(Math.Abs(cos), m)
	End Function
	Public Shared Function GenerateFunctionPoints(ByVal index As Integer, ByVal pointCount As Integer) As SeriesPoint()
		Dim m As Double = GetLineFactor(index)
		Dim [step] As Integer = 360 \ pointCount
		Dim points(pointCount - 1) As SeriesPoint
		For i As Integer = 0 To pointCount - 1
			points(i) = New SeriesPoint([step] * i, New Double() { [Function](m, [step] * i) })
		Next i
		Return points
	End Function

End Class