@sis-cc/dotstatsuite-components 20.3.0 → 20.5.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.
@@ -135,6 +135,37 @@ var getCombinationLevelCompatibility = exports.getCombinationLevelCompatibility
135
135
  return 'blank';
136
136
  };
137
137
 
138
+ var filterLayoutIds = function filterLayoutIds(indexedCombinations, layoutDimsIds, obsAttributes) {
139
+ return function (layoutIds) {
140
+ var layoutConcepts = R.map(R.reduce(function (acc, id) {
141
+ if (R.has(id, indexedCombinations)) {
142
+ return R.concat(acc, R.path([id, 'concepts'], indexedCombinations));
143
+ }
144
+ return R.append(id, acc);
145
+ }, []), layoutIds);
146
+
147
+ return R.mapObjIndexed(function (ids, level) {
148
+ return R.filter(function (id) {
149
+ if (id === 'OBS_ATTRIBUTES') {
150
+ return !R.isEmpty(obsAttributes);
151
+ }
152
+ if (R.has(id, indexedCombinations)) {
153
+ var comb = R.prop(id, indexedCombinations);
154
+ var dims = R.filter(function (i) {
155
+ return layoutDimsIds.has(i);
156
+ }, comb.concepts);
157
+ if (!R.isEmpty(dims)) {
158
+ return true;
159
+ }
160
+ var oppositeIds = level === 'header' ? R.concat(R.prop('sections', layoutConcepts), R.prop('rows', layoutConcepts)) : R.prop('header', layoutConcepts);
161
+ return R.isEmpty(R.intersection(comb.relationship, oppositeIds));
162
+ }
163
+ return layoutDimsIds.has(id);
164
+ }, ids);
165
+ }, layoutIds);
166
+ };
167
+ };
168
+
138
169
  var injectCombinationsInLayout = exports.injectCombinationsInLayout = function injectCombinationsInLayout(combinations, layoutIds) {
139
170
  var defaultLayoutIds = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
140
171
 
@@ -277,6 +308,7 @@ var injectRemainingDimensionsInLayout = exports.injectRemainingDimensionsInLayou
277
308
  var getTableLayoutIds = exports.getTableLayoutIds = function getTableLayoutIds(defaultLayoutIds, currentLayoutIds, dimensions, attributes, combinations) {
278
309
  var layoutDimsIds = getLayoutDimsIds(dimensions);
279
310
  var layoutCombinations = getLayoutCombinations(combinations, layoutDimsIds, attributes);
311
+ var isBlank = R.pipe(R.values, R.all(R.isEmpty))(currentLayoutIds);
280
312
 
281
313
  var combinationsConcepts = R.pipe(R.pluck('_concepts'), R.unnest, function (ids) {
282
314
  return new _set2.default(ids);
@@ -285,12 +317,8 @@ var getTableLayoutIds = exports.getTableLayoutIds = function getTableLayoutIds(d
285
317
  return a.series && R.isEmpty(a.relationship || []) && a.display && !combinationsConcepts.has(a);
286
318
  }, attributes);
287
319
  var indexedCombinations = R.indexBy(R.prop('id'), layoutCombinations);
288
- var filteredLayoutIds = R.map(R.filter(function (id) {
289
- if (id === 'OBS_ATTRIBUTES') {
290
- return !R.isEmpty(obsAttributes);
291
- }
292
- return R.has(id, indexedCombinations) || layoutDimsIds.has(id);
293
- }), currentLayoutIds);
320
+ var filteredLayoutIds = filterLayoutIds(indexedCombinations, layoutDimsIds, obsAttributes)(isBlank ? defaultLayoutIds : currentLayoutIds);
321
+
294
322
  var layoutWithCombs = injectCombinationsInLayout(layoutCombinations, filteredLayoutIds, defaultLayoutIds);
295
323
  var layoutRelationshipsSets = R.map(R.pipe(function (ids) {
296
324
  return R.pick(ids, indexedCombinations);
@@ -316,10 +344,10 @@ var getTableLayoutIds = exports.getTableLayoutIds = function getTableLayoutIds(d
316
344
  if (layoutRelationshipsSets.header.has(dim.id) || defaultLayoutConceptsSets.header.has(dim.id)) {
317
345
  return R.over(R.lensPath(['nextLayout', 'header']), R.append(dim.id))(acc);
318
346
  }
319
- if (layoutRelationshipsSets.sections.has(dim.id) || defaultLayoutConceptsSets.header.has(dim.id)) {
347
+ if (layoutRelationshipsSets.sections.has(dim.id) || defaultLayoutConceptsSets.sections.has(dim.id)) {
320
348
  return R.over(R.lensPath(['nextLayout', 'sections']), R.append(dim.id))(acc);
321
349
  }
322
- if (layoutRelationshipsSets.rows.has(dim.id) || defaultLayoutConceptsSets.header.has(dim.id)) {
350
+ if (layoutRelationshipsSets.rows.has(dim.id) || defaultLayoutConceptsSets.rows.has(dim.id)) {
323
351
  return R.over(R.lensPath(['nextLayout', 'rows']), R.append(dim.id))(acc);
324
352
  }
325
353
  if ((0, _dotstatsuiteSdmxjs.isTimePeriodDimension)(dim)) {
@@ -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.3.0",
4
+ "version": "20.5.0",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",
7
7
  "author": "OECD",
@@ -72,6 +72,39 @@ export const getCombinationLevelCompatibility = (layoutRelationships, combinatio
72
72
  return 'blank';
73
73
  }
74
74
 
75
+ const filterLayoutIds = (indexedCombinations, layoutDimsIds, obsAttributes) => (layoutIds) => {
76
+ const layoutConcepts = R.map(
77
+ R.reduce((acc, id) => {
78
+ if (R.has(id, indexedCombinations)) {
79
+ return R.concat(acc, R.path([id, 'concepts'], indexedCombinations));
80
+ }
81
+ return R.append(id, acc);
82
+ }, []),
83
+ layoutIds
84
+ );
85
+
86
+ return R.mapObjIndexed(
87
+ (ids, level) => R.filter(id => {
88
+ if (id === 'OBS_ATTRIBUTES') {
89
+ return !R.isEmpty(obsAttributes);
90
+ }
91
+ if (R.has(id, indexedCombinations)) {
92
+ const comb = R.prop(id, indexedCombinations);
93
+ const dims = R.filter(i => layoutDimsIds.has(i), comb.concepts);
94
+ if (!R.isEmpty(dims)) {
95
+ return true;
96
+ }
97
+ const oppositeIds = level === 'header'
98
+ ? R.concat(R.prop('sections', layoutConcepts), R.prop('rows', layoutConcepts))
99
+ : R.prop('header', layoutConcepts);
100
+ return R.isEmpty(R.intersection(comb.relationship, oppositeIds));
101
+ }
102
+ return layoutDimsIds.has(id);
103
+ }, ids),
104
+ layoutIds
105
+ );
106
+ };
107
+
75
108
  export const injectCombinationsInLayout = (combinations, layoutIds, defaultLayoutIds = {}) => {
76
109
  const notInLayoutCombs = getCombinationsNotInLayout(combinations, layoutIds);
77
110
  if (R.isEmpty(notInLayoutCombs)) {
@@ -219,21 +252,16 @@ export const getTableLayoutIds = (
219
252
  layoutDimsIds,
220
253
  attributes,
221
254
  );
255
+ const isBlank = R.pipe(R.values, R.all(R.isEmpty))(currentLayoutIds);
222
256
 
223
257
  const combinationsConcepts = R.pipe(R.pluck('_concepts'), R.unnest, ids => new Set(ids))(combinations);
224
258
  const obsAttributes = R.filter(a =>
225
259
  a.series && R.isEmpty(a.relationship || []) && a.display && !combinationsConcepts.has(a)
226
260
  , attributes);
227
261
  const indexedCombinations = R.indexBy(R.prop('id'), layoutCombinations);
228
- const filteredLayoutIds = R.map(
229
- R.filter(id => {
230
- if (id === 'OBS_ATTRIBUTES') {
231
- return !R.isEmpty(obsAttributes);
232
- }
233
- return R.has(id, indexedCombinations) || layoutDimsIds.has(id);
234
- }),
235
- currentLayoutIds
236
- );
262
+ const filteredLayoutIds = filterLayoutIds(indexedCombinations, layoutDimsIds, obsAttributes)
263
+ (isBlank ? defaultLayoutIds : currentLayoutIds);
264
+
237
265
  const layoutWithCombs = injectCombinationsInLayout(layoutCombinations, filteredLayoutIds, defaultLayoutIds);
238
266
  const layoutRelationshipsSets = R.map(R.pipe(
239
267
  ids => R.pick(ids, indexedCombinations),
@@ -267,10 +295,10 @@ export const getTableLayoutIds = (
267
295
  if (layoutRelationshipsSets.header.has(dim.id) || defaultLayoutConceptsSets.header.has(dim.id)) {
268
296
  return R.over(R.lensPath(['nextLayout', 'header']), R.append(dim.id))(acc);
269
297
  }
270
- if (layoutRelationshipsSets.sections.has(dim.id) || defaultLayoutConceptsSets.header.has(dim.id)) {
298
+ if (layoutRelationshipsSets.sections.has(dim.id) || defaultLayoutConceptsSets.sections.has(dim.id)) {
271
299
  return R.over(R.lensPath(['nextLayout', 'sections']), R.append(dim.id))(acc);
272
300
  }
273
- if (layoutRelationshipsSets.rows.has(dim.id) || defaultLayoutConceptsSets.header.has(dim.id)) {
301
+ if (layoutRelationshipsSets.rows.has(dim.id) || defaultLayoutConceptsSets.rows.has(dim.id)) {
274
302
  return R.over(R.lensPath(['nextLayout','rows']), R.append(dim.id))(acc);
275
303
  }
276
304
  if (isTimePeriodDimension(dim)) {
@@ -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
  }
@@ -329,8 +329,14 @@ describe('getTableLayoutIds tests', () => {
329
329
  rows: []
330
330
  };
331
331
 
332
+ const layoutIds3 = {
333
+ header: [],
334
+ sections: ['MEASURE'],
335
+ rows: []
336
+ }
337
+
332
338
  expect(getTableLayoutIds(defaultLayoutIds, layoutIds1, dimensions, attributes, combinations)).to.deep.equal({
333
- header: ['COMB1', 'COMB3', 'REF_AREA'],
339
+ header: ['COMB1', 'REF_AREA', 'COMB3',],
334
340
  sections: ['COMB2'],
335
341
  rows: ['TRANSACTION']
336
342
  });
@@ -340,5 +346,11 @@ describe('getTableLayoutIds tests', () => {
340
346
  sections: ['COMB2'],
341
347
  rows: ['REF_AREA']
342
348
  });
349
+
350
+ expect(getTableLayoutIds(defaultLayoutIds, layoutIds3, dimensions, attributes, combinations)).to.deep.equal({
351
+ header: ['REF_AREA'],
352
+ sections: ['COMB1', 'COMB2', 'COMB3'],
353
+ rows: ['TRANSACTION']
354
+ });
343
355
  });
344
356
  });
@@ -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
  });