@oanda/labs-crowd-view-widget 1.0.54 → 1.0.55

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 (168) hide show
  1. package/CHANGELOG.md +224 -0
  2. package/dist/main/CrowdViewWidget/components/Chart/Chart.js +37 -56
  3. package/dist/main/CrowdViewWidget/components/Chart/Chart.js.map +1 -1
  4. package/dist/main/CrowdViewWidget/components/Chart/ChartWithData.js +20 -7
  5. package/dist/main/CrowdViewWidget/components/Chart/ChartWithData.js.map +1 -1
  6. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getDataZoomConfig.js +15 -9
  7. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getDataZoomConfig.js.map +1 -1
  8. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getGridConfig.js +6 -6
  9. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getGridConfig.js.map +1 -1
  10. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getGridLines.js +41 -13
  11. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getGridLines.js.map +1 -1
  12. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getLabelsConfig.js +159 -0
  13. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getLabelsConfig.js.map +1 -0
  14. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getSeriesCandlestickConfig.js +7 -14
  15. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getSeriesCandlestickConfig.js.map +1 -1
  16. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getSeriesHeatmapConfig.js +20 -2
  17. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getSeriesHeatmapConfig.js.map +1 -1
  18. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getSeriesSentimentConfig.js +13 -5
  19. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getSeriesSentimentConfig.js.map +1 -1
  20. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getTooltipConfig.js +10 -3
  21. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getTooltipConfig.js.map +1 -1
  22. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getXAxisConfig.js +20 -5
  23. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getXAxisConfig.js.map +1 -1
  24. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getYAxisConfig.js +19 -28
  25. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getYAxisConfig.js.map +1 -1
  26. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/index.js +11 -0
  27. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/index.js.map +1 -1
  28. package/dist/main/CrowdViewWidget/components/Chart/chartUtils/formatXAxisAdditionalLabel.js +18 -0
  29. package/dist/main/CrowdViewWidget/components/Chart/chartUtils/formatXAxisAdditionalLabel.js.map +1 -0
  30. package/dist/main/CrowdViewWidget/components/Chart/chartUtils/getLabelData.js +1 -20
  31. package/dist/main/CrowdViewWidget/components/Chart/chartUtils/getLabelData.js.map +1 -1
  32. package/dist/main/CrowdViewWidget/components/Chart/chartUtils/getTooltipFormatter.js +21 -9
  33. package/dist/main/CrowdViewWidget/components/Chart/chartUtils/getTooltipFormatter.js.map +1 -1
  34. package/dist/main/CrowdViewWidget/components/Chart/chartUtils/handleLabelUpdate.js +59 -0
  35. package/dist/main/CrowdViewWidget/components/Chart/chartUtils/handleLabelUpdate.js.map +1 -0
  36. package/dist/main/CrowdViewWidget/components/Chart/chartUtils/handleTooltipUpdate.js +34 -0
  37. package/dist/main/CrowdViewWidget/components/Chart/chartUtils/handleTooltipUpdate.js.map +1 -0
  38. package/dist/main/CrowdViewWidget/components/Chart/chartUtils/index.js +33 -0
  39. package/dist/main/CrowdViewWidget/components/Chart/chartUtils/index.js.map +1 -1
  40. package/dist/main/CrowdViewWidget/components/Chart/dataUtils/getMultiplayerForTimeSpan.js +19 -0
  41. package/dist/main/CrowdViewWidget/components/Chart/dataUtils/getMultiplayerForTimeSpan.js.map +1 -0
  42. package/dist/main/CrowdViewWidget/components/Chart/dataUtils/index.js +11 -0
  43. package/dist/main/CrowdViewWidget/components/Chart/dataUtils/index.js.map +1 -1
  44. package/dist/main/CrowdViewWidget/components/Chart/getOption.js +33 -21
  45. package/dist/main/CrowdViewWidget/components/Chart/getOption.js.map +1 -1
  46. package/dist/main/CrowdViewWidget/components/Chart/types.js.map +1 -1
  47. package/dist/main/CrowdViewWidget/components/Chart/useCrowdViewData.js +7 -4
  48. package/dist/main/CrowdViewWidget/components/Chart/useCrowdViewData.js.map +1 -1
  49. package/dist/main/CrowdViewWidget/components/Legend/Legend.js +1 -1
  50. package/dist/main/CrowdViewWidget/components/Legend/Legend.js.map +1 -1
  51. package/dist/main/CrowdViewWidget/components/Legend/LegendBar.js +11 -1
  52. package/dist/main/CrowdViewWidget/components/Legend/LegendBar.js.map +1 -1
  53. package/dist/main/CrowdViewWidget/constants.js +13 -5
  54. package/dist/main/CrowdViewWidget/constants.js.map +1 -1
  55. package/dist/main/CrowdViewWidget/selectConfig.js +0 -6
  56. package/dist/main/CrowdViewWidget/selectConfig.js.map +1 -1
  57. package/dist/main/translations/sources/en.json +2 -1
  58. package/dist/module/CrowdViewWidget/components/Chart/Chart.js +38 -56
  59. package/dist/module/CrowdViewWidget/components/Chart/Chart.js.map +1 -1
  60. package/dist/module/CrowdViewWidget/components/Chart/ChartWithData.js +19 -6
  61. package/dist/module/CrowdViewWidget/components/Chart/ChartWithData.js.map +1 -1
  62. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getDataZoomConfig.js +15 -9
  63. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getDataZoomConfig.js.map +1 -1
  64. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getGridConfig.js +6 -6
  65. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getGridConfig.js.map +1 -1
  66. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getGridLines.js +41 -13
  67. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getGridLines.js.map +1 -1
  68. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getLabelsConfig.js +151 -0
  69. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getLabelsConfig.js.map +1 -0
  70. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getSeriesCandlestickConfig.js +7 -14
  71. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getSeriesCandlestickConfig.js.map +1 -1
  72. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getSeriesHeatmapConfig.js +20 -2
  73. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getSeriesHeatmapConfig.js.map +1 -1
  74. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getSeriesSentimentConfig.js +13 -5
  75. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getSeriesSentimentConfig.js.map +1 -1
  76. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getTooltipConfig.js +10 -3
  77. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getTooltipConfig.js.map +1 -1
  78. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getXAxisConfig.js +21 -6
  79. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getXAxisConfig.js.map +1 -1
  80. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getYAxisConfig.js +19 -28
  81. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getYAxisConfig.js.map +1 -1
  82. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/index.js +1 -0
  83. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/index.js.map +1 -1
  84. package/dist/module/CrowdViewWidget/components/Chart/chartUtils/formatXAxisAdditionalLabel.js +11 -0
  85. package/dist/module/CrowdViewWidget/components/Chart/chartUtils/formatXAxisAdditionalLabel.js.map +1 -0
  86. package/dist/module/CrowdViewWidget/components/Chart/chartUtils/getLabelData.js +1 -20
  87. package/dist/module/CrowdViewWidget/components/Chart/chartUtils/getLabelData.js.map +1 -1
  88. package/dist/module/CrowdViewWidget/components/Chart/chartUtils/getTooltipFormatter.js +21 -9
  89. package/dist/module/CrowdViewWidget/components/Chart/chartUtils/getTooltipFormatter.js.map +1 -1
  90. package/dist/module/CrowdViewWidget/components/Chart/chartUtils/handleLabelUpdate.js +52 -0
  91. package/dist/module/CrowdViewWidget/components/Chart/chartUtils/handleLabelUpdate.js.map +1 -0
  92. package/dist/module/CrowdViewWidget/components/Chart/chartUtils/handleTooltipUpdate.js +27 -0
  93. package/dist/module/CrowdViewWidget/components/Chart/chartUtils/handleTooltipUpdate.js.map +1 -0
  94. package/dist/module/CrowdViewWidget/components/Chart/chartUtils/index.js +3 -0
  95. package/dist/module/CrowdViewWidget/components/Chart/chartUtils/index.js.map +1 -1
  96. package/dist/module/CrowdViewWidget/components/Chart/dataUtils/getMultiplayerForTimeSpan.js +12 -0
  97. package/dist/module/CrowdViewWidget/components/Chart/dataUtils/getMultiplayerForTimeSpan.js.map +1 -0
  98. package/dist/module/CrowdViewWidget/components/Chart/dataUtils/index.js +1 -0
  99. package/dist/module/CrowdViewWidget/components/Chart/dataUtils/index.js.map +1 -1
  100. package/dist/module/CrowdViewWidget/components/Chart/getOption.js +34 -22
  101. package/dist/module/CrowdViewWidget/components/Chart/getOption.js.map +1 -1
  102. package/dist/module/CrowdViewWidget/components/Chart/types.js.map +1 -1
  103. package/dist/module/CrowdViewWidget/components/Chart/useCrowdViewData.js +8 -5
  104. package/dist/module/CrowdViewWidget/components/Chart/useCrowdViewData.js.map +1 -1
  105. package/dist/module/CrowdViewWidget/components/Legend/Legend.js +1 -1
  106. package/dist/module/CrowdViewWidget/components/Legend/Legend.js.map +1 -1
  107. package/dist/module/CrowdViewWidget/components/Legend/LegendBar.js +11 -1
  108. package/dist/module/CrowdViewWidget/components/Legend/LegendBar.js.map +1 -1
  109. package/dist/module/CrowdViewWidget/constants.js +13 -5
  110. package/dist/module/CrowdViewWidget/constants.js.map +1 -1
  111. package/dist/module/CrowdViewWidget/selectConfig.js +0 -6
  112. package/dist/module/CrowdViewWidget/selectConfig.js.map +1 -1
  113. package/dist/module/translations/sources/en.json +2 -1
  114. package/dist/types/CrowdViewWidget/components/Chart/Chart.d.ts +1 -1
  115. package/dist/types/CrowdViewWidget/components/Chart/chartOptions/getDataZoomConfig.d.ts +5 -1
  116. package/dist/types/CrowdViewWidget/components/Chart/chartOptions/getGridLines.d.ts +2 -1
  117. package/dist/types/CrowdViewWidget/components/Chart/chartOptions/getLabelsConfig.d.ts +8 -0
  118. package/dist/types/CrowdViewWidget/components/Chart/chartOptions/getSeriesCandlestickConfig.d.ts +2 -3
  119. package/dist/types/CrowdViewWidget/components/Chart/chartOptions/getSeriesHeatmapConfig.d.ts +2 -1
  120. package/dist/types/CrowdViewWidget/components/Chart/chartOptions/getSeriesSentimentConfig.d.ts +2 -1
  121. package/dist/types/CrowdViewWidget/components/Chart/chartOptions/getTooltipConfig.d.ts +3 -1
  122. package/dist/types/CrowdViewWidget/components/Chart/chartOptions/getYAxisConfig.d.ts +1 -3
  123. package/dist/types/CrowdViewWidget/components/Chart/chartOptions/index.d.ts +1 -0
  124. package/dist/types/CrowdViewWidget/components/Chart/chartUtils/formatXAxisAdditionalLabel.d.ts +1 -0
  125. package/dist/types/CrowdViewWidget/components/Chart/chartUtils/getLabelData.d.ts +1 -16
  126. package/dist/types/CrowdViewWidget/components/Chart/chartUtils/getTooltipFormatter.d.ts +3 -1
  127. package/dist/types/CrowdViewWidget/components/Chart/chartUtils/handleLabelUpdate.d.ts +4 -0
  128. package/dist/types/CrowdViewWidget/components/Chart/chartUtils/handleTooltipUpdate.d.ts +3 -0
  129. package/dist/types/CrowdViewWidget/components/Chart/chartUtils/index.d.ts +3 -0
  130. package/dist/types/CrowdViewWidget/components/Chart/dataUtils/getMultiplayerForTimeSpan.d.ts +2 -0
  131. package/dist/types/CrowdViewWidget/components/Chart/dataUtils/index.d.ts +1 -0
  132. package/dist/types/CrowdViewWidget/components/Chart/types.d.ts +5 -0
  133. package/dist/types/CrowdViewWidget/constants.d.ts +12 -4
  134. package/package.json +3 -3
  135. package/src/CrowdViewWidget/components/Chart/Chart.tsx +70 -79
  136. package/src/CrowdViewWidget/components/Chart/ChartWithData.tsx +31 -13
  137. package/src/CrowdViewWidget/components/Chart/chartOptions/getDataZoomConfig.ts +11 -2
  138. package/src/CrowdViewWidget/components/Chart/chartOptions/getGridConfig.ts +6 -6
  139. package/src/CrowdViewWidget/components/Chart/chartOptions/getGridLines.ts +48 -6
  140. package/src/CrowdViewWidget/components/Chart/chartOptions/getLabelsConfig.ts +191 -0
  141. package/src/CrowdViewWidget/components/Chart/chartOptions/getSeriesCandlestickConfig.ts +7 -15
  142. package/src/CrowdViewWidget/components/Chart/chartOptions/getSeriesHeatmapConfig.ts +22 -1
  143. package/src/CrowdViewWidget/components/Chart/chartOptions/getSeriesSentimentConfig.ts +13 -4
  144. package/src/CrowdViewWidget/components/Chart/chartOptions/getTooltipConfig.ts +12 -1
  145. package/src/CrowdViewWidget/components/Chart/chartOptions/getXAxisConfig.ts +55 -30
  146. package/src/CrowdViewWidget/components/Chart/chartOptions/getYAxisConfig.ts +13 -30
  147. package/src/CrowdViewWidget/components/Chart/chartOptions/index.ts +1 -0
  148. package/src/CrowdViewWidget/components/Chart/chartUtils/formatXAxisAdditionalLabel.ts +13 -0
  149. package/src/CrowdViewWidget/components/Chart/chartUtils/getLabelData.ts +11 -35
  150. package/src/CrowdViewWidget/components/Chart/chartUtils/getTooltipFormatter.ts +40 -11
  151. package/src/CrowdViewWidget/components/Chart/chartUtils/handleLabelUpdate.ts +75 -0
  152. package/src/CrowdViewWidget/components/Chart/chartUtils/handleTooltipUpdate.ts +37 -0
  153. package/src/CrowdViewWidget/components/Chart/chartUtils/index.ts +3 -0
  154. package/src/CrowdViewWidget/components/Chart/dataUtils/getMultiplayerForTimeSpan.ts +13 -0
  155. package/src/CrowdViewWidget/components/Chart/dataUtils/index.ts +1 -0
  156. package/src/CrowdViewWidget/components/Chart/getOption.ts +41 -17
  157. package/src/CrowdViewWidget/components/Chart/types.ts +5 -0
  158. package/src/CrowdViewWidget/components/Chart/useCrowdViewData.ts +12 -5
  159. package/src/CrowdViewWidget/components/Legend/Legend.tsx +1 -1
  160. package/src/CrowdViewWidget/components/Legend/LegendBar.tsx +17 -1
  161. package/src/CrowdViewWidget/constants.ts +12 -4
  162. package/src/CrowdViewWidget/selectConfig.ts +0 -8
  163. package/src/translations/sources/en.json +2 -1
  164. package/test/components/Chart/utils/chartUtils.test.ts +13 -2
  165. package/test/components/Chart/utils/handleLabelUpdate.test.ts +419 -0
  166. package/test/components/Chart/utils/handleTooltipUpdate.test.ts +140 -0
  167. package/test/components/Legend.test.tsx +3 -3
  168. package/test/components/LegendBar.test.tsx +22 -20
