@datarailsshared/dr_renderer 1.2.296 → 1.2.297

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.296",
3
+ "version": "1.2.297",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -502,7 +502,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
502
502
  var topSlot = '';
503
503
  if (labelOpts.show_percentage_in_labels) {
504
504
  rightSlot = `(${(this.point.percentage).toFixed(2)}%)`;
505
- if (labelOpts.show_value_in_labels && value) topSlot = `${value}<br>`;
505
+ if (labelOpts.show_value_in_labels && value) {
506
+ topSlot = `${value}<br>`;
507
+ }
506
508
  } else if (labelOpts.show_value_in_labels && value) {
507
509
  rightSlot = value;
508
510
  }
@@ -540,7 +542,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
540
542
 
541
543
  const labelOptions = lodash.get(opts.chartOptions, 'label') || lodash.get(opts.chartOptions, 'label_pie');
542
544
  const othersName = opts.total_value_options ? highchartsRenderer.getOthersName(opts) : undefined;
543
- const drOthersInAxis = highchartsRenderer.getDrOthersInAxisState(pivotData, othersName);
545
+ const drOthersInAxis = pivotData ? highchartsRenderer.getDrOthersInAxisState(pivotData, othersName) : {};
544
546
 
545
547
  var func = function () {
546
548
  var value = parseFloat(this.y);
@@ -717,7 +719,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
717
719
  }
718
720
 
719
721
  const othersName = opts.total_value_options ? highchartsRenderer.getOthersName(opts) : undefined;
720
- const drOthersInAxis = highchartsRenderer.getDrOthersInAxisState(pivotData, othersName);
722
+ const drOthersInAxis = pivotData ? highchartsRenderer.getDrOthersInAxisState(pivotData, othersName) : {};
721
723
 
722
724
  var func = function () {
723
725
  const isWaterfallBreakdown = this.series.options.className === SERIES_CLASSNAMES.WATERFALL_BREAKDOWN;
@@ -380,19 +380,117 @@ describe('highcharts_renderer', () => {
380
380
  });
381
381
  });
382
382
 
