-
Notifications
You must be signed in to change notification settings - Fork 142
/
barChartSettingsModel.ts
198 lines (179 loc) · 5.71 KB
/
barChartSettingsModel.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import powerbiVisualsApi from "powerbi-visuals-api";
import { formattingSettings } from "powerbi-visuals-utils-formattingmodel";
import { BarChartDataPoint } from "./barChart";
import Card = formattingSettings.SimpleCard;
import Model = formattingSettings.Model;
import Slice = formattingSettings.Slice;
import ColorPicker = formattingSettings.ColorPicker;
import ToggleSwitch = formattingSettings.ToggleSwitch;
import NumUpDown = formattingSettings.NumUpDown;
import TextInput = formattingSettings.TextInput;
import AutoDropdown = formattingSettings.AutoDropdown;
import FontControl = formattingSettings.FontControl;
import FontPicker = formattingSettings.FontPicker;
class EnableAxisCardSettings extends Card {
show = new ToggleSwitch({
name: "show",
displayName: undefined,
value: false,
});
fill = new ColorPicker({
name: "fill",
displayName: "Color",
value: { value: "#000000" }
});
topLevelSlice: ToggleSwitch = this.show;
name: string = "enableAxis";
displayName: string = "Enable Axis";
slices: Slice[] = [this.fill];
}
class ColorSelectorCardSettings extends Card {
name: string = "colorSelector";
displayName: string = "Data Colors";
slices: Slice[] = [];
}
class GeneralViewCardSettings extends Card {
opacity = new NumUpDown({
name: "opacity",
displayName: "Bars Opacity",
value: 100,
options: {
minValue: {
type: powerbiVisualsApi.visuals.ValidatorType.Min,
value: 0,
},
maxValue: {
type: powerbiVisualsApi.visuals.ValidatorType.Max,
value: 100,
}
}
});
showHelpLink = new ToggleSwitch({
name: "showHelpLink",
displayName: "Show Help Button",
value: false
});
name: string = "generalView";
displayName: string = "General View";
helpLinkColor: string = "#80B0E0"
slices: Slice[] = [this.opacity, this.showHelpLink];
}
class AverageLineCardSettings extends Card {
show = new ToggleSwitch({
name: "show",
displayName: undefined,
value: false,
});
fill = new ColorPicker({
name: "fill",
displayName: "Color",
value: { value: "#888888" },
});
showDataLabel = new ToggleSwitch({
name: "showDataLabel",
displayName: "Data Label",
value: false
});
topLevelSlice: ToggleSwitch = this.show;
name: string = "averageLine";
displayName: string = "Average Line";
analyticsPane: boolean = true;
slices: Slice[] = [this.show, this.fill, this.showDataLabel];
}
class DirectEditSettings extends Card {
displayName: string = "Direct Edit";
name: string = "directEdit";
private minFontSize: number = 8;
private defaultFontSize: number = 11;
show = new ToggleSwitch({
name: "show",
displayName: undefined,
value: true,
});
topLevelSlice: ToggleSwitch = this.show;
textProperty = new TextInput({
displayName: "Text Property",
name: "textProperty",
value: "What is your quest?",
placeholder: ""
});
position = new AutoDropdown({
name: "position",
displayName: "Position",
value: "Right"
});
font = new FontControl({
name: "font",
displayName: "Font",
fontFamily: new FontPicker({
name: "fontFamily",
displayName: "Font Family",
value: "Segoe UI, wf_segoe-ui_normal, helvetica, arial, sans-serif"
}),
fontSize: new NumUpDown({
name: "fontSize",
displayName: "Font Size",
value: this.defaultFontSize,
options: {
minValue: {
type: powerbi.visuals.ValidatorType.Min,
value: this.minFontSize,
}
}
}),
bold: new ToggleSwitch({
name: "bold",
displayName: "bold",
value: true
}),
italic: new ToggleSwitch({
name: "italic",
displayName: "italic",
value: true
}),
underline: new ToggleSwitch({
name: "underline",
displayName: "underline",
value: true
})
});
fontColor = new ColorPicker({
name: "fontColor",
displayName: "Color",
value: { value: "#000000" }
});
background = new ColorPicker({
name: "background",
displayName: "Background Color",
value: { value: "#FFFFFF" }
});
slices: Slice[] = [this.textProperty, this.font, this.fontColor, this.background, this.position];
}
/**
* BarChart formatting settings model class
*/
export class BarChartSettingsModel extends Model {
enableAxis = new EnableAxisCardSettings();
colorSelector = new ColorSelectorCardSettings();
generalView = new GeneralViewCardSettings();
averageLine = new AverageLineCardSettings();
directEditSettings = new DirectEditSettings();
cards: Card[] = [this.enableAxis, this.colorSelector, this.generalView, this.averageLine, this.directEditSettings];
/**
* populate colorSelector object categories formatting properties
* @param dataPoints
*/
populateColorSelector(dataPoints: BarChartDataPoint[]) {
const slices: Slice[] = this.colorSelector.slices;
if (dataPoints) {
dataPoints.forEach(dataPoint => {
slices.push(new ColorPicker({
name: "fill",
displayName: dataPoint.category,
value: { value: dataPoint.color },
selector: dataPoint.selectionId.getSelector(),
}));
});
}
}
}