@sis-cc/dotstatsuite-components 13.4.0 → 13.5.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.
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getTimePeriodLabel = exports.getReportedTimePeriodLabel = exports.getLocale = undefined;
6
+ exports.getTimePeriodLabel = exports.getReportedTimePeriodNote = exports.getReportedTimePeriod = exports.getReportedTimePeriodLabel = exports.getLocale = undefined;
7
7
 
8
8
  var _slicedToArray2 = require('babel-runtime/helpers/slicedToArray');
9
9
 
@@ -119,6 +119,59 @@ var getReportedTimePeriodLabel = exports.getReportedTimePeriodLabel = function g
119
119
  };
120
120
  };
121
121
 
122
+ var getReportedTimePeriod = exports.getReportedTimePeriod = function getReportedTimePeriod(reportYearStart, value, freq) {
123
+ if (reportYearStart.month === '01' && reportYearStart.day === '01') {
124
+ return value;
125
+ }
126
+ var start = new Date(R.prop('start', value));
127
+ start = _dateFns2.default.addMinutes(start, start.getTimezoneOffset());
128
+ start = _dateFns2.default.addMonths(start, reportYearStart.month - 1);
129
+ start = _dateFns2.default.addDays(start, reportYearStart.day - 1);
130
+ var end = void 0;
131
+ if (freq === 'A') {
132
+ end = _dateFns2.default.addYears(start, 1);
133
+ }
134
+ if (freq === 'S') {
135
+ end = _dateFns2.default.addMonths(start, 6);
136
+ }
137
+ if (freq === 'Q') {
138
+ end = _dateFns2.default.addMonths(start, 3);
139
+ }
140
+ if (freq === 'M') {
141
+ end = _dateFns2.default.addMonths(start, 6);
142
+ }
143
+ if (freq === 'W' || freq === 'B') {
144
+ end = _dateFns2.default.addDays(start, 7);
145
+ }
146
+ if (freq === 'D') {
147
+ end = _dateFns2.default.addDays(start, 1);
148
+ }
149
+ if (freq === 'H') {
150
+ end = _dateFns2.default.addHours(start, 1);
151
+ }
152
+ if (freq === 'N') {
153
+ end = _dateFns2.default.addMinutes(start, 1);
154
+ }
155
+ end = _dateFns2.default.subSeconds(end, 1);
156
+ return { start: start, end: end };
157
+ };
158
+
159
+ var getReportedTimePeriodNote = exports.getReportedTimePeriodNote = function getReportedTimePeriodNote(reportYearStart, start, end, freq) {
160
+ if (reportYearStart.month === '01' && reportYearStart.day === '01') {
161
+ return null;
162
+ }
163
+ if (R.includes(freq, ['D', 'H', 'N'])) {
164
+ return null;
165
+ }
166
+ var isFirstDayOfMonth = _dateFns2.default.isFirstDayOfMonth(start);
167
+ if (freq === 'M' && isFirstDayOfMonth) {
168
+ return null;
169
+ }
170
+ var formatedStart = _dateFns2.default.format(start, 'YYYY-MM-DD');
171
+ var formatedEnd = _dateFns2.default.format(end, 'YYYY-MM-DD');
172
+ return { label: formatedStart + ' - ' + formatedEnd };
173
+ };
174
+
122
175
  var getTimePeriodLabel = exports.getTimePeriodLabel = function getTimePeriodLabel(locale) {
123
176
  var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'YYYY MMM';
124
177
  return R.pipe(R.when(R.isNil, R.always('')), R.when(isValidDate, formaterPeriod(locale, format)));
@@ -39,7 +39,7 @@ var getDefaultSubtitle = exports.getDefaultSubtitle = function getDefaultSubtitl
39
39
  return acc;
40
40
  }
41
41
 
42
- var flags = _getFlags({ attributes: R.propOr({}, 'attributes', value) });
42
+ var flags = _getFlags({ attributes: R.propOr({}, 'attributes', value), notes: R.propOr([], 'notes', value) });
43
43
 
