@oanda/labs-crowd-view-widget 1.0.43 → 1.0.45
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 +364 -0
- package/dist/main/CrowdViewWidget/CrowdViewWidget.js +3 -3
- package/dist/main/CrowdViewWidget/CrowdViewWidget.js.map +1 -1
- package/dist/main/CrowdViewWidget/Main.js +22 -12
- package/dist/main/CrowdViewWidget/Main.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Chart/Chart.js +16 -17
- package/dist/main/CrowdViewWidget/components/Chart/Chart.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Chart/ChartWithData.js +16 -13
- package/dist/main/CrowdViewWidget/components/Chart/ChartWithData.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Chart/{getOption.js → chartOptions.js} +79 -62
- package/dist/main/CrowdViewWidget/components/Chart/chartOptions.js.map +1 -0
- package/dist/main/CrowdViewWidget/components/Chart/index.js +44 -0
- package/dist/main/CrowdViewWidget/components/Chart/index.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Chart/types.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Chart/useCrowdViewData.js +184 -0
- package/dist/main/CrowdViewWidget/components/Chart/useCrowdViewData.js.map +1 -0
- package/dist/main/CrowdViewWidget/components/Chart/utils/chartUtils.js +107 -0
- package/dist/main/CrowdViewWidget/components/Chart/utils/chartUtils.js.map +1 -0
- package/dist/main/CrowdViewWidget/components/Legend/Legend.js +3 -2
- package/dist/main/CrowdViewWidget/components/Legend/Legend.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Legend/LegendBar.js +9 -11
- package/dist/main/CrowdViewWidget/components/Legend/LegendBar.js.map +1 -1
- package/dist/main/CrowdViewWidget/constants.js +31 -0
- package/dist/main/CrowdViewWidget/constants.js.map +1 -0
- package/dist/main/CrowdViewWidget/render.js +1 -0
- package/dist/main/CrowdViewWidget/render.js.map +1 -1
- package/dist/main/CrowdViewWidget/selectConfig.js +121 -0
- package/dist/main/CrowdViewWidget/selectConfig.js.map +1 -0
- package/dist/main/CrowdViewWidget/types/index.js +17 -0
- package/dist/main/CrowdViewWidget/types/index.js.map +1 -0
- package/dist/main/CrowdViewWidget/types/instruments.js +45 -0
- package/dist/main/CrowdViewWidget/types/instruments.js.map +1 -0
- package/dist/main/CrowdViewWidget/types.js +0 -44
- package/dist/main/CrowdViewWidget/types.js.map +1 -1
- package/dist/main/CrowdViewWidget/utils/instrumentUtils.js +13 -0
- package/dist/main/CrowdViewWidget/utils/instrumentUtils.js.map +1 -0
- package/dist/main/gql/getOrderPositionBooks.js +1 -1
- package/dist/main/gql/getOrderPositionBooks.js.map +1 -1
- package/dist/main/gql/getPriceCandles.js +11 -0
- package/dist/main/gql/getPriceCandles.js.map +1 -0
- package/dist/main/gql/types/gql.js +2 -3
- package/dist/main/gql/types/gql.js.map +1 -1
- package/dist/main/gql/types/graphql.js +161 -160
- package/dist/main/gql/types/graphql.js.map +1 -1
- package/dist/main/translations/sources/en.json +24 -0
- package/dist/module/CrowdViewWidget/CrowdViewWidget.js +3 -3
- package/dist/module/CrowdViewWidget/CrowdViewWidget.js.map +1 -1
- package/dist/module/CrowdViewWidget/Main.js +23 -13
- package/dist/module/CrowdViewWidget/Main.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/Chart.js +15 -16
- package/dist/module/CrowdViewWidget/components/Chart/Chart.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/ChartWithData.js +16 -12
- package/dist/module/CrowdViewWidget/components/Chart/ChartWithData.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/{getOption.js → chartOptions.js} +77 -59
- package/dist/module/CrowdViewWidget/components/Chart/chartOptions.js.map +1 -0
- package/dist/module/CrowdViewWidget/components/Chart/index.js +4 -0
- package/dist/module/CrowdViewWidget/components/Chart/index.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/types.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/useCrowdViewData.js +177 -0
- package/dist/module/CrowdViewWidget/components/Chart/useCrowdViewData.js.map +1 -0
- package/dist/module/CrowdViewWidget/components/Chart/utils/chartUtils.js +94 -0
- package/dist/module/CrowdViewWidget/components/Chart/utils/chartUtils.js.map +1 -0
- package/dist/module/CrowdViewWidget/components/Legend/Legend.js +3 -2
- package/dist/module/CrowdViewWidget/components/Legend/Legend.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Legend/LegendBar.js +9 -11
- package/dist/module/CrowdViewWidget/components/Legend/LegendBar.js.map +1 -1
- package/dist/module/CrowdViewWidget/constants.js +25 -0
- package/dist/module/CrowdViewWidget/constants.js.map +1 -0
- package/dist/module/CrowdViewWidget/render.js +1 -0
- package/dist/module/CrowdViewWidget/render.js.map +1 -1
- package/dist/module/CrowdViewWidget/selectConfig.js +116 -0
- package/dist/module/CrowdViewWidget/selectConfig.js.map +1 -0
- package/dist/module/CrowdViewWidget/types/index.js +2 -0
- package/dist/module/CrowdViewWidget/types/index.js.map +1 -0
- package/dist/module/CrowdViewWidget/types/instruments.js +39 -0
- package/dist/module/CrowdViewWidget/types/instruments.js.map +1 -0
- package/dist/module/CrowdViewWidget/types.js +1 -43
- package/dist/module/CrowdViewWidget/types.js.map +1 -1
- package/dist/module/CrowdViewWidget/utils/instrumentUtils.js +6 -0
- package/dist/module/CrowdViewWidget/utils/instrumentUtils.js.map +1 -0
- package/dist/module/gql/getOrderPositionBooks.js +1 -1
- package/dist/module/gql/getOrderPositionBooks.js.map +1 -1
- package/dist/module/gql/getPriceCandles.js +6 -0
- package/dist/module/gql/getPriceCandles.js.map +1 -0
- package/dist/module/gql/types/gql.js +2 -3
- package/dist/module/gql/types/gql.js.map +1 -1
- package/dist/module/gql/types/graphql.js +160 -159
- package/dist/module/gql/types/graphql.js.map +1 -1
- package/dist/module/translations/sources/en.json +24 -0
- package/dist/types/CrowdViewWidget/CrowdViewWidget.d.ts +1 -1
- package/dist/types/CrowdViewWidget/components/Chart/ChartWithData.d.ts +1 -1
- package/dist/types/CrowdViewWidget/components/Chart/index.d.ts +4 -0
- package/dist/types/CrowdViewWidget/components/Chart/types.d.ts +23 -16
- package/dist/types/CrowdViewWidget/components/Chart/useCrowdViewData.d.ts +2 -0
- package/dist/types/CrowdViewWidget/components/Chart/{utils.d.ts → utils/chartUtils.d.ts} +9 -11
- package/dist/types/CrowdViewWidget/components/Legend/Legend.d.ts +3 -3
- package/dist/types/CrowdViewWidget/constants.d.ts +24 -0
- package/dist/types/CrowdViewWidget/selectConfig.d.ts +19 -0
- package/dist/types/CrowdViewWidget/types/index.d.ts +1 -0
- package/dist/types/CrowdViewWidget/types/instruments.d.ts +36 -0
- package/dist/types/CrowdViewWidget/types.d.ts +2 -50
- package/dist/types/CrowdViewWidget/utils/instrumentUtils.d.ts +8 -0
- package/dist/types/gql/types/gql.d.ts +10 -14
- package/dist/types/gql/types/graphql.d.ts +71 -63
- package/lokalise.config.json +1 -1
- package/package.json +6 -4
- package/src/CrowdViewWidget/CrowdViewWidget.tsx +2 -2
- package/src/CrowdViewWidget/Main.tsx +32 -22
- package/src/CrowdViewWidget/components/Chart/Chart.tsx +21 -17
- package/src/CrowdViewWidget/components/Chart/ChartWithData.tsx +12 -12
- package/src/CrowdViewWidget/components/Chart/chartOptions.ts +205 -0
- package/src/CrowdViewWidget/components/Chart/index.ts +4 -0
- package/src/CrowdViewWidget/components/Chart/types.ts +30 -24
- package/src/CrowdViewWidget/components/Chart/useCrowdViewData.ts +288 -0
- package/src/CrowdViewWidget/components/Chart/utils/chartUtils.ts +161 -0
- package/src/CrowdViewWidget/components/Legend/Legend.tsx +7 -3
- package/src/CrowdViewWidget/components/Legend/LegendBar.tsx +16 -20
- package/src/CrowdViewWidget/constants.ts +28 -0
- package/src/CrowdViewWidget/render.tsx +1 -0
- package/src/CrowdViewWidget/{config.ts → selectConfig.ts} +65 -43
- package/src/CrowdViewWidget/types/index.ts +1 -0
- package/src/CrowdViewWidget/types/instruments.ts +37 -0
- package/src/CrowdViewWidget/types.ts +4 -55
- package/src/CrowdViewWidget/utils/instrumentUtils.ts +11 -0
- package/src/gql/getOrderPositionBooks.ts +9 -4
- package/src/gql/{mock/getPriceCandles.ts → getPriceCandles.ts} +5 -5
- package/src/gql/types/gql.ts +6 -14
- package/src/gql/types/graphql.ts +170 -160
- package/src/translations/sources/en.json +24 -0
- package/test/Main.test.tsx +73 -27
- package/test/components/Chart/utils/chartUtils.test.ts +172 -0
- package/test/components/Legend.test.tsx +3 -6
- package/test/components/LegendBar.test.tsx +7 -8
- package/test/utils/instrumentUtils.test.ts +52 -0
- package/dist/main/CrowdViewWidget/components/Chart/constants.js +0 -14
- package/dist/main/CrowdViewWidget/components/Chart/constants.js.map +0 -1
- package/dist/main/CrowdViewWidget/components/Chart/getOption.js.map +0 -1
- package/dist/main/CrowdViewWidget/components/Chart/getOrderPositionDataMock.js +0 -47
- package/dist/main/CrowdViewWidget/components/Chart/getOrderPositionDataMock.js.map +0 -1
- package/dist/main/CrowdViewWidget/components/Chart/getPriceCandlesMock.js +0 -36
- package/dist/main/CrowdViewWidget/components/Chart/getPriceCandlesMock.js.map +0 -1
- package/dist/main/CrowdViewWidget/components/Chart/utils.js +0 -166
- package/dist/main/CrowdViewWidget/components/Chart/utils.js.map +0 -1
- package/dist/main/CrowdViewWidget/config.js +0 -107
- package/dist/main/CrowdViewWidget/config.js.map +0 -1
- package/dist/main/gql/mock/getPriceCandles.js +0 -11
- package/dist/main/gql/mock/getPriceCandles.js.map +0 -1
- package/dist/main/gql/mock/schema.graphqls +0 -62
- package/dist/main/gql/validateInstruments.js +0 -11
- package/dist/main/gql/validateInstruments.js.map +0 -1
- package/dist/module/CrowdViewWidget/components/Chart/constants.js +0 -8
- package/dist/module/CrowdViewWidget/components/Chart/constants.js.map +0 -1
- package/dist/module/CrowdViewWidget/components/Chart/getOption.js.map +0 -1
- package/dist/module/CrowdViewWidget/components/Chart/getOrderPositionDataMock.js +0 -40
- package/dist/module/CrowdViewWidget/components/Chart/getOrderPositionDataMock.js.map +0 -1
- package/dist/module/CrowdViewWidget/components/Chart/getPriceCandlesMock.js +0 -29
- package/dist/module/CrowdViewWidget/components/Chart/getPriceCandlesMock.js.map +0 -1
- package/dist/module/CrowdViewWidget/components/Chart/utils.js +0 -156
- package/dist/module/CrowdViewWidget/components/Chart/utils.js.map +0 -1
- package/dist/module/CrowdViewWidget/config.js +0 -102
- package/dist/module/CrowdViewWidget/config.js.map +0 -1
- package/dist/module/gql/mock/getPriceCandles.js +0 -6
- package/dist/module/gql/mock/getPriceCandles.js.map +0 -1
- package/dist/module/gql/mock/schema.graphqls +0 -62
- package/dist/module/gql/validateInstruments.js +0 -5
- package/dist/module/gql/validateInstruments.js.map +0 -1
- package/dist/types/CrowdViewWidget/components/Chart/constants.d.ts +0 -7
- package/dist/types/CrowdViewWidget/components/Chart/getOrderPositionDataMock.d.ts +0 -14
- package/dist/types/CrowdViewWidget/components/Chart/getPriceCandlesMock.d.ts +0 -2
- package/dist/types/CrowdViewWidget/config.d.ts +0 -22
- package/dist/types/gql/validateInstruments.d.ts +0 -1
- package/src/CrowdViewWidget/components/Chart/constants.tsx +0 -8
- package/src/CrowdViewWidget/components/Chart/getOption.ts +0 -200
- package/src/CrowdViewWidget/components/Chart/getOrderPositionDataMock.ts +0 -66
- package/src/CrowdViewWidget/components/Chart/getPriceCandlesMock.ts +0 -43
- package/src/CrowdViewWidget/components/Chart/utils.ts +0 -191
- package/src/gql/mock/schema.graphqls +0 -62
- package/src/gql/validateInstruments.ts +0 -10
- /package/dist/types/CrowdViewWidget/components/Chart/{getOption.d.ts → chartOptions.d.ts} +0 -0
- /package/dist/types/gql/{mock/getPriceCandles.d.ts → getPriceCandles.d.ts} +0 -0
|
@@ -6,33 +6,45 @@ import {
|
|
|
6
6
|
useLayoutProvider,
|
|
7
7
|
} from '@oanda/labs-widget-common';
|
|
8
8
|
import { useLocale } from '@oanda/mono-i18n';
|
|
9
|
-
import React, { useState } from 'react';
|
|
9
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
10
10
|
|
|
11
|
-
import {
|
|
11
|
+
import type { Granularity } from '../gql/types/graphql';
|
|
12
|
+
import { BookType } from '../gql/types/graphql';
|
|
12
13
|
import { ChartWithData, Legend } from './components';
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
navigationConfig,
|
|
18
|
-
} from './config';
|
|
19
|
-
import type { GranularityId, InstrumentId, MainProps } from './types';
|
|
14
|
+
import { granularitySelectConfig, navigationConfig } from './selectConfig';
|
|
15
|
+
import type { MainProps } from './types';
|
|
16
|
+
import type { InstrumentId } from './types/instruments';
|
|
17
|
+
import { getInstrumentConfigForDivision } from './utils/instrumentUtils';
|
|
20
18
|
|
|
21
19
|
const Main = ({ division }: MainProps) => {
|
|
22
|
-
const
|
|
23
|
-
division === Division.Oc
|
|
24
|
-
? instrumentSelectConfigOC
|
|
25
|
-
: instrumentSelectConfig;
|
|
26
|
-
|
|
20
|
+
const { lang } = useLocale();
|
|
27
21
|
const { size } = useLayoutProvider();
|
|
28
22
|
const isDesktop = size === Size.DESKTOP;
|
|
23
|
+
|
|
29
24
|
const [bookType, setBookType] = useState(BookType.Order);
|
|
25
|
+
|
|
26
|
+
const granularitySelectConfigWithLang = useMemo(
|
|
27
|
+
() =>
|
|
28
|
+
granularitySelectConfig.map((opt) => ({
|
|
29
|
+
...opt,
|
|
30
|
+
label: lang(opt.label),
|
|
31
|
+
})),
|
|
32
|
+
[lang]
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const instrumentSelectConfigWithDivision =
|
|
36
|
+
getInstrumentConfigForDivision(division);
|
|
30
37
|
const [instrument, setInstrument] = useState(
|
|
31
38
|
instrumentSelectConfigWithDivision[0]
|
|
32
39
|
);
|
|
33
40
|
|
|
34
|
-
const [granularity, setGranularity] = useState(
|
|
35
|
-
|
|
41
|
+
const [granularity, setGranularity] = useState(
|
|
42
|
+
granularitySelectConfigWithLang[0]
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
setGranularity(granularitySelectConfigWithLang[0]);
|
|
47
|
+
}, [granularitySelectConfigWithLang]);
|
|
36
48
|
|
|
37
49
|
return (
|
|
38
50
|
<>
|
|
@@ -72,12 +84,12 @@ const Main = ({ division }: MainProps) => {
|
|
|
72
84
|
})}
|
|
73
85
|
>
|
|
74
86
|
<Select
|
|
75
|
-
options={
|
|
87
|
+
options={granularitySelectConfigWithLang}
|
|
76
88
|
searchPlaceholder={lang('search')}
|
|
77
89
|
selectLabel={lang('granularity')}
|
|
78
90
|
selectedOption={granularity}
|
|
79
91
|
setSelectedOption={(val) =>
|
|
80
|
-
setGranularity(val as { id:
|
|
92
|
+
setGranularity(val as { id: Granularity; label: string })
|
|
81
93
|
}
|
|
82
94
|
/>
|
|
83
95
|
</div>
|
|
@@ -85,14 +97,12 @@ const Main = ({ division }: MainProps) => {
|
|
|
85
97
|
|
|
86
98
|
<ChartWithData
|
|
87
99
|
bookType={bookType}
|
|
100
|
+
division={division}
|
|
88
101
|
granularity={granularity.id}
|
|
89
102
|
instrument={instrument.id}
|
|
90
103
|
/>
|
|
91
104
|
|
|
92
|
-
<Legend
|
|
93
|
-
longValues={[0.15, 0.25, 0.4, 0.55]}
|
|
94
|
-
shortValues={[0.15, 0.25, 0.4, 0.55]}
|
|
95
|
-
/>
|
|
105
|
+
<Legend />
|
|
96
106
|
</div>
|
|
97
107
|
)}
|
|
98
108
|
</>
|
|
@@ -4,8 +4,14 @@ import {
|
|
|
4
4
|
Theme,
|
|
5
5
|
useLayoutProvider,
|
|
6
6
|
} from '@oanda/labs-widget-common';
|
|
7
|
+
import { useLocale } from '@oanda/mono-i18n';
|
|
7
8
|
import type { EChartsType } from 'echarts';
|
|
8
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
BarChart,
|
|
11
|
+
CandlestickChart,
|
|
12
|
+
CustomChart,
|
|
13
|
+
ScatterChart,
|
|
14
|
+
} from 'echarts/charts';
|
|
9
15
|
import {
|
|
10
16
|
DataZoomInsideComponent,
|
|
11
17
|
GraphicComponent,
|
|
@@ -17,10 +23,14 @@ import * as echarts from 'echarts/core';
|
|
|
17
23
|
import { CanvasRenderer } from 'echarts/renderers';
|
|
18
24
|
import React from 'react';
|
|
19
25
|
|
|
20
|
-
import {
|
|
21
|
-
import { getOption } from './
|
|
26
|
+
import { CHART_CONFIG } from '../../constants';
|
|
27
|
+
import { getOption } from './chartOptions';
|
|
22
28
|
import type { ChartProps } from './types';
|
|
23
|
-
import {
|
|
29
|
+
import {
|
|
30
|
+
formatXAxisLabel,
|
|
31
|
+
getLabelData,
|
|
32
|
+
isDifferenceGreaterThanTwoWeeks,
|
|
33
|
+
} from './utils/chartUtils';
|
|
24
34
|
|
|
25
35
|
echarts.use([
|
|
26
36
|
GridSimpleComponent,
|
|
@@ -32,6 +42,7 @@ echarts.use([
|
|
|
32
42
|
TooltipComponent,
|
|
33
43
|
CandlestickChart,
|
|
34
44
|
MarkPointComponent,
|
|
45
|
+
ScatterChart,
|
|
35
46
|
]);
|
|
36
47
|
|
|
37
48
|
echarts.registerTheme('dark_theme', getChartTheme(Theme.Dark));
|
|
@@ -39,14 +50,16 @@ echarts.registerTheme('light_theme', getChartTheme(Theme.Light));
|
|
|
39
50
|
|
|
40
51
|
const Chart = ({ data }: ChartProps) => {
|
|
41
52
|
const { isDark } = useLayoutProvider();
|
|
53
|
+
const { lang } = useLocale();
|
|
42
54
|
|
|
43
55
|
return (
|
|
44
56
|
<BaseChart
|
|
45
|
-
chartHeight={
|
|
57
|
+
chartHeight={CHART_CONFIG.HEIGHT}
|
|
46
58
|
echarts={echarts}
|
|
47
59
|
isDark={isDark}
|
|
48
60
|
lazyUpdate={true}
|
|
49
|
-
option={getOption(data, isDark)}
|
|
61
|
+
option={getOption(data, isDark, lang)}
|
|
62
|
+
opts={{ renderer: 'canvas' }}
|
|
50
63
|
onEvents={{
|
|
51
64
|
datazoom: (_params: unknown, instance: EChartsType) => {
|
|
52
65
|
const { dataZoom } = instance.getOption();
|
|
@@ -68,17 +81,8 @@ const Chart = ({ data }: ChartProps) => {
|
|
|
68
81
|
instance.setOption({
|
|
69
82
|
xAxis: {
|
|
70
83
|
axisLabel: {
|
|
71
|
-
formatter: (value: string) =>
|
|
72
|
-
|
|
73
|
-
return isGreaterThanTwoWeeks
|
|
74
|
-
? `${date.toLocaleTimeString(undefined, {
|
|
75
|
-
hour: '2-digit',
|
|
76
|
-
minute: '2-digit',
|
|
77
|
-
})}`
|
|
78
|
-
: `${date.toLocaleDateString(undefined, {
|
|
79
|
-
day: 'numeric',
|
|
80
|
-
})}`;
|
|
81
|
-
},
|
|
84
|
+
formatter: (value: string) =>
|
|
85
|
+
formatXAxisLabel(value, isGreaterThanTwoWeeks),
|
|
82
86
|
},
|
|
83
87
|
},
|
|
84
88
|
series: [
|
|
@@ -6,27 +6,27 @@ import {
|
|
|
6
6
|
useLayoutProvider,
|
|
7
7
|
} from '@oanda/labs-widget-common';
|
|
8
8
|
import classnames from 'classnames';
|
|
9
|
-
import React
|
|
9
|
+
import React from 'react';
|
|
10
10
|
|
|
11
11
|
import { Chart } from './Chart';
|
|
12
12
|
import type { ChartWithDataProps } from './types';
|
|
13
|
-
import {
|
|
13
|
+
import { useCrowdViewData } from './useCrowdViewData';
|
|
14
14
|
|
|
15
15
|
const ChartWithData = ({
|
|
16
16
|
instrument,
|
|
17
17
|
bookType,
|
|
18
|
+
division,
|
|
18
19
|
granularity,
|
|
19
20
|
}: ChartWithDataProps) => {
|
|
20
21
|
const { size } = useLayoutProvider();
|
|
21
22
|
const isDesktop = size === Size.DESKTOP;
|
|
22
23
|
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}, [instrument, granularity, bookType]);
|
|
24
|
+
const { data, loading, error } = useCrowdViewData({
|
|
25
|
+
instrument,
|
|
26
|
+
bookType,
|
|
27
|
+
division,
|
|
28
|
+
granularity,
|
|
29
|
+
});
|
|
30
30
|
|
|
31
31
|
return (
|
|
32
32
|
<>
|
|
@@ -36,7 +36,7 @@ const ChartWithData = ({
|
|
|
36
36
|
'lw-h-[390px]': !isDesktop,
|
|
37
37
|
})}
|
|
38
38
|
>
|
|
39
|
-
{
|
|
39
|
+
{error && (
|
|
40
40
|
<div
|
|
41
41
|
className={classnames(
|
|
42
42
|
'lw-absolute lw-left-0 lw-top-0 lw-flex lw-w-full lw-items-center lw-justify-center lw-border lw-border-solid lw-border-border-primary',
|
|
@@ -62,9 +62,9 @@ const ChartWithData = ({
|
|
|
62
62
|
<Spinner size={SpinnerSize.lg} />
|
|
63
63
|
</div>
|
|
64
64
|
)}
|
|
65
|
-
{!
|
|
65
|
+
{!loading && !error && !!data && (
|
|
66
66
|
<div className="lw-absolute lw-left-0 lw-top-0 lw-flex lw-h-full lw-w-full">
|
|
67
|
-
<Chart data={
|
|
67
|
+
<Chart data={data} />
|
|
68
68
|
</div>
|
|
69
69
|
)}
|
|
70
70
|
</div>
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import {
|
|
2
|
+
colorPalette,
|
|
3
|
+
getGridLines,
|
|
4
|
+
getLineCommons,
|
|
5
|
+
} from '@oanda/labs-widget-common';
|
|
6
|
+
|
|
7
|
+
import { CHART_CONFIG } from '../../constants';
|
|
8
|
+
import type { GetOptionType } from './types';
|
|
9
|
+
import {
|
|
10
|
+
formatXAxisLabel,
|
|
11
|
+
getLabelData,
|
|
12
|
+
getRectColor,
|
|
13
|
+
getTooltipFormatter,
|
|
14
|
+
isDifferenceGreaterThanTwoWeeks,
|
|
15
|
+
} from './utils/chartUtils';
|
|
16
|
+
|
|
17
|
+
// @ts-expect-error
|
|
18
|
+
export const getOption: GetOptionType = (
|
|
19
|
+
{ xAxisData, candlesSeriesData, orderPositionBooks, bucketWidth, buckets },
|
|
20
|
+
isDark,
|
|
21
|
+
labelCallback
|
|
22
|
+
) => {
|
|
23
|
+
let selectedPrice: number;
|
|
24
|
+
const visibleXAxisData = xAxisData.slice(
|
|
25
|
+
(xAxisData.length * CHART_CONFIG.INITIAL_START_ZOOM) / 100,
|
|
26
|
+
(xAxisData.length * CHART_CONFIG.INITIAL_END_ZOOM) / 100
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const isGreaterThanTwoWeeks = isDifferenceGreaterThanTwoWeeks(
|
|
30
|
+
visibleXAxisData[0],
|
|
31
|
+
visibleXAxisData[visibleXAxisData.length - 1]
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const labelsData = getLabelData({
|
|
35
|
+
xAxisData,
|
|
36
|
+
isGreaterThanTwoWeeks,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const gridLines = getGridLines({
|
|
40
|
+
isDark,
|
|
41
|
+
chartWidth: CHART_CONFIG.WIDTH,
|
|
42
|
+
chartHeight: CHART_CONFIG.HEIGHT,
|
|
43
|
+
xLabelsSize: CHART_CONFIG.X_LABEL_SIZE,
|
|
44
|
+
yLabelSize: CHART_CONFIG.Y_LABEL_SIZE_DESKTOP,
|
|
45
|
+
bottomLeftBox: false,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
animation: false,
|
|
50
|
+
dataZoom: [
|
|
51
|
+
{
|
|
52
|
+
type: 'inside',
|
|
53
|
+
xAxisIndex: 0,
|
|
54
|
+
start: CHART_CONFIG.INITIAL_START_ZOOM,
|
|
55
|
+
end: CHART_CONFIG.INITIAL_END_ZOOM,
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
tooltip: {
|
|
59
|
+
trigger: 'axis',
|
|
60
|
+
axisPointer: {
|
|
61
|
+
type: 'cross',
|
|
62
|
+
axis: 'x',
|
|
63
|
+
label: {
|
|
64
|
+
formatter: (params) => {
|
|
65
|
+
if (params.axisDimension === 'y') {
|
|
66
|
+
selectedPrice = Number(params.value);
|
|
67
|
+
return Number(params.value).toFixed(5);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (params.axisDimension === 'x') {
|
|
71
|
+
const date = new Date(params.value as string);
|
|
72
|
+
return date.toLocaleString(undefined, {
|
|
73
|
+
hour: '2-digit',
|
|
74
|
+
minute: '2-digit',
|
|
75
|
+
day: 'numeric',
|
|
76
|
+
month: 'short',
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return null;
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
confine: true,
|
|
85
|
+
formatter: (params) =>
|
|
86
|
+
getTooltipFormatter(
|
|
87
|
+
params,
|
|
88
|
+
buckets,
|
|
89
|
+
bucketWidth,
|
|
90
|
+
selectedPrice,
|
|
91
|
+
labelCallback
|
|
92
|
+
),
|
|
93
|
+
},
|
|
94
|
+
xAxis: {
|
|
95
|
+
type: 'category',
|
|
96
|
+
data: xAxisData,
|
|
97
|
+
splitNumber: 1,
|
|
98
|
+
axisTick: {
|
|
99
|
+
show: false,
|
|
100
|
+
},
|
|
101
|
+
axisLabel: {
|
|
102
|
+
padding: [8, 16, 8, 16],
|
|
103
|
+
margin: 0,
|
|
104
|
+
formatter: (value) => formatXAxisLabel(value, isGreaterThanTwoWeeks),
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
yAxis: {
|
|
108
|
+
type: 'value',
|
|
109
|
+
position: 'right',
|
|
110
|
+
min: (val) => val.min - bucketWidth * 2,
|
|
111
|
+
max: (val) => val.max + bucketWidth * 2,
|
|
112
|
+
axisLine: { show: false },
|
|
113
|
+
axisTick: { show: false },
|
|
114
|
+
axisLabel: {
|
|
115
|
+
showMaxLabel: false,
|
|
116
|
+
showMinLabel: false,
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
series: [
|
|
120
|
+
{
|
|
121
|
+
type: 'candlestick',
|
|
122
|
+
id: 'candlestick',
|
|
123
|
+
data: candlesSeriesData,
|
|
124
|
+
itemStyle: {
|
|
125
|
+
color: colorPalette.raspberryLight,
|
|
126
|
+
color0: colorPalette.bottleGreenLight,
|
|
127
|
+
},
|
|
128
|
+
markPoint: {
|
|
129
|
+
symbol: 'circle',
|
|
130
|
+
symbolSize: 0,
|
|
131
|
+
data: labelsData,
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
type: 'custom',
|
|
136
|
+
name: 'heatmap',
|
|
137
|
+
id: 'heatmap',
|
|
138
|
+
silent: true,
|
|
139
|
+
clip: true,
|
|
140
|
+
renderItem: (_params, api) => {
|
|
141
|
+
const xVal = api.value(0);
|
|
142
|
+
const bucketIndex = api.value(2) as number;
|
|
143
|
+
const metaValues = buckets[bucketIndex];
|
|
144
|
+
|
|
145
|
+
const [rectWidth, rectHeight] = api.size!([
|
|
146
|
+
0,
|
|
147
|
+
bucketWidth,
|
|
148
|
+
]) as number[];
|
|
149
|
+
|
|
150
|
+
const items = metaValues.map(
|
|
151
|
+
({ price, sentiment }: { price: number; sentiment: number }) => {
|
|
152
|
+
const start = api.coord([xVal, price]);
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
type: 'rect',
|
|
156
|
+
shape: {
|
|
157
|
+
x: start[0] - rectWidth / 2,
|
|
158
|
+
y: start[1] - rectHeight,
|
|
159
|
+
width: rectWidth,
|
|
160
|
+
height: rectHeight,
|
|
161
|
+
},
|
|
162
|
+
style: {
|
|
163
|
+
fill: getRectColor(sentiment),
|
|
164
|
+
},
|
|
165
|
+
silent: true,
|
|
166
|
+
emphasisDisabled: true,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
return {
|
|
172
|
+
type: 'group',
|
|
173
|
+
children: items,
|
|
174
|
+
silent: true,
|
|
175
|
+
emphasisDisabled: true,
|
|
176
|
+
};
|
|
177
|
+
},
|
|
178
|
+
data: orderPositionBooks,
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
grid: [
|
|
182
|
+
{
|
|
183
|
+
name: 'main-grid',
|
|
184
|
+
top: '0px',
|
|
185
|
+
left: '0px',
|
|
186
|
+
right: `${CHART_CONFIG.Y_LABEL_SIZE_DESKTOP}px`,
|
|
187
|
+
bottom: `${CHART_CONFIG.X_LABEL_SIZE}px`,
|
|
188
|
+
},
|
|
189
|
+
],
|
|
190
|
+
graphic: [
|
|
191
|
+
...gridLines,
|
|
192
|
+
{
|
|
193
|
+
...getLineCommons(isDark as boolean),
|
|
194
|
+
top: 0,
|
|
195
|
+
right: 0,
|
|
196
|
+
shape: {
|
|
197
|
+
x1: 0,
|
|
198
|
+
y1: 0,
|
|
199
|
+
x2: 0,
|
|
200
|
+
y2: 0,
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
],
|
|
204
|
+
};
|
|
205
|
+
};
|
|
@@ -1,45 +1,51 @@
|
|
|
1
1
|
import type { EChartsOption } from 'echarts';
|
|
2
2
|
|
|
3
|
-
import type {
|
|
4
|
-
|
|
3
|
+
import type {
|
|
4
|
+
BookType,
|
|
5
|
+
Division,
|
|
6
|
+
Granularity,
|
|
7
|
+
} from '../../../gql/types/graphql';
|
|
5
8
|
|
|
6
|
-
interface
|
|
9
|
+
export interface UseCrowdViewDataProps {
|
|
10
|
+
instrument: string;
|
|
11
|
+
bookType: BookType;
|
|
12
|
+
division: Division;
|
|
13
|
+
granularity: Granularity;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface CrowdViewData {
|
|
7
17
|
xAxisData: string[];
|
|
8
|
-
|
|
9
|
-
// timestamp
|
|
10
|
-
string,
|
|
11
|
-
// price
|
|
12
|
-
number,
|
|
13
|
-
// orders-positions sentiment
|
|
14
|
-
number,
|
|
15
|
-
][];
|
|
16
|
-
ordersPositionsBucketWidth: number;
|
|
18
|
+
// [open, close, low, high]
|
|
17
19
|
candlesSeriesData: [number, number, number, number][];
|
|
20
|
+
// [time, price, index]
|
|
21
|
+
orderPositionBooks: ([string, number, number] | null)[];
|
|
22
|
+
bucketWidth: number;
|
|
23
|
+
buckets: { price: number; sentiment: number }[][];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface UseCrowdViewDataReturn {
|
|
27
|
+
data: CrowdViewData | null;
|
|
28
|
+
loading: boolean;
|
|
29
|
+
error: boolean;
|
|
18
30
|
}
|
|
19
31
|
|
|
20
32
|
export type GetOptionType = (
|
|
21
|
-
props:
|
|
22
|
-
isDark: boolean
|
|
33
|
+
props: CrowdViewData,
|
|
34
|
+
isDark: boolean,
|
|
35
|
+
labelCallback: (key: string, params?: Record<string, unknown>) => string
|
|
23
36
|
) => EChartsOption;
|
|
24
37
|
|
|
25
38
|
export interface ChartProps {
|
|
26
|
-
data:
|
|
39
|
+
data: CrowdViewData;
|
|
27
40
|
}
|
|
28
41
|
|
|
29
42
|
export interface ChartWithDataProps {
|
|
30
43
|
bookType: BookType;
|
|
44
|
+
division: Division;
|
|
31
45
|
instrument: string;
|
|
32
|
-
granularity:
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
interface TransformDataForChartTypeProps {
|
|
36
|
-
granularity: GranularityId;
|
|
46
|
+
granularity: Granularity;
|
|
37
47
|
}
|
|
38
48
|
|
|
39
|
-
export type TransformDataForChartType = (
|
|
40
|
-
props: TransformDataForChartTypeProps
|
|
41
|
-
) => ChartOptionsProps;
|
|
42
|
-
|
|
43
49
|
export interface GetLabelsDataProps {
|
|
44
50
|
xAxisData: string[];
|
|
45
51
|
isGreaterThanTwoWeeks: boolean;
|