@sis-cc/dotstatsuite-components 21.0.1 → 21.1.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 (234) hide show
  1. package/dist/dotstatsuite-components.js +38112 -0
  2. package/package.json +4 -1
  3. package/.editorconfig +0 -19
  4. package/.gitlab-ci.yml +0 -48
  5. package/prettier.config.js +0 -13
  6. package/src/app.js +0 -13
  7. package/src/bridge-d3-react/README.md +0 -42
  8. package/src/bridge-d3-react/src/app.js +0 -64
  9. package/src/bridge-d3-react/src/index.js +0 -17
  10. package/src/bridge-d3-react/src/mock-choro.js +0 -394
  11. package/src/bridge-d3-react/src/react-chart-factory.js +0 -65
  12. package/src/index.js +0 -12
  13. package/src/rules/README.md +0 -23
  14. package/src/rules/src/chart/getAxisOptions.js +0 -258
  15. package/src/rules/src/chart/getBaseOptions.js +0 -84
  16. package/src/rules/src/chart/getChartOptions.js +0 -118
  17. package/src/rules/src/chart/getGridOptions.js +0 -52
  18. package/src/rules/src/chart/getTooltipOptions.js +0 -230
  19. package/src/rules/src/constants.js +0 -64
  20. package/src/rules/src/date.js +0 -118
  21. package/src/rules/src/dimension-utils.js +0 -54
  22. package/src/rules/src/factories/choro-series.js +0 -65
  23. package/src/rules/src/factories/sample-focus.js +0 -22
  24. package/src/rules/src/factories/sample-series.js +0 -51
  25. package/src/rules/src/factories/scatter-dimension.js +0 -31
  26. package/src/rules/src/factories/scatter-focus.js +0 -39
  27. package/src/rules/src/factories/scatter-series.js +0 -94
  28. package/src/rules/src/factories/stacked-dimension.js +0 -29
  29. package/src/rules/src/factories/stacked-series.js +0 -185
  30. package/src/rules/src/factories/symbol-dimension.js +0 -29
  31. package/src/rules/src/factories/symbol-series.js +0 -62
  32. package/src/rules/src/factories/timeline-focus.js +0 -18
  33. package/src/rules/src/factories/timeline-series.js +0 -91
  34. package/src/rules/src/get-values-enhanced.js +0 -134
  35. package/src/rules/src/header/getDefaultSubtitle.js +0 -40
  36. package/src/rules/src/header/getHeaderUnits.js +0 -17
  37. package/src/rules/src/header/getSubtitleFlags.js +0 -43
  38. package/src/rules/src/header/getTitleFlags.js +0 -8
  39. package/src/rules/src/header/index.js +0 -4
  40. package/src/rules/src/index.js +0 -398
  41. package/src/rules/src/layout.js +0 -113
  42. package/src/rules/src/observation-formater.js +0 -83
  43. package/src/rules/src/preparators/enhanceObservations.js +0 -152
  44. package/src/rules/src/preparators/formatValue.js +0 -84
  45. package/src/rules/src/preparators/getObservations.js +0 -19
  46. package/src/rules/src/preparators/getReportingYearStart.js +0 -16
  47. package/src/rules/src/properties/errors.js +0 -19
  48. package/src/rules/src/properties/focus.js +0 -69
  49. package/src/rules/src/properties/getAvailableChartTypes.js +0 -34
  50. package/src/rules/src/properties/getHeaderProps.js +0 -74
  51. package/src/rules/src/properties/getInformationsStateFromNewProps.js +0 -47
  52. package/src/rules/src/properties/getObservationsType.js +0 -29
  53. package/src/rules/src/properties/getStringifiedSubtitle.js +0 -6
  54. package/src/rules/src/properties/index.js +0 -424
  55. package/src/rules/src/properties/information.js +0 -84
  56. package/src/rules/src/properties/linear.js +0 -129
  57. package/src/rules/src/properties/scatter.js +0 -158
  58. package/src/rules/src/properties/stacked.js +0 -98
  59. package/src/rules/src/properties/symbol.js +0 -79
  60. package/src/rules/src/properties/utils.js +0 -110
  61. package/src/rules/src/sdmx-data/index.js +0 -39
  62. package/src/rules/src/table/factories/getCellValue.js +0 -50
  63. package/src/rules/src/table/index.js +0 -1
  64. package/src/rules/src/v8-transformer.js +0 -176
  65. package/src/rules/test/extractSdmxArtefacts.js +0 -26
  66. package/src/rules/test/get-values-enhanced.test.js +0 -127
  67. package/src/rules/test/oecd-HEALTH_PROT-no-freq.json +0 -2903
  68. package/src/rules/test/oecd-HEALTH_PROT-parsed.js +0 -398
  69. package/src/rules/test/oecd-HEALTH_PROT-wrong-freq.json +0 -2913
  70. package/src/rules/test/oecd-HEALTH_PROT.json +0 -2913
  71. package/src/rules/test/oecd-KEI.json +0 -372
  72. package/src/rules/test/scatter-property.js +0 -455
  73. package/src/rules/test/stacked-property.js +0 -273
  74. package/src/rules/test/symbol-property.js +0 -262
  75. package/src/rules/test/v8-transformer.test.js +0 -90
  76. package/src/rules2/src/applyHierarchicalCodesToDim.js +0 -149
  77. package/src/rules2/src/combinedValuesDisplay.js +0 -74
  78. package/src/rules2/src/constants.js +0 -6
  79. package/src/rules2/src/duplicateObservations.js +0 -35
  80. package/src/rules2/src/enhanceObservations.js +0 -95
  81. package/src/rules2/src/getAdvAttrSeriesAtCoordinates.js +0 -29
  82. package/src/rules2/src/getAttributesSeries.js +0 -36
  83. package/src/rules2/src/getCombinationDefinitions.js +0 -47
  84. package/src/rules2/src/getDataflowAttributes.js +0 -23
  85. package/src/rules2/src/getDataflowTooltipAttributesIds.js +0 -31
  86. package/src/rules2/src/getDimensionValuesIndexes.js +0 -13
  87. package/src/rules2/src/getHCodelistsRefsInData.js +0 -32
  88. package/src/rules2/src/getHeaderCombinations.js +0 -48
  89. package/src/rules2/src/getHeaderCoordinates.js +0 -7
  90. package/src/rules2/src/getHeaderSubtitle.js +0 -34
  91. package/src/rules2/src/getHeaderTitle.js +0 -15
  92. package/src/rules2/src/getMSDInformations.js +0 -23
  93. package/src/rules2/src/getManyValuesDimensions.js +0 -34
  94. package/src/rules2/src/getMetadataCoordinates.js +0 -37
  95. package/src/rules2/src/getMetadataStructureFromData.js +0 -17
  96. package/src/rules2/src/getNotDisplayedIds.js +0 -53
  97. package/src/rules2/src/getOneValueDimensions.js +0 -34
  98. package/src/rules2/src/getSeriesCombinations.js +0 -24
  99. package/src/rules2/src/hasCellMetadata.js +0 -14
  100. package/src/rules2/src/hierarchiseDimensionWithAdvancedHierarchy2.js +0 -57
  101. package/src/rules2/src/hierarchiseDimensionWithNativeHierarchy2.js +0 -35
  102. package/src/rules2/src/index.js +0 -50
  103. package/src/rules2/src/parseAttributes.js +0 -41
  104. package/src/rules2/src/parseCombinations.js +0 -102
  105. package/src/rules2/src/parseHierarchicalCodelist.js +0 -48
  106. package/src/rules2/src/parseMetadataSeries.js +0 -117
  107. package/src/rules2/src/prepareData.js +0 -73
  108. package/src/rules2/src/refineAttributes.js +0 -16
  109. package/src/rules2/src/refineDimensions.js +0 -18
  110. package/src/rules2/src/refineMetadataCoordinates.js +0 -28
  111. package/src/rules2/src/refineTimePeriod.js +0 -127
  112. package/src/rules2/src/sdmx3.0DataFormatPatch.js +0 -9
  113. package/src/rules2/src/table/declineObservationsOverAttributes.js +0 -32
  114. package/src/rules2/src/table/getCells.js +0 -93
  115. package/src/rules2/src/table/getCellsAttributesIds.js +0 -38
  116. package/src/rules2/src/table/getCellsMetadataCoordinates.js +0 -13
  117. package/src/rules2/src/table/getCombinationDimensionsData.js +0 -39
  118. package/src/rules2/src/table/getCuratedCells.js +0 -33
  119. package/src/rules2/src/table/getFlagsAndNotes.js +0 -23
  120. package/src/rules2/src/table/getIndexedCombinationsByDisplay.js +0 -16
  121. package/src/rules2/src/table/getLayout.js +0 -84
  122. package/src/rules2/src/table/getLayoutData2.js +0 -198
  123. package/src/rules2/src/table/getSortedLayoutIndexes.js +0 -124
  124. package/src/rules2/src/table/getTableLabelAccessor.js +0 -9
  125. package/src/rules2/src/table/getTableLayoutIds.js +0 -314
  126. package/src/rules2/src/table/getTableProps.js +0 -75
  127. package/src/rules2/src/table/parseSeriesIndexesHierarchies.js +0 -79
  128. package/src/rules2/src/table/parseValueHierarchy.js +0 -33
  129. package/src/rules2/src/table/refineLayoutSize2.js +0 -321
  130. package/src/rules2/src/utils.js +0 -37
  131. package/src/viewer/mocks/bar.js +0 -33
  132. package/src/viewer/mocks/gpp-symbol.js +0 -93
  133. package/src/viewer/mocks/gpp-time.js +0 -1103
  134. package/src/viewer/mocks/row.js +0 -39
  135. package/src/viewer/mocks/scatter.js +0 -93
  136. package/src/viewer/mocks/stack.js +0 -161
  137. package/src/viewer/src/app/leg.js +0 -36
  138. package/src/viewer/src/app/nodata-res.js +0 -22
  139. package/src/viewer/src/app/nodata-sized.js +0 -23
  140. package/src/viewer/src/app/one-table-cell.js +0 -70
  141. package/src/viewer/src/app/table.js +0 -423
  142. package/src/viewer/src/app/use-case-1.js +0 -33
  143. package/src/viewer/src/app/use-case-2.js +0 -38
  144. package/src/viewer/src/app/use-case-3.js +0 -18
  145. package/src/viewer/src/app.js +0 -116
  146. package/src/viewer/src/chart.js +0 -52
  147. package/src/viewer/src/chartUtils/options.js +0 -30
  148. package/src/viewer/src/chartUtils/series.js +0 -51
  149. package/src/viewer/src/footer.js +0 -24
  150. package/src/viewer/src/header.js +0 -10
  151. package/src/viewer/src/index.js +0 -158
  152. package/src/viewer/src/legends/AxisLegend.js +0 -41
  153. package/src/viewer/src/legends/ChartLegends.js +0 -66
  154. package/src/viewer/src/legends/FocusLegend.js +0 -63
  155. package/src/viewer/src/legends/Legend.js +0 -46
  156. package/src/viewer/src/legends/SeriesLegend.js +0 -78
  157. package/src/viewer/src/utils.js +0 -21
  158. package/test/applyHierarchicalCodesToDim.test.js +0 -160
  159. package/test/combinedValuesDisplay.test.js +0 -66
  160. package/test/duplicateObs.test.js +0 -118
  161. package/test/enhanceObservations2.test.js +0 -257
  162. package/test/getAttributesSeries.test.js +0 -66
  163. package/test/getAxisOptions.test.js +0 -309
  164. package/test/getBaseOptions.test.js +0 -77
  165. package/test/getCellValue.test.js +0 -32
  166. package/test/getCells.test.js +0 -178
  167. package/test/getCellsMetadataCoordinates.test.js +0 -40
  168. package/test/getCombinationDefinitions.test.js +0 -104
  169. package/test/getCombinationDimensionsData.test.js +0 -99
  170. package/test/getDataflowAttributes.test.js +0 -23
  171. package/test/getDataflowTooltipAttributesIds.test.js +0 -146
  172. package/test/getDimensionValuesIndexes.test.js +0 -33
  173. package/test/getGridOptions.test.js +0 -65
  174. package/test/getHCodelistsRefs.test.js +0 -23
  175. package/test/getHeaderCombinations.test.js +0 -62
  176. package/test/getHeaderTitle.test.js +0 -25
  177. package/test/getLayout.test.js +0 -54
  178. package/test/getLayoutData2.test.js +0 -535
  179. package/test/getMSDInformations.test.js +0 -35
  180. package/test/getMetadataCoordinates.test.js +0 -0
  181. package/test/getNotDisplayedIds.test.js +0 -47
  182. package/test/getObservationsType.test.js +0 -55
  183. package/test/getOneValueDimensions.test.js +0 -35
  184. package/test/getReportingYearStart.test.js +0 -59
  185. package/test/getSeriesCombinations.test.js +0 -29
  186. package/test/getSortedLayoutIndexes.test.js +0 -1138
  187. package/test/getTableLabelAccessor.test.js +0 -50
  188. package/test/getTableLayoutIds.test.js +0 -356
  189. package/test/hierarchiseDimensionWithNativeHierarchy2.test.js +0 -109
  190. package/test/isTableLayoutCompatible.test.js +0 -102
  191. package/test/metadata-parsing-perf.test.js +0 -509
  192. package/test/mocks/MSD_TEST.json +0 -490
  193. package/test/mocks/OECD_SNA_TABLE1_1.0_-_AUS_V_metadata.json +0 -152
  194. package/test/mocks/h-codelist.json +0 -2095
  195. package/test/mocks/large_metadata_series.json +0 -701
  196. package/test/mocks/observations-advanced-attributes.json +0 -55382
  197. package/test/mocks/table-invert-time--data.json +0 -80211
  198. package/test/mocks/table-invert-time--inverted.json +0 -80076
  199. package/test/mocks/table-layout-multi-hierarchies--layout.json +0 -621
  200. package/test/mocks/table-layout-multi-hierarchies--layoutData.json +0 -32411
  201. package/test/mocks/table-layout-multi-hierarchies--layoutIndexes.json +0 -2760
  202. package/test/mocks/table-layout-multi-hierarchies--observations.json +0 -30688
  203. package/test/mocks/table-layout-multi-hierarchies--sizedIndexes.json +0 -2762
  204. package/test/mocks/table-layout-truncation1--layout.json +0 -27469
  205. package/test/mocks/table-layout-truncation1--layoutData.json +0 -20358
  206. package/test/mocks/table-layout-truncation1--layoutIndexes.json +0 -7512
  207. package/test/mocks/table-layout-truncation1--observations.json +0 -70002
  208. package/test/mocks/table-layout-truncation1--sizedIndexes.json +0 -3011
  209. package/test/mocks/table-prep-multi-hierarchies--attributes.json +0 -46
  210. package/test/mocks/table-prep-multi-hierarchies--dimensions.json +0 -688
  211. package/test/mocks/table-prep-multi-hierarchies--enhancedObservations.json +0 -19696
  212. package/test/mocks/table-prep-multi-hierarchies--observations.json +0 -8246
  213. package/test/mocks/table-prep-multi-hierarchies--sdmxJson.json +0 -2985
  214. package/test/mocks/table-prep-simple-duplicate--dimensions2.json +0 -858
  215. package/test/mocks/table-prep-simple-duplicate--duplicated2.json +0 -77502
  216. package/test/mocks/table-prep-simple-duplicate--observations2.json +0 -60002
  217. package/test/mocks/table-prep-truncation1--dimensions.json +0 -35057
  218. package/test/mocks/table-prep-truncation1--enhancedObservations.json +0 -70002
  219. package/test/mocks/table-prep-truncation1--observations.json +0 -27502
  220. package/test/mocks/table-prep-truncation1--sdmxJson.json +0 -55103
  221. package/test/mocks/table-prep-units--observations.json +0 -284286
  222. package/test/mocks/table-prep-units--unitsSeries.json +0 -41042
  223. package/test/parseAttributes.test.js +0 -36
  224. package/test/parseCombinations.test.js +0 -172
  225. package/test/parseHierarchicalCodelist.test.js +0 -140
  226. package/test/parseMetadataSeries.test.js +0 -128
  227. package/test/parseSeriesIndexesHierarchies.test.js +0 -345
  228. package/test/parseValueHierarchy.test.js +0 -138
  229. package/test/refineAttributes.test.js +0 -29
  230. package/test/refineLayoutSize2.test.js +0 -3410
  231. package/test/refineMetadataCoordinates.test.js +0 -86
  232. package/test/refineTimePeriod.test.js +0 -580
  233. package/test/refinedDimensions.test.js +0 -35
  234. package/vite.config.mjs +0 -51