44
44
  return R.append({
45
45
  header: formatter(dim) + ':',
@@ -39,7 +39,7 @@ var getSubtitleFlags = exports.getSubtitleFlags = function getSubtitleFlags(_ref
39
39
  return acc;
40
40
  }
41
41
 
42
- var flags = _getFlags({ attributes: R.propOr({}, 'attributes', value) });
42
+ var flags = _getFlags({ attributes: R.propOr({}, 'attributes', value), notes: R.propOr([], 'notes', value) });
43
43
  if (R.isEmpty(flags)) {
44
44
  return acc;
45
45
  }
@@ -32,7 +32,9 @@ var getFlags = exports.getFlags = function getFlags(customAttributesIds, display
32
32
  var _ref$attributes = _ref.attributes,
33
33
  attributes = _ref$attributes === undefined ? {} : _ref$attributes,
34
34
  _ref$units = _ref.units,
35
- units = _ref$units === undefined ? {} : _ref$units;
35
+ units = _ref$units === undefined ? {} : _ref$units,
36
+ _ref$notes = _ref.notes,
37
+ notes = _ref$notes === undefined ? [] : _ref$notes;
36
38
 
37
39
  var refinedAttributes = R.omit(R.propOr([], 'rejected', customAttributesIds), attributes);
38
40
  var flags = R.pipe(R.pick(R.propOr([], 'flags', customAttributesIds)), R.values)(refinedAttributes);
@@ -70,7 +72,9 @@ var getFlags = exports.getFlags = function getFlags(customAttributesIds, display
70
72
  return { code: code, label: label };
71
73
  }, [R.path(['value', 'id']), getAttrLabel(display)])), R.pipe(R.flip(R.concat)(separatedUnitsFootnotes), R.map(R.pipe(getAttrLabel(display), function (label) {
72
74
  return { label: label };
73
- })), R.when(R.always(unitsDisplay === 'cells' && !R.isEmpty(fullUnitsFootnote)), R.append(fullUnitsFootnote)))])(flags, footnotes);
75
+ })), R.when(R.always(unitsDisplay === 'cells' && !R.isEmpty(fullUnitsFootnote)), R.append(fullUnitsFootnote)), function (res) {
76
+ return R.concat(res, notes);
77
+ })])(flags, footnotes);
74
78
  };
75
79
  };
76
80
 
@@ -24,7 +24,7 @@ var getManyValuesDimensions = exports.getManyValuesDimensions = function getMany
24
24
  var dimensionIndex = R.prop(dimension.id, dimensionsIds);
