@oanda/labs-currency-power-balance-widget 1.0.105 → 1.0.106
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 +428 -0
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/Chart.js +6 -2
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/Chart.js.map +1 -1
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/options/constants.js +3 -2
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/options/constants.js.map +1 -1
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/options/formatters.js +1 -1
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/options/formatters.js.map +1 -1
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/options/getOption.js +50 -6
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/options/getOption.js.map +1 -1
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/options/utils.js +10 -0
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/options/utils.js.map +1 -0
- package/dist/main/translations/sources/en.json +1 -0
- package/dist/main/translations/sources/es.json +1 -0
- package/dist/main/translations/sources/th.json +1 -0
- package/dist/main/translations/sources/zh_TW.json +1 -0
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/Chart.js +7 -3
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/Chart.js.map +1 -1
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/constants.js +3 -2
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/constants.js.map +1 -1
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/formatters.js +2 -2
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/formatters.js.map +1 -1
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/getOption.js +50 -6
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/getOption.js.map +1 -1
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/utils.js +4 -0
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/utils.js.map +1 -0
- package/dist/module/translations/sources/en.json +1 -0
- package/dist/module/translations/sources/es.json +1 -0
- package/dist/module/translations/sources/th.json +1 -0
- package/dist/module/translations/sources/zh_TW.json +1 -0
- package/dist/types/CurrencyPowerBalanceWidget/components/Chart/options/constants.d.ts +3 -2
- package/dist/types/CurrencyPowerBalanceWidget/components/Chart/options/getOption.d.ts +40 -4
- package/dist/types/CurrencyPowerBalanceWidget/components/Chart/options/utils.d.ts +2 -0
- package/package.json +3 -3
- package/src/CurrencyPowerBalanceWidget/components/Chart/Chart.tsx +5 -2
- package/src/CurrencyPowerBalanceWidget/components/Chart/options/{constants.tsx → constants.ts} +5 -2
- package/src/CurrencyPowerBalanceWidget/components/Chart/options/formatters.ts +4 -4
- package/src/CurrencyPowerBalanceWidget/components/Chart/options/getOption.ts +54 -4
- package/src/CurrencyPowerBalanceWidget/components/Chart/options/utils.ts +12 -0
- package/src/translations/sources/en.json +1 -0
- package/src/translations/sources/es.json +1 -0
- package/src/translations/sources/th.json +1 -0
- package/src/translations/sources/zh_TW.json +1 -0
- package/test/chartFormatters.test.ts +3 -1
- package/test/utils.test.ts +34 -0
|
@@ -1,15 +1,34 @@
|
|
|
1
|
+
import { darkTheme, lightTheme } from '@oanda/labs-widget-common';
|
|
1
2
|
import { COLOR_CONFIG, TOOLTIP_LINE_COLOR_CONFIG } from './constants';
|
|
2
3
|
import {
|
|
3
4
|
intervalFormatter, tooltipFormatter, xAxisLabelFormatter, formatLegendData,
|
|
4
5
|
} from './formatters';
|
|
5
6
|
import { CurrencyPowerBalance, CurrencyPowerBalanceTimeUnit } from '../../../../gql/types/graphql';
|
|
7
|
+
import { findLastIndexesBeforeWeekend } from './utils';
|
|
6
8
|
|
|
7
9
|
const getOption = (
|
|
8
10
|
chartData: CurrencyPowerBalance[],
|
|
9
11
|
timeUnit: CurrencyPowerBalanceTimeUnit,
|
|
10
12
|
isDark: boolean,
|
|
13
|
+
lang: (key: string) => string,
|
|
11
14
|
) => {
|
|
12
|
-
const
|
|
15
|
+
const currentTheme = isDark ? darkTheme : lightTheme;
|
|
16
|
+
const dataTimestamps = chartData[0].power.map((x) => new Date(x.point).getTime());
|
|
17
|
+
const weekendsIndexes = findLastIndexesBeforeWeekend(dataTimestamps);
|
|
18
|
+
const disableWeekendsIndicator = [
|
|
19
|
+
CurrencyPowerBalanceTimeUnit.CurrentDay,
|
|
20
|
+
CurrencyPowerBalanceTimeUnit.PreviousDay,
|
|
21
|
+
CurrencyPowerBalanceTimeUnit.M3,
|
|
22
|
+
].includes(timeUnit) || weekendsIndexes.length === 0;
|
|
23
|
+
|
|
24
|
+
const weekendsMarks = weekendsIndexes.map((item) => ({
|
|
25
|
+
xAxis: item,
|
|
26
|
+
label: {
|
|
27
|
+
formatter: () => lang('market_closed'),
|
|
28
|
+
},
|
|
29
|
+
}));
|
|
30
|
+
|
|
31
|
+
const seriesData = chartData.map(({ currency, power }, index) => ({
|
|
13
32
|
name: currency,
|
|
14
33
|
type: 'line',
|
|
15
34
|
symbol: 'circle',
|
|
@@ -17,10 +36,41 @@ const getOption = (
|
|
|
17
36
|
itemStyle: {
|
|
18
37
|
color: COLOR_CONFIG[currency],
|
|
19
38
|
},
|
|
20
|
-
lineStyle: {
|
|
21
|
-
color: COLOR_CONFIG[currency],
|
|
22
|
-
},
|
|
23
39
|
data: power.map(({ point, price }) => [point, price]),
|
|
40
|
+
markLine: index === chartData.length - 1 && !disableWeekendsIndicator ? {
|
|
41
|
+
label: {
|
|
42
|
+
show: false,
|
|
43
|
+
position: 'end',
|
|
44
|
+
align: 'center',
|
|
45
|
+
distance: -32,
|
|
46
|
+
padding: [8, 8],
|
|
47
|
+
fontSize: 12,
|
|
48
|
+
shadowBlur: 24,
|
|
49
|
+
shadowOffsetX: 0,
|
|
50
|
+
shadowOffsetY: 6,
|
|
51
|
+
borderWidth: 0,
|
|
52
|
+
color: currentTheme.textPrimary,
|
|
53
|
+
shadowColor: 'rgba(0,0,0,0.1)',
|
|
54
|
+
borderRadius: 4,
|
|
55
|
+
backgroundColor: isDark ? currentTheme.borderPrimary : currentTheme.backgroundSecondary,
|
|
56
|
+
},
|
|
57
|
+
show: false,
|
|
58
|
+
emphasis: {
|
|
59
|
+
label: {
|
|
60
|
+
show: true,
|
|
61
|
+
},
|
|
62
|
+
lineStyle: {
|
|
63
|
+
width: 1,
|
|
64
|
+
opacity: 0,
|
|
65
|
+
color: currentTheme.borderPrimary,
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
symbol: ['none', 'none'],
|
|
69
|
+
itemStyle: {
|
|
70
|
+
color: currentTheme.borderPrimary,
|
|
71
|
+
},
|
|
72
|
+
data: weekendsMarks,
|
|
73
|
+
} : undefined,
|
|
24
74
|
}));
|
|
25
75
|
|
|
26
76
|
const legendData = formatLegendData(chartData);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { WEEKEND_DURATION } from './constants';
|
|
2
|
+
|
|
3
|
+
const findLastIndexesBeforeWeekend = (timestamps: number[]) => timestamps
|
|
4
|
+
.reduce((acc, timestamp, index) => (
|
|
5
|
+
timestamps.length - 1 !== index && timestamps[index + 1] - timestamp >= WEEKEND_DURATION
|
|
6
|
+
? [...acc, index]
|
|
7
|
+
: acc
|
|
8
|
+
), [] as number[]);
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
findLastIndexesBeforeWeekend,
|
|
12
|
+
};
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"hour": "{{count}} Hour",
|
|
11
11
|
"hour_plural": "{{count}} Hours",
|
|
12
12
|
"last_updated": "Last updated",
|
|
13
|
+
"market_closed": "market closed",
|
|
13
14
|
"month": "{{count}} Month",
|
|
14
15
|
"month_plural": "{{count}} Months",
|
|
15
16
|
"pagination_entries_range": "{{firstItemOnPage}}-{{lastItemOnPage}} of {{itemCount}} entries",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"hour": "{{count}} Hora",
|
|
11
11
|
"hour_plural": "{{count}} Horas",
|
|
12
12
|
"last_updated": "Última actualización",
|
|
13
|
+
"market_closed": "mercado cerrado",
|
|
13
14
|
"month": "{{count}} Mes",
|
|
14
15
|
"month_plural": "{{count}} Meses",
|
|
15
16
|
"pagination_entries_range": "{{firstItemOnPage}}-{{lastItemOnPage}} de {{itemCount}} entradas",
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"data_unavailable": "ข้อมูลไม่พร้อมใช้งาน",
|
|
10
10
|
"hour_0": "{{count}} ชั่วโมง",
|
|
11
11
|
"last_updated": "ปรับปรุงล่าสุด",
|
|
12
|
+
"market_closed": "ตลาดปิดทำการ",
|
|
12
13
|
"month_0": "{{count}} เดือน",
|
|
13
14
|
"pagination_entries_range": "{{firstItemOnPage}}-{{lastItemOnPage}} จาก {{itemCount}} รายการ",
|
|
14
15
|
"previous_business_day": "วันทำการก่อนหน้า",
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"data_unavailable": "沒有數據",
|
|
10
10
|
"hour_0": "{{count}} 時",
|
|
11
11
|
"last_updated": "最後更新",
|
|
12
|
+
"market_closed": "市場已收盤",
|
|
12
13
|
"month_0": "{{count}} 月",
|
|
13
14
|
"pagination_entries_range": "{{itemCount}}个挂单中的{{firstItemOnPage}}-{{lastItemOnPage}}",
|
|
14
15
|
"previous_business_day": "前一營業日",
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
* @jest-environment jsdom
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
intervalFormatter, xAxisLabelFormatter, tooltipFormatter,
|
|
7
|
+
} from '../src/CurrencyPowerBalanceWidget/components/Chart/options/formatters';
|
|
6
8
|
import { CurrencyPowerBalanceTimeUnit } from '../src/gql/types/graphql';
|
|
7
9
|
|
|
8
10
|
describe('intervalFormatter', () => {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { findLastIndexesBeforeWeekend } from '../src/CurrencyPowerBalanceWidget/components/Chart/options/utils';
|
|
2
|
+
|
|
3
|
+
describe('findLastIndexesBeforeWeekend', () => {
|
|
4
|
+
it('should return an empty array if there are no weekends', () => {
|
|
5
|
+
const timestamps = [
|
|
6
|
+
1679952000000, // Monday
|
|
7
|
+
1680038400000, // Tuesday
|
|
8
|
+
1680124800000, // Wednesday
|
|
9
|
+
1680211200000, // Thursday
|
|
10
|
+
1680297600000, // Friday
|
|
11
|
+
];
|
|
12
|
+
const expected: number[] = [];
|
|
13
|
+
expect(findLastIndexesBeforeWeekend(timestamps)).toEqual(expected);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should return an array of weekend indexes', () => {
|
|
17
|
+
const timestamps = [
|
|
18
|
+
1679952000000, // Monday
|
|
19
|
+
1680038400000, // Tuesday
|
|
20
|
+
1680124800000, // Wednesday
|
|
21
|
+
1680211200000, // Thursday
|
|
22
|
+
1680297600000, // Friday
|
|
23
|
+
1680556800000, // Monday
|
|
24
|
+
1680643200000, // Tuesday
|
|
25
|
+
1680729600000, // Wednesday
|
|
26
|
+
1680816000000, // Thursday
|
|
27
|
+
1680902400000, // Friday
|
|
28
|
+
1681161600000, // Monday
|
|
29
|
+
|
|
30
|
+
];
|
|
31
|
+
const expected = [4, 9];
|
|
32
|
+
expect(findLastIndexesBeforeWeekend(timestamps)).toEqual(expected);
|
|
33
|
+
});
|
|
34
|
+
});
|