@datarailsshared/dr_renderer 1.2.66 → 1.2.67

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datarailsshared/dr_renderer",
3
- "version": "1.2.66",
3
+ "version": "1.2.67",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -485,6 +485,8 @@ let initDRPivotTable = function($, window, document) {
485
485
  SubtotalRenderer = function(pivotData, opts, charttype, tooMuch = false, error_params) {
486
486
  var addClass, allTotal, arrowCollapsed, arrowExpanded, buildColHeaderHeader, buildColHeaderHeaders, buildColHeaderHeadersClickEvents, buildColHeaders, buildColTotals, buildColTotalsHeader, buildGrandTotal, buildRowHeaderHeaders, buildRowHeaderHeadersClickEvents, buildRowHeaders, buildRowTotalsHeader, buildValues, classColCollapsed, classColExpanded, classColHide, classColShow, classCollapsed, classExpanded, classRowCollapsed, classRowExpanded, classRowHide, classRowShow, clickStatusCollapsed, clickStatusExpanded, colAttrs, colDisableAfter, colKeys, colTotals, collapseCol, collapseColsAt, collapseHideDescendantRow, collapseRow, collapseRowsAt, collapseShowColSubtotal, collapseShowRowSubtotal, createElement, defaults, expandChildCol, expandChildRow, expandCol, expandColsAt, expandHideColSubtotal, expandHideRowSubtotal, expandRow, expandRowsAt, expandShowColSubtotal, expandShowRowSubtotal, getTableEventHandlers, hasClass, hideDescendantCol, isColDisable, isColDisableExpandCollapse, isColHideOnExpand, isRowDisable, isRowDisableExpandCollapse, isRowHideOnExpand, main, getSubtotalInBrackets, processKeys, encodeHtmlEntities, ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7, removeClass, replaceClass, rowAttrs, rowDisableAfter, rowKeys, rowTotals, setAttributes, showChildCol, showChildRow, toggleCol, toggleColHeaderHeader, toggleRow, toggleRowHeaderHeader, tree, assumptionSubscribe;
487
487
  var createTotalValsBolder, createGrandTotalBolder, getHeaderColorProperties, colorizeRowLabelHeaders, colorizeTableIfNeed, valueNoDashes, getColorsWithOffsetForTable, offsetColors, handleFreezePanesScroll, selectFreezableElements, removeRowHeaderNullValue;
488
+ var getAdditionalAggregation, buildAdditionalHeaderCols, buildAdditionalHeaderRows, buildAdditionalColValues, buildAdditionalRowValues, buildAdditionalRowTotals, buildAdditionalColTotals;
489
+ var additionalFieldsCol, additionalFieldsRow, additionalFieldsList;
488
490
  var edit_assumptions;
489
491
 
490
492
  var horizontalFreezePaneClass = opts.chartOptions.table_options.freeze_panes ? ' horizontal-freeze-pane' : '';
@@ -497,6 +499,14 @@ let initDRPivotTable = function($, window, document) {
497
499
  XY: axisFreezePaneClass,
498
500
  }
499
501
 
502
+ additionalFieldsCol = [];
503
+ additionalFieldsRow = [];
504
+ additionalFieldsList = [
505
+ {key: 'DR_Average', name: 'DR_Average'},
506
+ {key: 'DR_Others', name: _.get(opts, "total_value_options.filter_options.filteredOutFieldName") || 'Others'}
507
+ ];
508
+ $.pivotUtilities.additionalFieldsList = additionalFieldsList;
509
+
500
510
  defaults = {
501
511
  table: {
502
512
  clickCallback: null
@@ -796,6 +806,16 @@ let initDRPivotTable = function($, window, document) {
796
806
  };
797
807
 
798
808
  processKeys = function(keysArr, className, dimention, attrs) {
809
+ for (let i = 0; i < keysArr.length; i++) {
810
+ const additionalField = _.find(additionalFieldsList, {key: keysArr[i][0]})
811
+
812
+ if (additionalField) {
813
+ dimention === 'rows'
814
+ ? additionalFieldsRow.push(additionalField)
815
+ : additionalFieldsCol.push(additionalField);
816
+ }
817
+ }
818
+
799
819
  var c, headers, k, key, lastCol, lastRow, node, nodePos, r, rMark, ref8, repeats, th, x;
800
820
  const showAllData = opts && opts.chartOptions && opts.chartOptions.table_options && opts.chartOptions.table_options.show_all;
801
821
 
@@ -1015,6 +1035,9 @@ let initDRPivotTable = function($, window, document) {
1015
1035
  return results;
1016
1036
  };
1017
1037
  buildColHeaders = function(colHeaderHeaders, colHeaderCols, colHeader, rowAttrs, colAttrs) {
1038
+ const additionalField = _.find(additionalFieldsList, {key: colHeader.key[0]})
1039
+ if (additionalField) return;
1040
+
1018
1041
  var colspan, h, hh, isColSubtotal, k, len, ref8, rowspan, sTh, style, th, tr;
1019
1042
  ref8 = colHeader.children;
1020
1043
  for (k = 0, len = ref8.length; k < len; k++) {
@@ -1177,6 +1200,9 @@ let initDRPivotTable = function($, window, document) {
1177
1200
  }
1178
1201
  };
1179
1202
  buildRowHeaders = function(tbody, rowHeaderHeaders, rowHeaderRows, rowHeader, rowAttrs, colAttrs, highlighted, hasColLabels) {
1203
+ const additionalField = _.find(additionalFieldsList, {key: rowHeader.key[0]})
1204
+ if (additionalField) return;
1205
+
1180
1206
  var colspan, h, hh, isRowSubtotal, k, len, ref8, results, style, th, tr;
1181
1207
  hh = rowHeaderHeaders.hh[rowHeader.col];
1182
1208
  ++hh.expandedCount;
@@ -1254,8 +1280,143 @@ let initDRPivotTable = function($, window, document) {
1254
1280
  }
1255
1281
  return results;
1256
1282
  };
1283
+
1284
+ getAdditionalAggregation = function (rowKey, colKey) {
1285
+ if ((tree && tree[rowKey] && tree[rowKey][colKey])
1286
+ && (rowKey !== '...' || colKey !== '...')) {
1287
+ return tree[rowKey][colKey];
1288
+ } else {
1289
+ return {
1290
+ value: (function() {
1291
+ return null;
1292
+ }),
1293
+ format: function() {
1294
+ return "";
1295
+ }
1296
+ };
1297
+ }
1298
+ }
1299
+
1300
+ buildAdditionalHeaderCols = function (tr, rowAttrs, colAttrs) {
1301
+ let rowspan, th;
1302
+
1303
+ rowspan = 1;
1304
+ if (colAttrs.length !== 0) {
1305
+ rowspan = colAttrs.length + (rowAttrs.length === 0 ? 0 : 1);
1306
+ }
1307
+
1308
+ for (let i = 0; i < additionalFieldsCol.length; i++) {
1309
+ const col = additionalFieldsCol[i];
1310
+ th = createElement("th", "pvtColLabel" + verticalFreezePaneClass , col.name, {
1311
+ rowspan: rowspan
1312
+ });
1313
+
1314
+ if (opts.chartOptions.table_options.freeze_panes) {
1315
+ tr.appendChild(th);
1316
+ getHeaderColorProperties(tr);
1317
+ } else {
1318
+ return tr.appendChild(th);
1319
+ }
1320
+ }
1321
+ };
1322
+
1323
+ buildAdditionalHeaderRows = function (fieldName, rowAttrs, colAttrs) {
1324
+ let colspan, th, tr;
1325
+
1326
+ tr = createElement("tr");
1327
+ colspan = rowAttrs.length + (colAttrs.length === 0 ? 0 : 1);
1328
+ th = createElement("th", "pvtRowLabel" + horizontalFreezePaneClass, fieldName, {
1329
+ colspan: colspan
1330
+ });
1331
+
1332
+ tr.appendChild(th);
1333
+ return tr;
1334
+ };
1335
+
1336
+ buildAdditionalColValues = function (tr, rowKey, rowHeader) {
1337
+ for (let i = 0; i < additionalFieldsCol.length; i++) {
1338
+ const colKey = additionalFieldsCol[i].key;
1339
+ const totalAggregator = getAdditionalAggregation(rowKey, colKey);
1340
+ const val = totalAggregator.value();
1341
+ const formattedValue = getFormattedNumber(val, totalAggregator, opts)
1342
+
1343
+ let className = "pvtVal rowshow colshow";
1344
+ className += " row" + rowHeader.row + " rowcol" + rowHeader.col;
1345
+
1346
+ const td = createElement("td", className, formattedValue, {
1347
+ "data-value": val,
1348
+ "data-row": "row" + rowHeader.row,
1349
+ "data-rowcol": "col" + rowHeader.col,
1350
+ "data-rownode": rowHeader.node
1351
+ }, getTableEventHandlers(val, rowHeader.key, []));
1352
+
1353
+ tr.appendChild(td)
1354
+ }
1355
+ }
1356
+
1357
+ buildAdditionalRowValues = function (tr, colHeaderCols, rowKey) {
1358
+ let totalRowValue = 0;
1359
+
1360
+ for (let i = 0; i < colHeaderCols.length; i++) {
1361
+ const colKey = colHeaderCols[i].flatKey;
1362
+ const totalAggregator = getAdditionalAggregation(rowKey, colKey);
1363
+ const val = totalAggregator.value();
1364
+ const formattedValue = getFormattedNumber(val, totalAggregator, opts)
1365
+ totalRowValue += +formattedValue;
1366
+
1367
+ let className = " col" + i + " colcol" + 0;
1368
+ const td = createElement("td", className, formattedValue, {
1369
+ "data-value": val,
1370
+ "data-for": "col" + 0,
1371
+ "data-colnode": "" + i
1372
+ });
1373
+
1374
+ tr.appendChild(td);
1375
+ }
1376
+
1377
+ if(opts.chartOptions.table_options.show_row_total) {
1378
+ buildAdditionalRowTotals(tr, totalRowValue)
1379
+ }
1380
+ }
1381
+
1382
+ buildAdditionalRowTotals = function (tr, totalRowValue) {
1383
+ let style = "pvtTotal pvtAddFiled rowTotal";
1384
+
1385
+ const td = createElement("td", style, totalRowValue, {
1386
+ "data-value": totalRowValue
1387
+ });
1388
+
1389
+ tr.appendChild(td);
1390
+ }
1391
+
1392
+ buildAdditionalColTotals = function (tr, rowHeaderRows, colKey, colHeader) {
1393
+ let othersVal = 0;
1394
+ let val;
1395
+
1396
+ for (let i = 0; i < rowHeaderRows.length; i++) {
1397
+ const rowKey = rowHeaderRows[i].flatKey;
1398
+ const totalAggregator = getAdditionalAggregation(rowKey, colKey);
1399
+ val = totalAggregator.value();
1400
+
1401
+ othersVal += +getFormattedNumber(val, totalAggregator, opts);
1402
+ }
1403
+
1404
+ let style = "pvtTotal pvtAddField colTotal";
1405
+ style += " col" + colHeader.row + " colcol" + colHeader.col;
1406
+
1407
+ const td = createElement("td", style, othersVal, {
1408
+ "data-value": othersVal,
1409
+ "data-rowcol": "col" + colHeader.col,
1410
+ "data-rownode": "" + colHeader.node
1411
+ }, getTableEventHandlers(othersVal, [], colHeader.key));
1412
+
1413
+
1414
+ return td;
1415
+ }
1416
+
1257
1417
  buildValues = function(rowHeaderRows, colHeaderCols, rowAttrs, colAttrs) {
1258
1418
  var aggregator, colHeader, eventHandlers, flatColKey, flatRowKey, isColSubtotal, isRowSubtotal, k, l, len, len1, ref8, results, rowHeader, style, td, totalAggregator, tr, val;
1419
+
1259
1420
  results = [];
1260
1421
  for (k = 0, len = rowHeaderRows.length; k < len; k++) {
1261
1422
  rowHeader = rowHeaderRows[k];
@@ -1305,6 +1466,11 @@ let initDRPivotTable = function($, window, document) {
1305
1466
 
1306
1467
  tr.appendChild(td);
1307
1468
  }
1469
+
1470
+ if (additionalFieldsCol.length > 0) {
1471
+ buildAdditionalColValues(tr, flatRowKey, rowHeader);
1472
+ }
1473
+
1308
1474
  totalAggregator = rowTotals[flatRowKey];
1309
1475
  if(!totalAggregator){
1310
1476
  totalAggregator = {
@@ -1406,12 +1572,13 @@ let initDRPivotTable = function($, window, document) {
1406
1572
  tr.appendChild(th);
1407
1573
  return tr;
1408
1574
  };
1409
- buildColTotals = function(tr, colHeaderCols, rowAttrs, colAttrs) {
1575
+ buildColTotals = function(tr, colHeaderCols, rowHeaderRows, rowAttrs, colAttrs) {
1410
1576
  var h, isColSubtotal, k, len, results, style, td, totalAggregator, val;
1411
1577
  results = [];
1412
1578
  for (k = 0, len = colHeaderCols.length; k < len; k++) {
1413
1579
  h = colHeaderCols[k];
1414
1580
  isColSubtotal = h.children.length !== 0;
1581
+
1415
1582
  totalAggregator = colTotals[h.flatKey];
1416
1583
  if(!totalAggregator){
1417
1584
  totalAggregator = {
@@ -1444,11 +1611,22 @@ let initDRPivotTable = function($, window, document) {
1444
1611
 
1445
1612
  results.push(tr.appendChild(td));
1446
1613
  }
1614
+
1615
+ if (additionalFieldsCol.length > 0) {
1616
+ for (let i = 0; i < additionalFieldsCol.length; i++) {
1617
+ const colKey = additionalFieldsCol[i].key;
1618
+
1619
+ td = buildAdditionalColTotals(tr, rowHeaderRows, colKey, h);
1620
+ results.push(tr.appendChild(td));
1621
+ }
1622
+ }
1623
+
1447
1624
  createGrandTotalBolder(tr);
1448
1625
  return results;
1449
1626
  };
1450
1627
  buildGrandTotal = function(result, tr, rowAttrs, colAttrs) {
1451
1628
  var td, totalAggregator, val;
1629
+
1452
1630
  totalAggregator = allTotal;
1453
1631
  val = totalAggregator.value();
1454
1632
  td = createElement("td", "pvtGrandTotal", getFormattedNumber(val, totalAggregator, opts), {
@@ -2154,10 +2332,20 @@ let initDRPivotTable = function($, window, document) {
2154
2332
  }
2155
2333
  if (rowAttrs.length > 0) {
2156
2334
  buildRowHeaderHeaders(thead, rowHeaderHeaders, rowAttrs, colAttrs);
2335
+
2336
+ if (colAttrs.length === 0 && additionalFieldsCol.length > 0) {
2337
+ buildAdditionalHeaderCols(rowHeaderHeaders.tr, rowAttrs, colAttrs)
2338
+ }
2339
+
2157
2340
  if (colAttrs.length === 0 && opts.chartOptions.table_options.show_row_total) {
2158
2341
  buildRowTotalsHeader(rowHeaderHeaders.tr, rowAttrs, colAttrs);
2159
2342
  }
2160
2343
  }
2344
+
2345
+ if (colAttrs.length > 0 && additionalFieldsCol.length > 0) {
2346
+ buildAdditionalHeaderCols(colHeaderHeaders[0].tr, rowAttrs, colAttrs)
2347
+ }
2348
+
2161
2349
  if (colAttrs.length > 0 && opts.chartOptions.table_options.show_row_total) {
2162
2350
  buildRowTotalsHeader(colHeaderHeaders[0].tr, rowAttrs, colAttrs);
2163
2351
  if(opts.chartOptions.table_options.colorize_headers == true){
@@ -2186,10 +2374,24 @@ let initDRPivotTable = function($, window, document) {
2186
2374
  }
2187
2375
  buildRowHeaderHeadersClickEvents(rowHeaderHeaders, rowHeaderRows, rowAttrs);
2188
2376
  buildValues(rowHeaderRows, colHeaderCols, rowAttrs, colAttrs);
2377
+
2378
+ if (additionalFieldsRow.length > 0) {
2379
+ for (let i = 0; i < additionalFieldsRow.length; i++) {
2380
+ const field = additionalFieldsRow[i];
2381
+ tr = buildAdditionalHeaderRows(field.name, rowAttrs, colAttrs);
2382
+
2383
+ if (colAttrs.length > 0) {
2384
+ buildAdditionalRowValues(tr, colHeaderCols, field.key);
2385
+ }
2386
+
2387
+ tbody.appendChild(tr);
2388
+ }
2389
+ }
2390
+
2189
2391
  if(opts.chartOptions.table_options.show_column_total){
2190
2392
  tr = buildColTotalsHeader(rowAttrs, colAttrs);
2191
2393
  if (colAttrs.length > 0) {
2192
- buildColTotals(tr, colHeaderCols, rowAttrs, colAttrs);
2394
+ buildColTotals(tr, colHeaderCols, rowHeaderRows, rowAttrs, colAttrs);
2193
2395
  }
2194
2396
  if(opts.chartOptions.table_options.show_row_total)
2195
2397
  buildGrandTotal(tbody, tr, rowAttrs, colAttrs);
@@ -41,6 +41,13 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
41
41
  highchartsRenderer.variance_color = default_colors.variance_color;
42
42
  }
43
43
 
44
+ const mobileBrowserRegex = new RegExp([
45
+ '(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)',
46
+ '|ipad|iris|kindle|Android|Silk|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/',
47
+ '|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino',
48
+ ].join(''), 'i');
49
+ highchartsRenderer.isMobile = mobileBrowserRegex.test(navigator.userAgent);
50
+
44
51
  highchartsRenderer.highcharts_theme = {
45
52
  "colors": highchartsRenderer.defaults_colors,
46
53
  "chart": {
@@ -2000,7 +2007,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
2000
2007
  };
2001
2008
 
2002
2009
  highchartsRenderer.setTitleAndSubTitle = function (chartOptions, opts, additionOptions) {
2003
- chartOptions.title = opts.chartOptions.hideChartHeader ? null : {
2010
+ chartOptions.title = opts.chartOptions.hideChartHeader ? { text: '' } : {
2004
2011
  align: 'center',
2005
2012
  text: opts && opts.chart_title ? opts.chart_title : "",
2006
2013
  style: {
@@ -4261,6 +4268,10 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4261
4268
  }
4262
4269
 
4263
4270
  if (typeof (value) != 'number') {
4271
+ const drAdditionalField = _.find($.pivotUtilities.additionalFieldsList, {key: value});
4272
+ if (drAdditionalField && drAdditionalField.key)
4273
+ return drAdditionalField.key;
4274
+
4264
4275
  value = 0;
4265
4276
  }
4266
4277
 
@@ -7410,6 +7421,10 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
7410
7421
  enabled: false,
7411
7422
  };
7412
7423
 
7424
+ if ((!additionOptions.legends_position || additionOptions.legends_position.value !== 'none') && highchartsRenderer.isMobile) {
7425
+ return topPosition;
7426
+ }
7427
+
7413
7428
  if (additionOptions.legends_position && additionOptions.legends_position.value) {
7414
7429
  switch (additionOptions.legends_position.value) {
7415
7430
  case 'top':