25
25
  var values = R.map(function (value) {
26
26
  var valueAttributes = (0, _refineObservationsAttributesValues.refineObservationsAttributesValues)(attributes)(R.propOr({}, dimensionIndex + ':' + value.__index, attributeValues));
27
- return (0, _extends3.default)({}, R.pick(['id', 'name', '__indexPosition', 'parent', '__index'], value), {
27
+ return (0, _extends3.default)({}, R.pick(['id', 'name', '__indexPosition', 'parent', '__index', 'notes'], value), {
28
28
  attributes: valueAttributes
29
29
  });
30
30
  }, dimension.values);
@@ -66,12 +66,23 @@ var dataTransformer = exports.dataTransformer = function dataTransformer(dataNew
66
66
  var isHidden = R.has(parent + '.' + value.id, hiddenIds) || (0, _sdmxData.getIsHidden)(valueAnnotations);
67
67
  var name = (0, _dotstatsuiteSdmxjs.getRefinedName)(value);
68
68
  var __indexPosition = NaN;
69
+ var notes = [];
69
70
  var start = null;
71
+ var end = null;
70
72
  if (isTimeDimension) {
71
- start = new Date(R.prop('start', value));
72
- start = Date.UTC(_dateFns2.default.getYear(start), _dateFns2.default.getMonth(start), _dateFns2.default.getDate(start), _dateFns2.default.getHours(start), _dateFns2.default.getMinutes(start), _dateFns2.default.getSeconds(start));
73
- start = _dateFns2.default.addMonths(start, reportYearStart.month - 1);
74
- start = _dateFns2.default.addDays(start, reportYearStart.day - 1);
73
+ /*start = new Date(R.prop('start', value));
74
+ start = Date.UTC(dateFns.getYear(start), dateFns.getMonth(start), dateFns.getDate(start), dateFns.getHours(start), dateFns.getMinutes(start), dateFns.getSeconds(start));
75
+ start = dateFns.addMonths(start, reportYearStart.month - 1);
76
+ start = dateFns.addDays(start, reportYearStart.day - 1);
77
+ end = new Date(R.prop('end', value));
78
+ end = Date.UTC(dateFns.getYear(end), dateFns.getMonth(end), dateFns.getDate(end), dateFns.getHours(end), dateFns.getMinutes(end), dateFns.getSeconds(end));
79
+ end = dateFns.addMonths(end, reportYearStart.month - 1);
80
+ end = dateFns.addDays(end, reportYearStart.day - 1);*/
81
+ var reported = (0, _date.getReportedTimePeriod)(reportYearStart, value, options.frequency);
82
+ start = reported.start;
83
+ end = reported.end;
84
+ var reportTimeNote = (0, _date.getReportedTimePeriodNote)(reportYearStart, start, end, options.frequency, options.isRtl);
85
+ notes = R.isNil(reportTimeNote) ? notes : R.append(reportTimeNote, notes);
75
86
  __indexPosition = _dateFns2.default.getTime(new Date(R.prop('start', value)));
76
87
  }
77
88
  if (isNaN(__indexPosition)) {
@@ -83,6 +94,7 @@ var dataTransformer = exports.dataTransformer = function dataTransformer(dataNew
83
94
  display: !isHidden,
84
95
  name: R.when(R.always(isTimeDimension), R.always((0, _date.getReportedTimePeriodLabel)(options.frequency, timeFormat, locale)(reportYearStart, { id: value.id, reportedStart: start, start: value.start })))(name),
85
96
  start: start ? start.toISOString() : null,
97
+ notes: notes,
86
98
  __indexPosition: __indexPosition,
87
99
  __index: __index
88
100
  });
@@ -116,11 +116,9 @@ var getSeriesAdvancedAttributes = exports.getSeriesAdvancedAttributes = function
116
116
  var dim = R.nth(Number(dInd), dimensions);
117
117
  var valId = R.path(['values', Number(vInd), 'id'], dim);
118
118
  var coordinates = (0, _defineProperty3.default)({}, dim.id, valId);
119
- var refinedKey = keyTemplate;
120
- refinedKey[Number(dInd)] = vInd;
119
+ var refinedKey = R.set(R.lensIndex(Number(dInd)), vInd)(keyTemplate);
121
120
  return R.assoc(R.join(':', refinedKey), { attributes: advancedAttributes, coordinates: coordinates }, acc);
122
121
  }, {}, R.keys(series));
123
122
  })(seriesAttributes);
124
-
125
123
  return R.merge(seriesAdvancedAttributes, dimensionsAdvancedAttributes);
126
124
  };
@@ -109,9 +109,7 @@ var parseMetadataSeries = exports.parseMetadataSeries = function parseMetadataSe
109
109
  });
110
110
 
111
111
  return makeTree(R.propOr([], '#ROOT', groupedAttrs));
112
- }, R.reject(function (attr) {
113
- return R.isNil(attr.value) && R.isEmpty(attr.children || []);
114
- }))(metaIndexes);
112
+ })(metaIndexes);
115
113
 
116
114
  return R.assoc(evolvedKey, attributes, acc);
117
115
  }, {}, R.keys(series));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sis-cc/dotstatsuite-components",
