@sis-cc/dotstatsuite-components 22.6.0 → 23.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.
Files changed (194) hide show
  1. package/dist/bridge-d3-react/src/index.js +1 -2
  2. package/dist/bridge-d3-react/src/index.js.map +1 -1
  3. package/dist/rules/src/chart/getChartOptions.js +1 -1
  4. package/dist/rules/src/chart/getChartOptions.js.map +1 -1
  5. package/dist/rules/src/constants.js +1 -35
  6. package/dist/rules/src/constants.js.map +1 -1
  7. package/dist/rules/src/dimension-utils.js +26 -24
  8. package/dist/rules/src/dimension-utils.js.map +1 -1
  9. package/dist/rules/src/factories/choro-series.js +43 -32
  10. package/dist/rules/src/factories/choro-series.js.map +1 -1
  11. package/dist/rules/src/factories/focus.js +20 -0
  12. package/dist/rules/src/factories/focus.js.map +1 -0
  13. package/dist/rules/src/factories/getChartSeries.js +11 -0
  14. package/dist/rules/src/factories/getChartSeries.js.map +1 -0
  15. package/dist/rules/src/factories/sample-focus.js +14 -18
  16. package/dist/rules/src/factories/sample-focus.js.map +1 -1
  17. package/dist/rules/src/factories/sample-series.js +20 -20
  18. package/dist/rules/src/factories/sample-series.js.map +1 -1
  19. package/dist/rules/src/factories/scatter-focus.js +21 -35
  20. package/dist/rules/src/factories/scatter-focus.js.map +1 -1
  21. package/dist/rules/src/factories/scatter-series.js +5 -5
  22. package/dist/rules/src/factories/scatter-series.js.map +1 -1
  23. package/dist/rules/src/factories/series.js +48 -0
  24. package/dist/rules/src/factories/series.js.map +1 -0
  25. package/dist/rules/src/factories/stacked-series.js +6 -7
  26. package/dist/rules/src/factories/stacked-series.js.map +1 -1
  27. package/dist/rules/src/factories/symbol-series.js +39 -46
  28. package/dist/rules/src/factories/symbol-series.js.map +1 -1
  29. package/dist/rules/src/factories/timeline-focus.js +10 -14
  30. package/dist/rules/src/factories/timeline-focus.js.map +1 -1
  31. package/dist/rules/src/factories/timeline-series.js +37 -41
  32. package/dist/rules/src/factories/timeline-series.js.map +1 -1
  33. package/dist/rules/src/get-values-enhanced.js +6 -0
  34. package/dist/rules/src/get-values-enhanced.js.map +1 -1
  35. package/dist/rules/src/index.js +6 -371
  36. package/dist/rules/src/index.js.map +1 -1
  37. package/dist/rules/src/layout.js +4 -2
  38. package/dist/rules/src/layout.js.map +1 -1
  39. package/dist/rules/src/observation-formater.js +8 -14
  40. package/dist/rules/src/observation-formater.js.map +1 -1
  41. package/dist/rules/src/properties/focus.js +51 -3
  42. package/dist/rules/src/properties/focus.js.map +1 -1
  43. package/dist/rules/src/properties/getHeaderProps.js +2 -53
  44. package/dist/rules/src/properties/getHeaderProps.js.map +1 -1
  45. package/dist/rules/src/properties/index.js +3 -94
  46. package/dist/rules/src/properties/index.js.map +1 -1
  47. package/dist/rules/src/properties/linear.js +4 -4
  48. package/dist/rules/src/properties/linear.js.map +1 -1
  49. package/dist/rules/src/properties/scatter.js +4 -4
  50. package/dist/rules/src/properties/scatter.js.map +1 -1
  51. package/dist/rules/src/properties/stacked.js +5 -7
  52. package/dist/rules/src/properties/stacked.js.map +1 -1
  53. package/dist/rules/src/properties/symbol.js.map +1 -1
  54. package/dist/rules/src/properties/utils.js +11 -12
  55. package/dist/rules/src/properties/utils.js.map +1 -1
  56. package/dist/rules/src/sdmx-data/index.js +2 -27
  57. package/dist/rules/src/sdmx-data/index.js.map +1 -1
  58. package/dist/rules2/src/combinedValuesDisplay.js +2 -2
  59. package/dist/rules2/src/combinedValuesDisplay.js.map +1 -1
  60. package/dist/rules2/src/getAttributes.js +37 -0
  61. package/dist/rules2/src/getAttributes.js.map +1 -0
  62. package/dist/rules2/src/getDataflowTooltipAttributesIds.js +2 -2
  63. package/dist/rules2/src/getDataflowTooltipAttributesIds.js.map +1 -1
  64. package/dist/rules2/src/getHeaderCombinations.js +1 -1
  65. package/dist/rules2/src/getHeaderCombinations.js.map +1 -1
  66. package/dist/rules2/src/getHeaderSubtitle.js +1 -1
  67. package/dist/rules2/src/getHeaderSubtitle.js.map +1 -1
  68. package/dist/rules2/src/getHeaderTitle.js +1 -1
  69. package/dist/rules2/src/getHeaderTitle.js.map +1 -1
  70. package/dist/rules2/src/getMetadataCoordinates.js +1 -1
  71. package/dist/rules2/src/getMetadataCoordinates.js.map +1 -1
  72. package/dist/rules2/src/getNotDisplayedIds.js +1 -1
  73. package/dist/rules2/src/getNotDisplayedIds.js.map +1 -1
  74. package/dist/rules2/src/index.js +1 -0
  75. package/dist/rules2/src/index.js.map +1 -1
  76. package/dist/rules2/src/parseAttributes.js +2 -2
  77. package/dist/rules2/src/parseAttributes.js.map +1 -1
  78. package/dist/rules2/src/parseHierarchicalCodelist.js +1 -1
  79. package/dist/rules2/src/parseHierarchicalCodelist.js.map +1 -1
  80. package/dist/rules2/src/parseMetadataSeries.js +1 -1
  81. package/dist/rules2/src/parseMetadataSeries.js.map +1 -1
  82. package/dist/rules2/src/prepareData.js +10 -3
  83. package/dist/rules2/src/prepareData.js.map +1 -1
  84. package/dist/rules2/src/refineDimensions.js +53 -8
  85. package/dist/rules2/src/refineDimensions.js.map +1 -1
  86. package/dist/rules2/src/table/getCells.js +1 -1
  87. package/dist/rules2/src/table/getCells.js.map +1 -1
  88. package/dist/rules2/src/table/getLayout.js +1 -1
  89. package/dist/rules2/src/table/getLayout.js.map +1 -1
  90. package/dist/rules2/src/table/getTableLayoutIds.js +1 -1
  91. package/dist/rules2/src/table/getTableLayoutIds.js.map +1 -1
  92. package/dist/rules2/src/table/getTableProps.js +0 -1
  93. package/dist/rules2/src/table/getTableProps.js.map +1 -1
  94. package/dist/rules2/src/table/parseValueHierarchy.js.map +1 -1
  95. package/dist/rules2/src/table/refineLayoutSize2.js +1 -1
  96. package/dist/rules2/src/table/refineLayoutSize2.js.map +1 -1
  97. package/dist/rules2/src/utils.js.map +1 -1
  98. package/dist/viewer/src/chart.js +13 -2
  99. package/dist/viewer/src/chart.js.map +1 -1
  100. package/dist/viewer/src/legends/FocusLegend.js +1 -1
  101. package/dist/viewer/src/legends/FocusLegend.js.map +1 -1
  102. package/package.json +6 -5
  103. package/src/bridge-d3-react/src/index.js +0 -1
  104. package/src/rules/src/chart/getChartOptions.js +2 -2
  105. package/src/rules/src/constants.js +0 -35
  106. package/src/rules/src/dimension-utils.js +25 -23
  107. package/src/rules/src/factories/choro-series.js +41 -30
  108. package/src/rules/src/factories/focus.js +17 -0
  109. package/src/rules/src/factories/getChartSeries.js +8 -0
  110. package/src/rules/src/factories/sample-focus.js +14 -18
  111. package/src/rules/src/factories/sample-series.js +20 -20
  112. package/src/rules/src/factories/scatter-focus.js +22 -36
  113. package/src/rules/src/factories/scatter-series.js +8 -8
  114. package/src/rules/src/factories/series.js +45 -0
  115. package/src/rules/src/factories/stacked-series.js +4 -5
  116. package/src/rules/src/factories/symbol-series.js +37 -44
  117. package/src/rules/src/factories/timeline-focus.js +10 -14
  118. package/src/rules/src/factories/timeline-series.js +35 -39
  119. package/src/rules/src/get-values-enhanced.js +6 -0
  120. package/src/rules/src/index.js +7 -384
  121. package/src/rules/src/layout.js +4 -2
  122. package/src/rules/src/observation-formater.js +14 -20
  123. package/src/rules/src/properties/focus.js +50 -2
  124. package/src/rules/src/properties/getHeaderProps.js +1 -53
  125. package/src/rules/src/properties/index.js +2 -93
  126. package/src/rules/src/properties/linear.js +2 -2
  127. package/src/rules/src/properties/scatter.js +4 -4
  128. package/src/rules/src/properties/stacked.js +4 -6
  129. package/src/rules/src/properties/symbol.js +0 -1
  130. package/src/rules/src/properties/utils.js +11 -22
  131. package/src/rules/src/sdmx-data/index.js +2 -31
  132. package/src/rules2/src/combinedValuesDisplay.js +2 -2
  133. package/src/rules2/src/getAttributes.js +34 -0
  134. package/src/rules2/src/getDataflowTooltipAttributesIds.js +2 -2
  135. package/src/rules2/src/getHeaderCombinations.js +1 -1
  136. package/src/rules2/src/getHeaderSubtitle.js +2 -2
  137. package/src/rules2/src/getHeaderTitle.js +1 -1
  138. package/src/rules2/src/getMetadataCoordinates.js +1 -1
  139. package/src/rules2/src/getNotDisplayedIds.js +1 -1
  140. package/src/rules2/src/index.js +1 -0
  141. package/src/rules2/src/parseAttributes.js +2 -2
  142. package/src/rules2/src/parseHierarchicalCodelist.js +1 -1
  143. package/src/rules2/src/parseMetadataSeries.js +1 -1
  144. package/src/rules2/src/prepareData.js +10 -3
  145. package/src/rules2/src/refineDimensions.js +53 -8
  146. package/src/rules2/src/table/getCells.js +2 -2
  147. package/src/rules2/src/table/getLayout.js +2 -2
  148. package/src/rules2/src/table/getTableLayoutIds.js +9 -9
  149. package/src/rules2/src/table/getTableProps.js +0 -1
  150. package/src/rules2/src/table/parseValueHierarchy.js +0 -7
  151. package/src/rules2/src/table/refineLayoutSize2.js +5 -5
  152. package/src/rules2/src/utils.js +0 -11
  153. package/src/viewer/src/app/leg.js +0 -1
  154. package/src/viewer/src/chart.jsx +23 -1
  155. package/src/viewer/src/legends/FocusLegend.jsx +1 -1
  156. package/dist/rules/src/factories/scatter-dimension.js +0 -35
  157. package/dist/rules/src/factories/scatter-dimension.js.map +0 -1
  158. package/dist/rules/src/factories/stacked-dimension.js +0 -32
  159. package/dist/rules/src/factories/stacked-dimension.js.map +0 -1
  160. package/dist/rules/src/factories/symbol-dimension.js +0 -32
  161. package/dist/rules/src/factories/symbol-dimension.js.map +0 -1
  162. package/dist/rules/src/header/getDefaultSubtitle.js +0 -44
  163. package/dist/rules/src/header/getDefaultSubtitle.js.map +0 -1
  164. package/dist/rules/src/header/getHeaderUnits.js +0 -21
  165. package/dist/rules/src/header/getHeaderUnits.js.map +0 -1
  166. package/dist/rules/src/header/getSubtitleFlags.js +0 -47
  167. package/dist/rules/src/header/getSubtitleFlags.js.map +0 -1
  168. package/dist/rules/src/header/getTitleFlags.js +0 -12
  169. package/dist/rules/src/header/getTitleFlags.js.map +0 -1
  170. package/dist/rules/src/properties/errors.js +0 -22
  171. package/dist/rules/src/properties/errors.js.map +0 -1
  172. package/dist/rules/src/properties/getInformationsStateFromNewProps.js +0 -50
  173. package/dist/rules/src/properties/getInformationsStateFromNewProps.js.map +0 -1
  174. package/dist/rules/src/v8-transformer.js +0 -174
  175. package/dist/rules/src/v8-transformer.js.map +0 -1
  176. package/src/bridge-d3-react/src/app.js +0 -64
  177. package/src/bridge-d3-react/src/mock-choro.js +0 -394
  178. package/src/rules/src/factories/scatter-dimension.js +0 -32
  179. package/src/rules/src/factories/stacked-dimension.js +0 -29
  180. package/src/rules/src/factories/symbol-dimension.js +0 -29
  181. package/src/rules/src/header/getDefaultSubtitle.js +0 -40
  182. package/src/rules/src/header/getHeaderUnits.js +0 -17
  183. package/src/rules/src/header/getSubtitleFlags.js +0 -43
  184. package/src/rules/src/header/getTitleFlags.js +0 -8
  185. package/src/rules/src/header/index.js +0 -4
  186. package/src/rules/src/preparators/enhanceObservations.js +0 -152
  187. package/src/rules/src/properties/errors.js +0 -19
  188. package/src/rules/src/properties/getInformationsStateFromNewProps.js +0 -47
  189. package/src/rules/src/properties/information.js +0 -84
  190. package/src/rules/src/v8-transformer.js +0 -177
  191. package/src/rules2/src/getAdvAttrSeriesAtCoordinates.js +0 -29
  192. package/src/rules2/src/getMetadataStructureFromData.js +0 -17
  193. package/src/rules2/src/refineMetadataCoordinates.js +0 -28
  194. package/src/rules2/src/table/getCombinationDimensionsData.js +0 -39
