@oanda/labs-volatility-chart-widget 1.0.167 → 1.0.169

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.
@@ -1,12 +1,11 @@
1
- import type { BaseChartRef } from '@oanda/labs-widget-common';
2
1
  import {
3
2
  BaseChart,
4
3
  getChartTheme,
5
- Size,
6
4
  Theme,
7
5
  useLayoutProvider,
8
6
  } from '@oanda/labs-widget-common';
9
7
  import { useLocale } from '@oanda/mono-i18n';
8
+ import type { EChartsType } from 'echarts';
10
9
  import { BarChart } from 'echarts/charts';
11
10
  import {
12
11
  GraphicComponent,
@@ -16,10 +15,10 @@ import {
16
15
  } from 'echarts/components';
17
16
  import * as echarts from 'echarts/core';
18
17
  import { CanvasRenderer } from 'echarts/renderers';
19
- import React, { useEffect, useRef } from 'react';
18
+ import React from 'react';
20
19
 
21
20
  import { CHART_HEIGHT } from './constants';
22
- import { getDesktopOption, getMobileOption, getOption } from './getOption';
21
+ import { getOption } from './getOption';
23
22
  import type { ChartProps } from './types';
24
23
 
25
24
  echarts.use([
@@ -36,51 +35,30 @@ echarts.registerTheme('light_theme', getChartTheme(Theme.Light));
36
35
 
37
36
  const Chart = ({ values, timeUnit }: ChartProps) => {
38
37
  const { lang } = useLocale();
39
- const { isDark, size } = useLayoutProvider();
40
- const isDesktop = size === Size.DESKTOP;
41
- const echartRef = useRef<BaseChartRef | null>(null);
42
-
43
- useEffect(() => {
44
- if (echartRef.current) {
45
- const echartInstance = echartRef.current.getEchartsInstance();
46
-
47
- echartInstance.setOption(
48
- isDesktop
49
- ? getDesktopOption({ timeUnit, lang, isDark })
50
- : getMobileOption({ timeUnit, lang, isDark })
51
- );
52
- }
53
- }, [echartRef, timeUnit, isDesktop, lang, isDark]);
54
-
55
- useEffect(() => {
56
- if (echartRef.current) {
57
- const echartInstance = echartRef.current.getEchartsInstance();
58
-
59
- echartInstance.on('highlight', () => {
60
- echartInstance.setOption({
61
- title: {
62
- show: false,
63
- },
64
- });
65
- });
66
-
67
- echartInstance.on('globalout', () => {
68
- echartInstance.setOption({
69
- title: {
70
- show: window.innerWidth < 769,
71
- },
72
- });
73
- });
74
- }
75
- }, [echartRef]);
38
+ const { isDark } = useLayoutProvider();
76
39
 
77
40
  return (
78
41
  <BaseChart
79
- ref={echartRef}
80
42
  chartHeight={CHART_HEIGHT}
81
43
  echarts={echarts}
82
44
  isDark={isDark}
83
- option={getOption(values, lang, timeUnit)}
45
+ option={getOption(values, lang, timeUnit, isDark)}
46
+ onEvents={{
47
+ highlight: (_params: unknown, instance: EChartsType) => {
48
+ instance.setOption({
49
+ title: {
50
+ show: false,
51
+ },
52
+ });
53
+ },
54
+ globalout: (_params: unknown, instance: EChartsType) => {
55
+ instance.setOption({
56
+ title: {
57
+ show: true,
58
+ },
59
+ });
60
+ },
61
+ }}
84
62
  />
85
63
  );
86
64
  };
@@ -1,4 +1,5 @@
1
1
  import {
2
+ DESKTOP_MIN_WIDTH,
2
3
  getGridLines,
3
4
  getLineCommons,
4
5
  themeColors,
@@ -48,7 +49,7 @@ export const getDesktopOption = ({
48
49
 
49
50
  return {
50
51
  title: {
51
- show: false,
52
+ text: '',
52
53
  },
53
54
  tooltip: {
54
55
  position: undefined,
@@ -113,7 +114,7 @@ export const getMobileOption = ({
113
114
 
114
115
  return {
115
116
  title: {
116
- show: true,
117
+ text: lang('mobile_tooltip_placeholder'),
117
118
  },
118
119
  tooltip: {
119
120
  backgroundColor: 'transparent',
@@ -176,7 +177,7 @@ export const pointFormatter = ({
176
177
  return point;
177
178
  };
178
179
 
179
- export const getOption: GetOptionType = (values, lang, timeUnit) => {
180
+ export const getOption: GetOptionType = (values, lang, timeUnit, isDark) => {
180
181
  const pipsValues = values.map(({ pips }) => pips.toFixed());
181
182
  const points = values.map(({ point }) =>
182
183
  pointFormatter({ point, lang, timeUnit })
@@ -187,7 +188,6 @@ export const getOption: GetOptionType = (values, lang, timeUnit) => {
187
188
  title: {
188
189
  left: 10,
189
190
  top: 20,
190
- text: lang('mobile_tooltip_placeholder'),
191
191
  textStyle: {
192
192
  fontFamily: 'Sofia W03',
193
193
  fontWeight: 500,
@@ -237,5 +237,23 @@ export const getOption: GetOptionType = (values, lang, timeUnit) => {
237
237
  type: 'bar',
238
238
  },
239
239
  ],
240
+ media: [
241
+ {
242
+ query: {
243
+ minWidth: DESKTOP_MIN_WIDTH,
244
+ },
245
+ option: {
246
+ ...getDesktopOption({ timeUnit, lang, isDark }),
247
+ },
248
+ },
249
+ {
250
+ query: {
251
+ maxWidth: DESKTOP_MIN_WIDTH - 1,
252
+ },
253
+ option: {
254
+ ...getMobileOption({ timeUnit, lang, isDark }),
255
+ },
256
+ },
257
+ ],
240
258
  };
241
259
  };
@@ -25,7 +25,8 @@ export interface TooltipData {
25
25
  export type GetOptionType = (
26
26
  values: VolatilityChartDataValues[],
27
27
  lang: (label: string) => string,
28
- timeUnit: VolatilityChartTimeUnit
28
+ timeUnit: VolatilityChartTimeUnit,
29
+ isDark: boolean
29
30
  ) => EChartsOption;
30
31
 
31
32
  export interface GetResponsiveOptionsProps {