@sis-cc/dotstatsuite-components 17.12.6 → 17.13.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.
Files changed (28) hide show
  1. package/lib/rules2/src/{hierarchiseDimensionWithAdvancedHierarchy.js → hierarchiseDimensionWithAdvancedHierarchy2.js} +22 -17
  2. package/lib/rules2/src/{hierarchiseDimensionWithNativeHierarchy.js → hierarchiseDimensionWithNativeHierarchy2.js} +10 -5
  3. package/lib/rules2/src/index.js +21 -12
  4. package/lib/rules2/src/prepareData.js +2 -2
  5. package/lib/rules2/src/refineDimensions.js +3 -6
  6. package/lib/rules2/src/table/getLayoutData2.js +218 -0
  7. package/lib/rules2/src/table/getTableProps.js +6 -9
  8. package/lib/rules2/src/table/parseSeriesIndexesHierarchies.js +96 -0
  9. package/lib/rules2/src/table/{refineLayoutSize.js → refineLayoutSize2.js} +53 -34
  10. package/package.json +1 -1
  11. package/src/rules2/src/{hierarchiseDimensionWithAdvancedHierarchy.js → hierarchiseDimensionWithAdvancedHierarchy2.js} +24 -23
  12. package/src/rules2/src/{hierarchiseDimensionWithNativeHierarchy.js → hierarchiseDimensionWithNativeHierarchy2.js} +31 -28
  13. package/src/rules2/src/index.js +5 -5
  14. package/src/rules2/src/prepareData.js +2 -2
  15. package/src/rules2/src/refineDimensions.js +3 -6
  16. package/src/rules2/src/table/getLayoutData2.js +175 -0
  17. package/src/rules2/src/table/getTableProps.js +8 -4
  18. package/src/rules2/src/table/parseSeriesIndexesHierarchies.js +62 -0
  19. package/src/rules2/src/table/{refineLayoutSize.js → refineLayoutSize2.js} +50 -21
  20. package/test/getLayoutData2.test.js +268 -0
  21. package/test/{hierarchiseDimensionWithAdvancedHierarchy.test.js → hierarchiseDimensionWithAdvancedHierarchy2.test.js} +34 -69
  22. package/test/{hierarchiseDimensionWithNativeHierarchy.test.js → hierarchiseDimensionWithNativeHierarchy2.test.js} +14 -14
  23. package/test/parseSeriesIndexesHierarchies.test.js +104 -0
  24. package/test/{refineLayoutSize.test.js → refineLayoutSize2.test.js} +63 -64
  25. package/test/refinedDimensions.test.js +8 -8
  26. package/lib/rules2/src/table/getLayoutData.js +0 -209
  27. package/src/rules2/src/table/getLayoutData.js +0 -193
  28. package/test/getLayoutData.test.js +0 -284
@@ -5,17 +5,17 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.refineLayoutSize = exports.truncateHeader = exports.truncateSectionRows = exports.refineHeader = exports.refineSections = exports.getCuratedCells = undefined;
7
7
 
8
- var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
8
+ var _slicedToArray2 = require('babel-runtime/helpers/slicedToArray');
9
9
 
10
- var _defineProperty3 = _interopRequireDefault(_defineProperty2);
10
+ var _slicedToArray3 = _interopRequireDefault(_slicedToArray2);
11
11
 
12
- var _extends4 = require('babel-runtime/helpers/extends');
12
+ var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
13
13
 
14
- var _extends5 = _interopRequireDefault(_extends4);
14
+ var _defineProperty3 = _interopRequireDefault(_defineProperty2);
15
15
 
16
- var _slicedToArray2 = require('babel-runtime/helpers/slicedToArray');
16
+ var _extends3 = require('babel-runtime/helpers/extends');
17
17
 
18
- var _slicedToArray3 = _interopRequireDefault(_slicedToArray2);
18
+ var _extends4 = _interopRequireDefault(_extends3);
19
19
 
20
20
  var _ramda = require('ramda');
21
21
 
