@oanda/labs-order-book-widget 1.0.218 → 1.0.220

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,4 +1,3 @@
1
- import type { BaseChartRef } from '@oanda/labs-widget-common';
2
1
  import {
3
2
  BaseChart,
4
3
  colorPalette,
@@ -8,6 +7,7 @@ import {
8
7
  useLayoutProvider,
9
8
  } from '@oanda/labs-widget-common';
10
9
  import { useLocale } from '@oanda/mono-i18n';
10
+ import type { EChartsType } from 'echarts';
11
11
  import { CustomChart } from 'echarts/charts';
12
12
  import {
13
13
  DatasetComponent,
@@ -21,9 +21,9 @@ import {
21
21
  } from 'echarts/components';
22
22
  import * as echarts from 'echarts/core';
23
23
  import { CanvasRenderer } from 'echarts/renderers';
24
- import React, { useEffect, useRef } from 'react';
24
+ import React from 'react';
25
25
 
26
- import { getOption, getResponsiveOption } from './getOption';
26
+ import { getOption } from './getOption';
27
27
  import type { ChartProps } from './types';
28
28
 
29
29
  echarts.use([
@@ -47,58 +47,11 @@ export const Chart = ({ data, isOrderBook, precision }: ChartProps) => {
47
47
  const { isDark, size } = useLayoutProvider();
48
48
  const isDesktop = size === Size.DESKTOP;
49
49
 
50
- const echartRef = useRef<BaseChartRef | null>(null);
51
-
52
- useEffect(() => {
53
- if (echartRef.current) {
54
- const echartInstance = echartRef.current.getEchartsInstance();
55
-
56
- echartInstance.on('highlight', () => {
57
- if (
58
- (echartInstance.getOption().color as echarts.Color[])[0] ===
59
- colorPalette.bottleGreenLight
60
- ) {
61
- echartInstance.setOption({
62
- color: [
63
- colorPalette.bottleGreenLight70,
64
- isDark ? colorPalette.orange70 : colorPalette.raspberryDark70,
65
- ],
66
- });
67
- }
68
- });
69
-
70
- echartInstance.on('globalout', () => {
71
- echartInstance.setOption({
72
- color: [
73
- colorPalette.bottleGreenLight,
74
- isDark ? colorPalette.orange : colorPalette.raspberryDark,
75
- ],
76
- });
77
- });
78
- }
79
- }, [echartRef, isDark]);
80
-
81
- useEffect(() => {
82
- if (echartRef.current) {
83
- const echartInstance = echartRef.current.getEchartsInstance();
84
-
85
- echartInstance.setOption(
86
- getResponsiveOption({
87
- isDark,
88
- isOrderBook,
89
- isDesktop,
90
- lang,
91
- })
92
- );
93
- }
94
- }, [echartRef, isDesktop, isDark, isOrderBook, lang]);
95
-
96
50
  return (
97
51
  <div className="lw-relative lw-w-full" data-testid="order-book-chart">
98
52
  <div>
99
53
  {data && (
100
54
  <BaseChart
101
- ref={echartRef}
102
55
  chartHeight={isDesktop ? 450 : 390}
103
56
  echarts={echarts}
104
57
  isDark={isDark}
@@ -110,6 +63,26 @@ export const Chart = ({ data, isOrderBook, precision }: ChartProps) => {
110
63
  isDesktop,
111
64
  lang,
112
65
  })}
66
+ onEvents={{
67
+ highlight: (_params: unknown, instance: EChartsType) => {
68
+ instance.setOption({
69
+ color: [
70
+ colorPalette.bottleGreenLight70,
71
+ isDark
72
+ ? colorPalette.orange70
73
+ : colorPalette.raspberryDark70,
74
+ ],
75
+ });
76
+ },
77
+ globalout: (_params: unknown, instance: EChartsType) => {
78
+ instance.setOption({
79
+ color: [
80
+ colorPalette.bottleGreenLight,
81
+ isDark ? colorPalette.orange : colorPalette.raspberryDark,
82
+ ],
83
+ });
84
+ },
85
+ }}
113
86
  />
114
87
  )}
115
88
  </div>
@@ -15,130 +15,7 @@ import {
15
15
  ZOOM_CONTROL_HEIGHT,
16
16
  } from './constants';
17
17
  import { tooltipFormatter } from './formatters';
18
- import type { GetOptionType, GetResponsiveOptionsProps } from './types';
19
-
20
- export const getResponsiveOption = ({
21
- isDark,
22
- isOrderBook,
23
- isDesktop,
24
- lang,
25
- }: GetResponsiveOptionsProps) => {
26
- const desktopGridLines = getGridLines({
27
- isDark,
28
- chartWidth: CHART_WIDTH,
29
- chartHeight: isDesktop ? CHART_HEIGHT_DESKTOP : CHART_HEIGHT_MOBILE,
30
- xLabelsSize: isDesktop ? X_LABEL_SIZE : X_LABEL_SIZE + ZOOM_CONTROL_HEIGHT,
31
- yLabelSize: isDesktop ? Y_LABEL_SIZE_DESKTOP : Y_LABEL_SIZE_MOBILE,
32
- bottomLeftBox: isDesktop,
33
- marginBottom: isDesktop ? 0 : ZOOM_CONTROL_HEIGHT,
34
- });
35
-
36
- return {
37
- grid: [
38
- {
39
- name: 'main-grid',
40
- top: '48px',
41
- left: '0px',
42
- right: `${isDesktop ? Y_LABEL_SIZE_DESKTOP : Y_LABEL_SIZE_MOBILE}px`,
43
- bottom: `${isDesktop ? X_LABEL_SIZE : X_LABEL_SIZE + ZOOM_CONTROL_HEIGHT}px`,
44
- },
45
- ],
46
- yAxis: {
47
- axisLabel: {
48
- margin: isDesktop ? 10 : 0,
49
- },
50
- },
51
- series: [
52
- {
53
- type: 'custom',
54
- name: 'current-price',
55
- id: 'current-price',
56
- markLine: {
57
- label: {
58
- padding: isDesktop ? [5, 15, 5, 15] : [5, 12, 5, 5],
59
- },
60
- },
61
- },
62
- ],
63
- graphic: [
64
- ...desktopGridLines,
65
- {
66
- type: 'group',
67
- left: '8px',
68
- top: '56px',
69
- silent: true,
70
- children: [
71
- {
72
- type: 'rect',
73
- z: 100,
74
- left: 'center',
75
- top: 'middle',
76
- shape: {
77
- width: 70,
78
- height: 30,
79
- },
80
- style: {
81
- fill: isDark ? colorPalette.darkGray : colorPalette.white,
82
- shadowBlur: 8,
83
- shadowOffsetX: 0,
84
- shadowOffsetY: 1,
85
- shadowColor: 'rgba(0,0,0,0.1)',
86
- },
87
- },
88
- {
89
- type: 'text',
90
- z: 100,
91
- left: 'center',
92
- top: 'middle',
93
- style: {
94
- fill: isDark ? colorPalette.white : colorPalette.black,
95
- width: 70,
96
- height: 30,
97
- text: lang(isOrderBook ? 'sell' : 'short'),
98
- },
99
- },
100
- ],
101
- },
102
- {
103
- type: 'group',
104
- right: `${(isDesktop ? Y_LABEL_SIZE_DESKTOP : Y_LABEL_SIZE_MOBILE) + 8}px'`,
105
- top: '56px',
106
- silent: true,
107
- children: [
108
- {
109
- type: 'rect',
110
- z: 100,
111
- right: 'center',
112
- top: 'middle',
113
- shape: {
114
- width: 70,
115
- height: 30,
116
- },
117
- style: {
118
- fill: isDark ? colorPalette.darkGray : colorPalette.white,
119
- shadowBlur: 8,
120
- shadowOffsetX: 0,
121
- shadowOffsetY: 1,
122
- shadowColor: 'rgba(0,0,0,0.1)',
123
- },
124
- },
125
- {
126
- type: 'text',
127
- z: 100,
128
- right: 'center',
129
- top: 'middle',
130
- style: {
131
- fill: isDark ? colorPalette.white : colorPalette.black,
132
- width: 70,
133
- height: 30,
134
- text: lang(isOrderBook ? 'buy' : 'long'),
135
- },
136
- },
137
- ],
138
- },
139
- ],
140
- };
141
- };
18
+ import type { GetOptionType } from './types';
142
19
 
143
20
  export const getOption: GetOptionType = ({
144
21
  data,
@@ -167,6 +44,16 @@ export const getOption: GetOptionType = ({
167
44
 
168
45
  const range = max > min ? max : min;
169
46
 
47
+ const gridLines = getGridLines({
48
+ isDark,
49
+ chartWidth: CHART_WIDTH,
50
+ chartHeight: isDesktop ? CHART_HEIGHT_DESKTOP : CHART_HEIGHT_MOBILE,
51
+ xLabelsSize: isDesktop ? X_LABEL_SIZE : X_LABEL_SIZE + ZOOM_CONTROL_HEIGHT,
52
+ yLabelSize: isDesktop ? Y_LABEL_SIZE_DESKTOP : Y_LABEL_SIZE_MOBILE,
53
+ bottomLeftBox: isDesktop,
54
+ marginBottom: isDesktop ? 0 : ZOOM_CONTROL_HEIGHT,
55
+ });
56
+
170
57
  return {
171
58
  animation: false,
172
59
  color: [
@@ -176,11 +63,15 @@ export const getOption: GetOptionType = ({
176
63
  title: {
177
64
  text: lang(isOrderBook ? 'open_orders' : 'open_positions').toUpperCase(),
178
65
  padding: 20,
66
+ top: 0,
67
+ left: 0,
179
68
  textStyle: {
180
69
  fontSize: 14,
181
70
  },
182
71
  },
183
72
  toolbox: {
73
+ bottom: -4,
74
+ right: -4,
184
75
  feature: getZoomControls({
185
76
  resetStartValue: zoomInitialStartValue,
186
77
  resetEndValue: zoomInitialEndValue,
@@ -359,6 +250,7 @@ export const getOption: GetOptionType = ({
359
250
  backgroundColor: isDark
360
251
  ? colorPalette.orange
361
252
  : colorPalette.bottleGreenDark,
253
+ padding: isDesktop ? [5, 15, 5, 15] : [5, 12, 5, 5],
362
254
  },
363
255
  data: [
364
256
  {
@@ -369,5 +261,82 @@ export const getOption: GetOptionType = ({
369
261
  renderItem: () => null,
370
262
  },
371
263
  ],
264
+ graphic: [
265
+ ...gridLines,
266
+ {
267
+ type: 'group',
268
+ left: '8px',
269
+ top: '56px',
270
+ silent: true,
271
+ children: [
272
+ {
273
+ type: 'rect',
274
+ z: 100,
275
+ left: 'center',
276
+ top: 'middle',
277
+ shape: {
278
+ width: 70,
279
+ height: 30,
280
+ },
281
+ style: {
282
+ fill: isDark ? colorPalette.darkGray : colorPalette.white,
283
+ shadowBlur: 8,
284
+ shadowOffsetX: 0,
285
+ shadowOffsetY: 1,
286
+ shadowColor: 'rgba(0,0,0,0.1)',
287
+ },
288
+ },
289
+ {
290
+ type: 'text',
291
+ z: 100,
292
+ left: 'center',
293
+ top: 'middle',
294
+ style: {
295
+ fill: isDark ? colorPalette.white : colorPalette.black,
296
+ width: 70,
297
+ height: 30,
298
+ text: lang(isOrderBook ? 'sell' : 'short'),
299
+ },
300
+ },
301
+ ],
302
+ },
303
+ {
304
+ type: 'group',
305
+ right: `${(isDesktop ? Y_LABEL_SIZE_DESKTOP : Y_LABEL_SIZE_MOBILE) + 8}px'`,
306
+ top: '56px',
307
+ silent: true,
308
+ children: [
309
+ {
310
+ type: 'rect',
311
+ z: 100,
312
+ right: 'center',
313
+ top: 'middle',
314
+ shape: {
315
+ width: 70,
316
+ height: 30,
317
+ },
318
+ style: {
319
+ fill: isDark ? colorPalette.darkGray : colorPalette.white,
320
+ shadowBlur: 8,
321
+ shadowOffsetX: 0,
322
+ shadowOffsetY: 1,
323
+ shadowColor: 'rgba(0,0,0,0.1)',
324
+ },
325
+ },
326
+ {
327
+ type: 'text',
328
+ z: 100,
329
+ right: 'center',
330
+ top: 'middle',
331
+ style: {
332
+ fill: isDark ? colorPalette.white : colorPalette.black,
333
+ width: 70,
334
+ height: 30,
335
+ text: lang(isOrderBook ? 'buy' : 'long'),
336
+ },
337
+ },
338
+ ],
339
+ },
340
+ ],
372
341
  };
373
342
  };
@@ -8,13 +8,6 @@ export interface ChartProps {
8
8
  precision: number;
9
9
  }
10
10
 
11
- export interface GetResponsiveOptionsProps {
12
- isDesktop: boolean;
13
- isDark: boolean;
14
- isOrderBook: boolean;
15
- lang: (label: string) => string;
16
- }
17
-
18
11
  export interface GetOptionProps {
19
12
  data: GetOrderPositionBooksQuery;
20
13
  precision: number;