@sis-cc/dotstatsuite-components 17.28.0 → 17.29.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.
@@ -23,7 +23,8 @@ var parseAttributes = exports.parseAttributes = function parseAttributes(attribu
23
23
  var indexedDimensions = R.indexBy(R.prop('id'), dimensions);
24
24
  return R.addIndex(R.map)(function (attr, index) {
25
25
  var res = R.assoc('index', index, attr);
26
- if (R.isEmpty(attr.values || []) || !R.propOr(true, 'display', attr) || attr.id === _constants.REPORTING_YEAR_START_DAY || attr.id === _constants.REPYEARSTART) {
26
+ var displayableValuesCount = R.pipe(R.filter(R.propOr(true, 'display')), R.length)(attr);
27
+ if (R.isEmpty(attr.values || []) || !R.propOr(true, 'display', attr) || displayableValuesCount < 1 || attr.id === _constants.REPORTING_YEAR_START_DAY || attr.id === _constants.REPYEARSTART) {
27
28
  return R.assoc('display', false, res);
28
29
  }
29
30
  if (R.propEq('id', customAttributes.prefscale, attr)) {
@@ -241,7 +241,6 @@ var getLayoutData = function getLayoutData(layoutIndexes, layout, _ref) {
241
241
  sections = layoutIndexes.sections,
242
242
  rest = (0, _objectWithoutProperties3.default)(layoutIndexes, ['header', 'sections']);
243
243
 
244
-
245
244
  var headerData = R.reduce(function (acc, serie) {
246
245
  var datas = getSerieDataWithMissingLines(serie, layout.header, topCoordinates, attributesSeries, customAttributes, metadataCoordinates);
247
246
  return R.concat(acc, datas);
@@ -123,10 +123,9 @@ var injectCombinationsInLayout = exports.injectCombinationsInLayout = function i
123
123
  if (idsInRowsSet.has(id)) return R.over(R.lensIndex(1), R.append(id), _acc);
124
124
  return R.over(R.lensIndex(2), R.append(id), _acc);
125
125
  }, [[], [], []], rest),
126
- _R$reduce2 = (0, _slicedToArray3.default)(_R$reduce, 3),
126
+ _R$reduce2 = (0, _slicedToArray3.default)(_R$reduce, 2),
127
127
  idsInSections = _R$reduce2[0],
128
- idsInRows = _R$reduce2[1],
129
- nowhere = _R$reduce2[2];
128
+ idsInRows = _R$reduce2[1];
130
129
 
131
130
  if (!R.isEmpty(idsInHeader) && R.isEmpty(idsInSections) && R.isEmpty(idsInRows)) {
132
131
  layoutRelationships.header = R.concat(layoutRelationships.header, relationship);
@@ -178,7 +177,17 @@ var getLayoutCombinations = exports.getLayoutCombinations = function getLayoutCo
178
177
  }, [], combinations);
179
178
  };
180
179
 
181
- var extractConcepts = function extractConcepts(ids, indexedCombinations) {
180
+ var extractConcepts = function extractConcepts(ids, indexedCombinations, layoutDimsIds) {
181
+ var entry = R.find(function (id) {
182
+ if (R.has(id, indexedCombinations)) {
183
+ var dimId = R.find(function (i) {
184
+ return layoutDimsIds.has(i);
185
+ }, R.pathOr([], [id, 'concepts'], indexedCombinations));
186
+ return !R.isNil(dimId);
187
+ }
188
+ return true;
189
+ }, ids);
190
+
182
191
  var getRelationship = function getRelationship(id) {
183
192
  if (R.has(id, indexedCombinations)) {
184
193
  return R.append(id, R.path([id, 'relationship'], indexedCombinations));
@@ -189,7 +198,7 @@ var extractConcepts = function extractConcepts(ids, indexedCombinations) {
189
198
  return R.assoc(id, getRelationship(id), acc);
190
199
  }, {}, ids);
191
200
 
192
- var relationship = [R.head(ids)];
201
+ var relationship = [entry];
193
202
  while (!R.isEmpty(indexedRels)) {
194
203
  var related = R.pickBy(function (rels) {
195
204
  return !R.isEmpty(R.intersection(relationship, rels));
@@ -206,20 +215,31 @@ var extractConcepts = function extractConcepts(ids, indexedCombinations) {
206
215
  }, ids);
207
216
  };
208
217
 
209
- var injectRemainingDimensionsInLayout = exports.injectRemainingDimensionsInLayout = function injectRemainingDimensionsInLayout(layoutIds, remainingDims, indexedCombinations) {
218
+ var injectRemainingDimensionsInLayout = exports.injectRemainingDimensionsInLayout = function injectRemainingDimensionsInLayout(layoutIds, remainingDims, indexedCombinations, layoutDimsIds) {
210
219
  var _layout = layoutIds;
211
220
  var _remaining = remainingDims;
212
221
 
213
- if (R.isEmpty(_layout.rows)) {
222
+ var dimInRows = R.find(function (id) {
223
+ if (layoutDimsIds.has(id)) {
224
+ return true;
225
+ }
226
+ var dimId = R.find(function (i) {
227
+ return layoutDimsIds.has(i);
228
+ }, R.pathOr([], [id, 'concepts'], indexedCombinations));
229
+ return !R.isNil(dimId);
230
+ }, _layout.rows);
231
+
232
+ console.log({ dimInRows: dimInRows, layoutIds: layoutIds, indexedCombinations: indexedCombinations, layoutDimsIds: layoutDimsIds });
233
+ if (R.isNil(dimInRows)) {
214
234
  if (R.isEmpty(_remaining)) {
215
235
  var toTakeIn = R.isEmpty(_layout.sections) ? 'header' : 'sections';
216
236
 
217
- var _extractConcepts = extractConcepts(R.prop(toTakeIn, _layout), indexedCombinations),
237
+ var _extractConcepts = extractConcepts(R.prop(toTakeIn, _layout), indexedCombinations, layoutDimsIds),
218
238
  _extractConcepts2 = (0, _slicedToArray3.default)(_extractConcepts, 2),
219
239
  extracted = _extractConcepts2[0],
220
240
  remains = _extractConcepts2[1];
221
241
 
222
- _layout = (0, _extends4.default)({}, _layout, (0, _defineProperty3.default)({ rows: extracted }, toTakeIn, remains));
242
+ _layout = (0, _extends4.default)({}, _layout, (0, _defineProperty3.default)({ rows: R.concat(_layout.rows, extracted) }, toTakeIn, remains));
223
243
  } else {
224
244
  _layout = R.over(R.lensProp('rows'), R.append(R.head(_remaining)))(_layout);
225
245
  _remaining = R.tail(_remaining);
@@ -240,6 +260,7 @@ var injectRemainingDimensionsInLayout = exports.injectRemainingDimensionsInLayou
240
260
  var getTableLayoutIds = exports.getTableLayoutIds = function getTableLayoutIds(defaultLayoutIds, dimensions, attributes, combinations) {
241
261
  var layoutDimsIds = getLayoutDimsIds(dimensions);
242
262
  var layoutCombinations = getLayoutCombinations(combinations, layoutDimsIds, attributes);
263
+
243
264
  var combinationsConcepts = R.pipe(R.pluck('_concepts'), R.unnest, function (ids) {
244
265
  return new _set2.default(ids);
245
266
  })(combinations);
@@ -292,5 +313,5 @@ var getTableLayoutIds = exports.getTableLayoutIds = function getTableLayoutIds(d
292
313
  nextLayout = _R$reduce4.nextLayout,
293
314
  remaining = _R$reduce4.remaining;
294
315
 
295
- return injectRemainingDimensionsInLayout(nextLayout, remaining, indexedCombinations);
316
+ return injectRemainingDimensionsInLayout(nextLayout, remaining, indexedCombinations, layoutDimsIds);
296
317
  };
@@ -276,8 +276,12 @@ var refineLayoutSize = exports.refineLayoutSize = function refineLayoutSize(_ref
276
276
  truncated = _truncateLayout.truncated,
277
277
  extractedKeys = _truncateLayout.extractedKeys;
278
278
 
279
+ var dimsLength = R.pipe(R.values, R.head, R.propOr([], 'orderedDimIndexes'), R.length)(observations);
280
+ var _layout = R.map(R.map(function (entry) {
281
+ return entry.id === 'OBS_ATTRIBUTES' ? R.assoc('__index', dimsLength - 1, entry) : entry;
282
+ }), layout);
279
283
  var curatedObs = R.pipe(getShape, function (shape) {
280
- return getCuratedCells({ layout: layout, observations: observations, shape: shape });
284
+ return getCuratedCells({ layout: _layout, observations: observations, shape: shape });
281
285
  })(isVertical);
282
286
 
283
287
  var refined = refineLayout(isVertical)(toRefine, extractedKeys, curatedObs);
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.28.0",
4
+ "version": "17.29.0",
5
5
  "main": "lib/index.js",
6
6
  "author": "OECD",
7
7
  "license": "MIT",
@@ -5,8 +5,13 @@ export const parseAttributes = (attributes, dimensions, customAttributes) => {
5
5
  const indexedDimensions = R.indexBy(R.prop('id'), dimensions);
6
6
  return R.addIndex(R.map)((attr, index) => {
7
7
  let res = R.assoc('index', index, attr);
8
+ const displayableValuesCount = R.pipe(
9
+ R.filter(R.propOr(true, 'display')),
10
+ R.length,
11
+ )(attr);
8
12
  if (R.isEmpty(attr.values || []) || !R.propOr(true, 'display', attr)
9
- || attr.id === REPORTING_YEAR_START_DAY || attr.id === REPYEARSTART) {
13
+ || displayableValuesCount < 1 || attr.id === REPORTING_YEAR_START_DAY
14
+ || attr.id === REPYEARSTART) {
10
15
  return R.assoc('display', false, res);
11
16
  }
12
17
  if (R.propEq('id', customAttributes.prefscale, attr)) {
@@ -167,7 +167,6 @@ export const getSerieDataWithoutMissingLines = (serie, definition, topCoordinate
167
167
 
168
168
  export const getLayoutData = (layoutIndexes, layout, { metadataCoordinates, attributesSeries, customAttributes, topCoordinates={} }) => {
169
169
  const { header, sections, ...rest } = layoutIndexes;
170
-
171
170
  const headerData = R.reduce((acc, serie) => {
172
171
  const datas = getSerieDataWithMissingLines(serie, layout.header, topCoordinates, attributesSeries, customAttributes, metadataCoordinates);
173
172
  return R.concat(acc, datas);
@@ -57,7 +57,7 @@ export const injectCombinationsInLayout = (combinations, layoutIds) => {
57
57
  i => idsInHeaderSet.has(i),
58
58
  relationship
59
59
  );
60
- const [idsInSections, idsInRows, nowhere] = R.reduce((_acc, id) => {
60
+ const [idsInSections, idsInRows] = R.reduce((_acc, id) => {
61
61
  if (idsInSectionsSet.has(id))
62
62
  return R.over(R.lensIndex(0), R.append(id), _acc);
63
63
  if (idsInRowsSet.has(id))
@@ -122,7 +122,15 @@ export const getLayoutCombinations = (combinations, layoutDimsIds, attributes) =
122
122
  );
123
123
  };
124
124
 
125
- const extractConcepts = (ids, indexedCombinations) => {
125
+ const extractConcepts = (ids, indexedCombinations, layoutDimsIds) => {
126
+ const entry = R.find(id => {
127
+ if (R.has(id, indexedCombinations)) {
128
+ const dimId = R.find(i => layoutDimsIds.has(i), R.pathOr([], [id, 'concepts'], indexedCombinations));
129
+ return !R.isNil(dimId);
130
+ }
131
+ return true;
132
+ }, ids);
133
+
126
134
  const getRelationship = id => {
127
135
  if (R.has(id, indexedCombinations)) {
128
136
  return R.append(id, R.path([id, 'relationship'], indexedCombinations));
@@ -133,7 +141,7 @@ const extractConcepts = (ids, indexedCombinations) => {
133
141
  R.assoc(id, getRelationship(id), acc)
134
142
  , {}, ids);
135
143
 
136
- let relationship = [R.head(ids)];
144
+ let relationship = [entry];
137
145
  while (!R.isEmpty(indexedRels)) {
138
146
  const related = R.pickBy(rels => !R.isEmpty(R.intersection(relationship, rels)), indexedRels);
139
147
  if (R.isEmpty(related)) {
@@ -146,15 +154,24 @@ const extractConcepts = (ids, indexedCombinations) => {
146
154
  return R.partition(id => set.has(id), ids);
147
155
  }
148
156
 
149
- export const injectRemainingDimensionsInLayout = (layoutIds, remainingDims, indexedCombinations) => {
157
+ export const injectRemainingDimensionsInLayout = (layoutIds, remainingDims, indexedCombinations, layoutDimsIds) => {
150
158
  let _layout = layoutIds;
151
159
  let _remaining = remainingDims;
152
160
 
153
- if (R.isEmpty(_layout.rows)) {
161
+ const dimInRows = R.find(id => {
162
+ if (layoutDimsIds.has(id)) {
163
+ return true;
164
+ }
165
+ const dimId = R.find(i => layoutDimsIds.has(i), R.pathOr([], [id, 'concepts'], indexedCombinations));
166
+ return !R.isNil(dimId);
167
+ }, _layout.rows);
168
+
169
+ console.log({ dimInRows, layoutIds, indexedCombinations, layoutDimsIds });
170
+ if (R.isNil(dimInRows)) {
154
171
  if (R.isEmpty(_remaining)) {
155
172
  const toTakeIn = R.isEmpty(_layout.sections) ? 'header' : 'sections';
156
- const [extracted, remains] = extractConcepts(R.prop(toTakeIn, _layout), indexedCombinations);
157
- _layout = ({ ..._layout, rows: extracted, [toTakeIn]: remains });
173
+ const [extracted, remains] = extractConcepts(R.prop(toTakeIn, _layout), indexedCombinations, layoutDimsIds);
174
+ _layout = ({ ..._layout, rows: R.concat(_layout.rows, extracted), [toTakeIn]: remains });
158
175
  }
159
176
  else {
160
177
  _layout = R.over(R.lensProp('rows'), R.append(R.head(_remaining)))(_layout);
@@ -186,6 +203,7 @@ export const getTableLayoutIds = (
186
203
  layoutDimsIds,
187
204
  attributes,
188
205
  );
206
+
189
207
  const combinationsConcepts = R.pipe(R.pluck('_concepts'), R.unnest, ids => new Set(ids))(combinations);
190
208
  const obsAttributes = R.filter(a =>
191
209
  a.series && R.isEmpty(a.relationship || []) && a.display && !combinationsConcepts.has(a)
@@ -244,5 +262,5 @@ export const getTableLayoutIds = (
244
262
  return R.over(R.lensProp('remaining'), R.append(dim.id))(acc);
245
263
  }, { nextLayout: layoutWithCombs, remaining: [] }, dimensions);
246
264
 
247
- return injectRemainingDimensionsInLayout(nextLayout, remaining, indexedCombinations);
265
+ return injectRemainingDimensionsInLayout(nextLayout, remaining, indexedCombinations, layoutDimsIds);
248
266
  };
@@ -299,9 +299,14 @@ export const refineLayoutSize = ({ layout, observations, limit }) => layoutIndex
299
299
 
300
300
  const { truncated, extractedKeys } = truncateLayout(isVertical)(cutLength, toTruncate);
301
301
 
302
+ const dimsLength = R.pipe(R.values, R.head, R.propOr([], 'orderedDimIndexes'), R.length)(observations);
303
+ const _layout = R.map(
304
+ R.map(entry => entry.id === 'OBS_ATTRIBUTES' ? R.assoc('__index', dimsLength - 1, entry) : entry),
305
+ layout
306
+ );
302
307
  const curatedObs = R.pipe(
303
308
  getShape,
304
- (shape) => getCuratedCells({ layout, observations, shape })
309
+ (shape) => getCuratedCells({ layout: _layout, observations, shape })
305
310
  )(isVertical);
306
311
 
307
312
 
@@ -224,4 +224,28 @@ describe('getTableLayoutIds tests', () => {
224
224
  rows: ['D4']
225
225
  });
226
226
  });
227
+ it('nothing in rows with combination without dimensions', () => {
228
+ const combinations = [{
229
+ id: 'COMB',
230
+ concepts: ['A1', 'A2']
231
+ }];
232
+ const attributes = [
233
+ { id: 'A1', series: true, relationship: ['D1'] },
234
+ { id: 'A2', series: true, relationship: ['D1'] },
235
+ ]
236
+ const dimensions = [
237
+ { id: 'D1' },
238
+ { id: 'D2' },
239
+ ];
240
+ const layoutIds = {
241
+ header: ['D2'],
242
+ sections: ['COMB', 'D1'],
243
+ rows: ['D3']
244
+ };
245
+ expect(getTableLayoutIds(layoutIds, dimensions, attributes, combinations)).to.deep.equal({
246
+ header: ['D2'],
247
+ sections: [],
248
+ rows: ['COMB', 'D1']
249
+ });
250
+ });
227
251
  });
@@ -403,6 +403,109 @@ describe('refineLayoutSize 2 tests', () => {
403
403
  })(layoutIndexes)
404
404
  ).to.deep.equal(expected);
405
405
  });
406
+ it('truncation with OBS_ATTRIBUTES in layout', () => {
407
+ const layout = {
408
+ header: [{ __index: 1 }, { id: 'OBS_ATTRIBUTES' }],
409
+ rows: [{ __index: 0 }],
410
+ sections: [],
411
+ };
412
+
413
+ const layoutIndexes = {
414
+ header: [
415
+ { indexes: [0, 0], parentsIndexes: [[]], missingIndexes: [[]] },
416
+ { indexes: [0, 1], parentsIndexes: [[]], missingIndexes: [[]] },
417
+ { indexes: [1, 0], parentsIndexes: [[]], missingIndexes: [[]] },
418
+ { indexes: [1, 1], parentsIndexes: [[]], missingIndexes: [[]] },
419
+ ],
420
+ sections: [
421
+ [
422
+ { indexes: [] },
423
+ [
424
+ { indexes: [0], parentsIndexes: [[]], missingIndexes: [[]] },
425
+ { indexes: [1], parentsIndexes: [[]], missingIndexes: [[]] },
426
+ { indexes: [2], parentsIndexes: [[]], missingIndexes: [[]] },
427
+ { indexes: [3], parentsIndexes: [[]], missingIndexes: [[]] },
428
+ { indexes: [4], parentsIndexes: [[]], missingIndexes: [[]] },
429
+ { indexes: [5], parentsIndexes: [[]], missingIndexes: [[]] },
430
+ { indexes: [6], parentsIndexes: [[]], missingIndexes: [[]] },
431
+ { indexes: [7], parentsIndexes: [[]], missingIndexes: [[]] },
432
+ { indexes: [8], parentsIndexes: [[]], missingIndexes: [[]] },
433
+ ]
434
+ ]
435
+ ]
436
+ };
437
+
438
+ const observations = {
439
+ '0:0:0': { orderedDimIndexes: [0, 0, 0] },
440
+ '0:0:1': { orderedDimIndexes: [0, 0, 1] },
441
+ '0:1:0': { orderedDimIndexes: [0, 1, 0] },
442
+ '0:1:1': { orderedDimIndexes: [0, 1, 1] },
443
+ '1:0:0': { orderedDimIndexes: [1, 0, 0] },
444
+ '1:0:1': { orderedDimIndexes: [1, 0, 1] },
445
+ '1:1:0': { orderedDimIndexes: [1, 1, 0] },
446
+ '1:1:1': { orderedDimIndexes: [1, 1, 1] },
447
+ '2:0:0': { orderedDimIndexes: [2, 0, 0] },
448
+ '2:0:1': { orderedDimIndexes: [2, 0, 1] },
449
+ '2:1:0': { orderedDimIndexes: [2, 1, 0] },
450
+ '2:1:1': { orderedDimIndexes: [2, 1, 1] },
451
+ '3:0:0': { orderedDimIndexes: [3, 0, 0] },
452
+ '3:0:1': { orderedDimIndexes: [3, 0, 1] },
453
+ '3:1:0': { orderedDimIndexes: [3, 1, 0] },
454
+ '3:1:1': { orderedDimIndexes: [3, 1, 1] },
455
+ '4:0:0': { orderedDimIndexes: [4, 0, 0] },
456
+ '4:0:1': { orderedDimIndexes: [4, 0, 1] },
457
+ '4:1:0': { orderedDimIndexes: [4, 1, 0] },
458
+ '4:1:1': { orderedDimIndexes: [4, 1, 1] },
459
+ '5:0:0': { orderedDimIndexes: [5, 0, 0] },
460
+ '5:0:1': { orderedDimIndexes: [5, 0, 1] },
461
+ '5:1:0': { orderedDimIndexes: [5, 1, 0] },
462
+ '5:1:1': { orderedDimIndexes: [5, 1, 1] },
463
+ '6:0:0': { orderedDimIndexes: [6, 0, 0] },
464
+ '6:0:1': { orderedDimIndexes: [6, 0, 1] },
465
+ '6:1:0': { orderedDimIndexes: [6, 1, 0] },
466
+ '6:1:1': { orderedDimIndexes: [6, 1, 1] },
467
+ '7:0:0': { orderedDimIndexes: [7, 0, 0] },
468
+ '7:0:1': { orderedDimIndexes: [7, 0, 1] },
469
+ '7:1:0': { orderedDimIndexes: [7, 1, 0] },
470
+ '7:1:1': { orderedDimIndexes: [7, 1, 1] },
471
+ '8:0:0': { orderedDimIndexes: [8, 0, 0] },
472
+ '8:0:1': { orderedDimIndexes: [8, 0, 1] },
473
+ '8:1:0': { orderedDimIndexes: [8, 1, 0] },
474
+ '8:1:1': { orderedDimIndexes: [8, 1, 1] },
475
+ };
476
+
477
+ const expected = {
478
+ header: [
479
+ { indexes: [0, 0], parentsIndexes: [[]], missingIndexes: [[]] },
480
+ { indexes: [0, 1], parentsIndexes: [[]], missingIndexes: [[]] },
481
+ { indexes: [1, 0], parentsIndexes: [[]], missingIndexes: [[]] },
482
+ { indexes: [1, 1], parentsIndexes: [[]], missingIndexes: [[]] },
483
+ ],
484
+ sections: [
485
+ [
486
+ { indexes: [] },
487
+ [
488
+ { indexes: [0], parentsIndexes: [[]], missingIndexes: [[]] },
489
+ { indexes: [1], parentsIndexes: [[]], missingIndexes: [[]] },
490
+ { indexes: [2], parentsIndexes: [[]], missingIndexes: [[]] },
491
+ { indexes: [3], parentsIndexes: [[]], missingIndexes: [[]] },
492
+ { indexes: [4], parentsIndexes: [[]], missingIndexes: [[]] },
493
+ { indexes: [5], parentsIndexes: [[]], missingIndexes: [[]] },
494
+ ]
495
+ ]
496
+ ],
497
+ truncated: true,
498
+ totalCells: 70
499
+ };
500
+
501
+ expect(
502
+ refineLayoutSize({
503
+ layout,
504
+ observations,
505
+ limit: 52
506
+ })(layoutIndexes)
507
+ ).to.deep.equal(expected);
508
+ });
406
509
  /*it('no rows', () => {
407
510
 
408
511
  const layout = {