@oanda/labs-currency-power-balance-widget 1.0.105 → 1.0.107
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 +860 -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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getOption.js","names":["COLOR_CONFIG","TOOLTIP_LINE_COLOR_CONFIG","intervalFormatter","tooltipFormatter","xAxisLabelFormatter","formatLegendData","getOption","chartData","timeUnit","isDark","
|
|
1
|
+
{"version":3,"file":"getOption.js","names":["darkTheme","lightTheme","COLOR_CONFIG","TOOLTIP_LINE_COLOR_CONFIG","intervalFormatter","tooltipFormatter","xAxisLabelFormatter","formatLegendData","CurrencyPowerBalanceTimeUnit","findLastIndexesBeforeWeekend","getOption","chartData","timeUnit","isDark","lang","currentTheme","dataTimestamps","power","map","x","Date","point","getTime","weekendsIndexes","disableWeekendsIndicator","CurrentDay","PreviousDay","M3","includes","length","weekendsMarks","item","xAxis","label","formatter","seriesData","_ref","index","currency","name","type","symbol","showSymbol","itemStyle","color","data","_ref2","price","markLine","show","position","align","distance","padding","fontSize","shadowBlur","shadowOffsetX","shadowOffsetY","borderWidth","textPrimary","shadowColor","borderRadius","backgroundColor","borderPrimary","backgroundSecondary","emphasis","lineStyle","width","opacity","undefined","legendData","animation","legend","bottom","icon","tooltip","trigger","axisPointer","axis","z","DARK","LIGHT","extraCssText","axisTick","axisLine","splitLine","axisLabel","margin","rotate","interval","yAxis","splitNumber","boundaryGap","showMaxLabel","showMinLabel","series"],"sources":["../../../../../../src/CurrencyPowerBalanceWidget/components/Chart/options/getOption.ts"],"sourcesContent":["import { darkTheme, lightTheme } from '@oanda/labs-widget-common';\nimport { COLOR_CONFIG, TOOLTIP_LINE_COLOR_CONFIG } from './constants';\nimport {\n intervalFormatter, tooltipFormatter, xAxisLabelFormatter, formatLegendData,\n} from './formatters';\nimport { CurrencyPowerBalance, CurrencyPowerBalanceTimeUnit } from '../../../../gql/types/graphql';\nimport { findLastIndexesBeforeWeekend } from './utils';\n\nconst getOption = (\n chartData: CurrencyPowerBalance[],\n timeUnit: CurrencyPowerBalanceTimeUnit,\n isDark: boolean,\n lang: (key: string) => string,\n) => {\n const currentTheme = isDark ? darkTheme : lightTheme;\n const dataTimestamps = chartData[0].power.map((x) => new Date(x.point).getTime());\n const weekendsIndexes = findLastIndexesBeforeWeekend(dataTimestamps);\n const disableWeekendsIndicator = [\n CurrencyPowerBalanceTimeUnit.CurrentDay,\n CurrencyPowerBalanceTimeUnit.PreviousDay,\n CurrencyPowerBalanceTimeUnit.M3,\n ].includes(timeUnit) || weekendsIndexes.length === 0;\n\n const weekendsMarks = weekendsIndexes.map((item) => ({\n xAxis: item,\n label: {\n formatter: () => lang('market_closed'),\n },\n }));\n\n const seriesData = chartData.map(({ currency, power }, index) => ({\n name: currency,\n type: 'line',\n symbol: 'circle',\n showSymbol: false,\n itemStyle: {\n color: COLOR_CONFIG[currency],\n },\n data: power.map(({ point, price }) => [point, price]),\n markLine: index === chartData.length - 1 && !disableWeekendsIndicator ? {\n label: {\n show: false,\n position: 'end',\n align: 'center',\n distance: -32,\n padding: [8, 8],\n fontSize: 12,\n shadowBlur: 24,\n shadowOffsetX: 0,\n shadowOffsetY: 6,\n borderWidth: 0,\n color: currentTheme.textPrimary,\n shadowColor: 'rgba(0,0,0,0.1)',\n borderRadius: 4,\n backgroundColor: isDark ? currentTheme.borderPrimary : currentTheme.backgroundSecondary,\n },\n show: false,\n emphasis: {\n label: {\n show: true,\n },\n lineStyle: {\n width: 1,\n opacity: 0,\n color: currentTheme.borderPrimary,\n },\n },\n symbol: ['none', 'none'],\n itemStyle: {\n color: currentTheme.borderPrimary,\n },\n data: weekendsMarks,\n } : undefined,\n }));\n\n const legendData = formatLegendData(chartData);\n\n return {\n animation: false,\n legend: {\n data: legendData,\n bottom: 10,\n icon: 'circle',\n },\n tooltip: {\n trigger: 'axis',\n axisPointer: {\n axis: 'x',\n z: 0,\n lineStyle: {\n color: isDark ? TOOLTIP_LINE_COLOR_CONFIG.DARK : TOOLTIP_LINE_COLOR_CONFIG.LIGHT,\n },\n },\n formatter: tooltipFormatter,\n extraCssText: 'z-index: 1',\n },\n xAxis: {\n type: 'category',\n axisTick: {\n show: false,\n },\n axisLine: { show: false },\n splitLine: {\n show: true,\n },\n axisLabel: {\n padding: [0, 0, 0, 4],\n align: 'left',\n margin: 10,\n rotate: -45,\n interval: intervalFormatter(seriesData[0].data.length),\n formatter: (label: string) => xAxisLabelFormatter(label, timeUnit),\n },\n },\n yAxis: {\n type: 'value',\n position: 'right',\n splitNumber: 5,\n axisLine: { show: false },\n axisTick: { show: false },\n boundaryGap: ['10%', '10%'],\n axisLabel: {\n showMaxLabel: false,\n showMinLabel: false,\n },\n },\n series: seriesData,\n };\n};\n\nexport { getOption };\n"],"mappings":"AAAA,SAASA,SAAS,EAAEC,UAAU,QAAQ,2BAA2B;AACjE,SAASC,YAAY,EAAEC,yBAAyB,QAAQ,aAAa;AACr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E,KAAK;QACnBC,YAAY,EAAE;MAChB;IACF,CAAC;IACDC,MAAM,EAAE5D;EACV,CAAC;AACH,CAAC;AAED,SAASzB,SAAS","ignoreList":[]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { WEEKEND_DURATION } from './constants';
|
|
2
|
+
const findLastIndexesBeforeWeekend = timestamps => timestamps.reduce((acc, timestamp, index) => timestamps.length - 1 !== index && timestamps[index + 1] - timestamp >= WEEKEND_DURATION ? [...acc, index] : acc, []);
|
|
3
|
+
export { findLastIndexesBeforeWeekend };
|
|
4
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","names":["WEEKEND_DURATION","findLastIndexesBeforeWeekend","timestamps","reduce","acc","timestamp","index","length"],"sources":["../../../../../../src/CurrencyPowerBalanceWidget/components/Chart/options/utils.ts"],"sourcesContent":["import { WEEKEND_DURATION } from './constants';\n\nconst findLastIndexesBeforeWeekend = (timestamps: number[]) => timestamps\n .reduce((acc, timestamp, index) => (\n timestamps.length - 1 !== index && timestamps[index + 1] - timestamp >= WEEKEND_DURATION\n ? [...acc, index]\n : acc\n ), [] as number[]);\n\nexport {\n findLastIndexesBeforeWeekend,\n};\n"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,aAAa;AAE9C,MAAMC,4BAA4B,GAAIC,UAAoB,IAAKA,UAAU,CACtEC,MAAM,CAAC,CAACC,GAAG,EAAEC,SAAS,EAAEC,KAAK,KAC5BJ,UAAU,CAACK,MAAM,GAAG,CAAC,KAAKD,KAAK,IAAIJ,UAAU,CAACI,KAAK,GAAG,CAAC,CAAC,GAAGD,SAAS,IAAIL,gBAAgB,GACpF,CAAC,GAAGI,GAAG,EAAEE,KAAK,CAAC,GACfF,GACL,EAAE,EAAc,CAAC;AAEpB,SACEH,4BAA4B","ignoreList":[]}
|
|
@@ -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": "前一營業日",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CurrencyName } from '../../../../gql/types/graphql';
|
|
2
|
+
declare const WEEKEND_DURATION = 172800000;
|
|
2
3
|
declare const X_LABEL_SIZE = 90;
|
|
3
4
|
declare const X_LABEL_SIZE_MOBILE = 110;
|
|
4
5
|
declare const Y_LABEL_SIZE_MOBILE = 35;
|
|
@@ -10,7 +11,7 @@ declare const LEGEND_HEIGHT_MOBILE = 70;
|
|
|
10
11
|
declare const VERTICAL_LINE_COUNT = 10;
|
|
11
12
|
declare const CANDLE_NUMBER_HOUR = 12;
|
|
12
13
|
declare const CANDLE_MINUTE = 5;
|
|
13
|
-
declare const
|
|
14
|
+
declare const CURRENCIES_ORDER: CurrencyName[];
|
|
14
15
|
declare const COLOR_CONFIG: {
|
|
15
16
|
USD: string;
|
|
16
17
|
EUR: string;
|
|
@@ -25,4 +26,4 @@ declare const TOOLTIP_LINE_COLOR_CONFIG: {
|
|
|
25
26
|
DARK: string;
|
|
26
27
|
LIGHT: string;
|
|
27
28
|
};
|
|
28
|
-
export { X_LABEL_SIZE, X_LABEL_SIZE_MOBILE, Y_LABEL_SIZE_MOBILE, Y_LABEL_SIZE, CHART_WIDTH, CHART_HEIGHT, LEGEND_HEIGHT, LEGEND_HEIGHT_MOBILE, VERTICAL_LINE_COUNT, COLOR_CONFIG, TOOLTIP_LINE_COLOR_CONFIG, CANDLE_NUMBER_HOUR, CANDLE_MINUTE,
|
|
29
|
+
export { X_LABEL_SIZE, X_LABEL_SIZE_MOBILE, Y_LABEL_SIZE_MOBILE, Y_LABEL_SIZE, CHART_WIDTH, CHART_HEIGHT, LEGEND_HEIGHT, LEGEND_HEIGHT_MOBILE, VERTICAL_LINE_COUNT, COLOR_CONFIG, TOOLTIP_LINE_COLOR_CONFIG, CANDLE_NUMBER_HOUR, CANDLE_MINUTE, CURRENCIES_ORDER, WEEKEND_DURATION, };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CurrencyPowerBalance, CurrencyPowerBalanceTimeUnit } from '../../../../gql/types/graphql';
|
|
2
|
-
declare const getOption: (chartData: CurrencyPowerBalance[], timeUnit: CurrencyPowerBalanceTimeUnit, isDark: boolean) => {
|
|
2
|
+
declare const getOption: (chartData: CurrencyPowerBalance[], timeUnit: CurrencyPowerBalanceTimeUnit, isDark: boolean, lang: (key: string) => string) => {
|
|
3
3
|
animation: boolean;
|
|
4
4
|
legend: {
|
|
5
5
|
data: {
|
|
@@ -67,10 +67,46 @@ declare const getOption: (chartData: CurrencyPowerBalance[], timeUnit: CurrencyP
|
|
|
67
67
|
itemStyle: {
|
|
68
68
|
color: string;
|
|
69
69
|
};
|
|
70
|
-
lineStyle: {
|
|
71
|
-
color: string;
|
|
72
|
-
};
|
|
73
70
|
data: (string | number)[][];
|
|
71
|
+
markLine: {
|
|
72
|
+
label: {
|
|
73
|
+
show: boolean;
|
|
74
|
+
position: string;
|
|
75
|
+
align: string;
|
|
76
|
+
distance: number;
|
|
77
|
+
padding: number[];
|
|
78
|
+
fontSize: number;
|
|
79
|
+
shadowBlur: number;
|
|
80
|
+
shadowOffsetX: number;
|
|
81
|
+
shadowOffsetY: number;
|
|
82
|
+
borderWidth: number;
|
|
83
|
+
color: string;
|
|
84
|
+
shadowColor: string;
|
|
85
|
+
borderRadius: number;
|
|
86
|
+
backgroundColor: string;
|
|
87
|
+
};
|
|
88
|
+
show: boolean;
|
|
89
|
+
emphasis: {
|
|
90
|
+
label: {
|
|
91
|
+
show: boolean;
|
|
92
|
+
};
|
|
93
|
+
lineStyle: {
|
|
94
|
+
width: number;
|
|
95
|
+
opacity: number;
|
|
96
|
+
color: string;
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
symbol: string[];
|
|
100
|
+
itemStyle: {
|
|
101
|
+
color: string;
|
|
102
|
+
};
|
|
103
|
+
data: {
|
|
104
|
+
xAxis: number;
|
|
105
|
+
label: {
|
|
106
|
+
formatter: () => string;
|
|
107
|
+
};
|
|
108
|
+
}[];
|
|
109
|
+
} | undefined;
|
|
74
110
|
}[];
|
|
75
111
|
};
|
|
76
112
|
export { getOption };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oanda/labs-currency-power-balance-widget",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.107",
|
|
4
4
|
"description": "Labs Currency Power Balance Widget",
|
|
5
5
|
"main": "dist/main/index.js",
|
|
6
6
|
"module": "dist/module/index.js",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"author": "OANDA",
|
|
13
13
|
"license": "UNLICENSED",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@oanda/labs-widget-common": "^1.0.
|
|
15
|
+
"@oanda/labs-widget-common": "^1.0.168",
|
|
16
16
|
"@oanda/mono-i18n": "10.0.1",
|
|
17
17
|
"echarts": "5.5.0",
|
|
18
18
|
"echarts-for-react": "3.0.2",
|
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
"@graphql-codegen/cli": "5.0.0",
|
|
23
23
|
"@graphql-codegen/client-preset": "4.1.0"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "ece7c06ca65b093ec259d7693f002ae03d8a7118"
|
|
26
26
|
}
|
|
@@ -4,11 +4,12 @@ import * as echarts from 'echarts/core';
|
|
|
4
4
|
import { LineChart } from 'echarts/charts';
|
|
5
5
|
import { CanvasRenderer } from 'echarts/renderers';
|
|
6
6
|
import {
|
|
7
|
-
GridSimpleComponent, GraphicComponent, TooltipComponent, LegendPlainComponent,
|
|
7
|
+
GridSimpleComponent, GraphicComponent, TooltipComponent, LegendPlainComponent, MarkLineComponent,
|
|
8
8
|
} from 'echarts/components';
|
|
9
9
|
import {
|
|
10
10
|
Theme, ThemeContext, getChartTheme, Size,
|
|
11
11
|
} from '@oanda/labs-widget-common';
|
|
12
|
+
import { useLocale } from '@oanda/mono-i18n';
|
|
12
13
|
import {
|
|
13
14
|
CHART_HEIGHT,
|
|
14
15
|
} from './options/constants';
|
|
@@ -22,12 +23,14 @@ echarts.use([
|
|
|
22
23
|
LegendPlainComponent,
|
|
23
24
|
LineChart,
|
|
24
25
|
CanvasRenderer,
|
|
26
|
+
MarkLineComponent,
|
|
25
27
|
]);
|
|
26
28
|
|
|
27
29
|
echarts.registerTheme('dark_theme', getChartTheme(Theme.Dark));
|
|
28
30
|
echarts.registerTheme('light_theme', getChartTheme(Theme.Light));
|
|
29
31
|
|
|
30
32
|
const Chart = ({ values, timeUnit, currencies }: ChartProps) => {
|
|
33
|
+
const { lang } = useLocale();
|
|
31
34
|
const { isDark, size } = useContext(ThemeContext);
|
|
32
35
|
const isDesktop = size === Size.DESKTOP;
|
|
33
36
|
const isMobile = size === Size.MOBILE;
|
|
@@ -58,7 +61,7 @@ const Chart = ({ values, timeUnit, currencies }: ChartProps) => {
|
|
|
58
61
|
height: `${CHART_HEIGHT}px`,
|
|
59
62
|
width: '100%',
|
|
60
63
|
}}
|
|
61
|
-
option={getOption(chartData, timeUnit, isDark)}
|
|
64
|
+
option={getOption(chartData, timeUnit, isDark, lang)}
|
|
62
65
|
/>
|
|
63
66
|
);
|
|
64
67
|
};
|
package/src/CurrencyPowerBalanceWidget/components/Chart/options/{constants.tsx → constants.ts}
RENAMED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { colorPalette } from '@oanda/labs-widget-common';
|
|
2
2
|
import { CurrencyName } from '../../../../gql/types/graphql';
|
|
3
3
|
|
|
4
|
+
const WEEKEND_DURATION = 172800000;
|
|
5
|
+
|
|
4
6
|
const X_LABEL_SIZE = 90;
|
|
5
7
|
const X_LABEL_SIZE_MOBILE = 110;
|
|
6
8
|
const Y_LABEL_SIZE_MOBILE = 35;
|
|
@@ -13,7 +15,7 @@ const VERTICAL_LINE_COUNT = 10;
|
|
|
13
15
|
const CANDLE_NUMBER_HOUR = 12;
|
|
14
16
|
const CANDLE_MINUTE = 5;
|
|
15
17
|
|
|
16
|
-
const
|
|
18
|
+
const CURRENCIES_ORDER: CurrencyName[] = [
|
|
17
19
|
CurrencyName.Usd,
|
|
18
20
|
CurrencyName.Eur,
|
|
19
21
|
CurrencyName.Gbp,
|
|
@@ -54,5 +56,6 @@ export {
|
|
|
54
56
|
TOOLTIP_LINE_COLOR_CONFIG,
|
|
55
57
|
CANDLE_NUMBER_HOUR,
|
|
56
58
|
CANDLE_MINUTE,
|
|
57
|
-
|
|
59
|
+
CURRENCIES_ORDER,
|
|
60
|
+
WEEKEND_DURATION,
|
|
58
61
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CurrencyPowerBalance, CurrencyPowerBalanceTimeUnit } from '../../../../gql/types/graphql';
|
|
2
|
-
import { VERTICAL_LINE_COUNT,
|
|
2
|
+
import { VERTICAL_LINE_COUNT, CURRENCIES_ORDER, COLOR_CONFIG } from './constants';
|
|
3
3
|
import { TooltipFormatterParams } from './types';
|
|
4
4
|
|
|
5
5
|
const getDateAndTime = (param: string) => {
|
|
@@ -54,9 +54,9 @@ const tooltipFormatter = (values: TooltipFormatterParams[]) => {
|
|
|
54
54
|
const formatLegendData = (values: CurrencyPowerBalance[]) => {
|
|
55
55
|
const dataCurrencies = values.map(({ currency }) => currency);
|
|
56
56
|
|
|
57
|
-
const list = dataCurrencies.length ===
|
|
58
|
-
?
|
|
59
|
-
:
|
|
57
|
+
const list = dataCurrencies.length === CURRENCIES_ORDER.length
|
|
58
|
+
? CURRENCIES_ORDER
|
|
59
|
+
: CURRENCIES_ORDER.filter((currency) => dataCurrencies.includes(currency));
|
|
60
60
|
|
|
61
61
|
return list.map((currency) => ({
|
|
62
62
|
name: currency,
|
|
@@ -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
|
+
});
|