/
ChartScaleBreakModule.vb
84 lines (82 loc) · 4.08 KB
/
ChartScaleBreakModule.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
Imports System
Imports System.Collections.Generic
Imports DevExpress.DashboardCommon
Imports DevExpress.DashboardWin
Imports DevExpress.Utils.Svg
Imports DevExpress.XtraBars
Imports DevExpress.XtraBars.Ribbon
Imports DevExpress.XtraCharts
Imports DevExpress.XtraReports.UI
Namespace WindowsFormsAppCustomProperties
Public Class ChartScaleBreakModule
Public Shared ReadOnly PropertyName As String = "ScaleBreak"
Private ReadOnly designer As DashboardDesigner
Private barItem As BarCheckItem
Public Sub New(ByVal designer As DashboardDesigner, Optional ByVal barImage As SvgImage = Nothing)
Me.designer = designer
Dim ribbon As RibbonControl = CType(designer.MenuManager, RibbonControl)
Dim page As RibbonPage = ribbon.GetDashboardRibbonPage(DashboardBarItemCategory.ChartTools, DashboardRibbonPage.Design)
Dim group As RibbonPageGroup = page.GetGroupByName("Custom Properties")
If group Is Nothing Then
group = New RibbonPageGroup("Custom Properties") With {.Name = "Custom Properties"}
page.Groups.Add(group)
End If
barItem = CreateBarItem("Scale Break", barImage)
group.ItemLinks.Add(barItem)
AddHandler barItem.ItemClick, AddressOf ChangeCustomPropertyValue
AddHandler designer.DashboardItemControlUpdated, AddressOf Designer_DashboardItemControlUpdated
AddHandler designer.DashboardItemSelected, AddressOf Designer_DashboardItemSelected
AddHandler designer.DashboardCustomPropertyChanged, AddressOf Designer_DashboardCustomPropertyChanged
AddHandler designer.CustomExport, AddressOf Designer_CustomExport
End Sub
Private Function CreateBarItem(ByVal caption As String, ByVal barImage As SvgImage) As BarCheckItem
Dim barItem As New BarCheckItem()
barItem.Caption = caption
barItem.ImageOptions.SvgImage = barImage
Return barItem
End Function
Private Sub ChangeCustomPropertyValue(ByVal sender As Object, ByVal e As ItemClickEventArgs)
Dim dashboardItem As DashboardItem = designer.SelectedDashboardItem
Dim newValue As Boolean = Not Convert.ToBoolean(dashboardItem.CustomProperties.GetValue(PropertyName))
Dim status As String = If(newValue, "enabled", "disabled")
Dim historyItem As New CustomPropertyHistoryItem(dashboardItem, PropertyName, newValue.ToString(), $"Scale break for {dashboardItem.ComponentName} is {status}")
designer.AddToHistory(historyItem)
End Sub
Private Sub Designer_DashboardCustomPropertyChanged(ByVal sender As Object, ByVal e As CustomPropertyChangedEventArgs)
If e.Name = PropertyName Then
UpdateBarItem()
End If
End Sub
Private Sub Designer_DashboardItemSelected(ByVal sender As Object, ByVal e As DashboardItemSelectedEventArgs)
UpdateBarItem()
End Sub
Private Sub UpdateBarItem()
If designer.SelectedDashboardItem IsNot Nothing Then
barItem.Checked = Convert.ToBoolean(designer.SelectedDashboardItem.CustomProperties.GetValue(PropertyName))
End If
End Sub
Private Sub Designer_CustomExport(ByVal sender As Object, ByVal e As CustomExportEventArgs)
Dim controls As Dictionary(Of String, XRControl) = e.GetPrintableControls()
For Each control In controls
Dim xrChart As XRChart = TryCast(control.Value, XRChart)
If xrChart IsNot Nothing Then
Dim itemComponentName As String = control.Key
UpdateChartScaleBreaks(designer.Dashboard.Items(itemComponentName), xrChart.Diagram)
End If
Next control
End Sub
Private Sub Designer_DashboardItemControlUpdated(ByVal sender As Object, ByVal e As DashboardItemControlEventArgs)
If e.ChartControl IsNot Nothing Then
UpdateChartScaleBreaks(designer.Dashboard.Items(e.DashboardItemName), e.ChartControl.Diagram)
End If
End Sub
Private Sub UpdateChartScaleBreaks(ByVal dashboardItem As DashboardItem, ByVal chartDiagram As Diagram)
Dim tempVar As Boolean = TypeOf chartDiagram Is XYDiagram
Dim diagram As XYDiagram = If(tempVar, CType(chartDiagram, XYDiagram), Nothing)
If tempVar Then
Dim scaleBreakEnabled As Boolean = Convert.ToBoolean(dashboardItem.CustomProperties.GetValue(PropertyName))
diagram.SecondaryAxesY(0).AutoScaleBreaks.Enabled = scaleBreakEnabled
End If
End Sub
End Class
End Namespace