@oanda/labs-crowd-view-widget 1.0.56 → 1.0.57
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 +232 -0
- package/dist/main/CrowdViewWidget/components/Chart/Chart.js +1 -6
- package/dist/main/CrowdViewWidget/components/Chart/Chart.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getGridConfig.js +5 -4
- package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getGridConfig.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getGridLines.js +13 -6
- package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getGridLines.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getLabelsConfig.js +4 -4
- package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getLabelsConfig.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getTooltipConfig.js +9 -43
- package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getTooltipConfig.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getXAxisConfig.js +19 -4
- package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getXAxisConfig.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getYAxisConfig.js +15 -2
- package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getYAxisConfig.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Chart/chartUtils/formatFullDate.js +27 -0
- package/dist/main/CrowdViewWidget/components/Chart/chartUtils/formatFullDate.js.map +1 -0
- package/dist/main/CrowdViewWidget/components/Chart/chartUtils/getTooltipFormatter.js +14 -23
- package/dist/main/CrowdViewWidget/components/Chart/chartUtils/getTooltipFormatter.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Chart/chartUtils/index.js +11 -0
- package/dist/main/CrowdViewWidget/components/Chart/chartUtils/index.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Chart/getOption.js +4 -4
- package/dist/main/CrowdViewWidget/components/Chart/getOption.js.map +1 -1
- package/dist/main/CrowdViewWidget/constants.js +6 -5
- package/dist/main/CrowdViewWidget/constants.js.map +1 -1
- package/dist/main/translations/sources/en.json +2 -1
- package/dist/module/CrowdViewWidget/components/Chart/Chart.js +2 -7
- package/dist/module/CrowdViewWidget/components/Chart/Chart.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getGridConfig.js +5 -4
- package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getGridConfig.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getGridLines.js +13 -6
- package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getGridLines.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getLabelsConfig.js +4 -4
- package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getLabelsConfig.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getTooltipConfig.js +9 -42
- package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getTooltipConfig.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getXAxisConfig.js +20 -5
- package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getXAxisConfig.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getYAxisConfig.js +15 -2
- package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getYAxisConfig.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/chartUtils/formatFullDate.js +20 -0
- package/dist/module/CrowdViewWidget/components/Chart/chartUtils/formatFullDate.js.map +1 -0
- package/dist/module/CrowdViewWidget/components/Chart/chartUtils/getTooltipFormatter.js +14 -23
- package/dist/module/CrowdViewWidget/components/Chart/chartUtils/getTooltipFormatter.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/chartUtils/index.js +1 -0
- package/dist/module/CrowdViewWidget/components/Chart/chartUtils/index.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/getOption.js +4 -4
- package/dist/module/CrowdViewWidget/components/Chart/getOption.js.map +1 -1
- package/dist/module/CrowdViewWidget/constants.js +6 -5
- package/dist/module/CrowdViewWidget/constants.js.map +1 -1
- package/dist/module/translations/sources/en.json +2 -1
- package/dist/types/CrowdViewWidget/components/Chart/chartOptions/getTooltipConfig.d.ts +1 -2
- package/dist/types/CrowdViewWidget/components/Chart/chartOptions/getXAxisConfig.d.ts +2 -1
- package/dist/types/CrowdViewWidget/components/Chart/chartOptions/getYAxisConfig.d.ts +4 -2
- package/dist/types/CrowdViewWidget/components/Chart/chartUtils/formatFullDate.d.ts +1 -0
- package/dist/types/CrowdViewWidget/components/Chart/chartUtils/index.d.ts +1 -0
- package/dist/types/CrowdViewWidget/constants.d.ts +4 -3
- package/package.json +3 -3
- package/src/CrowdViewWidget/components/Chart/Chart.tsx +1 -7
- package/src/CrowdViewWidget/components/Chart/chartOptions/getGridConfig.ts +5 -4
- package/src/CrowdViewWidget/components/Chart/chartOptions/getGridLines.ts +19 -10
- package/src/CrowdViewWidget/components/Chart/chartOptions/getLabelsConfig.ts +9 -5
- package/src/CrowdViewWidget/components/Chart/chartOptions/getTooltipConfig.ts +38 -79
- package/src/CrowdViewWidget/components/Chart/chartOptions/getXAxisConfig.ts +26 -2
- package/src/CrowdViewWidget/components/Chart/chartOptions/getYAxisConfig.ts +20 -3
- package/src/CrowdViewWidget/components/Chart/chartUtils/formatFullDate.ts +26 -0
- package/src/CrowdViewWidget/components/Chart/chartUtils/getTooltipFormatter.ts +49 -35
- package/src/CrowdViewWidget/components/Chart/chartUtils/index.ts +1 -0
- package/src/CrowdViewWidget/components/Chart/getOption.ts +2 -2
- package/src/CrowdViewWidget/constants.ts +9 -7
- package/src/translations/sources/en.json +2 -1
|
@@ -17,20 +17,29 @@ export const getGridLines = ({
|
|
|
17
17
|
MAIN_HEIGHT_DESKTOP,
|
|
18
18
|
MAIN_HEIGHT_MOBILE,
|
|
19
19
|
X_LABEL_SIZE,
|
|
20
|
-
|
|
20
|
+
TOOLTIP_HEIGHT_MOBILE,
|
|
21
|
+
TOOLTIP_HEIGHT_DESKTOP,
|
|
22
|
+
Y_SENTIMENT_LABEL_DESKTOP_SIZE,
|
|
23
|
+
Y_SENTIMENT_LABEL_MOBILE_SIZE,
|
|
24
|
+
Y_LABEL_SIZE_DESKTOP,
|
|
25
|
+
Y_LABEL_SIZE_MOBILE,
|
|
26
|
+
TOP_LABEL_SPACE_MOBILE,
|
|
21
27
|
} = CHART_CONFIG;
|
|
28
|
+
|
|
22
29
|
const mainHeight = isDesktop ? MAIN_HEIGHT_DESKTOP : MAIN_HEIGHT_MOBILE;
|
|
23
30
|
const ySentimentLabelSize = isDesktop
|
|
24
|
-
?
|
|
25
|
-
:
|
|
31
|
+
? Y_SENTIMENT_LABEL_DESKTOP_SIZE
|
|
32
|
+
: Y_SENTIMENT_LABEL_MOBILE_SIZE;
|
|
26
33
|
|
|
27
|
-
const yLabelSize = isDesktop
|
|
28
|
-
? CHART_CONFIG.Y_LABEL_SIZE_DESKTOP
|
|
29
|
-
: CHART_CONFIG.Y_LABEL_SIZE_MOBILE;
|
|
34
|
+
const yLabelSize = isDesktop ? Y_LABEL_SIZE_DESKTOP : Y_LABEL_SIZE_MOBILE;
|
|
30
35
|
|
|
31
36
|
const topMargin = isDesktop
|
|
32
|
-
? CHART_CONFIG.
|
|
33
|
-
:
|
|
37
|
+
? CHART_CONFIG.TOP_LABEL_SPACE_DESKTOP + TOOLTIP_HEIGHT_DESKTOP
|
|
38
|
+
: TOP_LABEL_SPACE_MOBILE + TOOLTIP_HEIGHT_MOBILE;
|
|
39
|
+
|
|
40
|
+
const tooltipHeight = isDesktop
|
|
41
|
+
? TOOLTIP_HEIGHT_DESKTOP
|
|
42
|
+
: TOOLTIP_HEIGHT_MOBILE;
|
|
34
43
|
|
|
35
44
|
return [
|
|
36
45
|
// Top
|
|
@@ -134,11 +143,11 @@ export const getGridLines = ({
|
|
|
134
143
|
// Mobile tooltip,
|
|
135
144
|
{
|
|
136
145
|
...getLineCommons(isDark),
|
|
137
|
-
top:
|
|
146
|
+
top: tooltipHeight - 3,
|
|
138
147
|
shape: {
|
|
139
148
|
x1: 0,
|
|
140
149
|
y1: 0,
|
|
141
|
-
x2:
|
|
150
|
+
x2: WIDTH,
|
|
142
151
|
y2: 0,
|
|
143
152
|
},
|
|
144
153
|
z: 30,
|
|
@@ -40,8 +40,8 @@ export const getLabelsConfig = ({
|
|
|
40
40
|
const priceVerticalOffset = priceEstimatedWidth / 2;
|
|
41
41
|
|
|
42
42
|
const topMargin = isDesktop
|
|
43
|
-
? CHART_CONFIG.
|
|
44
|
-
: CHART_CONFIG.
|
|
43
|
+
? CHART_CONFIG.TOP_LABEL_SPACE_DESKTOP + CHART_CONFIG.TOOLTIP_HEIGHT_DESKTOP
|
|
44
|
+
: CHART_CONFIG.TOP_LABEL_SPACE_MOBILE + CHART_CONFIG.TOOLTIP_HEIGHT_MOBILE;
|
|
45
45
|
|
|
46
46
|
const mainHeight = isDesktop
|
|
47
47
|
? CHART_CONFIG.MAIN_HEIGHT_DESKTOP
|
|
@@ -195,12 +195,16 @@ export const getLabelsConfig = ({
|
|
|
195
195
|
type: 'text',
|
|
196
196
|
z: 20,
|
|
197
197
|
left: 'center',
|
|
198
|
-
top:
|
|
198
|
+
top: isDesktop
|
|
199
|
+
? CHART_CONFIG.TOOLTIP_HEIGHT_DESKTOP / 2 - 5
|
|
200
|
+
: CHART_CONFIG.TOOLTIP_HEIGHT_MOBILE / 2 - 5,
|
|
199
201
|
silent: true,
|
|
200
202
|
style: {
|
|
201
|
-
fontSize: isDesktop ?
|
|
203
|
+
fontSize: isDesktop ? 12 : 11,
|
|
202
204
|
fill: textColor,
|
|
203
|
-
text: isDesktop
|
|
205
|
+
text: isDesktop
|
|
206
|
+
? labelCallback('hover_chart_to_see_more_details')
|
|
207
|
+
: labelCallback('tap_chart_to_see_more_details'),
|
|
204
208
|
},
|
|
205
209
|
},
|
|
206
210
|
];
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { colorPalette } from '@oanda/labs-widget-common';
|
|
2
|
-
import chroma from 'chroma-js';
|
|
3
1
|
import type { TooltipComponentOption } from 'echarts';
|
|
4
2
|
|
|
5
3
|
import type { BookType } from '../../../../gql/types/graphql';
|
|
6
|
-
import { CHART_CONFIG } from '../../../constants';
|
|
7
4
|
import { getTooltipFormatter } from '../chartUtils';
|
|
8
5
|
import type { Bucket, TooltipParam } from '../types';
|
|
9
6
|
|
|
@@ -11,7 +8,6 @@ interface GetTooltipConfigParams {
|
|
|
11
8
|
bookType: BookType;
|
|
12
9
|
bucketWidth: number;
|
|
13
10
|
buckets: Bucket[][];
|
|
14
|
-
displayPrecision: number;
|
|
15
11
|
labelCallback: (key: string, params?: Record<string, unknown>) => string;
|
|
16
12
|
selectedPriceRef: { current: number };
|
|
17
13
|
tooltipLinesColor: string;
|
|
@@ -26,7 +22,6 @@ export const getTooltipConfig = ({
|
|
|
26
22
|
bookType,
|
|
27
23
|
bucketWidth,
|
|
28
24
|
buckets,
|
|
29
|
-
displayPrecision,
|
|
30
25
|
labelCallback,
|
|
31
26
|
selectedPriceRef,
|
|
32
27
|
tooltipLinesColor,
|
|
@@ -35,83 +30,47 @@ export const getTooltipConfig = ({
|
|
|
35
30
|
isDesktop,
|
|
36
31
|
isDark,
|
|
37
32
|
locale,
|
|
38
|
-
}: GetTooltipConfigParams): TooltipComponentOption => {
|
|
39
|
-
|
|
33
|
+
}: GetTooltipConfigParams): TooltipComponentOption => ({
|
|
34
|
+
backgroundColor: 'transparent',
|
|
35
|
+
shadowColor: 'transparent',
|
|
36
|
+
extraCssText: 'width: 100%; z-index: 5;',
|
|
37
|
+
padding: 4,
|
|
38
|
+
textStyle: isDesktop
|
|
40
39
|
? {
|
|
41
|
-
|
|
42
|
-
? chroma(colorPalette.darkGray).alpha(0.95).hex()
|
|
43
|
-
: chroma(colorPalette.darkWhite).alpha(0.95).hex(),
|
|
44
|
-
shadowColor: colorPalette.black10,
|
|
45
|
-
extraCssText: 'z-index: 5;',
|
|
46
|
-
padding: 8,
|
|
47
|
-
alwaysShowContent: false,
|
|
48
|
-
textStyle: {
|
|
49
|
-
fontSize: 11,
|
|
50
|
-
},
|
|
40
|
+
fontSize: 12,
|
|
51
41
|
}
|
|
52
42
|
: {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
extraCssText: 'width: 100%; z-index: 5;',
|
|
56
|
-
padding: 4,
|
|
57
|
-
alwaysShowContent: true,
|
|
58
|
-
textStyle: {
|
|
59
|
-
fontSize: 10,
|
|
60
|
-
lineHeight: 12,
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
return {
|
|
64
|
-
...styles,
|
|
65
|
-
trigger: 'axis' as const,
|
|
66
|
-
formatter: (params) =>
|
|
67
|
-
getTooltipFormatter({
|
|
68
|
-
bookType,
|
|
69
|
-
bucketWidth,
|
|
70
|
-
buckets,
|
|
71
|
-
labelCallback,
|
|
72
|
-
params: params as unknown as TooltipParam[],
|
|
73
|
-
selectedPrice: selectedPriceRef.current,
|
|
74
|
-
sentimentLongs,
|
|
75
|
-
sentimentShorts,
|
|
76
|
-
isDesktop,
|
|
77
|
-
locale,
|
|
78
|
-
isDark,
|
|
79
|
-
}),
|
|
80
|
-
hideDelay: 0,
|
|
81
|
-
axisPointer: {
|
|
82
|
-
type: 'cross' as const,
|
|
83
|
-
axis: 'x' as const,
|
|
84
|
-
lineStyle: {
|
|
85
|
-
color: tooltipLinesColor,
|
|
86
|
-
},
|
|
87
|
-
crossStyle: {
|
|
88
|
-
color: tooltipLinesColor,
|
|
89
|
-
},
|
|
90
|
-
label: {
|
|
91
|
-
padding: 0,
|
|
92
|
-
lineHeight: 24,
|
|
93
|
-
formatter: (params: {
|
|
94
|
-
axisDimension?: string;
|
|
95
|
-
axisIndex?: number;
|
|
96
|
-
value: unknown;
|
|
97
|
-
}) => {
|
|
98
|
-
if (params.axisDimension === 'y' && params.axisIndex === 0) {
|
|
99
|
-
selectedPriceRef.current = Number(params.value);
|
|
100
|
-
return ` ${Number(params.value).toFixed(displayPrecision)} `;
|
|
101
|
-
}
|
|
102
|
-
return '';
|
|
103
|
-
},
|
|
43
|
+
fontSize: 10,
|
|
44
|
+
lineHeight: 12,
|
|
104
45
|
},
|
|
46
|
+
alwaysShowContent: true,
|
|
47
|
+
trigger: 'axis' as const,
|
|
48
|
+
formatter: (params) =>
|
|
49
|
+
getTooltipFormatter({
|
|
50
|
+
bookType,
|
|
51
|
+
bucketWidth,
|
|
52
|
+
buckets,
|
|
53
|
+
labelCallback,
|
|
54
|
+
params: params as unknown as TooltipParam[],
|
|
55
|
+
selectedPrice: selectedPriceRef.current,
|
|
56
|
+
sentimentLongs,
|
|
57
|
+
sentimentShorts,
|
|
58
|
+
isDesktop,
|
|
59
|
+
locale,
|
|
60
|
+
isDark,
|
|
61
|
+
}),
|
|
62
|
+
hideDelay: 0,
|
|
63
|
+
axisPointer: {
|
|
64
|
+
type: 'cross' as const,
|
|
65
|
+
axis: 'x' as const,
|
|
66
|
+
lineStyle: {
|
|
67
|
+
color: tooltipLinesColor,
|
|
105
68
|
},
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if (isDesktop) {
|
|
109
|
-
return [
|
|
110
|
-
point[0] + CHART_CONFIG.TOOLTIP_OFFSET,
|
|
111
|
-
point[1] + CHART_CONFIG.TOOLTIP_OFFSET,
|
|
112
|
-
];
|
|
113
|
-
}
|
|
114
|
-
return [0, 0];
|
|
69
|
+
crossStyle: {
|
|
70
|
+
color: tooltipLinesColor,
|
|
115
71
|
},
|
|
116
|
-
|
|
117
|
-
}
|
|
72
|
+
z: 30,
|
|
73
|
+
},
|
|
74
|
+
confine: true,
|
|
75
|
+
position: [0, 0],
|
|
76
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { XAXisComponentOption } from 'echarts';
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
+
formatFullDate,
|
|
4
5
|
formatXAxisAdditionalLabel,
|
|
5
6
|
formatXAxisLabel,
|
|
6
7
|
getLabelData,
|
|
@@ -10,12 +11,14 @@ interface GetXAxisConfigParams {
|
|
|
10
11
|
dates: string[];
|
|
11
12
|
isGreaterThanTwoWeeks: boolean;
|
|
12
13
|
locale: string;
|
|
14
|
+
isDesktop: boolean;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
export const getXAxisConfig = ({
|
|
16
18
|
dates,
|
|
17
19
|
isGreaterThanTwoWeeks,
|
|
18
20
|
locale,
|
|
21
|
+
isDesktop,
|
|
19
22
|
}: GetXAxisConfigParams): XAXisComponentOption[] => {
|
|
20
23
|
const labelsData = getLabelData({
|
|
21
24
|
dates,
|
|
@@ -38,14 +41,32 @@ export const getXAxisConfig = ({
|
|
|
38
41
|
},
|
|
39
42
|
},
|
|
40
43
|
axisLabel: {
|
|
41
|
-
showMaxLabel: false,
|
|
42
44
|
padding: [8, 16, 8, 16],
|
|
43
45
|
margin: 0,
|
|
44
46
|
formatter: (value: unknown) =>
|
|
45
|
-
|
|
47
|
+
value === dates[dates.length - 1]
|
|
48
|
+
? ''
|
|
49
|
+
: formatXAxisLabel(value, isGreaterThanTwoWeeks, locale),
|
|
46
50
|
},
|
|
47
51
|
boundaryGap: false,
|
|
48
52
|
z: 2,
|
|
53
|
+
axisPointer: {
|
|
54
|
+
label: {
|
|
55
|
+
lineHeight: 22,
|
|
56
|
+
margin: -22,
|
|
57
|
+
padding: [0, 8, 0, 8],
|
|
58
|
+
formatter: (params: {
|
|
59
|
+
axisDimension?: string;
|
|
60
|
+
axisIndex?: number;
|
|
61
|
+
value: unknown;
|
|
62
|
+
}) => {
|
|
63
|
+
const date = new Date(params.value as string);
|
|
64
|
+
|
|
65
|
+
return isDesktop ? formatFullDate(date, locale) : '';
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
z: 100,
|
|
69
|
+
},
|
|
49
70
|
},
|
|
50
71
|
{
|
|
51
72
|
type: 'category',
|
|
@@ -67,6 +88,9 @@ export const getXAxisConfig = ({
|
|
|
67
88
|
formatter: (value: unknown) =>
|
|
68
89
|
formatXAxisAdditionalLabel(value, isGreaterThanTwoWeeks, locale),
|
|
69
90
|
},
|
|
91
|
+
axisPointer: {
|
|
92
|
+
show: false,
|
|
93
|
+
},
|
|
70
94
|
data: dates,
|
|
71
95
|
boundaryGap: false,
|
|
72
96
|
z: 2,
|
|
@@ -5,13 +5,13 @@ import { CHART_CONFIG } from '../../../constants';
|
|
|
5
5
|
interface GetYAxisConfigParams {
|
|
6
6
|
bucketWidth: number;
|
|
7
7
|
displayPrecision: number;
|
|
8
|
-
|
|
8
|
+
selectedPriceRef: { current: number };
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export const getYAxisConfig = ({
|
|
12
12
|
bucketWidth,
|
|
13
13
|
displayPrecision,
|
|
14
|
-
|
|
14
|
+
selectedPriceRef,
|
|
15
15
|
}: GetYAxisConfigParams): YAXisComponentOption[] => [
|
|
16
16
|
{
|
|
17
17
|
type: 'value',
|
|
@@ -35,6 +35,23 @@ export const getYAxisConfig = ({
|
|
|
35
35
|
verticalAlignMaxLabel: 'top',
|
|
36
36
|
formatter: (value: number) => value.toFixed(displayPrecision),
|
|
37
37
|
},
|
|
38
|
+
axisPointer: {
|
|
39
|
+
label: {
|
|
40
|
+
padding: [4, 4, 4, 4],
|
|
41
|
+
margin: -1,
|
|
42
|
+
formatter: (params: {
|
|
43
|
+
axisDimension?: string;
|
|
44
|
+
axisIndex?: number;
|
|
45
|
+
value: unknown;
|
|
46
|
+
}) => {
|
|
47
|
+
if (params.axisDimension === 'y' && params.axisIndex === 0) {
|
|
48
|
+
selectedPriceRef.current = Number(params.value);
|
|
49
|
+
return Number(params.value).toFixed(displayPrecision);
|
|
50
|
+
}
|
|
51
|
+
return '';
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
38
55
|
z: 30,
|
|
39
56
|
},
|
|
40
57
|
{
|
|
@@ -51,7 +68,7 @@ export const getYAxisConfig = ({
|
|
|
51
68
|
margin: 4,
|
|
52
69
|
lineHeight: 20,
|
|
53
70
|
verticalAlignMinLabel: 'bottom',
|
|
54
|
-
verticalAlignMaxLabel:
|
|
71
|
+
verticalAlignMaxLabel: 'top',
|
|
55
72
|
customValues: [
|
|
56
73
|
CHART_CONFIG.SENTIMENT_MIN,
|
|
57
74
|
CHART_CONFIG.SENTIMENT_MAX / 5,
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export const formatFullDate = (date: Date, locale: string): string => {
|
|
2
|
+
const formattedDate = date
|
|
3
|
+
.toLocaleDateString(locale, {
|
|
4
|
+
day: 'numeric',
|
|
5
|
+
month: '2-digit',
|
|
6
|
+
year: '2-digit',
|
|
7
|
+
})
|
|
8
|
+
.replace(/\//g, '.');
|
|
9
|
+
|
|
10
|
+
const formattedTime = date.toLocaleTimeString(locale, {
|
|
11
|
+
hour: 'numeric',
|
|
12
|
+
minute: '2-digit',
|
|
13
|
+
hour12: false,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const formatter = new Intl.DateTimeFormat('en-US', {
|
|
17
|
+
timeZoneName: 'shortOffset',
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const parts = formatter.formatToParts(date);
|
|
21
|
+
const timeZoneOffset = parts.find(
|
|
22
|
+
(part) => part.type === 'timeZoneName'
|
|
23
|
+
)?.value;
|
|
24
|
+
|
|
25
|
+
return `${formattedDate} ${formattedTime} ${timeZoneOffset}`;
|
|
26
|
+
};
|
|
@@ -2,18 +2,7 @@ import { colorPalette } from '@oanda/labs-widget-common';
|
|
|
2
2
|
|
|
3
3
|
import { BookType } from '../../../../gql/types/graphql';
|
|
4
4
|
import type { Bucket, TooltipParam } from '../types';
|
|
5
|
-
|
|
6
|
-
const DATE_FORMAT_OPTIONS: Intl.DateTimeFormatOptions = {
|
|
7
|
-
day: 'numeric',
|
|
8
|
-
month: 'numeric',
|
|
9
|
-
year: 'numeric',
|
|
10
|
-
|
|
11
|
-
hour: 'numeric',
|
|
12
|
-
minute: '2-digit',
|
|
13
|
-
hour12: false,
|
|
14
|
-
|
|
15
|
-
timeZoneName: 'shortOffset',
|
|
16
|
-
};
|
|
5
|
+
import { formatFullDate } from './formatFullDate';
|
|
17
6
|
|
|
18
7
|
const SENTIMENT_DISPLAY_PRECISION = 2;
|
|
19
8
|
|
|
@@ -67,7 +56,8 @@ const getSentimentOverbalanceLabel = (
|
|
|
67
56
|
|
|
68
57
|
const formatCandleData = (
|
|
69
58
|
candleData: [number, number, number, number, number],
|
|
70
|
-
labelCallback: (key: string) => string
|
|
59
|
+
labelCallback: (key: string) => string,
|
|
60
|
+
isDesktop: boolean
|
|
71
61
|
): string => {
|
|
72
62
|
const [, open, close, low, high] = candleData;
|
|
73
63
|
const candleLabel = labelCallback('candle');
|
|
@@ -76,12 +66,19 @@ const formatCandleData = (
|
|
|
76
66
|
const lowLabel = labelCallback('low');
|
|
77
67
|
const highLabel = labelCallback('high');
|
|
78
68
|
|
|
79
|
-
return
|
|
69
|
+
return isDesktop
|
|
70
|
+
? `<div><b>${candleLabel}:</b></div>
|
|
71
|
+
<div style="display: flex; gap: 4px; margin-right: 4px;">
|
|
80
72
|
<div>${openLabel}: ${open} </div>
|
|
81
73
|
<div>${closeLabel}: ${close} </div>
|
|
82
74
|
<div>${lowLabel}: ${low} </div>
|
|
83
75
|
<div>${highLabel}: ${high} </div>
|
|
84
|
-
|
|
76
|
+
</div>`
|
|
77
|
+
: `<div><b>${candleLabel}:</b></div>
|
|
78
|
+
<div>${openLabel}: ${open} </div>
|
|
79
|
+
<div>${closeLabel}: ${close} </div>
|
|
80
|
+
<div>${lowLabel}: ${low} </div>
|
|
81
|
+
<div>${highLabel}: ${high} </div>`;
|
|
85
82
|
};
|
|
86
83
|
|
|
87
84
|
const formatBookData = ({
|
|
@@ -112,8 +109,8 @@ const formatBookData = ({
|
|
|
112
109
|
|
|
113
110
|
return isDesktop
|
|
114
111
|
? `<div><b>${labelCallback(bookLabelKey)}:</b></div>
|
|
115
|
-
<
|
|
116
|
-
<
|
|
112
|
+
<span style="margin-right: 4px;">${labelCallback('price_range')}: ${priceRangeStart} - ${priceRangeEnd} </span>
|
|
113
|
+
<span style="margin-right: 4px;">${labelCallback(sentimentLabel)}: ${sentimentValue}% </span>`
|
|
117
114
|
: `<div><b>${labelCallback(bookLabelKey)}:</b></div>
|
|
118
115
|
<div>${labelCallback('price_range')}:</div>
|
|
119
116
|
<div>${priceRangeStart} - ${priceRangeEnd} </div>
|
|
@@ -124,9 +121,14 @@ const formatBookData = ({
|
|
|
124
121
|
const formatSentimentData = (
|
|
125
122
|
sentimentLong: number,
|
|
126
123
|
sentimentShort: number,
|
|
127
|
-
labelCallback: (key: string) => string
|
|
124
|
+
labelCallback: (key: string) => string,
|
|
125
|
+
isDesktop: boolean
|
|
128
126
|
): string => {
|
|
129
|
-
return
|
|
127
|
+
return isDesktop
|
|
128
|
+
? `<div><b>${labelCallback('sentiment')}:</b></div>
|
|
129
|
+
<span style="margin-right: 4px;">${labelCallback('long')}: ${sentimentLong.toFixed(SENTIMENT_DISPLAY_PRECISION)}% </span>
|
|
130
|
+
<span style="margin-right: 4px;">${labelCallback('short')}: ${sentimentShort.toFixed(SENTIMENT_DISPLAY_PRECISION)}% </span>`
|
|
131
|
+
: `<div><b>${labelCallback('sentiment')}:</b></div>
|
|
130
132
|
<div>${labelCallback('long')}: ${sentimentLong.toFixed(SENTIMENT_DISPLAY_PRECISION)}% </div>
|
|
131
133
|
<div>${labelCallback('short')}: ${sentimentShort.toFixed(SENTIMENT_DISPLAY_PRECISION)}% </div>`;
|
|
132
134
|
};
|
|
@@ -214,11 +216,9 @@ export const getTooltipFormatter = ({
|
|
|
214
216
|
return '';
|
|
215
217
|
}
|
|
216
218
|
|
|
217
|
-
const timeFormatted = time
|
|
218
|
-
.toLocaleString(locale, DATE_FORMAT_OPTIONS)
|
|
219
|
-
.replace(/\//g, '.');
|
|
219
|
+
const timeFormatted = formatFullDate(time, locale);
|
|
220
220
|
const candleSection = showCandles
|
|
221
|
-
? formatCandleData(candleData, labelCallback)
|
|
221
|
+
? formatCandleData(candleData, labelCallback, isDesktop)
|
|
222
222
|
: '';
|
|
223
223
|
|
|
224
224
|
const bookSection = matchedBucket
|
|
@@ -234,7 +234,12 @@ export const getTooltipFormatter = ({
|
|
|
234
234
|
|
|
235
235
|
const sentimentSection =
|
|
236
236
|
showSentiment && sentimentLong && sentimentShort
|
|
237
|
-
? formatSentimentData(
|
|
237
|
+
? formatSentimentData(
|
|
238
|
+
sentimentLong,
|
|
239
|
+
sentimentShort,
|
|
240
|
+
labelCallback,
|
|
241
|
+
isDesktop
|
|
242
|
+
)
|
|
238
243
|
: '';
|
|
239
244
|
|
|
240
245
|
if (isDesktop) {
|
|
@@ -243,7 +248,7 @@ export const getTooltipFormatter = ({
|
|
|
243
248
|
candleSection,
|
|
244
249
|
sentimentSection,
|
|
245
250
|
bookSection,
|
|
246
|
-
|
|
251
|
+
isDark,
|
|
247
252
|
});
|
|
248
253
|
}
|
|
249
254
|
|
|
@@ -264,20 +269,29 @@ interface TooltipSections {
|
|
|
264
269
|
}
|
|
265
270
|
|
|
266
271
|
const buildDesktopTooltip = ({
|
|
267
|
-
timeFormatted,
|
|
268
272
|
candleSection,
|
|
269
273
|
sentimentSection,
|
|
270
274
|
bookSection,
|
|
271
|
-
|
|
272
|
-
}: TooltipSections & {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
+
isDark,
|
|
276
|
+
}: TooltipSections & {
|
|
277
|
+
isDark: boolean;
|
|
278
|
+
}): string => {
|
|
279
|
+
const backgroundColor = isDark ? colorPalette.black : colorPalette.white;
|
|
280
|
+
const fullWidth = TOOLTIP_STYLES.FULL_WIDTH;
|
|
275
281
|
|
|
276
|
-
return `<div style="
|
|
277
|
-
<div style="
|
|
278
|
-
<div style="
|
|
279
|
-
|
|
280
|
-
|
|
282
|
+
return `<div style="width: ${fullWidth}; background-color: ${backgroundColor};">
|
|
283
|
+
<div style="width: ${fullWidth}; display: flex; justify-content: space-between;">
|
|
284
|
+
<div style="width: 40%;">
|
|
285
|
+
${candleSection}
|
|
286
|
+
</div>
|
|
287
|
+
<div style="width: 22%;">
|
|
288
|
+
${sentimentSection}
|
|
289
|
+
</div>
|
|
290
|
+
<div style="width: 38%;">
|
|
291
|
+
${bookSection}
|
|
292
|
+
</div>
|
|
293
|
+
</div>
|
|
294
|
+
</div>`;
|
|
281
295
|
};
|
|
282
296
|
|
|
283
297
|
const buildMobileTooltip = ({
|
|
@@ -89,7 +89,6 @@ export const getOption: GetOptionType = ({
|
|
|
89
89
|
bookType,
|
|
90
90
|
bucketWidth,
|
|
91
91
|
buckets,
|
|
92
|
-
displayPrecision,
|
|
93
92
|
labelCallback,
|
|
94
93
|
selectedPriceRef,
|
|
95
94
|
tooltipLinesColor: styles.tooltipLinesColor,
|
|
@@ -104,11 +103,12 @@ export const getOption: GetOptionType = ({
|
|
|
104
103
|
dates,
|
|
105
104
|
isGreaterThanTwoWeeks,
|
|
106
105
|
locale,
|
|
106
|
+
isDesktop,
|
|
107
107
|
}),
|
|
108
108
|
yAxis: getYAxisConfig({
|
|
109
|
-
isDesktop,
|
|
110
109
|
bucketWidth,
|
|
111
110
|
displayPrecision,
|
|
111
|
+
selectedPriceRef,
|
|
112
112
|
}),
|
|
113
113
|
dataZoom: getDataZoomConfig({ isDesktop }),
|
|
114
114
|
visualMap: getVisualMapConfig({
|
|
@@ -32,22 +32,24 @@ const CHART_CONFIG_STATIC = {
|
|
|
32
32
|
X_AXIS_DATE_PADDING: ' ',
|
|
33
33
|
SENTIMENT_MIN: 0,
|
|
34
34
|
SENTIMENT_MAX: 100,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
TOP_LABEL_SPACE_DESKTOP: 0,
|
|
36
|
+
TOP_LABEL_SPACE_MOBILE: 24,
|
|
37
|
+
TOOLTIP_HEIGHT_MOBILE: 85,
|
|
38
|
+
TOOLTIP_HEIGHT_DESKTOP: 46,
|
|
38
39
|
TOOLTIP_OFFSET: 8,
|
|
39
40
|
};
|
|
40
41
|
|
|
41
42
|
const CHART_CONFIG_CALCULATED = {
|
|
42
43
|
HEIGHT_DESKTOP:
|
|
43
44
|
CHART_CONFIG_STATIC.MAIN_HEIGHT_DESKTOP +
|
|
44
|
-
CHART_CONFIG_STATIC.
|
|
45
|
-
CHART_CONFIG_STATIC.X_LABEL_SIZE
|
|
45
|
+
CHART_CONFIG_STATIC.TOP_LABEL_SPACE_DESKTOP +
|
|
46
|
+
CHART_CONFIG_STATIC.X_LABEL_SIZE +
|
|
47
|
+
CHART_CONFIG_STATIC.TOOLTIP_HEIGHT_DESKTOP,
|
|
46
48
|
HEIGHT_MOBILE:
|
|
47
49
|
CHART_CONFIG_STATIC.MAIN_HEIGHT_MOBILE +
|
|
48
50
|
CHART_CONFIG_STATIC.X_LABEL_SIZE +
|
|
49
|
-
CHART_CONFIG_STATIC.
|
|
50
|
-
CHART_CONFIG_STATIC.
|
|
51
|
+
CHART_CONFIG_STATIC.TOP_LABEL_SPACE_MOBILE +
|
|
52
|
+
CHART_CONFIG_STATIC.TOOLTIP_HEIGHT_MOBILE,
|
|
51
53
|
};
|
|
52
54
|
export const CHART_CONFIG = {
|
|
53
55
|
...CHART_CONFIG_STATIC,
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"sentiment": "Sentiment",
|
|
30
30
|
"short": "Short",
|
|
31
31
|
"short_overbalance": "Short overbalance",
|
|
32
|
-
"tap_chart_to_see_more_details": "Tap chart to see more details",
|
|
32
|
+
"tap_chart_to_see_more_details": "Tap the chart to see more details",
|
|
33
|
+
"hover_chart_to_see_more_details": "Hover over the chart to see more details",
|
|
33
34
|
"trades": "Trades"
|
|
34
35
|
}
|