3
3
  "description": "Set components based on React.",
4
- "version": "13.4.0",
4
+ "version": "13.5.0",
5
5
  "main": "lib/index.js",
6
6
  "author": "OECD",
7
7
  "license": "MIT",
@@ -55,7 +55,60 @@ export const getReportedTimePeriodLabel = (freq, _format, locale) => (reportYear
55
55
  // freq === 'W'
56
56
  const [week] = R.match(/W[\d]{2}/, id)
57
57
  return `${year}/${nextYear}-${week}`;
58
- }
58
+ };
59
+
60
+ export const getReportedTimePeriod = (reportYearStart, value, freq) => {
61
+ if(reportYearStart.month === '01' && reportYearStart.day === '01') {
62
+ return value;
63
+ }
64
+ let start = new Date(R.prop('start', value));
65
+ start = dateFns.addMinutes(start, start.getTimezoneOffset());
66
+ start = dateFns.addMonths(start, reportYearStart.month - 1);
67
+ start = dateFns.addDays(start, reportYearStart.day - 1);
68
+ let end;
69
+ if (freq === 'A') {
70
+ end = dateFns.addYears(start, 1);
71
+ }
72
+ if (freq === 'S') {
73
+ end = dateFns.addMonths(start, 6);
74
+ }
75
+ if (freq === 'Q') {
76
+ end = dateFns.addMonths(start, 3);
77
+ }
78
+ if (freq === 'M') {
79
+ end = dateFns.addMonths(start, 6);
80
+ }
81
+ if (freq === 'W' || freq === 'B') {
82
+ end = dateFns.addDays(start, 7);
83
+ }
84
+ if (freq === 'D') {
85
+ end = dateFns.addDays(start, 1);
86
+ }
87
+ if (freq === 'H') {
88
+ end = dateFns.addHours(start, 1);
89
+ }
90
+ if (freq === 'N') {
91
+ end = dateFns.addMinutes(start, 1);
92
+ }
93
+ end = dateFns.subSeconds(end, 1);
94
+ return ({ start, end });
95
+ };
96
+
97
+ export const getReportedTimePeriodNote = (reportYearStart, start, end, freq) => {
98
+ if(reportYearStart.month === '01' && reportYearStart.day === '01') {
99
+ return null;
100
+ }
101
+ if (R.includes(freq, ['D', 'H', 'N'])) {
102
+ return null;
103
+ }
104
+ const isFirstDayOfMonth = dateFns.isFirstDayOfMonth(start);
105
+ if (freq === 'M' && isFirstDayOfMonth) {
106
+ return null;
107
+ }
108
+ const formatedStart = dateFns.format(start, 'YYYY-MM-DD');
109
+ const formatedEnd = dateFns.format(end, 'YYYY-MM-DD');
110
+ return ({ label: `${formatedStart} - ${formatedEnd}` });
111
+ };
59
112
 
60
113
 
