@sis-cc/dotstatsuite-components 18.0.0 → 19.0.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.
package/.gitlab-ci.yml CHANGED
@@ -5,7 +5,7 @@ stages:
5
5
  - publish
6
6
 
7
7
  variables:
8
- NODE_VERSION: node:14-alpine
8
+ NODE_VERSION: node:18-alpine
9
9
 
10
10
  setup:
11
11
  stage: setup
package/lib/app.js CHANGED
@@ -6,29 +6,16 @@ var _react2 = _interopRequireDefault(_react);
6
6
 
7
7
  var _client = require('react-dom/client');
8
8
 
9
- var _app = require('./viewer/src/app');
10
-
11
- var _app2 = _interopRequireDefault(_app);
12
-
13
- var _dotstatsuiteVisions = require('@sis-cc/dotstatsuite-visions');
14
-
15
- var _styles = require('@mui/material/styles');
16
-
17
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
10
 
19
- var theme = (0, _styles.createTheme)((0, _dotstatsuiteVisions.sisccTheme)({ rtl: 'ltr' }));
20
11
  var container = document.getElementById('root');
21
12
  var root = (0, _client.createRoot)(container);
22
13
 
23
14
  var App = function App() {
24
15
  return _react2.default.createElement(
25
- _styles.StyledEngineProvider,
26
- { injectFirst: true },
27
- _react2.default.createElement(
28
- _styles.ThemeProvider,
29
- { theme: theme },
30
- _react2.default.createElement(_app2.default, null)
31
- )
16
+ _react.StrictMode,
17
+ null,
18
+ 'I\'m not groot, I\'m component'
32
19
  );
33
20
  };
34
21
 
@@ -0,0 +1,128 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.applyHierarchicalCodesToDim = undefined;
7
+
8
+ var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');
9
+
10
+ var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
11
+
12
+ var _extends2 = require('babel-runtime/helpers/extends');
13
+
14
+ var _extends3 = _interopRequireDefault(_extends2);
15
+
16
+ var _set = require('babel-runtime/core-js/set');
17
+
18
+ var _set2 = _interopRequireDefault(_set);
19
+
20
+ var _ramda = require('ramda');
21
+
22
+ var R = _interopRequireWildcard(_ramda);
23
+
24
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
25
+
26
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
+
28
+ var addParentId = function addParentId(id, ids) {
29
+ var last = R.last(ids);
30
+ return R.append(R.isNil(last) ? id : last + '.' + id, ids);
31
+ };
32
+
33
+ var applyHierarchicalCodesToDim = function applyHierarchicalCodesToDim(hCodes, dim) {
34
+ var confirmedHierarchisedChilds = new _set2.default([]);
35
+
36
+ var indexedValues = R.reduce(function (acc, val) {
37
+ if (!val.isSelected) {
38
+ return acc;
39
+ }
40
+ return R.assoc(val.id, val, acc);
41
+ }, {}, dim.values || []);
42
+
43
+ var parseHCodes = function parseHCodes(parentsDef, parentsInDim) {
44
+ return R.reduce(function (acc, hC) {
45
+ var codeID = hC.codeID,
46
+ _hC$hierarchicalCodes = hC.hierarchicalCodes,
47
+ hierarchicalCodes = _hC$hierarchicalCodes === undefined ? [] : _hC$hierarchicalCodes;
48
+
49
+ var hasInDim = R.has(codeID, indexedValues);
50
+ var isUnconfirmed = R.length(parentsInDim) !== R.length(parentsDef);
51
+ var children = parseHCodes(R.append(codeID, parentsDef), hasInDim ? addParentId(codeID, parentsInDim) : parentsInDim)(hierarchicalCodes);
52
+ if (!hasInDim) {
53
+ return R.concat(acc, children);
54
+ }
55
+ var val = (0, _extends3.default)({}, R.prop(codeID, indexedValues), {
56
+ parents: parentsInDim,
57
+ parent: R.last(parentsInDim),
58
+ children: children
59
+ });
60
+
61
+ if (isUnconfirmed) {
62
+ val = R.assoc('unconfirmed', true, val);
63
+ return R.append(val, acc);
64
+ }
65
+ confirmedHierarchisedChilds.add(codeID);
66
+ return R.append(val, acc);
67
+ }, []);
68
+ };
69
+
70
+ var parsed = parseHCodes([], [])(hCodes);
71
+
72
+ var flattenDescendants = R.reduce(function (acc, val) {
73
+ var children = flattenDescendants(val.children || []);
74
+ return R.concat(acc, R.prepend(val, children));
75
+ }, []);
76
+
77
+ var isValid = function isValid(val) {
78
+ return !val.unconfirmed || !confirmedHierarchisedChilds.has(val.id);
79
+ };
80
+
81
+ var refineCodes = R.reduce(function (acc, hC) {
82
+ var children = hC.children,
83
+ _hC$unconfirmed = hC.unconfirmed,
84
+ unconfirmed = _hC$unconfirmed === undefined ? false : _hC$unconfirmed,
85
+ val = (0, _objectWithoutProperties3.default)(hC, ['children', 'unconfirmed']);
86
+
87
+ if (isValid(hC)) {
88
+ var _children = refineCodes(children || []);
89
+ confirmedHierarchisedChilds.add(val.id);
90
+ return R.concat(acc, R.prepend(val, _children));
91
+ }
92
+ var flatDescendants = flattenDescendants(children);
93
+ var validDescendant = R.find(isValid, flatDescendants);
94
+ if (!validDescendant) {
95
+ return acc;
96
+ }
97
+ var refined = R.pipe(R.prepend(hC), R.map(function (v) {
98
+ confirmedHierarchisedChilds.add(v.id);
99
+ return R.omit(['unconfirmed', 'children'], v);
100
+ }))(flatDescendants);
101
+ return R.concat(acc, refined);
102
+ }, []);
103
+
104
+ var refined = refineCodes(parsed);
105
+
106
+ var missingValues = R.pipe(R.keys, R.filter(function (id) {
107
+ return !confirmedHierarchisedChilds.has(id);
108
+ }), function (ids) {
109
+ return R.props(ids, indexedValues);
110
+ }, R.map(function (v) {
111
+ return (0, _extends3.default)({}, v, { parents: [], parent: undefined });
112
+ }), R.sortBy(R.propOr(-1, '__indexPosition')))(indexedValues);
113
+
114
+ var hierarchicalIndexes = {};
115
+
116
+ return R.pipe(R.concat, R.addIndex(R.map)(function (v, ind) {
117
+ var parents = R.props(v.parents, hierarchicalIndexes);
118
+ var hierId = R.last(v.parents) ? R.last(v.parents) + '.' + v.id : v.id;
119
+ hierarchicalIndexes[hierId] = ind;
120
+ return (0, _extends3.default)({}, v, {
121
+ parents: parents,
122
+ __indexPosition: ind
123
+ });
124
+ }), function (values) {
125
+ return (0, _extends3.default)({}, dim, { values: values });
126
+ })(missingValues, refined);
127
+ };
128
+ exports.applyHierarchicalCodesToDim = applyHierarchicalCodesToDim;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.hierarchiseDimensionWithAdvancedHierarchy = exports.refinePartialHierarchy = undefined;
6
+ exports.refinePartialHierarchy = undefined;
7
7
 
