-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChartScaleBreakModule.cs
More file actions
80 lines (78 loc) · 4.02 KB
/
ChartScaleBreakModule.cs
File metadata and controls
80 lines (78 loc) · 4.02 KB
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
using System;
using System.Collections.Generic;
using DevExpress.DashboardCommon;
using DevExpress.DashboardWin;
using DevExpress.Utils.Svg;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraCharts;
using DevExpress.XtraReports.UI;
namespace WindowsFormsAppCustomProperties {
public class ChartScaleBreakModule {
public static readonly string PropertyName = "ScaleBreak";
readonly DashboardDesigner designer;
BarCheckItem barItem;
public ChartScaleBreakModule(DashboardDesigner designer, SvgImage barImage = null) {
this.designer = designer;
RibbonControl ribbon = (RibbonControl)designer.MenuManager;
RibbonPage page = ribbon.GetDashboardRibbonPage(DashboardBarItemCategory.ChartTools, DashboardRibbonPage.Design);
RibbonPageGroup group = page.GetGroupByName("Custom Properties");
if(group == null) {
group = new RibbonPageGroup("Custom Properties") { Name = "Custom Properties" };
page.Groups.Add(group);
}
barItem = CreateBarItem("Scale Break", barImage);
group.ItemLinks.Add(barItem);
barItem.ItemClick += ChangeCustomPropertyValue;
designer.DashboardItemControlUpdated += Designer_DashboardItemControlUpdated;
designer.DashboardItemSelected += Designer_DashboardItemSelected;
designer.DashboardCustomPropertyChanged += Designer_DashboardCustomPropertyChanged;
designer.CustomExport += Designer_CustomExport;
}
BarCheckItem CreateBarItem(string caption, SvgImage barImage) {
BarCheckItem barItem = new BarCheckItem();
barItem.Caption = caption;
barItem.ImageOptions.SvgImage = barImage;
return barItem;
}
void ChangeCustomPropertyValue(object sender, ItemClickEventArgs e) {
DashboardItem dashboardItem = designer.SelectedDashboardItem;
bool newValue = !Convert.ToBoolean(dashboardItem.CustomProperties.GetValue(PropertyName));
string status = newValue ? "enabled" : "disabled";
CustomPropertyHistoryItem historyItem = new CustomPropertyHistoryItem(dashboardItem, PropertyName, newValue.ToString(), $"Scale break for {dashboardItem.ComponentName} is {status}");
designer.AddToHistory(historyItem);
}
void Designer_DashboardCustomPropertyChanged(object sender, CustomPropertyChangedEventArgs e) {
if(e.Name == PropertyName)
UpdateBarItem();
}
void Designer_DashboardItemSelected(object sender, DashboardItemSelectedEventArgs e) {
UpdateBarItem();
}
void UpdateBarItem() {
if (designer.SelectedDashboardItem != null)
barItem.Checked = Convert.ToBoolean(designer.SelectedDashboardItem.CustomProperties.GetValue(PropertyName));
}
void Designer_CustomExport(object sender, CustomExportEventArgs e) {
Dictionary<string, XRControl> controls = e.GetPrintableControls();
foreach(var control in controls) {
XRChart xrChart = control.Value as XRChart;
if(xrChart != null) {
string itemComponentName = control.Key;
UpdateChartScaleBreaks(designer.Dashboard.Items[itemComponentName], xrChart.Diagram);
}
}
}
void Designer_DashboardItemControlUpdated(object sender, DashboardItemControlEventArgs e) {
if(e.ChartControl != null)
UpdateChartScaleBreaks(designer.Dashboard.Items[e.DashboardItemName], e.ChartControl.Diagram);
}
void UpdateChartScaleBreaks(DashboardItem dashboardItem, Diagram chartDiagram) {
if (chartDiagram is XYDiagram diagram)
{
bool scaleBreakEnabled = Convert.ToBoolean(dashboardItem.CustomProperties.GetValue(PropertyName));
diagram.SecondaryAxesY[0].AutoScaleBreaks.Enabled = scaleBreakEnabled;
}
}
}
}