@sis-cc/dotstatsuite-components 17.22.0 → 17.23.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.
@@ -168,7 +168,7 @@ var getLayoutCombinations = exports.getLayoutCombinations = function getLayoutCo
168
168
  layoutConcepts = _R$reduce3.layoutConcepts,
169
169
  relationship = _R$reduce3.relationship;
170
170
 
171
- if (R.isEmpty(layoutConcepts)) {
171
+ if (R.isEmpty(relationship)) {
172
172
  return acc;
173
173
  }
174
174
  return R.append((0, _extends3.default)({}, comb, { relationship: relationship, concepts: layoutConcepts }), acc);
@@ -182,41 +182,59 @@ var getTableLayoutIds = exports.getTableLayoutIds = function getTableLayoutIds(d
182
182
  var filteredLayoutIds = R.map(R.filter(function (id) {
183
183
  return R.has(id, indexedCombinations) || layoutDimsIds.has(id);
184
184
  }), defaultLayoutIds);
185
-
186
185
  var layoutWithCombs = injectCombinationsInLayout(layoutCombinations, filteredLayoutIds);
187
- var layoutRelationshipsSets = R.map(function (ids) {
188
- return R.pipe(R.pick(ids, indexedCombsRelationships), R.values, R.unnest, function (i) {
189
- return new _set2.default(i);
190
- })(ids);
191
- }, layoutWithCombs);
186
+ var layoutRelationshipsSets = R.map(R.pipe(function (ids) {
187
+ return R.pick(ids, indexedCombinations);
188
+ }, R.values, R.pluck('relationship'), R.unnest, function (i) {
189
+ return new _set2.default(i);
190
+ }), layoutWithCombs);
192
191
  var layoutConceptsSets = R.pipe(R.map(R.reduce(function (acc, id) {
193
192
  if (R.has(id, indexedCombinations)) {
194
- return R.concat(acc, R.path([id, 'relationship'], indexedCombinations));
193
+ return R.concat(acc, R.path([id, 'concepts'], indexedCombinations));
195
194
  }
196
195
  return R.append(id, acc);
197
196
  }, [])), R.values, R.unnest, function (ids) {
198
197
  return new _set2.default(ids);
199
198
  })(layoutWithCombs);
200
199
 
201
- return R.reduce(function (acc, dim) {
202
- if (layoutConceptsSets.has(id) || !dim.series) {
200
+ var _R$reduce4 = R.reduce(function (acc, dim) {
201
+ if (layoutConceptsSets.has(dim.id) || dim.header) {
203
202
  return acc;
204
203
  }
205
204
  if (layoutRelationshipsSets.header.has(dim.id)) {
206
- return R.over(R.lensProp('header'), R.append(dim.id))(acc);
205
+ return R.over(R.lensPath(['nextLayout', 'header']), R.append(dim.id))(acc);
207
206
  }
208
207
  if (layoutRelationshipsSets.sections.has(dim.id)) {
209
- return R.over(R.lensProp('sections'), R.append(dim.id))(acc);
208
+ return R.over(R.lensPath(['nextLayout', 'sections']), R.append(dim.id))(acc);
210
209
  }
211
210
  if (layoutRelationshipsSets.rows.has(dim.id)) {
212
- return R.over(R.lensProp('rows'), R.append(dim.id))(acc);
211
+ return R.over(R.lensPath(['nextLayout', 'rows']), R.append(dim.id))(acc);
213
212
  }
214
213
  if ((0, _dotstatsuiteSdmxjs.isTimePeriodDimension)(dim)) {
215
- return R.over(R.lensProp('header'), R.append(dim.id))(acc);
214
+ return R.over(R.lensPath(['nextLayout', 'header']), R.append(dim.id))(acc);
216
215
  }
217
216
  if ((0, _dotstatsuiteSdmxjs.isRefAreaDimension)(dim)) {
218
- return R.over(R.lensProp('rows'), R.append(dim.id))(acc);
217
+ return R.over(R.lensPath(['nextLayout', 'rows']), R.append(dim.id))(acc);
219
218
  }
220
- return R.over(R.lensProp('sections'), R.append(dim.id))(acc);
221
- }, layoutWithCombs, dimensions);
219
+ return R.over(R.lensProp('remaining'), R.append(dim.id))(acc);
220
+ }, { nextLayout: layoutWithCombs, remaining: [] }, dimensions),
221
+ nextLayout = _R$reduce4.nextLayout,
222
+ remaining = _R$reduce4.remaining;
223
+
224
+ var _remaining = remaining;
225
+ return R.pipe(R.when(function (l) {
226
+ return R.isEmpty(l.rows) && !R.isEmpty(_remaining);
227
+ }, function (l) {
228
+ var nextL = R.over(R.lensProp('rows'), R.append(R.head(_remaining)))(l);
229
+ _remaining = R.tail(_remaining);
230
+ return nextL;
231
+ }), R.when(function (l) {
232
+ return R.isEmpty(l.header) && !R.isEmpty(_remaining);
233
+ }, function (l) {
234
+ var nextL = R.over(R.lensProp('header'), R.append(R.head(_remaining)))(l);
235
+ _remaining = R.tail(_remaining);
236
+ return nextL;
237
+ }), R.when(R.always(!R.isEmpty(_remaining)), function (l) {
238
+ return R.over(R.lensProp('sections'), R.flip(R.concat)(_remaining))(l);;
239
+ }))(nextLayout);
222
240
  };
@@ -269,6 +269,9 @@ var refineLayoutSize = exports.refineLayoutSize = function refineLayoutSize(_ref
269
269
 
270
270
  var cutLength = R.pipe(R.ifElse(R.identity, R.always(rowCellsCount), R.always(columnCellsCount)), R.divide(excess), Math.ceil)(isVertical);
271
271
 
272
+ var maxCutLength = isVertical ? rowsCount - 2 : headerValuesCount - 1;
273
+ cutLength = cutLength > maxCutLength ? maxCutLength : cutLength;
274
+
272
275
  var _truncateLayout = truncateLayout(isVertical)(cutLength, toTruncate),
273
276
  truncated = _truncateLayout.truncated,
274
277
  extractedKeys = _truncateLayout.extractedKeys;
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.22.0",
4
+ "version": "17.23.0",
5
5
  "main": "lib/index.js",
6
6
  "author": "OECD",
7
7
  "license": "MIT",
@@ -113,7 +113,7 @@ export const getLayoutCombinations = (combinations, layoutDimsIds, attributes) =
113
113
  { layoutConcepts: [], relationship: [] },
114
114
  comb.concepts || [],
115
115
  );
116
- if (R.isEmpty(layoutConcepts)) {
116
+ if (R.isEmpty(relationship)) {
117
117
  return acc;
118
118
  }
119
119
  return R.append({ ...comb, relationship, concepts: layoutConcepts }, acc);
@@ -140,19 +140,19 @@ export const getTableLayoutIds = (
140
140
  R.filter(id => R.has(id, indexedCombinations) || layoutDimsIds.has(id)),
141
141
  defaultLayoutIds,
142
142
  );
143
-
144
143
  const layoutWithCombs = injectCombinationsInLayout(layoutCombinations, filteredLayoutIds);
145
- const layoutRelationshipsSets = R.map(ids => R.pipe(
146
- R.pick(ids, indexedCombsRelationships),
144
+ const layoutRelationshipsSets = R.map(R.pipe(
145
+ ids => R.pick(ids, indexedCombinations),
147
146
  R.values,
147
+ R.pluck('relationship'),
148
148
  R.unnest,
149
149
  i => new Set(i)
150
- )(ids),layoutWithCombs);
150
+ ), layoutWithCombs);
151
151
  const layoutConceptsSets = R.pipe(
152
152
  R.map(
153
153
  R.reduce((acc, id) => {
154
154
  if (R.has(id, indexedCombinations)) {
155
- return R.concat(acc, R.path([id, 'relationship'], indexedCombinations));
155
+ return R.concat(acc, R.path([id, 'concepts'], indexedCombinations));
156
156
  }
157
157
  return R.append(id, acc);
158
158
  }, []),
@@ -162,25 +162,51 @@ export const getTableLayoutIds = (
162
162
  ids => new Set(ids)
163
163
  )(layoutWithCombs);
164
164
 
165
- return R.reduce((acc, dim) => {
166
- if (layoutConceptsSets.has(id) || !dim.series) {
165
+ const { nextLayout, remaining } = R.reduce((acc, dim) => {
166
+ if (layoutConceptsSets.has(dim.id) || dim.header) {
167
167
  return acc;
168
168
  }
169
169
  if (layoutRelationshipsSets.header.has(dim.id)) {
170
- return R.over(R.lensProp('header'), R.append(dim.id))(acc);
170
+ return R.over(R.lensPath(['nextLayout', 'header']), R.append(dim.id))(acc);
171
171
  }
172
172
  if (layoutRelationshipsSets.sections.has(dim.id)) {
173
- return R.over(R.lensProp('sections'), R.append(dim.id))(acc);
173
+ return R.over(R.lensPath(['nextLayout', 'sections']), R.append(dim.id))(acc);
174
174
  }
175
175
  if (layoutRelationshipsSets.rows.has(dim.id)) {
176
- return R.over(R.lensProp('rows'), R.append(dim.id))(acc);
176
+ return R.over(R.lensPath(['nextLayout','rows']), R.append(dim.id))(acc);
177
177
  }
178
178
  if (isTimePeriodDimension(dim)) {
179
- return R.over(R.lensProp('header'), R.append(dim.id))(acc);
179
+ return R.over(R.lensPath(['nextLayout','header']), R.append(dim.id))(acc);
180
180
  }
181
181
  if (isRefAreaDimension(dim)) {
182
- return R.over(R.lensProp('rows'), R.append(dim.id))(acc);
182
+ return R.over(R.lensPath(['nextLayout','rows']), R.append(dim.id))(acc);
183
183
  }
184
- return R.over(R.lensProp('sections'), R.append(dim.id))(acc);
185
- }, layoutWithCombs, dimensions);
184
+ return R.over(R.lensProp('remaining'), R.append(dim.id))(acc);
185
+ }, { nextLayout: layoutWithCombs, remaining: [] }, dimensions);
186
+
187
+ let _remaining = remaining;
188
+ return R.pipe(
189
+ R.when(
190
+ l => R.isEmpty(l.rows) && !R.isEmpty(_remaining),
191
+ l => {
192
+ const nextL = R.over(R.lensProp('rows'), R.append(R.head(_remaining)))(l);
193
+ _remaining = R.tail(_remaining)
194
+ return nextL;
195
+ }
196
+ ),
197
+ R.when(
198
+ l => R.isEmpty(l.header) && !R.isEmpty(_remaining),
199
+ l => {
200
+ const nextL = R.over(R.lensProp('header'), R.append(R.head(_remaining)))(l);
201
+ _remaining = R.tail(_remaining)
202
+ return nextL;
203
+ }
204
+ ),
205
+ R.when(
206
+ R.always(!R.isEmpty(_remaining)),
207
+ l => {
208
+ return R.over(R.lensProp('sections'), R.flip(R.concat)(_remaining))(l);;
209
+ }
210
+ ),
211
+ )(nextLayout);
186
212
  };
@@ -288,12 +288,15 @@ export const refineLayoutSize = ({ layout, observations, limit }) => layoutIndex
288
288
 
289
289
  const [toTruncate, toRefine] = segregateLayout(isVertical)(layoutIndexes);
290
290
 
291
- const cutLength = R.pipe(
291
+ let cutLength = R.pipe(
292
292
  R.ifElse(R.identity, R.always(rowCellsCount), R.always(columnCellsCount)),
293
293
  R.divide(excess),
294
294
  Math.ceil
295
295
  )(isVertical);
296
296
 
297
+ const maxCutLength = isVertical ? rowsCount - 2 : headerValuesCount - 1;
298
+ cutLength = cutLength > maxCutLength ? maxCutLength : cutLength;
299
+
297
300
  const { truncated, extractedKeys } = truncateLayout(isVertical)(cutLength, toTruncate);
298
301
 
299
302
  const curatedObs = R.pipe(
@@ -1,8 +1,21 @@
1
1
  import { expect } from 'chai';
2
- import { injectCombinationsInLayout } from '../src/rules2/src/table/getTableLayoutIds';
2
+ import { injectCombinationsInLayout, getTableLayoutIds } from '../src/rules2/src/table/getTableLayoutIds';
3
3
 
4
4
  describe('injectCombinationsInLayout', () => {
5
- it('complete test', () => {
5
+ it('no combinations', () => {
6
+ const layoutIds = {
7
+ header: ['D1'],
8
+ sections: ['D2'],
9
+ rows: ['D3']
10
+ };
11
+ const combinations = [];
12
+ expect(injectCombinationsInLayout(combinations, layoutIds)).to.deep.equal({
13
+ header: ['D1'],
14
+ sections: ['D2'],
15
+ rows: ['D3']
16
+ });
17
+ });
18
+ it('partial start', () => {
6
19
  const layoutIds = {
7
20
  header: ['D1', 'C1', 'D2'],
8
21
  sections: ['C5', 'D5', 'D3'],
@@ -29,3 +42,72 @@ describe('injectCombinationsInLayout', () => {
29
42
  });
30
43
  });
31
44
  });
45
+
46
+ describe('getTableLayoutIds tests', () => {
47
+ it('simple case blank start', () => {
48
+ const layoutIds = {
49
+ header: [],
50
+ sections: [],
51
+ rows: []
52
+ };
53
+ const combinations = [];
54
+ const attributes = [];
55
+ const dimensions = [
56
+ { id: 'REF_AREA' },
57
+ { id: 'MEASURE' },
58
+ { id: 'REF_SECTOR' },
59
+ { id: 'TIME_PERIOD' },
60
+ ];
61
+
62
+ expect(getTableLayoutIds(layoutIds, dimensions, attributes, combinations)).to.deep.equal({
63
+ header: ['TIME_PERIOD'],
64
+ sections: ['MEASURE', 'REF_SECTOR'],
65
+ rows: ['REF_AREA']
66
+ });
67
+ });
68
+ it('blank start with combinations', () => {
69
+ const layoutIds = {
70
+ header: [],
71
+ sections: ['COMB1'],
72
+ rows: []
73
+ };
74
+ const combinations = [
75
+ {
76
+ id: 'COMB1',
77
+ concepts: ['REF_SECTOR', 'MEASURE'],
78
+ },
79
+ {
80
+ id: 'COMB2',
81
+ concepts: ['UNIT_MEASURE', 'CURRENCY'],
82
+ },
83
+ {
84
+ id: 'COMB3',
85
+ concepts: ['ATTR1', 'ATTR2'],
86
+ },
87
+ {
88
+ id: 'COMB4',
89
+ concepts: ['ATTR3', 'ATTR4']
90
+ }
91
+ ];
92
+ const dimensions = [
93
+ { id: 'REF_AREA' },
94
+ { id: 'REF_SECTOR' },
95
+ { id: 'TRANSACTION' },
96
+ { id: 'MEASURE' },
97
+ { id: 'UNIT_MEASURE' },
98
+ { id: 'CURRENCY' }
99
+ ];
100
+ const attributes = [
101
+ { id: 'ATTR1', relationship: ['MEASURE'], series: true },
102
+ { id: 'ATTR2', relationship: ['MEASURE'], series: true },
103
+ { id: 'ATTR3', relationship: [], series: true },
104
+ { id: 'ATTR4', relationship: [], series: true },
105
+ ];
106
+
107
+ expect(getTableLayoutIds(layoutIds, dimensions, attributes, combinations)).to.deep.equal({
108
+ header: ['TRANSACTION'],
109
+ sections: ['COMB1', 'COMB3'],
110
+ rows: ['COMB2', 'REF_AREA']
111
+ });
112
+ });
113
+ });
@@ -100,7 +100,7 @@ const partialObservations3 = {
100
100
  };
101
101
 
102
102
  describe('refineLayoutSize 2 tests', () => {
103
- it('no changes under limit', () => {
103
+ /*it('no changes under limit', () => {
104
104
  const layout = {
105
105
  header: [{ __index: 0 }],
106
106
  sections: [{ __index: 1 }],
@@ -335,6 +335,73 @@ describe('refineLayoutSize 2 tests', () => {
335
335
  limit: 90
336
336
  })(layoutIndexes)
337
337
  ).to.deep.equal(expected);
338
+ });*/
339
+ it('cannot fit the limit', () => {
340
+ const layout = {
341
+ header: [{ __index: 1 }],
342
+ rows: [{ __index: 0 }],
343
+ sections: [],
344
+ };
345
+
346
+ const layoutIndexes = {
347
+ header: [
348
+ { indexes: [0], parentsIndexes: [[]], missingIndexes: [[]] },
349
+ { indexes: [1], parentsIndexes: [[]], missingIndexes: [[]] },
350
+ ],
351
+ sections: [
352
+ [
353
+ { indexes: [] },
354
+ [
355
+ { indexes: [0], parentsIndexes: [[]], missingIndexes: [[]] },
356
+ { indexes: [1], parentsIndexes: [[]], missingIndexes: [[]] },
357
+ { indexes: [2], parentsIndexes: [[]], missingIndexes: [[]] },
358
+ { indexes: [3], parentsIndexes: [[]], missingIndexes: [[]] },
359
+ { indexes: [4], parentsIndexes: [[]], missingIndexes: [[]] },
360
+ { indexes: [5], parentsIndexes: [[]], missingIndexes: [[]] },
361
+ ]
362
+ ]
363
+ ]
364
+ };
365
+
366
+ const observations = {
367
+ '0:0': { orderedDimIndexes: [0, 0] },
368
+ '0:1': { orderedDimIndexes: [0, 1] },
369
+ '1:0': { orderedDimIndexes: [1, 0] },
370
+ '1:1': { orderedDimIndexes: [1, 1] },
371
+ '2:0': { orderedDimIndexes: [2, 0] },
372
+ '2:1': { orderedDimIndexes: [2, 1] },
373
+ '3:0': { orderedDimIndexes: [3, 0] },
374
+ '3:1': { orderedDimIndexes: [3, 1] },
375
+ '4:0': { orderedDimIndexes: [4, 0] },
376
+ '4:1': { orderedDimIndexes: [4, 1] },
377
+ '5:0': { orderedDimIndexes: [5, 0] },
378
+ '5:1': { orderedDimIndexes: [5, 1] },
379
+ };
380
+
381
+ const expected = {
382
+ header: [
383
+ { indexes: [0], parentsIndexes: [[]], missingIndexes: [[]] },
384
+ { indexes: [1], parentsIndexes: [[]], missingIndexes: [[]] },
385
+ ],
386
+ sections: [
387
+ [
388
+ { indexes: [] },
389
+ [
390
+ { indexes: [0], parentsIndexes: [[]], missingIndexes: [[]] },
391
+ ]
392
+ ]
393
+ ],
394
+ truncated: true,
395
+ totalCells: 31
396
+ };
397
+
398
+ expect(
399
+ refineLayoutSize({
400
+ layout,
401
+ observations,
402
+ limit: 2
403
+ })(layoutIndexes)
404
+ ).to.deep.equal(expected);
338
405
  });
339
406
  /*it('no rows', () => {
340
407