@datarailsshared/dr_renderer 1.2.437 → 1.2.439

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.437",
3
+ "version": "1.2.439",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -396,13 +396,10 @@ let initDRPivotTable = function($, window, document) {
396
396
  switch (opts.chartOptions.negative_numbers.value) {
397
397
  case 'red_minus':
398
398
  return '<span style="color: red; fill: red;">' + aggregator.format(val, format_argument) + '</span>';
399
- break;
400
399
  case 'absolute':
401
400
  return '(' + aggregator.format(Math.abs(val), format_argument) + ')';
402
- break;
403
401
  case 'red_absolute':
404
402
  return '<span style="color: red; fill: red;">(' + aggregator.format(Math.abs(val), format_argument) + ')</span>';
405
- break;
406
403
  default:
407
404
  return aggregator.format(val, format_argument);
408
405
  }
@@ -407,6 +407,20 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
407
407
  ].includes(type);
408
408
  };
409
409
 
410
+ /**
411
+ * @param {String} value
412
+ * @param {{ useUnitAbbreviation: boolean } labelOptions
413
+ * @returns {String}
414
+ */
415
+ const removeNumberFormatValueUnitSign = (value, labelOptions) => {
416
+ const removeUnitAbbreviation = labelOptions && !lodash.isNil(labelOptions.useUnitAbbreviation) && !labelOptions.useUnitAbbreviation;
417
+ if (!removeUnitAbbreviation || !value || typeof value !== 'string') {
418
+ return value;
419
+ }
420
+ const unitsAbbr = /[KM]/gi;
421
+ return value.replace(unitsAbbr, '');
422
+ }
423
+
410
424
  highchartsRenderer.filterFloat = function (value) {
411
425
  if (/^(\-|\+)?([0-9]+(\.[0-9]+)?|Infinity)$/.test(value))
412
426
  return Number(value);
@@ -542,19 +556,22 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
542
556
 
543
557
  //TODO No totals formatts
544
558
  highchartsRenderer.defaultValueLabelsFormatter = function (pivotData, opts) {
545
- var func = function () {
546
- var value = parseFloat(this.value);
547
- if (pivotData) {
548
- try {
549
- var aggr = pivotData.getAggregator([], []);
550
- return $.pivotUtilities.getFormattedNumber(value, aggr, opts, true);
551
- } catch (err) {
552
- // do nothing
553
- }
554
- }
555
- return $.pivotUtilities.getFormattedNumber(value, null, opts);
559
+ const labelOptions = lodash.get(opts.chartOptions, 'label') || lodash.get(opts.chartOptions, 'label_pie');
560
+
561
+ return function () {
562
+ const value = parseFloat(this.value);
563
+ try {
564
+ const aggr = pivotData ? pivotData.getAggregator([], []) : null;
565
+ let formattedValue = $.pivotUtilities.getFormattedNumber(value, aggr, opts, !!aggr);
566
+ formattedValue = removeNumberFormatValueUnitSign(formattedValue, labelOptions);
567
+ return formattedValue;
568
+ } catch (err) {
569
+ // do nothing
570
+ }
571
+ let formattedValue = $.pivotUtilities.getFormattedNumber(value, null, opts);
572
+ formattedValue = removeNumberFormatValueUnitSign(formattedValue, labelOptions);
573
+ return formattedValue;
556
574
  };
557
- return func;
558
575
  };
559
576
 
560
577
  highchartsRenderer.persantageValueLabelsFormatter = function (pivotData, opts) {
@@ -701,14 +718,17 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
701
718
 
702
719
  var aggr = pivotData.getAggregator(rows, cols);
703
720
 
704
- const formattedValue = is_drill_down_pie || labelOptions.show_value ? $.pivotUtilities.getFormattedNumber(value, aggr, opts, true) : '';
721
+ let formattedValue = is_drill_down_pie || labelOptions.show_value ? $.pivotUtilities.getFormattedNumber(value, aggr, opts, true) : '';
722
+ formattedValue = removeNumberFormatValueUnitSign(formattedValue, labelOptions);
705
723
  return String(formattedValue) + percentageWrapper;
706
724
 
707
725
  } catch (err) {
708
726
  // do nothing
709
727
  }
710
728
  }
711
- return $.pivotUtilities.getFormattedNumber(value, null, opts).replace(/\u00A0/g, " ");
729
+ let formattedValue = $.pivotUtilities.getFormattedNumber(value, null, opts).replace(/\u00A0/g, " ");
730
+ formattedValue = removeNumberFormatValueUnitSign(formattedValue, labelOptions);
731
+ return formattedValue;
712
732
  };
713
733
  return func;
714
734
  };
@@ -4963,9 +4983,14 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4963
4983
  //subopts.rendererOptions = { tableOptions: { showTotals: false } };
4964
4984
  }
4965
4985
 
4966
- if (is_graph)
4986
+ if (is_graph) {
4967
4987
  subopts.renderer = pivotOptions.chartRender;
4968
- else {
4988
+ const chartOptions = subopts.rendererOptions.chartOptions;
4989
+ const labelOptions = lodash.get(chartOptions, 'label_pie', lodash.get(chartOptions, 'label'));
4990
+ if (labelOptions) {
4991
+ labelOptions.useUnitAbbreviation = subopts.rendererOptions.useUnitAbbreviation;
4992
+ }
4993
+ } else {
4969
4994
  var functionToReturn = function (pivotData, opt) {
4970
4995
  opt.widgetId = widget.id;
4971
4996
  return $.pivotUtilities.subtotal_renderers(pivotData, opt, widget.chart_type);