383
- describe('function isSystemField', () => {
384
- it('system name', () => {
385
- const field = {
386
- name: 'Doc_ID'
383
+ describe('function defaultValueLabelsFormatter', () => {
384
+ let funcContext;
385
+
386
+ beforeEach(() => {
387
+ funcContext = { value: '12345.678' };
388
+ });
389
+
390
+ it('should return formatted number by aggregator', () => {
391
+ const format = '"$"#,###.##';
392
+ let pivotData = {
393
+ getAggregator: () => {
394
+ let aggregator = highchartsRenderer.rhPivotAggregatorSum([''], format, true, {}, {});
395
+ return aggregator({}, '', '');
396
+ }
387
397
  };
388
- expect(highchartsRenderer.isSystemField(field)).toBe(true);
398
+ let defaultValueLabelsFormatterFn = highchartsRenderer.defaultValueLabelsFormatter(pivotData, {})
399
+ let result = defaultValueLabelsFormatterFn.call(funcContext)
400
+ expect(result).toBe('$12,345.68');
389
401
  });
390
402
 
391
- it('not system name', () => {
392
- const field = {
393
- name: 'field name'
403
+ it('should return local string if there are no pivotData', () => {
404
+ let defaultValueLabelsFormatterFn = highchartsRenderer.defaultValueLabelsFormatter(null, {})
405
+ let result = defaultValueLabelsFormatterFn.call(funcContext)
406
+ expect(result).toBe('12,345.678');
407
+ });
408
+ });
409
+
410
+ describe('function persantageValueLabelsFormatter', () => {
411
+ it('should return local string with %', () => {
412
+ let funcContext = { value: '12345.678' };
413
+ let persantageValueLabelsFormatterFn = highchartsRenderer.persantageValueLabelsFormatter(null, {})
414
+ let result = persantageValueLabelsFormatterFn.call(funcContext)
415
+ expect(result).toBe('1,234,567.8%');
416
+ });
417
+ });
418
+
419
+ describe('function pieDataLabelFormatter', () => {
420
+ let funcContext;
421
+ let opts;
422
+
423
+ beforeEach(() => {
424
+ spyOn(highchartsRenderer, 'defaultDataLabelFormatter').and.returnValue(function() { return this.value })
425
+ funcContext = {
426
+ value: '12345.678',
427
+ point: {
428
+ color: 'red',
429
+ name: 'test',
430
+ percentage: 12.3456,
431
+ }
394
432
  };
395
- expect(highchartsRenderer.isSystemField(field)).toBe(false);
433
+ opts = {
434
+ chartOptions: {
435
+ label_pie: {
436
+ use_area_color: false,
437
+ show_percentage_in_labels: false,
438
+ show_value_in_labels: false,
439
+ }
440
+ }
441
+ }
442
+ });
443
+
444
+ it('should return null if value is nor defined', () => {
445
+ highchartsRenderer.defaultDataLabelFormatter.and.returnValue(() => null);
446
+ let func = highchartsRenderer.pieDataLabelFormatter(null, opts);
447
+ let result = func.call(funcContext);
448
+ expect(result).toBe(null);
449
+ });
450
+
451
+ it('should present only name with area color if only use_area_color option enabled', () => {
452
+ opts.chartOptions.label_pie.use_area_color = true;
453
+ let func = highchartsRenderer.pieDataLabelFormatter(null, opts);
454
+ let result = func.call(funcContext);
455
+ expect(result).toBe('<b><span style="color: red;">test</span><span>\u200E: </span></b>');
456
+ });
457
+
458
+ it('should present only name and value if only show_value_in_labels option enabled', () => {
459
+ opts.chartOptions.label_pie.show_value_in_labels = true;
460
+ let func = highchartsRenderer.pieDataLabelFormatter(null, opts);
461
+ let result = func.call(funcContext);
462
+ expect(result).toBe('<b><span >test</span><span>\u200E: 12345.678</span></b>');
463
+ });
464
+
465
+ it('should present only name and percentage if only show_percentage_in_labels option enabled', () => {
466
+ opts.chartOptions.label_pie.show_percentage_in_labels = true;
467
+ let func = highchartsRenderer.pieDataLabelFormatter(null, opts);
468
+ let result = func.call(funcContext);
469
+ expect(result).toBe('<b><span >test</span><span>\u200E: (12.35%)</span></b>');
470
+ });
471
+
472
+ it('should present vale + name + percentage if only % and value options enabled', () => {
473
+ opts.chartOptions.label_pie.show_percentage_in_labels = true;
474
+ opts.chartOptions.label_pie.show_value_in_labels = true;
475
+ let func = highchartsRenderer.pieDataLabelFormatter(null, opts);
476
+ let result = func.call(funcContext);
477
+ expect(result).toBe('12345.678<br><b><span >test</span><span>\u200E: (12.35%)</span></b>');
478
+ });
479
+ });
480
+
481
+ describe('function defaultDataLabelFormatter', () => {
482
+ let funcContext;
483
+ let opts;
484
+
485
+ beforeEach(() => {
486
+ funcContext = { y: '12345.678' };
487
+ opts = {}
488
+ });
489
+
490
+ it('should return local string if there are no pivotData', () => {
491
+ let fn = highchartsRenderer.defaultDataLabelFormatter(null, {})
492
+ let result = fn.call(funcContext)
493
+ expect(result).toBe('12,345.678');
396
494
  });
397
495
  });
398
496
 
@@ -1042,6 +1140,22 @@ describe('highcharts_renderer', () => {
1042
1140
  });
1043
1141
  });
1044
1142
 
1143
+ describe('function isSystemField', () => {
1144
+ it('system name', () => {
1145
+ const field = {
1146
+ name: 'Doc_ID'
1147
+ };
1148
+ expect(highchartsRenderer.isSystemField(field)).toBe(true);
1149
+ });
1150
+
1151
+ it('not system name', () => {
1152
+ const field = {
1153
+ name: 'field name'
1154
+ };
1155
+ expect(highchartsRenderer.isSystemField(field)).toBe(false);
1156
+ });
1157
+ });
1158
+
1045
1159
  describe('function getFieldColorClass', () => {
1046
1160
  it('should return "green_field" if field is not a system field and not mandatory', () => {
1047
1161
  const field = {
@@ -2327,7 +2441,6 @@ describe('highcharts_renderer', () => {
2327
2441
  });
2328
2442
  });
2329
2443
 
2330
-
2331
2444
  describe('function getChartAxisLabel', () => {
2332
2445
  it('should return default value', () => {
2333
2446
  expect(highchartsRenderer.getChartAxisLabel('invalidType')).toBe('Axis (Category)')