@sis-cc/dotstatsuite-components 20.4.0 → 20.6.0

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright © OECD 2019-2024
3
+ Copyright © OECD 2019-2025
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -27,7 +27,10 @@ var hierarchiseDimensionWithNativeHierarchy = exports.hierarchiseDimensionWithNa
27
27
  return R.reduce(function (acc, child) {
28
28
  index = index + 1;
29
29
  var refined = R.pipe(R.assoc('__indexPosition', index), R.assoc('parents', parentsIndexes), R.assoc('parent', R.isEmpty(parentsIndexes) ? undefined : parentId))(child);
30
- var children = getChildren({ parentsIndexes: R.append(index, parentsIndexes), parentId: child.id });
30
+ var children = getChildren({
31
+ parentsIndexes: R.propOr(false, 'isSelected', child) ? R.append(index, parentsIndexes) : parentsIndexes,
32
+ parentId: child.id
33
+ });
31
34
  return R.concat(acc, R.prepend(refined, children));
32
35
  }, [], childs);
33
36
  };
@@ -33,7 +33,7 @@ var getValueData = function getValueData(index, dimension, parentsIndexes) {
33
33
  var missingParents = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
34
34
  return {
35
35
  dimension: R.pick(['id', 'name', '__index'], dimension),
36
- value: (0, _extends3.default)({}, R.pipe(R.pathOr({}, ['values', index]), R.pick(['id', 'name', 'isNonCoded', 'flags', 'hasAdvancedAttributes']))(dimension), {
36
+ value: (0, _extends3.default)({}, R.pipe(R.pathOr({}, ['values', index]), R.pick(['id', 'name', 'isNonCoded', 'flags', 'hasAdvancedAttributes', 'display']))(dimension), {
37
37
  parents: parentsIndexes,
38
38
  missingParents: missingParents
39
39
  })
@@ -39,49 +39,61 @@ var registerParsedIndexes = function registerParsedIndexes(_ref, register) {
39
39
  return (0, _extends3.default)({}, merged, { isSameSerie: isSameSerie });
40
40
  };
41
41
 
42
- var parseSerieIndexesHierarchies = function parseSerieIndexesHierarchies(serieIndexes, previousSerie, dimensions) {
43
- var defaultIsSameSerie = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
42
+ var parseParentsIndexesWithPrevious = function parseParentsIndexesWithPrevious(parentsIndexes, previousParentsIndexes) {
43
+ var previousParentsSet = new _set2.default(previousParentsIndexes);
44
+ var lastParentIndexInPrevious = R.findLastIndex(function (i) {
45
+ return previousParentsSet.has(i);
46
+ }, parentsIndexes);
47
+
48
+ var _ref2 = lastParentIndexInPrevious !== -1 ? R.splitAt(lastParentIndexInPrevious + 1, parentsIndexes) : [[], parentsIndexes],
49
+ _ref3 = (0, _slicedToArray3.default)(_ref2, 2),
50
+ rawPresentParentsIndexes = _ref3[0],
51
+ missingParentsIndexes = _ref3[1];
52
+
53
+ var presentParentsIndexes = R.filter(function (i) {
54
+ return previousParentsSet.has(i);
55
+ }, rawPresentParentsIndexes);
56
+ return { presentParentsIndexes: presentParentsIndexes, missingParentsIndexes: missingParentsIndexes };
57
+ };
44
58
 
59
+ var parseSerieIndexesHierarchies = function parseSerieIndexesHierarchies(serieIndexes, previousSerie, dimensions, isSameSerie, replicate) {
45
60
  return R.addIndex(R.reduce)(function (acc, _valueIndex, dimensionIndex) {
46
61
  if (R.is(Array, _valueIndex)) {
47
62
  var previous = R.isEmpty(previousSerie) ? {} : R.map(R.nth(dimensionIndex), previousSerie);
48
- var parsed = parseSerieIndexesHierarchies(_valueIndex, previous, R.pathOr([], [dimensionIndex, 'dimensions'], dimensions), acc.isSameSerie);
63
+ var parsed = parseSerieIndexesHierarchies(_valueIndex, previous, R.pathOr([], [dimensionIndex, 'dimensions'], dimensions), acc.isSameSerie, replicate);
49
64
  return registerParsedIndexes(parsed, acc);
50
65
  }
51
66
  var valueIndex = Math.abs(_valueIndex);
52
67
  var parents = R.pathOr([], [dimensionIndex, 'values', valueIndex, 'parents'], dimensions);
53
- var previousIndex = acc.isSameSerie ? R.pipe(R.path(['indexes', dimensionIndex]), function (i) {
68
+ var previousIndex = R.pipe(R.path(['indexes', dimensionIndex]), function (i) {
54
69
  return R.isNil(i) ? -1 : Math.abs(i);
55
- })(previousSerie) : -1;
56
- var previousRegisteredIndexes = acc.isSameSerie ? R.pathOr(new _set2.default(), ['registeredIndexes', dimensionIndex], previousSerie) : new _set2.default();
57
- var registeredIndexes = new _set2.default(previousRegisteredIndexes);
58
-
59
- var _R$reduce = R.reduce(function (_acc, i) {
60
- if (previousRegisteredIndexes.has(i)) {
61
- return R.over(R.lensProp('presentParentsIndexes'), function (p) {
62
- return R.isNil(p) ? [i] : R.append(i, p);
63
- }, _acc);
64
- } else if (i > previousIndex) {
65
- registeredIndexes.add(i);
66
- return R.over(R.lensProp('missingParentsIndexes'), function (m) {
67
- return R.isNil(m) ? [i] : R.append(i, m);
68
- }, _acc);
69
- }
70
- return _acc;
71
- }, {}, parents),
72
- presentParentsIndexes = _R$reduce.presentParentsIndexes,
73
- missingParentsIndexes = _R$reduce.missingParentsIndexes;
74
-
75
- registeredIndexes.add(valueIndex);
76
- return registerParsedIndexes({ parentsIndexes: presentParentsIndexes, missingIndexes: missingParentsIndexes, registeredIndexes: registeredIndexes, isSameSerie: acc.isSameSerie && valueIndex === previousIndex }, acc);
77
- }, { parentsIndexes: [], missingIndexes: [], registeredIndexes: [], isSameSerie: defaultIsSameSerie }, serieIndexes);
70
+ })(previousSerie);
71
+ var previousParentsIndexes = acc.isSameSerie ? R.pipe(R.pathOr([], ['parentsIndexes', dimensionIndex]), R.append(previousIndex))(previousSerie) : [];
72
+ var previousMissingIndexes = acc.isSameSerie ? R.pathOr([], ['missingIndexes', dimensionIndex], previousSerie) : [];
73
+ /*
74
+ if replicate = true (sections), missing parents insdexes are replicated on each brother nodes not just the first (as empty lines)
75
+ thats why passing previous missing as previous parents in case replicate = false
76
+ */
77
+
78
+ var _parseParentsIndexesW = parseParentsIndexesWithPrevious(parents, replicate ? previousParentsIndexes : R.concat(previousParentsIndexes, previousMissingIndexes)),
79
+ presentParentsIndexes = _parseParentsIndexesW.presentParentsIndexes,
80
+ missingParentsIndexes = _parseParentsIndexesW.missingParentsIndexes;
81
+
82
+ return registerParsedIndexes({
83
+ parentsIndexes: presentParentsIndexes,
84
+ missingIndexes: missingParentsIndexes,
85
+ isSameSerie: acc.isSameSerie && valueIndex === previousIndex
86
+ }, acc);
87
+ }, { parentsIndexes: [], missingIndexes: [], isSameSerie: isSameSerie }, serieIndexes);
78
88
  };
79
89
 
80
90
  var parseSeriesIndexesHierarchies = function parseSeriesIndexesHierarchies(seriesIndexes, dimensions) {
91
+ var replicateMissing = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
92
+
81
93
  return R.reduce(function (acc, serieIndexes) {
82
94
  var previousSerie = R.last(acc) || {};
83
95
 
84
- var _parseSerieIndexesHie = parseSerieIndexesHierarchies(serieIndexes, previousSerie, dimensions),
96
+ var _parseSerieIndexesHie = parseSerieIndexesHierarchies(serieIndexes, previousSerie, dimensions, true, replicateMissing),
85
97
  isSameSerie = _parseSerieIndexesHie.isSameSerie,
86
98
  parsed = (0, _objectWithoutProperties3.default)(_parseSerieIndexesHie, ['isSameSerie']);
87
99
 
@@ -92,15 +104,16 @@ var parseSeriesIndexesHierarchies = function parseSeriesIndexesHierarchies(serie
92
104
  exports.parseSeriesIndexesHierarchies = parseSeriesIndexesHierarchies;
93
105
  var parseLayoutIndexesHierarchies = exports.parseLayoutIndexesHierarchies = function parseLayoutIndexesHierarchies(layoutIndexes, layout) {
94
106
  var header = parseSeriesIndexesHierarchies(layoutIndexes.header, layout.header);
95
- var sections = R.pipe(R.transpose, function (_ref2) {
96
- var _ref3 = (0, _slicedToArray3.default)(_ref2, 2),
97
- _sections = _ref3[0],
98
- _sectionsRows = _ref3[1];
107
+ var sections = R.pipe(R.transpose, function (_ref4) {
108
+ var _ref5 = (0, _slicedToArray3.default)(_ref4, 2),
109
+ _sections = _ref5[0],
110
+ _sectionsRows = _ref5[1];
99
111
 
100
112
  if (R.isNil(_sections)) {
101
113
  return [];
102
114
  }
103
- var sections = parseSeriesIndexesHierarchies(_sections, layout.sections);
115
+ // replicate = true on sections
116
+ var sections = parseSeriesIndexesHierarchies(_sections, layout.sections, true);
104
117
  var sectionsRows = R.map(function (rows) {
105
118
  return parseSeriesIndexesHierarchies(rows, layout.rows);
106
119
  }, _sectionsRows);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sis-cc/dotstatsuite-components",
3
3
  "description": "Set components based on React.",
4
- "version": "20.4.0",
4
+ "version": "20.6.0",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",
7
7
  "author": "OECD",
@@ -16,7 +16,11 @@ export const hierarchiseDimensionWithNativeHierarchy = (dimension) => {
16
16
  R.assoc('parents', parentsIndexes),
17
17
  R.assoc('parent', R.isEmpty(parentsIndexes) ? undefined : parentId),
18
18
  )(child);
19
- const children = getChildren({ parentsIndexes: R.append(index, parentsIndexes), parentId: child.id });
19
+ const children = getChildren({
20
+ parentsIndexes: R.propOr(false, 'isSelected', child)
21
+ ? R.append(index, parentsIndexes) : parentsIndexes,
22
+ parentId: child.id
23
+ });
20
24
  return R.concat(acc, R.prepend(refined, children));
21
25
  },
22
26
  [],
@@ -5,7 +5,10 @@ import { getLayoutCoordinatesValidator } from '../utils';
5
5
  const getValueData = (index, dimension, parentsIndexes, missingParents = []) => ({
6
6
  dimension: R.pick(['id', 'name', '__index'], dimension),
7
7
  value: {
8
- ...R.pipe(R.pathOr({}, ['values', index]), R.pick(['id', 'name', 'isNonCoded', 'flags', 'hasAdvancedAttributes']))(dimension),
8
+ ...R.pipe(
9
+ R.pathOr({}, ['values', index]),
10
+ R.pick(['id', 'name', 'isNonCoded', 'flags', 'hasAdvancedAttributes', 'display'])
11
+ )(dimension),
9
12
  parents: parentsIndexes,
10
13
  missingParents
11
14
  }
@@ -5,39 +5,56 @@ const registerParsedIndexes = ({ isSameSerie, ...parsed }, register) => {
5
5
  return ({ ...merged, isSameSerie });
6
6
  };
7
7
 
8
- const parseSerieIndexesHierarchies = (serieIndexes, previousSerie, dimensions, defaultIsSameSerie = true) => {
8
+ const parseParentsIndexesWithPrevious = (parentsIndexes, previousParentsIndexes) => {
9
+ const previousParentsSet = new Set(previousParentsIndexes);
10
+ const lastParentIndexInPrevious = R.findLastIndex(i => previousParentsSet.has(i), parentsIndexes);
11
+ const [rawPresentParentsIndexes, missingParentsIndexes] = lastParentIndexInPrevious !== -1
12
+ ? R.splitAt(lastParentIndexInPrevious + 1, parentsIndexes)
13
+ : [[], parentsIndexes];
14
+ const presentParentsIndexes = R.filter(i => previousParentsSet.has(i), rawPresentParentsIndexes);
15
+ return ({ presentParentsIndexes, missingParentsIndexes });
16
+ };
17
+
18
+ const parseSerieIndexesHierarchies = (serieIndexes, previousSerie, dimensions, isSameSerie, replicate) => {
9
19
  return R.addIndex(R.reduce)((acc, _valueIndex, dimensionIndex) => {
10
20
  if (R.is(Array, _valueIndex)) {
11
21
  const previous = R.isEmpty(previousSerie) ? {} : R.map(R.nth(dimensionIndex), previousSerie);
12
- const parsed = parseSerieIndexesHierarchies(_valueIndex, previous, R.pathOr([], [dimensionIndex, 'dimensions'], dimensions), acc.isSameSerie);
22
+ const parsed = parseSerieIndexesHierarchies(
23
+ _valueIndex,
24
+ previous,
25
+ R.pathOr([], [dimensionIndex, 'dimensions'], dimensions),
26
+ acc.isSameSerie,
27
+ replicate
28
+ );
13
29
  return registerParsedIndexes(parsed, acc);
14
30
  }
15
31
  const valueIndex = Math.abs(_valueIndex);
16
32
  const parents = R.pathOr([], [dimensionIndex, 'values', valueIndex, 'parents'], dimensions);
17
- const previousIndex = acc.isSameSerie
18
- ? R.pipe(R.path(['indexes', dimensionIndex]), i => R.isNil(i) ? -1 : Math.abs(i))(previousSerie)
19
- : -1;
20
- const previousRegisteredIndexes = acc.isSameSerie? R.pathOr(new Set(), ['registeredIndexes', dimensionIndex], previousSerie) : new Set();
21
- const registeredIndexes = new Set(previousRegisteredIndexes);
22
- const { presentParentsIndexes, missingParentsIndexes } = R.reduce((_acc, i) => {
23
- if (previousRegisteredIndexes.has(i)) {
24
- return R.over(R.lensProp('presentParentsIndexes'), p => R.isNil(p) ? [i] : R.append(i, p), _acc);
25
- }
26
- else if (i > previousIndex) {
27
- registeredIndexes.add(i);
28
- return R.over(R.lensProp('missingParentsIndexes'), m => R.isNil(m) ? [i] : R.append(i, m), _acc);
29
- }
30
- return _acc;
31
- }, {}, parents);
32
- registeredIndexes.add(valueIndex);
33
- return registerParsedIndexes({ parentsIndexes: presentParentsIndexes, missingIndexes: missingParentsIndexes, registeredIndexes, isSameSerie: acc.isSameSerie && valueIndex === previousIndex }, acc);
34
- }, { parentsIndexes: [], missingIndexes: [], registeredIndexes: [], isSameSerie: defaultIsSameSerie }, serieIndexes);
33
+ const previousIndex = R.pipe(R.path(['indexes', dimensionIndex]), i => R.isNil(i) ? -1 : Math.abs(i))(previousSerie)
34
+ const previousParentsIndexes = acc.isSameSerie
35
+ ? R.pipe(R.pathOr([], ['parentsIndexes', dimensionIndex]), R.append(previousIndex))(previousSerie) : [];
36
+ const previousMissingIndexes = acc.isSameSerie
37
+ ? R.pathOr([], ['missingIndexes', dimensionIndex], previousSerie) : [];
38
+ /*
39
+ if replicate = true (sections), missing parents insdexes are replicated on each brother nodes not just the first (as empty lines)
40
+ thats why passing previous missing as previous parents in case replicate = false
41
+ */
42
+ const { presentParentsIndexes, missingParentsIndexes } = parseParentsIndexesWithPrevious(
43
+ parents,
44
+ replicate ? previousParentsIndexes : R.concat(previousParentsIndexes, previousMissingIndexes),
45
+ );
46
+ return registerParsedIndexes({
47
+ parentsIndexes: presentParentsIndexes,
48
+ missingIndexes: missingParentsIndexes,
49
+ isSameSerie: acc.isSameSerie && valueIndex === previousIndex
50
+ }, acc);
51
+ }, { parentsIndexes: [], missingIndexes: [], isSameSerie }, serieIndexes);
35
52
  };
36
53
 
37
- export const parseSeriesIndexesHierarchies = (seriesIndexes, dimensions) => {
54
+ export const parseSeriesIndexesHierarchies = (seriesIndexes, dimensions, replicateMissing = false) => {
38
55
  return R.reduce((acc, serieIndexes) => {
39
56
  const previousSerie = R.last(acc) || {};
40
- const { isSameSerie, ...parsed } = parseSerieIndexesHierarchies(serieIndexes, previousSerie, dimensions);
57
+ const { isSameSerie, ...parsed } = parseSerieIndexesHierarchies(serieIndexes, previousSerie, dimensions, true, replicateMissing);
41
58
  return R.append(R.assoc('indexes', serieIndexes, parsed), acc);
42
59
  }, [], seriesIndexes);
43
60
  };
@@ -50,7 +67,8 @@ export const parseLayoutIndexesHierarchies = (layoutIndexes, layout) => {
50
67
  if (R.isNil(_sections)) {
51
68
  return [];
52
69
  }
53
- const sections = parseSeriesIndexesHierarchies(_sections, layout.sections);
70
+ // replicate = true on sections
71
+ const sections = parseSeriesIndexesHierarchies(_sections, layout.sections, true);
54
72
  const sectionsRows = R.map(rows => parseSeriesIndexesHierarchies(rows, layout.rows), _sectionsRows);
55
73
  return R.transpose([sections, sectionsRows]);
56
74
  }
@@ -6,24 +6,24 @@ describe('hierarchiseDimensionWithNativeHierarchy tests', () => {
6
6
  const dimension = {
7
7
  id: 'test',
8
8
  values: [
9
- { id: 'FRA', parent: 'EA', __indexPosition: 101 },
10
- { id: 'GER', parent: 'EA', __indexPosition: 100 },
11
- { id: 'EA', parent: 'W', __indexPosition: 30 },
12
- { id: 'A', parent: 'W', __indexPosition: 20 },
13
- { id: 'W', parent: undefined, __indexPosition: 5 },
14
- { id: 'CHI', parent: undefined, __indexPosition: 0 }
9
+ { id: 'FRA', parent: 'EA', __indexPosition: 101, isSelected: true },
10
+ { id: 'GER', parent: 'EA', __indexPosition: 100, isSelected: true },
11
+ { id: 'EA', parent: 'W', __indexPosition: 30, isSelected: true },
12
+ { id: 'A', parent: 'W', __indexPosition: 20, isSelected: true },
13
+ { id: 'W', parent: undefined, __indexPosition: 5, isSelected: true },
14
+ { id: 'CHI', parent: undefined, __indexPosition: 0, isSelected: true }
15
15
  ]
16
16
  };
17
17
 
18
18
  const expected = {
19
19
  id: 'test',
20
20
  values: [
21
- { id: 'CHI', parent: undefined, parents: [], __indexPosition: 0 },
22
- { id: 'W', parent: undefined, parents: [], __indexPosition: 1 },
23
- { id: 'A', parent: 'W', parents: [1], __indexPosition: 2 },
24
- { id: 'EA', parent: 'W', parents: [1], __indexPosition: 3 },
25
- { id: 'GER', parent: 'EA', parents: [1, 3], __indexPosition: 4 },
26
- { id: 'FRA', parent: 'EA', parents: [1, 3], __indexPosition: 5 }
21
+ { id: 'CHI', parent: undefined, parents: [], __indexPosition: 0, isSelected: true },
22
+ { id: 'W', parent: undefined, parents: [], __indexPosition: 1, isSelected: true },
23
+ { id: 'A', parent: 'W', parents: [1], __indexPosition: 2, isSelected: true },
24
+ { id: 'EA', parent: 'W', parents: [1], __indexPosition: 3, isSelected: true },
25
+ { id: 'GER', parent: 'EA', parents: [1, 3], __indexPosition: 4, isSelected: true },
26
+ { id: 'FRA', parent: 'EA', parents: [1, 3], __indexPosition: 5, isSelected: true }
27
27
  ]
28
28
  };
29
29
 
@@ -33,22 +33,22 @@ describe('hierarchiseDimensionWithNativeHierarchy tests', () => {
33
33
  const dimension = {
34
34
  id: 'test',
35
35
  values: [
36
- { id: 'FRA', parent: 'EA', __indexPosition: 101 },
37
- { id: 'GER', parent: 'EA', __indexPosition: 100 },
38
- { id: 'EA', parent: 'W', __indexPosition: 30 },
39
- { id: 'A', parent: 'W', __indexPosition: 20 },
40
- { id: 'CHI', parent: undefined, __indexPosition: 0 }
36
+ { id: 'FRA', parent: 'EA', __indexPosition: 101, isSelected: true },
37
+ { id: 'GER', parent: 'EA', __indexPosition: 100, isSelected: true },
38
+ { id: 'EA', parent: 'W', __indexPosition: 30, isSelected: true },
39
+ { id: 'A', parent: 'W', __indexPosition: 20, isSelected: true },
40
+ { id: 'CHI', parent: undefined, __indexPosition: 0, isSelected: true }
41
41
  ]
42
42
  };
43
43
 
44
44
  const expected = {
45
45
  id: 'test',
46
46
  values: [
47
- { id: 'CHI', parent: undefined, parents: [], __indexPosition: 0 },
48
- { id: 'A', parent: undefined, parents: [], __indexPosition: 1 },
49
- { id: 'EA', parent: undefined, parents: [], __indexPosition: 2 },
50
- { id: 'GER', parent: 'EA', parents: [2], __indexPosition: 3 },
51
- { id: 'FRA', parent: 'EA', parents: [2], __indexPosition: 4 }
47
+ { id: 'CHI', parent: undefined, parents: [], __indexPosition: 0, isSelected: true },
48
+ { id: 'A', parent: undefined, parents: [], __indexPosition: 1, isSelected: true },
49
+ { id: 'EA', parent: undefined, parents: [], __indexPosition: 2, isSelected: true },
50
+ { id: 'GER', parent: 'EA', parents: [2], __indexPosition: 3, isSelected: true },
51
+ { id: 'FRA', parent: 'EA', parents: [2], __indexPosition: 4, isSelected: true }
52
52
  ]
53
53
  };
54
54
 
@@ -58,25 +58,52 @@ describe('hierarchiseDimensionWithNativeHierarchy tests', () => {
58
58
  const dimension = {
59
59
  id: 'test',
60
60
  values: [
61
- { id: '', parent: '', __indexPosition: 101 },
62
- { id: 'GER', parent: 'EA', __indexPosition: 100 },
63
- { id: 'EA', parent: 'W', __indexPosition: 30 },
64
- { id: 'A', parent: 'W', __indexPosition: 20 },
65
- { id: 'CHI', parent: undefined, __indexPosition: 0 }
61
+ { id: '', parent: '', __indexPosition: 101, isSelected: true },
62
+ { id: 'GER', parent: 'EA', __indexPosition: 100, isSelected: true },
63
+ { id: 'EA', parent: 'W', __indexPosition: 30, isSelected: true },
64
+ { id: 'A', parent: 'W', __indexPosition: 20, isSelected: true },
65
+ { id: 'CHI', parent: undefined, __indexPosition: 0, isSelected: true }
66
66
  ]
67
67
  };
68
68
 
69
69
  const expected = {
70
70
  id: 'test',
71
71
  values: [
72
- { id: 'CHI', parent: undefined, parents: [], __indexPosition: 0 },
73
- { id: 'A', parent: undefined, parents: [], __indexPosition: 1 },
74
- { id: 'EA', parent: undefined, parents: [], __indexPosition: 2 },
75
- { id: 'GER', parent: 'EA', parents: [2], __indexPosition: 3 },
76
- { id: '', parent: undefined, parents: [], __indexPosition: 4 }
72
+ { id: 'CHI', parent: undefined, parents: [], __indexPosition: 0, isSelected: true },
73
+ { id: 'A', parent: undefined, parents: [], __indexPosition: 1, isSelected: true },
74
+ { id: 'EA', parent: undefined, parents: [], __indexPosition: 2, isSelected: true },
75
+ { id: 'GER', parent: 'EA', parents: [2], __indexPosition: 3, isSelected: true },
76
+ { id: '', parent: undefined, parents: [], __indexPosition: 4, isSelected: true }
77
77
  ]
78
78
  };
79
79
 
80
80
  expect(hierarchiseDimensionWithNativeHierarchy(dimension)).to.deep.equal(expected);
81
81
  });
82
+ it('non selected parent', () => {
83
+ const dimension = {
84
+ id: 'test',
85
+ values: [
86
+ { id: 'FRA', parent: 'EA', __indexPosition: 101, isSelected: true },
87
+ { id: 'GER', parent: 'EA', __indexPosition: 100, isSelected: true },
88
+ { id: 'EA', parent: 'W', __indexPosition: 30, isSelected: false },
89
+ { id: 'A', parent: 'W', __indexPosition: 20, isSelected: true },
90
+ { id: 'W', parent: undefined, __indexPosition: 5, isSelected: true },
91
+ { id: 'CHI', parent: undefined, __indexPosition: 0, isSelected: true }
92
+ ]
93
+ };
94
+
95
+ const expected = {
96
+ id: 'test',
97
+ values: [
98
+ { id: 'CHI', parent: undefined, parents: [], __indexPosition: 0, isSelected: true },
99
+ { id: 'W', parent: undefined, parents: [], __indexPosition: 1, isSelected: true },
100
+ { id: 'A', parent: 'W', parents: [1], __indexPosition: 2, isSelected: true },
101
+ { id: 'EA', parent: 'W', parents: [1], __indexPosition: 3, isSelected: false },
102
+ { id: 'GER', parent: 'EA', parents: [1], __indexPosition: 4, isSelected: true },
103
+ { id: 'FRA', parent: 'EA', parents: [1], __indexPosition: 5, isSelected: true }
104
+ ]
105
+ };
106
+
107
+ expect(hierarchiseDimensionWithNativeHierarchy(dimension)).to.deep.equal(expected);
108
+ })
82
109
  });
@@ -23,45 +23,323 @@ describe('parseSeriesIndexesHierarchies tests', () => {
23
23
  ];
24
24
 
25
25
  expect(parseSeriesIndexesHierarchies(seriesIndexes, dimensions)).to.deep.equal([
26
- { indexes: [2], parentsIndexes: [[]], missingIndexes: [[]], registeredIndexes: [new Set([2])] },
27
- { indexes: [3], parentsIndexes: [[]], missingIndexes: [[]], registeredIndexes: [new Set([2, 3])] },
28
- { indexes: [4], parentsIndexes: [[]], missingIndexes: [[]], registeredIndexes: [new Set([2, 3, 4])] },
26
+ { indexes: [2], parentsIndexes: [[]], missingIndexes: [[]] },
27
+ { indexes: [3], parentsIndexes: [[]], missingIndexes: [[]] },
28
+ { indexes: [4], parentsIndexes: [[]], missingIndexes: [[]] },
29
29
  ])
30
30
  });
31
- it('with combination', () => {
31
+ it('hierarchical in second dimension, no replicate missing parents', () => {
32
32
  const dimensions = [
33
+ {
34
+ id: 'D0',
35
+ values: [
36
+ { id: 'v0' },
37
+ { id: 'v1' },
38
+ ]
39
+ },
40
+ {
41
+ id: 'D1',
42
+ values: [
43
+ { id: 'v0' },
44
+ { id: 'v1', parents: [0] },
45
+ { id: 'v2', parents: [0, 1] },
46
+ { id: 'v3', parents: [0, 1] },
47
+ { id: 'v4', parents: [0, 1] },
48
+ ]
49
+ },
50
+ ];
51
+
52
+ const seriesIndexes = [
53
+ [0, 0],
54
+ [0, 1],
55
+ [0, 2],
56
+ [0, 3],
57
+ [0, 4],
58
+ [1, 2],
59
+ [1, 3],
60
+ [1, 4],
61
+ ];
62
+
63
+ expect(parseSeriesIndexesHierarchies(seriesIndexes, dimensions)).to.deep.equal([
64
+ { indexes: [0, 0], parentsIndexes: [[], []], missingIndexes: [[], []] },
65
+ { indexes: [0, 1], parentsIndexes: [[], [0]], missingIndexes: [[], []] },
66
+ { indexes: [0, 2], parentsIndexes: [[], [0, 1]], missingIndexes: [[], []] },
67
+ { indexes: [0, 3], parentsIndexes: [[], [0, 1]], missingIndexes: [[], []] },
68
+ { indexes: [0, 4], parentsIndexes: [[], [0, 1]], missingIndexes: [[], []] },
69
+ { indexes: [1, 2], parentsIndexes: [[], []], missingIndexes: [[], [0, 1]] },
70
+ { indexes: [1, 3], parentsIndexes: [[], [0, 1]], missingIndexes: [[], []] },
71
+ { indexes: [1, 4], parentsIndexes: [[], [0, 1]], missingIndexes: [[], []] },
72
+ ])
73
+ });
74
+ it('hierarchical in second dimension, replicate missing parents', () => {
75
+ const dimensions = [
76
+ {
77
+ id: 'D0',
78
+ values: [
79
+ { id: 'v0' },
80
+ { id: 'v1' },
81
+ ]
82
+ },
83
+ {
84
+ id: 'D1',
85
+ values: [
86
+ { id: 'v0' },
87
+ { id: 'v1', parents: [0] },
88
+ { id: 'v2', parents: [0, 1] },
89
+ { id: 'v3', parents: [0, 1] },
90
+ { id: 'v4', parents: [0, 1] },
91
+ ]
92
+ },
93
+ ];
94
+
95
+ const seriesIndexes = [
96
+ [0, 0],
97
+ [0, 1],
98
+ [0, 2],
99
+ [0, 3],
100
+ [0, 4],
101
+ [1, 2],
102
+ [1, 3],
103
+ [1, 4],
104
+ ];
105
+
106
+ expect(parseSeriesIndexesHierarchies(seriesIndexes, dimensions, true)).to.deep.equal([
107
+ { indexes: [0, 0], parentsIndexes: [[], []], missingIndexes: [[], []] },
108
+ { indexes: [0, 1], parentsIndexes: [[], [0]], missingIndexes: [[], []] },
109
+ { indexes: [0, 2], parentsIndexes: [[], [0, 1]], missingIndexes: [[], []] },
110
+ { indexes: [0, 3], parentsIndexes: [[], [0, 1]], missingIndexes: [[], []] },
111
+ { indexes: [0, 4], parentsIndexes: [[], [0, 1]], missingIndexes: [[], []] },
112
+ { indexes: [1, 2], parentsIndexes: [[], []], missingIndexes: [[], [0, 1]] },
113
+ { indexes: [1, 3], parentsIndexes: [[], []], missingIndexes: [[], [0, 1]] },
114
+ { indexes: [1, 4], parentsIndexes: [[], []], missingIndexes: [[], [0, 1]] },
115
+ ])
116
+ });
117
+ it('two hierarchical dimensions, no replicate missing parents', () => {
118
+ const dimensions = [
119
+ {
120
+ id: 'D0',
121
+ values: [
122
+ { id: 'v0' },
123
+ { id: 'v1', parents: [0] },
124
+ { id: 'v2', parents: [0, 1] },
125
+ { id: 'v3', parents: [0, 1] },
126
+ ]
127
+ },
128
+ {
129
+ id: 'D1',
130
+ values: [
131
+ { id: 'v0' },
132
+ { id: 'v1', parents: [0] },
133
+ { id: 'v2', parents: [0, 1] },
134
+ { id: 'v3', parents: [0, 1] },
135
+ ]
136
+ },
137
+ ];
138
+
139
+ const seriesIndexes = [
140
+ [0, 0],
141
+ [0, 1],
142
+ [0, 2],
143
+ [0, 3],
144
+ [2, 2],
145
+ [2, 3],
146
+ [3, 2],
147
+ [3, 3],
148
+ ];
149
+
150
+ expect(parseSeriesIndexesHierarchies(seriesIndexes, dimensions)).to.deep.equal([
151
+ { indexes: [0, 0], parentsIndexes: [[], []], missingIndexes: [[], []] },
152
+ { indexes: [0, 1], parentsIndexes: [[], [0]], missingIndexes: [[], []] },
153
+ { indexes: [0, 2], parentsIndexes: [[], [0, 1]], missingIndexes: [[], []] },
154
+ { indexes: [0, 3], parentsIndexes: [[], [0, 1]], missingIndexes: [[], []] },
155
+ { indexes: [2, 2], parentsIndexes: [[0], []], missingIndexes: [[1], [0, 1]] },
156
+ { indexes: [2, 3], parentsIndexes: [[0, 1], [0, 1]], missingIndexes: [[], []] },
157
+ { indexes: [3, 2], parentsIndexes: [[0, 1], []], missingIndexes: [[], [0, 1]] },
158
+ { indexes: [3, 3], parentsIndexes: [[0, 1], [0, 1]], missingIndexes: [[], []] },
159
+ ])
160
+ });
161
+ it('two hierarchical dimensions, replicate missing parents', () => {
162
+ const dimensions = [
163
+ {
164
+ id: 'D0',
165
+ values: [
166
+ { id: 'v0' },
167
+ { id: 'v1', parents: [0] },
168
+ { id: 'v2', parents: [0, 1] },
169
+ { id: 'v3', parents: [0, 1] },
170
+ ]
171
+ },
172
+ {
173
+ id: 'D1',
174
+ values: [
175
+ { id: 'v0' },
176
+ { id: 'v1', parents: [0] },
177
+ { id: 'v2', parents: [0, 1] },
178
+ { id: 'v3', parents: [0, 1] },
179
+ ]
180
+ },
181
+ ];
182
+
183
+ const seriesIndexes = [
184
+ [0, 0],
185
+ [0, 1],
186
+ [0, 2],
187
+ [0, 3],
188
+ [2, 2],
189
+ [2, 3],
190
+ [3, 2],
191
+ [3, 3],
192
+ ];
193
+
194
+ expect(parseSeriesIndexesHierarchies(seriesIndexes, dimensions, true)).to.deep.equal([
195
+ { indexes: [0, 0], parentsIndexes: [[], []], missingIndexes: [[], []] },
196
+ { indexes: [0, 1], parentsIndexes: [[], [0]], missingIndexes: [[], []] },
197
+ { indexes: [0, 2], parentsIndexes: [[], [0, 1]], missingIndexes: [[], []] },
198
+ { indexes: [0, 3], parentsIndexes: [[], [0, 1]], missingIndexes: [[], []] },
199
+ { indexes: [2, 2], parentsIndexes: [[0], []], missingIndexes: [[1], [0, 1]] },
200
+ { indexes: [2, 3], parentsIndexes: [[0], []], missingIndexes: [[1], [0, 1]] },
201
+ { indexes: [3, 2], parentsIndexes: [[0], []], missingIndexes: [[1], [0, 1]] },
202
+ { indexes: [3, 3], parentsIndexes: [[0], []], missingIndexes: [[1], [0, 1]] },
203
+ ])
204
+ });
205
+ it('two hierarchical dimensions in combination, no replicate missing parents', () => {
206
+ const dimensions = [
207
+ {
208
+ id: 'D0',
209
+ values: [
210
+ { id: 'v0' },
211
+ { id: 'v1', parents: [0] },
212
+ { id: 'v2', parents: [0, 1] },
213
+ ]
214
+ },
33
215
  {
34
216
  id: 'COMB',
35
217
  dimensions: [{
218
+ id: 'D1',
36
219
  values: [
37
220
  { id: 'v0' },
38
- { id: 'v1' },
39
- { id: 'v2' },
40
- { id: 'v3' },
41
- { id: 'v4' },
221
+ { id: 'v1', parents: [0] },
222
+ { id: 'v2', parents: [0, 1] },
223
+ { id: 'v3', parents: [0, 1] },
42
224
  ]
43
- },
44
- {
225
+ },{
226
+ id: 'D2',
45
227
  values: [
46
- { id: 'W', isSelected: true },
47
- { id: 'NA', parents: [0], isSelected: false },
48
- { id: 'A', parents: [0, 1], isSelected: true },
49
- { id: 'USA', parents: [0, 1, 2], isSelected: true },
50
- { id: 'CAN', parents: [0, 1, 2], isSelected: true },
51
- { id: 'MEX', parents: [0, 1, 2], isSelected: true }
228
+ { id: 'v0' },
229
+ { id: 'v1', parents: [0] },
230
+ { id: 'v2', parents: [0, 1] },
231
+ { id: 'v3', parents: [0, 1] },
52
232
  ]
53
233
  }]
54
- },
234
+ }
55
235
  ];
56
236
 
57
237
  const seriesIndexes = [
58
- [[0, 0]],
59
- [[0, 1]],
238
+ [0, [0, 0]],
239
+ [0, [0, 1]],
240
+ [0, [0, 2]],
241
+ [0, [0, 3]],
242
+ [0, [2, 2]],
243
+ [0, [2, 3]],
244
+ [0, [3, 2]],
245
+ [0, [3, 3]],
246
+ [2, [0, 0]],
247
+ [2, [0, 1]],
248
+ [2, [0, 2]],
249
+ [2, [0, 3]],
250
+ [2, [2, 2]],
251
+ [2, [2, 3]],
252
+ [2, [3, 2]],
253
+ [2, [3, 3]],
60
254
  ];
61
255
 
62
256
  expect(parseSeriesIndexesHierarchies(seriesIndexes, dimensions)).to.deep.equal([
63
- { indexes: [[0, 0]], parentsIndexes: [[[], []]], missingIndexes: [[[], []]], registeredIndexes: [[new Set([0]), new Set([0])]] },
64
- { indexes: [[0, 1]], parentsIndexes: [[[], [0]]], missingIndexes: [[[], []]], registeredIndexes: [[new Set([0]), new Set([0, 1])]] },
257
+ { indexes: [0, [0, 0]], parentsIndexes: [[], [[], []]], missingIndexes: [[], [[], []]] },
258
+ { indexes: [0, [0, 1]], parentsIndexes: [[], [[], [0]]], missingIndexes: [[], [[], []]] },
259
+ { indexes: [0, [0, 2]], parentsIndexes: [[], [[], [0, 1]]], missingIndexes: [[], [[], []]] },
260
+ { indexes: [0, [0, 3]], parentsIndexes: [[], [[], [0, 1]]], missingIndexes: [[], [[], []]] },
261
+ { indexes: [0, [2, 2]], parentsIndexes: [[], [[0], []]], missingIndexes: [[], [[1], [0, 1]]] },
262
+ { indexes: [0, [2, 3]], parentsIndexes: [[], [[0, 1], [0, 1]]], missingIndexes: [[], [[], []]] },
263
+ { indexes: [0, [3, 2]], parentsIndexes: [[], [[0, 1], []]], missingIndexes: [[], [[], [0, 1]]] },
264
+ { indexes: [0, [3, 3]], parentsIndexes: [[], [[0, 1], [0, 1]]], missingIndexes: [[], [[], []]] },
265
+ { indexes: [2, [0, 0]], parentsIndexes: [[0], [[], []]], missingIndexes: [[1], [[], []]] },
266
+ { indexes: [2, [0, 1]], parentsIndexes: [[0, 1], [[], [0]]], missingIndexes: [[], [[], []]] },
267
+ { indexes: [2, [0, 2]], parentsIndexes: [[0, 1], [[], [0, 1]]], missingIndexes: [[], [[], []]] },
268
+ { indexes: [2, [0, 3]], parentsIndexes: [[0, 1], [[], [0, 1]]], missingIndexes: [[], [[], []]] },
269
+ { indexes: [2, [2, 2]], parentsIndexes: [[0, 1], [[0], []]], missingIndexes: [[], [[1], [0, 1]]] },
270
+ { indexes: [2, [2, 3]], parentsIndexes: [[0, 1], [[0, 1], [0, 1]]], missingIndexes: [[], [[], []]] },
271
+ { indexes: [2, [3, 2]], parentsIndexes: [[0, 1], [[0, 1], []]], missingIndexes: [[], [[], [0, 1]]] },
272
+ { indexes: [2, [3, 3]], parentsIndexes: [[0, 1], [[0, 1], [0, 1]]], missingIndexes: [[], [[], []]] },
273
+ ])
274
+ });
275
+ it('two hierarchical dimensions in combination, replicate missing parents', () => {
276
+ const dimensions = [
277
+ {
278
+ id: 'D0',
279
+ values: [
280
+ { id: 'v0' },
281
+ { id: 'v1', parents: [0] },
282
+ { id: 'v2', parents: [0, 1] },
283
+ ]
284
+ },
285
+ {
286
+ id: 'COMB',
287
+ dimensions: [{
288
+ id: 'D1',
289
+ values: [
290
+ { id: 'v0' },
291
+ { id: 'v1', parents: [0] },
292
+ { id: 'v2', parents: [0, 1] },
293
+ { id: 'v3', parents: [0, 1] },
294
+ ]
295
+ },{
296
+ id: 'D2',
297
+ values: [
298
+ { id: 'v0' },
299
+ { id: 'v1', parents: [0] },
300
+ { id: 'v2', parents: [0, 1] },
301
+ { id: 'v3', parents: [0, 1] },
302
+ ]
303
+ }]
304
+ }
305
+ ];
306
+
307
+ const seriesIndexes = [
308
+ [0, [0, 0]],
309
+ [0, [0, 1]],
310
+ [0, [0, 2]],
311
+ [0, [0, 3]],
312
+ [0, [2, 2]],
313
+ [0, [2, 3]],
314
+ [0, [3, 2]],
315
+ [0, [3, 3]],
316
+ [2, [0, 0]],
317
+ [2, [0, 1]],
318
+ [2, [0, 2]],
319
+ [2, [0, 3]],
320
+ [2, [2, 2]],
321
+ [2, [2, 3]],
322
+ [2, [3, 2]],
323
+ [2, [3, 3]],
324
+ ];
325
+
326
+ expect(parseSeriesIndexesHierarchies(seriesIndexes, dimensions, true)).to.deep.equal([
327
+ { indexes: [0, [0, 0]], parentsIndexes: [[], [[], []]], missingIndexes: [[], [[], []]] },
328
+ { indexes: [0, [0, 1]], parentsIndexes: [[], [[], [0]]], missingIndexes: [[], [[], []]] },
329
+ { indexes: [0, [0, 2]], parentsIndexes: [[], [[], [0, 1]]], missingIndexes: [[], [[], []]] },
330
+ { indexes: [0, [0, 3]], parentsIndexes: [[], [[], [0, 1]]], missingIndexes: [[], [[], []]] },
331
+ { indexes: [0, [2, 2]], parentsIndexes: [[], [[0], []]], missingIndexes: [[], [[1], [0, 1]]] },
332
+ { indexes: [0, [2, 3]], parentsIndexes: [[], [[0], []]], missingIndexes: [[], [[1], [0, 1]]] },
333
+ { indexes: [0, [3, 2]], parentsIndexes: [[], [[0], []]], missingIndexes: [[], [[1], [0, 1]]] },
334
+ { indexes: [0, [3, 3]], parentsIndexes: [[], [[0], []]], missingIndexes: [[], [[1], [0, 1]]] },
335
+ { indexes: [2, [0, 0]], parentsIndexes: [[0], [[], []]], missingIndexes: [[1], [[], []]] },
336
+ { indexes: [2, [0, 1]], parentsIndexes: [[0], [[], [0]]], missingIndexes: [[1], [[], []]] },
337
+ { indexes: [2, [0, 2]], parentsIndexes: [[0], [[], [0, 1]]], missingIndexes: [[1], [[], []]] },
338
+ { indexes: [2, [0, 3]], parentsIndexes: [[0], [[], [0, 1]]], missingIndexes: [[1], [[], []]] },
339
+ { indexes: [2, [2, 2]], parentsIndexes: [[0], [[0], []]], missingIndexes: [[1], [[1], [0, 1]]] },
340
+ { indexes: [2, [2, 3]], parentsIndexes: [[0], [[0], []]], missingIndexes: [[1], [[1], [0, 1]]] },
341
+ { indexes: [2, [3, 2]], parentsIndexes: [[0], [[0], []]], missingIndexes: [[1], [[1], [0, 1]]] },
342
+ { indexes: [2, [3, 3]], parentsIndexes: [[0], [[0], []]], missingIndexes: [[1], [[1], [0, 1]]] },
65
343
  ])
66
344
  });
67
345
  });