@oanda/labs-currency-power-balance-widget 1.0.112 → 1.0.113

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.
Files changed (119) hide show
  1. package/CHANGELOG.md +456 -0
  2. package/dist/main/CurrencyPowerBalanceWidget/ChartWithData.js +7 -7
  3. package/dist/main/CurrencyPowerBalanceWidget/ChartWithData.js.map +1 -1
  4. package/dist/main/CurrencyPowerBalanceWidget/CurrencyPowerBalance.js +9 -9
  5. package/dist/main/CurrencyPowerBalanceWidget/CurrencyPowerBalance.js.map +1 -1
  6. package/dist/main/CurrencyPowerBalanceWidget/Main.js +10 -10
  7. package/dist/main/CurrencyPowerBalanceWidget/Main.js.map +1 -1
  8. package/dist/main/CurrencyPowerBalanceWidget/components/Chart/Chart.js +11 -11
  9. package/dist/main/CurrencyPowerBalanceWidget/components/Chart/Chart.js.map +1 -1
  10. package/dist/main/CurrencyPowerBalanceWidget/components/Chart/options/constants.js.map +1 -1
  11. package/dist/main/CurrencyPowerBalanceWidget/components/Chart/options/formatters.js.map +1 -1
  12. package/dist/main/CurrencyPowerBalanceWidget/components/Chart/options/getOption.js +1 -1
  13. package/dist/main/CurrencyPowerBalanceWidget/components/Chart/options/getOption.js.map +1 -1
  14. package/dist/main/CurrencyPowerBalanceWidget/components/Chart/options/getResponsiveOption.js.map +1 -1
  15. package/dist/main/CurrencyPowerBalanceWidget/components/Chart/options/types.js.map +1 -1
  16. package/dist/main/CurrencyPowerBalanceWidget/components/Chart/options/utils.js.map +1 -1
  17. package/dist/main/CurrencyPowerBalanceWidget/components/Chart/types.js.map +1 -1
  18. package/dist/main/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSelect.js +4 -4
  19. package/dist/main/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSelect.js.map +1 -1
  20. package/dist/main/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSwitch.js +9 -9
  21. package/dist/main/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSwitch.js.map +1 -1
  22. package/dist/main/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/types.js.map +1 -1
  23. package/dist/main/CurrencyPowerBalanceWidget/config.js.map +1 -1
  24. package/dist/main/CurrencyPowerBalanceWidget/constants.js.map +1 -1
  25. package/dist/main/CurrencyPowerBalanceWidget/render.js +8 -8
  26. package/dist/main/CurrencyPowerBalanceWidget/render.js.map +1 -1
  27. package/dist/main/CurrencyPowerBalanceWidget/types.js.map +1 -1
  28. package/dist/main/gql/types/fragment-masking.js.map +1 -1
  29. package/dist/main/gql/types/gql.js +1 -1
  30. package/dist/main/gql/types/gql.js.map +1 -1
  31. package/dist/main/gql/types/graphql.js +64 -64
  32. package/dist/main/gql/types/graphql.js.map +1 -1
  33. package/dist/main/gql/types/index.js.map +1 -1
  34. package/dist/main/translations/index.js +1 -1
  35. package/dist/main/translations/index.js.map +1 -1
  36. package/dist/main/translations/translations.js.map +1 -1
  37. package/dist/module/CurrencyPowerBalanceWidget/ChartWithData.js +7 -7
  38. package/dist/module/CurrencyPowerBalanceWidget/ChartWithData.js.map +1 -1
  39. package/dist/module/CurrencyPowerBalanceWidget/CurrencyPowerBalance.js +9 -9
  40. package/dist/module/CurrencyPowerBalanceWidget/CurrencyPowerBalance.js.map +1 -1
  41. package/dist/module/CurrencyPowerBalanceWidget/Main.js +10 -10
  42. package/dist/module/CurrencyPowerBalanceWidget/Main.js.map +1 -1
  43. package/dist/module/CurrencyPowerBalanceWidget/components/Chart/Chart.js +10 -10
  44. package/dist/module/CurrencyPowerBalanceWidget/components/Chart/Chart.js.map +1 -1
  45. package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/constants.js +1 -1
  46. package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/constants.js.map +1 -1
  47. package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/formatters.js +2 -2
  48. package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/formatters.js.map +1 -1
  49. package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/getOption.js +2 -2
  50. package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/getOption.js.map +1 -1
  51. package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/getResponsiveOption.js.map +1 -1
  52. package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/types.js.map +1 -1
  53. package/dist/module/CurrencyPowerBalanceWidget/components/Chart/options/utils.js.map +1 -1
  54. package/dist/module/CurrencyPowerBalanceWidget/components/Chart/types.js.map +1 -1
  55. package/dist/module/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSelect.js +4 -4
  56. package/dist/module/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSelect.js.map +1 -1
  57. package/dist/module/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSwitch.js +10 -10
  58. package/dist/module/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSwitch.js.map +1 -1
  59. package/dist/module/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/types.js.map +1 -1
  60. package/dist/module/CurrencyPowerBalanceWidget/config.js.map +1 -1
  61. package/dist/module/CurrencyPowerBalanceWidget/constants.js.map +1 -1
  62. package/dist/module/CurrencyPowerBalanceWidget/render.js +8 -8
  63. package/dist/module/CurrencyPowerBalanceWidget/render.js.map +1 -1
  64. package/dist/module/CurrencyPowerBalanceWidget/types.js.map +1 -1
  65. package/dist/module/gql/types/fragment-masking.js.map +1 -1
  66. package/dist/module/gql/types/gql.js +1 -1
  67. package/dist/module/gql/types/gql.js.map +1 -1
  68. package/dist/module/gql/types/graphql.js +64 -64
  69. package/dist/module/gql/types/graphql.js.map +1 -1
  70. package/dist/module/gql/types/index.js +2 -2
  71. package/dist/module/gql/types/index.js.map +1 -1
  72. package/dist/module/translations/index.js +1 -1
  73. package/dist/module/translations/index.js.map +1 -1
  74. package/dist/module/translations/translations.js.map +1 -1
  75. package/dist/types/CurrencyPowerBalanceWidget/ChartWithData.d.ts +1 -1
  76. package/dist/types/CurrencyPowerBalanceWidget/CurrencyPowerBalance.d.ts +1 -1
  77. package/dist/types/CurrencyPowerBalanceWidget/Main.d.ts +1 -1
  78. package/dist/types/CurrencyPowerBalanceWidget/components/Chart/Chart.d.ts +1 -1
  79. package/dist/types/CurrencyPowerBalanceWidget/components/Chart/options/constants.d.ts +1 -1
  80. package/dist/types/CurrencyPowerBalanceWidget/components/Chart/options/formatters.d.ts +4 -3
  81. package/dist/types/CurrencyPowerBalanceWidget/components/Chart/options/getOption.d.ts +2 -1
  82. package/dist/types/CurrencyPowerBalanceWidget/components/Chart/options/utils.d.ts +1 -1
  83. package/dist/types/CurrencyPowerBalanceWidget/components/Chart/types.d.ts +1 -1
  84. package/dist/types/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSelect.d.ts +1 -1
  85. package/dist/types/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSwitch.d.ts +1 -1
  86. package/dist/types/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/types.d.ts +3 -3
  87. package/dist/types/CurrencyPowerBalanceWidget/types.d.ts +2 -2
  88. package/dist/types/gql/types/gql.d.ts +2 -2
  89. package/dist/types/gql/types/index.d.ts +2 -2
  90. package/dist/types/translations/index.d.ts +2 -2
  91. package/package.json +3 -3
  92. package/src/CurrencyPowerBalanceWidget/ChartWithData.tsx +31 -17
  93. package/src/CurrencyPowerBalanceWidget/CurrencyPowerBalance.tsx +16 -9
  94. package/src/CurrencyPowerBalanceWidget/Main.tsx +18 -9
  95. package/src/CurrencyPowerBalanceWidget/components/Chart/Chart.tsx +25 -20
  96. package/src/CurrencyPowerBalanceWidget/components/Chart/options/constants.ts +11 -10
  97. package/src/CurrencyPowerBalanceWidget/components/Chart/options/formatters.ts +42 -22
  98. package/src/CurrencyPowerBalanceWidget/components/Chart/options/getOption.ts +59 -44
  99. package/src/CurrencyPowerBalanceWidget/components/Chart/options/getResponsiveOption.ts +7 -4
  100. package/src/CurrencyPowerBalanceWidget/components/Chart/options/types.ts +1 -1
  101. package/src/CurrencyPowerBalanceWidget/components/Chart/options/utils.ts +10 -9
  102. package/src/CurrencyPowerBalanceWidget/components/Chart/types.ts +4 -1
  103. package/src/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSelect.tsx +21 -15
  104. package/src/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/TimeUnitSwitch.tsx +47 -37
  105. package/src/CurrencyPowerBalanceWidget/components/TimeUnitSwitch/types.ts +3 -3
  106. package/src/CurrencyPowerBalanceWidget/config.ts +8 -2
  107. package/src/CurrencyPowerBalanceWidget/constants.ts +2 -1
  108. package/src/CurrencyPowerBalanceWidget/render.tsx +24 -20
  109. package/src/CurrencyPowerBalanceWidget/types.ts +5 -3
  110. package/src/gql/types/fragment-masking.ts +41 -21
  111. package/src/gql/types/gql.ts +7 -3
  112. package/src/gql/types/graphql.ts +117 -44
  113. package/src/gql/types/index.ts +2 -2
  114. package/src/translations/index.ts +4 -4
  115. package/src/translations/translations.ts +2 -1
  116. package/test/Main.test.tsx +28 -14
  117. package/test/chartFormatters.test.ts +84 -24
  118. package/test/responsesMocks.ts +254 -255
  119. package/test/utils.test.ts +0 -1
