@oanda/labs-crowd-view-widget 1.0.59 → 1.0.60
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 +244 -0
- package/dist/main/CrowdViewWidget/components/Chart/dataUtils/getBucketWidthMultiplayer.js +20 -1
- package/dist/main/CrowdViewWidget/components/Chart/dataUtils/getBucketWidthMultiplayer.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/dataUtils/getBucketWidthMultiplayer.js +20 -1
- package/dist/module/CrowdViewWidget/components/Chart/dataUtils/getBucketWidthMultiplayer.js.map +1 -1
- package/package.json +3 -3
- package/src/CrowdViewWidget/components/Chart/dataUtils/getBucketWidthMultiplayer.ts +26 -1
- package/test/components/Chart/dataUtils/getBucketWidthMultiplayer.test.ts +129 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,250 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 1.0.60 (2025-12-16)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## 1.0.241 (2025-12-16)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## 1.0.240 (2025-12-15)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
## 1.0.239 (2025-12-12)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## 1.0.238 (2025-12-11)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
## 1.0.237 (2025-12-09)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## 1.0.236 (2025-12-05)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
## 1.0.235 (2025-12-04)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
## 1.0.234 (2025-11-27)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
## 1.0.233 (2025-11-27)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
## 1.0.232 (2025-11-27)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
## 1.0.231 (2025-11-07)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
## 1.0.230 (2025-11-05)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
## 1.0.229 (2025-11-05)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
## 1.0.228 (2025-11-05)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
## 1.0.227 (2025-10-31)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
## 1.0.226 (2025-10-29)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
## 1.0.225 (2025-10-09)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
## 1.0.224 (2025-09-29)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
## 1.0.223 (2025-09-29)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
## 1.0.222 (2025-09-17)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
## 1.0.221 (2025-09-11)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
## 1.0.220 (2025-09-09)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
## 1.0.219 (2025-09-02)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
## 1.0.218 (2025-09-01)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
## 1.0.217 (2025-08-25)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
## 1.0.216 (2025-08-18)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
## 1.0.215 (2025-08-18)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
## 1.0.214 (2025-08-14)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
## 1.0.213 (2025-08-12)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
## 1.0.212 (2025-08-05)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
## 1.0.211 (2025-08-05)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
## 1.0.210 (2025-07-31)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
## 1.0.209 (2025-07-31)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
## 1.0.208 (2025-07-24)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
## 1.0.207 (2025-07-18)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
## 1.0.206 (2025-07-18)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
## 1.0.205 (2025-07-17)
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
## 1.0.204 (2025-07-09)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
## 1.0.203 (2025-06-16)
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
## 1.0.202 (2025-06-04)
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
## 1.0.201 (2025-06-02)
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
## 1.0.200 (2025-05-30)
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
## 1.0.199 (2025-05-29)
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
## 1.0.198 (2025-05-26)
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
## 1.0.197 (2025-05-23)
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
## 1.0.196 (2025-05-22)
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
## 1.0.195 (2025-05-21)
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
## 1.0.194 (2025-05-21)
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
## 1.0.193 (2025-05-15)
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
## 1.0.192 (2025-05-14)
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
## 1.0.191 (2025-04-30)
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
## 1.0.190 (2025-04-28)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
## 1.0.189 (2025-04-23)
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
## 1.0.188 (2025-04-22)
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
## 1.0.187 (2025-04-18)
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
## 1.0.186 (2025-04-10)
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
## 1.0.185 (2025-04-09)
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
## 1.0.184 (2025-04-08)
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
## 1.0.183 (2025-04-04)
|
|
243
|
+
|
|
244
|
+
**Note:** Version bump only for package @oanda/labs-crowd-view-widget
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
|
|
6
250
|
## 1.0.59 (2025-12-16)
|
|
7
251
|
|
|
8
252
|
|
|
@@ -5,6 +5,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.getBucketWidthMultiplayer = void 0;
|
|
7
7
|
var _constants = require("../../../constants");
|
|
8
|
+
const roundToClosest = (value, options) => {
|
|
9
|
+
return options.reduce((closest, option) => {
|
|
10
|
+
const distanceToOption = Math.abs(value - option);
|
|
11
|
+
const distanceToClosest = Math.abs(value - closest);
|
|
12
|
+
if (distanceToOption === distanceToClosest) {
|
|
13
|
+
return option > closest ? option : closest;
|
|
14
|
+
}
|
|
15
|
+
return distanceToOption < distanceToClosest ? option : closest;
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
const getRoundingValues = base => {
|
|
19
|
+
return [base, 2 * base, 4 * base, 5 * base, 10 * base];
|
|
20
|
+
};
|
|
8
21
|
const getBucketWidthMultiplayer = _ref => {
|
|
9
22
|
let {
|
|
10
23
|
minPrice,
|
|
@@ -16,7 +29,13 @@ const getBucketWidthMultiplayer = _ref => {
|
|
|
16
29
|
} = _constants.INSTRUMENTS_CONFIG[instrument];
|
|
17
30
|
const priceRange = maxPrice - minPrice;
|
|
18
31
|
const calculatedMultiplier = priceRange / (defaultBucketWidth * _constants.DISPLAYED_BUCKETS_COUNT);
|
|
19
|
-
|
|
32
|
+
if (calculatedMultiplier <= 1) {
|
|
33
|
+
return 1;
|
|
34
|
+
}
|
|
35
|
+
const powerOf10 = Math.floor(Math.log10(calculatedMultiplier));
|
|
36
|
+
const base = Math.pow(10, powerOf10);
|
|
37
|
+
const roundingValues = getRoundingValues(base);
|
|
38
|
+
return roundToClosest(calculatedMultiplier, roundingValues);
|
|
20
39
|
};
|
|
21
40
|
exports.getBucketWidthMultiplayer = getBucketWidthMultiplayer;
|
|
22
41
|
//# sourceMappingURL=getBucketWidthMultiplayer.js.map
|
package/dist/main/CrowdViewWidget/components/Chart/dataUtils/getBucketWidthMultiplayer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBucketWidthMultiplayer.js","names":["_constants","require","getBucketWidthMultiplayer","_ref","minPrice","maxPrice","instrument","defaultBucketWidth","INSTRUMENTS_CONFIG","priceRange","calculatedMultiplier","DISPLAYED_BUCKETS_COUNT","
|
|
1
|
+
{"version":3,"file":"getBucketWidthMultiplayer.js","names":["_constants","require","roundToClosest","value","options","reduce","closest","option","distanceToOption","Math","abs","distanceToClosest","getRoundingValues","base","getBucketWidthMultiplayer","_ref","minPrice","maxPrice","instrument","defaultBucketWidth","INSTRUMENTS_CONFIG","priceRange","calculatedMultiplier","DISPLAYED_BUCKETS_COUNT","powerOf10","floor","log10","pow","roundingValues","exports"],"sources":["../../../../../../src/CrowdViewWidget/components/Chart/dataUtils/getBucketWidthMultiplayer.ts"],"sourcesContent":["import {\n DISPLAYED_BUCKETS_COUNT,\n INSTRUMENTS_CONFIG,\n} from '../../../constants';\nimport type { InstrumentId } from '../../../types';\n\ninterface GetBucketWidthMultiplayerParams {\n minPrice: number;\n maxPrice: number;\n instrument: InstrumentId;\n}\n\nconst roundToClosest = (value: number, options: number[]): number => {\n return options.reduce((closest, option) => {\n const distanceToOption = Math.abs(value - option);\n const distanceToClosest = Math.abs(value - closest);\n\n if (distanceToOption === distanceToClosest) {\n return option > closest ? option : closest;\n }\n\n return distanceToOption < distanceToClosest ? option : closest;\n });\n};\n\nconst getRoundingValues = (base: number): number[] => {\n return [base, 2 * base, 4 * base, 5 * base, 10 * base];\n};\n\nexport const getBucketWidthMultiplayer = ({\n minPrice,\n maxPrice,\n instrument,\n}: GetBucketWidthMultiplayerParams): number => {\n const { defaultBucketWidth } = INSTRUMENTS_CONFIG[instrument];\n const priceRange = maxPrice - minPrice;\n\n const calculatedMultiplier =\n priceRange / (defaultBucketWidth * DISPLAYED_BUCKETS_COUNT);\n\n if (calculatedMultiplier <= 1) {\n return 1;\n }\n\n const powerOf10 = Math.floor(Math.log10(calculatedMultiplier));\n const base = Math.pow(10, powerOf10);\n const roundingValues = getRoundingValues(base);\n\n return roundToClosest(calculatedMultiplier, roundingValues);\n};\n"],"mappings":";;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AAYA,MAAMC,cAAc,GAAGA,CAACC,KAAa,EAAEC,OAAiB,KAAa;EACnE,OAAOA,OAAO,CAACC,MAAM,CAAC,CAACC,OAAO,EAAEC,MAAM,KAAK;IACzC,MAAMC,gBAAgB,GAAGC,IAAI,CAACC,GAAG,CAACP,KAAK,GAAGI,MAAM,CAAC;IACjD,MAAMI,iBAAiB,GAAGF,IAAI,CAACC,GAAG,CAACP,KAAK,GAAGG,OAAO,CAAC;IAEnD,IAAIE,gBAAgB,KAAKG,iBAAiB,EAAE;MAC1C,OAAOJ,MAAM,GAAGD,OAAO,GAAGC,MAAM,GAAGD,OAAO;IAC5C;IAEA,OAAOE,gBAAgB,GAAGG,iBAAiB,GAAGJ,MAAM,GAAGD,OAAO;EAChE,CAAC,CAAC;AACJ,CAAC;AAED,MAAMM,iBAAiB,GAAIC,IAAY,IAAe;EACpD,OAAO,CAACA,IAAI,EAAE,CAAC,GAAGA,IAAI,EAAE,CAAC,GAAGA,IAAI,EAAE,CAAC,GAAGA,IAAI,EAAE,EAAE,GAAGA,IAAI,CAAC;AACxD,CAAC;AAEM,MAAMC,yBAAyB,GAAGC,IAAA,IAIM;EAAA,IAJL;IACxCC,QAAQ;IACRC,QAAQ;IACRC;EAC+B,CAAC,GAAAH,IAAA;EAChC,MAAM;IAAEI;EAAmB,CAAC,GAAGC,6BAAkB,CAACF,UAAU,CAAC;EAC7D,MAAMG,UAAU,GAAGJ,QAAQ,GAAGD,QAAQ;EAEtC,MAAMM,oBAAoB,GACxBD,UAAU,IAAIF,kBAAkB,GAAGI,kCAAuB,CAAC;EAE7D,IAAID,oBAAoB,IAAI,CAAC,EAAE;IAC7B,OAAO,CAAC;EACV;EAEA,MAAME,SAAS,GAAGf,IAAI,CAACgB,KAAK,CAAChB,IAAI,CAACiB,KAAK,CAACJ,oBAAoB,CAAC,CAAC;EAC9D,MAAMT,IAAI,GAAGJ,IAAI,CAACkB,GAAG,CAAC,EAAE,EAAEH,SAAS,CAAC;EACpC,MAAMI,cAAc,GAAGhB,iBAAiB,CAACC,IAAI,CAAC;EAE9C,OAAOX,cAAc,CAACoB,oBAAoB,EAAEM,cAAc,CAAC;AAC7D,CAAC;AAACC,OAAA,CAAAf,yBAAA,GAAAA,yBAAA","ignoreList":[]}
|
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
import { DISPLAYED_BUCKETS_COUNT, INSTRUMENTS_CONFIG } from '../../../constants';
|
|
2
|
+
const roundToClosest = (value, options) => {
|
|
3
|
+
return options.reduce((closest, option) => {
|
|
4
|
+
const distanceToOption = Math.abs(value - option);
|
|
5
|
+
const distanceToClosest = Math.abs(value - closest);
|
|
6
|
+
if (distanceToOption === distanceToClosest) {
|
|
7
|
+
return option > closest ? option : closest;
|
|
8
|
+
}
|
|
9
|
+
return distanceToOption < distanceToClosest ? option : closest;
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
const getRoundingValues = base => {
|
|
13
|
+
return [base, 2 * base, 4 * base, 5 * base, 10 * base];
|
|
14
|
+
};
|
|
2
15
|
export const getBucketWidthMultiplayer = _ref => {
|
|
3
16
|
let {
|
|
4
17
|
minPrice,
|
|
@@ -10,6 +23,12 @@ export const getBucketWidthMultiplayer = _ref => {
|
|
|
10
23
|
} = INSTRUMENTS_CONFIG[instrument];
|
|
11
24
|
const priceRange = maxPrice - minPrice;
|
|
12
25
|
const calculatedMultiplier = priceRange / (defaultBucketWidth * DISPLAYED_BUCKETS_COUNT);
|
|
13
|
-
|
|
26
|
+
if (calculatedMultiplier <= 1) {
|
|
27
|
+
return 1;
|
|
28
|
+
}
|
|
29
|
+
const powerOf10 = Math.floor(Math.log10(calculatedMultiplier));
|
|
30
|
+
const base = Math.pow(10, powerOf10);
|
|
31
|
+
const roundingValues = getRoundingValues(base);
|
|
32
|
+
return roundToClosest(calculatedMultiplier, roundingValues);
|
|
14
33
|
};
|
|
15
34
|
//# sourceMappingURL=getBucketWidthMultiplayer.js.map
|
package/dist/module/CrowdViewWidget/components/Chart/dataUtils/getBucketWidthMultiplayer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBucketWidthMultiplayer.js","names":["DISPLAYED_BUCKETS_COUNT","INSTRUMENTS_CONFIG","getBucketWidthMultiplayer","_ref","minPrice","maxPrice","instrument","defaultBucketWidth","priceRange","calculatedMultiplier","
|
|
1
|
+
{"version":3,"file":"getBucketWidthMultiplayer.js","names":["DISPLAYED_BUCKETS_COUNT","INSTRUMENTS_CONFIG","roundToClosest","value","options","reduce","closest","option","distanceToOption","Math","abs","distanceToClosest","getRoundingValues","base","getBucketWidthMultiplayer","_ref","minPrice","maxPrice","instrument","defaultBucketWidth","priceRange","calculatedMultiplier","powerOf10","floor","log10","pow","roundingValues"],"sources":["../../../../../../src/CrowdViewWidget/components/Chart/dataUtils/getBucketWidthMultiplayer.ts"],"sourcesContent":["import {\n DISPLAYED_BUCKETS_COUNT,\n INSTRUMENTS_CONFIG,\n} from '../../../constants';\nimport type { InstrumentId } from '../../../types';\n\ninterface GetBucketWidthMultiplayerParams {\n minPrice: number;\n maxPrice: number;\n instrument: InstrumentId;\n}\n\nconst roundToClosest = (value: number, options: number[]): number => {\n return options.reduce((closest, option) => {\n const distanceToOption = Math.abs(value - option);\n const distanceToClosest = Math.abs(value - closest);\n\n if (distanceToOption === distanceToClosest) {\n return option > closest ? option : closest;\n }\n\n return distanceToOption < distanceToClosest ? option : closest;\n });\n};\n\nconst getRoundingValues = (base: number): number[] => {\n return [base, 2 * base, 4 * base, 5 * base, 10 * base];\n};\n\nexport const getBucketWidthMultiplayer = ({\n minPrice,\n maxPrice,\n instrument,\n}: GetBucketWidthMultiplayerParams): number => {\n const { defaultBucketWidth } = INSTRUMENTS_CONFIG[instrument];\n const priceRange = maxPrice - minPrice;\n\n const calculatedMultiplier =\n priceRange / (defaultBucketWidth * DISPLAYED_BUCKETS_COUNT);\n\n if (calculatedMultiplier <= 1) {\n return 1;\n }\n\n const powerOf10 = Math.floor(Math.log10(calculatedMultiplier));\n const base = Math.pow(10, powerOf10);\n const roundingValues = getRoundingValues(base);\n\n return roundToClosest(calculatedMultiplier, roundingValues);\n};\n"],"mappings":"AAAA,SACEA,uBAAuB,EACvBC,kBAAkB,QACb,oBAAoB;AAS3B,MAAMC,cAAc,GAAGA,CAACC,KAAa,EAAEC,OAAiB,KAAa;EACnE,OAAOA,OAAO,CAACC,MAAM,CAAC,CAACC,OAAO,EAAEC,MAAM,KAAK;IACzC,MAAMC,gBAAgB,GAAGC,IAAI,CAACC,GAAG,CAACP,KAAK,GAAGI,MAAM,CAAC;IACjD,MAAMI,iBAAiB,GAAGF,IAAI,CAACC,GAAG,CAACP,KAAK,GAAGG,OAAO,CAAC;IAEnD,IAAIE,gBAAgB,KAAKG,iBAAiB,EAAE;MAC1C,OAAOJ,MAAM,GAAGD,OAAO,GAAGC,MAAM,GAAGD,OAAO;IAC5C;IAEA,OAAOE,gBAAgB,GAAGG,iBAAiB,GAAGJ,MAAM,GAAGD,OAAO;EAChE,CAAC,CAAC;AACJ,CAAC;AAED,MAAMM,iBAAiB,GAAIC,IAAY,IAAe;EACpD,OAAO,CAACA,IAAI,EAAE,CAAC,GAAGA,IAAI,EAAE,CAAC,GAAGA,IAAI,EAAE,CAAC,GAAGA,IAAI,EAAE,EAAE,GAAGA,IAAI,CAAC;AACxD,CAAC;AAED,OAAO,MAAMC,yBAAyB,GAAGC,IAAA,IAIM;EAAA,IAJL;IACxCC,QAAQ;IACRC,QAAQ;IACRC;EAC+B,CAAC,GAAAH,IAAA;EAChC,MAAM;IAAEI;EAAmB,CAAC,GAAGlB,kBAAkB,CAACiB,UAAU,CAAC;EAC7D,MAAME,UAAU,GAAGH,QAAQ,GAAGD,QAAQ;EAEtC,MAAMK,oBAAoB,GACxBD,UAAU,IAAID,kBAAkB,GAAGnB,uBAAuB,CAAC;EAE7D,IAAIqB,oBAAoB,IAAI,CAAC,EAAE;IAC7B,OAAO,CAAC;EACV;EAEA,MAAMC,SAAS,GAAGb,IAAI,CAACc,KAAK,CAACd,IAAI,CAACe,KAAK,CAACH,oBAAoB,CAAC,CAAC;EAC9D,MAAMR,IAAI,GAAGJ,IAAI,CAACgB,GAAG,CAAC,EAAE,EAAEH,SAAS,CAAC;EACpC,MAAMI,cAAc,GAAGd,iBAAiB,CAACC,IAAI,CAAC;EAE9C,OAAOX,cAAc,CAACmB,oBAAoB,EAAEK,cAAc,CAAC;AAC7D,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oanda/labs-crowd-view-widget",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.60",
|
|
4
4
|
"description": "Labs Crowd View Widget",
|
|
5
5
|
"main": "dist/main/index.js",
|
|
6
6
|
"module": "dist/module/index.js",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"author": "OANDA",
|
|
14
14
|
"license": "UNLICENSED",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@oanda/labs-widget-common": "^1.0.
|
|
16
|
+
"@oanda/labs-widget-common": "^1.0.242",
|
|
17
17
|
"@oanda/mono-i18n": "10.0.1",
|
|
18
18
|
"chroma-js": "^3.1.2",
|
|
19
19
|
"decimal.js": "^10.6.0",
|
|
@@ -24,5 +24,5 @@
|
|
|
24
24
|
"@graphql-codegen/client-preset": "4.1.0",
|
|
25
25
|
"@types/chroma-js": "^3.1.2"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "5023edd1d0ab11c4d681588f2ee9f9ea482a9605"
|
|
28
28
|
}
|
|
@@ -10,6 +10,23 @@ interface GetBucketWidthMultiplayerParams {
|
|
|
10
10
|
instrument: InstrumentId;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
const roundToClosest = (value: number, options: number[]): number => {
|
|
14
|
+
return options.reduce((closest, option) => {
|
|
15
|
+
const distanceToOption = Math.abs(value - option);
|
|
16
|
+
const distanceToClosest = Math.abs(value - closest);
|
|
17
|
+
|
|
18
|
+
if (distanceToOption === distanceToClosest) {
|
|
19
|
+
return option > closest ? option : closest;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return distanceToOption < distanceToClosest ? option : closest;
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const getRoundingValues = (base: number): number[] => {
|
|
27
|
+
return [base, 2 * base, 4 * base, 5 * base, 10 * base];
|
|
28
|
+
};
|
|
29
|
+
|
|
13
30
|
export const getBucketWidthMultiplayer = ({
|
|
14
31
|
minPrice,
|
|
15
32
|
maxPrice,
|
|
@@ -21,5 +38,13 @@ export const getBucketWidthMultiplayer = ({
|
|
|
21
38
|
const calculatedMultiplier =
|
|
22
39
|
priceRange / (defaultBucketWidth * DISPLAYED_BUCKETS_COUNT);
|
|
23
40
|
|
|
24
|
-
|
|
41
|
+
if (calculatedMultiplier <= 1) {
|
|
42
|
+
return 1;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const powerOf10 = Math.floor(Math.log10(calculatedMultiplier));
|
|
46
|
+
const base = Math.pow(10, powerOf10);
|
|
47
|
+
const roundingValues = getRoundingValues(base);
|
|
48
|
+
|
|
49
|
+
return roundToClosest(calculatedMultiplier, roundingValues);
|
|
25
50
|
};
|
|
@@ -9,7 +9,7 @@ describe('getBucketWidthMultiplayer', () => {
|
|
|
9
9
|
maxPrice: 1.1,
|
|
10
10
|
instrument: InstrumentId.EUR_USD,
|
|
11
11
|
});
|
|
12
|
-
expect(result).toBe(
|
|
12
|
+
expect(result).toBe(2);
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
it('should calculate multiplier correctly for EUR_JPY with standard price range', () => {
|
|
@@ -30,4 +30,132 @@ describe('getBucketWidthMultiplayer', () => {
|
|
|
30
30
|
});
|
|
31
31
|
expect(result).toBe(1);
|
|
32
32
|
});
|
|
33
|
+
|
|
34
|
+
describe('rounding behavior for 1 < multiplier < 10', () => {
|
|
35
|
+
it('should round to closest value from [1, 2, 4, 5, 10]', () => {
|
|
36
|
+
const result1 = getBucketWidthMultiplayer({
|
|
37
|
+
minPrice: 1.0,
|
|
38
|
+
maxPrice: 1.03,
|
|
39
|
+
instrument: InstrumentId.EUR_USD,
|
|
40
|
+
});
|
|
41
|
+
expect(result1).toBe(2);
|
|
42
|
+
|
|
43
|
+
const result2 = getBucketWidthMultiplayer({
|
|
44
|
+
minPrice: 1.0,
|
|
45
|
+
maxPrice: 1.07,
|
|
46
|
+
instrument: InstrumentId.EUR_USD,
|
|
47
|
+
});
|
|
48
|
+
expect(result2).toBe(4);
|
|
49
|
+
|
|
50
|
+
const result3 = getBucketWidthMultiplayer({
|
|
51
|
+
minPrice: 1.0,
|
|
52
|
+
maxPrice: 1.14,
|
|
53
|
+
instrument: InstrumentId.EUR_USD,
|
|
54
|
+
});
|
|
55
|
+
expect(result3).toBe(5);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe('rounding behavior for 10 <= multiplier < 100', () => {
|
|
60
|
+
it('should round to closest value from [10, 20, 40, 50, 100]', () => {
|
|
61
|
+
const result1 = getBucketWidthMultiplayer({
|
|
62
|
+
minPrice: 140.0,
|
|
63
|
+
maxPrice: 164.0,
|
|
64
|
+
instrument: InstrumentId.EUR_JPY,
|
|
65
|
+
});
|
|
66
|
+
expect(result1).toBe(10);
|
|
67
|
+
|
|
68
|
+
const result2 = getBucketWidthMultiplayer({
|
|
69
|
+
minPrice: 140.0,
|
|
70
|
+
maxPrice: 170.0,
|
|
71
|
+
instrument: InstrumentId.EUR_JPY,
|
|
72
|
+
});
|
|
73
|
+
expect(result2).toBe(20);
|
|
74
|
+
|
|
75
|
+
const result3 = getBucketWidthMultiplayer({
|
|
76
|
+
minPrice: 140.0,
|
|
77
|
+
maxPrice: 200.0,
|
|
78
|
+
instrument: InstrumentId.EUR_JPY,
|
|
79
|
+
});
|
|
80
|
+
expect(result3).toBe(40);
|
|
81
|
+
|
|
82
|
+
const result4 = getBucketWidthMultiplayer({
|
|
83
|
+
minPrice: 140.0,
|
|
84
|
+
maxPrice: 210.0,
|
|
85
|
+
instrument: InstrumentId.EUR_JPY,
|
|
86
|
+
});
|
|
87
|
+
expect(result4).toBe(40);
|
|
88
|
+
|
|
89
|
+
const result5 = getBucketWidthMultiplayer({
|
|
90
|
+
minPrice: 140.0,
|
|
91
|
+
maxPrice: 230.0,
|
|
92
|
+
instrument: InstrumentId.EUR_JPY,
|
|
93
|
+
});
|
|
94
|
+
expect(result5).toBe(50);
|
|
95
|
+
|
|
96
|
+
const result6 = getBucketWidthMultiplayer({
|
|
97
|
+
minPrice: 140.0,
|
|
98
|
+
maxPrice: 290.0,
|
|
99
|
+
instrument: InstrumentId.EUR_JPY,
|
|
100
|
+
});
|
|
101
|
+
expect(result6).toBe(100);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe('rounding behavior for 100 <= multiplier < 1000', () => {
|
|
106
|
+
it('should round to closest value from [100, 200, 400, 500, 1000]', () => {
|
|
107
|
+
const result1 = getBucketWidthMultiplayer({
|
|
108
|
+
minPrice: 140.0,
|
|
109
|
+
maxPrice: 440.0,
|
|
110
|
+
instrument: InstrumentId.EUR_JPY,
|
|
111
|
+
});
|
|
112
|
+
expect(result1).toBe(200);
|
|
113
|
+
|
|
114
|
+
const result2 = getBucketWidthMultiplayer({
|
|
115
|
+
minPrice: 140.0,
|
|
116
|
+
maxPrice: 640.0,
|
|
117
|
+
instrument: InstrumentId.EUR_JPY,
|
|
118
|
+
});
|
|
119
|
+
expect(result2).toBe(200);
|
|
120
|
+
|
|
121
|
+
const result3 = getBucketWidthMultiplayer({
|
|
122
|
+
minPrice: 140.0,
|
|
123
|
+
maxPrice: 740.0,
|
|
124
|
+
instrument: InstrumentId.EUR_JPY,
|
|
125
|
+
});
|
|
126
|
+
expect(result3).toBe(400);
|
|
127
|
+
|
|
128
|
+
const result4 = getBucketWidthMultiplayer({
|
|
129
|
+
minPrice: 140.0,
|
|
130
|
+
maxPrice: 1040.0,
|
|
131
|
+
instrument: InstrumentId.EUR_JPY,
|
|
132
|
+
});
|
|
133
|
+
expect(result4).toBe(500);
|
|
134
|
+
|
|
135
|
+
const result5 = getBucketWidthMultiplayer({
|
|
136
|
+
minPrice: 140.0,
|
|
137
|
+
maxPrice: 1640.0,
|
|
138
|
+
instrument: InstrumentId.EUR_JPY,
|
|
139
|
+
});
|
|
140
|
+
expect(result5).toBe(1000);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
describe('rounding behavior for multiplier >= 1000', () => {
|
|
145
|
+
it('should round to closest value from [1000, 2000, 4000, 5000, 10000]', () => {
|
|
146
|
+
const result1 = getBucketWidthMultiplayer({
|
|
147
|
+
minPrice: 140.0,
|
|
148
|
+
maxPrice: 3140.0,
|
|
149
|
+
instrument: InstrumentId.EUR_JPY,
|
|
150
|
+
});
|
|
151
|
+
expect(result1).toBe(2000);
|
|
152
|
+
|
|
153
|
+
const result2 = getBucketWidthMultiplayer({
|
|
154
|
+
minPrice: 140.0,
|
|
155
|
+
maxPrice: 7140.0,
|
|
156
|
+
instrument: InstrumentId.EUR_JPY,
|
|
157
|
+
});
|
|
158
|
+
expect(result2).toBe(4000);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
33
161
|
});
|