@sis-cc/dotstatsuite-components 17.12.5 → 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 (31) 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/parseCombinations.js +26 -3
  5. package/lib/rules2/src/prepareData.js +2 -2
  6. package/lib/rules2/src/refineDimensions.js +3 -6
  7. package/lib/rules2/src/table/getLayoutData2.js +218 -0
  8. package/lib/rules2/src/table/getTableProps.js +6 -9
  9. package/lib/rules2/src/table/parseSeriesIndexesHierarchies.js +96 -0
  10. package/lib/rules2/src/table/{refineLayoutSize.js → refineLayoutSize2.js} +53 -34
  11. package/package.json +1 -1
  12. package/src/rules2/src/{hierarchiseDimensionWithAdvancedHierarchy.js → hierarchiseDimensionWithAdvancedHierarchy2.js} +24 -23
  13. package/src/rules2/src/{hierarchiseDimensionWithNativeHierarchy.js → hierarchiseDimensionWithNativeHierarchy2.js} +31 -28
  14. package/src/rules2/src/index.js +5 -5
  15. package/src/rules2/src/parseCombinations.js +84 -42
  16. package/src/rules2/src/prepareData.js +2 -2
  17. package/src/rules2/src/refineDimensions.js +3 -6
  18. package/src/rules2/src/table/getLayoutData2.js +175 -0
  19. package/src/rules2/src/table/getTableProps.js +8 -4
  20. package/src/rules2/src/table/parseSeriesIndexesHierarchies.js +62 -0
  21. package/src/rules2/src/table/{refineLayoutSize.js → refineLayoutSize2.js} +50 -21
  22. package/test/getLayoutData2.test.js +268 -0
  23. package/test/{hierarchiseDimensionWithAdvancedHierarchy.test.js → hierarchiseDimensionWithAdvancedHierarchy2.test.js} +34 -69
  24. package/test/{hierarchiseDimensionWithNativeHierarchy.test.js → hierarchiseDimensionWithNativeHierarchy2.test.js} +14 -14
  25. package/test/parseCombinations.test.js +134 -20
  26. package/test/parseSeriesIndexesHierarchies.test.js +104 -0
  27. package/test/{refineLayoutSize.test.js → refineLayoutSize2.test.js} +63 -64
  28. package/test/refinedDimensions.test.js +8 -8
  29. package/lib/rules2/src/table/getLayoutData.js +0 -209
  30. package/src/rules2/src/table/getLayoutData.js +0 -193
  31. package/test/getLayoutData.test.js +0 -284
