@dhis2/analytics 26.7.1 → 26.7.2

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/README.md CHANGED
@@ -3,23 +3,8 @@
3
3
  **master**
4
4
  [![Test](https://github.com/dhis2/analytics/actions/workflows/node-test.yml/badge.svg)](https://github.com/dhis2/analytics/actions/workflows/node-test.yml) [![DHIS2: Release](https://github.com/dhis2/analytics/actions/workflows/node-publish.yml/badge.svg)](https://github.com/dhis2/analytics/actions/workflows/node-publish.yml)
5
5
 
6
- **21.x**
7
- [![Test](https://github.com/dhis2/analytics/actions/workflows/node-test.yml/badge.svg?branch=21.x)](https://github.com/dhis2/analytics/actions/workflows/node-test.yml) [![DHIS2: Release](https://github.com/dhis2/analytics/actions/workflows/node-publish.yml/badge.svg?branch=21.x)](https://github.com/dhis2/analytics/actions/workflows/node-publish.yml)
8
-
9
- **20.x**
10
- [![Test](https://github.com/dhis2/analytics/actions/workflows/node-test.yml/badge.svg?branch=20.x)](https://github.com/dhis2/analytics/actions/workflows/node-test.yml) [![DHIS2: Release](https://github.com/dhis2/analytics/actions/workflows/node-publish.yml/badge.svg?branch=20.x)](https://github.com/dhis2/analytics/actions/workflows/node-publish.yml)
11
-
12
- **16.x**
13
- [![Test](https://github.com/dhis2/analytics/actions/workflows/node-test.yml/badge.svg?branch=16.x)](https://github.com/dhis2/analytics/actions/workflows/node-test.yml) [![DHIS2: Release](https://github.com/dhis2/analytics/actions/workflows/node-publish.yml/badge.svg?branch=16.x)](https://github.com/dhis2/analytics/actions/workflows/node-publish.yml)
14
-
15
- **11.0.x**
16
- [![Test](https://github.com/dhis2/analytics/actions/workflows/node-test.yml/badge.svg?branch=11.0.x)](https://github.com/dhis2/analytics/actions/workflows/node-test.yml) [![DHIS2: Release](https://github.com/dhis2/analytics/actions/workflows/node-publish.yml/badge.svg?branch=11.0.x)](https://github.com/dhis2/analytics/actions/workflows/node-publish.yml)
17
-
18
- **4.x**
19
- [![Test](https://github.com/dhis2/analytics/actions/workflows/node-test.yml/badge.svg?branch=4.x)](https://github.com/dhis2/analytics/actions/workflows/node-test.yml) [![DHIS2: Release](https://github.com/dhis2/analytics/actions/workflows/node-publish.yml/badge.svg?branch=4.x)](https://github.com/dhis2/analytics/actions/workflows/node-publish.yml)
20
-
21
- **2.4.x**
22
- [![Test](https://github.com/dhis2/analytics/actions/workflows/node-test.yml/badge.svg?branch=2.4.x)](https://github.com/dhis2/analytics/actions/workflows/node-test.yml) [![DHIS2: Release](https://github.com/dhis2/analytics/actions/workflows/node-publish.yml/badge.svg?branch=2.4.x)](https://github.com/dhis2/analytics/actions/workflows/node-publish.yml)
6
+ **24.x**
7
+ [![Test](https://github.com/dhis2/analytics/actions/workflows/node-test.yml/badge.svg?branch=24.x)](https://github.com/dhis2/analytics/actions/workflows/node-test.yml) [![DHIS2: Release](https://github.com/dhis2/analytics/actions/workflows/node-publish.yml/badge.svg?branch=24.x)](https://github.com/dhis2/analytics/actions/workflows/node-publish.yml)
23
8
 
24
9
  ## Overview
25
10
 
@@ -28,6 +13,7 @@ The analytics library contains components and modules that are used in DHIS 2 an
28
13
  - [dhis2/dashboards-app](https://github.com/dhis2/dashboards-app)
29
14
  - [dhis2/data-visualizer-app](https://github.com/dhis2/data-visualizer-app)
30
15
  - [dhis2/maps-app](https://github.com/dhis2/maps-app)
16
+ - [dhis2/line-listing-app](https://github.com/dhis2/line-listing-app)
31
17
 
32
18
  [Module layout documentation](./docs/module-layout.md)
33
19
 
@@ -35,7 +21,7 @@ The analytics library contains components and modules that are used in DHIS 2 an
35
21
 
36
22
  The analytics package is published to npm as @dhis2/analytics.
37
23
 
38
- To publish, simply mark the commit using [semantic release terminology](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines) (see notes below for branch-specific restrictions). Once committed, github actions will take care of publishing the new version to npm.
24
+ To publish, mark the commit using [semantic release terminology](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines) (see notes below for branch-specific restrictions). Once committed, github actions will take care of publishing the new version to npm.
39
25
 
40
26
  ### master branch
41
27
 
@@ -43,7 +29,31 @@ The master branch follows semantic versioning according to spec.
43
29
 
44
30
  ### .x branches
45
31
 
46
- Commits to .x branches (e.g. 16.x) cannot trigger a major version bump, even if it is technically a breaking change. This is because the next version has already been published. Additionally, branches that use .x for the patch version (e.g. 11.0.x, 2.4.x), cannot trigger a minor version bump. In the unlikely case that you need to commit a change that would trigger a version bump that's not possible, you will have to mark it to only trigger a patch or minor bump respectively, then make sure to update the apps that are locked to the .x version of analytics
32
+ Commits to .x branches (e.g. 24.x) cannot trigger a major version bump, even if it is technically a breaking change. This is because the next version has already been published. Additionally, branches that use .x for the patch version (e.g. 11.0.x, 2.4.x), cannot trigger a minor version bump. In the unlikely case that you need to commit a change that would trigger a version bump that's not possible, you will have to mark it to only trigger a patch or minor bump respectively, then make sure to update the apps that are locked to the .x version of analytics
33
+
34
+ ## Publishing pre-release versions during app development
35
+
36
+ Builds for all non-production branches are automatically copied to [d2-ci/analytics](https://github.com/d2-ci/analytics) for use during development and testing, prior to production release.
37
+
38
+ To test changes in a development branch, change the analytics dependency of package.json of the app you are testing with. There are a few options:
39
+
40
+ 1. point to a specific commit:
41
+
42
+ ```
43
+ "dependencies": {
44
+ "@dhis2/analytics": "git+https://github.com/d2-ci/analytics.git#70249ebe8be39051fa10142f850de449e1ec488c",
45
+ ...
46
+ }
47
+ ```
48
+
49
+ 2. point to a branch:
50
+
51
+ ```
52
+ "dependencies": {
53
+ "@dhis2/analytics": "git+https://github.com/d2-ci/analytics.git#chore/some-chore",
54
+ ...
55
+ }
56
+ ```
47
57
 
48
58
  ## Report an issue
49
59
 
@@ -3,12 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.renderValue = void 0;
6
+ exports.separateDigitGroups = exports.renderValue = void 0;
7
7
  var _pivotTableConstants = require("./pivotTable/pivotTableConstants.js");
8
8
  var _valueTypes = require("./valueTypes.js");
9
9
  const trimTrailingZeros = stringValue => stringValue.replace(/\.?0+$/, '');
10
- const decimalSeparator = '.';
11
- const separateDigitGroups = (stringValue, decimalSeparator) => {
10
+ const separateDigitGroups = function (stringValue) {
11
+ let decimalSeparator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '.';
12
12
  const isNegative = stringValue[0] === '-';
13
13
  const [integer, remainder] = stringValue.replace(/^-/, '').split('.');
14
14
  const groups = [];
@@ -26,6 +26,7 @@ const separateDigitGroups = (stringValue, decimalSeparator) => {
26
26
  }
27
27
  return groups;
28
28
  };
29
+ exports.separateDigitGroups = separateDigitGroups;
29
30
  const getSeparator = visualization => {
30
31
  switch (visualization.digitGroupSeparator) {
31
32
  case 'SPACE':
@@ -51,10 +52,10 @@ const renderValue = (value, valueType, visualization) => {
51
52
  }
52
53
  if (visualization.numberType === _pivotTableConstants.NUMBER_TYPE_ROW_PERCENTAGE || visualization.numberType === _pivotTableConstants.NUMBER_TYPE_COLUMN_PERCENTAGE) {
53
54
  const stringValue = trimTrailingZeros(toFixedPrecisionString(value * 100, visualization.skipRounding));
54
- return separateDigitGroups(stringValue, decimalSeparator).join(getSeparator(visualization)) + '%';
55
+ return separateDigitGroups(stringValue).join(getSeparator(visualization)) + '%';
55
56
  } else {
56
57
  const stringValue = toFixedPrecisionString(value, visualization.skipRounding);
57
- return separateDigitGroups(stringValue, decimalSeparator).join(getSeparator(visualization));
58
+ return separateDigitGroups(stringValue).join(getSeparator(visualization));
58
59
  }
59
60
  };
60
61
  exports.renderValue = renderValue;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ var _pie = require("../pie.js");
4
+ describe('formatDataLabel', () => {
5
+ it('should format data label correctly with integers', () => {
6
+ const result = (0, _pie.formatDataLabel)('Test', 1000, 50);
7
+ expect(result).toEqual('<span style="font-weight:normal">Test</span><br/>1 000<span style="font-weight:normal"> (50%)</span>');
8
+ });
9
+ it('should format data label correctly with decimals', () => {
10
+ const result = (0, _pie.formatDataLabel)('Test', 1000.123456789, 50.1234);
11
+ expect(result).toEqual('<span style="font-weight:normal">Test</span><br/>1 000.123456789<span style="font-weight:normal"> (50.1%)</span>');
12
+ });
13
+ it('should handle large numbers correctly', () => {
14
+ const result = (0, _pie.formatDataLabel)('Test', 1000000, 75.5678);
15
+ expect(result).toEqual('<span style="font-weight:normal">Test</span><br/>1 000 000<span style="font-weight:normal"> (75.6%)</span>');
16
+ });
17
+ it('should handle small percentages correctly', () => {
18
+ const result = (0, _pie.formatDataLabel)('Test', 1000.000001, 0.09);
19
+ expect(result).toEqual('<span style="font-weight:normal">Test</span><br/>1 000.000001<span style="font-weight:normal"> (0.1%)</span>');
20
+ });
21
+ it('should handle zero correctly', () => {
22
+ const result = (0, _pie.formatDataLabel)('Test', 0, 0);
23
+ expect(result).toEqual('<span style="font-weight:normal">Test</span><br/>0<span style="font-weight:normal"> (0%)</span>');
24
+ });
25
+ it('should handle negative numbers correctly', () => {
26
+ const result = (0, _pie.formatDataLabel)('Test', -1000, -50);
27
+ expect(result).toEqual('<span style="font-weight:normal">Test</span><br/>-1 000<span style="font-weight:normal"> (-50%)</span>');
28
+ });
29
+ it('should handle empty string as name correctly', () => {
30
+ const result = (0, _pie.formatDataLabel)('', 1000, 50);
31
+ expect(result).toEqual('<span style="font-weight:normal"></span><br/>1 000<span style="font-weight:normal"> (50%)</span>');
32
+ });
33
+ it('should handle undefined as name correctly', () => {
34
+ const result = (0, _pie.formatDataLabel)(undefined, 1000, 50);
35
+ expect(result).toEqual('<span style="font-weight:normal"></span><br/>1 000<span style="font-weight:normal"> (50%)</span>');
36
+ });
37
+ it('should handle special characters in name correctly', () => {
38
+ const result = (0, _pie.formatDataLabel)('Test&Test', 1000, 50);
39
+ expect(result).toEqual('<span style="font-weight:normal">Test&Test</span><br/>1 000<span style="font-weight:normal"> (50%)</span>');
40
+ });
41
+ });
@@ -4,6 +4,16 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = _default;
7
+ exports.formatDataLabel = void 0;
8
+ var _renderValue = require("../../../../../modules/renderValue.js");
9
+ const formatDataLabel = function () {
10
+ let name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
11
+ let y = arguments.length > 1 ? arguments[1] : undefined;
12
+ let percentage = arguments.length > 2 ? arguments[2] : undefined;
13
+ const value = (0, _renderValue.separateDigitGroups)(y.toString()).join(' ');
14
+ return '<span style="font-weight:normal">' + name + '</span><br/>' + value + '<span style="font-weight:normal"> (' + parseFloat(percentage.toFixed(1)) + '%)</span>';
15
+ };
16
+ exports.formatDataLabel = formatDataLabel;
7
17
  function _default(series, colors) {
8
18
  return [{
9
19
  colorByPoint: true,
@@ -14,7 +24,7 @@ function _default(series, colors) {
14
24
  dataLabels: {
15
25
  enabled: true,
16
26
  formatter: function () {
17
- return '<span style="font-weight:normal">' + this.point.name + '</span><br/>' + this.y + '<span style="font-weight:normal"> (' + this.percentage.toFixed(1) + ' %)</span>';
27
+ return formatDataLabel(this.point.name, this.y, this.percentage);
18
28
  }
19
29
  },
20
30
  tooltip: {
@@ -1,8 +1,8 @@
1
1
  import { NUMBER_TYPE_ROW_PERCENTAGE, NUMBER_TYPE_COLUMN_PERCENTAGE } from './pivotTable/pivotTableConstants.js';
2
2
  import { isNumericValueType } from './valueTypes.js';
3
3
  const trimTrailingZeros = stringValue => stringValue.replace(/\.?0+$/, '');
4
- const decimalSeparator = '.';
5
- const separateDigitGroups = (stringValue, decimalSeparator) => {
4
+ export const separateDigitGroups = function (stringValue) {
5
+ let decimalSeparator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '.';
6
6
  const isNegative = stringValue[0] === '-';
7
7
  const [integer, remainder] = stringValue.replace(/^-/, '').split('.');
8
8
  const groups = [];
@@ -45,9 +45,9 @@ export const renderValue = (value, valueType, visualization) => {
45
45
  }
46
46
  if (visualization.numberType === NUMBER_TYPE_ROW_PERCENTAGE || visualization.numberType === NUMBER_TYPE_COLUMN_PERCENTAGE) {
47
47
  const stringValue = trimTrailingZeros(toFixedPrecisionString(value * 100, visualization.skipRounding));
48
- return separateDigitGroups(stringValue, decimalSeparator).join(getSeparator(visualization)) + '%';
48
+ return separateDigitGroups(stringValue).join(getSeparator(visualization)) + '%';
49
49
  } else {
50
50
  const stringValue = toFixedPrecisionString(value, visualization.skipRounding);
51
- return separateDigitGroups(stringValue, decimalSeparator).join(getSeparator(visualization));
51
+ return separateDigitGroups(stringValue).join(getSeparator(visualization));
52
52
  }
53
53
  };
@@ -0,0 +1,39 @@
1
+ import { formatDataLabel } from '../pie.js';
2
+ describe('formatDataLabel', () => {
3
+ it('should format data label correctly with integers', () => {
4
+ const result = formatDataLabel('Test', 1000, 50);
5
+ expect(result).toEqual('<span style="font-weight:normal">Test</span><br/>1 000<span style="font-weight:normal"> (50%)</span>');
6
+ });
7
+ it('should format data label correctly with decimals', () => {
8
+ const result = formatDataLabel('Test', 1000.123456789, 50.1234);
9
+ expect(result).toEqual('<span style="font-weight:normal">Test</span><br/>1 000.123456789<span style="font-weight:normal"> (50.1%)</span>');
10
+ });
11
+ it('should handle large numbers correctly', () => {
12
+ const result = formatDataLabel('Test', 1000000, 75.5678);
13
+ expect(result).toEqual('<span style="font-weight:normal">Test</span><br/>1 000 000<span style="font-weight:normal"> (75.6%)</span>');
14
+ });
15
+ it('should handle small percentages correctly', () => {
16
+ const result = formatDataLabel('Test', 1000.000001, 0.09);
17
+ expect(result).toEqual('<span style="font-weight:normal">Test</span><br/>1 000.000001<span style="font-weight:normal"> (0.1%)</span>');
18
+ });
19
+ it('should handle zero correctly', () => {
20
+ const result = formatDataLabel('Test', 0, 0);
21
+ expect(result).toEqual('<span style="font-weight:normal">Test</span><br/>0<span style="font-weight:normal"> (0%)</span>');
22
+ });
23
+ it('should handle negative numbers correctly', () => {
24
+ const result = formatDataLabel('Test', -1000, -50);
25
+ expect(result).toEqual('<span style="font-weight:normal">Test</span><br/>-1 000<span style="font-weight:normal"> (-50%)</span>');
26
+ });
27
+ it('should handle empty string as name correctly', () => {
28
+ const result = formatDataLabel('', 1000, 50);
29
+ expect(result).toEqual('<span style="font-weight:normal"></span><br/>1 000<span style="font-weight:normal"> (50%)</span>');
30
+ });
31
+ it('should handle undefined as name correctly', () => {
32
+ const result = formatDataLabel(undefined, 1000, 50);
33
+ expect(result).toEqual('<span style="font-weight:normal"></span><br/>1 000<span style="font-weight:normal"> (50%)</span>');
34
+ });
35
+ it('should handle special characters in name correctly', () => {
36
+ const result = formatDataLabel('Test&Test', 1000, 50);
37
+ expect(result).toEqual('<span style="font-weight:normal">Test&Test</span><br/>1 000<span style="font-weight:normal"> (50%)</span>');
38
+ });
39
+ });
@@ -1,3 +1,11 @@
1
+ import { separateDigitGroups } from '../../../../../modules/renderValue.js';
2
+ export const formatDataLabel = function () {
3
+ let name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
4
+ let y = arguments.length > 1 ? arguments[1] : undefined;
5
+ let percentage = arguments.length > 2 ? arguments[2] : undefined;
6
+ const value = separateDigitGroups(y.toString()).join(' ');
7
+ return '<span style="font-weight:normal">' + name + '</span><br/>' + value + '<span style="font-weight:normal"> (' + parseFloat(percentage.toFixed(1)) + '%)</span>';
8
+ };
1
9
  export default function (series, colors) {
2
10
  return [{
3
11
  colorByPoint: true,
@@ -8,7 +16,7 @@ export default function (series, colors) {
8
16
  dataLabels: {
9
17
  enabled: true,
10
18
  formatter: function () {
11
- return '<span style="font-weight:normal">' + this.point.name + '</span><br/>' + this.y + '<span style="font-weight:normal"> (' + this.percentage.toFixed(1) + ' %)</span>';
19
+ return formatDataLabel(this.point.name, this.y, this.percentage);
12
20
  }
13
21
  },
14
22
  tooltip: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhis2/analytics",
3
- "version": "26.7.1",
3
+ "version": "26.7.2",
4
4
  "main": "./build/cjs/index.js",
5
5
  "module": "./build/es/index.js",
6
6
  "exports": {