@@ -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,84 +0,0 @@
1
- import * as R from 'ramda';
2
- import numeral from 'numeral';
3
-
4
- const isValidNumber = R.both(R.is(Number), R.complement(R.equals(NaN)));
5
- const parseValidNumber = R.pipe(
6
- v => R.isNil(v) ? null : Number(v),
7
- v => isNaN(v) ? null : v
8
- );
9
-
10
- const getFormatAttributesValues = (observation, formatAttributesIndexes, attributes) => R.mapObjIndexed(
11
- attributeIndex => {
12
- let valueIndex;
13
- const relationship = R.pipe(R.nth(attributeIndex), R.propOr({}, 'relationship'))(attributes);
14
- //if (!R.isNil(attributeIndex) && attributeIndex >= R.length(R.propOr([], 'attrValuesIndexes', observation))) {
15
- if (R.has('none', relationship) || R.has('dataflow', relationship)) {
16
- valueIndex = 0;
17
- }
18
- else {
19
- valueIndex = R.pipe(
20
- R.propOr([], 'attrValuesIndexes'),
21
- R.nth(attributeIndex),
22
- parseValidNumber
23
- )(observation);
24
- }
25
-
26
- return R.pipe(
27
- R.path([attributeIndex, 'values', valueIndex, 'id']),
28
- parseValidNumber
29
- )(attributes);
30
- },
31
- formatAttributesIndexes
32
- );
33
-
34
- export const formatValue = (observation, formatAttributesIndexes, attributes) => {
35
- const value = R.prop('value', observation);
36
- if (R.is(Boolean, value)) {
37
- return value;
38
- }
39
- if (R.is(String, value)) {
40
- const monthMatch = value.match(/^\-\-([\d]{2})$/);
41
- if (R.is(Array, monthMatch)) {
42
- return R.nth(1, monthMatch);
43
- }
44
- const monthDayMatch = value.match(/^\-\-([\d]{2}\-[\d]{2})$/);
45
- if (R.is(Array, monthDayMatch)) {
46
- return R.nth(1, monthDayMatch);
47
- }
48
- const dayMatch = value.match(/^\-\-\-([\d]{2})$/);
49
- if (R.is(Array, dayMatch)) {
50
- return R.nth(1, dayMatch);
51
- }
52
- return value;
53
- }
54
-
55
- const { prefscale, decimals } = getFormatAttributesValues(
56
- observation,
57
- formatAttributesIndexes,
58
- attributes
59
- );
60
-
61
- const formatScale = R.when(
62
- R.always(isValidNumber(prefscale)),
63
- value => numeral(value).multiply(Math.pow(10, -1 * Number(prefscale))).value(),
64
- );
65
-
66
- const formatSeparator = value => numeral(value).format(`0,0.[0000000]`);
67
- const formatDecimals = R.ifElse(
68
- R.always(isValidNumber(decimals)),
69
- value => numeral(value).format(
70
- R.ifElse(R.equals(0), R.always('0,0'), d => `0,0.${R.join('', R.times(R.always('0'), d))}`)(decimals)
71
- ),
72
- formatSeparator
73
- );
74
-
75
- return R.ifElse(
76
- isValidNumber,
77
- R.pipe(
78
- formatScale,
79
- formatDecimals,
80
- res => res === 'NaN' ? String(value) : res
81
- ),
82
- R.always('..')
83
- )(observation.value);
84
- };
@@ -1,19 +0,0 @@
1
- import * as R from 'ramda';
2
-
3
- export const getObservations = (sdmxJson) => R.pipe(
4
- R.pathOr({}, ['data', 'dataSets', 0, 'observations']),
5
- R.mapObjIndexed(
6
- (observation, observationKey) => {
7
- const value = R.head(observation);
8
- const attrValuesIndexes = R.tail(observation);
9
- const dimValuesIndexes = R.split(':', observationKey);
10
-
11
- return ({
12
- key: observationKey,
13
- value,
14
- attrValuesIndexes,
15
- dimValuesIndexes
16
- });
17
- },
18
- )
19
- )(sdmxJson);
@@ -1,16 +0,0 @@
1
- import * as R from 'ramda';
2
- import { REPORTING_YEAR_START_DAY, REPYEARSTART } from '../constants';
3
-
4
- export const getReportingYearStart = (sdmxJson) => {
5
- const attributes = R.pipe(
6
- R.pathOr({}, ['data', 'structure', 'attributes']),
7
- ({ dataSet=[], observation=[], series=[] }) => [...dataSet, ...observation, ...series]
8
- )(sdmxJson);
9
-
10
- const reportYearStartAttr = R.find(({ id }) => {
11
- return id === REPORTING_YEAR_START_DAY || id === REPYEARSTART;
12
- }, attributes) || {};
13
- const reportYearStart = R.pathOr('--01-01', ['values', 0, 'value'], reportYearStartAttr);
14
- const [month = '01', day = '01'] = R.match(/[\d]{2}/g, reportYearStart);
15
- return ({ month, day });
16
- };
@@ -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,69 +0,0 @@
1
- import * as R from 'ramda';
2
- import { extractSdmxArtefacts, focus } from '../';
3
- import { BAR, ROW, TIMELINE } from '../constants';
4
- import { hasFocus } from './utils';
5
-
6
- const sampleFocusTypes = { [BAR]: BAR, [ROW]: ROW, [TIMELINE]: TIMELINE };
7
-
8
- const focusComparator = (op1, op2) => op1.value === op2.value;
9
-
10
- export const focusOptions = (props, state, otherFocus, singularity) => {
11
- if (!hasFocus(props.type)) {
12
- return [];
13
- }
14
- const options = focus(
15
- props.data,
16
- props.type,
17
- singularity,
18
- props.display
19
- );
20
- return R.differenceWith(
21
- focusComparator,
22
- options,
23
- R.prop(otherFocus, state)
24
- );
25
- };
26
-
27
- export const onChangeFocusSelection = (_value) => {
28
- const value = R.isNil(_value) ? [] : _value;
29
- return (R.is(Array, value) ? value : [value]);
30
- };
31
-
32
- const toKey = () => R.prop('value');
33
-
34
- const filterFocus = (focus, keyedOptions, type) => R.reduce(
35
- (acc, entry) => {
36
- const entryKey = toKey(type)(entry);
37
- if (R.has(entryKey, keyedOptions)) {
38
- return R.append(R.prop(entryKey, keyedOptions), acc);
39
- }
40
- return acc;
41
- },
42
- [],
43
- focus
44
- )
45
-
46
- export const focusStateFromNewProps = ({ data, display, type }, singularity, state) => {
47
- const { id } = extractSdmxArtefacts(data);
48
- const highlightState = R.propOr([], 'highlight', state);
49
- const baselineState = R.propOr([], 'baseline', state);
50
- const options = focus(data, type, singularity, display);
51
- const keyedOptions = R.indexBy(toKey(type), options);
52
- return ({
53
- baseline: filterFocus(baselineState, keyedOptions, R.prop('type', state)),
54
- highlight: filterFocus(highlightState, keyedOptions, R.prop('type', state)),
55
- });
56
- };
57
-
58
- /*
59
- This props/state parser which will be exposed in highlight/baseline properties,
60
- only deals for Bar and Row Chart (no chart dimension singularity involved).
61
- For other chart types, their own chart dimension singularity parser will handle focus management.
62
- */
63
-
64
- export const sampleFocusStateFromNewProps = (props, state) => {
65
- if (!R.has(props.type, sampleFocusTypes) || R.isNil(props.data)) {
66
- return ({}); //no changes
67
- }
68
- return focusStateFromNewProps(props, null, state);
69
- };
@@ -1,34 +0,0 @@
1
- import * as R from 'ramda';
2
- import {
3
- CHORO,
4
- OBS_TYPE_NUMBER,
5
- OBS_TYPE_NUMERICAL_STRING,
6
- TIMELINE,
7
- TYPES
8
- } from '../constants';
9
- import { getRefAreaDimension, getTimePeriodDimension } from '@sis-cc/dotstatsuite-sdmxjs';
10
- import { getObservationsType } from './getObservationsType';
11
-
12
- export const getAvailableChartTypes = (data) => {
13
- const observationsType = getObservationsType(data);
14
- if (!R.includes(observationsType, [OBS_TYPE_NUMBER, OBS_TYPE_NUMERICAL_STRING])) {
15
- return {};
16
- }
17
- const dimensions = R.pathOr([], ['structure', 'dimensions', 'observation'], data);
18
- const timeDimension = getTimePeriodDimension({ dimensions });
19
- const refAreaDimension = getRefAreaDimension({ dimensions });
20
- const hasNoTime = R.anyPass([
21
- R.isNil,
22
- R.pipe(R.propOr([], 'values'), R.length, R.gte(1))
23
- ])(timeDimension);
24
- return R.pipe(
25
- R.when(
26
- R.always(hasNoTime),
27
- R.omit([TIMELINE])
28
- ),
29
- R.when(
30
- R.always(R.isNil(refAreaDimension)),
31
- R.omit([CHORO])
32
- )
33
- )(TYPES);
34
- };
@@ -1,74 +0,0 @@
1
- import * as R from 'ramda';
2
- import {
3
- getDefaultSubtitle,
4
- getHeaderUnits,
5
- getSubtitleFlags,
6
- getTitleFlags
7
- } from '../header';
8
- import { dimensionValueDisplay, parseDisplay } from '../';
9
- import { isChart } from './utils';
10
-
11
- const isCustomInvalid = ({ type }) => (value) => R.isNil(value) || !isChart(type);
12
-
13
- const getDataflowName = (props) => {
14
- const dataflow = R.propOr({}, 'dataflow', props);
15
- const display = parseDisplay(props.display);
16
- return dimensionValueDisplay(display)(dataflow);
17
- };
18
-
19
- export const getTitleLabel = (props, state) => R.when(
20
- isCustomInvalid({ type: props.type }),
21
- R.always(getDataflowName(props))
22
- )(state.title);
23
-
24
- export const getSubtitle = (props, state) => R.ifElse(
25
- isCustomInvalid({type: props.type }),
26
- R.always(getDefaultSubtitle({
27
- customAttributes: props.customAttributes,
28
- dimensions: state.dimensions,
29
- display: props.display,
30
- units: state.units
31
- })),
32
- (label) => {
33
- const flags = getSubtitleFlags({
34
- customAttributes: props.customAttributes,
35
- dimensions: state.dimensions,
36
- display: props.display,
37
- units: state.units
38
- });
39
- return ([{ label, flags }]);
40
- }
41
- )(state.subtitle);
42
-
43
- export const getSourceLabel = (props, state) => R.when(
44
- isCustomInvalid({ type: props.type }),
45
- R.always(getDataflowName(props))
46
- )(state.sourceLabel);
47
-
48
- export const getHeaderProps = (props, state) => {
49
- const title = {
50
- label: getTitleLabel(props, state),
51
- flags: getTitleFlags({
52
- customAttributes: props.customAttributes,
53
- dataflowAttributes: state.dataflowAttributes,
54
- display: props.display,
55
- })
56
- };
57
-
58
- const subtitle = getSubtitle(props, state);
59
-
60
- const uprs = getHeaderUnits({
61
- display: props.display,
62
- units: R.assoc(
63
- 'values',
64
- R.pathOr([], ['units', 'headerUnits'], state)
65
- )(R.pathOr({}, ['units', 'unitDimension'], props))
66
- });
67
- return ({ subtitle, title, uprs });
68
- };
69
-
70
- export const getFooterProps = (props, state) => ({
71
- withCopyright: isChart(props.type) ? state.withCopyright : true,
72
- withLogo: isChart(props.type) ? state.withLogo : true,
73
- sourceLabel: getSourceLabel(props, state)
74
- });
@@ -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,29 +0,0 @@
1
- import * as R from 'ramda';
2
- import {
3
- OBS_TYPE_NUMBER,
4
- OBS_TYPE_NUMERICAL_STRING,
5
- OBS_TYPE_STRING
6
- } from '../constants';
7
-
8
- export const getObservationsType = (data) => {
9
- if (R.isNil(data)) {
10
- return undefined;
11
- }
12
- const firstObs = R.pipe(
13
- R.pathOr({}, ['dataSets', 0, 'observations']),
14
- R.values,
15
- R.find(obs => R.not(R.either(R.isNil, R.isEmpty)(R.head(obs))))
16
- )(data);
17
- if (R.isNil(firstObs)) {
18
- return undefined;
19
- }
20
- const firstObsValue = R.head(firstObs);
21
- if (R.is(Number, firstObsValue)) {
22
- return OBS_TYPE_NUMBER;
23
- }
24
- return R.ifElse(
25
- R.equals(NaN),
26
- R.always(OBS_TYPE_STRING),
27
- R.always(OBS_TYPE_NUMERICAL_STRING)
28
- )(Number(firstObsValue));
29
- };
@@ -1,6 +0,0 @@
1
- import * as R from 'ramda';
2
-
3
- export const stringifySubtitle = R.pipe(
4
- R.map(({ header, label }) => R.isNil(header) ? label : `${header} ${label}`),
5
- R.join(' · ')
6
- );