61
114
  export const getTimePeriodLabel = (locale, format = 'YYYY MMM') => R.pipe(
@@ -26,7 +26,7 @@ export const getDefaultSubtitle = ({ customAttributes, dimensions, display, unit
26
26
  return acc;
27
27
  }
28
28
 
29
- const flags = _getFlags({ attributes: R.propOr({}, 'attributes', value) });
29
+ const flags = _getFlags({ attributes: R.propOr({}, 'attributes', value), notes: R.propOr([], 'notes', value) });
30
30
 
31
31
  return R.append({
32
32
  header: `${formatter(dim)}:`,
@@ -26,7 +26,7 @@ export const getSubtitleFlags = ({ customAttributes, dimensions, display, units
26
26
  return acc;
27
27
  }
28
28
 
29
- const flags = _getFlags({ attributes: R.propOr({}, 'attributes', value) });
29
+ const flags = _getFlags({ attributes: R.propOr({}, 'attributes', value), notes: R.propOr([], 'notes', value) });
30
30
  if (R.isEmpty(flags)) {
31
31
  return acc;
32
32
  }
@@ -4,7 +4,7 @@ import { hasCellMetadata } from '../../../../rules2/src/hasCellMetadata';
4
4
 
5
5
  const getAttrLabel = (display) => (attribute) => `${display(attribute)}: ${display(R.propOr({}, 'value', attribute))}`;
6
6
 
7
- export const getFlags = (customAttributesIds, display, unitsProps) => ({ attributes={}, units={} }) => {
7
+ export const getFlags = (customAttributesIds, display, unitsProps) => ({ attributes={}, units={}, notes=[] }) => {
8
8
  const refinedAttributes = R.omit(R.propOr([], 'rejected', customAttributesIds), attributes);
9
9
  const flags = R.pipe(R.pick(R.propOr([], 'flags', customAttributesIds)), R.values)(refinedAttributes);
10
10
  const footnotes = R.pipe(R.pick(R.propOr([], 'notes', customAttributesIds)), R.values)(refinedAttributes);
@@ -68,7 +68,8 @@ export const getFlags = (customAttributesIds, display, unitsProps) => ({ attribu
68
68
  R.when(
69
69
  R.always(unitsDisplay === 'cells' && !R.isEmpty(fullUnitsFootnote)),
70
70
  R.append(fullUnitsFootnote)
71
- )
71
+ ),
72
+ res => R.concat(res, notes)
72
73
  )
73
74
  ]
74
75
  )(flags, footnotes);
@@ -9,7 +9,7 @@ export const getManyValuesDimensions = (dimensionsByIds, dimensionsIds, attribut
9
9
  const valueAttributes = refineObservationsAttributesValues(attributes)
10
10
  (R.propOr({}, `${dimensionIndex}:${value.__index}`, attributeValues));
11
11
  return ({
12
- ...R.pick(['id', 'name', '__indexPosition', 'parent', '__index'], value),
12
+ ...R.pick(['id', 'name', '__indexPosition', 'parent', '__index', 'notes'], value),
13
13
  attributes: valueAttributes,
14
14
  });
15
15
  }, dimension.values);
@@ -3,7 +3,7 @@ import dateFns from 'date-fns';
3
3
  import { getCodeOrder, getRefinedName, isTimePeriodDimension } from '@sis-cc/dotstatsuite-sdmxjs';
4
4
  import {
5
5
  getRelationnalAnnotations, setAnnotationsLayout, getIsHidden } from './sdmx-data';
6
- import { getReportedTimePeriodLabel } from './date';
6
+ import { getReportedTimePeriodLabel, getReportedTimePeriodNote, getReportedTimePeriod } from './date';
7
7
  import { getReportingYearStart } from './preparators/getReportingYearStart';
8
8
  import { getNotDisplayedIds } from '../../rules2/src';
9
9
 
@@ -43,12 +43,23 @@ export const dataTransformer = (dataNew, options = {}) => {
43
43
  const isHidden = R.has(`${parent}.${value.id}`, hiddenIds) || getIsHidden(valueAnnotations);
44
44
  const name = getRefinedName(value);
45
45
  let __indexPosition = NaN;
46
+ let notes = [];
46
47
  let start = null;
48
+ let end = null;
47
49
  if (isTimeDimension) {
48
- start = new Date(R.prop('start', value));
50
+ /*start = new Date(R.prop('start', value));
49
51
  start = Date.UTC(dateFns.getYear(start), dateFns.getMonth(start), dateFns.getDate(start), dateFns.getHours(start), dateFns.getMinutes(start), dateFns.getSeconds(start));
50
52
  start = dateFns.addMonths(start, reportYearStart.month - 1);
51
53
  start = dateFns.addDays(start, reportYearStart.day - 1);
54
+ end = new Date(R.prop('end', value));
55
+ end = Date.UTC(dateFns.getYear(end), dateFns.getMonth(end), dateFns.getDate(end), dateFns.getHours(end), dateFns.getMinutes(end), dateFns.getSeconds(end));
56
+ end = dateFns.addMonths(end, reportYearStart.month - 1);
57
+ end = dateFns.addDays(end, reportYearStart.day - 1);*/
58
+ const reported = getReportedTimePeriod(reportYearStart, value, options.frequency);
59
+ start = reported.start;
60
+ end = reported.end;
61
+ const reportTimeNote = getReportedTimePeriodNote(reportYearStart, start, end, options.frequency, options.isRtl);
62
+ notes = R.isNil(reportTimeNote) ? notes : R.append(reportTimeNote, notes);
52
63
  __indexPosition = dateFns.getTime(new Date(R.prop('start', value)));
53
64
  }
54
65
  if (isNaN(__indexPosition)) {
@@ -67,6 +78,7 @@ export const dataTransformer = (dataNew, options = {}) => {
67
78
  R.always(getReportedTimePeriodLabel(options.frequency, timeFormat, locale)(reportYearStart, { id: value.id, reportedStart: start, start:value.start }))
68
79
  )(name),
69
80
  start: start ? start.toISOString() : null,
81
+ notes,
70
82
  __indexPosition,
71
83
  __index,
72
84
  });
@@ -100,14 +100,12 @@ export const getSeriesAdvancedAttributes = (seriesAttributes, dimensions, advanc
100
100
  const dim = R.nth(Number(dInd), dimensions);
101
101
  const valId = R.path(['values', Number(vInd), 'id'], dim);
102
102
  const coordinates = { [dim.id]: valId };
103
- let refinedKey = keyTemplate;
104
- refinedKey[Number(dInd)] = vInd;
103
+ const refinedKey = R.set(R.lensIndex(Number(dInd)), vInd)(keyTemplate);
105
104
  return R.assoc(R.join(':', refinedKey), { attributes: advancedAttributes, coordinates }, acc);
106
105
  },
107
106
  {},
108
107
  R.keys(series)
109
108
  )
110
109
  )(seriesAttributes);
111
-
112
110
  return R.merge(seriesAdvancedAttributes, dimensionsAdvancedAttributes);
113
111
  };
@@ -105,7 +105,6 @@ export const parseMetadataSeries = (metadataJson, options) => {
105
105
 
106
106
  return makeTree(R.propOr([], '#ROOT', groupedAttrs));
107
107
  },
108
- R.reject(attr => R.isNil(attr.value) && R.isEmpty(attr.children || []))
109
108
  )(metaIndexes);