8
8
  var _extends2 = require('babel-runtime/helpers/extends');
9
9
 
@@ -62,39 +62,4 @@ var refinePartialHierarchy = exports.refinePartialHierarchy = function refinePar
62
62
  return (0, _extends3.default)({}, refinedBroken, intact, {
63
63
  '#ROOT': R.concat(refinedBroken['#ROOT'], intact['#ROOT'])
64
64
  });
65
- };
66
-
67
- var hierarchiseDimensionWithAdvancedHierarchy = exports.hierarchiseDimensionWithAdvancedHierarchy = function hierarchiseDimensionWithAdvancedHierarchy(dimension, _hierarchy) {
68
- var indexed = R.indexBy(R.prop('id'), dimension.values);
69
- var hierarchy = refinePartialHierarchy(_hierarchy, indexed);
70
-
71
- var rest = R.pipe(R.values, R.unnest, R.flip(R.omit)(indexed), R.values)(hierarchy);
72
- var index = R.length(rest) - 1;
73
- var getChildren = function getChildren(_ref3) {
74
- var parentsIndexes = _ref3.parentsIndexes,
75
- parentId = _ref3.parentId;
76
-
77
- var childrenIds = R.propOr([], parentId, hierarchy);
78
- var children = R.reduce(function (acc, childId) {
79
- if (!R.has(childId, indexed)) {
80
- return acc;
81
- }
82
- index = index + 1;
83
- var child = (0, _extends3.default)({}, R.prop(childId, indexed), { __indexPosition: index, parents: parentsIndexes, parent: R.isEmpty(parentsIndexes) ? undefined : R.pipe(R.split('.'), R.last)(parentId) });
84
- var descendants = getChildren({ parentsIndexes: R.append(index, parentsIndexes), parentId: R.isEmpty(parentsIndexes) ? child.id : parentId + '.' + child.id });
85
- return R.append(R.prepend(child, descendants), acc);
86
- }, [], childrenIds);
87
-
88
- return children;
89
- };
90
-
91
- return R.set(R.lensProp('values'), R.pipe(getChildren, R.flatten, function (values) {
92
- if (R.isEmpty(rest)) {
93
- return values;
94
- }
95
- var sortedRest = R.pipe(R.sortBy(R.prop('__indexPosition')), R.addIndex(R.map)(function (val, ind) {
96
- return (0, _extends3.default)({}, val, { __indexPosition: ind, parent: undefined, parents: [] });
97
- }))(rest);
98
- return R.concat(sortedRest, values);
99
- })({ parentsIndexes: [], parentId: '#ROOT' }))(dimension);
100
65
  };
@@ -114,12 +114,6 @@ Object.defineProperty(exports, 'refinePartialHierarchy', {
114
114
  return _hierarchiseDimensionWithAdvancedHierarchy.refinePartialHierarchy;
115
115
  }
116
116
  });
117
- Object.defineProperty(exports, 'hierarchiseDimensionWithAdvancedHierarchy', {
118
- enumerable: true,
119
- get: function get() {
120
- return _hierarchiseDimensionWithAdvancedHierarchy.hierarchiseDimensionWithAdvancedHierarchy;
121
- }
122
- });
123
117
 
124
118
  var _hierarchiseDimensionWithNativeHierarchy = require('./hierarchiseDimensionWithNativeHierarchy2');
125
119
 
@@ -437,4 +431,13 @@ Object.defineProperty(exports, 'declineObservationsOverAttributes', {
437
431
  get: function get() {
438
432
  return _declineObservationsOverAttributes.declineObservationsOverAttributes;
439
433
  }
434
+ });
435
+
436
+ var _applyHierarchicalCodesToDim = require('./applyHierarchicalCodesToDim');
437
+
438
+ Object.defineProperty(exports, 'applyHierarchicalCodesToDim', {
439
+ enumerable: true,
440
+ get: function get() {
441
+ return _applyHierarchicalCodesToDim.applyHierarchicalCodesToDim;
442
+ }
440
443
  });
@@ -35,8 +35,6 @@ var _getOneValueDimensions = require('./getOneValueDimensions');
35
35
 
36
36
  var _hierarchiseDimensionWithNativeHierarchy = require('./hierarchiseDimensionWithNativeHierarchy2');
37
37
 
38
- var _hierarchiseDimensionWithAdvancedHierarchy = require('./hierarchiseDimensionWithAdvancedHierarchy2');
39
-
40
38
  var _getDataflowAttributes = require('./getDataflowAttributes');
41
39
 
42
40
  var _getHeaderTitle = require('./getHeaderTitle');
@@ -47,6 +45,8 @@ var _getHeaderCombinations = require('./getHeaderCombinations');
47
45
 
48
46
  var _getHeaderCoordinates = require('./getHeaderCoordinates');
49
47
 
48
+ var _applyHierarchicalCodesToDim = require('./applyHierarchicalCodesToDim');
49
+
50
50
  function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
51
51
 
52
52
  var prepareData = exports.prepareData = function prepareData(sdmxJson, _ref) {
@@ -86,7 +86,7 @@ var prepareData = exports.prepareData = function prepareData(sdmxJson, _ref) {
86
86
  if (R.isEmpty(R.propOr({}, dim.id, hierarchies))) {
87
87
  return (0, _hierarchiseDimensionWithNativeHierarchy.hierarchiseDimensionWithNativeHierarchy)(dim);
88
88
  }
89
- return (0, _hierarchiseDimensionWithAdvancedHierarchy.hierarchiseDimensionWithAdvancedHierarchy)(dim, R.prop(dim.id, hierarchies));
89
+ return (0, _applyHierarchicalCodesToDim.applyHierarchicalCodesToDim)(R.prop(dim.id, hierarchies), dim);
90
90
  }, manyValuesDimensions);
91
91
  var duplicatedObservations = (0, _duplicateObservations.duplicateObs)(R.values(hierarchisedDimensions), enhancedObservations);
92
92
 
@@ -61,7 +61,7 @@ var parseSerieIndexesHierarchies = function parseSerieIndexesHierarchies(serieIn
61
61
  return R.over(R.lensProp('presentParentsIndexes'), function (p) {
62
62
  return R.isNil(p) ? [i] : R.append(i, p);
63
63
  }, _acc);
64
- } else if (i > previousIndex && R.pathOr(false, [dimensionIndex, 'values', i, 'isSelected'], dimensions)) {
64
+ } else if (i > previousIndex) {
65
65
  registeredIndexes.add(i);
66
66
  return R.over(R.lensProp('missingParentsIndexes'), function (m) {
67
67
  return R.isNil(m) ? [i] : R.append(i, m);
@@ -26,29 +26,11 @@ var _oecdHEALTH_PROT = require('../../../rules/test/oecd-HEALTH_PROT.json');
26
26
 
27
27
  var _oecdHEALTH_PROT2 = _interopRequireDefault(_oecdHEALTH_PROT);
28
28
 
29
- var _dotstatsuiteVisions = require('@sis-cc/dotstatsuite-visions');
30
-
31
29
  function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
32
30
 
33
31
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
34
32
 
35
- /*return (
36
- <div style={{display: 'flex', flexWrap: 'wrap'}}>
37
- {R.map(([key, value]) => (
38
- <React.Fragment key={key}>
39
- <div style={{width: value - 1, margin: 10}}>
40
- <h5>{key}: {value}px</h5>
41
- <Viewer {...rowData()} chartOptions={options} type="RowChart" />
42
- </div>
43
- <div style={{width: value - 1, margin: 10}}>
44
- <h5>{key}: {value}px</h5>
45
- <Viewer {...stackData()} chartOptions={options} type="StackedBarChart" />
46
- </div>
47
- </React.Fragment>
48
- ), R.toPairs(T4_BREAKPOINTS))}
49
- </div>
50
- );*/
51
-
33
+ //import stackData from '../../mocks/stack';
52
34
  exports.default = function (_ref) {
53
35
  var config = _ref.config,
54
36
  style = _ref.style,
@@ -75,5 +57,4 @@ exports.default = function (_ref) {
75
57
  },
76
58
  type: type
77
59
  });
78
- };
79
- //import stackData from '../../mocks/stack';
60
+ };
@@ -12,10 +12,6 @@ var _react = require('react');
12
12
 