@@ -1,17 +0,0 @@
1
- import * as R from 'ramda';
2
- import { dimensionValueDisplay, parseDisplay } from '../';
3
-
4
- export const getHeaderUnits = ({ units, display }) => {
5
- const _display = parseDisplay(display);
6
- return R.converge(
7
- (header, label) => R.isEmpty(label) ? null : { header, label },
8
- [
9
- (units) => `${dimensionValueDisplay(_display)(units)}:`,
10
- R.pipe(
11
- R.propOr([], 'values'),
12
- R.map(R.pipe(R.propOr({}, 'value'), dimensionValueDisplay(_display))),
13
- R.join(', ')
14
- )
15
- ]
16
- )(units);
17
- };
@@ -1,43 +0,0 @@
1
- import * as R from 'ramda';
2
- import { dimensionValueDisplay, getFlags, parseDisplay } from '../';
3
- import { DEFAULT_REJECTED_SUBTITLE_IDS } from '../constants';
4
-
5
- export const getSubtitleFlags = ({ customAttributes, dimensions, display, units }) => {
6
- const _display = parseDisplay(display);
7
- const formatter = dimensionValueDisplay(_display);
8
- const _getFlags = getFlags(customAttributes, formatter, {});
9
- const unitsValuesIds = R.pipe(R.propOr([], 'values'), R.pluck('id'))(units);
10
-
11
- return R.pipe(
12
- R.propOr([], 'one'),
13
- R.values,
14
- R.sortBy(R.prop('__index')),
15
- R.reduce(
16
- (acc, dim) => {
17
- if (!R.propOr(true, 'display', dim)) {
18
- return acc;
19
- }
20
- if (R.includes(dim.id, unitsValuesIds)) {
21
- return acc;
22
- }
23
- const value = R.path(['values', 0], dim);
24
-
25
- if (R.includes(value.id, DEFAULT_REJECTED_SUBTITLE_IDS) || !R.propOr(true, 'display', value)) {
26
- return acc;
27
- }
28
-
29
- const flags = _getFlags({ attributes: R.propOr({}, 'attributes', value), notes: R.propOr([], 'notes', value) });
30
- if (R.isEmpty(flags)) {
31
- return acc;
32
- }
33
-
34
- return R.append({
35
- header: `${formatter(dim)}:`,
36
- label: formatter(value),
37
- sub: flags
38
- }, acc);
39
- },
40
- []
41
- )
42
- )(dimensions);
43
- };
@@ -1,8 +0,0 @@
1
- import * as R from 'ramda';
2
- import { parseDisplay, dimensionValueDisplay, getFlags } from '../';
3
-
4
- export const getTitleFlags = ({ customAttributes, dataflowAttributes, display }) => {
5
- const _display = parseDisplay(display);
6
- const formatter = dimensionValueDisplay(_display);
7
- return getFlags(customAttributes, formatter, {})({ attributes: dataflowAttributes });
8
- };
@@ -1,4 +0,0 @@
1
- export { getDefaultSubtitle } from './getDefaultSubtitle';
2
- export { getSubtitleFlags } from './getSubtitleFlags';
3
- export { getHeaderUnits } from './getHeaderUnits';
4
- export { getTitleFlags } from './getTitleFlags';
@@ -1,152 +0,0 @@
1
- import * as R from 'ramda';
2
- import { formatValue } from './formatValue';
3
-
4
- /*
5
- options = {
6
- attachmentSeriesIndexes, //units
7
- customAttributes: {
8
- decimals: id,
9
- prefscale: id,
10
- },
11
- unitsArtefacts,
12
- obsAttributes,
13
- rejectedValueIds,
14
- }
15
- */
16
-
17
- const getSerieKey = (dimValuesIndexes, options) => {
18
- let indexes = R.propOr([], 'attachmentSeriesIndexes', options);
19
- return R.pipe(
20
- R.addIndex(R.map)((valueIndex, dimIndex) => {
21
- if (dimIndex === R.head(indexes)) {
22
- indexes = R.tail(indexes);
23
- return valueIndex;
24
- }
25
- return 'x';
26
- }),
27
- R.join(':')
28
- )(dimValuesIndexes);
29
- };
30
-
31
- const getUnitsValues = (indexes, options) => R.reduce(
32
- (acc, codelist) => {
33
- const { id } = codelist;
34
- if (!R.includes(id, R.propOr([], 'unitsIds', options))) {
35
- return acc;
36
- }
37
- const valueIndex = R.prop(codelist.__index, indexes);
38
- if (R.isNil(valueIndex) || !R.propOr(true, 'display', codelist)) {
39
- return acc;
40
- }
41
- const value = R.path(['values', Number(valueIndex)], codelist);
42
- if (R.isNil(value) || R.includes(value.id, R.propOr([], 'rejectedValueIds', options))
43
- || !R.propOr(true, 'display', value)) {
44
- return acc;
45
- }
46
- return R.assoc(
47
- id,
48
- {
49
- ...R.pick(['id', 'name', '__index'], codelist),
50
- value: R.when(R.complement(R.isNil), R.assoc('index', Number(valueIndex)))(value)
51
- },
52
- acc
53
- );
54
- },
55
- {}
56
- );
57
-
58
- const getObservationUnits = (observation, dimensions, attributes, options) => {
59
- const dimensionsUnits = getUnitsValues(
60
- R.propOr([], 'dimValuesIndexes', observation),
61
- options
62
- )(dimensions);
63
-
64
- const attributesUnits = getUnitsValues(
65
- R.propOr([], 'attrValuesIndexes', observation),
66
- options
67
- )(attributes);
68
-
69
- const serieKey = getSerieKey(R.propOr([], 'dimValuesIndexes', observation), options);
70
-
71
- return ({ ...dimensionsUnits, ...attributesUnits, serieKey });
72
- };
73
-
74
- const getFormatAttributesIndexes = (attributes, customAttributes) => R.addIndex(R.reduce)(
75
- (acc, attribute, index) => {
76
- if (R.equals(attribute.id, customAttributes.decimals)) {
77
- return ({ ...acc, decimals: index });
78
- }
79
- if (R.equals(attribute.id, customAttributes.prefscale)) {
80
- return ({ ...acc, prefscale: index });
81
- }
82
- return acc;
83
- },
84
- { prefscale: null, decimals: null },
85
- attributes
86
- );
87
-
88
- const getAttributeValue = (attribute, valueIndex, options) => {
89
- if (!R.propOr(true, 'display', attribute)) {
90
- return null;
91
- }
92
- const value = R.pipe(
93
- R.propOr([], 'values'),
94
- R.nth(valueIndex)
95
- )(attribute);
96
-
97
- if (R.isNil(value) || !R.propOr(true, 'display', value) || R.includes(value.id,R.propOr([],'rejectedValueIds')(options))) {
98
- return null;
99
- }
100
-
101
- return ({
102
- ...R.pick(['id', 'name'], attribute),
103
- value: R.pick(['id', 'name'], value)
104
- });
105
- };
106
-
107
-
108
- export const enhanceObservations = (dimensions = [], observations = {}, attributes = [], options = {}) => {
109
- const formatAttributesIndexes = getFormatAttributesIndexes(attributes, R.propOr({}, 'customAttributes', options));
110
- const _attributes = R.addIndex(R.map)((attr, index) => R.assoc('__index', index, attr), attributes);
111
- const _obsAttributes = R.pipe(
112
- R.indexBy(R.prop('id')),
113
- R.props(options.attributesIds || [])
114
- )(_attributes);
115
-
116
- return R.mapObjIndexed(
117
- (observation) => {
118
- const { attrValuesIndexes, dimValuesIndexes } = observation;
119
- const obsAttributes = R.reduce(
120
- (acc, attribute) => {
121
- const attrValue = getAttributeValue(attribute, R.nth(attribute.__index, attrValuesIndexes), options);
122
- if (R.isNil(attrValue)) {
123
- return acc;
124
- }
125
- return R.assoc(attribute.id, attrValue, acc);
126
- },
127
- {},
128
- _obsAttributes
129
- );
130
-
131
- const indexedDimValIds = R.addIndex(R.reduce)(
132
- (acc, dimension, dimensionIndex) => {
133
- const id = dimension.id;
134
- const valueIndex = R.nth(dimensionIndex, dimValuesIndexes);
135
- const valueId = R.path(['values', Number(valueIndex), 'id'], dimension);
136
- return R.assoc(id, valueId, acc);
137
- },
138
- {},
139
- dimensions
140
- );
141
-
142
- return ({
143
- ...observation,
144
- attributes: obsAttributes,
145
- formattedValue: formatValue(observation, formatAttributesIndexes, attributes),
146
- units: getObservationUnits(observation, dimensions, _attributes, options),
147
- indexedDimValIds,
148
- });
149
- },
150
- observations
151
- );
152
- };
@@ -1,19 +0,0 @@
1
- import * as R from 'ramda';
2
- import { TIMELINE } from '../constants';
3
- import { getTimePeriodDimension } from '@sis-cc/dotstatsuite-sdmxjs';
4
-
5
- export const getHasNoTimePeriodError = ({ data, type }) => {
6
- if (!R.equals(TIMELINE, type)) {
7
- return false;
8
- }
9
- const dimensions = R.pathOr([], ['structure', 'dimensions', 'observation'], data);
10
- const timeDimension = getTimePeriodDimension({ dimensions });
11
- if (R.isNil(timeDimension)) {
12
- return true;
13
- }
14
- return R.pipe(
15
- R.propOr([], 'values'),
16
- R.length,
17
- R.gte(1)
18
- )(timeDimension);
19
- };
@@ -1,47 +0,0 @@
1
- import * as R from 'ramda';
2
- import { extractSdmxArtefacts, prepareData } from '../';
3
-
4
- const initialState = {
5
- dataflow: null,
6
- dataflowAttributes: null,
7
- dimensions: null,
8
- units: null,
9
- id: null,
10
- sourceLabel: null,
11
- subtitle: null,
12
- title: null,
13
- withCopyright: true,
14
- withLogo: true
15
- };
16
-
17
- export const getInformationsStateFromNewProps = (props, state) => {
18
- if (R.isNil(props.data)) {
19
- return initialState
20
- }
21
- const id = R.pipe(
22
- R.prop('data'),
23
- extractSdmxArtefacts,
24
- R.prop('id')
25
- )(props);
26
- if (id === state.id && props.display === state.display) {
27
- return {};
28
- }
29
- const {
30
- dataflowAttributes,
31
- dataflowName,
32
- dimensions,
33
- units
34
- } = prepareData({ data: props.data }, props.customAttributes, props.units);
35
- return {
36
- ...initialState,
37
- dataflow: {
38
- id: props.dataflowId,
39
- name: dataflowName
40
- },
41
- dataflowAttributes,
42
- dimensions,
43
- display: props.display,
44
- id,
45
- units
46
- };
47
- };
@@ -1,84 +0,0 @@
1
- import { is, isEmpty, isNil, map, not, of, path, pipe, prop, length, split, when } from 'ramda';
2
- import {
3
- defaultSubtitle,
4
- extractSdmxArtefacts,
5
- headerUprsLabel,
6
- parseDisplay,
7
- uprAttributes,
8
- uprAttributesWithOneRelevantValue,
9
- } from '../';
10
-
11
- import { dimensionValueDisplay } from '../dimension-utils';
12
-
13
- export const initialState = {
14
- subtitle: undefined,
15
- title: undefined,
16
- sourceLabel: undefined,
17
- };
18
-
19
- export const informationStateFromNewProps = (props, state) => {
20
- const { id } = extractSdmxArtefacts(props.data);
21
- if (id !== state.id) {
22
- return initialState;
23
- }
24
- return ({});
25
- };
26
-
27
- const getDataflowCode = (url) => {
28
- if (isNil(url) || isEmpty(url)) {
29
- return null;
30
- }
31
- const match = url.match(/[\w\/]+\/data\/([^\/]+)\//);
32
- if (!is(Array, match)) {
33
- return null;
34
- }
35
- //v8 case: 'AGENCY,CODE,VERSION'
36
- const id = match[1];
37
- const splitId = split(',', id);
38
- if ((length(splitId) === 1)) {
39
- return splitId[0];
40
- }
41
- return splitId[1];
42
- };
43
-
44
- const defaultTitle = (props, display) => {
45
- const name = path(['data', 'structure', 'name'], props);
46
- const code = getDataflowCode(props.sdmxUrl);
47
- return dimensionValueDisplay(display)({ id: code, name });
48
- };
49
-
50
- const defaultSourceLabel = (props, title) => {
51
- const propsLabel = path(['source', 'label'], props);
52
- return (isNil(propsLabel) || isEmpty(propsLabel))
53
- ? title : propsLabel;
54
- }
55
-
56
- export const toHeader = (props, state) => {
57
- const display = parseDisplay(props.display);
58
- const stateTitle = prop('title', state);
59
- const stateSubtitle = prop('subtitle', state);
60
- const stateSourceLabel = prop('sourceLabel', state);
61
- const propsSourceLink = path(['source', 'link'], props);
62
- const title = (isNil(stateTitle) || isEmpty(stateTitle))
63
- ? defaultTitle(props, display) : stateTitle;
64
- const subtitle = (isNil(stateSubtitle) || isEmpty(stateSubtitle))
65
- ? defaultSubtitle(props.data, display) : stateSubtitle;
66
- const sourceLink = (isNil(propsSourceLink) || isEmpty(propsSourceLink))
67
- ? props.sdmxUrl : propsSourceLink;
68
- const sourceLabel = (isNil(stateSourceLabel) || isEmpty(stateSourceLabel))
69
- ? defaultSourceLabel(props, title) : stateSourceLabel;
70
- return ({
71
- footnotes: { source: sourceLink, sourceLabel },
72
- title: { label: title },
73
- subtitle: pipe(
74
- when(pipe(is(Array), not), of),
75
- map(entry => ({ label: entry }))
76
- )(subtitle),
77
- uprs: pipe(
78
- extractSdmxArtefacts,
79
- ({ attributes }) => uprAttributes(attributes),
80
- uprAttributesWithOneRelevantValue,
81
- headerUprsLabel(display),
82
- )(props.data)
83
- });
84
- };
@@ -1,177 +0,0 @@
1
- import * as R from 'ramda';
2
- import {
3
- isTimePeriodDimension,
4
- } from '@sis-cc/dotstatsuite-sdmxjs';
5
- import {
6
- getRelationnalAnnotations,
7
- setAnnotationsLayout,
8
- getIsHidden,
9
- } from './sdmx-data';
10
- import { getReportingYearStart } from './preparators/getReportingYearStart';
11
- import { getNotDisplayedIds } from '../../rules2/src';
12
- import { getValuesEnhanced } from './get-values-enhanced';
13
-
14
- const TIME_PERIOD_ID = 'TIME_PERIOD';
15
-
16
- export const dataTransformer = (dataNew, options = {}) => {
17
- const { locale } = options;
18
- const reportYearStart = getReportingYearStart(dataNew);
19
- const getName = R.prop('name')
20
- //---------------------------------------------------------------------------------------Annotations
21
- const getStructure = R.pathOr({}, ['data', 'structure']);
22
- const structure = getStructure(dataNew);
23
- const getAnnotations = R.propOr([], 'annotations');
24
- const annotations = getAnnotations(structure);
25
- const getDataSets = R.pathOr({}, ['data', 'dataSets']);
26
- const dataSets = getDataSets(dataNew);
27
-
28
- const dataSetsAnnotations = R.props(
29
- R.pathOr([], [0, 'annotations'], dataSets),
30
- annotations,
31
- );
32
-
33
- /*
34
- hiddenValues => codelistIds or codelistValuesIds for display computation
35
- hiddenCombinations => used only for dimensions, if dimension values match the provided set, all dimension is removed
36
- */
37
- const { hiddenValues, hiddenCombinations } = getNotDisplayedIds(dataSetsAnnotations);
38
- const getIsAllDimHidden = ({ id, values }) => {
39
- if (!R.has(id, hiddenCombinations)) {
40
- return false;
41
- }
42
- const valuesIds = R.pluck('id', values);
43
- return R.isEmpty(R.difference(valuesIds, hiddenCombinations[id]));
44
- }
45
-
46
- //--------------------------------------------------------------------------------------------Header
47
- const getMeta = R.propOr({}, 'meta');
48
- const meta = getMeta(dataNew);
49
-
50
- const getSender = R.propOr({}, 'sender');
51
- const sender = getSender(meta);
52
-
53
- const resHeader = {
54
- ...meta,
55
- sender: { ...sender, name: getName(sender) },
56
- };
57
-
58
- //----------------------------------------------------------------------------------------Attributes
59
- const getAttributes = R.propOr({}, 'attributes');
60
- const attributes = getAttributes(structure);
61
-
62
- const getAttrObservations = R.propOr([], 'observation');
63
- const attrObservations = getAttrObservations(attributes);
64
-
65
- const resAttrObservations = R.addIndex(R.map)((observation, index) => {
66
- const obsAnnotations = R.props(observation.annotations || [], annotations);
67
- return {
68
- ...observation,
69
- __index: index,
70
- display:
71
- !R.has(observation.id, hiddenValues) && !getIsHidden(obsAnnotations),
72
- name: getName(observation),
73
- values: getValuesEnhanced({
74
- locale,
75
- annotations,
76
- parent: observation.id,
77
- reportYearStart,
78
- hiddenIds: hiddenValues,
79
- options,
80
- })(R.propOr([], 'values', observation)),
81
- roles: !R.isNil(observation.role) ? R.head(observation.role) : null,
82
- };
83
- }, attrObservations);
84
-
85
- const datasetAttributes = R.map((attr) => {
86
- const attrAnnotations = R.props(attr.annotations || [], annotations);
87
- return {
88
- ...attr,
89
- display: !R.has(attr.id, hiddenValues) && !getIsHidden(attrAnnotations),
90
- name: getName(attr),
91
- values: getValuesEnhanced({
92
- locale,
93
- annotations,
94
- parent: attr.id,
95
- hiddenIds: hiddenValues,
96
- options,
97
- reportYearStart,
98
- })(R.propOr([], 'values', attr)),
99
- };
100
- }, R.propOr([], 'dataSet', attributes));
101
-
102
- const resAttributes = {
103
- ...attributes,
104
- observation: R.concat(resAttrObservations, datasetAttributes),
105
- };
106
-
107
- //----------------------------------------------------------------------------------------Dimensions
108
- const getDimensions = R.propOr({}, 'dimensions');
109
- const dimensions = getDimensions(structure);
110
-
111
- const getDimObservations = R.propOr([], 'observation');
112
- const dimObservations = getDimObservations(dimensions);
113
-
114
- const getObservations = (locale) =>
115
- R.addIndex(R.reduce)(
116
- (acc, observation, obsIndex) => {
117
- const id = R.prop('id')(observation);
118
- const dimAnnotations = getRelationnalAnnotations(
119
- R.propOr([], 'annotations')(observation),
120
- )(annotations);
121
- const isTimeDimension = isTimePeriodDimension(observation);
122
- const values = getValuesEnhanced({
123
- locale,
124
- annotations,
125
- isTimeDimension,
126
- reportYearStart,
127
- parent: id,
128
- hiddenIds: hiddenValues,
129
- options,
130
- })(R.propOr([], 'values', observation));
131
- const isAllDimHidden = getIsAllDimHidden({ id, values });
132
- const isHidden = isAllDimHidden || R.has(id, hiddenValues)
133
- || getIsHidden(dimAnnotations);
134
- return {
135
- observation: R.append({
136
- ...observation,
137
- rejected: isAllDimHidden || R.isEmpty(values),
138
- display: !isHidden,
139
- __index: obsIndex,
140
- name: getName(observation),
141
- values,
142
- role: isTimeDimension
143
- ? TIME_PERIOD_ID
144
- : R.head(R.propOr([], 'roles', observation)),
145
- })(acc.observation),
146
- dimensionsLayout: setAnnotationsLayout(
147
- id,
148
- acc.dimensionsLayout,
149
- )(dimAnnotations),
150
- };
151
- },
152
- { observation: [], dimensionsLayout: {} },
153
- );
154
-
155
- //-----------------------------------------------------------------------------------------Structure
156
- const { dimensionsLayout, observation } =
157
- getObservations(locale)(dimObservations);
158
- const resStructure = {
159
- ...structure,
160
- name: getName({ ...structure, id: options.dataflowId }),
161
- annotations,
162
- attributes: resAttributes,
163
- dimensions: { observation },
164
- };
165
-
166
- //------------------------------------------------------------------------------------------------------Layout
167
- const dataSetsLayout = R.reduce((acc, dataSetsAnnotation) => {
168
- const title = R.propOr('', 'title')(dataSetsAnnotation);
169
- if (R.isEmpty(title)) return acc;
170
- return setAnnotationsLayout(title, acc)([dataSetsAnnotation]);
171
- }, {})(dataSetsAnnotations);
172
-
173
- return {
174
- data: { header: resHeader, dataSets, structure: resStructure },
175
- layout: R.mergeRight(dimensionsLayout, dataSetsLayout),
176
- };
177
- };
@@ -1,29 +0,0 @@
1
- import * as R from 'ramda';
2
-
3
- const attribueValueDisplay = (display) => data => {
4
- if (display === 'code') {
5
- return R.prop('id', data);
6
- }
7
- if (display === 'both') {
8
- return `${R.prop('id', data)}: ${R.prop('name', data)}`;
9
- }
10
- return R.prop('name', data);
11
- };
12
-
13
- export const getAdvAttrSeriesAtCoordinates = (coordinates, advancedAttributes, display) => R.pipe(
14
- R.filter(serie => {
15
- const mergedCoord = R.mergeLeft(serie.coordinates, coordinates);
16
- return R.equals(mergedCoord, coordinates);
17
- }),
18
- R.map(serie => {
19
- return R.pipe(
20
- R.propOr({}, 'attributes'),
21
- R.values,
22
- R.map(attribute => ({
23
- id: attribute.id,
24
- label: attribueValueDisplay(display)(attribute),
25
- value: attribueValueDisplay(display)(attribute.value)
26
- }))
27
- )(serie);
28
- }),
29
- )(advancedAttributes);
@@ -1,17 +0,0 @@
1
- import * as R from 'ramda';
2
-
3
- export const getDataflowMetadataStructure = sdmxJson => {
4
- const annotations = R.pathOr([], ['data', 'stucture', 'annotations'], sdmxJson);
5
- const dataSetAnnotIndexes = R.pathOr([], ['data', 'dataSets', 0, 'annotations'], sdmxJson);
6
- const dataSetAnnotations = R.props(dataSetAnnotIndexes, annotations);
7
- const metadataAnnotation = R.find(R.propEq('type', 'METADATA'), dataSetAnnotations);
8
- if (!metadataAnnotation) {
9
- return null;
10
- }
11
- return R.pipe(
12
- R.propOr('', 'title'),
13
- R.split('='),
14
- R.last,
15
-
16
- )(metadataAnnotation);
17
- };
@@ -1,28 +0,0 @@
1
- import * as R from 'ramda';
2
-
3
- export const refineMetadataCoordinates = (metadataCoordinates, layoutIds) => {
4
- const relevantIds = R.pipe(R.values, R.unnest)(layoutIds);
5
- return R.reduce(
6
- (acc, coordinates) => {
7
- const refinedCoord = R.pick(relevantIds, coordinates);
8
- if (R.isEmpty(refinedCoord)) {
9
- return acc;
10
- }
11
- const removedHeaderCodes = R.omit(layoutIds.header, refinedCoord);
12
- if (R.isEmpty(removedHeaderCodes)) {
13
- return R.over(R.lensProp('header'), R.append(refinedCoord))(acc);
14
- }
15
- const removedSectionCodes = R.omit(layoutIds.sections, refinedCoord);
16
- if (R.isEmpty(removedSectionCodes)) {
17
- return R.over(R.lensProp('sections'), R.append(refinedCoord))(acc);
18
- }
19
- const removedRowsCodes = R.omit(layoutIds.rows, removedSectionCodes);
20
- if (R.isEmpty(removedRowsCodes)) {
21
- return R.over(R.lensProp('rows'), R.append(refinedCoord))(acc);
22
- }
23
- return R.over(R.lensProp('cells'), R.append(refinedCoord))(acc);
24
- },
25
- { cells: [], header: [], sections: [], rows: [] },
26
- metadataCoordinates
27
- );
28
- };
@@ -1,39 +0,0 @@
1
- import * as R from 'ramda';
2
- import { parseValueHierarchy, isSameValueAsPrevious } from './parseValueHierarchy';
3
-
4
- export const getCombinationDimensionsData = (indexes, combination, previous, sameSerie) => {
5
- let coordinates = {};
6
- let ids = [];
7
- let _sameSerie = sameSerie;
8
- let hasAdvancedAttributes = false;
9
-
10
- const { dimensions=[] } = combination;
11
- const dimValues = R.addIndex(R.reduce)(
12
- (acc, valIndex, dimIndex) => {
13
- const dimension = R.nth(dimIndex, dimensions);
14
- const value = R.nth(Math.abs(valIndex), R.propOr([], 'values', dimension));
15
- hasAdvancedAttributes = !hasAdvancedAttributes ? value.hasAdvancedAttributes : true;
16
- coordinates = R.assoc(dimension.id, value.id, coordinates);
17
- ids = R.append(`${dimension.id}=${value.id}`, ids);
18
- const previousValue = R.propOr({}, dimension.id, previous);
19
- if (isSameValueAsPrevious(value, previousValue) && _sameSerie) {
20
- return R.assoc(dimension.id, previousValue, acc);
21
- }
22
- else {
23
- const _parsedValue = parseValueHierarchy(value, _sameSerie ? previousValue || {} : {}, dimension.indexedValues);
24
- const parsedValue = R.over(
25
- R.lensProp('display'),
26
- (display=true) => display && R.propOr(true, 'display', dimension)
27
- )(_parsedValue);
28
- if (!R.isNil(previous)) {
29
- _sameSerie = false;
30
- }
31
- return R.assoc(dimension.id, parsedValue, acc);
32
- }
33
- },
34
- {},
35
- indexes
36
- );
37
-
38
- return ({ dimValues, coordinates, ids, sameSerie: _sameSerie, hasAdvancedAttributes });
39
- };