@datarailsshared/dr_renderer 1.2.401 → 1.2.405

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.401",
3
+ "version": "1.2.405",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -863,19 +863,14 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
863
863
 
864
864
  /* model renderers */
865
865
 
866
- highchartsRenderer.tableCSVExportRenderer = function (pivotData, opts) {
867
- var aggregator, colAttrs, colKey, colKeys, defaults, i, j, rowAttrs, rowKey, rowKeys, tempAr,
866
+ highchartsRenderer.tableCSVExportRenderer = function (pivotData) {
867
+ var aggregator, colAttrs, colKey, colKeys, i, j, rowAttrs, rowKey, rowKeys, tempAr,
868
868
  totalAggregator, val;
869
869
 
870
870
  var hasProp = {}.hasOwnProperty;
871
871
  var forExport = [];
872
872
 
873
- defaults = {
874
- localeStrings: {
875
- totals: "Totals"
876
- }
877
- };
878
- opts = $.extend(defaults, opts);
873
+ const TOTAL_CELL = 'Totals';
879
874
  colAttrs = pivotData.colAttrs;
880
875
  rowAttrs = pivotData.rowAttrs;
881
876
  rowKeys = pivotData.getRowKeys();
@@ -897,7 +892,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
897
892
  tempAr = tempAr.concat(lodash.map(colKeys, function (row) {
898
893
  return row[j];
899
894
  }));
900
- tempAr.push(opts.localeStrings.totals);
895
+ tempAr.push(TOTAL_CELL);
901
896
  forExport.push(tempAr);
902
897
  }
903
898
 
@@ -930,7 +925,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
930
925
 
931
926
  for (j in rowAttrs) {
932
927
  if (!hasProp.call(rowAttrs, j)) continue;
933
- tempAr.push(opts.localeStrings.totals)
928
+ tempAr.push(TOTAL_CELL)
934
929
  }
935
930
 
936
931
  for (j in colKeys) {
@@ -949,10 +944,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
949
944
  return forExport;
950
945
  };
951
946
 
952
- highchartsRenderer.getNoDataResult = function (rendererOptions, to_match) {
947
+ highchartsRenderer.getNoDataResult = function (to_match) {
953
948
  var temp_result = $('<div class="noData-box"></div>');
954
949
  var resultsArr = [];
955
- var subTitle;
956
950
 
957
951
  if (to_match) {
958
952
  resultsArr.push(highchartsRenderer.getWidgetPlaceholder(highchartsRenderer.widgetPlaceholders.tooMuchData));
@@ -1070,11 +1064,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1070
1064
  }
1071
1065
 
1072
1066
  if (!seriesDataLength && !chartOptions.onlyText) {
1073
- result = highchartsRenderer.getNoDataResult(chartOptions);
1067
+ result = highchartsRenderer.getNoDataResult();
1074
1068
  opts.error_has_occurred = true;
1075
1069
  opts.error_params = highchartsRenderer.widgetPlaceholders.nodata;
1076
1070
  } else if (!chartOptions.onlyText && chartOptions.series && toMatch) {
1077
- result = highchartsRenderer.getNoDataResult(chartOptions, toMatch);
1071
+ result = highchartsRenderer.getNoDataResult(toMatch);
1078
1072
  opts.error_has_occurred = true;
1079
1073
  opts.error_params = highchartsRenderer.widgetPlaceholders.tooMuchData;
1080
1074
  } else {
@@ -1235,7 +1229,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1235
1229
  trendSeries.name = highchartsRenderer.getTrendSeriesName(trendSeries);
1236
1230
  trendSeries.dashStyle = 'shortdot';
1237
1231
  trendSeries.type = 'line';
1238
- trendSeries.data = trendSeries.data.map((el, index) => a + b * (index + 1));
1232
+ trendSeries.data = trendSeries.data.map(
1233
+ (data, index) => lodash.get(data, 'name')
1234
+ ? { name: data.name, initialName: data.initialName, y: a + b * (index + 1) }
1235
+ : a + b * (index + 1)
1236
+ );
1239
1237
 
1240
1238
  if (colors && colors[i]) {
1241
1239
  trendSeries.color = colors[i];
@@ -1424,7 +1422,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1424
1422
  trendSeries.name = highchartsRenderer.getTrendSeriesName(trendSeries);
1425
1423
  trendSeries.dashStyle = 'shortdot';
1426
1424
  trendSeries.type = 'line';
1427
- trendSeries.data = trendSeries.data.map((data, index) => ({name: data.name, y: a + b * (index + 1)}));
1425
+ trendSeries.data = trendSeries.data.map(
1426
+ (data, index) => ({ name: data.name, initialName: data.initialName, y: a + b * (index + 1) })
1427
+ );
1428
1428
 
1429
1429
  if (colors && colors[i]) {
1430
1430
  trendSeries.color = colors[i];
@@ -4663,7 +4663,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4663
4663
  class: uniqueCategories.length < minCategories ? 'waterfall-nodata' : 'waterfall-too-much-data',
4664
4664
  }
4665
4665
 
4666
- return highchartsRenderer.getNoDataResult(options.rendererOptions, true);
4666
+ return highchartsRenderer.getNoDataResult(true);
4667
4667
  }
4668
4668
  }
4669
4669
 
@@ -4674,7 +4674,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4674
4674
 
4675
4675
  options.error_has_occurred = true;
4676
4676
  options.error_params = highchartsRenderer.widgetPlaceholders.nodata;
4677
- return highchartsRenderer.getNoDataResult(options.rendererOptions);
4677
+ return highchartsRenderer.getNoDataResult();
4678
4678
  }
4679
4679
 
4680
4680
  if (rowData.length > highchartsRenderer.MAX_ROWS_FOR_SHOW_RESULTS) {
@@ -4684,7 +4684,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4684
4684
 
4685
4685
  options.error_has_occurred = true;
4686
4686
  options.error_params = highchartsRenderer.widgetPlaceholders.tooMuchData;
4687
- return highchartsRenderer.getNoDataResult(options.rendererOptions, true);
4687
+ return highchartsRenderer.getNoDataResult(true);
4688
4688
  }
4689
4689
 
4690
4690
  var tmp = $.pivotUtilities.aggregatorTemplates;
@@ -4833,7 +4833,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4833
4833
  class: uniqueCategories.length < minCategories ? 'waterfall-nodata' : 'waterfall-too-much-data',
4834
4834
  }
4835
4835
 
4836
- return highchartsRenderer.getNoDataResult(options.rendererOptions, true);
4836
+ return highchartsRenderer.getNoDataResult(true);
4837
4837
  }