13
13
  var _react2 = _interopRequireDefault(_react);
14
14
 
15
- var _reactHelmet = require('react-helmet');
16
-
17
- var _core = require('@blueprintjs/core');
18
-
19
15
  var _styles = require('@mui/material/styles');
20
16
 
21
17
  var _dotstatsuiteVisions = require('@sis-cc/dotstatsuite-visions');
@@ -62,9 +58,9 @@ var AppTab = function AppTab(_ref) {
62
58
  var label = _ref.label,
63
59
  iconName = _ref.iconName;
64
60
  return _react2.default.createElement(
65
- _core.Tooltip,
66
- { content: label, position: _core.Position.RIGHT },
67
- _react2.default.createElement(_core.Icon, { iconName: iconName })
61
+ Tooltip,
62
+ { content: label, position: Position.RIGHT },
63
+ _react2.default.createElement(Icon, { iconName: iconName })
68
64
  );
69
65
  };
70
66
 
@@ -149,25 +145,18 @@ exports.default = function () {
149
145
 
150
146
  */
151
147
 
152
- return _react2.default.createElement(
153
- 'div',
154
- { style: { padding: 10 } },
155
- _react2.default.createElement(_reactHelmet.Helmet, { htmlAttributes: { dir: isRtl ? 'rtl' : 'ltr' } }),
156
- _react2.default.createElement(
157
- 'button',
158
- { onClick: function onClick() {
159
- return setRtl(!isRtl);
160
- } },
161
- isRtl ? 'left to right' : 'right to left'
162
- ),
163
- _react2.default.createElement(
164
- _core.Tabs2,
165
- { renderActiveTabPanelOnly: false },
166
- _react2.default.createElement(_core.Tab2, {
167
- id: 'uc1',
168
- title: _react2.default.createElement(AppTab, { label: 'full screen resizable chart', iconName: 'fullscreen' }),
169
- panel: _react2.default.createElement(_useCase2.default, { isRtl: isRtl, config: config, style: style, options: options })
170
- })
171
- )
172
- );
148
+ return {/* <div style={{ padding: 10 }}>
149
+ <StyledEngineProvider injectFirst>
150
+ <ThemeProvider theme={theme}>
151
+ <button onClick={() => setRtl(!isRtl)}>{isRtl ? 'left to right' : 'right to left'}</button>
152
+ <Tabs2 renderActiveTabPanelOnly={false}>
153
+ <Tab2
154
+ id="uc1"
155
+ title={<AppTab label="full screen resizable chart" iconName="fullscreen" />}
156
+ panel={<UseCase1 isRtl={isRtl} config={config} style={style} options={options} />}
157
+ />
158
+ </Tabs2>
159
+ </ThemeProvider>
160
+ </StyledEngineProvider>
161
+ </div> */};
173
162
  };