110
109
 
111
110
  return R.assoc(evolvedKey, attributes, acc);
@@ -9,6 +9,7 @@ describe('getSeriesAdvancedAttributes tests', () => {
9
9
  '0:1:0:x:x': { attributes: { a0: { id: 'a0' }, a1: { id: 'a1' } } },
10
10
  },
11
11
  dimensions: {
12
+ '2:0': { attributes: { a1: { id: 'a1' } } },
12
13
  '3:0': { attributes: { a0: { id: 'a0' } } },
13
14
  '4:1': { attributes: { a0: { id: 'a0' }, a1: { id: 'a1' } } },
14
15
  }
@@ -24,6 +25,7 @@ describe('getSeriesAdvancedAttributes tests', () => {
24
25
 
25
26
  expect(getSeriesAdvancedAttributes(seriesAttributes, dimensions, advancedAttributesIds)).to.deep.equal({
26
27
  '0:1:0::': { attributes: { a1: { id: 'a1' } }, coordinates: { d0: 'v0', d1: 'v1', d2: 'v0' } },
28
+ '::0::': { attributes: { a1: { id: 'a1' } }, coordinates: { d2: 'v0' } },
27
29
  '::::1': { attributes: { a1: { id: 'a1' } }, coordinates: { d4: 'v1' } }
28
30
  });
29
31
  });