@@ -1,45 +1,54 @@
1
- import React, { useState } from 'react';
2
1
  import { useLayoutProvider } from '@oanda/labs-widget-common';
3
2
  import { useLocale } from '@oanda/mono-i18n';
3
+ import React, { useState } from 'react';
4
+
4
5
  import { CurrencyPowerBalanceTimeUnit } from '../gql/types/graphql';
6
+ import { ChartWithData } from './ChartWithData';
5
7
  import { TimeUnitSwitch } from './components/TimeUnitSwitch';
6
8
  import { timeUnitConfig } from './config';
7
- import { ChartWithData } from './ChartWithData';
8
- import { MainProps } from './types';
9
+ import type { MainProps } from './types';
9
10
 
10
11
  const Main = ({ timeUnit, currencies }: MainProps) => {
11
12
  const { size } = useLayoutProvider();
12
13
  const { lang } = useLocale();
13
14
  const [selectedTimeUnit, setSelectedTimeUnit] = useState(
14
- timeUnit || CurrencyPowerBalanceTimeUnit.CurrentDay,
15
+ timeUnit || CurrencyPowerBalanceTimeUnit.CurrentDay
15
16
  );
16
17
  return (
17
18
  <>
18
19
  {size && (
19
20
  <div
20
- data-testid="currency-power-balance-wrapper"
21
21
  className="lw-flex lw-flex-col lw-text-sm lw-tracking-normal"
22
+ data-testid="currency-power-balance-wrapper"
22
23
  >
23
24
  {timeUnit && currencies ? (
24
25
  <>
25
26
  {timeUnitConfig
26
27
  .filter(({ value }) => value === selectedTimeUnit)
27
28
  .map(({ tooltipLabel, label }) => (
28
- <div data-testid="time-unit-label" key={label} className="lw-mb-6 lw-flex lw-justify-center lw-font-sans lw-text-lg lw-font-bold">
29
- {tooltipLabel ? <span>{`${lang(tooltipLabel!.translationKey, { count: tooltipLabel!.count })}`}</span> : <span>{`${lang(label)}`}</span>}
29
+ <div
30
+ key={label}
31
+ className="lw-mb-6 lw-flex lw-justify-center lw-font-sans lw-text-lg lw-font-bold"
32
+ data-testid="time-unit-label"
33
+ >
34
+ {tooltipLabel ? (
35
+ <span>{`${lang(tooltipLabel!.translationKey, { count: tooltipLabel!.count })}`}</span>
36
+ ) : (
37
+ <span>{`${lang(label)}`}</span>
38
+ )}
30
39
  </div>
31
40
  ))}
32
41
  </>
33
42
  ) : (
34
43
  <TimeUnitSwitch
35
- selected={selectedTimeUnit}
36
44
  callback={setSelectedTimeUnit}
37
45
  options={timeUnitConfig}
46
+ selected={selectedTimeUnit}
38
47
  />
39
48
  )}
40
49
  <ChartWithData
41
- timeUnit={selectedTimeUnit}
42
50
  currencies={timeUnit && currencies}
51
+ timeUnit={selectedTimeUnit}
43
52
  />
44
53
  </div>
45
54
  )}
@@ -1,20 +1,26 @@
1
- import React, { useRef, useEffect } from 'react';
2
- import ReactEChartsCore from 'echarts-for-react/lib/core';
3
- import * as echarts from 'echarts/core';
4
- import { LineChart } from 'echarts/charts';
5
- import { CanvasRenderer } from 'echarts/renderers';
6
- import {
7
- GridSimpleComponent, GraphicComponent, TooltipComponent, LegendPlainComponent, MarkLineComponent,
8
- } from 'echarts/components';
9
1
  import {
10
- Theme, useLayoutProvider, getChartTheme, Size,
2
+ getChartTheme,
3
+ Size,
4
+ Theme,
5
+ useLayoutProvider,
11
6
  } from '@oanda/labs-widget-common';
12
7
  import { useLocale } from '@oanda/mono-i18n';
8
+ import { LineChart } from 'echarts/charts';
13
9
  import {
14
- CHART_HEIGHT,
15
- } from './options/constants';
16
- import { getResponsiveOption, getOption } from './options';
17
- import { ChartProps } from './types';
10
+ GraphicComponent,
11
+ GridSimpleComponent,
12
+ LegendPlainComponent,
13
+ MarkLineComponent,
14
+ TooltipComponent,
15
+ } from 'echarts/components';
16
+ import * as echarts from 'echarts/core';
17
+ import { CanvasRenderer } from 'echarts/renderers';
18
+ import ReactEChartsCore from 'echarts-for-react/lib/core';
19
+ import React, { useEffect, useRef } from 'react';
20
+
21
+ import { getOption, getResponsiveOption } from './options';
22
+ import { CHART_HEIGHT } from './options/constants';
23
+ import type { ChartProps } from './types';
18
24
 
19
25
  echarts.use([
20
26
  GridSimpleComponent,
@@ -35,7 +41,7 @@ const Chart = ({ values, timeUnit, currencies }: ChartProps) => {
35
41
  const isDesktop = size === Size.DESKTOP;
36
42
  const isMobile = size === Size.MOBILE;
37
43
 
38
- const echartRef = useRef(null);
44
+ const echartRef = useRef<ReactEChartsCore | null>(null);
39
45
 
40
46
  const chartData = currencies
41
47
  ? values.filter(({ currency }) => currencies.includes(currency))
@@ -43,25 +49,24 @@ const Chart = ({ values, timeUnit, currencies }: ChartProps) => {
43
49
 
44
50
  useEffect(() => {
45
51
  if (echartRef.current) {
46
- // @ts-ignore
47
- const echartInstance = echartRef.current.getEchartsInstance() as echarts.EChartsType;
52
+ const echartInstance = echartRef.current.getEchartsInstance();
48
53
 
49
54
  echartInstance.setOption(
50
- getResponsiveOption(isDesktop, isMobile, isDark),
55
+ getResponsiveOption(isDesktop, isMobile, isDark)
51
56
  );
52
57
  }
53
58
  }, [echartRef, isDesktop, isMobile, isDark]);
54
59
 
55
60
  return (
56
61
  <ReactEChartsCore
57
- echarts={echarts}
58
62
  ref={echartRef}
59
- theme={isDark ? 'dark_theme' : 'light_theme'}
63
+ echarts={echarts}
64
+ option={getOption(chartData, timeUnit, isDark, lang)}
60
65
  style={{
61
66
  height: `${CHART_HEIGHT}px`,
62
67
  width: '100%',
63
68
  }}
64
- option={getOption(chartData, timeUnit, isDark, lang)}
69
+ theme={isDark ? 'dark_theme' : 'light_theme'}
65
70
  />
66
71
  );
67
72
  };
@@ -1,4 +1,5 @@
1
1
  import { colorPalette } from '@oanda/labs-widget-common';
2
+
2
3
  import { CurrencyName } from '../../../../gql/types/graphql';
3
4
 
4
5
  const WEEKEND_DURATION = 172800000;
@@ -43,19 +44,19 @@ const TOOLTIP_LINE_COLOR_CONFIG = {
43
44
  };
44
45
 
45
46
  export {
46
- X_LABEL_SIZE,
47
- X_LABEL_SIZE_MOBILE,
48
- Y_LABEL_SIZE_MOBILE,
49
- Y_LABEL_SIZE,
50
- CHART_WIDTH,
47
+ CANDLE_MINUTE,
48
+ CANDLE_NUMBER_HOUR,
51
49
  CHART_HEIGHT,
50
+ CHART_WIDTH,
51
+ COLOR_CONFIG,
52
+ CURRENCIES_ORDER,
52
53
  LEGEND_HEIGHT,
53
54
  LEGEND_HEIGHT_MOBILE,
54
- VERTICAL_LINE_COUNT,
55
- COLOR_CONFIG,
56
55
  TOOLTIP_LINE_COLOR_CONFIG,
57
- CANDLE_NUMBER_HOUR,
58
- CANDLE_MINUTE,
59
- CURRENCIES_ORDER,
56
+ VERTICAL_LINE_COUNT,
60
57
  WEEKEND_DURATION,
58
+ X_LABEL_SIZE,
59
+ X_LABEL_SIZE_MOBILE,
60
+ Y_LABEL_SIZE,
61
+ Y_LABEL_SIZE_MOBILE,
61
62
  };
@@ -1,6 +1,11 @@
1
- import { CurrencyPowerBalance, CurrencyPowerBalanceTimeUnit } from '../../../../gql/types/graphql';
2
- import { VERTICAL_LINE_COUNT, CURRENCIES_ORDER, COLOR_CONFIG } from './constants';
3
- import { TooltipFormatterParams } from './types';
1
+ import type { CurrencyPowerBalance } from '../../../../gql/types/graphql';
2
+ import { CurrencyPowerBalanceTimeUnit } from '../../../../gql/types/graphql';
3
+ import {
4
+ COLOR_CONFIG,
5
+ CURRENCIES_ORDER,
6
+ VERTICAL_LINE_COUNT,
7
+ } from './constants';
8
+ import type { TooltipFormatterParams } from './types';
4
9
 
5
10
  const getDateAndTime = (param: string) => {
6
11
  const dateAndTime = param.split('T');
@@ -11,39 +16,51 @@ const getDateAndTime = (param: string) => {
11
16
  };
12
17
  };
13
18
 
14
- const dateFormat = (date: string) => `${new Date(date).toLocaleDateString(undefined, { month: 'numeric', day: 'numeric' })}`;
19
+ const dateFormat = (date: string) =>
20
+ `${new Date(date).toLocaleDateString(undefined, { month: 'numeric', day: 'numeric' })}`;
15
21
 
16
- const dateTimeFormat = ({ date, time }: { date: string, time: string }) => `${new Date(date).toLocaleDateString(undefined, { year: 'numeric', month: 'numeric', day: 'numeric' })}, ${time} UTC`;
22
+ const dateTimeFormat = ({ date, time }: { date: string; time: string }) =>
23
+ `${new Date(date).toLocaleDateString(undefined, { year: 'numeric', month: 'numeric', day: 'numeric' })}, ${time} UTC`;
17
24
 
18
- const isMonthWeek = (
19
- timeUnit: CurrencyPowerBalanceTimeUnit,
20
- ) => timeUnit === CurrencyPowerBalanceTimeUnit.M3
21
- || timeUnit === CurrencyPowerBalanceTimeUnit.M1
22
- || timeUnit === CurrencyPowerBalanceTimeUnit.W1;
25
+ const isMonthWeek = (timeUnit: CurrencyPowerBalanceTimeUnit) =>
26
+ timeUnit === CurrencyPowerBalanceTimeUnit.M3 ||
27
+ timeUnit === CurrencyPowerBalanceTimeUnit.M1 ||
28
+ timeUnit === CurrencyPowerBalanceTimeUnit.W1;
23
29
 
24
- const xAxisLabelFormatter = (label: string, timeUnit: CurrencyPowerBalanceTimeUnit) => {
30
+ const xAxisLabelFormatter = (
31
+ label: string,
32
+ timeUnit: CurrencyPowerBalanceTimeUnit
33
+ ) => {
25
34
  const { date, time } = getDateAndTime(label);
26
35
  const isDateFormat = isMonthWeek(timeUnit) || time === '00:00';
27
36
 
28
37
  return isDateFormat ? dateFormat(date) : time;
29
38
  };
30
39
 
31
- const intervalFormatter = (
32
- dataLength: number,
33
- ) => Math.round(dataLength / VERTICAL_LINE_COUNT);
40
+ const intervalFormatter = (dataLength: number) =>
41
+ Math.round(dataLength / VERTICAL_LINE_COUNT);
34
42
 
35
43
  const tooltipFormatter = (values: TooltipFormatterParams[]) => {
36
44
  const date = dateTimeFormat(getDateAndTime(values[0].value[0]));
37
45
 
38
46
  const row = values
39
- .sort(({ value: valueA }, { value: valueB }) => Number(valueB[1]) - Number(valueA[1]))
40
- .map(({ marker, seriesName, value }) => `<div style="display:flex;align-items:center;">
47
+ .sort(
48
+ ({ value: valueA }, { value: valueB }) =>
49
+ Number(valueB[1]) - Number(valueA[1])
50
+ )
51
+ .map(
52
+ ({
53
+ marker,
54
+ seriesName,
55
+ value,
56
+ }) => `<div style="display:flex;align-items:center;">
41
57
  <div style="display:flex;align-items:center;width:50px;margin-right:10px;">
42
58
  ${marker}
43
59
  <span>${seriesName}</span>
44
60
  </div>
45
61
  <span>${value[1]}</span>
46
- </div>`);
62
+ </div>`
63
+ );
47
64
 
48
65
  return `<div style="display:flex; flex-direction:column;">
49
66
  <span style="margin-bottom:5px;">${date}</span>
@@ -54,9 +71,12 @@ const tooltipFormatter = (values: TooltipFormatterParams[]) => {
54
71
  const formatLegendData = (values: CurrencyPowerBalance[]) => {
55
72
  const dataCurrencies = values.map(({ currency }) => currency);
56
73
 
57
- const list = dataCurrencies.length === CURRENCIES_ORDER.length
58
- ? CURRENCIES_ORDER
59
- : CURRENCIES_ORDER.filter((currency) => dataCurrencies.includes(currency));
74
+ const list =
75
+ dataCurrencies.length === CURRENCIES_ORDER.length
76
+ ? CURRENCIES_ORDER
77
+ : CURRENCIES_ORDER.filter((currency) =>
78
+ dataCurrencies.includes(currency)
79
+ );
60
80
 
61
81
  return list.map((currency) => ({
62
82
  name: currency,
@@ -67,9 +87,9 @@ const formatLegendData = (values: CurrencyPowerBalance[]) => {
67
87
  };
68
88
 
69
89
  export {
90
+ formatLegendData,
91
+ intervalFormatter,
70
92
  isMonthWeek,
71
93
  tooltipFormatter,
72
94
  xAxisLabelFormatter,
73
- intervalFormatter,
74
- formatLegendData,
75
95
  };
@@ -1,25 +1,33 @@
1
1
  import { darkTheme, lightTheme } from '@oanda/labs-widget-common';
2
+
3
+ import type { CurrencyPowerBalance } from '../../../../gql/types/graphql';
4
+ import { CurrencyPowerBalanceTimeUnit } from '../../../../gql/types/graphql';
2
5
  import { COLOR_CONFIG, TOOLTIP_LINE_COLOR_CONFIG } from './constants';
3
6
  import {
4
- intervalFormatter, tooltipFormatter, xAxisLabelFormatter, formatLegendData,
7
+ formatLegendData,
8
+ intervalFormatter,
9
+ tooltipFormatter,
10
+ xAxisLabelFormatter,
5
11
  } from './formatters';
6
- import { CurrencyPowerBalance, CurrencyPowerBalanceTimeUnit } from '../../../../gql/types/graphql';
7
12
  import { findLastIndexesBeforeWeekend } from './utils';
8
13
 
9
14
  const getOption = (
10
15
  chartData: CurrencyPowerBalance[],
11
16
  timeUnit: CurrencyPowerBalanceTimeUnit,
12
17
  isDark: boolean,
13
- lang: (key: string) => string,
18
+ lang: (key: string) => string
14
19
  ) => {
15
20
  const currentTheme = isDark ? darkTheme : lightTheme;
16
- const dataTimestamps = chartData[0].power.map((x) => new Date(x.point).getTime());
21
+ const dataTimestamps = chartData[0].power.map((x) =>
22
+ new Date(x.point).getTime()
23
+ );
17
24
  const weekendsIndexes = findLastIndexesBeforeWeekend(dataTimestamps);
18
- const disableWeekendsIndicator = [
19
- CurrencyPowerBalanceTimeUnit.CurrentDay,
20
- CurrencyPowerBalanceTimeUnit.PreviousDay,
21
- CurrencyPowerBalanceTimeUnit.M3,
22
- ].includes(timeUnit) || weekendsIndexes.length === 0;
25
+ const disableWeekendsIndicator =
26
+ [
27
+ CurrencyPowerBalanceTimeUnit.CurrentDay,
28
+ CurrencyPowerBalanceTimeUnit.PreviousDay,
29
+ CurrencyPowerBalanceTimeUnit.M3,
30
+ ].includes(timeUnit) || weekendsIndexes.length === 0;
23
31
 
24
32
  const weekendsMarks = weekendsIndexes.map((item) => ({
25
33
  xAxis: item,
@@ -37,40 +45,45 @@ const getOption = (
37
45
  color: COLOR_CONFIG[currency],
38
46
  },
39
47
  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,
48
+ markLine:
49
+ index === chartData.length - 1 && !disableWeekendsIndicator
50
+ ? {
51
+ label: {
52
+ show: false,
53
+ position: 'end',
54
+ align: 'center',
55
+ distance: -32,
56
+ padding: [8, 8],
57
+ fontSize: 12,
58
+ shadowBlur: 24,
59
+ shadowOffsetX: 0,
60
+ shadowOffsetY: 6,
61
+ borderWidth: 0,
62
+ color: currentTheme.textPrimary,
63
+ shadowColor: 'rgba(0,0,0,0.1)',
64
+ borderRadius: 4,
65
+ backgroundColor: isDark
66
+ ? currentTheme.borderPrimary
67
+ : currentTheme.backgroundSecondary,
68
+ },
69
+ show: false,
70
+ emphasis: {
71
+ label: {
72
+ show: true,
73
+ },
74
+ lineStyle: {
75
+ width: 1,
76
+ opacity: 0,
77
+ color: currentTheme.borderPrimary,
78
+ },
79
+ },
80
+ symbol: ['none', 'none'],
81
+ itemStyle: {
82
+ color: currentTheme.borderPrimary,
83
+ },
84
+ data: weekendsMarks,
85
+ }
86
+ : undefined,
74
87
  }));
75
88
 
76
89
  const legendData = formatLegendData(chartData);
@@ -88,7 +101,9 @@ const getOption = (
88
101
  axis: 'x',
89
102
  z: 0,
90
103
  lineStyle: {
91
- color: isDark ? TOOLTIP_LINE_COLOR_CONFIG.DARK : TOOLTIP_LINE_COLOR_CONFIG.LIGHT,
104
+ color: isDark
105
+ ? TOOLTIP_LINE_COLOR_CONFIG.DARK
106
+ : TOOLTIP_LINE_COLOR_CONFIG.LIGHT,
92
107
  },
93
108
  },
94
109
  formatter: tooltipFormatter,
@@ -1,4 +1,5 @@
1
1
  import { getGridLines } from '@oanda/labs-widget-common';
2
+
2
3
  import {
3
4
  CHART_HEIGHT,
4
5
  CHART_WIDTH,
@@ -10,7 +11,11 @@ import {
10
11
  Y_LABEL_SIZE_MOBILE,
11
12
  } from './constants';
12
13
 
13
- const getResponsiveOption = (isDesktop: boolean, isMobile: boolean, isDark: boolean) => {
14
+ const getResponsiveOption = (
15
+ isDesktop: boolean,
16
+ isMobile: boolean,
17
+ isDark: boolean
18
+ ) => {
14
19
  const baseGridLines = getGridLines({
15
20
  isDark,
16
21
  chartWidth: CHART_WIDTH,
@@ -36,9 +41,7 @@ const getResponsiveOption = (isDesktop: boolean, isMobile: boolean, isDark: bool
36
41
  bottom: `${isMobile ? X_LABEL_SIZE_MOBILE : X_LABEL_SIZE}px`,
37
42
  },
38
43
  ],
39
- graphic: [
40
- ...baseGridLines,
41
- ],
44
+ graphic: [...baseGridLines],
42
45
  };
43
46
  };
44
47
 
@@ -1,5 +1,5 @@
1
1
  export interface TooltipFormatterParams {
2
2
  marker: string;
3
3
  seriesName: string;
4
- value: string[]
4
+ value: string[];
5
5
  }
@@ -1,12 +1,13 @@
1
1
  import { WEEKEND_DURATION } from './constants';
2
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[]);
3
+ const findLastIndexesBeforeWeekend = (timestamps: number[]) =>
4
+ timestamps.reduce(
5
+ (acc, timestamp, index) =>
6
+ timestamps.length - 1 !== index &&
7
+ timestamps[index + 1] - timestamp >= WEEKEND_DURATION
8
+ ? [...acc, index]
9
+ : acc,
10
+ [] as number[]
11
+ );
9
12
 
10
- export {
11
- findLastIndexesBeforeWeekend,
12
- };
13
+ export { findLastIndexesBeforeWeekend };
@@ -1,4 +1,7 @@
1
- import { CurrencyPowerBalance, CurrencyPowerBalanceTimeUnit } from '../../../gql/types/graphql';
1
+ import type {
2
+ CurrencyPowerBalance,
3
+ CurrencyPowerBalanceTimeUnit,
4
+ } from '../../../gql/types/graphql';
2
5
 
3
6
  export interface ChartProps {
4
7
  values: CurrencyPowerBalance[];
@@ -1,29 +1,35 @@
1
- import React from 'react';
2
1
  import { Select } from '@oanda/labs-widget-common';
3
2
  import { useLocale } from '@oanda/mono-i18n';
4
- import { TimeUnitSwitchProps } from './types';
5
- import { CurrencyPowerBalanceTimeUnit } from '../../../gql/types/graphql';
3
+ import React from 'react';
4
+
5
+ import type { CurrencyPowerBalanceTimeUnit } from '../../../gql/types/graphql';
6
+ import type { TimeUnitSwitchProps } from './types';
6
7
 
7
8
  const TimeUnitSelect = ({
8
- selected, options, callback,
9
+ selected,
10
+ options,
11
+ callback,
9
12
  }: TimeUnitSwitchProps) => {
10
13
  const { lang } = useLocale();
11
- const selectOptions = options
12
- .map(({ value: id, label, tooltipLabel }) => ({
13
- id,
14
- label: tooltipLabel
15
- ? lang(tooltipLabel.translationKey, { count: tooltipLabel.count })
16
- : lang(label),
17
- }));
18
- const [{ label: selectedLabel }] = selectOptions.filter(({ id }) => id === selected);
14
+ const selectOptions = options.map(({ value: id, label, tooltipLabel }) => ({
15
+ id,
16
+ label: tooltipLabel
17
+ ? lang(tooltipLabel.translationKey, { count: tooltipLabel.count })
18
+ : lang(label),
19
+ }));
20
+ const [{ label: selectedLabel }] = selectOptions.filter(
21
+ ({ id }) => id === selected
22
+ );
19
23
 
20
24
  return (
21
- <div data-testid="time-unit-select" className="lw-mb-6 lw-w-full">
25
+ <div className="lw-mb-6 lw-w-full" data-testid="time-unit-select">
22
26
  <Select
23
- searchPlaceholder={lang('search')}
24
27
  options={selectOptions}
28
+ searchPlaceholder={lang('search')}
25
29
  selectedOption={{ id: selected, label: selectedLabel }}
26
- setSelectedOption={({ id }) => callback(id as CurrencyPowerBalanceTimeUnit)}
30
+ setSelectedOption={({ id }) =>
31
+ callback(id as CurrencyPowerBalanceTimeUnit)
32
+ }
27
33
  />
28
34
  </div>
29
35
  );
@@ -1,15 +1,22 @@
1
- import React from 'react';
2
1
  import {
3
- Button, ButtonSize, ButtonVariant, useLayoutProvider, Size,
2
+ Button,
3
+ ButtonSize,
4
+ ButtonVariant,
5
+ Size,
6
+ useLayoutProvider,
4
7
  } from '@oanda/labs-widget-common';
5
8
  import { useLocale } from '@oanda/mono-i18n';
6
- import { TimeUnitSwitchProps } from './types';
7
- import { CurrencyPowerBalanceTimeUnit } from '../../../gql/types/graphql';
9
+ import React from 'react';
10
+
11
+ import type { CurrencyPowerBalanceTimeUnit } from '../../../gql/types/graphql';
8
12
  import { CURRENCY_POWER_BALANCE_TOOLTIP_ID } from '../../constants';
9
13
  import { TimeUnitSelect } from './TimeUnitSelect';
14
+ import type { TimeUnitSwitchProps } from './types';
10
15
 
11
16
  const TimeUnitSwitch = ({
12
- selected, options, callback,
17
+ selected,
18
+ options,
19
+ callback,
13
20
  }: TimeUnitSwitchProps) => {
14
21
  const { lang } = useLocale();
15
22
  const { size } = useLayoutProvider();
@@ -21,40 +28,43 @@ const TimeUnitSwitch = ({
21
28
 
22
29
  return (
23
30
  <>
24
- {isDesktop
25
- ? (
26
- <div data-testid="time-unit-switch" className="lw-mb-6 lw-flex lw-gap-1 lw-self-end">
27
- {options.map(({ value, label, tooltipLabel }) => {
28
- const tooltip = tooltipLabel
29
- ? lang(tooltipLabel.translationKey, { count: tooltipLabel.count })
30
- : tooltipLabel;
31
- const buttonLabel = lang(label);
31
+ {isDesktop ? (
32
+ <div
33
+ className="lw-mb-6 lw-flex lw-gap-1 lw-self-end"
34
+ data-testid="time-unit-switch"
35
+ >
36
+ {options.map(({ value, label, tooltipLabel }) => {
37
+ const tooltip = tooltipLabel
38
+ ? lang(tooltipLabel.translationKey, { count: tooltipLabel.count })
39
+ : tooltipLabel;
40
+ const buttonLabel = lang(label);
32
41
 
33
- return (
34
- <Button
35
- key={value}
36
- size={ButtonSize.full}
37
- variant={selected === value
42
+ return (
43
+ <Button
44
+ key={value}
45
+ data-tooltip-content={tooltip}
46
+ data-tooltip-id={CURRENCY_POWER_BALANCE_TOOLTIP_ID}
47
+ size={ButtonSize.full}
48
+ value={value}
49
+ variant={
50
+ selected === value
38
51
  ? ButtonVariant.primary
39
- : ButtonVariant.secondary}
40
- onClick={handleButtonClick}
41
- value={value}
42
- data-tooltip-id={CURRENCY_POWER_BALANCE_TOOLTIP_ID}
43
- data-tooltip-content={tooltip}
44
- >
45
- {buttonLabel}
46
- </Button>
47
- );
48
- })}
49
- </div>
50
- )
51
- : (
52
- <TimeUnitSelect
53
- selected={selected}
54
- callback={callback}
55
- options={options}
56
- />
57
- )}
52
+ : ButtonVariant.secondary
53
+ }
54
+ onClick={handleButtonClick}
55
+ >
56
+ {buttonLabel}
57
+ </Button>
58
+ );
59
+ })}
60
+ </div>
61
+ ) : (
62
+ <TimeUnitSelect
63
+ callback={callback}
64
+ options={options}
65
+ selected={selected}
66
+ />
67
+ )}
58
68
  </>
59
69
  );
60
70
  };
@@ -1,4 +1,4 @@
1
- import { CurrencyPowerBalanceTimeUnit } from '../../../gql/types/graphql';
1
+ import type { CurrencyPowerBalanceTimeUnit } from '../../../gql/types/graphql';
2
2
 
3
3
  export interface TimeUnitOption {
4
4
  value: CurrencyPowerBalanceTimeUnit;
@@ -12,7 +12,7 @@ export interface TimeUnitSwitchProps {
12
12
  callback: (value: CurrencyPowerBalanceTimeUnit) => void;
13
13
  }
14
14
 
15
- type TooltipLabel = {
15
+ interface TooltipLabel {
16
16
  translationKey: string;
17
17
  count: number;
18
- };
18
+ }