package/package.json CHANGED
@@ -1,36 +1,24 @@
1
1
  {
2
2
  "name": "@sis-cc/dotstatsuite-components",
3
3
  "description": "Set components based on React.",
4
- "version": "18.0.0",
4
+ "version": "19.0.0",
5
5
  "main": "lib/index.js",
6
+ "type": "module",
6
7
  "author": "OECD",
7
8
  "license": "MIT",
8
9
  "scripts": {
9
10
  "build": "wce build",
10
11
  "start": "wce start",
11
- "test": "wce test",
12
- "demo": "wce bundle --app --relative && mv dist public"
12
+ "test": "wce test"
13
13
  },
14
14
  "devDependencies": {
15
- "@blueprintjs/core": "^1.22.0",
16
- "@mui/material": "^5.16.5",
17
- "@mui/styles": "^5.16.5",
18
- "@sis-cc/dotstatsuite-sdmxjs": "*",
19
- "@sis-cc/dotstatsuite-visions": "*",
20
- "react": "^18",
21
- "react-dom": "^18",
22
- "react-addons-css-transition-group": "^15.6.2",
23
- "react-helmet": "^5.2.1",
24
15
  "web-component-env": "^2.0.0"
25
16
  },
26
17
  "dependencies": {
27
- "@emotion/react": "^11.13.3",
28
- "@emotion/styled": "^11.13.0",
29
- "@mui/icons-material": "^5.16.5",
30
- "@mui/material": "^5.16.5",
31
- "@mui/styles": "^5.16.5",
32
18
  "@react-hook/size": "^2.1.1",
33
- "@sis-cc/dotstatsuite-d3-charts": "^8.3.0",
19
+ "@sis-cc/dotstatsuite-d3-charts": "~8.3.0",
20
+ "@sis-cc/dotstatsuite-sdmxjs": "~10.1.0",
21
+ "@sis-cc/dotstatsuite-visions": "~12.2.0",
34
22
  "date-fns": "^1.30.1",
35
23
  "lodash": "^4.17.2",
36
24
  "lodash.compose": "^2.4.1",
@@ -40,10 +28,11 @@
40
28
  "ramda": "^0.26.1"
41
29
  },
42
30
  "peerDependencies": {
43
- "@mui/icons-material": "^5.16.5",
44
- "@mui/material": "^5.16.5",
45
- "@sis-cc/dotstatsuite-sdmxjs": "^8",
46
- "@sis-cc/dotstatsuite-visions": "^9",
31
+ "@emotion/react": "^11",
32
+ "@emotion/styled": "^11",
33
+ "@mui/icons-material": "^5",
34
+ "@mui/material": "^5",
35
+ "@mui/styles": "^5",
47
36
  "react": "^18",
48
37
  "react-dom": "^18"
49
38
  }
package/src/app.js CHANGED
@@ -1,20 +1,13 @@
1
- import React from 'react';
1
+ import React, { StrictMode } from 'react';
2
2
  import { createRoot } from 'react-dom/client';
3
- import ViewerApp from './viewer/src/app';
4
- import { sisccTheme } from '@sis-cc/dotstatsuite-visions';
5
- import { ThemeProvider, StyledEngineProvider } from '@mui/material/styles';
6
- import { createTheme } from '@mui/material/styles';
7
3
 
8
- const theme = createTheme(sisccTheme({ rtl: 'ltr' }));
9
4
  const container = document.getElementById('root');
10
5
  const root = createRoot(container);
11
6
 
12
7
  const App = () => (
13
- <StyledEngineProvider injectFirst>
14
- <ThemeProvider theme={theme}>
15
- <ViewerApp />
16
- </ThemeProvider>
17
- </StyledEngineProvider>
8
+ <StrictMode>
9
+ I'm not groot, I'm component
10
+ </StrictMode>
18
11
  );
19
12
 
20
13
  root.render(<App />);
@@ -0,0 +1,101 @@
1
+ import * as R from 'ramda';
2
+
3
+ const addParentId = (id, ids) => {
4
+ const last = R.last(ids);
5
+ return R.append(R.isNil(last) ? id : `${last}.${id}`, ids);
6
+ }
7
+
8
+ export const applyHierarchicalCodesToDim = (hCodes, dim) => {
9
+ let confirmedHierarchisedChilds = new Set([]);
10
+
11
+ const indexedValues = R.reduce((acc, val) => {
12
+ if (!val.isSelected) {
13
+ return acc;
14
+ }
15
+ return R.assoc(val.id, val, acc);
16
+ }, {}, dim.values || []);
17
+
18
+ const parseHCodes = (parentsDef, parentsInDim) => R.reduce((acc, hC) => {
19
+ const { codeID, hierarchicalCodes = [] } = hC;
20
+ const hasInDim = R.has(codeID, indexedValues);
21
+ const isUnconfirmed = R.length(parentsInDim) !== R.length(parentsDef);
22
+ const children = parseHCodes(
23
+ R.append(codeID, parentsDef),
24
+ hasInDim ? addParentId(codeID, parentsInDim) : parentsInDim
25
+ )(hierarchicalCodes);
26
+ if (!hasInDim) {
27
+ return R.concat(acc, children);
28
+ }
29
+ let val = {
30
+ ...R.prop(codeID, indexedValues),
31
+ parents: parentsInDim,
32
+ parent: R.last(parentsInDim),
33
+ children
34
+ };
35
+
36
+ if (isUnconfirmed) {
37
+ val = R.assoc('unconfirmed', true, val);
38
+ return R.append(val, acc);
39
+ }
40
+ confirmedHierarchisedChilds.add(codeID);
41
+ return R.append(val, acc);
42
+ }, []);
43
+
44
+ const parsed = parseHCodes([], [])(hCodes);
45
+
46
+ const flattenDescendants = R.reduce((acc, val ) => {
47
+ const children = flattenDescendants(val.children || []);
48
+ return R.concat(acc, R.prepend(val, children));
49
+ }, []);
50
+
51
+ const isValid = val => !val.unconfirmed || !confirmedHierarchisedChilds.has(val.id);
52
+
53
+ const refineCodes = R.reduce((acc, hC) => {
54
+ const { children, unconfirmed = false, ...val } = hC;
55
+ if (isValid(hC)) {
56
+ const _children = refineCodes(children || []);
57
+ confirmedHierarchisedChilds.add(val.id);
58
+ return R.concat(acc, R.prepend(val, _children));
59
+ }
60
+ const flatDescendants = flattenDescendants(children);
61
+ const validDescendant = R.find(isValid, flatDescendants);
62
+ if (!validDescendant) {
63
+ return acc;
64
+ }
65
+ const refined = R.pipe(
66
+ R.prepend(hC),
67
+ R.map(v => {
68
+ confirmedHierarchisedChilds.add(v.id);
69
+ return R.omit(['unconfirmed', 'children'], v);
70
+ })
71
+ )(flatDescendants);
72
+ return R.concat(acc, refined);
73
+ }, []);
74
+
75
+ const refined = refineCodes(parsed);
76
+
77
+ const missingValues = R.pipe(
78
+ R.keys,
79
+ R.filter(id => !confirmedHierarchisedChilds.has(id)),
80
+ ids => R.props(ids, indexedValues),
81
+ R.map(v => ({ ...v, parents: [], parent: undefined })),
82
+ R.sortBy(R.propOr(-1, '__indexPosition')),
83
+ )(indexedValues);
84
+
85
+ let hierarchicalIndexes = {};
86
+
87
+ return R.pipe(
88
+ R.concat,
89
+ R.addIndex(R.map)((v, ind) => {
90
+ const parents = R.props(v.parents, hierarchicalIndexes);
91
+ const hierId = R.last(v.parents) ? `${R.last(v.parents)}.${v.id}` : v.id;
92
+ hierarchicalIndexes[hierId] = ind;
93
+ return {
94
+ ...v,
95
+ parents,
96
+ __indexPosition: ind
97
+ };
98
+ }),
99
+ values => ({ ...dim, values })
100
+ )(missingValues, refined);
101
+ };
@@ -55,48 +55,3 @@ export const refinePartialHierarchy = (hier, indexed) => {
55
55
  '#ROOT': R.concat(refinedBroken['#ROOT'], intact['#ROOT'])
56
56
  })
57
57
  };
58
-
59
- export const hierarchiseDimensionWithAdvancedHierarchy = (dimension, _hierarchy) => {
60
- const indexed = R.indexBy(R.prop('id'), dimension.values);
61
- const hierarchy = refinePartialHierarchy(_hierarchy, indexed);
62
-
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
- }
84
-
85
- return R.set(
86
- R.lensProp('values'),
87
- R.pipe(
88
- getChildren,
89
- R.flatten,
90
- values => {
91
- if (R.isEmpty(rest)) {
92
- return values;
93
- }
94
- const sortedRest = R.pipe(
95
- R.sortBy(R.prop('__indexPosition')),
96
- R.addIndex(R.map)((val, ind) => ({ ...val, __indexPosition: ind, parent: undefined, parents: [] })),
97
- )(rest);
98
- return R.concat(sortedRest, values);
99
- }
100
- )({ parentsIndexes: [], parentId: '#ROOT' })
101
- )(dimension);
102
- };
@@ -12,7 +12,7 @@ export { getHCodelistsRefs, getHCodelistsRefsInData } from './getHCodelistsRefsI
12
12
  export { parseHierarchicalCodelist } from './parseHierarchicalCodelist';
13
13
  export { getMetadataCoordinates } from './getMetadataCoordinates';
14
14
  export { duplicateObs } from './duplicateObservations';
15
- export { refinePartialHierarchy, hierarchiseDimensionWithAdvancedHierarchy } from './hierarchiseDimensionWithAdvancedHierarchy2';
15
+ export { refinePartialHierarchy } from './hierarchiseDimensionWithAdvancedHierarchy2';
16
16
  export { hierarchiseDimensionWithNativeHierarchy } from './hierarchiseDimensionWithNativeHierarchy2';
17
17
  export { getDimensionValuesIndexes } from './getDimensionValuesIndexes';
18
18
  export { getCombinationDefinitions, parseCombinationDefinition } from './getCombinationDefinitions';
@@ -47,3 +47,4 @@ export { parseValueHierarchy } from './table/parseValueHierarchy';
47
47
  export { parseLayoutIndexesHierarchies } from './table/parseSeriesIndexesHierarchies';
48
48
  export { getTableLayoutIds, injectCombinationsInLayout } from './table/getTableLayoutIds';
