@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,94 +0,0 @@
1
- import {
2
- get, reject, map, reduce, head, findIndex, split, includes, has, each, size, find, keys,
3
- isNil, filter
4
- } from 'lodash';
5
- import { dimensionValueDisplay } from '../dimension-utils';
6
- import { getFormatedObservation } from '../observation-formater';
7
-
8
- export function dimensionValueIsValid(dimensionValue, chartDimension) {
9
- return includes(
10
- map(['x', 'y'], k => get(chartDimension, `${k}Id`)),
11
- get(dimensionValue, 'id')
12
- );
13
- };
14
-
15
- export function getDimensionValues(
16
- dimensionValuesIndexes, dimensions, dimensionsWithValuesIndexedById, chartDimensionId, display
17
- ) {
18
- const dimensionsWithValuesIds = keys(dimensionsWithValuesIndexedById);
19
- return reduce(
20
- dimensionValuesIndexes,
21
- (m, dvi, i) => {
22
- const dimension = get(dimensions, `[${i}]`);
23
- const dimensionId = get(dimension, 'id');
24
- const dimensionValue = get(dimension, `values[${dvi}]`);
25
- if (dimensionId !== chartDimensionId && includes(dimensionsWithValuesIds, dimensionId)) {
26
- m[dimensionId] = { ...dimensionValue, name: dimensionValueDisplay(display)(dimensionValue) };
27
- }
28
- return m;
29
- },
30
- {}
31
- );
32
- };
33
-
34
- export function getDimensionValueKey(chartDimension, dimensionValue) {
35
- return get(chartDimension, 'xId') === get(dimensionValue, 'id') ? 'x' : 'y';
36
- };
37
-
38
- export function datapoints(observations, dimensions, dimensionsWithValuesIndexedById, chartDimension, display, formaterAttrs) {
39
- const chartDimensionId = get(chartDimension, 'id');
40
- const chartDimensionIndex = findIndex(dimensions, { id: chartDimensionId });
41
- const datapoints = reduce(
42
- observations,
43
- (m, o, k) => {
44
- const oDimensionValuesIndexes = split(k, ':');
45
- const oDimensionValueIndex = oDimensionValuesIndexes[chartDimensionIndex];
46
- const oDimensionValue = get(
47
- dimensions,
48
- `[${chartDimensionIndex}].values[${oDimensionValueIndex}]`
49
- );
50
- if (dimensionValueIsValid(oDimensionValue, chartDimension)) {
51
- const oPartialKey = reject(
52
- oDimensionValuesIndexes,
53
- (o, i) => i === chartDimensionIndex
54
- ).join('');
55
- if (!has(m, oPartialKey)) {
56
- const dimensionValues = getDimensionValues(
57
- oDimensionValuesIndexes, dimensions, dimensionsWithValuesIndexedById, chartDimensionId, display
58
- );
59
- m[oPartialKey] = { dimensionValues };
60
- }
61
- const dimensionValueKey = getDimensionValueKey(chartDimension, oDimensionValue);
62
- m[oPartialKey][dimensionValueKey] = head(o);
63
- m[oPartialKey][`${dimensionValueKey}Format`] = getFormatedObservation(o, formaterAttrs);
64
- }
65
- return m;
66
- },
67
- {}
68
- );
69
- // it is possible to have null observations or incomplete datapoints (just an x or y)
70
- return filter(
71
- datapoints,
72
- dp => ((!isNil(dp.x)) && (!isNil(dp.y)))
73
- );
74
- };
75
-
76
- export const series = (observations, dimensions, dimensionsWithValuesIndexedById, chartDimension, display, formaterAttrs) => {
77
- // the 2 following lines may sound absurd but we could have 2 dimensions involved
78
- // and not only 1 as first specified...
79
- const xValues = get(dimensionsWithValuesIndexedById, `${get(chartDimension, 'id')}.values`, []);
80
- const yValues = get(dimensionsWithValuesIndexedById, `${get(chartDimension, 'id')}.values`, []);
81
- const xValue = find(xValues, { id: get(chartDimension, 'xId') });
82
- const yValue = find(yValues, { id: get(chartDimension, 'yId') });
83
- return [{
84
- dimensionValues: {
85
- x: { ...xValue, name: dimensionValueDisplay(display)(xValue) },
86
- y: { ...yValue, name: dimensionValueDisplay(display)(yValue) }
87
- },
88
- datapoints: datapoints(observations, dimensions, dimensionsWithValuesIndexedById, chartDimension, display, formaterAttrs)
89
- }]
90
- };
91
-
92
- export default ({ observations, dimensions }, dimensionsWithValuesIndexedById, chartDimension, display, formaterAttrs) => (
93
- series(observations, dimensions, dimensionsWithValuesIndexedById, chartDimension, display, formaterAttrs)
94
- );
@@ -1,29 +0,0 @@
1
- import * as R from 'ramda';
2
- import { getRefAreaDimension, getTimePeriodDimension } from '@sis-cc/dotstatsuite-sdmxjs';
3
-
4
- export default (dimensions, singularity) => {
5
- const { value, values } = dimensions;
6
- const mode = R.prop('mode', singularity) === 'percent' ? 'percent' : 'values';
7
- if (R.length(values) === 1) {
8
- return ({
9
- limit: R.propOr(Infinity, 'limit', singularity),
10
- mode,
11
- id: R.pathOr(null, [0, 'id'], value)
12
- });
13
- }
14
- let serieDimension = null;
15
- const id = R.prop('id', singularity);
16
- if (!R.isNil(id)) {
17
- serieDimension = R.find(R.propEq('id', id), values);
18
- }
19
- const areaDimension = getRefAreaDimension({ dimensions: values });
20
- const timeDimension = getTimePeriodDimension({ dimensions: values });
21
-
22
- serieDimension = serieDimension || areaDimension || timeDimension || R.head(values);
23
-
24
- return ({
25
- limit: R.propOr(Infinity, 'limit', singularity),
26
- mode,
27
- id: R.propOr(null, 'id', serieDimension)
28
- });
29
- }
@@ -1,185 +0,0 @@
1
- import { isTimePeriodDimension } from '@sis-cc/dotstatsuite-sdmxjs';
2
- import { dimensionValueDisplay } from '../dimension-utils';
3
- import { getObservationFormater } from '../observation-formater';
4
- import * as R from 'ramda';
5
-
6
- const flatDatapoints = (
7
- observations,
8
- dimensions,
9
- dimensionsWithValuesIndexedById,
10
- serieDimensionId,
11
- display,
12
- formaterAttrs,
13
- [stackKey, categoryKey]
14
- ) => {
15
- const datapoints = R.mapObjIndexed(
16
- (observationValue, observationKey) => {
17
- let category = null;
18
- const value = Number(R.head(observationValue));
19
- const formater = getObservationFormater(observationValue, formaterAttrs);
20
- const splittedKey = R.split(':', observationKey);
21
- let layerKey = [];
22
- const layerDimensions = R.addIndex(R.reduce)(
23
- (memo, dimensionValueIndex, dimensionIndex) => {
24
- const dimension = R.nth(dimensionIndex, dimensions);
25
- const _dimensionValue = R.pathOr({}, ['values', Number(dimensionValueIndex)], dimension);
26
- const label = dimensionValueDisplay(display)(_dimensionValue);
27
- const dimensionValue = {
28
- ..._dimensionValue,
29
- index: Number(dimensionValueIndex),
30
- label
31
- };
32
- if (dimension.id === serieDimensionId) {
33
- category = dimensionValue;
34
- }
35
- else if (R.has(dimension.id, dimensionsWithValuesIndexedById)) {
36
- memo.push(dimensionValue);
37
- layerKey.push(dimensionValueIndex);
38
- }
39
- return memo;
40
- },
41
- [],
42
- splittedKey
43
- );
44
- return ({
45
- formater,
46
- [categoryKey]: category,
47
- [stackKey]: value,
48
- layerDimensions,
49
- layerKey: R.join(':', layerKey)
50
- });
51
- },
52
- observations
53
- );
54
-
55
- return R.values(datapoints);
56
- };
57
-
58
- const serie = (
59
- observations,
60
- dimensions,
61
- dimensionsWithValuesIndexedById,
62
- singularity,
63
- display,
64
- formaterAttrs,
65
- [stackKey, categoryKey]
66
- ) => {
67
- const serieDimensionId = R.propOr(null, 'id', singularity);
68
- const serieDimension = R.find(R.propEq('id', serieDimensionId), dimensions);
69
- if (R.isNil(serieDimension)) {
70
- return { datapoints: [], layerSeries: [] };
71
- }
72
- const _flatDatapoints = flatDatapoints(observations, dimensions, dimensionsWithValuesIndexedById, serieDimensionId, display, formaterAttrs, [stackKey, categoryKey]);
73
-
74
- const layeredDatapoints = R.groupBy(
75
- R.prop('layerKey'),
76
- _flatDatapoints
77
- ); // { [layeredKey]: [dps] }
78
-
79
- const layerFullSeries = R.map(
80
- datapoints => ({
81
- layerDimensions: R.prop('layerDimensions', R.head(datapoints)),
82
- layerKey: R.prop('layerKey', R.head(datapoints))
83
- }),
84
- R.values(layeredDatapoints)
85
- ); // [{ layerDimensions, layerKey }]
86
-
87
- const layerLimit = R.propOr(Infinity, 'limit', singularity);
88
- const layerSeries = R.take(layerLimit, R.sortBy(R.prop('layerKey'), layerFullSeries));
89
-
90
- const layeredDatapointsKeyedByCategory = R.mapObjIndexed(
91
- R.indexBy(R.path([categoryKey, 'id'])),
92
- layeredDatapoints
93
- ); // { [layeredKey]: { [x.id]: dp } }
94
-
95
- const datapoints = R.addIndex(R.map)(
96
- (serieValue, index) => {
97
- const serieValueId = serieValue.id;
98
- const category = dimensionValueDisplay(display)(serieValue);
99
- const values = R.map(
100
- ({ layerKey }) => R.pathOr(null, [layerKey, serieValueId, stackKey], layeredDatapointsKeyedByCategory),
101
- layerSeries,
102
- );
103
- const formaters = R.map(
104
- ({ layerKey }) => R.pathOr(null, [layerKey, serieValueId, 'formater'], layeredDatapointsKeyedByCategory),
105
- layerSeries,
106
- );
107
- return ({ category, formaters, index, [categoryKey]: category, [stackKey]: values, key: serieValueId });
108
- },
109
- serieDimension.values
110
- );
111
-
112
- const _datapoints = R.when(
113
- R.pipe(R.length, R.equals(1)),
114
- R.pipe(
115
- R.set(R.lensPath([0, 'category']), ''),
116
- R.set(R.lensPath([0, categoryKey]), ''),
117
- ),
118
- datapoints
119
- );
120
-
121
- return ({
122
- datapoints: _datapoints,
123
- layerSeries: R.map(
124
- layer => ({
125
- id: R.pipe(R.prop('layerDimensions'), R.pluck('id'), R.join(' - '))(layer),
126
- label: R.pipe(R.prop('layerDimensions'), R.pluck('label'), R.join(' - '))(layer),
127
- }),
128
- layerSeries
129
- )
130
- });
131
- };
132
-
133
- const percentSerie = (stackKey) => R.pipe(
134
- R.over(
135
- R.lensProp('datapoints'),
136
- R.map(dp => {
137
- const total = R.pipe(R.map(v => Math.abs(v)), R.sum)(dp[stackKey]);
138
- if (!total) {
139
- return dp;
140
- }
141
- return ({
142
- ...dp,
143
- [stackKey]: R.map(v => (Math.abs(v) / total) * 100, dp[stackKey]),
144
- formaters: null,
145
- });
146
- })
147
- ),
148
- R.of
149
- );
150
-
151
- const serieSortedByTotal = (stackKey) => R.pipe(
152
- R.over(
153
- R.lensProp('datapoints'),
154
- R.sortBy(R.pipe(R.prop(stackKey), R.map(v => v > 0 ? R.negate(v) : 0), R.sum))
155
- ),
156
- R.of
157
- );
158
-
159
- const serieSortedByDataOrder = R.pipe(
160
- R.over(
161
- R.lensProp('datapoints'),
162
- R.sortBy(R.prop('index'))
163
- ),
164
- R.of
165
- );
166
-
167
- export default (
168
- { observations, dimensions },
169
- dimensionsWithValuesIndexedById,
170
- singularity,
171
- display,
172
- formaterAttrs,
173
- [stackKey, categoryKey]
174
- ) => {
175
- const mode = R.propOr('values', 'mode', singularity);
176
- const serieDimensionId = R.propOr(null, 'id', singularity);
177
- const _serie = serie(observations, dimensions, dimensionsWithValuesIndexedById, singularity, display, formaterAttrs, [stackKey, categoryKey]);
178
- if (mode === 'percent') {
179
- return percentSerie(stackKey)(_serie);
180
- }
181
- else if (isTimePeriodDimension({ id: serieDimensionId })) {
182
- return serieSortedByDataOrder(_serie);
183
- }
184
- return serieSortedByTotal(stackKey)(_serie);
185
- };
@@ -1,29 +0,0 @@
1
- import { find, get, head, isEmpty, isUndefined, isNil, reject, take } from 'lodash';
2
- import { isRefAreaDimension, isTimePeriodDimension } from '@sis-cc/dotstatsuite-sdmxjs';
3
-
4
- export default (dimensions, ids) => {
5
- if (isEmpty(dimensions)) return;
6
-
7
- let symbolDimension = undefined;
8
- const id = get(ids, 'id');
9
- if (!isNil(id)) symbolDimension = find(dimensions, { id });
10
-
11
- if (isUndefined(symbolDimension)) {
12
- const isAreaOrTimeDimension = d => isRefAreaDimension(d) || isTimePeriodDimension(d);
13
- const _dimensions1 = reject(dimensions, isAreaOrTimeDimension);
14
- const _dimensions2 = reject(dimensions, isRefAreaDimension);
15
- if (isEmpty(_dimensions1)) {
16
- symbolDimension = head(isEmpty(_dimensions2) ? dimensions : _dimensions2);
17
- }
18
- else {
19
- symbolDimension = head(_dimensions1);
20
- }
21
- }
22
-
23
- const symbolDimensionId = get(symbolDimension, 'id');
24
-
25
- return {
26
- id: symbolDimensionId,
27
- serie: take(symbolDimension.values, 5)
28
- };
29
- }
@@ -1,62 +0,0 @@
1
- import { fill, findIndex, get, head, isEmpty, isNil, map, reduce, split, size, sortBy } from 'lodash';
2
- import { categoryDisplay, dimensionValueDisplay } from '../dimension-utils';
3
- import { getFormatedObservation } from '../observation-formater';
4
-
5
- const series = (observations, dimensions, dimensionsWithValuesIndexedById, symbolDimension, sortDirection, display, formaterAttrs) => {
6
- const symbolDimensionId = get(symbolDimension, 'id', null);
7
- if (symbolDimensionId === null) return [];
8
- const symbolDimensionIndex = findIndex(dimensions, d => d.id === symbolDimensionId);
9
- const datapoints = sortBy(
10
- reduce(
11
- observations,
12
- (memo, observationValue, observationKey) => {
13
- if (!(head(observationValue))) {
14
- // because yes it is possible to have null observations, why not ...
15
- return memo;
16
- }
17
- const oDimensionValuesIndexes = split(observationKey, ':');
18
- const oSymbolDimensionValueIndex = Number(oDimensionValuesIndexes[symbolDimensionIndex]);
19
- const oSymbolDimensionValueId = dimensions[symbolDimensionIndex].values[oSymbolDimensionValueIndex].id;
20
-
21
- const symbolIndex = findIndex(symbolDimension.serie, v => v.id === oSymbolDimensionValueId);
22
- if (symbolIndex === -1) {
23
- return memo;
24
- }
25
- const category = categoryDisplay(oDimensionValuesIndexes, dimensions, dimensionsWithValuesIndexedById, symbolDimensionId, display);
26
- const ids = categoryDisplay(oDimensionValuesIndexes, dimensions, dimensionsWithValuesIndexedById, symbolDimensionId, 'code');
27
- let dpIndex = findIndex(memo, dp => dp.key === ids);
28
- let dpValues = (dpIndex === -1) ? fill(Array(size(symbolDimension.serie)), null) : memo[dpIndex].values;
29
- let dpFormatedValues = (dpIndex === -1) ? fill(Array(size(symbolDimension.serie)), null) : memo[dpIndex].formatedValues;
30
- dpValues[oSymbolDimensionValueIndex] = head(observationValue);
31
- dpFormatedValues[oSymbolDimensionValueIndex] = getFormatedObservation(observationValue, formaterAttrs);
32
- let key = ids;
33
- if (isNil(ids) || isEmpty(ids)) {
34
- key = 'uniq-dp';
35
- }
36
- if (dpIndex !== -1) {
37
- memo[dpIndex].values = dpValues;
38
- memo[dpIndex].formatedValues = dpFormatedValues;
39
- }
40
- else {
41
- memo.push({ category, formatedValues: dpFormatedValues, values: dpValues, key });
42
- }
43
- return memo;
44
- },
45
- []
46
- ),
47
- d => head(d.values) * sortDirection
48
- );
49
- const symbolValues = map(symbolDimension.serie, v => dimensionValueDisplay(display)(v));
50
- return [{ datapoints , symbolValues }];
51
- }
52
-
53
- export default ({ observations, dimensions }, chartType, dimensionsWithValuesIndexedById, symbolDimension, display, formaterAttrs) => {
54
- switch(chartType) {
55
- case 'HorizontalSymbolChart':
56
- return series(observations, dimensions, dimensionsWithValuesIndexedById, symbolDimension, -1, display, formaterAttrs);
57
- case 'VerticalSymbolChart':
58
- return series(observations, dimensions, dimensionsWithValuesIndexedById, symbolDimension, 1, display, formaterAttrs);
59
- default:
60
- return [];
61
- }
62
- }
@@ -1,18 +0,0 @@
1
- import { map, each, findIndex, get, omit, isArray, keys } from 'lodash';
2
-
3
- export default function focus(series, focusSelections) {
4
- return map(
5
- series,
6
- (serie, index) => {
7
- each(focusSelections, (focusSelection, focusKey) => {
8
- const _focusKey = `${focusKey}Index`;
9
- const res = findIndex(
10
- isArray(focusSelection) ? focusSelection : [focusSelection],
11
- focus => focus.value === serie.key
12
- );
13
- serie[`${_focusKey}`] = res;
14
- });
15
- return serie;
16
- }
17
- );
18
- }
@@ -1,91 +0,0 @@
1
- import { findIndex, get, has, head, isEmpty, isNil, map, reduce, sortBy, split } from 'lodash';
2
- import { getTimePeriodDimension } from '@sis-cc/dotstatsuite-sdmxjs';
3
- import { categoryDisplay, dimensionValueDisplayAt } from '../dimension-utils';
4
- import { getFormatedObservation } from '../observation-formater';
5
-
6
- const getDimensionValues = (splitObservationKey, dimensions, dimensionsWithValuesIndexedById, rejectedId, display) => (
7
- reduce(
8
- splitObservationKey,
9
- (memo, dimensionValueIndex, dimensionIndex) => {
10
- const dimension = get(dimensions, `[${dimensionIndex}]`, {});
11
- if (has(dimensionsWithValuesIndexedById, dimension.id) && dimension.id !== rejectedId) {
12
- const dimensionValue = get(dimension, `values[${dimensionValueIndex}]`, {});
13
- memo[dimensionValue.id] = {
14
- ...dimensionValue,
15
- name: dimensionValueDisplayAt(dimension, dimensionValueIndex, display)
16
- }
17
- }
18
- return memo;
19
- },
20
- {}
21
- )
22
- );
23
-
24
- const series = (
25
- observations, dimensions,
26
- dimensionsWithValuesIndexedById,
27
- timePeriodDimensionIndex,
28
- display, formaterAttrs
29
- ) => {
30
- const rawSeries = reduce(
31
- observations,
32
- (memo, o, k) => {
33
- const oDimensionValuesIndexes = split(k, ':');
34
-
35
- const timePeriodDimension = get(dimensions, `[${timePeriodDimensionIndex}]`);
36
- const timePeriodDimensionValueIndex = oDimensionValuesIndexes[timePeriodDimensionIndex];
37
- const timePeriod = get(timePeriodDimension, `values[${timePeriodDimensionValueIndex}]`);
38
-
39
- const datapoint = {
40
- x: timePeriod.start,
41
- y: head(o),
42
- timeLabel: timePeriod.name,
43
- formatedValue: getFormatedObservation(o, formaterAttrs),
44
- dimensionValues: getDimensionValues(
45
- oDimensionValuesIndexes, dimensions, dimensionsWithValuesIndexedById, timePeriodDimension.id, display
46
- ),
47
- //index: Number(timePeriodDimensionValueIndex)
48
- };
49
-
50
- const category = categoryDisplay(
51
- oDimensionValuesIndexes, dimensions, dimensionsWithValuesIndexedById, timePeriodDimension.id, display
52
- );
53
- let key = categoryDisplay(
54
- oDimensionValuesIndexes, dimensions, dimensionsWithValuesIndexedById, timePeriodDimension.id, 'code'
55
- );
56
- if (isNil(key) || isEmpty(key)) {
57
- key = 'uniq-dp';
58
- }
59
- const serieIndex = findIndex(memo, serie => serie.key === key);
60
-
61
- if (serieIndex !== -1) memo[serieIndex].datapoints.push(datapoint);
62
- else memo.push({ datapoints: [datapoint], category, key });
63
-
64
- return memo;
65
- },
66
- []
67
- );
68
- return map(
69
- rawSeries,
70
- serie => ({
71
- ...serie,
72
- datapoints: sortBy(
73
- serie.datapoints,
74
- datapoint => datapoint.x
75
- )
76
- })
77
- );
78
- };
79
-
80
- export default ({ observations, dimensions }, dimensionsWithValuesIndexedById, display, formaterAttrs) => {
81
- const timePeriodDimension = getTimePeriodDimension({ dimensions });
82
- const timePeriodDimensionIndex = timePeriodDimension ? timePeriodDimension.index : -1;
83
- const timePeriodDimensionHasManyPeriods = !has(dimensionsWithValuesIndexedById, get(timePeriodDimension, 'id'));
84
- if ((timePeriodDimensionIndex === -1) || timePeriodDimensionHasManyPeriods) return [];
85
-
86
- return series(
87
- observations, dimensions,
88
- dimensionsWithValuesIndexedById,
89
- timePeriodDimensionIndex, display, formaterAttrs
90
- );
91
- };
@@ -1,134 +0,0 @@
1
- import * as R from 'ramda';
2
- import dateFns from 'date-fns';
3
- import { getCodeOrder } from '@sis-cc/dotstatsuite-sdmxjs';
4
- import { getIsHidden } from './sdmx-data';
5
- import {
6
- getReportedTimePeriodLabel,
7
- getReportedTimePeriodNote,
8
- getReportedTimePeriod,
9
- } from './date';
10
- import { refineTimePeriod } from '../../rules2/src/refineTimePeriod';
11
-
12
- const isNonCoded = R.both(R.has('value'), R.pipe(R.has('id'), R.not));
13
-
14
- const getId = (value, fallbackId) => {
15
- const valueId = R.prop('id', value);
16
- if (valueId) return valueId;
17
- if (isNonCoded(value)) return R.prop('value', value);
18
- // Fallback (value has no id but is not a non-coded)
19
- return fallbackId;
20
- };
21
-
22
- const getName =
23
- ({ isTimeDimension, options, locale, start, reportYearStart }) =>
24
- (value) => {
25
- if (!isTimeDimension) return R.prop('name')(value);
26
- return getReportedTimePeriodLabel(
27
- options.frequency,
28
- options.timeFormat,
29
- locale,
30
- )(reportYearStart, {
31
- id: value.id,
32
- reportedStart: start,
33
- start: new Date(value.start),
34
- });
35
- };
36
-
37
- export const getValuesEnhanced = ({
38
- locale = '',
39
- annotations = [],
40
- isTimeDimension = false,
41
- parent = '',
42
- reportYearStart,
43
- hiddenIds = {},
44
- options = {},
45
- }) => {
46
- return R.pipe(
47
- R.addIndex(R.map)((value, __index) => {
48
- const id = getId(value, `${parent}-${__index}`);
49
-
50
- const valueAnnotations = R.pipe(
51
- R.propOr([], 'annotations'),
52
- R.flip(R.props)(annotations),
53
- )(value);
54
-
55
- const isHidden = R.has(`${parent}.${id}`, hiddenIds) ||
56
- getIsHidden(valueAnnotations);
57
-
58
- const { start, notes } = isTimeDimension
59
- ? getTimePeriodAttributes({ reportYearStart, options })(value)
60
- : { notes: [] };
61
-
62
- let __indexPosition = NaN;
63
- if (isNaN(__indexPosition)) {
64
- __indexPosition = getCodeOrder({ annotations: valueAnnotations });
65
- }
66
- let res = {
67
- // names is explicitely skipped because of metadata "standard"
68
- // not completely aligned with NSI "standard"
69
- // value is explicitely skipped (non-coded) into id
70
- ...R.omit(['names', 'value'], value),
71
- id,
72
- display: !isHidden,
73
- start: start ? start.toISOString() : null,
74
- flags: notes,
75
- __indexPosition,
76
- __index,
77
- isNonCoded: isNonCoded(value),
78
- };
79
- if (!isNonCoded(value)) {
80
- res = R.assoc(
81
- 'name',
82
- getName({ isTimeDimension, options, locale, start, reportYearStart })(
83
- value,
84
- ),
85
- res,
86
- );
87
- }
88
- if (isTimeDimension) {
89
- res = refineTimePeriod(res, {
90
- locale,
91
- monthlyFormat: options.timeFormat,
92
- });
93
- }
94
- return res;
95
- }),
96
- // __indexPosition is used for pre-sorting
97
- R.sortWith(isTimeDimension ? timeDimensionSorts : defaultSorts),
98
- // __indexPosition is reset after pre-sorting
99
- R.addIndex(R.map)((val, index) => R.assoc('__indexPosition', index, val)),
100
- // values are re-sorted by __index after __indexPosition settlement
101
- R.sortBy(R.prop('__index')),
102
- );
103
- };
104
-
105
- const getDateForSort = (key) => (val) => dateFns.getTime(new Date(R.prop(key, val)));
106
- const byStartDate = R.ascend(getDateForSort('start'));
107
- const byEndDate = R.descend(getDateForSort('end'));
108
- const timeDimensionSorts = [byStartDate, byEndDate];
109
- const byIndexPosition = R.ascend(R.prop('__indexPosition'));
110
- const byOrder = R.ascend(R.propOr(-1, 'order'));
111
- const defaultSorts = [byIndexPosition, byOrder];
112
-
113
- const getTimePeriodAttributes =
114
- ({ reportYearStart, options }) =>
115
- (value) => {
116
- const reported = getReportedTimePeriod(
117
- reportYearStart,
118
- value,
119
- options.frequency,
120
- );
121
- const start = reported.start;
122
- const end = reported.end;
123
- const reportTimeNote = getReportedTimePeriodNote(
124
- reportYearStart,
125
- start,
126
- end,
127
- options.frequency,
128
- options.isRtl,
129
- );
130
- const notes = R.isNil(reportTimeNote)
131
- ? []
132
- : R.append(reportTimeNote, []);
133
- return { start, notes };
134
- };
@@ -1,40 +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 getDefaultSubtitle = ({ 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
-
31
- return R.append({
32
- header: `${formatter(dim)}:`,
33
- label: formatter(value),
34
- flags
35
- }, acc);
36
- },
37
- []
38
- )
39
- )(dimensions);
40
- };