-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchart-axis-max-value-extension.ts
171 lines (158 loc) · 6.59 KB
/
chart-axis-max-value-extension.ts
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import * as Dashboard from 'devexpress-dashboard';
import * as Model from 'devexpress-dashboard/model';
import * as Designer from 'devexpress-dashboard/designer';
// 1. Model
const axisMaxValueEnabledProperty: Model.CustomPropertyMetadata = {
ownerType: Model.ChartItem,
propertyName: "AxisMaxValueEnabled",
defaultValue: false,
valueType: 'boolean'
};
const axisMaxValueIsBoundProperty: Model.CustomPropertyMetadata = {
ownerType: Model.ChartItem,
propertyName: "AxisMaxValueIsBound",
defaultValue: false,
valueType: 'boolean'
};
const axisMaxValueConstantProperty: Model.CustomPropertyMetadata = {
ownerType: Model.ChartItem,
propertyName: "AxisMaxValueConstant",
defaultValue: 100,
valueType: 'number'
};
const axisMaxValueDataItemProperty: Model.CustomPropertyMetadata = {
ownerType: Model.ChartItem,
propertyName: "AxisMaxValueDataItem",
defaultValue: '',
valueType: 'string'
};
Model.registerCustomProperty(axisMaxValueEnabledProperty);
Model.registerCustomProperty(axisMaxValueIsBoundProperty);
Model.registerCustomProperty(axisMaxValueConstantProperty);
Model.registerCustomProperty(axisMaxValueDataItemProperty);
// 2. Viewer
function onItemWidgetOptionsPrepared(args) {
if(args.dashboardItem.customProperties.getValue(axisMaxValueEnabledProperty.propertyName)) {
var value = args.dashboardItem.customProperties.getValue(axisMaxValueConstantProperty.propertyName)
if(args.dashboardItem.customProperties.getValue(axisMaxValueIsBoundProperty.propertyName)) {
var measureId = args.dashboardItem.customProperties.getValue(axisMaxValueDataItemProperty.propertyName)
value = args.itemData.getMeasureValue(measureId).getValue()
}
args.options.valueAxis[0].visualRange = [null, value]
}
}
// 3. Designer
function isAxisMaxValueDisabled(dashboardItem) {
return !dashboardItem.customProperties.getValue(axisMaxValueEnabledProperty.propertyName);
}
function isBoundMode(dashboardItem) {
return dashboardItem.customProperties.getValue(axisMaxValueIsBoundProperty.propertyName);
}
function changeDisabledState(dxForm, fieldName, isDisabled) {
let itemOptions = dxForm.itemOption(fieldName)
if(itemOptions) {
let editorOptions = itemOptions.editorOptions || {}
editorOptions.disabled = isDisabled
dxForm.itemOption(fieldName, "editorOptions", editorOptions)
}
}
function changeVisibleState(dxForm, fieldName, isVisible) {
let itemOptions = dxForm.itemOption(fieldName, "visible", isVisible)
}
function updateFormState(dxForm, dashboardItem) {
dxForm.beginUpdate();
changeDisabledState(dxForm, axisMaxValueIsBoundProperty.propertyName, isAxisMaxValueDisabled(dashboardItem))
changeDisabledState(dxForm, axisMaxValueConstantProperty.propertyName, isAxisMaxValueDisabled(dashboardItem))
changeDisabledState(dxForm, axisMaxValueDataItemProperty.propertyName, isAxisMaxValueDisabled(dashboardItem))
changeVisibleState(dxForm, axisMaxValueConstantProperty.propertyName, !isBoundMode(dashboardItem))
changeVisibleState(dxForm, axisMaxValueDataItemProperty.propertyName, isBoundMode(dashboardItem))
dxForm.endUpdate();
}
function onCustomizeSections(args) {
if (args.dashboardItem instanceof Model.ChartItem) {
args.addSection({
title: "Primary Axis Max Value (Custom)",
onFieldDataChanged: (e) => {
updateFormState(e.component, args.dashboardItem);
},
onInitialized: (e) => {
updateFormState(e.component, args.dashboardItem);
},
items: [
{
dataField: axisMaxValueEnabledProperty.propertyName,
editorType: "dxCheckBox",
label: { visible: false },
editorOptions: {
text: "Enabled",
}
},
{
dataField: axisMaxValueIsBoundProperty.propertyName,
label: {
text: "Mode"
},
template: Designer.FormItemTemplates.buttonGroup,
editorOptions: {
keyExpr: "value",
items: [{
value: true,
text: "Bound"
}, {
value: false,
text: "Value"
}]
}
},
{
dataField: axisMaxValueConstantProperty.propertyName,
editorType: "dxTextBox",
label: {
text: "Value",
}
},
{
dataField: axisMaxValueDataItemProperty.propertyName,
editorType: "dxSelectBox",
label: {
text: "DataItem",
},
editorOptions: {
displayExpr: "text",
valueExpr: "value",
items: args.dashboardItem.hiddenMeasures().map(measure => ({
text: measure.name() || measure.dataMember(),
value: measure.uniqueName()
})),
}
}
]
})
}
}
// 4. Event Subscription
export class ChartAxisMaxValueExtension {
name = "ChartAxisMaxValueExtension";
constructor(private dashboardControl: Dashboard.DashboardControl) {
}
start() {
let viewerApiExtension = <Dashboard.ViewerApiExtension>this.dashboardControl.findExtension('viewer-api');
if (viewerApiExtension) {
viewerApiExtension.on('itemWidgetOptionsPrepared', onItemWidgetOptionsPrepared);
}
let bindingPanelExtension = <Designer.OptionsPanelExtension>this.dashboardControl.findExtension("item-options-panel");
if (bindingPanelExtension) {
bindingPanelExtension.on('customizeSections', onCustomizeSections);
}
}
stop() {
let viewerApiExtension = <Dashboard.ViewerApiExtension>this.dashboardControl.findExtension('viewer-api');
if (viewerApiExtension) {
viewerApiExtension.off('itemWidgetOptionsPrepared', onItemWidgetOptionsPrepared);
}
let bindingPanelExtension = <Designer.OptionsPanelExtension>this.dashboardControl.findExtension("item-options-panel");
if (bindingPanelExtension) {
bindingPanelExtension.off('customizeSections', onCustomizeSections);
}
}
}