@oanda/labs-currency-power-balance-widget 1.0.1
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 +8 -0
- package/codegen.ts +15 -0
- package/dist/main/CurrencyPowerBalanceWidget/ChartWithData.js +46 -0
- package/dist/main/CurrencyPowerBalanceWidget/ChartWithData.js.map +1 -0
- package/dist/main/CurrencyPowerBalanceWidget/CurrencyPowerBalance.js +28 -0
- package/dist/main/CurrencyPowerBalanceWidget/CurrencyPowerBalance.js.map +1 -0
- package/dist/main/CurrencyPowerBalanceWidget/Main.js +12 -0
- package/dist/main/CurrencyPowerBalanceWidget/Main.js.map +1 -0
- package/dist/main/CurrencyPowerBalanceWidget/Tool.js +28 -0
- package/dist/main/CurrencyPowerBalanceWidget/Tool.js.map +1 -0
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/Chart.js +45 -0
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/Chart.js.map +1 -0
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/index.js +17 -0
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/index.js.map +1 -0
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/options/constants.js +31 -0
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/options/constants.js.map +1 -0
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/options/formatters.js +59 -0
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/options/formatters.js.map +1 -0
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/options/getOption.js +103 -0
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/options/getOption.js.map +1 -0
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/options/getResponsiveOption.js +36 -0
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/options/getResponsiveOption.js.map +1 -0
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/options/index.js +28 -0
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/options/index.js.map +1 -0
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/options/types.js +6 -0
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/options/types.js.map +1 -0
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/types.js +6 -0
- package/dist/main/CurrencyPowerBalanceWidget/components/Chart/types.js.map +1 -0
- package/dist/main/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSelect.js +53 -0
- package/dist/main/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSelect.js.map +1 -0
- package/dist/main/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSwitch.js +46 -0
- package/dist/main/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSwitch.js.map +1 -0
- package/dist/main/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/index.js +17 -0
- package/dist/main/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/index.js.map +1 -0
- package/dist/main/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/types.js +6 -0
- package/dist/main/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/types.js.map +1 -0
- package/dist/main/CurrencyPowerBalanceWidget/config.js +39 -0
- package/dist/main/CurrencyPowerBalanceWidget/config.js.map +1 -0
- package/dist/main/CurrencyPowerBalanceWidget/constants.js +8 -0
- package/dist/main/CurrencyPowerBalanceWidget/constants.js.map +1 -0
- package/dist/main/CurrencyPowerBalanceWidget/index.js +17 -0
- package/dist/main/CurrencyPowerBalanceWidget/index.js.map +1 -0
- package/dist/main/CurrencyPowerBalanceWidget/render.js +28 -0
- package/dist/main/CurrencyPowerBalanceWidget/render.js.map +1 -0
- package/dist/main/CurrencyPowerBalanceWidget/types.js +6 -0
- package/dist/main/CurrencyPowerBalanceWidget/types.js.map +1 -0
- package/dist/main/gql/getCurrencyPowerBalance.js +11 -0
- package/dist/main/gql/getCurrencyPowerBalance.js.map +1 -0
- package/dist/main/gql/types/fragment-masking.js +24 -0
- package/dist/main/gql/types/fragment-masking.js.map +1 -0
- package/dist/main/gql/types/gql.js +17 -0
- package/dist/main/gql/types/gql.js.map +1 -0
- package/dist/main/gql/types/graphql.js +171 -0
- package/dist/main/gql/types/graphql.js.map +1 -0
- package/dist/main/gql/types/index.js +28 -0
- package/dist/main/gql/types/index.js.map +1 -0
- package/dist/main/index.js +17 -0
- package/dist/main/index.js.map +1 -0
- package/dist/module/CurrencyPowerBalanceWidget/ChartWithData.js +39 -0
- package/dist/module/CurrencyPowerBalanceWidget/ChartWithData.js.map +1 -0
- package/dist/module/CurrencyPowerBalanceWidget/CurrencyPowerBalance.js +21 -0
- package/dist/module/CurrencyPowerBalanceWidget/CurrencyPowerBalance.js.map +1 -0
- package/dist/module/CurrencyPowerBalanceWidget/Main.js +5 -0
- package/dist/module/CurrencyPowerBalanceWidget/Main.js.map +1 -0
- package/dist/module/CurrencyPowerBalanceWidget/Tool.js +20 -0
- package/dist/module/CurrencyPowerBalanceWidget/Tool.js.map +1 -0
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/Chart.js +36 -0
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/Chart.js.map +1 -0
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/index.js +2 -0
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/index.js.map +1 -0
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/constants.js +26 -0
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/constants.js.map +1 -0
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/formatters.js +52 -0
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/formatters.js.map +1 -0
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/getOption.js +97 -0
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/getOption.js.map +1 -0
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/getResponsiveOption.js +30 -0
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/getResponsiveOption.js.map +1 -0
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/index.js +3 -0
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/index.js.map +1 -0
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/types.js +2 -0
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/types.js.map +1 -0
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/types.js +2 -0
- package/dist/module/CurrencyPowerBalanceWidget/components/Chart/types.js.map +1 -0
- package/dist/module/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSelect.js +46 -0
- package/dist/module/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSelect.js.map +1 -0
- package/dist/module/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSwitch.js +39 -0
- package/dist/module/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSwitch.js.map +1 -0
- package/dist/module/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/index.js +2 -0
- package/dist/module/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/index.js.map +1 -0
- package/dist/module/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/types.js +2 -0
- package/dist/module/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/types.js.map +1 -0
- package/dist/module/CurrencyPowerBalanceWidget/config.js +34 -0
- package/dist/module/CurrencyPowerBalanceWidget/config.js.map +1 -0
- package/dist/module/CurrencyPowerBalanceWidget/constants.js +2 -0
- package/dist/module/CurrencyPowerBalanceWidget/constants.js.map +1 -0
- package/dist/module/CurrencyPowerBalanceWidget/index.js +2 -0
- package/dist/module/CurrencyPowerBalanceWidget/index.js.map +1 -0
- package/dist/module/CurrencyPowerBalanceWidget/render.js +25 -0
- package/dist/module/CurrencyPowerBalanceWidget/render.js.map +1 -0
- package/dist/module/CurrencyPowerBalanceWidget/types.js +2 -0
- package/dist/module/CurrencyPowerBalanceWidget/types.js.map +1 -0
- package/dist/module/gql/getCurrencyPowerBalance.js +5 -0
- package/dist/module/gql/getCurrencyPowerBalance.js.map +1 -0
- package/dist/module/gql/types/fragment-masking.js +16 -0
- package/dist/module/gql/types/fragment-masking.js.map +1 -0
- package/dist/module/gql/types/gql.js +9 -0
- package/dist/module/gql/types/gql.js.map +1 -0
- package/dist/module/gql/types/graphql.js +165 -0
- package/dist/module/gql/types/graphql.js.map +1 -0
- package/dist/module/gql/types/index.js +3 -0
- package/dist/module/gql/types/index.js.map +1 -0
- package/dist/module/index.js +2 -0
- package/dist/module/index.js.map +1 -0
- package/dist/types/CurrencyPowerBalanceWidget/ChartWithData.d.ts +4 -0
- package/dist/types/CurrencyPowerBalanceWidget/CurrencyPowerBalance.d.ts +4 -0
- package/dist/types/CurrencyPowerBalanceWidget/Main.d.ts +3 -0
- package/dist/types/CurrencyPowerBalanceWidget/Tool.d.ts +3 -0
- package/dist/types/CurrencyPowerBalanceWidget/components/Chart/Chart.d.ts +4 -0
- package/dist/types/CurrencyPowerBalanceWidget/components/Chart/index.d.ts +1 -0
- package/dist/types/CurrencyPowerBalanceWidget/components/Chart/options/constants.d.ts +24 -0
- package/dist/types/CurrencyPowerBalanceWidget/components/Chart/options/formatters.d.ts +5 -0
- package/dist/types/CurrencyPowerBalanceWidget/components/Chart/options/getOption.d.ts +74 -0
- package/dist/types/CurrencyPowerBalanceWidget/components/Chart/options/getResponsiveOption.d.ts +110 -0
- package/dist/types/CurrencyPowerBalanceWidget/components/Chart/options/index.d.ts +2 -0
- package/dist/types/CurrencyPowerBalanceWidget/components/Chart/options/types.d.ts +5 -0
- package/dist/types/CurrencyPowerBalanceWidget/components/Chart/types.d.ts +5 -0
- package/dist/types/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSelect.d.ts +4 -0
- package/dist/types/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSwitch.d.ts +4 -0
- package/dist/types/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/index.d.ts +1 -0
- package/dist/types/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/types.d.ts +12 -0
- package/dist/types/CurrencyPowerBalanceWidget/config.d.ts +11 -0
- package/dist/types/CurrencyPowerBalanceWidget/constants.d.ts +1 -0
- package/dist/types/CurrencyPowerBalanceWidget/index.d.ts +1 -0
- package/dist/types/CurrencyPowerBalanceWidget/render.d.ts +1 -0
- package/dist/types/CurrencyPowerBalanceWidget/types.d.ts +12 -0
- package/dist/types/gql/getCurrencyPowerBalance.d.ts +1 -0
- package/dist/types/gql/types/fragment-masking.d.ts +15 -0
- package/dist/types/gql/types/gql.d.ts +36 -0
- package/dist/types/gql/types/graphql.d.ts +274 -0
- package/dist/types/gql/types/index.d.ts +2 -0
- package/dist/types/index.d.ts +1 -0
- package/index.ts +1 -0
- package/package.json +27 -0
- package/src/CurrencyPowerBalanceWidget/ChartWithData.tsx +48 -0
- package/src/CurrencyPowerBalanceWidget/CurrencyPowerBalance.tsx +24 -0
- package/src/CurrencyPowerBalanceWidget/Main.tsx +10 -0
- package/src/CurrencyPowerBalanceWidget/Tool.tsx +27 -0
- package/src/CurrencyPowerBalanceWidget/components/Chart/Chart.tsx +45 -0
- package/src/CurrencyPowerBalanceWidget/components/Chart/index.ts +1 -0
- package/src/CurrencyPowerBalanceWidget/components/Chart/options/constants.tsx +41 -0
- package/src/CurrencyPowerBalanceWidget/components/Chart/options/formatters.ts +46 -0
- package/src/CurrencyPowerBalanceWidget/components/Chart/options/getOption.ts +82 -0
- package/src/CurrencyPowerBalanceWidget/components/Chart/options/getResponsiveOption.ts +45 -0
- package/src/CurrencyPowerBalanceWidget/components/Chart/options/index.ts +2 -0
- package/src/CurrencyPowerBalanceWidget/components/Chart/options/types.ts +5 -0
- package/src/CurrencyPowerBalanceWidget/components/Chart/types.ts +6 -0
- package/src/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSelect.tsx +24 -0
- package/src/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSwitch.tsx +58 -0
- package/src/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/index.ts +1 -0
- package/src/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/types.ts +14 -0
- package/src/CurrencyPowerBalanceWidget/config.ts +30 -0
- package/src/CurrencyPowerBalanceWidget/constants.ts +1 -0
- package/src/CurrencyPowerBalanceWidget/index.ts +1 -0
- package/src/CurrencyPowerBalanceWidget/render.tsx +36 -0
- package/src/CurrencyPowerBalanceWidget/types.ts +15 -0
- package/src/gql/getCurrencyPowerBalance.ts +13 -0
- package/src/gql/types/fragment-masking.ts +66 -0
- package/src/gql/types/gql.ts +42 -0
- package/src/gql/types/graphql.ts +283 -0
- package/src/gql/types/index.ts +2 -0
- package/src/index.ts +1 -0
- package/test/Main.test.tsx +29 -0
- package/test/chartFormatters.test.ts +59 -0
- package/test/responsesMocks.ts +223 -0
- package/tsconfig.types.json +12 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { COLOR_CONFIG, TOOLTIP_LINE_COLOR_CONFIG, VERTICAL_LINE_COUNT } from './constants';
|
|
2
|
+
import { tooltipFormatter, xAxisLabelFormatter } from './formatters';
|
|
3
|
+
import { CurrencyPowerBalance, CurrencyPowerBalanceTimeUnit } from '../../../../gql/types/graphql';
|
|
4
|
+
|
|
5
|
+
const getOption = (
|
|
6
|
+
values: CurrencyPowerBalance[],
|
|
7
|
+
timeUnit: CurrencyPowerBalanceTimeUnit,
|
|
8
|
+
isDark: boolean,
|
|
9
|
+
) => {
|
|
10
|
+
const seriesData = values.map(({ currency, power }) => ({
|
|
11
|
+
name: currency,
|
|
12
|
+
type: 'line',
|
|
13
|
+
symbol: 'circle',
|
|
14
|
+
showSymbol: false,
|
|
15
|
+
itemStyle: {
|
|
16
|
+
color: COLOR_CONFIG[currency],
|
|
17
|
+
},
|
|
18
|
+
lineStyle: {
|
|
19
|
+
color: COLOR_CONFIG[currency],
|
|
20
|
+
},
|
|
21
|
+
data: power.map(({ point, price }) => [point, price]),
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
const legendData = values.map(({ currency }) => ({
|
|
25
|
+
name: currency,
|
|
26
|
+
itemStyle: {
|
|
27
|
+
color: COLOR_CONFIG[currency],
|
|
28
|
+
},
|
|
29
|
+
}));
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
animation: false,
|
|
33
|
+
legend: {
|
|
34
|
+
data: legendData,
|
|
35
|
+
bottom: 10,
|
|
36
|
+
icon: 'circle',
|
|
37
|
+
},
|
|
38
|
+
tooltip: {
|
|
39
|
+
trigger: 'axis',
|
|
40
|
+
axisPointer: {
|
|
41
|
+
axis: 'x',
|
|
42
|
+
z: 0,
|
|
43
|
+
lineStyle: {
|
|
44
|
+
color: isDark ? TOOLTIP_LINE_COLOR_CONFIG.DARK : TOOLTIP_LINE_COLOR_CONFIG.LIGHT,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
formatter: tooltipFormatter,
|
|
48
|
+
},
|
|
49
|
+
xAxis: {
|
|
50
|
+
type: 'category',
|
|
51
|
+
axisTick: {
|
|
52
|
+
show: false,
|
|
53
|
+
},
|
|
54
|
+
axisLine: { show: false },
|
|
55
|
+
splitLine: {
|
|
56
|
+
show: true,
|
|
57
|
+
},
|
|
58
|
+
axisLabel: {
|
|
59
|
+
margin: 10,
|
|
60
|
+
showMinLabel: false,
|
|
61
|
+
rotate: -45,
|
|
62
|
+
interval: Math.round(seriesData[0].data.length / VERTICAL_LINE_COUNT),
|
|
63
|
+
formatter: (label: string) => xAxisLabelFormatter(label, timeUnit),
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
yAxis: {
|
|
67
|
+
type: 'value',
|
|
68
|
+
position: 'right',
|
|
69
|
+
splitNumber: 5,
|
|
70
|
+
axisLine: { show: false },
|
|
71
|
+
axisTick: { show: false },
|
|
72
|
+
boundaryGap: ['10%', '10%'],
|
|
73
|
+
axisLabel: {
|
|
74
|
+
showMaxLabel: false,
|
|
75
|
+
showMinLabel: false,
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
series: seriesData,
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export { getOption };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { getGridLines } from '@oanda/labs-widget-common';
|
|
2
|
+
import {
|
|
3
|
+
CHART_HEIGHT,
|
|
4
|
+
CHART_WIDTH,
|
|
5
|
+
LEGEND_HEIGHT,
|
|
6
|
+
LEGEND_HEIGHT_MOBILE,
|
|
7
|
+
X_LABEL_SIZE,
|
|
8
|
+
X_LABEL_SIZE_MOBILE,
|
|
9
|
+
Y_LABEL_SIZE,
|
|
10
|
+
Y_LABEL_SIZE_MOBILE,
|
|
11
|
+
} from './constants';
|
|
12
|
+
|
|
13
|
+
const getResponsiveOption = (isDesktop: boolean, isMobile: boolean, isDark: boolean) => {
|
|
14
|
+
const baseGridLines = getGridLines({
|
|
15
|
+
isDark,
|
|
16
|
+
chartWidth: CHART_WIDTH,
|
|
17
|
+
chartHeight: CHART_HEIGHT,
|
|
18
|
+
xLabelsSize: isMobile ? X_LABEL_SIZE_MOBILE : X_LABEL_SIZE,
|
|
19
|
+
yLabelSize: isMobile ? Y_LABEL_SIZE_MOBILE : Y_LABEL_SIZE,
|
|
20
|
+
bottomLeftBox: isDesktop,
|
|
21
|
+
marginBottom: isMobile ? LEGEND_HEIGHT_MOBILE : LEGEND_HEIGHT,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
yAxis: {
|
|
26
|
+
axisLabel: {
|
|
27
|
+
margin: isDesktop ? 8 : 6,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
grid: [
|
|
31
|
+
{
|
|
32
|
+
name: 'main-grid',
|
|
33
|
+
top: '0px',
|
|
34
|
+
left: '0px',
|
|
35
|
+
right: `${isMobile ? Y_LABEL_SIZE_MOBILE : Y_LABEL_SIZE}px`,
|
|
36
|
+
bottom: `${isMobile ? X_LABEL_SIZE_MOBILE : X_LABEL_SIZE}px`,
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
graphic: [
|
|
40
|
+
...baseGridLines,
|
|
41
|
+
],
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export { getResponsiveOption };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Select } from '@oanda/labs-widget-common';
|
|
3
|
+
import { TimeUnitSwitchProps } from './types';
|
|
4
|
+
import { CurrencyPowerBalanceTimeUnit } from '../../../gql/types/graphql';
|
|
5
|
+
|
|
6
|
+
const TimeUnitSelect = ({
|
|
7
|
+
selected, options, callback,
|
|
8
|
+
}: TimeUnitSwitchProps) => {
|
|
9
|
+
const selectOptions = options
|
|
10
|
+
.map(({ value: id, label, tooltip }) => ({ id, label: tooltip || label }));
|
|
11
|
+
const [{ label: selectedLabel }] = selectOptions.filter(({ id }) => id === selected);
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<div data-testid="time-unit-select" className="lw-mb-6 lw-w-full">
|
|
15
|
+
<Select
|
|
16
|
+
options={selectOptions}
|
|
17
|
+
selectedOption={{ id: selected, label: selectedLabel }}
|
|
18
|
+
setSelectedOption={({ id }) => callback(id as CurrencyPowerBalanceTimeUnit)}
|
|
19
|
+
/>
|
|
20
|
+
</div>
|
|
21
|
+
);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { TimeUnitSelect };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Button, ButtonSize, ButtonVariant } from '@oanda/labs-widget-common';
|
|
3
|
+
import { useMediaQuery } from 'usehooks-ts';
|
|
4
|
+
import { TimeUnitSwitchProps } from './types';
|
|
5
|
+
import { CurrencyPowerBalanceTimeUnit } from '../../../gql/types/graphql';
|
|
6
|
+
import { CURRENCY_POWER_BALANCE_TOOLTIP_ID } from '../../constants';
|
|
7
|
+
import { TimeUnitSelect } from './TimeUnitSelect';
|
|
8
|
+
|
|
9
|
+
const TimeUnitSwitch = ({
|
|
10
|
+
selected, options, callback, labelCallback,
|
|
11
|
+
}: TimeUnitSwitchProps) => {
|
|
12
|
+
const isDesktop = useMediaQuery('(min-width: 768px)');
|
|
13
|
+
|
|
14
|
+
const handleButtonClick = (e: React.SyntheticEvent<HTMLButtonElement>) => {
|
|
15
|
+
callback(e.currentTarget.value as CurrencyPowerBalanceTimeUnit);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<>
|
|
20
|
+
{isDesktop
|
|
21
|
+
? (
|
|
22
|
+
<div data-testid="time-unit-switch" className="lw-mb-6 lw-flex lw-gap-1 lw-self-end">
|
|
23
|
+
{options.map((item) => {
|
|
24
|
+
const tooltip = labelCallback && item.tooltip
|
|
25
|
+
? labelCallback(item.tooltip)
|
|
26
|
+
: item.tooltip;
|
|
27
|
+
const label = labelCallback ? labelCallback(item.label) : item.label;
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<Button
|
|
31
|
+
key={item.value}
|
|
32
|
+
size={ButtonSize.full}
|
|
33
|
+
variant={selected === item.value
|
|
34
|
+
? ButtonVariant.primary
|
|
35
|
+
: ButtonVariant.secondary}
|
|
36
|
+
onClick={handleButtonClick}
|
|
37
|
+
value={item.value}
|
|
38
|
+
data-tooltip-id={CURRENCY_POWER_BALANCE_TOOLTIP_ID}
|
|
39
|
+
data-tooltip-content={tooltip}
|
|
40
|
+
>
|
|
41
|
+
{label}
|
|
42
|
+
</Button>
|
|
43
|
+
);
|
|
44
|
+
})}
|
|
45
|
+
</div>
|
|
46
|
+
)
|
|
47
|
+
: (
|
|
48
|
+
<TimeUnitSelect
|
|
49
|
+
selected={selected}
|
|
50
|
+
callback={callback}
|
|
51
|
+
options={options}
|
|
52
|
+
/>
|
|
53
|
+
)}
|
|
54
|
+
</>
|
|
55
|
+
);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export { TimeUnitSwitch };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TimeUnitSwitch';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CurrencyPowerBalanceTimeUnit } from '../../../gql/types/graphql';
|
|
2
|
+
|
|
3
|
+
export interface TimeUnitOption {
|
|
4
|
+
value: CurrencyPowerBalanceTimeUnit;
|
|
5
|
+
label: string;
|
|
6
|
+
tooltip?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface TimeUnitSwitchProps {
|
|
10
|
+
selected: CurrencyPowerBalanceTimeUnit;
|
|
11
|
+
options: TimeUnitOption[];
|
|
12
|
+
callback: (value: CurrencyPowerBalanceTimeUnit) => void;
|
|
13
|
+
labelCallback?: (value: string) => string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { CurrencyPowerBalanceTimeUnit } from '../gql/types/graphql';
|
|
2
|
+
|
|
3
|
+
const timeUnitConfig = [
|
|
4
|
+
{
|
|
5
|
+
value: CurrencyPowerBalanceTimeUnit.M3,
|
|
6
|
+
label: '3m',
|
|
7
|
+
tooltip: '3_months',
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
value: CurrencyPowerBalanceTimeUnit.M1,
|
|
11
|
+
label: '1m',
|
|
12
|
+
tooltip: '1_month',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
value: CurrencyPowerBalanceTimeUnit.W1,
|
|
16
|
+
label: '1w',
|
|
17
|
+
tooltip: '1_week',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
value: CurrencyPowerBalanceTimeUnit.H24,
|
|
21
|
+
label: '24h',
|
|
22
|
+
tooltip: '24_months',
|
|
23
|
+
},
|
|
24
|
+
{ value: CurrencyPowerBalanceTimeUnit.H8, label: '8h', tooltip: '8_hours' },
|
|
25
|
+
{ value: CurrencyPowerBalanceTimeUnit.H4, label: '4h', tooltip: '4_hours' },
|
|
26
|
+
{ value: CurrencyPowerBalanceTimeUnit.PreviousDay, label: 'Previous Business Day' },
|
|
27
|
+
{ value: CurrencyPowerBalanceTimeUnit.CurrentDay, label: 'Current Business Day' },
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
export { timeUnitConfig };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const CURRENCY_POWER_BALANCE_TOOLTIP_ID = 'currency-power-balance-widget-tooltip';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './CurrencyPowerBalance';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from 'react-dom';
|
|
3
|
+
import { Theme } from '@oanda/labs-widget-common';
|
|
4
|
+
import { CurrencyPowerBalance } from './CurrencyPowerBalance';
|
|
5
|
+
|
|
6
|
+
const {
|
|
7
|
+
graphqlUrl: configGraphQl,
|
|
8
|
+
renderElementId: configRenderElementId,
|
|
9
|
+
} = window.currencyPowerBalanceWidgetConfig || {};
|
|
10
|
+
|
|
11
|
+
const {
|
|
12
|
+
graphqlUrl,
|
|
13
|
+
} = window.widgetsConfig || {};
|
|
14
|
+
|
|
15
|
+
const currencyPowerBalanceParamsElements = document.querySelectorAll('div[data-currency-power-balance-params]');
|
|
16
|
+
|
|
17
|
+
if (currencyPowerBalanceParamsElements.length > 0) {
|
|
18
|
+
currencyPowerBalanceParamsElements.forEach((element) => {
|
|
19
|
+
const mode = element.getAttribute('data-mode');
|
|
20
|
+
|
|
21
|
+
render(
|
|
22
|
+
<CurrencyPowerBalance
|
|
23
|
+
graphqlUrl={graphqlUrl}
|
|
24
|
+
theme={mode as Theme}
|
|
25
|
+
/>,
|
|
26
|
+
element,
|
|
27
|
+
);
|
|
28
|
+
});
|
|
29
|
+
} else {
|
|
30
|
+
render(
|
|
31
|
+
<CurrencyPowerBalance
|
|
32
|
+
graphqlUrl={configGraphQl}
|
|
33
|
+
/>,
|
|
34
|
+
document.getElementById(configRenderElementId),
|
|
35
|
+
);
|
|
36
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Theme } from '@oanda/labs-widget-common';
|
|
2
|
+
import { CurrencyPowerBalanceTimeUnit } from '../gql/types/graphql';
|
|
3
|
+
|
|
4
|
+
export interface CurrencyPowerBalanceConfig {
|
|
5
|
+
graphqlUrl: string;
|
|
6
|
+
theme?: Theme;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface CurrencyPowerBalanceWrapperConfig extends CurrencyPowerBalanceConfig {
|
|
10
|
+
renderElementId: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ChartWithDataProps {
|
|
14
|
+
timeUnit: CurrencyPowerBalanceTimeUnit;
|
|
15
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { gql } from '@apollo/client';
|
|
2
|
+
|
|
3
|
+
export const getCurrencyPowerBalance = gql`
|
|
4
|
+
query GetCurrencyPowerBalance($timeUnit: CurrencyPowerBalanceTimeUnit!) {
|
|
5
|
+
currencyPowerBalance(timeUnit: $timeUnit) {
|
|
6
|
+
currency
|
|
7
|
+
power {
|
|
8
|
+
point
|
|
9
|
+
price
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
`;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
2
|
+
import { FragmentDefinitionNode } from 'graphql';
|
|
3
|
+
import { Incremental } from './graphql';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export type FragmentType<TDocumentType extends DocumentTypeDecoration<any, any>> = TDocumentType extends DocumentTypeDecoration<
|
|
7
|
+
infer TType,
|
|
8
|
+
any
|
|
9
|
+
>
|
|
10
|
+
? [TType] extends [{ ' $fragmentName'?: infer TKey }]
|
|
11
|
+
? TKey extends string
|
|
12
|
+
? { ' $fragmentRefs'?: { [key in TKey]: TType } }
|
|
13
|
+
: never
|
|
14
|
+
: never
|
|
15
|
+
: never;
|
|
16
|
+
|
|
17
|
+
// return non-nullable if `fragmentType` is non-nullable
|
|
18
|
+
export function useFragment<TType>(
|
|
19
|
+
_documentNode: DocumentTypeDecoration<TType, any>,
|
|
20
|
+
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>>
|
|
21
|
+
): TType;
|
|
22
|
+
// return nullable if `fragmentType` is nullable
|
|
23
|
+
export function useFragment<TType>(
|
|
24
|
+
_documentNode: DocumentTypeDecoration<TType, any>,
|
|
25
|
+
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null | undefined
|
|
26
|
+
): TType | null | undefined;
|
|
27
|
+
// return array of non-nullable if `fragmentType` is array of non-nullable
|
|
28
|
+
export function useFragment<TType>(
|
|
29
|
+
_documentNode: DocumentTypeDecoration<TType, any>,
|
|
30
|
+
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
|
|
31
|
+
): ReadonlyArray<TType>;
|
|
32
|
+
// return array of nullable if `fragmentType` is array of nullable
|
|
33
|
+
export function useFragment<TType>(
|
|
34
|
+
_documentNode: DocumentTypeDecoration<TType, any>,
|
|
35
|
+
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
|
|
36
|
+
): ReadonlyArray<TType> | null | undefined;
|
|
37
|
+
export function useFragment<TType>(
|
|
38
|
+
_documentNode: DocumentTypeDecoration<TType, any>,
|
|
39
|
+
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
|
|
40
|
+
): TType | ReadonlyArray<TType> | null | undefined {
|
|
41
|
+
return fragmentType as any;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
export function makeFragmentData<
|
|
46
|
+
F extends DocumentTypeDecoration<any, any>,
|
|
47
|
+
FT extends ResultOf<F>
|
|
48
|
+
>(data: FT, _fragment: F): FragmentType<F> {
|
|
49
|
+
return data as FragmentType<F>;
|
|
50
|
+
}
|
|
51
|
+
export function isFragmentReady<TQuery, TFrag>(
|
|
52
|
+
queryNode: DocumentTypeDecoration<TQuery, any>,
|
|
53
|
+
fragmentNode: TypedDocumentNode<TFrag>,
|
|
54
|
+
data: FragmentType<TypedDocumentNode<Incremental<TFrag>, any>> | null | undefined
|
|
55
|
+
): data is FragmentType<typeof fragmentNode> {
|
|
56
|
+
const deferredFields = (queryNode as { __meta__?: { deferredFields: Record<string, (keyof TFrag)[]> } }).__meta__
|
|
57
|
+
?.deferredFields;
|
|
58
|
+
|
|
59
|
+
if (!deferredFields) return true;
|
|
60
|
+
|
|
61
|
+
const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined;
|
|
62
|
+
const fragName = fragDef?.name?.value;
|
|
63
|
+
|
|
64
|
+
const fields = (fragName && deferredFields[fragName]) || [];
|
|
65
|
+
return fields.length > 0 && fields.every(field => data && field in data);
|
|
66
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
import * as types from './graphql';
|
|
3
|
+
import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Map of all GraphQL operations in the project.
|
|
7
|
+
*
|
|
8
|
+
* This map has several performance disadvantages:
|
|
9
|
+
* 1. It is not tree-shakeable, so it will include all operations in the project.
|
|
10
|
+
* 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
|
|
11
|
+
* 3. It does not support dead code elimination, so it will add unused operations.
|
|
12
|
+
*
|
|
13
|
+
* Therefore it is highly recommended to use the babel or swc plugin for production.
|
|
14
|
+
*/
|
|
15
|
+
const documents = {
|
|
16
|
+
"\n query GetCurrencyPowerBalance($timeUnit: CurrencyPowerBalanceTimeUnit!) {\n currencyPowerBalance(timeUnit: $timeUnit) {\n currency\n power {\n point\n price\n }\n }\n }\n": types.GetCurrencyPowerBalanceDocument,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
|
21
|
+
*
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* const query = graphql(`query GetUser($id: ID!) { user(id: $id) { name } }`);
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* The query argument is unknown!
|
|
29
|
+
* Please regenerate the types.
|
|
30
|
+
*/
|
|
31
|
+
export function graphql(source: string): unknown;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
|
35
|
+
*/
|
|
36
|
+
export function graphql(source: "\n query GetCurrencyPowerBalance($timeUnit: CurrencyPowerBalanceTimeUnit!) {\n currencyPowerBalance(timeUnit: $timeUnit) {\n currency\n power {\n point\n price\n }\n }\n }\n"): (typeof documents)["\n query GetCurrencyPowerBalance($timeUnit: CurrencyPowerBalanceTimeUnit!) {\n currencyPowerBalance(timeUnit: $timeUnit) {\n currency\n power {\n point\n price\n }\n }\n }\n"];
|
|
37
|
+
|
|
38
|
+
export function graphql(source: string) {
|
|
39
|
+
return (documents as any)[source] ?? {};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type DocumentType<TDocumentNode extends DocumentNode<any, any>> = TDocumentNode extends DocumentNode< infer TType, any> ? TType : never;
|