@datarailsshared/dr_renderer 1.4.61 → 1.4.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
@@ -670,7 +670,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
670
670
|
}
|
671
671
|
|
672
672
|
var cols = highchartsRenderer.getColsInFormatterContext(this);
|
673
|
-
if (typeof (cols) == 'object' && cols.name) {
|
673
|
+
if (typeof (cols) == 'object' && cols && cols.name) {
|
674
674
|
cols = cols.name;
|
675
675
|
}
|
676
676
|
|
@@ -5256,10 +5256,27 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
5256
5256
|
}
|
5257
5257
|
};
|
5258
5258
|
|
5259
|
-
highchartsRenderer.setMissingWidgetOptions = function(options, type) {
|
5260
|
-
if (!lodash.has(options, 'chartOptions')) return;
|
5259
|
+
highchartsRenderer.setMissingWidgetOptions = function (options, type) {
|
5260
|
+
if (!options || !lodash.has(options, 'chartOptions')) return;
|
5261
|
+
|
5261
5262
|
const defaultOptions = highchartsRenderer.getDefaultValueForChart(type);
|
5262
|
-
|
5263
|
+
|
5264
|
+
// User can remove segment and this part of code was made to
|
5265
|
+
// prevent a set of default value
|
5266
|
+
if (type === highchartsRenderer.CHART_TYPES.GAUGE_CHART_DYNAMIC_GOAL) {
|
5267
|
+
const chartOptions = options.chartOptions || {};
|
5268
|
+
const userSegments = chartOptions.segments;
|
5269
|
+
const merged = lodash.merge({}, defaultOptions, lodash.omit(chartOptions, 'segments'));
|
5270
|
+
|
5271
|
+
if (Array.isArray(userSegments)) {
|
5272
|
+
merged.segments = userSegments;
|
5273
|
+
}
|
5274
|
+
|
5275
|
+
options.chartOptions = merged;
|
5276
|
+
return;
|
5277
|
+
}
|
5278
|
+
|
5279
|
+
options.chartOptions = lodash.merge({}, defaultOptions, options.chartOptions);
|
5263
5280
|
};
|
5264
5281
|
|
5265
5282
|
highchartsRenderer.addPivotOptions = function (selectedTemplateWOData, widgetOptions, drilldownFunction, drillDownListFunction) {
|
@@ -511,19 +511,559 @@ describe('highcharts_renderer', () => {
|
|
511
511
|
});
|
512
512
|
|
513
513
|
describe('function defaultDataLabelFormatter', () => {
|
514
|
+
let mockPivotData;
|
514
515
|
let funcContext;
|
515
516
|
let opts;
|
516
517
|
|
517
518
|
beforeEach(() => {
|
518
519
|
highchartsRenderer.enabledNewWidgetValueFormatting = false;
|
519
|
-
|
520
|
-
|
520
|
+
highchartsRenderer.delimer = ' , ';
|
521
|
+
|
522
|
+
funcContext = {
|
523
|
+
y: 12345.678,
|
524
|
+
series: {
|
525
|
+
name: 'TestSeries',
|
526
|
+
userOptions: {},
|
527
|
+
options: {}
|
528
|
+
},
|
529
|
+
point: {
|
530
|
+
name: 'TestPoint',
|
531
|
+
options: {}
|
532
|
+
}
|
533
|
+
};
|
534
|
+
opts = {};
|
535
|
+
|
536
|
+
mockPivotData = {
|
537
|
+
rowAttrs: ['row1'],
|
538
|
+
colAttrs: ['col1'],
|
539
|
+
getRowKeys: jest.fn(() => [['row1'], ['row2']]),
|
540
|
+
getAggregator: jest.fn(() => ({
|
541
|
+
value: () => 1000
|
542
|
+
}))
|
543
|
+
};
|
544
|
+
|
545
|
+
spyOn(highchartsRenderer, 'getSeriesNameInFormatterContext').and.returnValue('TestSeries');
|
546
|
+
spyOn(highchartsRenderer, 'getColsInFormatterContext').and.returnValue(['col1']);
|
547
|
+
spyOn(highchartsRenderer, 'getOthersName').and.returnValue('Others');
|
548
|
+
spyOn(highchartsRenderer, 'getDrOthersInAxisState').and.returnValue({});
|
549
|
+
spyOn(highchartsRenderer, 'transformRowsAndColsForBreakdown').and.returnValue({
|
550
|
+
rows: ['row1'],
|
551
|
+
cols: ['col1']
|
552
|
+
});
|
553
|
+
spyOn(highchartsRenderer, 'replaceDrOthersKeys');
|
554
|
+
spyOn(highchartsRenderer, 'selfStartsWith').and.returnValue(false);
|
555
|
+
|
556
|
+
global.$ = {
|
557
|
+
pivotUtilities: {
|
558
|
+
getFormattedNumber: jest.fn(() => '1,234.56')
|
559
|
+
}
|
560
|
+
};
|
521
561
|
});
|
522
562
|
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
563
|
+
describe('No pivotData is provided', () => {
|
564
|
+
it('should return formatted number as local string', () => {
|
565
|
+
let fn = highchartsRenderer.defaultDataLabelFormatter(null, {});
|
566
|
+
let result = fn.call(funcContext);
|
567
|
+
|
568
|
+
expect(result).toBe('12,345.678');
|
569
|
+
});
|
570
|
+
|
571
|
+
it('should handle unit sign removal when labelOptions are provided', () => {
|
572
|
+
const labelOptions = { useUnitAbbreviation: false };
|
573
|
+
opts = { chartOptions: { label: labelOptions } };
|
574
|
+
|
575
|
+
let fn = highchartsRenderer.defaultDataLabelFormatter(null, opts);
|
576
|
+
let result = fn.call(funcContext);
|
577
|
+
|
578
|
+
expect(result).toBe('12,345.678');
|
579
|
+
});
|
580
|
+
});
|
581
|
+
|
582
|
+
describe('pivotData is provided', () => {
|
583
|
+
beforeEach(() => {
|
584
|
+
funcContext.y = 1234.56;
|
585
|
+
});
|
586
|
+
|
587
|
+
it('should format value using pivot data aggregator when show_value is true', () => {
|
588
|
+
opts = { chartOptions: { label: { show_value: true } } };
|
589
|
+
|
590
|
+
let fn = highchartsRenderer.defaultDataLabelFormatter(mockPivotData, opts);
|
591
|
+
let result = fn.call(funcContext);
|
592
|
+
|
593
|
+
expect(highchartsRenderer.getSeriesNameInFormatterContext).toHaveBeenCalledWith(funcContext);
|
594
|
+
expect(highchartsRenderer.getColsInFormatterContext).toHaveBeenCalledWith(funcContext);
|
595
|
+
expect(mockPivotData.getAggregator).toHaveBeenCalled();
|
596
|
+
expect(result).toBe('1,234.56');
|
597
|
+
});
|
598
|
+
|
599
|
+
it('should return empty string when show_value is false and not drill-down pie', () => {
|
600
|
+
opts = { chartOptions: { label: { show_value: false } } };
|
601
|
+
let fn = highchartsRenderer.defaultDataLabelFormatter(mockPivotData, opts);
|
602
|
+
let result = fn.call(funcContext);
|
603
|
+
|
604
|
+
expect(result).toBe('');
|
605
|
+
});
|
606
|
+
|
607
|
+
it('should handle empty row attributes', () => {
|
608
|
+
mockPivotData.rowAttrs = [];
|
609
|
+
opts = { chartOptions: { label: { show_value: true } } };
|
610
|
+
let fn = highchartsRenderer.defaultDataLabelFormatter(mockPivotData, opts);
|
611
|
+
let result = fn.call(funcContext);
|
612
|
+
|
613
|
+
expect(result).toBe('1,234.56');
|
614
|
+
});
|
615
|
+
|
616
|
+
it('should handle totalSeries className', () => {
|
617
|
+
funcContext.series.options.className = 'totalSeries';
|
618
|
+
opts = { chartOptions: { label: { show_value: true } } };
|
619
|
+
let fn = highchartsRenderer.defaultDataLabelFormatter(mockPivotData, opts);
|
620
|
+
let result = fn.call(funcContext);
|
621
|
+
|
622
|
+
expect(result).toBe('1,234.56');
|
623
|
+
});
|
624
|
+
|
625
|
+
it('should handle trendSeries className', () => {
|
626
|
+
funcContext.series.options.className = 'trendSeries';
|
627
|
+
opts = { chartOptions: { label: { show_value: true } } };
|
628
|
+
let fn = highchartsRenderer.defaultDataLabelFormatter(mockPivotData, opts);
|
629
|
+
let result = fn.call(funcContext);
|
630
|
+
|
631
|
+
expect(result).toBe('1,234.56');
|
632
|
+
});
|
633
|
+
});
|
634
|
+
|
635
|
+
describe('Drill-down pie chart scenarios', () => {
|
636
|
+
beforeEach(() => {
|
637
|
+
funcContext.y = 500;
|
638
|
+
});
|
639
|
+
|
640
|
+
it('should handle drill-down pie when series name starts with "Series "', () => {
|
641
|
+
highchartsRenderer.selfStartsWith.and.returnValue(true);
|
642
|
+
highchartsRenderer.getSeriesNameInFormatterContext.and.returnValue('Series 1');
|
643
|
+
|
644
|
+
opts = { chartOptions: {} };
|
645
|
+
let fn = highchartsRenderer.defaultDataLabelFormatter(mockPivotData, opts, true);
|
646
|
+
let result = fn.call(funcContext);
|
647
|
+
|
648
|
+
expect(highchartsRenderer.selfStartsWith).toHaveBeenCalledWith('Series 1', 'Series ');
|
649
|
+
expect(result).toBe('500');
|
650
|
+
});
|
651
|
+
|
652
|
+
it('should use point name for columns when cols is null in drill-down pie', () => {
|
653
|
+
highchartsRenderer.getColsInFormatterContext.and.returnValue(null);
|
654
|
+
funcContext.point.name = 'DrillDownPoint';
|
655
|
+
|
656
|
+
opts = { chartOptions: {} };
|
657
|
+
let fn = highchartsRenderer.defaultDataLabelFormatter(mockPivotData, opts, true);
|
658
|
+
let result = fn.call(funcContext);
|
659
|
+
|
660
|
+
expect(result).toBe('500');
|
661
|
+
});
|
662
|
+
|
663
|
+
it('should swap rows and cols for drill-down pie when series name does not start with "Series "', () => {
|
664
|
+
highchartsRenderer.selfStartsWith.and.returnValue(false);
|
665
|
+
highchartsRenderer.getSeriesNameInFormatterContext.and.returnValue('CustomSeries');
|
666
|
+
|
667
|
+
opts = { chartOptions: {} };
|
668
|
+
let fn = highchartsRenderer.defaultDataLabelFormatter(mockPivotData, opts, true);
|
669
|
+
let result = fn.call(funcContext);
|
670
|
+
|
671
|
+
expect(result).toBe('500');
|
672
|
+
});
|
673
|
+
});
|
674
|
+
|
675
|
+
describe('Delta column handling', () => {
|
676
|
+
it('should replace variant name when delta column field is series', () => {
|
677
|
+
opts = {
|
678
|
+
chartOptions: {
|
679
|
+
label: { show_value: true },
|
680
|
+
delta_column: {
|
681
|
+
field: 'series',
|
682
|
+
name: 'test_variant'
|
683
|
+
}
|
684
|
+
}
|
685
|
+
};
|
686
|
+
|
687
|
+
highchartsRenderer.getSeriesNameInFormatterContext.and.returnValue('test_variant' + highchartsRenderer.delimer + 'other');
|
688
|
+
|
689
|
+
let fn = highchartsRenderer.defaultDataLabelFormatter(mockPivotData, opts);
|
690
|
+
let result = fn.call(funcContext);
|
691
|
+
|
692
|
+
expect(result).toBe('12,345.678');
|
693
|
+
});
|
694
|
+
|
695
|
+
it('should handle variant name matching when series name differs by underscores from delta column name', () => {
|
696
|
+
opts = {
|
697
|
+
chartOptions: {
|
698
|
+
label: { show_value: true },
|
699
|
+
delta_column: {
|
700
|
+
field: 'series',
|
701
|
+
name: 'test_variant'
|
702
|
+
}
|
703
|
+
}
|
704
|
+
};
|
705
|
+
|
706
|
+
highchartsRenderer.getSeriesNameInFormatterContext.and.returnValue('testvariant' + highchartsRenderer.delimer + 'other');
|
707
|
+
|
708
|
+
let fn = highchartsRenderer.defaultDataLabelFormatter(mockPivotData, opts);
|
709
|
+
let result = fn.call(funcContext);
|
710
|
+
|
711
|
+
expect(result).toBe('12,345.678');
|
712
|
+
});
|
713
|
+
});
|
714
|
+
|
715
|
+
describe('Label options handling', () => {
|
716
|
+
it('should return raw value when show_out_of_x_axis is true but percentage logic is not triggered', () => {
|
717
|
+
opts = {
|
718
|
+
chartOptions: {
|
719
|
+
label: {
|
720
|
+
show_value: true,
|
721
|
+
show_out_of_x_axis: true
|
722
|
+
}
|
723
|
+
}
|
724
|
+
};
|
725
|
+
|
726
|
+
funcContext.y = 250;
|
727
|
+
mockPivotData.getAggregator = jest.fn(() => ({ value: () => 1000 }));
|
728
|
+
|
729
|
+
let fn = highchartsRenderer.defaultDataLabelFormatter(mockPivotData, opts);
|
730
|
+
let result = fn.call(funcContext);
|
731
|
+
|
732
|
+
expect(result).toBe('250');
|
733
|
+
});
|
734
|
+
|
735
|
+
it('should return raw value when show_out_of_data_series is true but percentage logic is not triggered', () => {
|
736
|
+
opts = {
|
737
|
+
chartOptions: {
|
738
|
+
label: {
|
739
|
+
show_value: true,
|
740
|
+
show_out_of_data_series: true
|
741
|
+
}
|
742
|
+
}
|
743
|
+
};
|
744
|
+
|
745
|
+
funcContext.y = 200;
|
746
|
+
mockPivotData.getAggregator = jest.fn(() => ({ value: () => 800 }));
|
747
|
+
|
748
|
+
let fn = highchartsRenderer.defaultDataLabelFormatter(mockPivotData, opts);
|
749
|
+
let result = fn.call(funcContext);
|
750
|
+
|
751
|
+
expect(result).toBe('200');
|
752
|
+
});
|
753
|
+
|
754
|
+
it('should return raw value when both percentage options are enabled but percentage logic is not triggered', () => {
|
755
|
+
opts = {
|
756
|
+
chartOptions: {
|
757
|
+
label: {
|
758
|
+
show_value: true,
|
759
|
+
show_out_of_x_axis: true,
|
760
|
+
show_out_of_data_series: true
|
761
|
+
}
|
762
|
+
}
|
763
|
+
};
|
764
|
+
|
765
|
+
funcContext.y = 250;
|
766
|
+
let callCount = 0;
|
767
|
+
mockPivotData.getAggregator = jest.fn(() => {
|
768
|
+
callCount++;
|
769
|
+
return { value: () => callCount === 1 ? 1000 : 800 };
|
770
|
+
});
|
771
|
+
|
772
|
+
let fn = highchartsRenderer.defaultDataLabelFormatter(mockPivotData, opts);
|
773
|
+
let result = fn.call(funcContext);
|
774
|
+
|
775
|
+
expect(result).toBe('250');
|
776
|
+
});
|
777
|
+
|
778
|
+
it('should show only percentages without value when show_value is false but percentages are enabled', () => {
|
779
|
+
opts = {
|
780
|
+
chartOptions: {
|
781
|
+
label: {
|
782
|
+
show_value: false,
|
783
|
+
show_out_of_x_axis: true
|
784
|
+
}
|
785
|
+
}
|
786
|
+
};
|
787
|
+
|
788
|
+
funcContext.y = 250;
|
789
|
+
mockPivotData.getAggregator = jest.fn(() => ({ value: () => 1000 }));
|
790
|
+
|
791
|
+
let fn = highchartsRenderer.defaultDataLabelFormatter(mockPivotData, opts);
|
792
|
+
let result = fn.call(funcContext);
|
793
|
+
|
794
|
+
expect(result).toBe('(25%)');
|
795
|
+
});
|
796
|
+
|
797
|
+
it('should not add percentage when value is falsy', () => {
|
798
|
+
opts = {
|
799
|
+
chartOptions: {
|
800
|
+
label: {
|
801
|
+
show_value: true,
|
802
|
+
show_out_of_x_axis: true
|
803
|
+
}
|
804
|
+
}
|
805
|
+
};
|
806
|
+
|
807
|
+
funcContext.y = 0;
|
808
|
+
mockPivotData.getAggregator = jest.fn(() => ({ value: () => 1000 }));
|
809
|
+
|
810
|
+
let fn = highchartsRenderer.defaultDataLabelFormatter(mockPivotData, opts);
|
811
|
+
let result = fn.call(funcContext);
|
812
|
+
|
813
|
+
expect(result).toBe('0');
|
814
|
+
});
|
815
|
+
|
816
|
+
it('should not add percentage when axisTotal is falsy', () => {
|
817
|
+
opts = {
|
818
|
+
chartOptions: {
|
819
|
+
label: {
|
820
|
+
show_value: true,
|
821
|
+
show_out_of_x_axis: true
|
822
|
+
}
|
823
|
+
}
|
824
|
+
};
|
825
|
+
|
826
|
+
funcContext.y = 250;
|
827
|
+
mockPivotData.getAggregator = jest.fn(() => ({ value: () => 0 }));
|
828
|
+
|
829
|
+
let fn = highchartsRenderer.defaultDataLabelFormatter(mockPivotData, opts);
|
830
|
+
let result = fn.call(funcContext);
|
831
|
+
|
832
|
+
expect(result).toBe('250');
|
833
|
+
});
|
834
|
+
});
|
835
|
+
|
836
|
+
describe('Object column handling', () => {
|
837
|
+
it('should extract name property from object columns', () => {
|
838
|
+
highchartsRenderer.getColsInFormatterContext.and.returnValue({ name: 'ObjectColumn' });
|
839
|
+
|
840
|
+
opts = { chartOptions: { label: { show_value: true } } };
|
841
|
+
let fn = highchartsRenderer.defaultDataLabelFormatter(mockPivotData, opts);
|
842
|
+
let result = fn.call(funcContext);
|
843
|
+
|
844
|
+
expect(result).toBe('12,345.678');
|
845
|
+
});
|
846
|
+
});
|
847
|
+
|
848
|
+
describe('Column initialization handling', () => {
|
849
|
+
it('should initialize cols to empty array when cols is falsy after array check', () => {
|
850
|
+
spyOn(lodash, 'isArray').and.returnValue(true);
|
851
|
+
highchartsRenderer.getColsInFormatterContext.and.returnValue(null);
|
852
|
+
|
853
|
+
opts = { chartOptions: { label: { show_value: true } } };
|
854
|
+
let fn = highchartsRenderer.defaultDataLabelFormatter(mockPivotData, opts);
|
855
|
+
let result = fn.call(funcContext);
|
856
|
+
|
857
|
+
expect(result).toBe('12,345.678');
|
858
|
+
expect(lodash.isArray).toHaveBeenCalledWith(null);
|
859
|
+
});
|
860
|
+
});
|
861
|
+
|
862
|
+
describe('Waterfall breakdown handling', () => {
|
863
|
+
beforeEach(() => {
|
864
|
+
funcContext.series.options.className = 'waterfallBreakdown';
|
865
|
+
});
|
866
|
+
|
867
|
+
it('should transform rows and cols for waterfall breakdown', () => {
|
868
|
+
opts = { chartOptions: { label: { show_value: true } } };
|
869
|
+
|
870
|
+
let fn = highchartsRenderer.defaultDataLabelFormatter(mockPivotData, opts);
|
871
|
+
let result = fn.call(funcContext);
|
872
|
+
|
873
|
+
expect(highchartsRenderer.transformRowsAndColsForBreakdown).toHaveBeenCalled();
|
874
|
+
expect(result).toBe('12,345.678');
|
875
|
+
});
|
876
|
+
|
877
|
+
it('should return raw value for waterfall breakdown when show_out_of_data_series is true but percentage logic is not triggered', () => {
|
878
|
+
opts = {
|
879
|
+
chartOptions: {
|
880
|
+
label: {
|
881
|
+
show_value: true,
|
882
|
+
show_out_of_data_series: true
|
883
|
+
}
|
884
|
+
}
|
885
|
+
};
|
886
|
+
|
887
|
+
funcContext.y = 300;
|
888
|
+
mockPivotData.getRowKeys = jest.fn(() => ([['row1'], ['row2']]));
|
889
|
+
|
890
|
+
let callCount = 0;
|
891
|
+
mockPivotData.getAggregator = jest.fn((rows, cols) => {
|
892
|
+
if (rows.length === 1) return { value: () => 400 };
|
893
|
+
if (rows.length === 0 && cols.length > 0) return { value: () => 1200 };
|
894
|
+
return { value: () => 800 };
|
895
|
+
});
|
896
|
+
|
897
|
+
let fn = highchartsRenderer.defaultDataLabelFormatter(mockPivotData, opts);
|
898
|
+
let result = fn.call(funcContext);
|
899
|
+
|
900
|
+
expect(result).toBe('300');
|
901
|
+
});
|
902
|
+
|
903
|
+
it('should calculate percentage using dataSeriesTotal when axisTotal is falsy (waterfall breakdown)', () => {
|
904
|
+
opts = {
|
905
|
+
chartOptions: {
|
906
|
+
label: {
|
907
|
+
show_value: false,
|
908
|
+
show_out_of_data_series: true
|
909
|
+
}
|
910
|
+
}
|
911
|
+
};
|
912
|
+
|
913
|
+
funcContext.y = 200; // value = 200
|
914
|
+
mockPivotData.getRowKeys = jest.fn(() => ([['row1'], ['row2']]));
|
915
|
+
|
916
|
+
let callCount = 0;
|
917
|
+
mockPivotData.getAggregator = jest.fn((rows, cols) => {
|
918
|
+
callCount++;
|
919
|
+
|
920
|
+
if (rows.length === 1) {
|
921
|
+
return { value: () => 400 };
|
922
|
+
}
|
923
|
+
if (rows.length === 0 && cols.length > 0) {
|
924
|
+
return { value: () => 0 };
|
925
|
+
}
|
926
|
+
|
927
|
+
return { value: () => 200 };
|
928
|
+
});
|
929
|
+
|
930
|
+
let fn = highchartsRenderer.defaultDataLabelFormatter(mockPivotData, opts);
|
931
|
+
let result = fn.call(funcContext);
|
932
|
+
|
933
|
+
expect(result).toBe('(25%)');
|
934
|
+
});
|
935
|
+
|
936
|
+
it('should not add percentage when dataSeriesTotal is falsy (non-waterfall breakdown)', () => {
|
937
|
+
funcContext.series.options.className = 'regularSeries';
|
938
|
+
|
939
|
+
opts = {
|
940
|
+
chartOptions: {
|
941
|
+
label: {
|
942
|
+
show_value: false,
|
943
|
+
show_out_of_data_series: true
|
944
|
+
}
|
945
|
+
}
|
946
|
+
};
|
947
|
+
|
948
|
+
funcContext.y = 200;
|
949
|
+
|
950
|
+
mockPivotData.getAggregator = jest.fn((rows, cols) => {
|
951
|
+
if (cols.length === 0) {
|
952
|
+
return { value: () => 0 };
|
953
|
+
}
|
954
|
+
return { value: () => 200 };
|
955
|
+
});
|
956
|
+
|
957
|
+
let fn = highchartsRenderer.defaultDataLabelFormatter(mockPivotData, opts);
|
958
|
+
let result = fn.call(funcContext);
|
959
|
+
|
960
|
+
expect(result).toBe('');
|
961
|
+
});
|
962
|
+
});
|
963
|
+
|
964
|
+
describe('Error handling', () => {
|
965
|
+
it('should fallback to basic formatting when aggregator throws error', () => {
|
966
|
+
mockPivotData.getAggregator = jest.fn(() => { throw new Error('Test error'); });
|
967
|
+
|
968
|
+
opts = { chartOptions: { label: { show_value: true } } };
|
969
|
+
let fn = highchartsRenderer.defaultDataLabelFormatter(mockPivotData, opts);
|
970
|
+
let result = fn.call(funcContext);
|
971
|
+
|
972
|
+
expect(result).toBe('12,345.678');
|
973
|
+
});
|
974
|
+
|
975
|
+
it('should handle null columns gracefully', () => {
|
976
|
+
highchartsRenderer.getColsInFormatterContext.and.returnValue(null);
|
977
|
+
|
978
|
+
opts = { chartOptions: { label: { show_value: true } } };
|
979
|
+
let fn = highchartsRenderer.defaultDataLabelFormatter(mockPivotData, opts);
|
980
|
+
let result = fn.call(funcContext);
|
981
|
+
|
982
|
+
expect(result).toBe('12,345.678');
|
983
|
+
});
|
984
|
+
|
985
|
+
it('should handle empty options gracefully for drill-down pie', () => {
|
986
|
+
let fn = highchartsRenderer.defaultDataLabelFormatter(mockPivotData, {}, true);
|
987
|
+
let result = fn.call(funcContext);
|
988
|
+
|
989
|
+
expect(result).toBe('12,345.678');
|
990
|
+
});
|
991
|
+
});
|
992
|
+
|
993
|
+
describe('Unit abbreviation options (fallback behavior)', () => {
|
994
|
+
it('should fallback to raw value formatting when useUnitAbbreviation is false and getFormattedNumber returns abbreviated value', () => {
|
995
|
+
opts = {
|
996
|
+
chartOptions: {
|
997
|
+
label: {
|
998
|
+
show_value: true,
|
999
|
+
useUnitAbbreviation: false
|
1000
|
+
}
|
1001
|
+
}
|
1002
|
+
};
|
1003
|
+
|
1004
|
+
jest.spyOn(global.$.pivotUtilities, 'getFormattedNumber').mockReturnValue('12.5K');
|
1005
|
+
|
1006
|
+
let fn = highchartsRenderer.defaultDataLabelFormatter(mockPivotData, opts);
|
1007
|
+
let result = fn.call(funcContext);
|
1008
|
+
|
1009
|
+
expect(result).toBe('12,345.678');
|
1010
|
+
});
|
1011
|
+
|
1012
|
+
it('should fallback to raw value formatting when useUnitAbbreviation is true and getFormattedNumber returns abbreviated value', () => {
|
1013
|
+
opts = {
|
1014
|
+
chartOptions: {
|
1015
|
+
label: {
|
1016
|
+
show_value: true,
|
1017
|
+
useUnitAbbreviation: true
|
1018
|
+
}
|
1019
|
+
}
|
1020
|
+
};
|
1021
|
+
|
1022
|
+
jest.spyOn(global.$.pivotUtilities, 'getFormattedNumber').mockReturnValue('12.5K');
|
1023
|
+
|
1024
|
+
let fn = highchartsRenderer.defaultDataLabelFormatter(mockPivotData, opts);
|
1025
|
+
let result = fn.call(funcContext);
|
1026
|
+
|
1027
|
+
expect(result).toBe('12,345.678');
|
1028
|
+
});
|
1029
|
+
|
1030
|
+
it('should fallback to raw value formatting when getFormattedNumber returns M-abbreviated value regardless of useUnitAbbreviation setting', () => {
|
1031
|
+
opts = {
|
1032
|
+
chartOptions: {
|
1033
|
+
label: {
|
1034
|
+
show_value: true,
|
1035
|
+
useUnitAbbreviation: false
|
1036
|
+
}
|
1037
|
+
}
|
1038
|
+
};
|
1039
|
+
|
1040
|
+
jest.spyOn(global.$.pivotUtilities, 'getFormattedNumber').mockReturnValue('1.2M');
|
1041
|
+
|
1042
|
+
let fn = highchartsRenderer.defaultDataLabelFormatter(mockPivotData, opts);
|
1043
|
+
let result = fn.call(funcContext);
|
1044
|
+
|
1045
|
+
expect(result).toBe('12,345.678');
|
1046
|
+
});
|
1047
|
+
});
|
1048
|
+
|
1049
|
+
describe('Others name handling', () => {
|
1050
|
+
it('should handle others name replacement', () => {
|
1051
|
+
opts = {
|
1052
|
+
total_value_options: { some: 'option' },
|
1053
|
+
chartOptions: { label: { show_value: true } }
|
1054
|
+
};
|
1055
|
+
|
1056
|
+
highchartsRenderer.getOthersName.and.returnValue('CustomOthers');
|
1057
|
+
highchartsRenderer.getDrOthersInAxisState.and.returnValue({ cols: true });
|
1058
|
+
|
1059
|
+
let fn = highchartsRenderer.defaultDataLabelFormatter(mockPivotData, opts);
|
1060
|
+
let result = fn.call(funcContext);
|
1061
|
+
|
1062
|
+
expect(highchartsRenderer.getOthersName).toHaveBeenCalledWith(opts);
|
1063
|
+
expect(highchartsRenderer.getDrOthersInAxisState).toHaveBeenCalledWith(mockPivotData, 'CustomOthers');
|
1064
|
+
expect(highchartsRenderer.replaceDrOthersKeys).toHaveBeenCalled();
|
1065
|
+
expect(result).toBe('12,345.678');
|
1066
|
+
});
|
527
1067
|
});
|
528
1068
|
});
|
529
1069
|
|
@@ -7657,7 +8197,7 @@ describe('highcharts_renderer', () => {
|
|
7657
8197
|
const noDataFnSpy = jest.spyOn(highchartsRenderer, 'getNoDataResult').mockImplementation(() => {});
|
7658
8198
|
|
7659
8199
|
highchartsRenderer.ptCreateElementAndDraw(chartOptions, options);
|
7660
|
-
|
8200
|
+
|
7661
8201
|
expect(noDataFnSpy).toHaveBeenCalled();
|
7662
8202
|
expect(options.error_has_occurred).toBeTruthy();
|
7663
8203
|
expect(options.error_params).toBe(highchartsRenderer.widgetPlaceholders.nodata);
|