4838
4838
  }
4839
4839
 
@@ -4844,7 +4844,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4844
4844
 
4845
4845
  options.error_has_occurred = true;
4846
4846
  options.error_params = highchartsRenderer.widgetPlaceholders.nodata;
4847
- return highchartsRenderer.getNoDataResult(options.rendererOptions);
4847
+ return highchartsRenderer.getNoDataResult();
4848
4848
  }
4849
4849
 
4850
4850
  if (rowData.length > highchartsRenderer.MAX_ROWS_FOR_SHOW_RESULTS) {
@@ -4854,7 +4854,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4854
4854
 
4855
4855
  options.error_has_occurred = true;
4856
4856
  options.error_params = highchartsRenderer.widgetPlaceholders.tooMuchData;
4857
- return highchartsRenderer.getNoDataResult(options.rendererOptions, true);
4857
+ return highchartsRenderer.getNoDataResult(true);
4858
4858
  }
4859
4859
 
4860
4860
  var tmp = $.pivotUtilities.aggregatorTemplates;
@@ -6244,6 +6244,84 @@ describe('highcharts_renderer', () => {
6244
6244
  });
6245
6245
  });
6246
6246
 
6247
+ describe('Function tableCSVExportRenderer', () => {
6248
+ window._ = lodash;
6249
+ it('should create csv json object representation based on pivot data', () => {
6250
+ const inputs = [
6251
+ {
6252
+ "Date": 1653955200,
6253
+ "Amount": 2849521.69
6254
+ },
6255
+ {
6256
+ "Date": 1653177600,
6257
+ "Amount": 3141257.27
6258
+ },
6259
+ {
6260
+ "Date": 1652400000,
6261
+ "Amount": 1700691.7000000002
6262
+ },
6263
+ {
6264
+ "Date": 1651363200,
6265
+ "Amount": 2142840.39
6266
+ },
6267
+ {
6268
+ "Amount": 9834311.05
6269
+ },
6270
+ {
6271
+ "col_keys": [
6272
+ [
6273
+ 1651363200
6274
+ ],
6275
+ [
6276
+ 1652400000
6277
+ ],
6278
+ [
6279
+ 1653177600
6280
+ ],
6281
+ [
6282
+ 1653955200
6283
+ ]
6284
+ ],
6285
+ "row_keys": []
6286
+ }
6287
+ ];
6288
+ const subOptions = {
6289
+ "sorters": () => null,
6290
+ "sortByValueAttrs": [],
6291
+ "cols": [
6292
+ "Date",
6293
+ "Payment Date"
6294
+ ],
6295
+ "rows": [],
6296
+ "colFormats": [
6297
+ {
6298
+ "type": "Date",
6299
+ "name": "Date",
6300
+ "val_not_convert": []
6301
+ },
6302
+ {
6303
+ "type": "Date",
6304
+ "name": "Payment Date",
6305
+ "val_not_convert": []
6306
+ }
6307
+ ],
6308
+ "rowFormats": [],
6309
+ "rendererOptions": {
6310
+ },
6311
+ };
6312
+ const pivotData = $.pivotUtilities.getPivotDataModel(inputs, subOptions);
6313
+ const csvJson = highchartsRenderer.tableCSVExportRenderer(pivotData);
6314
+ expect(csvJson).toEqual(
6315
+ [
6316
+ [1651363200, 1652400000, 1653177600, 1653955200, 'null', 'Totals' ],
6317
+ ['null', 'null', 'null', 'null', 'null', 'Totals'],
6318
+ [],
6319
+ [1, 1, 1, 1, 2, 6]
6320
+ ]
6321
+ );
6322
+ });
6323
+ });
6324
+
6247
6325
  describe("Function returnRawDataValue", () => {
6248
6326
  const testCases = [{
6249
6327
  name: "Date",
@@ -6804,14 +6882,17 @@ describe('highcharts_renderer', () => {
6804
6882
  {
6805
6883
  data: [
6806
6884
  {
6885
+ initialName: 'col 1',
6807
6886
  name: 'col 1',
6808
6887
  y: 11728
6809
6888
  },
6810
6889
  {
6890
+ initialName: 'col 2',
6811
6891
  name: 'col 2',
6812
6892
  y: 55555
6813
6893
  },
6814
6894
  {
6895
+ initialName: 'Others',
6815
6896
  name: 'Others',
6816
6897
  y: 99382
6817
6898
  }
@@ -6837,14 +6918,17 @@ describe('highcharts_renderer', () => {
6837
6918
  {
6838
6919
  data: [
6839
6920
  {
6921
+ initialName: 'col 1',
6840
6922
  name: 'col 1',
6841
6923
  y: 89913.5
6842
6924
  },
6843
6925
  {
6926
+ initialName: 'col 2',
6844
6927
  name: 'col 2',
6845
6928
  y: 78184
6846
6929
  },
6847
6930
  {
6931
+ initialName: 'Others',
6848
6932
  name: 'Others',
6849
6933
  y: 66454.5
6850
6934
  }
@@ -7320,9 +7404,21 @@ describe('highcharts_renderer', () => {
7320
7404
  },
7321
7405
  {
7322
7406
  data: [
7323
- 11728,
7324
- 55555,
7325
- 99382
7407
+ {
7408
+ initialName: 'col 1',
7409
+ name: 'col 1',
7410
+ y: 11728
7411
+ },
7412
+ {
7413
+ initialName: 'col 2',
7414
+ name: 'col 2',
7415
+ y: 55555
7416
+ },
7417
+ {
7418
+ initialName: 'Others',
7419
+ name: 'Others',
7420
+ y: 99382
7421
+ }
7326
7422
  ],
7327
7423
  initialName: 'row 1',
7328
7424
  name: 'Trend Line (row 1)',
@@ -7333,9 +7429,21 @@ describe('highcharts_renderer', () => {
7333
7429
  },
7334
7430
  {
7335
7431
  data: [
7336
- 89913.5,
7337
- 78184,
7338
- 66454.5
7432
+ {
7433
+ initialName: 'col 1',
7434
+ name: 'col 1',
7435
+ y: 89913.5
7436
+ },
7437
+ {
7438
+ initialName: 'col 2',
7439
+ name: 'col 2',
7440
+ y: 78184
7441
+ },
7442
+ {
7443
+ initialName: 'Others',
7444
+ name: 'Others',
7445
+ y: 66454.5
7446
+ }
7339
7447
  ],
7340
7448
  initialName: 'row 2',
7341
7449
  name: 'Trend Line (row 2)',
@@ -7397,4 +7505,42 @@ describe('highcharts_renderer', () => {
7397
7505
  ]);
7398
7506
  })
7399
7507
  });
7508
+
7509
+ describe('Function getNoDataResult', () => {
7510
+ const container = $('<div class="noData-box"></div>');
7511
+
7512
+ it('should return no data html', () => {
7513
+ const placeholderMeta = highchartsRenderer.widgetPlaceholders.nodata;
7514
+ const expected = container.clone().html(highchartsRenderer.getWidgetPlaceholder(placeholderMeta));
7515
+ expect(highchartsRenderer.getNoDataResult()).toEqual(expected);
7516
+ });
7517
+
7518
+ it('should return too much data html', () => {
7519
+ const placeholderMeta = highchartsRenderer.widgetPlaceholders.tooMuchData;
7520
+ const expected = container.clone().html(highchartsRenderer.getWidgetPlaceholder(placeholderMeta));
7521
+ expect(highchartsRenderer.getNoDataResult(true)).toEqual(expected);
7522
+ });
7523
+
7524
+ });
7525
+
7526
+ describe('Function getWidgetPlaceholder', () => {
7527
+ const titleSelector = '.noData-title';
7528
+ const imageSelector = '.noData-image';
7529
+ const textSelector = '.noData-text';
7530
+
7531
+ it('should return default placeholder when no data is provided', () => {
7532
+ const placeholder = highchartsRenderer.getWidgetPlaceholder();
7533
+ const defaultPlaceholder = '<div class="noData"><i class="noData-image"></i> no data</div>';
7534
+ expect(placeholder[0].outerHTML).toEqual(defaultPlaceholder);
7535
+ });
7536
+
7537
+ it('should return placeholder html when data is provided', () => {
7538
+ Object.entries(highchartsRenderer.widgetPlaceholders).forEach(([, value]) => {
7539
+ const placeholder = highchartsRenderer.getWidgetPlaceholder(value)[0];
7540
+ expect(placeholder.querySelector(titleSelector).innerHTML).toEqual(value.title);
7541
+ expect(placeholder.querySelector(imageSelector).classList.contains(value.class)).toBeTruthy();
7542
+ expect(placeholder.querySelector(textSelector).innerHTML).toEqual(value.text);
7543
+ });
7544
+ });
7545
+ })
7400
7546
  });