@@ -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
+ };
@@ -50,12 +50,12 @@ export const getCuratedCells = ({ layout, observations, shape }) => {
50
50
  export const refineSections = (sections, extractedKeys, curatedObs) => R.pipe(
51
51
  R.map(
52
52
  (section) => {
53
- const sectionKey = toKey(R.head(section) || []);
53
+ const sectionKey = toKey(R.propOr([], 'indexes', R.head(section)));
54
54
  return R.over(
55
55
  R.lensIndex(1),
56
56
  R.filter(
57
- rowData => {
58
- const rowKey = toKey(rowData);
57
+ row => {
58
+ const rowKey = toKey(R.prop('indexes', row));
59
59
  return R.pipe(
60
60
  R.path([sectionKey, rowKey]),
61
61
  R.omit(extractedKeys),
@@ -74,7 +74,7 @@ export const refineSections = (sections, extractedKeys, curatedObs) => R.pipe(
74
74
 
75
75
  export const refineHeader = (header, extractedKeys, curatedObs) => R.filter( // extracted : { [sectionKey]: [...rowKeys] }
76
76
  (header) => {
77
- const headerKey = toKey(header);
77
+ const headerKey = toKey(R.prop('indexes', header));
78
78
  return R.pipe(
79
79
  R.prop(headerKey),
80
80
  (sections) => {
@@ -93,6 +93,12 @@ export const refineHeader = (header, extractedKeys, curatedObs) => R.filter( //
93
93
  }
94
94
  )(header);
95
95
 
96
+ const getSerieLinesCount = serie => {
97
+ const missingParents = R.propOr([], 'missingParents', serie);
98
+ const missingParentsRowsCount = R.pipe(R.flatten, R.length)(missingParents);
99
+ return missingParentsRowsCount + 1;
100
+ }
101
+
96
102
  export const truncateSectionRows = (n, sectionsData) => {
97
103
  let truncated = sectionsData;
98
104
  let extractedKeys = {};
@@ -101,26 +107,42 @@ export const truncateSectionRows = (n, sectionsData) => {
101
107
  const lastSection = R.last(truncated);
102
108
  const rows = lastSection[1];
103
109
  const rowsLength = R.length(rows);
104
- const sectionKey = toKey(R.head(lastSection));
105
- if (rowsLength > _n) {
106
- const [rest, extracted] = R.splitAt(R.negate(_n), rows);
107
- const updatedSection = R.set(R.lensIndex(1), rest)(lastSection);
108
- truncated = R.set(R.lensIndex(-1), updatedSection)(truncated);
109
- extractedKeys = { ...extractedKeys, [sectionKey]: R.map(toKey, extracted) };
110
- _n = 0;
110
+ let truncatedRowsCount = 0;
111
+ while (_n > 0 && truncatedRowsCount !== rowsLength) {
112
+ const rowsCount = getSerieLinesCount(R.nth(-1 * truncatedRowsCount, rows));
113
+ _n = _n - rowsCount;
114
+ truncatedRowsCount++;
111
115
  }
112
- else {
116
+ const sectionKey = R.pipe(R.head, R.prop('indexes'), toKey)(lastSection);
117
+ extractedKeys = {
118
+ ...extractedKeys,
119
+ [sectionKey]: R.pipe(
120
+ R.takeLast(truncatedRowsCount),
121
+ R.map(r => toKey(R.prop('indexes', r)))
122
+ )(rows)
123
+ };
124
+ if (_n > 0) {
113
125
  truncated = R.dropLast(1, truncated);
114
- extractedKeys = { ...extractedKeys, [sectionKey]: R.map(toKey, rows) };
115
- _n = _n - rowsLength;
126
+ }
127
+ else {
128
+ truncated = R.over(R.lensIndex(-1), R.over(R.lensIndex(1), R.dropLast(truncatedRowsCount)))(truncated);
116
129
  }
117
130
  }
118
131
  return ({ truncated, extractedKeys });
119
132
  };
120
133
 
121
134
  export const truncateHeader = (n, headerData) => {
122
- const [truncated, extracted] = R.splitAt(R.negate(n))(headerData);
123
- return ({ truncated, extractedKeys: R.map(toKey, extracted) });
135
+ let { truncated, extractedKeys } = { truncated: headerData, extractedKeys: [] };
136
+ let _n = n;
137
+ while (_n > 0) {
138
+ const lastHeader = R.last(truncated);
139
+ const columnsCount = getSerieLinesCount(lastHeader);
140
+ const extractedKey = toKey(R.prop('indexes', lastHeader));
141
+ extractedKeys = R.append(extractedKey, extractedKeys);
142
+ truncated = R.dropLast(1, truncated);
143
+ _n = _n - columnsCount;
144
+ }
145
+ return ({ truncated, extractedKeys });
124
146
  };
125
147
 
126
148
  const truncateLayout = (isVertical) => R.ifElse(
@@ -161,13 +183,17 @@ export const refineLayoutSize = ({ layout, observations, limit }) => layoutIndex
161
183
  //number of dimensions in header
162
184
  const headerDimCount = R.pipe(
163
185
  R.head, // first column
164
- R.when(R.isNil, R.always([])),
186
+ R.when(R.isNil, R.always({})),
187
+ R.propOr([], 'indexes'),
165
188
  R.length // number of dims
166
189
  )(header);
167
190
 
168
191
  //number of columns for values
169
192
  const headerValuesCount = R.pipe(
170
- R.length,
193
+ R.reduce((acc, header) => {
194
+ const columnsCount = getSerieLinesCount(header);
195
+ return acc + columnsCount;
196
+ }, 0),
171
197
  R.when(R.equals(0), R.always(1))
172
198
  )(header);
173
199
 
@@ -179,6 +205,7 @@ export const refineLayoutSize = ({ layout, observations, limit }) => layoutIndex
179
205
  R.head, // firstSection
180
206
  R.last, // rows,
181
207
  R.head, // first row
208
+ R.propOr([], 'indexes'),
182
209
  R.length
183
210
  )(sections);
184
211
 
@@ -189,8 +216,10 @@ export const refineLayoutSize = ({ layout, observations, limit }) => layoutIndex
189
216
  const rowsCount = R.pipe(
190
217
  R.map(R.last),
191
218
  R.unnest,
192
- R.length,
193
- R.add(1)
219
+ R.reduce((acc, row) => {
220
+ const rowsCount = getSerieLinesCount(row);
221
+ return acc + rowsCount;
222
+ }, 1)
194
223
  )(sections);
195
224
 
196
225
  // total of cells in all rows
@@ -198,7 +227,7 @@ export const refineLayoutSize = ({ layout, observations, limit }) => layoutIndex
198
227
 
199
228
  // number of sections cells
200
229
  const sectionsCellsCount = R.ifElse(
201
- R.pipe(R.head, R.head, R.length, R.equals(0)),
230
+ R.pipe(R.head, R.head, R.propOr([], 'indexes'), R.length, R.equals(0)),
202
231
  R.always(0),
203
232
  R.length
204
233
  )(sections);
@@ -0,0 +1,268 @@
1
+ import { expect } from 'chai';
2
+ import { getSerieDatas } from '../src/rules2/src/table/getLayoutData2';
3
+
4
+ describe('getLayoutData 2 tests', () => {
5
+ it('getSerieDatas test 1', () => {
6
+ const dimensions = [
7
+ {
8
+ id: 'D0',
9
+ values: [
10
+ { id: 'v0' },
11
+ { id: 'v1' },
12
+ { id: 'v2' },
13
+ { id: 'v3' },
14
+ { id: 'v4' },
15
+ ]
16
+ },
17
+ {
18
+ id: 'D1',
19
+ values: [
20
+ { id: 'W', isSelected: true },
21
+ { id: 'NA', parentsIndexes: [0], isSelected: false },
22
+ { id: 'A', parentsIndexes: [0, 1], isSelected: true },
23
+ { id: 'USA', parentsIndexes: [0, 1, 2], isSelected: true },
24
+ { id: 'CAN', parentsIndexes: [0, 1, 2], isSelected: true },
25
+ { id: 'MEX', parentsIndexes: [0, 1, 2], isSelected: true }
26
+ ]
27
+ }
28
+ ];
29
+
30
+ const serie = { indexes: [0, 3], parentsIndexes: [[], []], missingIndexes: [[], [0, 2]] };
31
+ expect(getSerieDatas(serie, dimensions, {}, {}, {}, {})).to.deep.equal([
32
+ {
33
+ data: [{ dimension: { id: 'D0' }, value: { id: 'v0', parents: [] } }, { dimension: { id: 'D1' }, value: { id: 'W', parents: [] } }],
34
+ coordinates: { D0: 'v0', D1: 'W' },
35
+ key: 'D0=v0:D1=W',
36
+ flags: [],
37
+ sideProps: null,
38
+ isEmpty: true,
39
+ },
40
+ {
41
+ data: [{ dimension: { id: 'D0' }, value: { id: 'v0', parents: [] } }, { dimension: { id: 'D1' }, value: { id: 'A', parents: [0] } }],
42
+ coordinates: { D0: 'v0', D1: 'A' },
43
+ key: 'D0=v0:D1=A',
44
+ flags: [],
45
+ sideProps: null,
46
+ isEmpty: true
47
+ },
48
+ {
49
+ data: [{ dimension: { id: 'D0' }, value: { id: 'v0', parents: [] } }, { dimension: { id: 'D1' }, value: { id: 'USA', parents: [0, 2] } }],
50
+ coordinates: { D0: 'v0', D1: 'USA' },
51
+ key: 'D0=v0:D1=USA',
52
+ flags: [],
53
+ sideProps: null,
54
+ }
55
+ ]);
56
+ });
57
+ it('getSerieDatas test 2', () => {
58
+ const dimensions = [
59
+ {
60
+ id: 'D0',
61
+ values: [
62
+ { id: 'W' },
63
+ { id: 'NA', parentsIndexes: [0] },
64
+ { id: 'A', parentsIndexes: [0, 1] },
65
+ { id: 'USA', parentsIndexes: [0, 1, 2] },
66
+ { id: 'CAN', parentsIndexes: [0, 1, 2] },
67
+ { id: 'MEX', parentsIndexes: [0, 1, 2] }
68
+ ]
69
+ },
70
+ {
71
+ id: 'COMB0',
72
+ concepts: ['D1', 'A0', 'D2'],
73
+ dimensions: [
74
+ {
75
+ id: 'D1',
76
+ values: [
77
+ { id: 'D1ROOT' },
78
+ { id: 'D1ROOT>CHILD' },
79
+ { id: 'D1ROOT>CHILD>CHILD' },
80
+ ]
81
+ },
82
+ {
83
+ id: 'D2',
84
+ values: [
85
+ { id: 'D2ROOT' },
86
+ { id: 'D2ROOT>CHILD' },
87
+ { id: 'D2ROOT>CHILD>CHILD' },
88
+ ]
89
+ }
90
+ ]
91
+ },
92
+ {
93
+ id: 'COMB1',
94
+ concepts: ['D3', 'D4'],
95
+ dimensions: [
96
+ {
97
+ id: 'D3',
98
+ values: [
99
+ { id: 'D3ROOT' },
100
+ { id: 'D3ROOT>CHILD' },
101
+ { id: 'D3ROOT>CHILD>CHILD' },
102
+ ]
103
+ },
104
+ {
105
+ id: 'D4',
106
+ values: [
107
+ { id: 'D4ROOT' },
108
+ { id: 'D4ROOT>CHILD' },
109
+ { id: 'D4ROOT>CHILD>CHILD' },
110
+ ]
111
+ }
112
+ ]
113
+ },
114
+ ];
115
+
116
+ const attributesSeries = {
117
+ 'D1=D1ROOT>CHILD>CHILD:D2=D2ROOT>CHILD>CHILD': {
118
+ A0: { id: 'A0', value: { id: 'A0VAL' }, coordinates: { D1: 'D1ROOT>CHILD>CHILD', D2: 'D2ROOT>CHILD>CHILD' } },
119
+ A1: { id: 'A1', value: { id: 'A1VAL' }, coordinates: { D1: 'D1ROOT>CHILD>CHILD', D2: 'D2ROOT>CHILD>CHILD' } },
120
+ }
121
+ };
122
+
123
+ const topCoordinates = {};
124
+
125
+ const serie = {
126
+ indexes: [3, [2, 2], [2, 2]],
127
+ parentsIndexes: [[], [[], []], [[], []]],
128
+ missingIndexes: [[0, 2], [[0, 1], [0, 1]], [[0, 1], [0, 1]]],
129
+ };
130
+
131
+ expect(getSerieDatas(serie, dimensions, topCoordinates, attributesSeries, {}, {})).to.deep.equal([
132
+ {
133
+ data: [
134
+ { dimension: { id: 'D0' }, value: { id: 'W', parents: [] } }
135
+ ],
136
+ coordinates: { D0: 'W' },
137
+ key: 'D0=W',
138
+ flags: [],
139
+ sideProps: null,
140
+ isEmpty: true
141
+ },
142
+ {
143
+ data: [
144
+ { dimension: { id: 'D0' }, value: { id: 'A', parents: [0] } }
145
+ ],
146
+ coordinates: { D0: 'A' },
147
+ key: 'D0=A',
148
+ flags: [],
149
+ sideProps: null,
150
+ isEmpty: true
151
+ },
152
+ {
153
+ data: [
154
+ { dimension: { id: 'D0' }, value: { id: 'USA', parents: [0, 2] } },
155
+ { dimension: { id: 'COMB0' }, values: [{ id: 'D1ROOT', parents: [] }] }
156
+ ],
157
+ coordinates: { D0: 'USA', D1: 'D1ROOT' },
158
+ key: 'D0=USA:D1=D1ROOT',
159
+ flags: [],
160
+ sideProps: null,
161
+ isEmpty: true
162
+ },
163
+ {
164
+ data: [
165
+ { dimension: { id: 'D0' }, value: { id: 'USA', parents: [0, 2] } },
166
+ { dimension: { id: 'COMB0' }, values: [{ id: 'D1ROOT>CHILD', parents: [0] }] }
167
+ ],
168
+ coordinates: { D0: 'USA', D1: 'D1ROOT>CHILD' },
169
+ key: 'D0=USA:D1=D1ROOT>CHILD',
170
+ flags: [],
171
+ sideProps: null,
172
+ isEmpty: true
173
+ },
174
+ {
175
+ data: [
176
+ { dimension: { id: 'D0' }, value: { id: 'USA', parents: [0, 2] } },
177
+ { dimension: { id: 'COMB0' }, values: [{ id: 'D1ROOT>CHILD>CHILD', parents: [0, 1] }, { id: 'D2ROOT', parents: [] }] }
178
+ ],
179
+ coordinates: { D0: 'USA', D1: 'D1ROOT>CHILD>CHILD', D2: 'D2ROOT' },
180
+ key: 'D0=USA:D1=D1ROOT>CHILD>CHILD:D2=D2ROOT',
181
+ flags: [],
182
+ sideProps: null,
183
+ isEmpty: true
184
+ },
185
+ {
186
+ data: [
187
+ { dimension: { id: 'D0' }, value: { id: 'USA', parents: [0, 2] } },
188
+ { dimension: { id: 'COMB0' }, values: [{ id: 'D1ROOT>CHILD>CHILD', parents: [0, 1] }, { id: 'D2ROOT>CHILD', parents: [0] }] }
189
+ ],
190
+ coordinates: { D0: 'USA', D1: 'D1ROOT>CHILD>CHILD', D2: 'D2ROOT>CHILD' },
191
+ key: 'D0=USA:D1=D1ROOT>CHILD>CHILD:D2=D2ROOT>CHILD',
192
+ flags: [],
193
+ sideProps: null,
194
+ isEmpty: true
195
+ },
196
+ {
197
+ data: [
198
+ { dimension: { id: 'D0' }, value: { id: 'USA', parents: [0, 2] } },
199
+ { dimension: { id: 'COMB0' }, values: [{ id: 'D1ROOT>CHILD>CHILD', parents: [0, 1] }, { id: 'A0VAL' }, { id: 'D2ROOT>CHILD>CHILD', parents: [0, 1] }] },
200
+ { dimension: { id: 'COMB1' }, values: [{ id: 'D3ROOT', parents: [] }] }
201
+ ],
202
+ coordinates: { D0: 'USA', D1: 'D1ROOT>CHILD>CHILD', D2: 'D2ROOT>CHILD>CHILD', D3: 'D3ROOT' },
203
+ key: 'D0=USA:D1=D1ROOT>CHILD>CHILD:D2=D2ROOT>CHILD>CHILD:D3=D3ROOT',
204
+ flags: [],
205
+ sideProps: null,
206
+ isEmpty: true
207
+ },
208
+ {
209
+ data: [
210
+ { dimension: { id: 'D0' }, value: { id: 'USA', parents: [0, 2] } },
211
+ { dimension: { id: 'COMB0' }, values: [{ id: 'D1ROOT>CHILD>CHILD', parents: [0, 1] }, { id: 'A0VAL' }, { id: 'D2ROOT>CHILD>CHILD', parents: [0, 1] }] },
212
+ { dimension: { id: 'COMB1' }, values: [{ id: 'D3ROOT>CHILD', parents: [0] }] }
213
+ ],
214
+ coordinates: { D0: 'USA', D1: 'D1ROOT>CHILD>CHILD', D2: 'D2ROOT>CHILD>CHILD', D3: 'D3ROOT>CHILD' },
215
+ key: 'D0=USA:D1=D1ROOT>CHILD>CHILD:D2=D2ROOT>CHILD>CHILD:D3=D3ROOT>CHILD',
216
+ flags: [],
217
+ sideProps: null,
218
+ isEmpty: true
219
+ },
220
+ {
221
+ data: [
222
+ { dimension: { id: 'D0' }, value: { id: 'USA', parents: [0, 2] } },
223
+ { dimension: { id: 'COMB0' }, values: [{ id: 'D1ROOT>CHILD>CHILD', parents: [0, 1] }, { id: 'A0VAL' }, { id: 'D2ROOT>CHILD>CHILD', parents: [0, 1] }] },
224
+ { dimension: { id: 'COMB1' }, values: [{ id: 'D3ROOT>CHILD>CHILD', parents: [0, 1] }, { id: 'D4ROOT', parents: [] }] }
225
+ ],
226
+ coordinates: { D0: 'USA', D1: 'D1ROOT>CHILD>CHILD', D2: 'D2ROOT>CHILD>CHILD', D3: 'D3ROOT>CHILD>CHILD', D4: 'D4ROOT' },
227
+ key: 'D0=USA:D1=D1ROOT>CHILD>CHILD:D2=D2ROOT>CHILD>CHILD:D3=D3ROOT>CHILD>CHILD:D4=D4ROOT',
228
+ flags: [],
229
+ sideProps: null,
230
+ isEmpty: true
231
+ },
232
+
233
+ {
234
+ data: [
235
+ { dimension: { id: 'D0' }, value: { id: 'USA', parents: [0, 2] } },
236
+ { dimension: { id: 'COMB0' }, values: [{ id: 'D1ROOT>CHILD>CHILD', parents: [0, 1] }, { id: 'A0VAL' }, { id: 'D2ROOT>CHILD>CHILD', parents: [0, 1] }] },
237
+ { dimension: { id: 'COMB1' }, values: [{ id: 'D3ROOT>CHILD>CHILD', parents: [0, 1] }, { id: 'D4ROOT>CHILD', parents: [0] }] }
238
+ ],
239
+ coordinates: { D0: 'USA', D1: 'D1ROOT>CHILD>CHILD', D2: 'D2ROOT>CHILD>CHILD', D3: 'D3ROOT>CHILD>CHILD', D4: 'D4ROOT>CHILD' },
240
+ key: 'D0=USA:D1=D1ROOT>CHILD>CHILD:D2=D2ROOT>CHILD>CHILD:D3=D3ROOT>CHILD>CHILD:D4=D4ROOT>CHILD',
241
+ flags: [],
242
+ sideProps: null,
243
+ isEmpty: true
244
+ },
245
+ {
246
+ data: [
247
+ { dimension: { id: 'D0' }, value: { id: 'USA', parents: [0, 2] } },
248
+ { dimension: { id: 'COMB0' }, values: [{ id: 'D1ROOT>CHILD>CHILD', parents: [0, 1] }, { id: 'A0VAL' }, { id: 'D2ROOT>CHILD>CHILD', parents: [0, 1] }] },
249
+ { dimension: { id: 'COMB1' }, values: [{ id: 'D3ROOT>CHILD>CHILD', parents: [0, 1] }, { id: 'D4ROOT>CHILD>CHILD', parents: [0, 1] }] }
250
+ ],
251
+ coordinates: { D0: 'USA', D1: 'D1ROOT>CHILD>CHILD', D2: 'D2ROOT>CHILD>CHILD', D3: 'D3ROOT>CHILD>CHILD', D4: 'D4ROOT>CHILD>CHILD' },
252
+ key: 'D0=USA:D1=D1ROOT>CHILD>CHILD:D2=D2ROOT>CHILD>CHILD:D3=D3ROOT>CHILD>CHILD:D4=D4ROOT>CHILD>CHILD',
253
+ flags: [],
254
+ sideProps: {
255
+ coordinates: {
256
+ D0: 'USA',
257
+ D1: 'D1ROOT>CHILD>CHILD',
258
+ D2: 'D2ROOT>CHILD>CHILD',
259
+ D3: 'D3ROOT>CHILD>CHILD',
260
+ D4: 'D4ROOT>CHILD>CHILD',
261
+ },
262
+ hasAdvancedAttributes: true,
263
+ hasMetadata: false
264
+ }
265
+ }
266
+ ]);
267
+ });
268
+ });