@@ -62,9 +62,9 @@ var getCuratedCells = exports.getCuratedCells = function getCuratedCells(_ref) {
62
62
 
63
63
  var refineSections = exports.refineSections = function refineSections(sections, extractedKeys, curatedObs) {
64
64
  return R.pipe(R.map(function (section) {
65
- var sectionKey = toKey(R.head(section) || []);
66
- return R.over(R.lensIndex(1), R.filter(function (rowData) {
67
- var rowKey = toKey(rowData);
65
+ var sectionKey = toKey(R.propOr([], 'indexes', R.head(section)));
66
+ return R.over(R.lensIndex(1), R.filter(function (row) {
67
+ var rowKey = toKey(R.prop('indexes', row));
68
68
  return R.pipe(R.path([sectionKey, rowKey]), R.omit(extractedKeys), R.isEmpty, R.not)(curatedObs);
69
69
  }))(section);
70
70
  }), R.filter(R.pipe(R.nth(1), R.isEmpty, R.not)))(sections);
@@ -73,7 +73,7 @@ var refineSections = exports.refineSections = function refineSections(sections,
73
73
  var refineHeader = exports.refineHeader = function refineHeader(header, extractedKeys, curatedObs) {
74
74
  return R.filter( // extracted : { [sectionKey]: [...rowKeys] }
75
75
  function (header) {
76
- var headerKey = toKey(header);
76
+ var headerKey = toKey(R.prop('indexes', header));
77
77
  return R.pipe(R.prop(headerKey), function (sections) {
78
78
  return R.pickBy(function (rows, section) {
79
79
  return R.pipe(R.omit(R.propOr([], section, extractedKeys)), R.isEmpty, R.not)(rows);
@@ -82,6 +82,12 @@ var refineHeader = exports.refineHeader = function refineHeader(header, extracte
82
82
  })(header);
83
83
  };
84
84
 
85
+ var getSerieLinesCount = function getSerieLinesCount(serie) {
86
+ var missingParents = R.propOr([], 'missingParents', serie);
87
+ var missingParentsRowsCount = R.pipe(R.flatten, R.length)(missingParents);
88
+ return missingParentsRowsCount + 1;
89
+ };
90
+
85
91
  var truncateSectionRows = exports.truncateSectionRows = function truncateSectionRows(n, sectionsData) {
86
92
  var truncated = sectionsData;
87
93
  var extractedKeys = {};
@@ -90,33 +96,40 @@ var truncateSectionRows = exports.truncateSectionRows = function truncateSection
90
96
  var lastSection = R.last(truncated);
91
97
  var rows = lastSection[1];
92
98
  var rowsLength = R.length(rows);
93
- var sectionKey = toKey(R.head(lastSection));
94
- if (rowsLength > _n) {
95
- var _R$splitAt = R.splitAt(R.negate(_n), rows),
96
- _R$splitAt2 = (0, _slicedToArray3.default)(_R$splitAt, 2),
97
- rest = _R$splitAt2[0],
98
- extracted = _R$splitAt2[1];
99
-
100
- var updatedSection = R.set(R.lensIndex(1), rest)(lastSection);
101
- truncated = R.set(R.lensIndex(-1), updatedSection)(truncated);
102
- extractedKeys = (0, _extends5.default)({}, extractedKeys, (0, _defineProperty3.default)({}, sectionKey, R.map(toKey, extracted)));
103
- _n = 0;
104
- } else {
99
+ var truncatedRowsCount = 0;
100
+ while (_n > 0 && truncatedRowsCount !== rowsLength) {
101
+ var rowsCount = getSerieLinesCount(R.nth(-1 * truncatedRowsCount, rows));
102
+ _n = _n - rowsCount;
103
+ truncatedRowsCount++;
104
+ }
105
+ var sectionKey = R.pipe(R.head, R.prop('indexes'), toKey)(lastSection);
106
+ extractedKeys = (0, _extends4.default)({}, extractedKeys, (0, _defineProperty3.default)({}, sectionKey, R.pipe(R.takeLast(truncatedRowsCount), R.map(function (r) {
107
+ return toKey(R.prop('indexes', r));
108
+ }))(rows)));
109
+ if (_n > 0) {
105
110
  truncated = R.dropLast(1, truncated);
106
- extractedKeys = (0, _extends5.default)({}, extractedKeys, (0, _defineProperty3.default)({}, sectionKey, R.map(toKey, rows)));
107
- _n = _n - rowsLength;
111
+ } else {
112
+ truncated = R.over(R.lensIndex(-1), R.over(R.lensIndex(1), R.dropLast(truncatedRowsCount)))(truncated);
108
113
  }
109
114
  }
110
115
  return { truncated: truncated, extractedKeys: extractedKeys };
111
116
  };
112
117
 
113
118
  var truncateHeader = exports.truncateHeader = function truncateHeader(n, headerData) {
114
- var _R$splitAt3 = R.splitAt(R.negate(n))(headerData),
115
- _R$splitAt4 = (0, _slicedToArray3.default)(_R$splitAt3, 2),
116
- truncated = _R$splitAt4[0],
117
- extracted = _R$splitAt4[1];
119
+ var _truncated$extractedK = { truncated: headerData, extractedKeys: [] },
120
+ truncated = _truncated$extractedK.truncated,
121
+ extractedKeys = _truncated$extractedK.extractedKeys;
118
122
 
119
- return { truncated: truncated, extractedKeys: R.map(toKey, extracted) };
123
+ var _n = n;
124
+ while (_n > 0) {
125
+ var lastHeader = R.last(truncated);
126
+ var columnsCount = getSerieLinesCount(lastHeader);
127
+ var extractedKey = toKey(R.prop('indexes', lastHeader));
128
+ extractedKeys = R.append(extractedKey, extractedKeys);
129
+ truncated = R.dropLast(1, truncated);
130
+ _n = _n - columnsCount;
131
+ }
132
+ return { truncated: truncated, extractedKeys: extractedKeys };
120
133
  };
121
134
 
122
135
  var truncateLayout = function truncateLayout(isVertical) {
@@ -153,11 +166,14 @@ var refineLayoutSize = exports.refineLayoutSize = function refineLayoutSize(_ref
153
166
 
154
167
  //number of dimensions in header
155
168
  var headerDimCount = R.pipe(R.head, // first column
156
- R.when(R.isNil, R.always([])), R.length // number of dims
169
+ R.when(R.isNil, R.always({})), R.propOr([], 'indexes'), R.length // number of dims
157
170
  )(header);
158
171
 
159
172
  //number of columns for values
160
- var headerValuesCount = R.pipe(R.length, R.when(R.equals(0), R.always(1)))(header);
173
+ var headerValuesCount = R.pipe(R.reduce(function (acc, header) {
174
+ var columnsCount = getSerieLinesCount(header);
175
+ return acc + columnsCount;
176
+ }, 0), R.when(R.equals(0), R.always(1)))(header);
161
177
 
162
178
  //total of cells in header
163
179
  var headerCellsCount = headerDimCount * (headerValuesCount + 1);
@@ -166,19 +182,22 @@ var refineLayoutSize = exports.refineLayoutSize = function refineLayoutSize(_ref
166
182
  var rowDimCount = R.pipe(R.head, // firstSection
167
183
  R.last, // rows,
168
184
  R.head, // first row
169
- R.length)(sections);
185
+ R.propOr([], 'indexes'), R.length)(sections);
170
186
 
171
187
  // number of cells in a row
172
188
  var rowCellsCount = rowDimCount + headerValuesCount + 1;
173
189
 
174
190
  // number of rows
175
- var rowsCount = R.pipe(R.map(R.last), R.unnest, R.length, R.add(1))(sections);
191
+ var rowsCount = R.pipe(R.map(R.last), R.unnest, R.reduce(function (acc, row) {
192
+ var rowsCount = getSerieLinesCount(row);
193
+ return acc + rowsCount;
194
+ }, 1))(sections);
176
195
 
177
196
  // total of cells in all rows
178
197
  var rowsCellsCount = rowCellsCount * rowsCount;
179
198
 
180
199
  // number of sections cells
181
- var sectionsCellsCount = R.ifElse(R.pipe(R.head, R.head, R.length, R.equals(0)), R.always(0), R.length)(sections);
200
+ var sectionsCellsCount = R.ifElse(R.pipe(R.head, R.head, R.propOr([], 'indexes'), R.length, R.equals(0)), R.always(0), R.length)(sections);
182
201
 
183
202
  var total = rowsCellsCount + sectionsCellsCount + headerCellsCount;
184
203
 
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": "17.12.6",
4
+ "version": "17.13.0",
5
5
  "main": "lib/index.js",
6
6
  "author": "OECD",
7
7
  "license": "MIT",
@@ -60,25 +60,27 @@ export const hierarchiseDimensionWithAdvancedHierarchy = (dimension, _hierarchy)
60
60
  const indexed = R.indexBy(R.prop('id'), dimension.values);
61
61
  const hierarchy = refinePartialHierarchy(_hierarchy, indexed);
62
62
 
63
- let rest = indexed;
64
- const getChildren = (parents, hier) => R.pipe(
65
- ids => {
66
- rest = R.omit(ids, rest);
67
- return R.props(ids, indexed)
68
- },
69
- R.filter(R.identity),
70
- R.map(
71
- (val) => {
72
- const _val = {
73
- ...val,
74
- parent: R.last(parents),
75
- parents
76
- };
77
- const children = getChildren(R.append(val.id, parents), hier);
78
- return R.prepend(_val, children);
79
- },
80
- )
81
- )(R.propOr([], R.isEmpty(parents) ? '#ROOT' : R.join('.', parents), hier));
63
+ const rest = R.pipe(
64
+ R.values,
65
+ R.unnest,
66
+ R.flip(R.omit)(indexed),
67
+ R.values,
68
+ )(hierarchy);
69
+ let index = R.length(rest) - 1;
70
+ const getChildren = ({ parentsIndexes, parentId }) => {
71
+ const childrenIds = R.propOr([], parentId, hierarchy);
72
+ const children = R.reduce((acc, childId) => {
73
+ if (!R.has(childId, indexed)) {
74
+ return acc;
75
+ }
76
+ index = index + 1;
77
+ const child = { ...R.prop(childId, indexed), __indexPosition: index, parents: parentsIndexes, parent: R.isEmpty(parentsIndexes) ? undefined : R.pipe(R.split('.'), R.last)(parentId) };
78
+ const descendants = getChildren({ parentsIndexes: R.append(index, parentsIndexes), parentId: R.isEmpty(parentsIndexes) ? child.id : `${parentId}.${child.id}` });
79
+ return R.append(R.prepend(child, descendants), acc);
80
+ }, [], childrenIds);
81
+
82
+ return children;
83
+ }
82
84
 
83
85
  return R.set(
84
86
  R.lensProp('values'),
@@ -90,12 +92,11 @@ export const hierarchiseDimensionWithAdvancedHierarchy = (dimension, _hierarchy)
90
92
  return values;
91
93
  }
92
94
  const sortedRest = R.pipe(
93
- R.values,
94
- R.map(val => ({ ...val, parent: undefined, parents: [] })),
95
- R.sortBy(R.prop('__indexPosition'))
95
+ R.sortBy(R.prop('__indexPosition')),
96
+ R.addIndex(R.map)((val, ind) => ({ ...val, __indexPosition: ind, parent: undefined, parents: [] })),
96
97
  )(rest);
97
98
  return R.concat(sortedRest, values);
98
99
  }
99
- )([], hierarchy)
100
+ )({ parentsIndexes: [], parentId: '#ROOT' })
100
101
  )(dimension);
101
102
  };
@@ -1,28 +1,31 @@
1
- import * as R from 'ramda';
2
-
3
- export const hierarchiseDimensionWithNativeHierarchy = (dimension) => {
4
- const values = R.sortBy(R.prop('__indexPosition'), dimension.values || []);
5
- const indexed = R.indexBy(R.prop('id'), values);
6
- const grouped = R.groupBy(val => val.parent && R.has(val.parent, indexed) ? val.parent : '#ROOT', values);
7
-
8
- const getChildren = (parents) => {
9
- const childs = R.propOr([], R.defaultTo('#ROOT', R.last(parents)), grouped);
10
- return R.reduce(
11
- (acc, child) => {
12
- const refined = R.pipe(
13
- R.assoc('parents', parents),
14
- R.assoc('parent', R.last(parents)),
15
- )(child);
16
- const children = getChildren(R.append(child.id, parents));
17
- return R.concat(acc, R.prepend(refined, children));
18
- },
19
- [],
20
- childs
21
- );
22
- }
23
-
24
- return R.set(
25
- R.lensProp('values'),
26
- getChildren([])
27
- )(dimension);
28
- };
1
+ import * as R from 'ramda';
2
+
3
+ export const hierarchiseDimensionWithNativeHierarchy = (dimension) => {
4
+ const values = R.sortBy(R.prop('__indexPosition'), dimension.values || []);
5
+ const indexed = R.indexBy(R.prop('id'), values);
6
+ const grouped = R.groupBy(val => val.parent && R.has(val.parent, indexed) ? val.parent : '#ROOT', values);
7
+
8
+ let index = -1;
9
+ const getChildren = ({ parentsIndexes, parentId }) => {
10
+ const childs = R.propOr([], parentId, grouped);
11
+ return R.reduce(
12
+ (acc, child) => {
13
+ index = index + 1;
14
+ const refined = R.pipe(
15
+ R.assoc('__indexPosition', index),
16
+ R.assoc('parents', parentsIndexes),
17
+ R.assoc('parent', R.isEmpty(parentsIndexes) ? undefined : parentId),
18
+ )(child);
19
+ const children = getChildren({ parentsIndexes: R.append(index, parentsIndexes), parentId: child.id });
20
+ return R.concat(acc, R.prepend(refined, children));
21
+ },
22
+ [],
23
+ childs
24
+ );
25
+ }
26
+
27
+ return R.set(
28
+ R.lensProp('values'),
29
+ getChildren({ parentsIndexes: [], parentId: '#ROOT' })
30
+ )(dimension);
31
+ };
@@ -11,11 +11,10 @@ export { getMSDInformations } from './getMSDInformations';
11
11
  export { getNotDisplayedIds } from './getNotDisplayedIds';
12
12
  export { getHCodelistsRefs, getHCodelistsRefsInData } from './getHCodelistsRefsInData';
13
13
  export { parseHierarchicalCodelist } from './parseHierarchicalCodelist';
14
- export { refinePartialHierarchy } from './hierarchiseDimensionWithAdvancedHierarchy';
15
14
  export { getMetadataCoordinates } from './getMetadataCoordinates';
16
15
  export { duplicateObs } from './duplicateObservations';
17
- export { hierarchiseDimensionWithAdvancedHierarchy } from './hierarchiseDimensionWithAdvancedHierarchy';
18
- export { hierarchiseDimensionWithNativeHierarchy } from './hierarchiseDimensionWithNativeHierarchy';
16
+ export { refinePartialHierarchy, hierarchiseDimensionWithAdvancedHierarchy } from './hierarchiseDimensionWithAdvancedHierarchy2';
17
+ export { hierarchiseDimensionWithNativeHierarchy } from './hierarchiseDimensionWithNativeHierarchy2';
19
18
  export { getDimensionValuesIndexes } from './getDimensionValuesIndexes';
20
19
  export { getCombinationDefinitions } from './getCombinationDefinitions';
21
20
  export { refineDimensions } from './refineDimensions';
@@ -34,9 +33,9 @@ export { getHeaderCombinations } from './getHeaderCombinations';
34
33
  export { getHeaderCoordinates } from './getHeaderCoordinates';
35
34
  export { getLayout } from './table/getLayout';
36
35
  export { getSortedLayoutIndexes } from './table/getSortedLayoutIndexes';
37
- export { refineLayoutSize } from './table/refineLayoutSize';
36
+ export { refineLayoutSize } from './table/refineLayoutSize2';
38
37
  export { getFlagsAndNotes } from './table/getFlagsAndNotes';
39
- export { getLayoutData } from './table/getLayoutData';
38
+ export { getLayoutData } from './table/getLayoutData2';
40
39
  export { getCellsAttributesIds } from './table/getCellsAttributesIds';
41
40
  export { getCellsMetadataCoordinates } from './table/getCellsMetadataCoordinates';
42
41
  export { getIndexedCombinationsByDisplay } from './table/getIndexedCombinationsByDisplay';
@@ -46,3 +45,4 @@ export { prepareData } from './prepareData';
46
45
  export { getTableProps } from './table/getTableProps';
47
46
  export { getTableLabelAccessor } from './table/getTableLabelAccessor';
48
47
  export { parseValueHierarchy } from './table/parseValueHierarchy';
48
+ export { parseLayoutIndexesHierarchies } from './table/parseSeriesIndexesHierarchies';
@@ -11,8 +11,8 @@ import { getMetadataCoordinates } from './getMetadataCoordinates';
11
11
  import { getAttributesSeries } from './getAttributesSeries';
12
12
  import { getManyValuesDimensions } from './getManyValuesDimensions';
13
13
  import { getOneValueDimensions } from './getOneValueDimensions';
14
- import { hierarchiseDimensionWithNativeHierarchy } from './hierarchiseDimensionWithNativeHierarchy';
15
- import { hierarchiseDimensionWithAdvancedHierarchy } from './hierarchiseDimensionWithAdvancedHierarchy';
14
+ import { hierarchiseDimensionWithNativeHierarchy } from './hierarchiseDimensionWithNativeHierarchy2';
15
+ import { hierarchiseDimensionWithAdvancedHierarchy } from './hierarchiseDimensionWithAdvancedHierarchy2';
16
16
  import { getDataflowAttributes } from './getDataflowAttributes';
17
17
  import { getHeaderTitle } from './getHeaderTitle';
18
18
  import { getHeaderSubtitle } from './getHeaderSubtitle';
@@ -5,15 +5,12 @@ export const refineDimensions = (dimensions=[], dataquery='') => {
5
5
 
6
6
  return R.addIndex(R.map)((dim, index) => {
7
7
  const selection = R.nth(index, selectionIds);
8
- if (R.isNil(selection) || R.length(selection) === 0 || R.isEmpty(R.head(selection))) {
9
- return { ...dim, header: R.length(dim.values || []) <= 1 };
10
- }
11
8
  const values = R.map(val => {
12
- if (R.includes(val.id, selection)) {
13
- return val;
9
+ if (R.includes(val.id, selection || []) || R.isNil(selection) || R.length(selection) === 0 || R.isEmpty(R.head(selection))) {
10
+ return R.assoc('isSelected', true, val);
14
11
  }
15
12
  return R.assoc('empty', true, val);
16
13
  }, dim.values || []);
17
- return { ...dim, values, header: R.length(values) <= 1 || R.length(selection) === 1 };
14
+ return { ...dim, values, header: R.length(values) <= 1 || (R.length(selection) === 1 && !R.isEmpty(R.head(selection))) };
18
15
  }, dimensions);
19
16
  };
@@ -0,0 +1,175 @@
1
+ import * as R from 'ramda';
2
+ import { getFlagsAndNotes } from './getFlagsAndNotes';
3
+ import { getLayoutCoordinatesValidator } from '../utils';
4
+
5
+ const getValueData = (index, dimension, parentsIndexes) => ({
6
+ dimension: R.pick(['id', 'name', '__index'], dimension),
7
+ value: {
8
+ ...R.pipe(R.pathOr({}, ['values', index]), R.pick(['id', 'name']))(dimension),
9
+ parents: parentsIndexes
10
+ }
11
+ });
12
+
13
+ const addCoordinatesToKey = (key, dimensionId, valueId) =>
14
+ `${key}${R.isEmpty(key) ? '' : ':'}${dimensionId}=${valueId}`;
15
+
16
+ const simpleValueDataSetter = (valueData, datas = []) => R.append(valueData, datas);
17
+
18
+ const combinedValueDataSetter = (valueData, datas = []) =>
19
+ R.over(R.lensIndex(-1), d => ({ ...d, values: R.append(R.prop('value', valueData), d.values) }), datas);
20
+
21
+ const addValueToSerieData = (dataSetter) => (index, parentsIndexes, dimension, serieData) => {
22
+ const valueData = getValueData(index, dimension, parentsIndexes);
23
+ const valueId = R.path(['value', 'id'], valueData);
24
+ return ({
25
+ ...serieData,
26
+ data: dataSetter(valueData, R.prop('data', serieData)),
27
+ coordinates: R.assoc(dimension.id, valueId, R.prop('coordinates', serieData)),
28
+ key: addCoordinatesToKey(R.prop('key', serieData), R.prop('id', dimension), valueId)
29
+ });
30
+ };
31
+
32
+ const addSimpleValueToSerieData = addValueToSerieData(simpleValueDataSetter);
33
+
34
+ const addCombinedValueToSerieData = addValueToSerieData(combinedValueDataSetter);
35
+
36
+ const getHasAdvancedAttributes = (attrValues, customAttributes) => R.pipe(
37
+ R.omit(R.concat(customAttributes.flags || [], customAttributes.notes || [])),
38
+ R.isEmpty,
39
+ R.not
40
+ )(attrValues);
41
+
42
+ const getCoordinates = (indexes, topCoordinates, definition) => R.addIndex(R.reduce)((acc, entry, index) => {
43
+ if (R.has('dimensions', entry)) {
44
+ return R.addIndex(R.reduce)((_acc, dim, _index) => {
45
+ const valInd = R.path([index, _index], indexes);
46
+ return R.assoc(dim.id, R.path(['values', valInd, 'id'], dim), _acc)
47
+ }, acc, entry.dimensions);
48
+ }
49
+ const valInd = R.nth(index, indexes);
50
+ return R.assoc(entry.id, R.path(['values', valInd, 'id'], entry), acc);
51
+ }, topCoordinates, definition);
52
+
53
+ const getAttributesSeries = (validator, attributesSeries) => R.reduce((acc, attrs) => {
54
+ const attr = R.head(R.values(attrs));
55
+ const coordinates = R.propOr({}, 'coordinates', attr);
56
+ const isValid = validator(coordinates);
57
+ if (!isValid && !attr.isObs) {
58
+ return acc;
59
+ }
60
+ return ({ ...acc, ...attrs });
61
+ }, {}, R.values(attributesSeries));
62
+
63
+ const combineConcepts = (combDimValues, definition, attrValues) => R.over(
64
+ R.lensProp('data'),
65
+ R.over(R.lensIndex(-1), data => ({
66
+ ...data,
67
+ values: R.reduce((acc, conceptId) => {
68
+ if (R.has(conceptId, combDimValues)) {
69
+ return R.append(R.prop(conceptId, combDimValues), acc);
70
+ }
71
+ if (R.has(conceptId, definition.fixedDimValues || {})) {
72
+ return R.append(R.prop(conceptId, definition.fixedDimValues), acc);
73
+ }
74
+ if (R.has(conceptId, attrValues)) {
75
+ const value = R.path([conceptId, 'value'], attrValues);
76
+ return R.append(value, acc);
77
+ }
78
+ return acc;
79
+ }, [], definition.concepts)
80
+ })));
81
+
82
+ const getSerieFlagsAndSideProps = (coordinates, validator, attributesValues, customAttributes, metadataCoordinates) => {
83
+ const layoutAttrValues = R.reject(R.prop('isObs'), attributesValues);
84
+ const flags = getFlagsAndNotes(layoutAttrValues, customAttributes);
85
+ const hasMetadata = !R.isNil(R.find(validator, metadataCoordinates));
86
+ const hasAdvancedAttributes = getHasAdvancedAttributes(layoutAttrValues, customAttributes);
87
+ const sideProps = hasMetadata || hasAdvancedAttributes
88
+ ? { hasMetadata, hasAdvancedAttributes, coordinates } : null;
89
+ return { flags, sideProps };
90
+ };
91
+
92
+ export const getSerieDatas = (serie, definition, topCoordinates, attributesSeries, customAttributes, metadataCoordinates) => {
93
+ const lines = [];
94
+
95
+ const serieCoordinates = getCoordinates(serie.indexes, topCoordinates, definition);
96
+ const coordinatesValidator = getLayoutCoordinatesValidator(serieCoordinates, topCoordinates);
97
+ let attributesValues = getAttributesSeries(coordinatesValidator, attributesSeries);
98
+
99
+ const addMissingParentsLines = dataSetter => (missingParentsIndexes, parentsIndexes, dim, serieData) => R.reduce(
100
+ (parents, index) => {
101
+ const missingParentData = addValueToSerieData(dataSetter)(index, parents, dim, serieData);
102
+ lines.push(R.assoc('isEmpty', true, missingParentData));
103
+ return R.append(index, parents);
104
+ }, parentsIndexes, missingParentsIndexes
105
+ );
106
+
107
+ const addSimpleMissingParentsLines = addMissingParentsLines(simpleValueDataSetter);
108
+ const addCombinedMissingParentsLines = addMissingParentsLines(combinedValueDataSetter);
109
+
110
+ const serieData = R.addIndex(R.reduce)(
111
+ (onGoingSerie, entry, index) => {
112
+ if (R.has('dimensions', entry)) {
113
+ const combValuesIndexes = R.pathOr([], ['indexes', index], serie);
114
+ const combParentsIndexes = R.pathOr([], ['parentsIndexes', index], serie);
115
+ const combMissingParentsIndexes = R.pathOr([], ['missingIndexes', index], serie);
116
+ let combDimValues = {};
117
+ const res = R.addIndex(R.reduce)((combSerie, dimension, dimIndex) => {
118
+ const valueIndex = Math.abs(R.nth(dimIndex, combValuesIndexes));
119
+ const _parentsIndexes = R.nth(dimIndex, combParentsIndexes) || [];
120
+ const missingParentsIndexes = R.nth(dimIndex, combMissingParentsIndexes) || [];
121
+ const parentsIndexes = addCombinedMissingParentsLines(missingParentsIndexes, _parentsIndexes, dimension, combSerie);
122
+ const next = addCombinedValueToSerieData(valueIndex, parentsIndexes, dimension, combSerie);
123
+ const value = R.pipe(R.prop('data'), R.last, R.prop('values'), R.last)(next);
124
+ combDimValues = R.assoc(dimension.id, value, combDimValues);
125
+ return next;
126
+ },
127
+ R.over(
128
+ R.lensProp('data'),
129
+ R.append({ dimension: R.pick(['id', 'name'], entry), values: [] })
130
+ )(onGoingSerie),
131
+ R.propOr([], 'dimensions', entry));
132
+
133
+ const combined = combineConcepts(combDimValues, entry, attributesValues)(res);
134
+ attributesValues = R.omit(entry.concepts, attributesValues);
135
+ return combined;
136
+ }
137
+
138
+ const valueIndex = Math.abs(R.path(['indexes', index], serie));
139
+ const _parentsIndexes = R.pathOr([], ['parentsIndexes', index], serie);
140
+ const missingParentsIndexes = R.pathOr([], ['missingIndexes', index], serie);
141
+ const parentsIndexes = addSimpleMissingParentsLines(missingParentsIndexes, _parentsIndexes, entry, onGoingSerie);
142
+ return addSimpleValueToSerieData(valueIndex, parentsIndexes, entry, onGoingSerie);
143
+ },
144
+ { data: [], coordinates: {}, key: '', sideProps: null, flags: [] },
145
+ definition,
146
+ );
147
+ const { flags, sideProps } = getSerieFlagsAndSideProps(serieCoordinates, coordinatesValidator, attributesValues, customAttributes, metadataCoordinates);
148
+ lines.push({ ...serieData, flags, sideProps });
149
+ return lines;
150
+ };
151
+
152
+ export const getLayoutData = (layoutIndexes, layout, { metadataCoordinates, attributesSeries, customAttributes, topCoordinates={} }) => {
153
+ const { header, sections, ...rest } = layoutIndexes;
154
+
155
+ const headerData = R.reduce((acc, serie) => {
156
+ const datas = getSerieDatas(serie, layout.header, topCoordinates, attributesSeries, customAttributes, metadataCoordinates);
157
+ return R.concat(acc, datas);
158
+ }, [], header);
159
+
160
+ const sectionsData = R.map(
161
+ ([sectionSerie, rowsSeries]) => {
162
+ const sectionData = getSerieDatas(sectionSerie, layout.sections, topCoordinates, attributesSeries, customAttributes, metadataCoordinates);
163
+ return [
164
+ R.last(sectionData),
165
+ R.reduce((acc, serie) => {
166
+ const datas = getSerieDatas(serie, layout.rows, sectionData.coordinates, attributesSeries, customAttributes, metadataCoordinates);
167
+ return R.concat(acc, datas);
168
+ }, [], rowsSeries)
169
+ ];
170
+ },
171
+ sections
172
+ );
173
+
174
+ return ({ headerData, sectionsData, ...rest });
175
+ };
@@ -1,8 +1,8 @@
1
- import * as R from 'ramda';
2
1
  import { getLayout } from './getLayout';
3
2
  import { getSortedLayoutIndexes } from './getSortedLayoutIndexes';
4
- import { refineLayoutSize } from './refineLayoutSize';
5
- import { getLayoutData } from './getLayoutData';
3
+ import { parseLayoutIndexesHierarchies } from './parseSeriesIndexesHierarchies';
4
+ import { refineLayoutSize } from './refineLayoutSize2';
5
+ import { getLayoutData } from './getLayoutData2';
6
6
  import { getCellsAttributesIds } from './getCellsAttributesIds';
7
7
  import { getIndexedCombinationsByDisplay } from './getIndexedCombinationsByDisplay';
8
8
  import { getCells } from './getCells';
@@ -24,7 +24,11 @@ export const getTableProps = ({ data, layoutIds, customAttributes, limit, isTime
24
24
  const seriesCombinations = getSeriesCombinations(combinations, oneValueDimensions);
25
25
  const layout = getLayout(layoutIds, dimensions, seriesCombinations, isTimeInverted);
26
26
  const layoutIndexes = getSortedLayoutIndexes(layout, observations);
27
- const refinedLayoutIndexes = refineLayoutSize({ layout, observations, limit })(layoutIndexes);
27
+ const enhancedLayoutIndexes = parseLayoutIndexesHierarchies(
28
+ layoutIndexes,
29
+ layout,
30
+ );
31
+ const refinedLayoutIndexes = refineLayoutSize({ layout, observations, limit })(enhancedLayoutIndexes);
28
32
  const layoutData = getLayoutData(refinedLayoutIndexes, layout, { metadataCoordinates, attributesSeries, customAttributes, topCoordinates: header.coordinates });
29
33
 
30
34
  const cellsAttributesIds = getCellsAttributesIds(layoutIds, attributes);
@@ -0,0 +1,62 @@
1
+ import * as R from 'ramda';
2
+
3
+ const parseSerieIndexesHierarchies = (serieIndexes, previousSerie, dimensions, isSameSerie = true) => {
4
+ return R.addIndex(R.reduce)((acc, _valueIndex, dimensionIndex) => {
5
+ if (R.is(Array, _valueIndex)) {
6
+ const previous = R.isEmpty(previousSerie) ? {} : {
7
+ indexes: R.nth(dimensionIndex, previousSerie.indexes || []),
8
+ parentsIndexes: R.nth(dimensionIndex, previousSerie.parentsIndexes || []),
9
+ missingIndexes: R.nth(dimensionIndex, previousSerie.missingIndexes || []),
10
+ registeredIndexes: R.nth(dimensionIndex, previousSerie.registeredIndexes || []),
11
+ };
12
+ const parsed = parseSerieIndexesHierarchies(_valueIndex, previous, R.pathOr([], [dimensionIndex, 'dimensions'], dimensions), acc.isSameSerie);
13
+ return ({
14
+ parentsIndexes: R.append(parsed.parentsIndexes, acc.parentsIndexes),
15
+ missingIndexes: R.append(parsed.missingIndexes, acc.missingIndexes),
16
+ registeredIndexes: R.append(parsed.registeredIndexes, acc.registeredIndexes),
17
+ isSameSerie: parsed.isSameSerie
18
+ });
19
+ }
20
+ const valueIndex = Math.abs(_valueIndex);
21
+ const _parentsIndexes = R.pathOr([], [dimensionIndex, 'values', valueIndex, 'parents'], dimensions);
22
+ const previousIndex = acc.isSameSerie ? R.pathOr(-1, ['indexes', dimensionIndex], previousSerie) : -1;
23
+ const previousRegisteredIndexes = acc.isSameSerie ? R.pathOr(new Set(), ['registeredIndexes', dimensionIndex], previousSerie) : new Set();
24
+ const registeredIndexes = new Set(previousRegisteredIndexes);
25
+ const [parentsIndexes, missingParentsIndexes] = R.reduce((_acc, ind) => {
26
+ if (previousRegisteredIndexes.has(ind)) {
27
+ return R.over(R.lensIndex(0), R.append(ind), _acc);
28
+ }
29
+ else if (ind > previousIndex && R.pathOr(false, [dimensionIndex, 'values', ind, 'isSelected'], dimensions)) {
30
+ registeredIndexes.add(ind);
31
+ return R.over(R.lensIndex(1), R.append(ind), _acc);
32
+ }
33
+ return _acc;
34
+ }, [[], []], _parentsIndexes);
35
+ registeredIndexes.add(valueIndex);
36
+ return ({
37
+ parentsIndexes: R.append(parentsIndexes, acc.parentsIndexes),
38
+ missingIndexes: R.append(missingParentsIndexes, acc.missingIndexes),
39
+ registeredIndexes: R.append(registeredIndexes, acc.registeredIndexes),
40
+ isSameSerie: acc.isSameSerie && valueIndex === previousIndex
41
+ });
42
+ }, { parentsIndexes: [], missingIndexes: [], registeredIndexes: [], isSameSerie }, serieIndexes);
43
+ };
44
+
45
+ export const parseSeriesIndexesHierarchies = (seriesIndexes, dimensions) => R.reduce((acc, serieIndexes) => {
46
+ const previousSerie = R.last(acc) || {};
47
+ const { parentsIndexes, missingIndexes, registeredIndexes } = parseSerieIndexesHierarchies(serieIndexes, previousSerie, dimensions);
48
+ return R.append({ indexes: serieIndexes, parentsIndexes, missingIndexes, registeredIndexes }, acc);
49
+ }, [], seriesIndexes);
50
+
51
+ export const parseLayoutIndexesHierarchies = (layoutIndexes, layout) => {
52
+ const header = parseSeriesIndexesHierarchies(layoutIndexes.header, layout.header);
53
+ const sections = R.map(
54
+ ([sectionIndexes, rowsIndexes]) => ([
55
+ { indexes: sectionIndexes, parentsIndexes: [], missingIndexes: [] },
56
+ parseSeriesIndexesHierarchies(rowsIndexes, layout.rows)
57
+ ]),
58
+ layoutIndexes.sections
59
+ );
60
+
61
+ return ({ header, sections });
62
+ };