-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTATableUtils.js
More file actions
414 lines (369 loc) · 15.7 KB
/
TATableUtils.js
File metadata and controls
414 lines (369 loc) · 15.7 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
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
/**
* @class TATableUtils
* @classdesc Class to work with tables using Text Analytics variables
*
* @constructs TATableUtils
* @param {Object} globals - object of global report variables {pageContext: this.pageContext, report: report, user: user, state: state, confirmit: confirmit, log: log}
* @param {TAFolder} folder
* @param {Table} table
*/
class TATableUtils{
private var _globals;
private var _folder: TAFolder;
private var _table: Table;
function TATableUtils(globals, folder, table){
_globals = globals;
_folder = folder;
_table = table;
}
/**
* @memberof TATableUtils
* @instance
* @function SetupRowsTableSorting
* @param {Boolean} directionAscending
* @param {Byte} position
* @param {Number} topN
* @param {Boolean} positionFromEnd
*/
function SetupRowsTableSorting(directionAscending: Boolean, position: Byte, topN, positionFromEnd){
_table.Sorting.Rows.Enabled = true;
_table.Sorting.Rows.SortByType = TableSortByType.Position;
_table.Sorting.Rows.Direction = directionAscending ? TableSortDirection.Ascending : TableSortDirection.Descending;
_table.Sorting.Rows.Position = position;
_table.Sorting.Rows.PositionDirection = positionFromEnd ? TableSortByPositionType.FromEnd : TableSortByPositionType.FromStart;
_table.Sorting.Rows.TopN = topN ? topN : 0;
}
/**
* @memberof TATableUtils
* @instance
* @function SetupConditionalFormatting
* @param {Object[]} conditions - array of objects like { expression: 'cellv(col,row)<(-1)', style: 'negative'}
* @param {String} name
* @param {Object} applyTo - define area in object like {axis: Area.Columns, direction: Area.Left, indexes: "3"}
*/
function SetupConditionalFormatting(conditions, name, applyTo){
var formatter : ConditionalFormatting = _table.ConditionalFormatting;
var area : Area = new Area();
area.Name = name;
area.ApplyTo(applyTo.axis, applyTo.direction, applyTo.indexes);
for(var i = 0; i< conditions.length; i++){
var condition: Condition = new Condition();
condition.Expression = conditions[i].expression;
condition.Style = conditions[i].style;
area.AddCondition(condition);
}
formatter.AddArea(area);
_table.ConditionalFormatting = formatter;
}
/**
* @memberof TATableUtils
* @instance
* @function SetupDrilldown
* @param {String} parameterId
* @param {String} pageIDs
*/
function SetupDrilldown(parameterId: String, pageIDs){
_table.Drilling.Rows.Enabled = true;
_table.Drilling.Rows.Type = DrilldownType.SetParameter;
_table.Drilling.Rows.ParameterID = parameterId;
_table.Drilling.Rows.TargetPages = pageIDs;
}
/**
* @memberof TATableUtils
* @instance
* @function SetupHideEmptyRows
* @param {Boolean} parameterId
*/
function SetupHideEmptyRows(hideEmptyRows){
_table.RemoveEmptyHeaders.Rows = hideEmptyRows;
}
/**
* @memberof TATableUtils
* @instance
* @function AddClasses
* @param {String[]} classes
*/
function AddClasses(classes){
_table.CssClass = ( ( !_table.CssClass ) ? "" : (_table.CssClass + " " ) ) + classes.join(" ");
}
/**
* @memberof TATableUtils
* @instance
* @private
* @function _getSumOfCells
* @description function to get formula expression for sum of previous columns
* @param {Number} cellsNumber
* @param {Number} offset
* @returns {String}
*/
private function _getSumOfCells(cellsNumber,offset){
var cellsSum;
var cellsValues = [];
var columnNumber;
for( var i = 1; i <= cellsNumber; i++){
columnNumber = i + ( offset ? offset : 0);
cellsValues.push(("IF(cellv(col-"+columnNumber+",row) = EMPTYV(), 0, cellv(col-"+columnNumber+",row))"));
}
cellsSum = "IF(("+cellsValues.join('+')+") = 0, EMPTYV(), "+cellsValues.join('+')+")"
return cellsSum
}
/**
* @memberof TATableUtils
* @instance
* @function GetCategoriesHeader
* @description function to get columnHeader for total or neg, neu, pos categories
* @param {String} groupName - "total", "neg", "neu","pos"
* @param {Boolean} addMinus - if you want to add minus to negative values
* @param {Boolean} hideHeader
* @param {String} distribution - 0 - for counts, 1 - for percents
* @returns {HeaderCollection}
*/
function GetCategoriesHeader(groupName: String, addMinus, hideHeader, distribution, config){
var header: HeaderCollection = new HeaderCollection();
var headerFormula : HeaderFormula;
var headerCategories: HeaderCategories;
var categoryTitle: Label;
var defaultConfig = {
Positive: [8,9,10,11],
Neutral: [5,6,7],
Negative: [1,2,3,4]
};
var configuration = config ? config : defaultConfig;
if( groupName == "all" ){
headerCategories= new HeaderCategories();
headerCategories.Mask.Type = MaskType.HideAll;
headerCategories.Totals = true;
headerCategories.HideHeader = hideHeader ? hideHeader : false;
header.Add(headerCategories);
}else{
headerCategories= new HeaderCategories();
headerCategories.Mask.Type = MaskType.ShowCodes;
headerCategories.Totals = false;
headerCategories.HideData = true;
headerFormula = new HeaderFormula();
headerFormula.Type = FormulaType.Expression;
headerFormula.Decimals = 0;
headerFormula.Priority = 0;
switch(groupName.toLowerCase()){
case "neg":
headerCategories.Mask.Codes = configuration.Negative.join(",");
headerFormula.Expression = _getSumOfCells(configuration.Negative.length)+(addMinus?"*(-1)":"");
categoryTitle = new Label(9, "Negative");
break;
case "neu":
headerCategories.Mask.Codes = configuration.Neutral.join(",");
headerFormula.Expression = _getSumOfCells(configuration.Neutral.length);
categoryTitle = new Label(9, "Neutral");
break;
case "pos":
headerCategories.Mask.Codes = configuration.Positive.join(",");
headerFormula.Expression = _getSumOfCells(configuration.Positive.length);
categoryTitle = new Label(9, "Positive");
break;
}
headerFormula.Title = categoryTitle;
headerFormula.HideHeader = hideHeader ? hideHeader : false;
if(distribution && distribution == "1"){
headerCategories.Distributions.Enabled = true;
headerCategories.Distributions.Count = false;
headerCategories.Distributions.HorizontalPercents = true;
headerFormula.Expression +="/100";
headerFormula.Percent = true;
}
header.Add(headerCategories);
header.Add(headerFormula);
}
return header
}
/**
* @memberof TATableUtils
* @instance
* @function GetCategoriesExpression
* @description function to get columnHeaderExpression for total or neg, neu, pos categories
* @param {String} groupName - "total", "neg", "neu","pos"
* @param {Boolean} addMinus - if you want to add minus to negative values
* @param {Boolean} hideHeader
* @param {String} distribution - 0 - for counts, 1 - for percents
* @returns {String}
*/
function GetCategoriesExpression( groupName: String, addMinus, hideHeader, distribution, config ){
var expression = "";
var defaultConfig = {
Positive: [8,9,10,11],
Neutral: [5,6,7],
Negative: [1,2,3,4]
};
var configuration = config ? config : defaultConfig;
if( groupName == "all" ){
expression = '[CAT]{totals:true';
expression += ';mask:emptyv';
if ( hideHeader )
expression += ';hideheader:true';
expression += '}'
}else{
var categoriesHeader = '[CAT]{totals:false;hidedata:true';
var formulaHeader = '[FORMULA]{decimals:0';
var formulaExpression;
var categoryLabel;
switch(groupName.toLowerCase()){
case "neg":
formulaExpression = _getSumOfCells(configuration.Negative.length, (configuration.Positive.length+configuration.Neutral.length))+(addMinus?'*(-1)':'');
categoryLabel = '"Negative"';
break;
case "neu":
formulaExpression = _getSumOfCells(configuration.Neutral.length,(configuration.Positive.length));
categoryLabel = '"Neutral"';
break;
case "pos":
formulaExpression = _getSumOfCells(configuration.Positive.length,0);
categoryLabel = '"Positive"';
break;
}
if(distribution && distribution == "1"){
formulaExpression +="/100";
formulaHeader += ";percent:true";
}
formulaHeader += ';label:'+categoryLabel+';expression:"'+formulaExpression+'"';
if ( hideHeader )
formulaHeader += ';hideheader:true';
formulaHeader +='}'
categoriesHeader += "}"
expression = [categoriesHeader, formulaHeader].join("+")
}
return expression
}
/**
* @memberof TATableUtils
* @instance
* @function GetChartHeader
* @description function to get Header containing Barchart
* @param {ChartComboType} type
* @param {Object[]} formulas - array of objects with formulas like {Formula: "cellv(col-25,row)", Color: (Config.Colors.NegNeuPosPalette.Positive)}
* @param {String} title
* @returns {HeaderChartCombo}
*/
function GetChartHeader(type: ChartComboType, formulas, title){
var chartHeader: HeaderChartCombo = new HeaderChartCombo();
var chartValues = []
chartHeader.TypeOfChart = type;
chartHeader.Thickness = "80%";
chartHeader.CssClass = "chart-header";
chartHeader.ShowTitle = true;
chartHeader.Title = new Label(9, title?title:"Chart");
var chartValue: ChartComboValue;
for(var i = 0; i< formulas.length; i++) {
chartValue = new ChartComboValue();
chartValue.CssClass = "chart-value";
chartValue.Expression = formulas[i].Formula;
chartValue.BaseColor = new ChartComboColorSet([formulas[i].Color]);
chartValues.push(chartValue);
}
chartHeader.Values = chartValues;
return chartHeader;
}
/**
* @memberof TATableUtils
* @instance
* @function GetTAQuestionExpression
* @description function to get Expression for header containing Text Analytics variable
* @param {String} questionType - "overallsentiment", "categories", "positivementions", "negativementions", "categorysentiment"
* @param {String[]} mask
* @param {String} additionalStatement
* @returns {String}
*/
function GetTAQuestionExpression(questionType, mask, additionalStatement){
var rowExpression;
var variableId = _folder.GetQuestionId(questionType);
rowExpression = variableId+'{id:'+variableId+';collapsed:true;totals:false'+( mask && mask.length > 0 ? (';mask:'+mask.join(",")) : null )+( additionalStatement ? (";"+additionalStatement) : null)+'}';
return rowExpression
}
/**
* @memberof TATableUtils
* @instance
* @function GetTimePeriodHeader
* @description function to get Header for certain time period
* @param {String} unit - breaking by "d" - for days, "w" - for weeks, "m" - for months, "q" - for quarters, "y" - for years
* @param {Number} from - rolling from
* @param {Number} to - rolling to
* @returns {HeaderQuestion}
*/
function GetTimePeriodHeader(unit, from, to){
var project = _globals.report.DataSource.GetProject(_folder.GetDatasourceId());
var questionnaireElement: QuestionnaireElement = project.CreateQuestionnaireElement(_folder.GetTimeVariableId());
var headerTimeSeries: HeaderQuestion;
headerTimeSeries = new HeaderQuestion(questionnaireElement);
headerTimeSeries.TimeSeries.FlatLayout = true;
headerTimeSeries.TimeSeries.RollingTimeseries.Enabled = true;
headerTimeSeries.TimeSeries.Time1 = TimeseriesTimeUnitType.Year;
switch (unit.toLowerCase()){
case "d":
headerTimeSeries.TimeSeries.Time2 = TimeseriesTimeUnitType.Month;
headerTimeSeries.TimeSeries.Time3 = TimeseriesTimeUnitType.DayOfMonth;
headerTimeSeries.TimeSeries.RollingTimeseries.Unit = RollingUnitType.Day;
break;
case "w":
headerTimeSeries.TimeSeries.Time2 = TimeseriesTimeUnitType.Week;
headerTimeSeries.TimeSeries.RollingTimeseries.Unit = RollingUnitType.Week;
break;
case "m":
headerTimeSeries.TimeSeries.Time2 = TimeseriesTimeUnitType.Month
headerTimeSeries.TimeSeries.RollingTimeseries.Unit = RollingUnitType.Month;;
break;
case "q":
headerTimeSeries.TimeSeries.Time2 = TimeseriesTimeUnitType.Quarter
headerTimeSeries.TimeSeries.RollingTimeseries.Unit = RollingUnitType.Quarter;
break;
case "y":
default:
headerTimeSeries.TimeSeries.RollingTimeseries.Unit = RollingUnitType.Year;
break;
}
headerTimeSeries.ShowTotals = false;
headerTimeSeries.TimeSeries.RollingTimeseries.From = from;
headerTimeSeries.TimeSeries.RollingTimeseries.To = to;
return headerTimeSeries
}
/**
* @memberof TATableUtils
* @instance
* @function CreateTableFromExpression
* @description function to create table from columns and rows expression
* @param {String} rowHeaders
* @param {String} columnHeaders
*/
function CreateTableFromExpression(rowHeaders, columnHeaders){
var headersArray = [rowHeaders];
if( columnHeaders ){
headersArray.push( columnHeaders )
}
var tableExpression = headersArray.join('^');
//_table.AddHeaders(_globals.report, Config.DS_Main, tableExpression);
_table.AddHeaders(_globals.report, _folder.GetDatasourceId(), tableExpression);
}
/**
* @memberof TATableUtils
* @instance
* @function ClearTableDistributions
* @description function to clear distributions presets for table
*/
function ClearTableDistributions(){
_table.Distribution.Count = false;
_table.Distribution.VerticalPercents = false;
_table.Distribution.HorizontalPercents = false;
}
/**
* @memberof TATableUtils
* @instance
* @function SetDataSupressing
* @description function to set suppression
* @param {Number} baseLessThen
*/
function SetupDataSupressing(baseLessThan){
_table.SuppressData.SuppressData = true;
_table.SuppressData.BaseDisplay = BaseDisplayOption.Hide;
_table.SuppressData.BaseLessThan = baseLessThan;
_table.SuppressData.DistributionMeasure = DistributionMeasureType.InnermostColumn;
_table.SuppressData.CellDisplay = BaseDisplayOption.Hide;
_table.SuppressData.CellLimit = 1;
}
}