49
49
  export { declineObservationsOverAttributes } from './table/declineObservationsOverAttributes';
50
+ export { applyHierarchicalCodesToDim } from './applyHierarchicalCodesToDim';
@@ -12,12 +12,12 @@ import { getAttributesSeries } from './getAttributesSeries';
12
12
  import { getManyValuesDimensions } from './getManyValuesDimensions';
13
13
  import { getOneValueDimensions } from './getOneValueDimensions';
14
14
  import { hierarchiseDimensionWithNativeHierarchy } from './hierarchiseDimensionWithNativeHierarchy2';
15
- import { hierarchiseDimensionWithAdvancedHierarchy } from './hierarchiseDimensionWithAdvancedHierarchy2';
16
15
  import { getDataflowAttributes } from './getDataflowAttributes';
17
16
  import { getHeaderTitle } from './getHeaderTitle';
18
17
  import { getHeaderSubtitle } from './getHeaderSubtitle';
19
18
  import { getHeaderCombinations } from './getHeaderCombinations';
20
19
  import { getHeaderCoordinates } from './getHeaderCoordinates';
20
+ import { applyHierarchicalCodesToDim } from './applyHierarchicalCodesToDim';
21
21
 
22
22
  export const prepareData = (sdmxJson, { customAttributes, locale, hierarchies, dataflow, display, defaultCombinations, dataquery }) => {
23
23
  const dimensions = R.pathOr([], ['data', 'structure', 'dimensions', 'observation'], sdmxJson);
@@ -46,7 +46,7 @@ export const prepareData = (sdmxJson, { customAttributes, locale, hierarchies, d
46
46
  if (R.isEmpty(R.propOr({}, dim.id, hierarchies))) {
47
47
  return hierarchiseDimensionWithNativeHierarchy(dim);
48
48
  }
49
- return hierarchiseDimensionWithAdvancedHierarchy(dim, R.prop(dim.id, hierarchies));
49
+ return applyHierarchicalCodesToDim(R.prop(dim.id, hierarchies), dim);
50
50
  }, manyValuesDimensions)
51
51
  const duplicatedObservations = duplicateObs(R.values(hierarchisedDimensions), enhancedObservations);
52
52
 
@@ -23,7 +23,7 @@ const parseSerieIndexesHierarchies = (serieIndexes, previousSerie, dimensions, d
23
23
  if (previousRegisteredIndexes.has(i)) {
24
24
  return R.over(R.lensProp('presentParentsIndexes'), p => R.isNil(p) ? [i] : R.append(i, p), _acc);
25
25
  }
26
- else if (i > previousIndex && R.pathOr(false, [dimensionIndex, 'values', i, 'isSelected'], dimensions)) {
26
+ else if (i > previousIndex) {
27
27
  registeredIndexes.add(i);
28
28
  return R.over(R.lensProp('missingParentsIndexes'), m => R.isNil(m) ? [i] : R.append(i, m), _acc);
29
29
  }
@@ -5,24 +5,6 @@ import rowData from '../../mocks/row';
5
5
  //import stackData from '../../mocks/stack';
6
6
  import { series } from '../../../rules/src';
7
7
  import data from '../../../rules/test/oecd-HEALTH_PROT.json';
8
- import { T4_BREAKPOINTS } from '@sis-cc/dotstatsuite-visions';
9
-
10
- /*return (
11
- <div style={{display: 'flex', flexWrap: 'wrap'}}>
12
- {R.map(([key, value]) => (
13
- <React.Fragment key={key}>
14
- <div style={{width: value - 1, margin: 10}}>
15
- <h5>{key}: {value}px</h5>
16
- <Viewer {...rowData()} chartOptions={options} type="RowChart" />
17
- </div>
18
- <div style={{width: value - 1, margin: 10}}>
19
- <h5>{key}: {value}px</h5>
20
- <Viewer {...stackData()} chartOptions={options} type="StackedBarChart" />
21
- </div>
22
- </React.Fragment>
23
- ), R.toPairs(T4_BREAKPOINTS))}
24
- </div>
25
- );*/
26
8
 
27
9
  export default ({ config, style, options }) => {
28
10
  const type = 'StackedRowChart';
@@ -1,6 +1,4 @@
1
1
  import React, { useState } from 'react';
2
- import { Helmet } from 'react-helmet';
3
- import { Tab2, Tabs2, Intent, Icon, Tooltip, Position } from '@blueprintjs/core';
4
2
  import { ThemeProvider, StyledEngineProvider } from '@mui/material/styles';
5
3
  import { createTheme } from '@mui/material/styles';
6
4
  import { sisccTheme } from '@sis-cc/dotstatsuite-visions';
@@ -100,10 +98,9 @@ export default () => {
100
98
  */
101
99
 
102
100
  return (
103
- <div style={{ padding: 10 }}>
104
- {/* <StyledEngineProvider injectFirst>
105
- <ThemeProvider theme={theme}> */}
106
- <Helmet htmlAttributes={{ dir: isRtl ? 'rtl' : 'ltr' }} />
101
+ {/* <div style={{ padding: 10 }}>
102
+ <StyledEngineProvider injectFirst>
103
+ <ThemeProvider theme={theme}>
107
104
  <button onClick={() => setRtl(!isRtl)}>{isRtl ? 'left to right' : 'right to left'}</button>
108
105
  <Tabs2 renderActiveTabPanelOnly={false}>
109
106
  <Tab2
@@ -112,8 +109,8 @@ export default () => {
112
109
  panel={<UseCase1 isRtl={isRtl} config={config} style={style} options={options} />}
113
110
  />
114
111
  </Tabs2>
115
- {/* </ThemeProvider>
116
- </StyledEngineProvider> */}
117
- </div>
112
+ </ThemeProvider>
113
+ </StyledEngineProvider>
114
+ </div> */}
118
115
  );
119
116
  };
@@ -0,0 +1,147 @@
1
+ import { applyHierarchicalCodesToDim } from '../src/rules2/src/applyHierarchicalCodesToDim';
2
+ import { expect } from 'chai';
3
+ import * as R from 'ramda';
4
+
5
+ const hCodes = [
6
+ { codeID: 'PARENT_A', hierarchicalCodes: [
7
+ { codeID: 'ITEM', hierarchicalCodes: [
8
+ { codeID: 'CHILD_A', hierarchicalCodes: [] },
9
+ { codeID: 'CHILD_B', hierarchicalCodes: [] },
10
+ ] },
11
+ { codeID: 'BROTHER_A', hierarchicalCodes: [] },
12
+ ] },
13
+ { codeID: 'PARENT_B', hierarchicalCodes: [
14
+ { codeID: 'ITEM', hierarchicalCodes: [
15
+ { codeID: 'CHILD_A', hierarchicalCodes: [] },
16
+ { codeID: 'CHILD_C', hierarchicalCodes: [] },
17
+ ] },
18
+ { codeID: 'BROTHER_B', hierarchicalCodes: [] },
19
+ ] },
20
+ ];
21
+
22
+ const dim = {
23
+ id: 'DIM',
24
+ values: [
25
+ { id: 'PARENT_A', isSelected: true },
26
+ { id: 'PARENT_B', isSelected: true },
27
+ { id: 'ITEM', isSelected: true },
28
+ { id: 'BROTHER_A', isSelected: true },
29
+ { id: 'BROTHER_B', isSelected: true },
30
+ { id: 'CHILD_A', isSelected: true },
31
+ { id: 'CHILD_B', isSelected: true },
32
+ { id: 'CHILD_C', isSelected: true },
33
+ ]
34
+ };
35
+
36
+ const deselectedDim = (indexes) => R.over(
37
+ R.lensProp('values'),
38
+ R.addIndex(R.map)((v, i) => R.includes(i, indexes) ? { ...v, isSelected: false } : v)
39
+ )(dim);
40
+
41
+ describe('refineHierarchicalCodelist tests', () => {
42
+ it('complete test', () => {
43
+ const expected = {
44
+ id: 'DIM',
45
+ values: [
46
+ { id: 'PARENT_A', parents: [], parent: undefined, isSelected: true, __indexPosition: 0 },
47
+ { id: 'ITEM', parents: [0], parent: 'PARENT_A', isSelected: true, __indexPosition: 1 },
48
+ { id: 'CHILD_A', parents: [0, 1], parent: 'PARENT_A.ITEM', isSelected: true, __indexPosition: 2 },
49
+ { id: 'CHILD_B', parents: [0, 1], parent: 'PARENT_A.ITEM', isSelected: true, __indexPosition: 3 },
50
+ { id: 'BROTHER_A', parents: [0], parent: 'PARENT_A', isSelected: true, __indexPosition: 4 },
51
+ { id: 'PARENT_B', parents: [], parent: undefined, isSelected: true, __indexPosition: 5 },
52
+ { id: 'ITEM', parents: [5], parent: 'PARENT_B', isSelected: true, __indexPosition: 6 },
53
+ { id: 'CHILD_A', parents: [5, 6], parent: 'PARENT_B.ITEM', isSelected: true, __indexPosition: 7 },
54
+ { id: 'CHILD_C', parents: [5, 6], parent: 'PARENT_B.ITEM', isSelected: true, __indexPosition: 8 },
55
+ { id: 'BROTHER_B', parents: [5], parent: 'PARENT_B', isSelected: true, __indexPosition: 9 },
56
+ ]
57
+ };
58
+
59
+ expect(applyHierarchicalCodesToDim(hCodes, dim)).to.deep.equal(expected);
60
+ });
61
+ it('partial test 1', () => {
62
+ const partialDim = deselectedDim([0]);
63
+
64
+ const expected = {
65
+ id: 'DIM',
66
+ values: [
67
+ { id: 'ITEM', parents: [], parent: undefined, isSelected: true, __indexPosition: 0 },
68
+ { id: 'CHILD_A', parents: [0], parent: 'ITEM', isSelected: true, __indexPosition: 1 },
69
+ { id: 'CHILD_B', parents: [0], parent: 'ITEM', isSelected: true, __indexPosition: 2 },
70
+ { id: 'BROTHER_A', parents: [], parent: undefined, isSelected: true, __indexPosition: 3 },
71
+ { id: 'PARENT_B', parents: [], parent: undefined, isSelected: true, __indexPosition: 4 },
72
+ { id: 'ITEM', parents: [4], parent: 'PARENT_B', isSelected: true, __indexPosition: 5 },
73
+ { id: 'CHILD_A', parents: [4, 5], parent: 'PARENT_B.ITEM', isSelected: true, __indexPosition: 6 },
74
+ { id: 'CHILD_C', parents: [4, 5], parent: 'PARENT_B.ITEM', isSelected: true, __indexPosition: 7 },
75
+ { id: 'BROTHER_B', parents: [4], parent: 'PARENT_B', isSelected: true, __indexPosition: 8 },
76
+ ]
77
+ };
78
+
79
+ expect(applyHierarchicalCodesToDim(hCodes, partialDim)).to.deep.equal(expected);
80
+ });
81
+ it('partial test 2', () => {
82
+ const partialDim = deselectedDim([1, 4, 7]);
83
+
84
+ const expected = {
85
+ id: 'DIM',
86
+ values: [
87
+ { id: 'PARENT_A', parents: [], parent: undefined, isSelected: true, __indexPosition: 0 },
88
+ { id: 'ITEM', parents: [0], parent: 'PARENT_A', isSelected: true, __indexPosition: 1 },
89
+ { id: 'CHILD_A', parents: [0, 1], parent: 'PARENT_A.ITEM', isSelected: true, __indexPosition: 2 },
90
+ { id: 'CHILD_B', parents: [0, 1], parent: 'PARENT_A.ITEM', isSelected: true, __indexPosition: 3 },
91
+ { id: 'BROTHER_A', parents: [0], parent: 'PARENT_A', isSelected: true, __indexPosition: 4 },
92
+ ]
93
+ };
94
+
95
+ expect(applyHierarchicalCodesToDim(hCodes, partialDim)).to.deep.equal(expected);
96
+ });
97
+ it('partial test 3', () => {
98
+ const partialDim = deselectedDim([0, 6]);
99
+
100
+ const expected = {
101
+ id: 'DIM',
102
+ values: [
103
+ { id: 'BROTHER_A', parents: [], parent: undefined, isSelected: true, __indexPosition: 0 },
104
+ { id: 'PARENT_B', parents: [], parent: undefined, isSelected: true, __indexPosition: 1 },
105
+ { id: 'ITEM', parents: [1], parent: 'PARENT_B', isSelected: true, __indexPosition: 2 },
106
+ { id: 'CHILD_A', parents: [1, 2], parent: 'PARENT_B.ITEM', isSelected: true, __indexPosition: 3 },
107
+ { id: 'CHILD_C', parents: [1, 2], parent: 'PARENT_B.ITEM', isSelected: true, __indexPosition: 4 },
108
+ { id: 'BROTHER_B', parents: [1], parent: 'PARENT_B', isSelected: true, __indexPosition: 5 },
109
+ ]
110
+ };
111
+
112
+ expect(applyHierarchicalCodesToDim(hCodes, partialDim)).to.deep.equal(expected);
113
+ });
114
+ it('partial test 4', () => {
115
+ const partialDim = deselectedDim([6]);
116
+
117
+ const expected = {
118
+ id: 'DIM',
119
+ values: [
120
+ { id: 'PARENT_A', parents: [], parent: undefined, isSelected: true, __indexPosition: 0 },
121
+ { id: 'ITEM', parents: [0], parent: 'PARENT_A', isSelected: true, __indexPosition: 1 },
122
+ { id: 'CHILD_A', parents: [0, 1], parent: 'PARENT_A.ITEM', isSelected: true, __indexPosition: 2 },
123
+ { id: 'BROTHER_A', parents: [0], parent: 'PARENT_A', isSelected: true, __indexPosition: 3 },
124
+ { id: 'PARENT_B', parents: [], parent: undefined, isSelected: true, __indexPosition: 4 },
125
+ { id: 'ITEM', parents: [4], parent: 'PARENT_B', isSelected: true, __indexPosition: 5 },
126
+ { id: 'CHILD_A', parents: [4, 5], parent: 'PARENT_B.ITEM', isSelected: true, __indexPosition: 6 },
127
+ { id: 'CHILD_C', parents: [4, 5], parent: 'PARENT_B.ITEM', isSelected: true, __indexPosition: 7 },
128
+ { id: 'BROTHER_B', parents: [4], parent: 'PARENT_B', isSelected: true, __indexPosition: 8 },
129
+ ]
130
+ };
131
+
132
+ expect(applyHierarchicalCodesToDim(hCodes, partialDim)).to.deep.equal(expected);
133
+ });
134
+ it('partial test 5', () => {
135
+ const partialDim = deselectedDim([0, 1, 2, 3, 4]);
136
+
137
+ const expected = {
138
+ id: 'DIM',
139
+ values: [
140
+ { id: 'CHILD_A', parents: [], parent: undefined, isSelected: true, __indexPosition: 0 },
141
+ { id: 'CHILD_B', parents: [], parent: undefined, isSelected: true, __indexPosition: 1 },
142
+ { id: 'CHILD_C', parents: [], parent: undefined, isSelected: true, __indexPosition: 2 },
143
+ ]
144
+ };
145
+ expect(applyHierarchicalCodesToDim(hCodes, partialDim)).to.deep.equal(expected);
146
+ });
147
+ });
@@ -1,4 +1,3 @@
1
- import * as R from 'ramda';
2
1
  import { expect } from 'chai';
3
2
  import { parseSeriesIndexesHierarchies } from '../src/rules2/src/table/parseSeriesIndexesHierarchies';
4
3
 
@@ -29,43 +28,6 @@ describe('parseSeriesIndexesHierarchies tests', () => {
29
28
  { indexes: [4], parentsIndexes: [[]], missingIndexes: [[]], registeredIndexes: [new Set([2, 3, 4])] },
30
29
  ])
31
30
  });
32
- it('more complex stuff', () => {
33
- const dimensions = [
34
- {
35
- id: 'D0',
36
- values: [
37
- { id: 'v0' },
38
- { id: 'v1' },
39
- { id: 'v2' },
40
- { id: 'v3' },
41
- { id: 'v4' },
42
- ]
43
- },
44
- {
45
- id: 'D1',
46
- values: [
47
- { id: 'W', isSelected: true },
48
- { id: 'NA', parents: [0], isSelected: false },
49
- { id: 'A', parents: [0, 1], isSelected: true },
50
- { id: 'USA', parents: [0, 1, 2], isSelected: true },
51
- { id: 'CAN', parents: [0, 1, 2], isSelected: true },
52
- { id: 'MEX', parents: [0, 1, 2], isSelected: true }
53
- ]
54
- }
55
- ];
56
-
57
- const seriesIndexes = [
58
- [0, 3],
59
- [0, 4],
60
- [1, 5]
61
- ];
62
-
63
- expect(parseSeriesIndexesHierarchies(seriesIndexes, dimensions)).to.deep.equal([
64
- { indexes: [0, 3], parentsIndexes: [[], []], missingIndexes: [[], [0, 2]], registeredIndexes: [new Set([0]), new Set([0, 2, 3])] },
65
- { indexes: [0, 4], parentsIndexes: [[], [0, 2]], missingIndexes: [[], []], registeredIndexes: [new Set([0]), new Set([0, 2, 3, 4])] },
66
- { indexes: [1, 5], parentsIndexes: [[], []], missingIndexes: [[], [0, 2]], registeredIndexes: [new Set([0, 1]), new Set([0, 2, 5])] },
67
- ])
68
- });
69
31
  it('with combination', () => {
70
32
  const dimensions = [
71
33
  {
@@ -102,56 +64,4 @@ describe('parseSeriesIndexesHierarchies tests', () => {
102
64
  { indexes: [[0, 1]], parentsIndexes: [[[], [0]]], missingIndexes: [[[], []]], registeredIndexes: [[new Set([0]), new Set([0, 1])]] },
103
65
  ])
104
66
  });
105
- it('combinations and inversed dimension', () => {
106
- const dimensions = [
107
- {
108
- id: 'D',
109
- values: [
110
- { id: 'A' },
111
- { id: 'B' },
112
- { id: 'C' }
113
- ]
114
- },
115
- {
116
- id: 'COMB',
117
- dimensions: [{
118
- values: [
119
- { id: 'v0' },
120
- { id: 'v1' },
121
- { id: 'v2' },
122
- { id: 'v3' },
123
- { id: 'v4' },
124
- ]
125
- },
126
- {
127
- values: [
128
- { id: 'W', isSelected: true },
129
- { id: 'NA', parents: [0], isSelected: false },
130
- { id: 'A', parents: [0, 1], isSelected: true },
131
- { id: 'USA', parents: [0, 1, 2], isSelected: true },
132
- { id: 'CAN', parents: [0, 1, 2], isSelected: true },
133
- { id: 'MEX', parents: [0, 1, 2], isSelected: true }
134
- ]
135
- }]
136
- },
137
- ];
138
-
139
- const seriesIndexes = [
140
- [-2, [0, 2]],
141
- [-2, [0, 3]],
142
- [-1, [0, 2]],
143
- [-1, [0, 3]],
144
- [0, [0, 2]],
145
- [0, [0, 3]],
146
- ];
147
-
148
- expect(parseSeriesIndexesHierarchies(seriesIndexes, dimensions)).to.deep.equal([
149
- { indexes: [-2, [0, 2]], parentsIndexes: [[], [[], []]], missingIndexes: [[], [[], [0]]], registeredIndexes: [new Set([2]), [new Set([0]), new Set([0, 2])]] },
150
- { indexes: [-2, [0, 3]], parentsIndexes: [[], [[], [0, 2]]], missingIndexes: [[], [[], []]], registeredIndexes: [new Set([2]), [new Set([0]), new Set([0, 2, 3])]] },
151
- { indexes: [-1, [0, 2]], parentsIndexes: [[], [[], []]], missingIndexes: [[], [[], [0]]], registeredIndexes: [new Set([1, 2]), [new Set([0]), new Set([0, 2])]] },
152
- { indexes: [-1, [0, 3]], parentsIndexes: [[], [[], [0, 2]]], missingIndexes: [[], [[], []]], registeredIndexes: [new Set([1, 2]), [new Set([0]), new Set([0, 2, 3])]] },
153
- { indexes: [0, [0, 2]], parentsIndexes: [[], [[], []]], missingIndexes: [[], [[], [0]]], registeredIndexes: [new Set([0, 1, 2]), [new Set([0]), new Set([0, 2])]] },
154
- { indexes: [0, [0, 3]], parentsIndexes: [[], [[], [0, 2]]], missingIndexes: [[], [[], []]], registeredIndexes: [new Set([0, 1, 2]), [new Set([0]), new Set([0, 2, 3])]] },
155
- ])
156
- })
157
67
  });
@@ -1,159 +0,0 @@
1
- import { expect } from 'chai';
2
- import { hierarchiseDimensionWithAdvancedHierarchy } from '../src/rules2/src/hierarchiseDimensionWithAdvancedHierarchy2';
3
-
4
- describe('hierarchiseDimensionWithAdvancedHierarchy tests', () => {
5
- it('basic test', () => {
6
- const dimension = {
7
- id: 'test',
8
- values: [
9
- { id: 'FRA' },
10
- { id: 'GER' },
11
- { id: 'OECD' },
12
- { id: 'USA' },
13
- { id: 'A' },
14
- { id: 'EA' },
15
- { id: 'MEX' },
16
- ]
17
- };
18
-
19
- const hierarchy = {
20
- '#ROOT': ['OECD', 'A', 'EA'],
21
- OECD: ['GER', 'FRA', 'USA'],
22
- A: ['USA', 'MEX'],
23
- EA: ['FRA', 'GER']
24
- };
25
-
26
- const hierarchised = {
27
- id: 'test',
28
- values: [
29
- { id: 'OECD', parent: undefined, parents: [], __indexPosition: 0 },
30
- { id: 'GER', parent: 'OECD', parents: [0], __indexPosition: 1 },
31
- { id: 'FRA', parent: 'OECD', parents: [0], __indexPosition: 2 },
32
- { id: 'USA', parent: 'OECD', parents: [0], __indexPosition: 3 },
33
- { id: 'A', parent: undefined, parents: [], __indexPosition: 4 },
34
- { id: 'USA', parent: 'A', parents: [4], __indexPosition: 5 },
35
- { id: 'MEX', parent: 'A', parents: [4], __indexPosition: 6 },
36
- { id: 'EA', parent: undefined, parents: [], __indexPosition: 7 },
37
- { id: 'FRA', parent: 'EA', parents: [7], __indexPosition: 8 },
38
- { id: 'GER', parent: 'EA', parents: [7], __indexPosition: 9 },
39
- ]
40
- }
41
-
42
- expect(hierarchiseDimensionWithAdvancedHierarchy(dimension, hierarchy)).to.deep.equal(hierarchised);
43
- });
44
- it('missing ids defined in the hierarchy', () => {
45
- const hierarchy = {
46
- '#ROOT': ['W'],
47
- W: ['EA', 'A'],
48
- 'W.A': ['NA', 'SA'],
49
- 'W.A.NA': ['USA', 'CAN'],
50
- 'W.A.SA': ['BRA'],
51
- 'W.EA': ['FRA', 'GER'],
52
- 'W.EA.FRA': ['IDF', 'BRE', 'ALS']
53
- };
54
-
55
- const dimension = {
56
- id: 'test',
57
- values: [
58
- { id: 'IDF', __indexPosition: 0 },
59
- { id: 'CAN', __indexPosition: 1 },
60
- { id: 'USA', __indexPosition: 2 },
61
- { id: 'AFK', __indexPosition: 3 },
62
- { id: 'GER', __indexPosition: 4 },
63
- { id: 'FRA', __indexPosition: 5 },
64
- { id: 'EA', __indexPosition: 6 },
65
- { id: 'A', __indexPosition: 7 },
66
- { id: 'W', __indexPosition: 8 },
67
- ]
68
- };
69
-
70
- const hierarchised = {
71
- id: 'test',
72
- values: [
73
- { id: 'AFK', parent: undefined, parents: [], __indexPosition: 0 },
74
- { id: 'USA', parent: undefined, parents: [], __indexPosition: 1 },
75
- { id: 'CAN', parent: undefined, parents: [], __indexPosition: 2 },
76
- { id: 'W', parent: undefined, parents: [], __indexPosition: 3 },
77
- { id: 'EA', parent: 'W', parents: [3], __indexPosition: 4 },
78
- { id: 'FRA', parent: 'EA', parents: [3, 4], __indexPosition: 5 },
79
- { id: 'IDF', parent: 'FRA', parents: [3, 4, 5], __indexPosition: 6 },
80
- { id: 'GER', parent: 'EA', parents: [3, 4], __indexPosition: 7 },
81
- { id: 'A', parent: 'W', parents: [3], __indexPosition: 8 },
82
- ]
83
- };
84
-
85
- expect(hierarchiseDimensionWithAdvancedHierarchy(dimension, hierarchy)).to.deep.equal(hierarchised);
86
- });
87
- it('partial deep hierarchy', () => {
88
- const hierarchy = {
89
- '#ROOT': ['W'],
90
- 'W': ['OECD', 'UE'],
91
- 'W.OECD': ['USA', 'FRA'],
92
- 'W.OECD.USA': ['NY', 'SF', 'LA'],
93
- 'W.OECD.FRA': ['IDF'],
94
- 'W.UE': ['FRA', 'GER'],
95
- 'W.UE.FRA': ['IDF'],
96
- 'W.UE.GER': ['BER'],
97
- };
98
- const dimension = {
99
- id: 'test',
100
- values: [
101
- { id: 'OECD' },
102
- { id: 'UE' },
103
- { id: 'USA' },
104
- { id: 'FRA' },
105
- { id: 'GER' },
106
- { id: 'NY' },
107
- { id: 'SF' },
108
- { id: 'LA' },
109
- { id: 'IDF' },
110
- { id: 'BER' },
111
- ]
112
- };
113
-
114
- const expected = {
115
- id: 'test',
116
- values: [
117
- { id: 'OECD', parents: [], parent: undefined, __indexPosition: 0 },
118
- { id: 'USA', parents: [0], parent: 'OECD', __indexPosition: 1 },
119
- { id: 'NY', parents: [0, 1], parent: 'USA', __indexPosition: 2 },
120
- { id: 'SF', parents: [0, 1], parent: 'USA', __indexPosition: 3 },
121
- { id: 'LA', parents: [0, 1], parent: 'USA', __indexPosition: 4 },
122
- { id: 'FRA', parents: [0], parent: 'OECD', __indexPosition: 5 },
123
- { id: 'IDF', parents: [0, 5], parent: 'FRA', __indexPosition: 6 },
124
- { id: 'UE', parents: [], parent: undefined, __indexPosition: 7 },
125
- { id: 'FRA', parents: [7], parent: 'UE', __indexPosition: 8 },
126
- { id: 'IDF', parents: [7, 8], parent: 'FRA', __indexPosition: 9 },
127
- { id: 'GER', parents: [7], parent: 'UE', __indexPosition: 10 },
128
- { id: 'BER', parents: [7, 10], parent: 'GER', __indexPosition: 11 },
129
- ]
130
- };
131
-
132
- expect(hierarchiseDimensionWithAdvancedHierarchy(dimension, hierarchy)).to.deep.equal(expected);
133
- });
134
- it('non duplicates case 1', () => {
135
- const hierarchy = {
136
- '#ROOT': ['ONU', 'OECD'],
137
- 'OECD': ['FRA', 'USA'],
138
- 'ONU': ['USA', 'FRA'],
139
- };
140
-
141
- const dimension = {
142
- id: 'REF_AREA',
143
- values: [
144
- { id: 'FRA' },
145
- { id: 'USA' }
146
- ]
147
- };
148
-
149
- const expected = {
150
- id: 'REF_AREA',
151
- values: [
152
- { id: 'FRA', parents: [], parent: undefined, __indexPosition: 0 },
153
- { id: 'USA', parents: [], parent: undefined, __indexPosition: 1 }
154
- ]
155
- };
156
-
157
- expect(hierarchiseDimensionWithAdvancedHierarchy(dimension, hierarchy)).to.deep.equal(expected);
158
- });
159
- });