@dhis2/analytics 24.0.5 → 24.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/build/cjs/__demo__/FileMenu.stories.js +2 -2
- package/build/cjs/components/FileMenu/SaveAsDialog.js +4 -1
- package/build/cjs/components/FileMenu/__tests__/SaveAsDialog.spec.js +2 -2
- package/build/cjs/locales/en/translations.json +1 -0
- package/build/cjs/locales/uk/translations.json +3 -2
- package/build/cjs/modules/__tests__/getColorByValueFromLegendSet.spec.js +162 -0
- package/build/cjs/modules/legends.js +2 -2
- package/build/es/__demo__/FileMenu.stories.js +2 -2
- package/build/es/components/FileMenu/SaveAsDialog.js +4 -1
- package/build/es/components/FileMenu/__tests__/SaveAsDialog.spec.js +2 -2
- package/build/es/locales/en/translations.json +1 -0
- package/build/es/locales/uk/translations.json +3 -2
- package/build/es/modules/__tests__/getColorByValueFromLegendSet.spec.js +159 -0
- package/build/es/modules/legends.js +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
## [24.0.8](https://github.com/dhis2/analytics/compare/v24.0.7...v24.0.8) (2022-09-06)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* prevent empty values from displaying a legend color ([#1335](https://github.com/dhis2/analytics/issues/1335)) ([5b6567e](https://github.com/dhis2/analytics/commit/5b6567e75ea1d5252f314108998ff24f181f182b))
|
|
7
|
+
|
|
8
|
+
## [24.0.7](https://github.com/dhis2/analytics/compare/v24.0.6...v24.0.7) (2022-08-27)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **translations:** sync translations from transifex (master) ([3246bf2](https://github.com/dhis2/analytics/commit/3246bf2b5eba3ea94b43fcd0dc6d6de4e7b60e46))
|
|
14
|
+
|
|
15
|
+
## [24.0.6](https://github.com/dhis2/analytics/compare/v24.0.5...v24.0.6) (2022-08-26)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* change default value for Save as (DHIS2-13328) ([#1325](https://github.com/dhis2/analytics/issues/1325)) ([1957c51](https://github.com/dhis2/analytics/commit/1957c519a47998f3ae637836861a88dac0ec5110))
|
|
21
|
+
|
|
1
22
|
## [24.0.5](https://github.com/dhis2/analytics/compare/v24.0.4...v24.0.5) (2022-08-26)
|
|
2
23
|
|
|
3
24
|
|
|
@@ -24,10 +24,10 @@ const visObject = {
|
|
|
24
24
|
href: 'http://localhost:8080/api/32/visualizations/a8LrqsBQlHP',
|
|
25
25
|
id: 'a8LrqsBQlHP',
|
|
26
26
|
created: '2012-11-05T09:17:23.388',
|
|
27
|
-
name: 'ANC: 1-3 dropout rate Yearly
|
|
27
|
+
name: 'ANC: 1-3 dropout rate Yearly',
|
|
28
28
|
publicAccess: '--------',
|
|
29
29
|
displayDescription: 'some _italic (10%)_ and some *bold (10%)*',
|
|
30
|
-
displayName: 'ANC: 1-3 dropout rate Yearly
|
|
30
|
+
displayName: 'ANC: 1-3 dropout rate Yearly',
|
|
31
31
|
description: 'some _italic (10%)_ and some *bold (10%)*',
|
|
32
32
|
externalAccess: false,
|
|
33
33
|
access: {
|
|
@@ -30,7 +30,9 @@ const SaveAsDialog = _ref => {
|
|
|
30
30
|
onClose,
|
|
31
31
|
onSaveAs
|
|
32
32
|
} = _ref;
|
|
33
|
-
const [name, setName] = (0, _react.useState)(object
|
|
33
|
+
const [name, setName] = (0, _react.useState)(object !== null && object !== void 0 && object.displayName || object !== null && object !== void 0 && object.name ? _index.default.t('{{objectName}} (copy)', {
|
|
34
|
+
objectName: object.name
|
|
35
|
+
}) : '');
|
|
34
36
|
const [description, setDescription] = (0, _react.useState)(object === null || object === void 0 ? void 0 : object.description); // the actual API request is done in the app
|
|
35
37
|
|
|
36
38
|
const saveObjectAs = () => {
|
|
@@ -83,6 +85,7 @@ exports.SaveAsDialog = SaveAsDialog;
|
|
|
83
85
|
SaveAsDialog.propTypes = {
|
|
84
86
|
object: _propTypes.default.shape({
|
|
85
87
|
description: _propTypes.default.string,
|
|
88
|
+
displayName: _propTypes.default.string,
|
|
86
89
|
name: _propTypes.default.string
|
|
87
90
|
}),
|
|
88
91
|
type: _propTypes.default.oneOf(_utils.supportedFileTypes),
|
|
@@ -44,7 +44,7 @@ describe('The FileMenu - SaveAsDialog component', () => {
|
|
|
44
44
|
});
|
|
45
45
|
it('renders a InputField for name with prefilled value from the object prop', () => {
|
|
46
46
|
const nameInputField = getSaveAsDialogComponent(props).findWhere(n => n.prop('label') === 'Name');
|
|
47
|
-
expect(nameInputField.prop('value')).toEqual(
|
|
47
|
+
expect(nameInputField.prop('value')).toEqual('Save as name test (copy)');
|
|
48
48
|
});
|
|
49
49
|
it('renders a TextAreaField for description with prefilled value from the object prop', () => {
|
|
50
50
|
const descriptionInputField = getSaveAsDialogComponent(props).findWhere(n => n.prop('label') === 'Description');
|
|
@@ -53,7 +53,7 @@ describe('The FileMenu - SaveAsDialog component', () => {
|
|
|
53
53
|
it('calls the onSaveAs callback when the Save button is clicked', () => {
|
|
54
54
|
getSaveAsDialogComponent(props).find(_ui.Button).at(1).simulate('click');
|
|
55
55
|
expect(onSaveAs).toHaveBeenCalledWith({
|
|
56
|
-
name:
|
|
56
|
+
name: 'Save as name test (copy)',
|
|
57
57
|
description: props.object.description
|
|
58
58
|
});
|
|
59
59
|
});
|
|
@@ -83,6 +83,7 @@
|
|
|
83
83
|
"Name": "Ім'я",
|
|
84
84
|
"Description": "Змалювання",
|
|
85
85
|
"Rename": "Перейменувати",
|
|
86
|
+
"{{objectName}} (copy)": "",
|
|
86
87
|
"Save {{fileType}} as": "",
|
|
87
88
|
"event report": "звіт про подію",
|
|
88
89
|
"line list": "",
|
|
@@ -129,14 +130,14 @@
|
|
|
129
130
|
"Created": "Створено",
|
|
130
131
|
"Last updated": "Останнє оновлення",
|
|
131
132
|
"Type": "Тип",
|
|
132
|
-
"Clear filters": "",
|
|
133
|
+
"Clear filters": "Очистити фільтри",
|
|
133
134
|
"{{firstItemIndex}}-{{lastItemIndex}} of {{totalNumberOfItems}}": "",
|
|
134
135
|
"Open": "Відкрити",
|
|
135
136
|
"Couldn't load items": "",
|
|
136
137
|
"There was a problem loading items. Try again or contact your system administrator.": "",
|
|
137
138
|
"No items found. Create a new to get started.": "",
|
|
138
139
|
"No items found. Try adjusting your search or filter options to find what you're looking for.": "",
|
|
139
|
-
"Create new": "",
|
|
140
|
+
"Create new": "Створити новий",
|
|
140
141
|
"Open a visualization": "",
|
|
141
142
|
"Loading visualizations": "",
|
|
142
143
|
"Couldn't load visualizations": "",
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _legends = require("../legends.js");
|
|
4
|
+
|
|
5
|
+
const positiveLegendSet = {
|
|
6
|
+
legends: [{
|
|
7
|
+
startValue: 65,
|
|
8
|
+
endValue: 75,
|
|
9
|
+
color: '#2171b5',
|
|
10
|
+
id: 'ZuBlFGK8U7D',
|
|
11
|
+
name: '65 - 74'
|
|
12
|
+
}, {
|
|
13
|
+
startValue: 35,
|
|
14
|
+
endValue: 45,
|
|
15
|
+
color: '#9ecae1',
|
|
16
|
+
id: 'XTmLeJHmd3m',
|
|
17
|
+
name: '35 - 44'
|
|
18
|
+
}, {
|
|
19
|
+
startValue: 75,
|
|
20
|
+
endValue: 85,
|
|
21
|
+
color: '#08519c',
|
|
22
|
+
id: 'VPEprgLdi1g',
|
|
23
|
+
name: '75 - 84'
|
|
24
|
+
}, {
|
|
25
|
+
startValue: 25,
|
|
26
|
+
endValue: 35,
|
|
27
|
+
color: '#c6dbef',
|
|
28
|
+
id: 'CqUnYcUy2eb',
|
|
29
|
+
name: '25 - 34'
|
|
30
|
+
}, {
|
|
31
|
+
startValue: 15,
|
|
32
|
+
endValue: 25,
|
|
33
|
+
color: '#deebf7',
|
|
34
|
+
id: 'evLlhbRsG6e',
|
|
35
|
+
name: '15 - 24'
|
|
36
|
+
}, {
|
|
37
|
+
startValue: 0,
|
|
38
|
+
endValue: 5,
|
|
39
|
+
color: '#FFFFFF',
|
|
40
|
+
id: 'GHcJ24t8oEs',
|
|
41
|
+
name: '0 - 4'
|
|
42
|
+
}, {
|
|
43
|
+
startValue: 85,
|
|
44
|
+
endValue: 150,
|
|
45
|
+
color: '#08306b',
|
|
46
|
+
id: 'dPFk7tcCg7U',
|
|
47
|
+
name: '85+'
|
|
48
|
+
}, {
|
|
49
|
+
startValue: 45,
|
|
50
|
+
endValue: 55,
|
|
51
|
+
color: '#6baed6',
|
|
52
|
+
id: 'uHBR7cbKoy3',
|
|
53
|
+
name: '45 - 54'
|
|
54
|
+
}, {
|
|
55
|
+
startValue: 5,
|
|
56
|
+
endValue: 15,
|
|
57
|
+
color: '#f7fbff',
|
|
58
|
+
id: 'RUD8IwOsXEW',
|
|
59
|
+
name: '5 - 14'
|
|
60
|
+
}, {
|
|
61
|
+
startValue: 55,
|
|
62
|
+
endValue: 65,
|
|
63
|
+
color: '#4292c6',
|
|
64
|
+
id: 'UojF9VGBvnE',
|
|
65
|
+
name: '55 - 64'
|
|
66
|
+
}],
|
|
67
|
+
name: 'Positive'
|
|
68
|
+
};
|
|
69
|
+
const negativeLegendSet = {
|
|
70
|
+
legends: [{
|
|
71
|
+
startValue: -48,
|
|
72
|
+
endValue: -36,
|
|
73
|
+
color: '#fecc5c',
|
|
74
|
+
id: 'TR60hS8mQag',
|
|
75
|
+
name: '-48 - -36'
|
|
76
|
+
}, {
|
|
77
|
+
startValue: -1000,
|
|
78
|
+
endValue: -60,
|
|
79
|
+
color: '#D10AFF',
|
|
80
|
+
id: 'nxCTJlHd9V2',
|
|
81
|
+
name: 'Critically low'
|
|
82
|
+
}, {
|
|
83
|
+
startValue: -24,
|
|
84
|
+
endValue: -12,
|
|
85
|
+
color: '#f03b20',
|
|
86
|
+
id: 'JOYfGUtyLJF',
|
|
87
|
+
name: '-24 - -12'
|
|
88
|
+
}, {
|
|
89
|
+
startValue: -60,
|
|
90
|
+
endValue: -48,
|
|
91
|
+
color: '#ffffb2',
|
|
92
|
+
id: 'JodoDUR31ig',
|
|
93
|
+
name: '-60 - -48'
|
|
94
|
+
}, {
|
|
95
|
+
startValue: -12,
|
|
96
|
+
endValue: 0,
|
|
97
|
+
color: '#bd0026',
|
|
98
|
+
id: 'rFFEKuATWaZ',
|
|
99
|
+
name: '-12 - 0'
|
|
100
|
+
}, {
|
|
101
|
+
startValue: 0,
|
|
102
|
+
endValue: 10000,
|
|
103
|
+
color: '#A3A3A3',
|
|
104
|
+
id: 'rOD16kf9YzA',
|
|
105
|
+
name: 'Out of bounds'
|
|
106
|
+
}, {
|
|
107
|
+
startValue: -36,
|
|
108
|
+
endValue: -24,
|
|
109
|
+
color: '#fd8d3c',
|
|
110
|
+
id: 'i682LxWmGQ6',
|
|
111
|
+
name: '-36 - -24'
|
|
112
|
+
}],
|
|
113
|
+
name: 'Negative'
|
|
114
|
+
};
|
|
115
|
+
const tests = [{
|
|
116
|
+
legendSet: positiveLegendSet,
|
|
117
|
+
value: 60,
|
|
118
|
+
expected: '#4292c6'
|
|
119
|
+
}, {
|
|
120
|
+
legendSet: positiveLegendSet,
|
|
121
|
+
value: '60.0',
|
|
122
|
+
expected: '#4292c6'
|
|
123
|
+
}, {
|
|
124
|
+
legendSet: positiveLegendSet,
|
|
125
|
+
value: 0,
|
|
126
|
+
expected: '#FFFFFF'
|
|
127
|
+
}, {
|
|
128
|
+
legendSet: positiveLegendSet,
|
|
129
|
+
value: '',
|
|
130
|
+
expected: null
|
|
131
|
+
}, {
|
|
132
|
+
legendSet: positiveLegendSet,
|
|
133
|
+
value: ' ',
|
|
134
|
+
expected: null
|
|
135
|
+
}, {
|
|
136
|
+
legendSet: positiveLegendSet,
|
|
137
|
+
value: 'ABC',
|
|
138
|
+
expected: null
|
|
139
|
+
}, {
|
|
140
|
+
legendSet: negativeLegendSet,
|
|
141
|
+
value: -50,
|
|
142
|
+
expected: '#ffffb2'
|
|
143
|
+
}, {
|
|
144
|
+
legendSet: negativeLegendSet,
|
|
145
|
+
value: '-50.0',
|
|
146
|
+
expected: '#ffffb2'
|
|
147
|
+
}, {
|
|
148
|
+
legendSet: negativeLegendSet,
|
|
149
|
+
value: 0,
|
|
150
|
+
expected: '#A3A3A3'
|
|
151
|
+
}, {
|
|
152
|
+
legendSet: negativeLegendSet,
|
|
153
|
+
value: '',
|
|
154
|
+
expected: null
|
|
155
|
+
}];
|
|
156
|
+
describe('getColorByValueFromLegendSet', () => {
|
|
157
|
+
tests.forEach(t => {
|
|
158
|
+
it("Legend set: ".concat(t.legendSet.name, ", value: ").concat(t.value, ", expected: ").concat(t.expected), () => {
|
|
159
|
+
expect((0, _legends.getColorByValueFromLegendSet)(t.legendSet, t.value)).toEqual(t.expected);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
});
|
|
@@ -16,8 +16,8 @@ exports.LEGEND_DISPLAY_STYLE_TEXT = LEGEND_DISPLAY_STYLE_TEXT;
|
|
|
16
16
|
const getLegendByValueFromLegendSet = (legendSet, value) => {
|
|
17
17
|
var _legendSet$legends;
|
|
18
18
|
|
|
19
|
-
return legendSet === null || legendSet === void 0 ? void 0 : (_legendSet$legends = legendSet.legends) === null || _legendSet$legends === void 0 ? void 0 : _legendSet$legends.find(legend => value >= legend.startValue && value < legend.endValue // TODO: Confirm inclusive/exclusive bounds
|
|
20
|
-
);
|
|
19
|
+
return Number.isInteger(parseInt(value)) ? legendSet === null || legendSet === void 0 ? void 0 : (_legendSet$legends = legendSet.legends) === null || _legendSet$legends === void 0 ? void 0 : _legendSet$legends.find(legend => value >= legend.startValue && value < legend.endValue // TODO: Confirm inclusive/exclusive bounds
|
|
20
|
+
) : null;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
exports.getLegendByValueFromLegendSet = getLegendByValueFromLegendSet;
|
|
@@ -16,10 +16,10 @@ const visObject = {
|
|
|
16
16
|
href: 'http://localhost:8080/api/32/visualizations/a8LrqsBQlHP',
|
|
17
17
|
id: 'a8LrqsBQlHP',
|
|
18
18
|
created: '2012-11-05T09:17:23.388',
|
|
19
|
-
name: 'ANC: 1-3 dropout rate Yearly
|
|
19
|
+
name: 'ANC: 1-3 dropout rate Yearly',
|
|
20
20
|
publicAccess: '--------',
|
|
21
21
|
displayDescription: 'some _italic (10%)_ and some *bold (10%)*',
|
|
22
|
-
displayName: 'ANC: 1-3 dropout rate Yearly
|
|
22
|
+
displayName: 'ANC: 1-3 dropout rate Yearly',
|
|
23
23
|
description: 'some _italic (10%)_ and some *bold (10%)*',
|
|
24
24
|
externalAccess: false,
|
|
25
25
|
access: {
|
|
@@ -11,7 +11,9 @@ export const SaveAsDialog = _ref => {
|
|
|
11
11
|
onClose,
|
|
12
12
|
onSaveAs
|
|
13
13
|
} = _ref;
|
|
14
|
-
const [name, setName] = useState(object
|
|
14
|
+
const [name, setName] = useState(object !== null && object !== void 0 && object.displayName || object !== null && object !== void 0 && object.name ? i18n.t('{{objectName}} (copy)', {
|
|
15
|
+
objectName: object.name
|
|
16
|
+
}) : '');
|
|
15
17
|
const [description, setDescription] = useState(object === null || object === void 0 ? void 0 : object.description); // the actual API request is done in the app
|
|
16
18
|
|
|
17
19
|
const saveObjectAs = () => {
|
|
@@ -62,6 +64,7 @@ export const SaveAsDialog = _ref => {
|
|
|
62
64
|
SaveAsDialog.propTypes = {
|
|
63
65
|
object: PropTypes.shape({
|
|
64
66
|
description: PropTypes.string,
|
|
67
|
+
displayName: PropTypes.string,
|
|
65
68
|
name: PropTypes.string
|
|
66
69
|
}),
|
|
67
70
|
type: PropTypes.oneOf(supportedFileTypes),
|
|
@@ -36,7 +36,7 @@ describe('The FileMenu - SaveAsDialog component', () => {
|
|
|
36
36
|
});
|
|
37
37
|
it('renders a InputField for name with prefilled value from the object prop', () => {
|
|
38
38
|
const nameInputField = getSaveAsDialogComponent(props).findWhere(n => n.prop('label') === 'Name');
|
|
39
|
-
expect(nameInputField.prop('value')).toEqual(
|
|
39
|
+
expect(nameInputField.prop('value')).toEqual('Save as name test (copy)');
|
|
40
40
|
});
|
|
41
41
|
it('renders a TextAreaField for description with prefilled value from the object prop', () => {
|
|
42
42
|
const descriptionInputField = getSaveAsDialogComponent(props).findWhere(n => n.prop('label') === 'Description');
|
|
@@ -45,7 +45,7 @@ describe('The FileMenu - SaveAsDialog component', () => {
|
|
|
45
45
|
it('calls the onSaveAs callback when the Save button is clicked', () => {
|
|
46
46
|
getSaveAsDialogComponent(props).find(Button).at(1).simulate('click');
|
|
47
47
|
expect(onSaveAs).toHaveBeenCalledWith({
|
|
48
|
-
name:
|
|
48
|
+
name: 'Save as name test (copy)',
|
|
49
49
|
description: props.object.description
|
|
50
50
|
});
|
|
51
51
|
});
|
|
@@ -83,6 +83,7 @@
|
|
|
83
83
|
"Name": "Ім'я",
|
|
84
84
|
"Description": "Змалювання",
|
|
85
85
|
"Rename": "Перейменувати",
|
|
86
|
+
"{{objectName}} (copy)": "",
|
|
86
87
|
"Save {{fileType}} as": "",
|
|
87
88
|
"event report": "звіт про подію",
|
|
88
89
|
"line list": "",
|
|
@@ -129,14 +130,14 @@
|
|
|
129
130
|
"Created": "Створено",
|
|
130
131
|
"Last updated": "Останнє оновлення",
|
|
131
132
|
"Type": "Тип",
|
|
132
|
-
"Clear filters": "",
|
|
133
|
+
"Clear filters": "Очистити фільтри",
|
|
133
134
|
"{{firstItemIndex}}-{{lastItemIndex}} of {{totalNumberOfItems}}": "",
|
|
134
135
|
"Open": "Відкрити",
|
|
135
136
|
"Couldn't load items": "",
|
|
136
137
|
"There was a problem loading items. Try again or contact your system administrator.": "",
|
|
137
138
|
"No items found. Create a new to get started.": "",
|
|
138
139
|
"No items found. Try adjusting your search or filter options to find what you're looking for.": "",
|
|
139
|
-
"Create new": "",
|
|
140
|
+
"Create new": "Створити новий",
|
|
140
141
|
"Open a visualization": "",
|
|
141
142
|
"Loading visualizations": "",
|
|
142
143
|
"Couldn't load visualizations": "",
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { getColorByValueFromLegendSet } from '../legends.js';
|
|
2
|
+
const positiveLegendSet = {
|
|
3
|
+
legends: [{
|
|
4
|
+
startValue: 65,
|
|
5
|
+
endValue: 75,
|
|
6
|
+
color: '#2171b5',
|
|
7
|
+
id: 'ZuBlFGK8U7D',
|
|
8
|
+
name: '65 - 74'
|
|
9
|
+
}, {
|
|
10
|
+
startValue: 35,
|
|
11
|
+
endValue: 45,
|
|
12
|
+
color: '#9ecae1',
|
|
13
|
+
id: 'XTmLeJHmd3m',
|
|
14
|
+
name: '35 - 44'
|
|
15
|
+
}, {
|
|
16
|
+
startValue: 75,
|
|
17
|
+
endValue: 85,
|
|
18
|
+
color: '#08519c',
|
|
19
|
+
id: 'VPEprgLdi1g',
|
|
20
|
+
name: '75 - 84'
|
|
21
|
+
}, {
|
|
22
|
+
startValue: 25,
|
|
23
|
+
endValue: 35,
|
|
24
|
+
color: '#c6dbef',
|
|
25
|
+
id: 'CqUnYcUy2eb',
|
|
26
|
+
name: '25 - 34'
|
|
27
|
+
}, {
|
|
28
|
+
startValue: 15,
|
|
29
|
+
endValue: 25,
|
|
30
|
+
color: '#deebf7',
|
|
31
|
+
id: 'evLlhbRsG6e',
|
|
32
|
+
name: '15 - 24'
|
|
33
|
+
}, {
|
|
34
|
+
startValue: 0,
|
|
35
|
+
endValue: 5,
|
|
36
|
+
color: '#FFFFFF',
|
|
37
|
+
id: 'GHcJ24t8oEs',
|
|
38
|
+
name: '0 - 4'
|
|
39
|
+
}, {
|
|
40
|
+
startValue: 85,
|
|
41
|
+
endValue: 150,
|
|
42
|
+
color: '#08306b',
|
|
43
|
+
id: 'dPFk7tcCg7U',
|
|
44
|
+
name: '85+'
|
|
45
|
+
}, {
|
|
46
|
+
startValue: 45,
|
|
47
|
+
endValue: 55,
|
|
48
|
+
color: '#6baed6',
|
|
49
|
+
id: 'uHBR7cbKoy3',
|
|
50
|
+
name: '45 - 54'
|
|
51
|
+
}, {
|
|
52
|
+
startValue: 5,
|
|
53
|
+
endValue: 15,
|
|
54
|
+
color: '#f7fbff',
|
|
55
|
+
id: 'RUD8IwOsXEW',
|
|
56
|
+
name: '5 - 14'
|
|
57
|
+
}, {
|
|
58
|
+
startValue: 55,
|
|
59
|
+
endValue: 65,
|
|
60
|
+
color: '#4292c6',
|
|
61
|
+
id: 'UojF9VGBvnE',
|
|
62
|
+
name: '55 - 64'
|
|
63
|
+
}],
|
|
64
|
+
name: 'Positive'
|
|
65
|
+
};
|
|
66
|
+
const negativeLegendSet = {
|
|
67
|
+
legends: [{
|
|
68
|
+
startValue: -48,
|
|
69
|
+
endValue: -36,
|
|
70
|
+
color: '#fecc5c',
|
|
71
|
+
id: 'TR60hS8mQag',
|
|
72
|
+
name: '-48 - -36'
|
|
73
|
+
}, {
|
|
74
|
+
startValue: -1000,
|
|
75
|
+
endValue: -60,
|
|
76
|
+
color: '#D10AFF',
|
|
77
|
+
id: 'nxCTJlHd9V2',
|
|
78
|
+
name: 'Critically low'
|
|
79
|
+
}, {
|
|
80
|
+
startValue: -24,
|
|
81
|
+
endValue: -12,
|
|
82
|
+
color: '#f03b20',
|
|
83
|
+
id: 'JOYfGUtyLJF',
|
|
84
|
+
name: '-24 - -12'
|
|
85
|
+
}, {
|
|
86
|
+
startValue: -60,
|
|
87
|
+
endValue: -48,
|
|
88
|
+
color: '#ffffb2',
|
|
89
|
+
id: 'JodoDUR31ig',
|
|
90
|
+
name: '-60 - -48'
|
|
91
|
+
}, {
|
|
92
|
+
startValue: -12,
|
|
93
|
+
endValue: 0,
|
|
94
|
+
color: '#bd0026',
|
|
95
|
+
id: 'rFFEKuATWaZ',
|
|
96
|
+
name: '-12 - 0'
|
|
97
|
+
}, {
|
|
98
|
+
startValue: 0,
|
|
99
|
+
endValue: 10000,
|
|
100
|
+
color: '#A3A3A3',
|
|
101
|
+
id: 'rOD16kf9YzA',
|
|
102
|
+
name: 'Out of bounds'
|
|
103
|
+
}, {
|
|
104
|
+
startValue: -36,
|
|
105
|
+
endValue: -24,
|
|
106
|
+
color: '#fd8d3c',
|
|
107
|
+
id: 'i682LxWmGQ6',
|
|
108
|
+
name: '-36 - -24'
|
|
109
|
+
}],
|
|
110
|
+
name: 'Negative'
|
|
111
|
+
};
|
|
112
|
+
const tests = [{
|
|
113
|
+
legendSet: positiveLegendSet,
|
|
114
|
+
value: 60,
|
|
115
|
+
expected: '#4292c6'
|
|
116
|
+
}, {
|
|
117
|
+
legendSet: positiveLegendSet,
|
|
118
|
+
value: '60.0',
|
|
119
|
+
expected: '#4292c6'
|
|
120
|
+
}, {
|
|
121
|
+
legendSet: positiveLegendSet,
|
|
122
|
+
value: 0,
|
|
123
|
+
expected: '#FFFFFF'
|
|
124
|
+
}, {
|
|
125
|
+
legendSet: positiveLegendSet,
|
|
126
|
+
value: '',
|
|
127
|
+
expected: null
|
|
128
|
+
}, {
|
|
129
|
+
legendSet: positiveLegendSet,
|
|
130
|
+
value: ' ',
|
|
131
|
+
expected: null
|
|
132
|
+
}, {
|
|
133
|
+
legendSet: positiveLegendSet,
|
|
134
|
+
value: 'ABC',
|
|
135
|
+
expected: null
|
|
136
|
+
}, {
|
|
137
|
+
legendSet: negativeLegendSet,
|
|
138
|
+
value: -50,
|
|
139
|
+
expected: '#ffffb2'
|
|
140
|
+
}, {
|
|
141
|
+
legendSet: negativeLegendSet,
|
|
142
|
+
value: '-50.0',
|
|
143
|
+
expected: '#ffffb2'
|
|
144
|
+
}, {
|
|
145
|
+
legendSet: negativeLegendSet,
|
|
146
|
+
value: 0,
|
|
147
|
+
expected: '#A3A3A3'
|
|
148
|
+
}, {
|
|
149
|
+
legendSet: negativeLegendSet,
|
|
150
|
+
value: '',
|
|
151
|
+
expected: null
|
|
152
|
+
}];
|
|
153
|
+
describe('getColorByValueFromLegendSet', () => {
|
|
154
|
+
tests.forEach(t => {
|
|
155
|
+
it("Legend set: ".concat(t.legendSet.name, ", value: ").concat(t.value, ", expected: ").concat(t.expected), () => {
|
|
156
|
+
expect(getColorByValueFromLegendSet(t.legendSet, t.value)).toEqual(t.expected);
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
});
|
|
@@ -5,8 +5,8 @@ export const LEGEND_DISPLAY_STYLE_TEXT = 'TEXT';
|
|
|
5
5
|
export const getLegendByValueFromLegendSet = (legendSet, value) => {
|
|
6
6
|
var _legendSet$legends;
|
|
7
7
|
|
|
8
|
-
return legendSet === null || legendSet === void 0 ? void 0 : (_legendSet$legends = legendSet.legends) === null || _legendSet$legends === void 0 ? void 0 : _legendSet$legends.find(legend => value >= legend.startValue && value < legend.endValue // TODO: Confirm inclusive/exclusive bounds
|
|
9
|
-
);
|
|
8
|
+
return Number.isInteger(parseInt(value)) ? legendSet === null || legendSet === void 0 ? void 0 : (_legendSet$legends = legendSet.legends) === null || _legendSet$legends === void 0 ? void 0 : _legendSet$legends.find(legend => value >= legend.startValue && value < legend.endValue // TODO: Confirm inclusive/exclusive bounds
|
|
9
|
+
) : null;
|
|
10
10
|
};
|
|
11
11
|
export const getColorByValueFromLegendSet = (legendSet, value) => {
|
|
12
12
|
const legend = getLegendByValueFromLegendSet(legendSet, value);
|