@@ -1,6 +1,10 @@
1
1
  import type { XAXisComponentOption } from 'echarts';
2
2
 
3
- import { formatXAxisLabel } from '../chartUtils';
3
+ import {
4
+ formatXAxisAdditionalLabel,
5
+ formatXAxisLabel,
6
+ getLabelData,
7
+ } from '../chartUtils';
4
8
 
5
9
  interface GetXAxisConfigParams {
6
10
  dates: string[];
@@ -10,34 +14,55 @@ interface GetXAxisConfigParams {
10
14
  export const getXAxisConfig = ({
11
15
  dates,
12
16
  isGreaterThanTwoWeeks,
13
- }: GetXAxisConfigParams): XAXisComponentOption[] => [
14
- {
15
- type: 'category',
16
- id: 'main-xAxis',
17
- name: 'xAxis-less-than-two-weeks',
18
- nameTextStyle: {
19
- fontSize: 0,
20
- },
21
- axisTick: {
22
- show: false,
23
- },
24
- axisLabel: {
25
- padding: [8, 16, 8, 16],
26
- margin: 0,
27
- formatter: (value: unknown) =>
28
- formatXAxisLabel(value, isGreaterThanTwoWeeks),
29
- },
30
- },
31
- {
32
- type: 'category',
33
- gridIndex: 1,
34
- show: false,
35
- axisTick: {
36
- show: false,
17
+ }: GetXAxisConfigParams): XAXisComponentOption[] => {
18
+ const labelsData = getLabelData({
19
+ dates,
20
+ isGreaterThanTwoWeeks,
21
+ });
22
+
23
+ return [
24
+ {
25
+ type: 'category',
26
+ id: 'main-xAxis',
27
+ name: isGreaterThanTwoWeeks
28
+ ? 'xAxis-greater-than-two-weeks'
29
+ : 'xAxis-less-than-two-weeks',
30
+ nameTextStyle: {
31
+ fontSize: 0,
32
+ },
33
+ axisTick: {
34
+ show: false,
35
+ },
36
+ axisLabel: {
37
+ padding: [8, 16, 8, 16],
38
+ margin: 0,
39
+ formatter: (value: unknown) =>
40
+ formatXAxisLabel(value, isGreaterThanTwoWeeks),
41
+ },
42
+ boundaryGap: false,
37
43
  },
38
- axisLabel: {
39
- show: false,
44
+ {
45
+ type: 'category',
46
+ id: 'additional-xAxis',
47
+ gridIndex: 1,
48
+ axisTick: {
49
+ show: false,
50
+ },
51
+ axisLine: {
52
+ show: false,
53
+ },
54
+ splitLine: {
55
+ show: false,
56
+ },
57
+ axisLabel: {
58
+ margin: 24,
59
+ hideOverlap: true,
60
+ customValues: labelsData,
61
+ formatter: (value: unknown) =>
62
+ formatXAxisAdditionalLabel(value, isGreaterThanTwoWeeks),
63
+ },
64
+ data: dates,
65
+ boundaryGap: false,
40
66
  },
41
- data: dates,
42
- },
43
- ];
67
+ ];
68
+ };
@@ -5,15 +5,11 @@ import { BUCKET_CONFIG, CHART_CONFIG } from '../../../constants';
5
5
  interface GetYAxisConfigParams {
6
6
  bucketWidth: number;
7
7
  displayPrecision: number;
8
- isDesktop: boolean;
9
- labelCallback: (key: string, params?: Record<string, unknown>) => string;
10
8
  }
11
9
 
12
10
  export const getYAxisConfig = ({
13
11
  bucketWidth,
14
12
  displayPrecision,
15
- isDesktop,
16
- labelCallback,
17
13
  }: GetYAxisConfigParams): YAXisComponentOption[] => [
18
14
  {
19
15
  type: 'value',
@@ -25,11 +21,15 @@ export const getYAxisConfig = ({
25
21
  val.max + bucketWidth * BUCKET_CONFIG.PRICE_MARGIN_MULTIPLIER,
26
22
  axisLine: { show: false },
27
23
  axisTick: { show: false },
24
+ splitLine: { show: false },
28
25
  axisLabel: {
29
- showMinLabel: false,
30
- showMaxLabel: false,
31
- formatter: (value: number) => value.toFixed(displayPrecision - 1),
26
+ lineHeight: 20,
27
+ margin: 4,
28
+ verticalAlignMinLabel: 'bottom',
29
+ verticalAlignMaxLabel: 'top',
30
+ formatter: (value: number) => value.toFixed(displayPrecision),
32
31
  },
32
+ z: 30,
33
33
  },
34
34
  {
35
35
  type: 'value',
@@ -39,14 +39,13 @@ export const getYAxisConfig = ({
39
39
  max: CHART_CONFIG.SENTIMENT_MAX,
40
40
  axisLine: { show: false },
41
41
  axisTick: { show: false },
42
- axisPointer: {
43
- show: false,
44
- },
42
+ axisPointer: { show: false },
43
+ splitLine: { show: false },
45
44
  axisLabel: {
46
- margin: isDesktop ? 4 : 2,
45
+ margin: 4,
47
46
  lineHeight: 20,
48
47
  verticalAlignMinLabel: 'bottom',
49
- verticalAlignMaxLabel: 'top',
48
+ verticalAlignMaxLabel: 'middle',
50
49
  customValues: [
51
50
  CHART_CONFIG.SENTIMENT_MIN,
52
51
  CHART_CONFIG.SENTIMENT_MAX / 5,
@@ -54,24 +53,8 @@ export const getYAxisConfig = ({
54
53
  (CHART_CONFIG.SENTIMENT_MAX * 4) / 5,
55
54
  CHART_CONFIG.SENTIMENT_MAX,
56
55
  ],
57
- formatter: (value: number) => {
58
- if (value === CHART_CONFIG.SENTIMENT_MIN) {
59
- return `${labelCallback('short')}`;
60
- }
61
- if (value === CHART_CONFIG.SENTIMENT_MAX) {
62
- return `${labelCallback('long')}`;
63
- }
64
- if (value === CHART_CONFIG.SENTIMENT_MAX / 2) {
65
- return '50%';
66
- }
67
- if (value === CHART_CONFIG.SENTIMENT_MAX / 5) {
68
- return '80%';
69
- }
70
- if (value === (CHART_CONFIG.SENTIMENT_MAX * 4) / 5) {
71
- return '20%';
72
- }
73
- return '';
74
- },
56
+ formatter: (value: number) => `${value}%`,
75
57
  },
58
+ z: 30,
76
59
  },
77
60
  ];
@@ -1,6 +1,7 @@
1
1
  export * from './getDataZoomConfig';
2
2
  export * from './getGridConfig';
3
3
  export * from './getGridLines';
4
+ export * from './getLabelsConfig';
4
5
  export * from './getSeriesCandlestickConfig';
5
6
  export * from './getSeriesHeatmapConfig';
6
7
  export * from './getSeriesSentimentConfig';
@@ -0,0 +1,13 @@
1
+ export const formatXAxisAdditionalLabel = (
2
+ value: unknown,
3
+ isGreaterThanTwoWeeks: boolean
4
+ ) => {
5
+ const date = new Date(value as string);
6
+ if (isNaN(date.getTime())) {
7
+ return '';
8
+ }
9
+ return `${date.toLocaleDateString(undefined, {
10
+ month: isGreaterThanTwoWeeks ? 'short' : 'long',
11
+ day: isGreaterThanTwoWeeks ? 'numeric' : undefined,
12
+ })}`;
13
+ };
@@ -1,42 +1,18 @@
1
- import { CHART_CONFIG } from '../../../constants';
2
1
  import type { GetLabelsDataProps } from '../types';
3
2
 
4
3
  export const getLabelData = ({
5
4
  dates,
6
5
  isGreaterThanTwoWeeks,
7
6
  }: GetLabelsDataProps) =>
8
- dates
9
- .filter((record, index, arr) => {
10
- if (index === 0) {
11
- return false;
12
- }
13
- const previousTimestamp = arr[index - 1];
14
- const currentDate = new Date(record);
15
- const previousDate = new Date(previousTimestamp);
7
+ dates.filter((record, index, arr) => {
8
+ if (index === 0) {
9
+ return false;
10
+ }
11
+ const previousTimestamp = arr[index - 1];
12
+ const currentDate = new Date(record);
13
+ const previousDate = new Date(previousTimestamp);
16
14
 
17
- return isGreaterThanTwoWeeks
18
- ? currentDate.getDate() !== previousDate.getDate()
19
- : currentDate.getMonth() !== previousDate.getMonth();
20
- })
21
- .map(
22
- (item) =>
23
- ({
24
- name: new Date(item).toLocaleDateString(undefined, {
25
- month: isGreaterThanTwoWeeks ? 'short' : 'long',
26
- day: isGreaterThanTwoWeeks ? 'numeric' : undefined,
27
- }),
28
- xAxis: item,
29
- y: CHART_CONFIG.MAIN_HEIGHT + CHART_CONFIG.X_LABEL_SIZE - 22,
30
- silent: true,
31
- emphasis: {
32
- disabled: true,
33
- },
34
- label: {
35
- fontFamily: 'Sofia W03',
36
- fontSize: 10,
37
- position: 'bottom' as const,
38
- align: 'center' as const,
39
- formatter: '{b}',
40
- },
41
- }) as const
42
- );
15
+ return isGreaterThanTwoWeeks
16
+ ? currentDate.getDate() !== previousDate.getDate()
17
+ : currentDate.getMonth() !== previousDate.getMonth();
18
+ });
@@ -26,6 +26,22 @@ const findSeriesParam = <T extends TooltipParam['seriesId']>(
26
26
  );
27
27
  };
28
28
 
29
+ const findSentimentSeriesParam = (
30
+ params: TooltipParam[],
31
+ sentimentLongs: (number | null)[],
32
+ sentimentShorts: (number | null)[]
33
+ ): {
34
+ sentimentLong: number | null;
35
+ sentimentShort: number | null;
36
+ } => {
37
+ const index = params[0].dataIndex as number;
38
+
39
+ return {
40
+ sentimentLong: sentimentLongs[index] ?? null,
41
+ sentimentShort: sentimentShorts[index] ?? null,
42
+ };
43
+ };
44
+
29
45
  const getSentimentOverbalanceLabel = (
30
46
  sentiment: number,
31
47
  bookType: BookType
@@ -83,22 +99,25 @@ const formatBookData = ({
83
99
  };
84
100
 
85
101
  const formatSentimentData = (
86
- sentimentParam: Extract<TooltipParam, { seriesId: 'sentiment' }>,
102
+ sentimentLong: number,
103
+ sentimentShort: number,
87
104
  labelCallback: (key: string) => string
88
105
  ): string => {
89
- const [, shortPercent, longPercent] = sentimentParam.value;
90
106
  return `<br /><p><b>${labelCallback('sentiment')}:</b></p>
91
- <p>${labelCallback('long')}: ${longPercent.toFixed(SENTIMENT_DISPLAY_PRECISION)}% </p>
92
- <p>${labelCallback('short')}: ${shortPercent.toFixed(SENTIMENT_DISPLAY_PRECISION)}% </p>`;
107
+ <p>${labelCallback('long')}: ${sentimentLong.toFixed(SENTIMENT_DISPLAY_PRECISION)}% </p>
108
+ <p>${labelCallback('short')}: ${sentimentShort.toFixed(SENTIMENT_DISPLAY_PRECISION)}% </p>`;
93
109
  };
94
110
 
95
111
  const hasValidCandleData = (
96
112
  candleData: [number, number, number, number, number]
97
113
  ): boolean =>
98
- !!candleData[1] && !!candleData[2] && !!candleData[3] && !!candleData[3];
114
+ !!candleData[1] && !!candleData[2] && !!candleData[3] && !!candleData[4];
115
+
99
116
  const hasValidSentimentData = (
100
- sentimentParam: Extract<TooltipParam, { seriesId: 'sentiment' }> | undefined
101
- ): boolean => !!sentimentParam?.value[1] && !!sentimentParam?.value[2];
117
+ sentimentLong: number | null,
118
+ sentimentShort: number | null
119
+ ): boolean => sentimentLong !== null && sentimentShort !== null;
120
+
102
121
  const findMatchingBucket = (
103
122
  buckets: Bucket[][],
104
123
  bucketsIndex: number | undefined,
@@ -121,6 +140,8 @@ export const getTooltipFormatter = ({
121
140
  selectedPrice,
122
141
  bookType,
123
142
  labelCallback,
143
+ sentimentLongs,
144
+ sentimentShorts,
124
145
  }: {
125
146
  params: TooltipParam[];
126
147
  buckets: Bucket[][];
@@ -128,6 +149,8 @@ export const getTooltipFormatter = ({
128
149
  selectedPrice: number;
129
150
  bookType: BookType;
130
151
  labelCallback: (key: string) => string;
152
+ sentimentLongs: (number | null)[];
153
+ sentimentShorts: (number | null)[];
131
154
  }) => {
132
155
  if (!params || !Array.isArray(params) || params.length === 0) {
133
156
  return '';
@@ -135,7 +158,11 @@ export const getTooltipFormatter = ({
135
158
 
136
159
  const candleParam = findSeriesParam(params, 'candlestick');
137
160
  const booksParam = findSeriesParam(params, 'heatmap');
138
- const sentimentParam = findSeriesParam(params, 'sentiment');
161
+ const { sentimentLong, sentimentShort } = findSentimentSeriesParam(
162
+ params,
163
+ sentimentLongs,
164
+ sentimentShorts
165
+ );
139
166
 
140
167
  if (!candleParam) {
141
168
  return '';
@@ -152,7 +179,7 @@ export const getTooltipFormatter = ({
152
179
  bucketWidth
153
180
  );
154
181
  const showCandles = hasValidCandleData(candleData);
155
- const showSentiment = hasValidSentimentData(sentimentParam);
182
+ const showSentiment = hasValidSentimentData(sentimentLong, sentimentShort);
156
183
 
157
184
  if (!showCandles && !matchedBucket) {
158
185
  return '';
@@ -162,6 +189,7 @@ export const getTooltipFormatter = ({
162
189
  const candleSection = showCandles
163
190
  ? formatCandleData(candleData, labelCallback)
164
191
  : '';
192
+
165
193
  const bookSection = matchedBucket
166
194
  ? formatBookData({
167
195
  matchedBucket,
@@ -171,9 +199,10 @@ export const getTooltipFormatter = ({
171
199
  labelCallback,
172
200
  })
173
201
  : '';
202
+
174
203
  const sentimentSection =
175
- showSentiment && sentimentParam
176
- ? formatSentimentData(sentimentParam, labelCallback)
204
+ showSentiment && sentimentLong && sentimentShort
205
+ ? formatSentimentData(sentimentLong, sentimentShort, labelCallback)
177
206
  : '';
178
207
 
179
208
  return `<p>${timeFormatted}</p><br />
@@ -0,0 +1,75 @@
1
+ import type { EChartsType } from 'echarts';
2
+ import type { MutableRefObject } from 'react';
3
+
4
+ import type { ChartProps, DataZoomArray } from '../types';
5
+ import { formatXAxisAdditionalLabel } from './formatXAxisAdditionalLabel';
6
+ import { formatXAxisLabel } from './formatXAxisLabel';
7
+ import { getLabelData } from './getLabelData';
8
+ import { isDifferenceGreaterThanTwoWeeks } from './isDifferenceGreaterThanTwoWeeks';
9
+
10
+ export const handleLabelUpdate = (
11
+ instance: EChartsType,
12
+ mainData: ChartProps['mainData'],
13
+ labelTimerRef: MutableRefObject<NodeJS.Timeout | null>,
14
+ isGreaterThanTwoWeeksRef: MutableRefObject<boolean | null>
15
+ ): void => {
16
+ if (labelTimerRef.current) {
17
+ clearTimeout(labelTimerRef.current);
18
+ }
19
+ labelTimerRef.current = setTimeout(() => {
20
+ const { dates } = mainData;
21
+
22
+ const { dataZoom } = instance.getOption();
23
+ if (
24
+ !Array.isArray(dataZoom) ||
25
+ dataZoom.length === 0 ||
26
+ !dataZoom[0] ||
27
+ typeof dataZoom[0].startValue !== 'number' ||
28
+ typeof dataZoom[0].endValue !== 'number'
29
+ ) {
30
+ return;
31
+ }
32
+
33
+ const { startValue, endValue } = dataZoom[0] as DataZoomArray[0];
34
+
35
+ if (!dates[startValue] || !dates[endValue]) {
36
+ return;
37
+ }
38
+
39
+ const isGreaterThanTwoWeeks = isDifferenceGreaterThanTwoWeeks(
40
+ dates[startValue],
41
+ dates[endValue]
42
+ );
43
+
44
+ const wasGreaterThanTwoWeeks = isGreaterThanTwoWeeksRef.current ?? false;
45
+
46
+ if (isGreaterThanTwoWeeks !== wasGreaterThanTwoWeeks) {
47
+ const labelsData = getLabelData({
48
+ dates,
49
+ isGreaterThanTwoWeeks,
50
+ });
51
+
52
+ instance.setOption({
53
+ xAxis: [
54
+ {
55
+ id: 'main-xAxis',
56
+ axisLabel: {
57
+ formatter: (value: string) =>
58
+ formatXAxisLabel(value, isGreaterThanTwoWeeks),
59
+ },
60
+ },
61
+ {
62
+ id: 'additional-xAxis',
63
+ axisLabel: {
64
+ customValues: labelsData,
65
+ formatter: (value: unknown) =>
66
+ formatXAxisAdditionalLabel(value, isGreaterThanTwoWeeks),
67
+ },
68
+ },
69
+ ],
70
+ });
71
+
72
+ isGreaterThanTwoWeeksRef.current = isGreaterThanTwoWeeks;
73
+ }
74
+ }, 50);
75
+ };
@@ -0,0 +1,37 @@
1
+ import type { EChartsType } from 'echarts';
2
+ import type { MutableRefObject } from 'react';
3
+
4
+ export const handleTooltipUpdate = (
5
+ instance: EChartsType,
6
+ zoomTimerRef: MutableRefObject<NodeJS.Timeout | null>,
7
+ tooltipVisibleRef: MutableRefObject<boolean>,
8
+ canHover: boolean
9
+ ): void => {
10
+ if (!canHover) {
11
+ return;
12
+ }
13
+
14
+ if (tooltipVisibleRef.current) {
15
+ instance.setOption({
16
+ tooltip: {
17
+ show: false,
18
+ },
19
+ });
20
+ tooltipVisibleRef.current = false;
21
+ }
22
+
23
+ if (zoomTimerRef.current) {
24
+ clearTimeout(zoomTimerRef.current);
25
+ }
26
+
27
+ zoomTimerRef.current = setTimeout(() => {
28
+ if (!tooltipVisibleRef.current) {
29
+ instance.setOption({
30
+ tooltip: {
31
+ show: true,
32
+ },
33
+ });
34
+ tooltipVisibleRef.current = true;
35
+ }
36
+ }, 100);
37
+ };
@@ -1,7 +1,10 @@
1
+ export * from './formatXAxisAdditionalLabel';
1
2
  export * from './formatXAxisLabel';
2
3
  export * from './getChartStyles';
3
4
  export * from './getGradientColor';
4
5
  export * from './getLabelData';
5
6
  export * from './getRectColor';
6
7
  export * from './getTooltipFormatter';
8
+ export * from './handleLabelUpdate';
9
+ export * from './handleTooltipUpdate';
7
10
  export * from './isDifferenceGreaterThanTwoWeeks';
@@ -0,0 +1,13 @@
1
+ import { Granularity } from '../../../../gql/types/graphql';
2
+ import { BUCKET_CONFIG } from '../../../constants';
3
+
4
+ export const getMultiplayerForTimeSpan = (granularity: Granularity): number => {
5
+ const timeSpanMultiplierMap: Record<Granularity, number> = {
6
+ [Granularity.M5]: BUCKET_CONFIG.MULTIPLIER_5M,
7
+ [Granularity.M15]: BUCKET_CONFIG.MULTIPLIER_15M,
8
+ [Granularity.H1]: BUCKET_CONFIG.MULTIPLIER_1H,
9
+ [Granularity.H4]: BUCKET_CONFIG.MULTIPLIER_4H,
10
+ };
11
+
12
+ return timeSpanMultiplierMap[granularity] || BUCKET_CONFIG.MULTIPLIER_5M;
13
+ };
@@ -1,4 +1,5 @@
1
1
  export * from './getInstrumentConfigForDivision';
2
+ export * from './getMultiplayerForTimeSpan';
2
3
  export * from './getTimeSpanForGranularity';
3
4
  export * from './processOrderPositionBooks';
4
5
  export * from './processPriceCandles';
@@ -3,6 +3,7 @@ import {
3
3
  getDataZoomConfig,
4
4
  getGridConfig,
5
5
  getGridLines,
6
+ getLabelsConfig,
6
7
  getSeriesCandlestickConfig,
7
8
  getSeriesHeatmapConfig,
8
9
  getSeriesSentimentConfig,
@@ -35,6 +36,7 @@ export const getOption: GetOptionType = ({
35
36
  sentimentThresholdMin,
36
37
  sentimentThresholdMax,
37
38
  },
39
+ isLoading,
38
40
  isDark,
39
41
  isDesktop,
40
42
  labelCallback,
@@ -42,8 +44,12 @@ export const getOption: GetOptionType = ({
42
44
  const styles = getChartStyles(isDark);
43
45
  const selectedPriceRef = { current: 0 };
44
46
 
47
+ const initialStartZoom = isDesktop
48
+ ? CHART_CONFIG.INITIAL_START_ZOOM_DESKTOP
49
+ : CHART_CONFIG.INITIAL_START_ZOOM_MOBILE;
50
+
45
51
  const visibleXAxisData = dates.slice(
46
- (dates.length * CHART_CONFIG.INITIAL_START_ZOOM) / 100,
52
+ (dates.length * initialStartZoom) / 100,
47
53
  (dates.length * CHART_CONFIG.INITIAL_END_ZOOM) / 100
48
54
  );
49
55
 
@@ -52,6 +58,30 @@ export const getOption: GetOptionType = ({
52
58
  visibleXAxisData[visibleXAxisData.length - 1]
53
59
  );
54
60
 
61
+ const heatmapChart =
62
+ bookPrices && bookPrices.length > 0
63
+ ? [
64
+ getSeriesHeatmapConfig({
65
+ bucketWidth,
66
+ buckets,
67
+ isDark,
68
+ sentimentThresholdMax,
69
+ sentimentThresholdMin,
70
+ isLoading,
71
+ }),
72
+ ]
73
+ : [];
74
+
75
+ const sentimentChart =
76
+ sentimentLongs && sentimentLongs.length > 0
77
+ ? [
78
+ getSeriesSentimentConfig({
79
+ styles,
80
+ isLoading,
81
+ }),
82
+ ]
83
+ : [];
84
+
55
85
  return {
56
86
  animation: false,
57
87
  tooltip: getTooltipConfig({
@@ -62,6 +92,8 @@ export const getOption: GetOptionType = ({
62
92
  labelCallback,
63
93
  selectedPriceRef,
64
94
  tooltipLinesColor: styles.tooltipLinesColor,
95
+ sentimentLongs,
96
+ sentimentShorts,
65
97
  }),
66
98
  grid: getGridConfig({ isDesktop }),
67
99
  xAxis: getXAxisConfig({
@@ -71,15 +103,16 @@ export const getOption: GetOptionType = ({
71
103
  yAxis: getYAxisConfig({
72
104
  bucketWidth,
73
105
  displayPrecision,
74
- isDesktop,
75
- labelCallback,
76
106
  }),
77
- dataZoom: getDataZoomConfig(),
107
+ dataZoom: getDataZoomConfig({ isDesktop }),
78
108
  visualMap: getVisualMapConfig({
79
109
  sentimentLongColor: styles.sentimentLongColor,
80
110
  sentimentShortColor: styles.sentimentShortColor,
81
111
  }),
82
- graphic: getGridLines({ isDark }),
112
+ graphic: [
113
+ ...getGridLines({ isDark, isDesktop }),
114
+ ...getLabelsConfig({ isDark, isDesktop, labelCallback }),
115
+ ],
83
116
  dataset: {
84
117
  source: {
85
118
  dates,
@@ -95,20 +128,11 @@ export const getOption: GetOptionType = ({
95
128
  },
96
129
  series: [
97
130
  getSeriesCandlestickConfig({
98
- dates,
99
- isGreaterThanTwoWeeks,
100
- styles,
101
- }),
102
- getSeriesHeatmapConfig({
103
- bucketWidth,
104
- buckets,
105
- isDark,
106
- sentimentThresholdMax,
107
- sentimentThresholdMin,
108
- }),
109
- getSeriesSentimentConfig({
110
131
  styles,
132
+ isLoading,
111
133
  }),
134
+ ...heatmapChart,
135
+ ...sentimentChart,
112
136
  ],
113
137
  };
114
138
  };
@@ -44,6 +44,9 @@ export interface UseCrowdViewDataReturn {
44
44
  mainData?: CrowdViewMainData | null;
45
45
  additionalData?: CrowdViewAdditionalData | null;
46
46
  loading: boolean;
47
+ priceCandlesLoading: boolean;
48
+ orderPositionLoading: boolean;
49
+ sentimentsLoading: boolean;
47
50
  error: boolean;
48
51
  }
49
52
 
@@ -52,6 +55,7 @@ interface GetOptionProps {
52
55
  additionalData: CrowdViewAdditionalData;
53
56
  isDark: boolean;
54
57
  isDesktop: boolean;
58
+ isLoading: boolean;
55
59
  labelCallback: (key: string, params?: Record<string, unknown>) => string;
56
60
  }
57
61
 
@@ -61,6 +65,7 @@ export interface ChartProps {
61
65
  mainData: CrowdViewMainData;
62
66
  additionalData: CrowdViewAdditionalData;
63
67
  isDesktop: boolean;
68
+ isLoading: boolean;
64
69
  }
65
70
 
66
71
  export interface ChartWithDataProps {