@ivanmatiaspascual/interactive 1.3.1-sp1-beta.0.1.0

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 (136) hide show
  1. package/CHANGELOG.md +190 -0
  2. package/LICENSE +24 -0
  3. package/README.md +5 -0
  4. package/lib/Brush.d.ts +35 -0
  5. package/lib/Brush.js +103 -0
  6. package/lib/Brush.js.map +1 -0
  7. package/lib/ClickCallback.d.ts +18 -0
  8. package/lib/ClickCallback.js +12 -0
  9. package/lib/ClickCallback.js.map +1 -0
  10. package/lib/DrawingObjectSelector.d.ts +18 -0
  11. package/lib/DrawingObjectSelector.js +73 -0
  12. package/lib/DrawingObjectSelector.js.map +1 -0
  13. package/lib/EquidistantChannel.d.ts +74 -0
  14. package/lib/EquidistantChannel.js +149 -0
  15. package/lib/EquidistantChannel.js.map +1 -0
  16. package/lib/FibonacciRetracement.d.ts +83 -0
  17. package/lib/FibonacciRetracement.js +163 -0
  18. package/lib/FibonacciRetracement.js.map +1 -0
  19. package/lib/GannFan.d.ts +78 -0
  20. package/lib/GannFan.js +128 -0
  21. package/lib/GannFan.js.map +1 -0
  22. package/lib/InteractiveText.d.ts +70 -0
  23. package/lib/InteractiveText.js +89 -0
  24. package/lib/InteractiveText.js.map +1 -0
  25. package/lib/InteractiveYCoordinate.d.ts +128 -0
  26. package/lib/InteractiveYCoordinate.js +106 -0
  27. package/lib/InteractiveYCoordinate.js.map +1 -0
  28. package/lib/StandardDeviationChannel.d.ts +74 -0
  29. package/lib/StandardDeviationChannel.js +125 -0
  30. package/lib/StandardDeviationChannel.js.map +1 -0
  31. package/lib/TrendLine.d.ts +77 -0
  32. package/lib/TrendLine.js +125 -0
  33. package/lib/TrendLine.js.map +1 -0
  34. package/lib/ZoomButtons.d.ts +37 -0
  35. package/lib/ZoomButtons.js +85 -0
  36. package/lib/ZoomButtons.js.map +1 -0
  37. package/lib/components/ChannelWithArea.d.ts +30 -0
  38. package/lib/components/ChannelWithArea.js +126 -0
  39. package/lib/components/ChannelWithArea.js.map +1 -0
  40. package/lib/components/ClickableCircle.d.ts +26 -0
  41. package/lib/components/ClickableCircle.js +48 -0
  42. package/lib/components/ClickableCircle.js.map +1 -0
  43. package/lib/components/ClickableShape.d.ts +33 -0
  44. package/lib/components/ClickableShape.js +64 -0
  45. package/lib/components/ClickableShape.js.map +1 -0
  46. package/lib/components/GannFan.d.ts +32 -0
  47. package/lib/components/GannFan.js +134 -0
  48. package/lib/components/GannFan.js.map +1 -0
  49. package/lib/components/HoverTextNearMouse.d.ts +35 -0
  50. package/lib/components/HoverTextNearMouse.js +113 -0
  51. package/lib/components/HoverTextNearMouse.js.map +1 -0
  52. package/lib/components/InteractiveStraightLine.d.ts +57 -0
  53. package/lib/components/InteractiveStraightLine.js +220 -0
  54. package/lib/components/InteractiveStraightLine.js.map +1 -0
  55. package/lib/components/InteractiveText.d.ts +37 -0
  56. package/lib/components/InteractiveText.js +84 -0
  57. package/lib/components/InteractiveText.js.map +1 -0
  58. package/lib/components/InteractiveYCoordinate.d.ts +46 -0
  59. package/lib/components/InteractiveYCoordinate.js +109 -0
  60. package/lib/components/InteractiveYCoordinate.js.map +1 -0
  61. package/lib/components/LinearRegressionChannelWithArea.d.ts +31 -0
  62. package/lib/components/LinearRegressionChannelWithArea.js +104 -0
  63. package/lib/components/LinearRegressionChannelWithArea.js.map +1 -0
  64. package/lib/components/MouseLocationIndicator.d.ts +34 -0
  65. package/lib/components/MouseLocationIndicator.js +79 -0
  66. package/lib/components/MouseLocationIndicator.js.map +1 -0
  67. package/lib/components/Text.d.ts +17 -0
  68. package/lib/components/Text.js +26 -0
  69. package/lib/components/Text.js.map +1 -0
  70. package/lib/components/index.d.ts +11 -0
  71. package/lib/components/index.js +12 -0
  72. package/lib/components/index.js.map +1 -0
  73. package/lib/index.d.ts +12 -0
  74. package/lib/index.js +13 -0
  75. package/lib/index.js.map +1 -0
  76. package/lib/utils.d.ts +7 -0
  77. package/lib/utils.js +84 -0
  78. package/lib/utils.js.map +1 -0
  79. package/lib/wrapper/EachEquidistantChannel.d.ts +59 -0
  80. package/lib/wrapper/EachEquidistantChannel.js +172 -0
  81. package/lib/wrapper/EachEquidistantChannel.js.map +1 -0
  82. package/lib/wrapper/EachFibRetracement.d.ts +77 -0
  83. package/lib/wrapper/EachFibRetracement.js +197 -0
  84. package/lib/wrapper/EachFibRetracement.js.map +1 -0
  85. package/lib/wrapper/EachGannFan.d.ts +81 -0
  86. package/lib/wrapper/EachGannFan.js +161 -0
  87. package/lib/wrapper/EachGannFan.js.map +1 -0
  88. package/lib/wrapper/EachInteractiveYCoordinate.d.ts +50 -0
  89. package/lib/wrapper/EachInteractiveYCoordinate.js +80 -0
  90. package/lib/wrapper/EachInteractiveYCoordinate.js.map +1 -0
  91. package/lib/wrapper/EachLinearRegressionChannel.d.ts +75 -0
  92. package/lib/wrapper/EachLinearRegressionChannel.js +89 -0
  93. package/lib/wrapper/EachLinearRegressionChannel.js.map +1 -0
  94. package/lib/wrapper/EachText.d.ts +58 -0
  95. package/lib/wrapper/EachText.js +79 -0
  96. package/lib/wrapper/EachText.js.map +1 -0
  97. package/lib/wrapper/EachTrendLine.d.ts +76 -0
  98. package/lib/wrapper/EachTrendLine.js +141 -0
  99. package/lib/wrapper/EachTrendLine.js.map +1 -0
  100. package/lib/wrapper/index.d.ts +7 -0
  101. package/lib/wrapper/index.js +8 -0
  102. package/lib/wrapper/index.js.map +1 -0
  103. package/package.json +55 -0
  104. package/src/Brush.tsx +177 -0
  105. package/src/ClickCallback.tsx +37 -0
  106. package/src/DrawingObjectSelector.tsx +97 -0
  107. package/src/EquidistantChannel.tsx +268 -0
  108. package/src/FibonacciRetracement.tsx +298 -0
  109. package/src/GannFan.tsx +233 -0
  110. package/src/InteractiveText.tsx +185 -0
  111. package/src/InteractiveYCoordinate.tsx +205 -0
  112. package/src/StandardDeviationChannel.tsx +269 -0
  113. package/src/TrendLine.tsx +283 -0
  114. package/src/ZoomButtons.tsx +172 -0
  115. package/src/components/ChannelWithArea.tsx +199 -0
  116. package/src/components/ClickableCircle.tsx +91 -0
  117. package/src/components/ClickableShape.tsx +114 -0
  118. package/src/components/GannFan.tsx +189 -0
  119. package/src/components/HoverTextNearMouse.tsx +174 -0
  120. package/src/components/InteractiveStraightLine.tsx +317 -0
  121. package/src/components/InteractiveText.tsx +153 -0
  122. package/src/components/InteractiveYCoordinate.tsx +205 -0
  123. package/src/components/LinearRegressionChannelWithArea.tsx +169 -0
  124. package/src/components/MouseLocationIndicator.tsx +128 -0
  125. package/src/components/Text.tsx +47 -0
  126. package/src/components/index.ts +11 -0
  127. package/src/index.ts +12 -0
  128. package/src/utils.ts +101 -0
  129. package/src/wrapper/EachEquidistantChannel.tsx +302 -0
  130. package/src/wrapper/EachFibRetracement.tsx +342 -0
  131. package/src/wrapper/EachGannFan.tsx +289 -0
  132. package/src/wrapper/EachInteractiveYCoordinate.tsx +198 -0
  133. package/src/wrapper/EachLinearRegressionChannel.tsx +202 -0
  134. package/src/wrapper/EachText.tsx +183 -0
  135. package/src/wrapper/EachTrendLine.tsx +297 -0
  136. package/src/wrapper/index.ts +7 -0
@@ -0,0 +1,302 @@
1
+ import * as React from "react";
2
+ import { isDefined, noop } from "@ivanmatiaspascual/core";
3
+ import { getXValue } from "@ivanmatiaspascual/core/lib/utils/ChartDataUtil";
4
+ import { isHover, saveNodeType } from "../utils";
5
+ import { ChannelWithArea, ClickableCircle, HoverTextNearMouse } from "../components";
6
+
7
+ export interface EachEquidistantChannelProps {
8
+ readonly startXY: number[];
9
+ readonly endXY: number[];
10
+ readonly dy?: number;
11
+ readonly interactive: boolean;
12
+ readonly selected: boolean;
13
+ readonly hoverText: {
14
+ readonly enable: boolean;
15
+ readonly fontFamily: string;
16
+ readonly fontSize: number;
17
+ readonly fill: string;
18
+ readonly text: string;
19
+ readonly bgFill: string;
20
+ readonly bgOpacity: number;
21
+ readonly bgWidth: number | string;
22
+ readonly bgHeight: number | string;
23
+ };
24
+ readonly appearance: {
25
+ readonly stroke: string;
26
+ readonly strokeWidth: number;
27
+ readonly fill: string;
28
+ readonly edgeStroke: string;
29
+ readonly edgeFill: string;
30
+ readonly edgeFill2: string;
31
+ readonly edgeStrokeWidth: number;
32
+ readonly r: number;
33
+ };
34
+ readonly index?: number;
35
+ readonly onDrag: (e: React.MouseEvent, index: number | undefined, moreProps: any) => void;
36
+ readonly onDragComplete?: (e: React.MouseEvent, moreProps: any) => void;
37
+ }
38
+
39
+ interface EachEquidistantChannelState {
40
+ hover: boolean;
41
+ }
42
+
43
+ export class EachEquidistantChannel extends React.Component<EachEquidistantChannelProps, EachEquidistantChannelState> {
44
+ public static defaultProps = {
45
+ yDisplayFormat: (d: number) => d.toFixed(2),
46
+ interactive: true,
47
+ selected: false,
48
+ onDrag: noop,
49
+ hoverText: {
50
+ enable: false,
51
+ },
52
+ };
53
+
54
+ private dragStart: any;
55
+ // @ts-ignore
56
+ private isHover: any;
57
+ private saveNodeType: any;
58
+
59
+ public constructor(props: EachEquidistantChannelProps) {
60
+ super(props);
61
+
62
+ this.isHover = isHover.bind(this);
63
+ this.saveNodeType = saveNodeType.bind(this);
64
+
65
+ this.state = {
66
+ hover: false,
67
+ };
68
+ }
69
+
70
+ public render() {
71
+ const { startXY, endXY, dy } = this.props;
72
+ const { interactive, hoverText, appearance } = this.props;
73
+ const { edgeFill, edgeFill2, stroke, strokeWidth, fill } = appearance;
74
+ const { selected } = this.props;
75
+ const { onDragComplete } = this.props;
76
+ const { hover } = this.state;
77
+ const { enable: hoverTextEnabled, ...restHoverTextProps } = hoverText;
78
+
79
+ const hoverHandler = interactive ? { onHover: this.handleHover, onUnHover: this.handleHover } : {};
80
+
81
+ const line1Edge =
82
+ isDefined(startXY) && isDefined(endXY) ? (
83
+ <g>
84
+ {this.getEdgeCircle({
85
+ xy: startXY,
86
+ dragHandler: this.handleLine1Edge1Drag,
87
+ cursor: "react-financial-charts-move-cursor",
88
+ fill: edgeFill,
89
+ edge: "line1edge1",
90
+ })}
91
+ {this.getEdgeCircle({
92
+ xy: endXY,
93
+ dragHandler: this.handleLine1Edge2Drag,
94
+ cursor: "react-financial-charts-move-cursor",
95
+ fill: edgeFill,
96
+ edge: "line1edge2",
97
+ })}
98
+ </g>
99
+ ) : null;
100
+ const line2Edge =
101
+ dy !== undefined && isDefined(dy) ? (
102
+ <g>
103
+ {this.getEdgeCircle({
104
+ xy: [startXY[0], startXY[1] + dy],
105
+ dragHandler: this.handleChannelHeightChange,
106
+ cursor: "react-financial-charts-ns-resize-cursor",
107
+ fill: edgeFill2,
108
+ edge: "line2edge1",
109
+ })}
110
+ {this.getEdgeCircle({
111
+ xy: [endXY[0], endXY[1] + dy],
112
+ dragHandler: this.handleChannelHeightChange,
113
+ cursor: "react-financial-charts-ns-resize-cursor",
114
+ fill: edgeFill2,
115
+ edge: "line2edge2",
116
+ })}
117
+ </g>
118
+ ) : null;
119
+
120
+ return (
121
+ <g>
122
+ <ChannelWithArea
123
+ ref={this.saveNodeType("channel")}
124
+ selected={selected || hover}
125
+ {...hoverHandler}
126
+ startXY={startXY}
127
+ endXY={endXY}
128
+ dy={dy}
129
+ strokeStyle={stroke}
130
+ strokeWidth={hover || selected ? strokeWidth + 1 : strokeWidth}
131
+ fillStyle={fill}
132
+ interactiveCursorClass="react-financial-charts-move-cursor"
133
+ onDragStart={this.handleDragStart}
134
+ onDrag={this.handleChannelDrag}
135
+ onDragComplete={onDragComplete}
136
+ />
137
+ {line1Edge}
138
+ {line2Edge}
139
+ <HoverTextNearMouse show={hoverTextEnabled && hover && !selected} {...restHoverTextProps} />
140
+ </g>
141
+ );
142
+ }
143
+
144
+ private readonly getEdgeCircle = ({ xy, dragHandler, cursor, fill, edge }: any) => {
145
+ const { hover } = this.state;
146
+ const { appearance } = this.props;
147
+ const { edgeStroke, edgeStrokeWidth, r } = appearance;
148
+ const { selected } = this.props;
149
+ const { onDragComplete } = this.props;
150
+
151
+ return (
152
+ <ClickableCircle
153
+ ref={this.saveNodeType(edge)}
154
+ show={selected || hover}
155
+ cx={xy[0]}
156
+ cy={xy[1]}
157
+ r={r}
158
+ fillStyle={fill}
159
+ strokeStyle={edgeStroke}
160
+ strokeWidth={edgeStrokeWidth}
161
+ interactiveCursorClass={cursor}
162
+ onDragStart={this.handleDragStart}
163
+ onDrag={dragHandler}
164
+ onDragComplete={onDragComplete}
165
+ />
166
+ );
167
+ };
168
+
169
+ private readonly handleChannelHeightChange = (e: React.MouseEvent, moreProps: any) => {
170
+ const { index, onDrag } = this.props;
171
+
172
+ const { startXY, endXY } = this.dragStart;
173
+
174
+ const {
175
+ chartConfig: { yScale },
176
+ } = moreProps;
177
+ const { startPos, mouseXY } = moreProps;
178
+
179
+ const y2 = yScale(endXY[1]);
180
+
181
+ const dy = startPos[1] - mouseXY[1];
182
+
183
+ const newY2Value = yScale.invert(y2 - dy);
184
+
185
+ const newDy = newY2Value - endXY[1] + this.dragStart.dy;
186
+
187
+ onDrag(e, index, {
188
+ startXY,
189
+ endXY,
190
+ dy: newDy,
191
+ });
192
+ };
193
+
194
+ private readonly handleLine1Edge2Drag = (e: React.MouseEvent, moreProps: any) => {
195
+ const { index, onDrag } = this.props;
196
+ const { endXY } = this.dragStart;
197
+
198
+ const {
199
+ startPos,
200
+ mouseXY,
201
+ xAccessor,
202
+ xScale,
203
+ fullData,
204
+ chartConfig: { yScale },
205
+ } = moreProps;
206
+
207
+ const dx = startPos[0] - mouseXY[0];
208
+ const dy = startPos[1] - mouseXY[1];
209
+
210
+ const x1 = xScale(endXY[0]);
211
+ const y1 = yScale(endXY[1]);
212
+
213
+ const newX1Value = getXValue(xScale, xAccessor, [x1 - dx, y1 - dy], fullData);
214
+ const newY1Value = yScale.invert(y1 - dy);
215
+
216
+ onDrag(e, index, {
217
+ startXY: this.dragStart.startXY,
218
+ endXY: [newX1Value, newY1Value],
219
+ dy: this.dragStart.dy,
220
+ });
221
+ };
222
+
223
+ private readonly handleLine1Edge1Drag = (e: React.MouseEvent, moreProps: any) => {
224
+ const { index, onDrag } = this.props;
225
+ const { startXY } = this.dragStart;
226
+
227
+ const {
228
+ startPos,
229
+ mouseXY,
230
+ xAccessor,
231
+ xScale,
232
+ fullData,
233
+ chartConfig: { yScale },
234
+ } = moreProps;
235
+
236
+ const dx = startPos[0] - mouseXY[0];
237
+ const dy = startPos[1] - mouseXY[1];
238
+
239
+ const x1 = xScale(startXY[0]);
240
+ const y1 = yScale(startXY[1]);
241
+
242
+ const newX1Value = getXValue(xScale, xAccessor, [x1 - dx, y1 - dy], fullData);
243
+ const newY1Value = yScale.invert(y1 - dy);
244
+
245
+ onDrag(e, index, {
246
+ startXY: [newX1Value, newY1Value],
247
+ endXY: this.dragStart.endXY,
248
+ dy: this.dragStart.dy,
249
+ });
250
+ };
251
+
252
+ private readonly handleChannelDrag = (e: React.MouseEvent, moreProps: any) => {
253
+ const { index, onDrag } = this.props;
254
+
255
+ const { startXY, endXY } = this.dragStart;
256
+
257
+ const {
258
+ xScale,
259
+ chartConfig: { yScale },
260
+ xAccessor,
261
+ fullData,
262
+ } = moreProps;
263
+ const { startPos, mouseXY } = moreProps;
264
+
265
+ const x1 = xScale(startXY[0]);
266
+ const y1 = yScale(startXY[1]);
267
+ const x2 = xScale(endXY[0]);
268
+ const y2 = yScale(endXY[1]);
269
+
270
+ const dx = startPos[0] - mouseXY[0];
271
+ const dy = startPos[1] - mouseXY[1];
272
+
273
+ const newX1Value = getXValue(xScale, xAccessor, [x1 - dx, y1 - dy], fullData);
274
+ const newY1Value = yScale.invert(y1 - dy);
275
+ const newX2Value = getXValue(xScale, xAccessor, [x2 - dx, y2 - dy], fullData);
276
+ const newY2Value = yScale.invert(y2 - dy);
277
+
278
+ onDrag(e, index, {
279
+ startXY: [newX1Value, newY1Value],
280
+ endXY: [newX2Value, newY2Value],
281
+ dy: this.dragStart.dy,
282
+ });
283
+ };
284
+
285
+ private readonly handleDragStart = () => {
286
+ const { startXY, endXY, dy } = this.props;
287
+
288
+ this.dragStart = {
289
+ startXY,
290
+ endXY,
291
+ dy,
292
+ };
293
+ };
294
+
295
+ private readonly handleHover = (_: React.MouseEvent, moreProps: any) => {
296
+ if (this.state.hover !== moreProps.hovering) {
297
+ this.setState({
298
+ hover: moreProps.hovering,
299
+ });
300
+ }
301
+ };
302
+ }
@@ -0,0 +1,342 @@
1
+ import * as React from "react";
2
+ import { head, last, noop } from "@ivanmatiaspascual/core";
3
+ import { getXValue } from "@ivanmatiaspascual/core/lib/utils/ChartDataUtil";
4
+ import { isHover, saveNodeType } from "../utils";
5
+ import { ClickableCircle, HoverTextNearMouse, InteractiveStraightLine, generateLine, Text } from "../components";
6
+ import { getNewXY } from "./EachTrendLine";
7
+
8
+ export interface EachFibRetracementProps {
9
+ readonly x1: any;
10
+ readonly x2: any;
11
+ readonly y1: number;
12
+ readonly y2: number;
13
+ readonly yDisplayFormat: (value: number) => string;
14
+ readonly type: string;
15
+ readonly selected: boolean;
16
+ readonly appearance: {
17
+ readonly strokeStyle: string;
18
+ readonly strokeWidth: number;
19
+ readonly fontFamily: string;
20
+ readonly fontSize: number;
21
+ readonly fontFill: string;
22
+ readonly edgeStroke: string;
23
+ readonly edgeFill: string;
24
+ readonly nsEdgeFill: string;
25
+ readonly edgeStrokeWidth: number;
26
+ readonly r: number;
27
+ };
28
+ readonly interactive: boolean;
29
+ readonly hoverText: {
30
+ readonly enable: boolean;
31
+ readonly fontFamily: string;
32
+ readonly fontSize: number;
33
+ readonly fill: string;
34
+ readonly text: string;
35
+ readonly bgFill: string;
36
+ readonly bgOpacity: number;
37
+ readonly bgWidth: number | string;
38
+ readonly bgHeight: number | string;
39
+ readonly selectedText: string;
40
+ };
41
+ readonly index?: number;
42
+ readonly onDrag: (e: React.MouseEvent, index: number | undefined, moreProps: any) => void;
43
+ readonly onDragComplete?: (e: React.MouseEvent, moreProps: any) => void;
44
+ }
45
+
46
+ interface EachFibRetracementState {
47
+ hover: boolean;
48
+ }
49
+
50
+ export class EachFibRetracement extends React.Component<EachFibRetracementProps, EachFibRetracementState> {
51
+ public static defaultProps = {
52
+ yDisplayFormat: (d: number) => d.toFixed(2),
53
+ interactive: true,
54
+ appearance: {
55
+ strokeStyle: "#000000",
56
+ strokeWidth: 1,
57
+ fontFamily: "-apple-system, system-ui, Roboto, 'Helvetica Neue', Ubuntu, sans-serif",
58
+ fontSize: 10,
59
+ fontFill: "#000000",
60
+ edgeStroke: "#000000",
61
+ edgeFill: "#FFFFFF",
62
+ nsEdgeFill: "#000000",
63
+ edgeStrokeWidth: 1,
64
+ r: 5,
65
+ },
66
+ selected: false,
67
+ onDrag: noop,
68
+ hoverText: {
69
+ enable: false,
70
+ },
71
+ };
72
+
73
+ private dragStart: any;
74
+ // @ts-ignore
75
+ private isHover: any;
76
+ private saveNodeType: any;
77
+
78
+ public constructor(props: EachFibRetracementProps) {
79
+ super(props);
80
+
81
+ this.isHover = isHover.bind(this);
82
+ this.saveNodeType = saveNodeType.bind(this);
83
+
84
+ this.state = {
85
+ hover: false,
86
+ };
87
+ }
88
+
89
+ public render() {
90
+ const { x1, x2, y1, y2 } = this.props;
91
+ const { interactive, yDisplayFormat, type, appearance } = this.props;
92
+ const { strokeStyle, strokeWidth } = appearance;
93
+ const { fontFamily, fontSize, fontFill } = appearance;
94
+ const { edgeStroke, edgeFill, nsEdgeFill, edgeStrokeWidth, r } = appearance;
95
+ const { hoverText, selected } = this.props;
96
+ const { hover } = this.state;
97
+ const { onDragComplete } = this.props;
98
+ const lines = helper({ x1, x2, y1, y2 });
99
+
100
+ const {
101
+ enable: hoverTextEnabled,
102
+ selectedText: hoverTextSelected,
103
+ text: hoverTextUnselected,
104
+ ...restHoverTextProps
105
+ } = hoverText;
106
+
107
+ const lineType = type === "EXTEND" ? "XLINE" : type === "BOUND" ? "LINE" : "RAY";
108
+ const dir = head(lines).y1 > last(lines).y1 ? 3 : -1.3;
109
+
110
+ return (
111
+ <g>
112
+ {lines.map((line, j) => {
113
+ const text = `${yDisplayFormat(line.y)} (${line.percent.toFixed(2)}%)`;
114
+
115
+ const xyProvider = ({ xScale, chartConfig }: any) => {
116
+ const { yScale } = chartConfig;
117
+ const { x1: lineX1, y1: lineY1, x2: lineX2 } = generateLine({
118
+ type: lineType,
119
+ start: [line.x1, line.y],
120
+ end: [line.x2, line.y],
121
+ xScale,
122
+ yScale,
123
+ });
124
+
125
+ const x = xScale(Math.min(lineX1, lineX2)) + 10;
126
+ const y = yScale(lineY1) + dir * 4;
127
+ return [x, y];
128
+ };
129
+
130
+ const firstOrLast = j === 0 || j === lines.length - 1;
131
+
132
+ const interactiveCursorClass = firstOrLast
133
+ ? "react-financial-charts-ns-resize-cursor"
134
+ : "react-financial-charts-move-cursor";
135
+
136
+ const interactiveEdgeCursorClass = firstOrLast
137
+ ? "react-financial-charts-ns-resize-cursor"
138
+ : "react-financial-charts-ew-resize-cursor";
139
+
140
+ const dragHandler =
141
+ j === 0
142
+ ? this.handleLineNSResizeTop
143
+ : j === lines.length - 1
144
+ ? this.handleLineNSResizeBottom
145
+ : this.handleLineMove;
146
+
147
+ const edge1DragHandler =
148
+ j === 0
149
+ ? this.handleLineNSResizeTop
150
+ : j === lines.length - 1
151
+ ? this.handleLineNSResizeBottom
152
+ : this.handleEdge1Drag;
153
+ const edge2DragHandler =
154
+ j === 0
155
+ ? this.handleLineNSResizeTop
156
+ : j === lines.length - 1
157
+ ? this.handleLineNSResizeBottom
158
+ : this.handleEdge2Drag;
159
+
160
+ const hoverHandler = interactive ? { onHover: this.handleHover, onUnHover: this.handleHover } : {};
161
+ return (
162
+ <g key={j}>
163
+ <InteractiveStraightLine
164
+ ref={this.saveNodeType(`line_${j}`)}
165
+ selected={selected || hover}
166
+ {...hoverHandler}
167
+ type={lineType}
168
+ x1Value={line.x1}
169
+ y1Value={line.y}
170
+ x2Value={line.x2}
171
+ y2Value={line.y}
172
+ strokeStyle={strokeStyle}
173
+ strokeWidth={hover || selected ? strokeWidth + 1 : strokeWidth}
174
+ interactiveCursorClass={interactiveCursorClass}
175
+ onDragStart={this.handleLineDragStart}
176
+ onDrag={dragHandler}
177
+ onDragComplete={onDragComplete}
178
+ />
179
+ <Text
180
+ selected={selected}
181
+ xyProvider={xyProvider}
182
+ fontFamily={fontFamily}
183
+ fontSize={fontSize}
184
+ fillStyle={fontFill}
185
+ >
186
+ {text}
187
+ </Text>
188
+ <ClickableCircle
189
+ ref={this.saveNodeType("edge1")}
190
+ show={selected || hover}
191
+ cx={line.x1}
192
+ cy={line.y}
193
+ r={r}
194
+ fillStyle={firstOrLast ? nsEdgeFill : edgeFill}
195
+ strokeStyle={edgeStroke}
196
+ strokeWidth={edgeStrokeWidth}
197
+ interactiveCursorClass={interactiveEdgeCursorClass}
198
+ onDrag={edge1DragHandler}
199
+ onDragComplete={onDragComplete}
200
+ />
201
+ <ClickableCircle
202
+ ref={this.saveNodeType("edge2")}
203
+ show={selected || hover}
204
+ cx={line.x2}
205
+ cy={line.y}
206
+ r={r}
207
+ fillStyle={firstOrLast ? nsEdgeFill : edgeFill}
208
+ strokeStyle={edgeStroke}
209
+ strokeWidth={edgeStrokeWidth}
210
+ interactiveCursorClass={interactiveEdgeCursorClass}
211
+ onDrag={edge2DragHandler}
212
+ onDragComplete={onDragComplete}
213
+ />
214
+ </g>
215
+ );
216
+ })}
217
+ <HoverTextNearMouse
218
+ show={hoverTextEnabled && hover}
219
+ {...restHoverTextProps}
220
+ text={selected ? hoverTextSelected : hoverTextUnselected}
221
+ />
222
+ </g>
223
+ );
224
+ }
225
+
226
+ private readonly handleEdge2Drag = (e: React.MouseEvent, moreProps: any) => {
227
+ const { index, onDrag, x1, y1, y2 } = this.props;
228
+
229
+ const [x2] = getNewXY(moreProps);
230
+
231
+ onDrag(e, index, {
232
+ x1,
233
+ y1,
234
+ x2,
235
+ y2,
236
+ });
237
+ };
238
+
239
+ private readonly handleEdge1Drag = (e: React.MouseEvent, moreProps: any) => {
240
+ const { index, onDrag, y1, x2, y2 } = this.props;
241
+
242
+ const [x1] = getNewXY(moreProps);
243
+
244
+ onDrag(e, index, {
245
+ x1,
246
+ y1,
247
+ x2,
248
+ y2,
249
+ });
250
+ };
251
+
252
+ private readonly handleLineNSResizeBottom = (e: React.MouseEvent, moreProps: any) => {
253
+ const { index, onDrag, x1, y1, x2 } = this.props;
254
+
255
+ const [, y2] = getNewXY(moreProps);
256
+
257
+ onDrag(e, index, {
258
+ x1,
259
+ y1,
260
+ x2,
261
+ y2,
262
+ });
263
+ };
264
+
265
+ private readonly handleLineNSResizeTop = (e: React.MouseEvent, moreProps: any) => {
266
+ const { index, onDrag, x1, x2, y2 } = this.props;
267
+
268
+ const [, y1] = getNewXY(moreProps);
269
+
270
+ onDrag(e, index, {
271
+ x1,
272
+ y1,
273
+ x2,
274
+ y2,
275
+ });
276
+ };
277
+
278
+ private readonly handleLineMove = (e: React.MouseEvent, moreProps: any) => {
279
+ const { index, onDrag } = this.props;
280
+
281
+ const { x1: x1Value, y1: y1Value, x2: x2Value, y2: y2Value } = this.dragStart;
282
+
283
+ const {
284
+ xScale,
285
+ chartConfig: { yScale },
286
+ xAccessor,
287
+ fullData,
288
+ } = moreProps;
289
+ const { startPos, mouseXY } = moreProps;
290
+
291
+ const x1 = xScale(x1Value);
292
+ const y1 = yScale(y1Value);
293
+ const x2 = xScale(x2Value);
294
+ const y2 = yScale(y2Value);
295
+
296
+ const dx = startPos[0] - mouseXY[0];
297
+ const dy = startPos[1] - mouseXY[1];
298
+
299
+ const newX1Value = getXValue(xScale, xAccessor, [x1 - dx, y1 - dy], fullData);
300
+ const newY1Value = yScale.invert(y1 - dy);
301
+ const newX2Value = getXValue(xScale, xAccessor, [x2 - dx, y2 - dy], fullData);
302
+ const newY2Value = yScale.invert(y2 - dy);
303
+
304
+ onDrag(e, index, {
305
+ x1: newX1Value,
306
+ y1: newY1Value,
307
+ x2: newX2Value,
308
+ y2: newY2Value,
309
+ });
310
+ };
311
+
312
+ private readonly handleLineDragStart = () => {
313
+ const { x1, y1, x2, y2 } = this.props;
314
+
315
+ this.dragStart = {
316
+ x1,
317
+ y1,
318
+ x2,
319
+ y2,
320
+ };
321
+ };
322
+
323
+ private readonly handleHover = (_: React.MouseEvent, moreProps: any) => {
324
+ if (this.state.hover !== moreProps.hovering) {
325
+ this.setState({
326
+ hover: moreProps.hovering,
327
+ });
328
+ }
329
+ };
330
+ }
331
+
332
+ function helper({ x1, y1, x2, y2 }: any) {
333
+ const dy = y2 - y1;
334
+ const retracements = [100, 61.8, 50, 38.2, 23.6, 0].map((each) => ({
335
+ percent: each,
336
+ x1,
337
+ x2,
338
+ y: y2 - (each / 100) * dy,
339
+ }));
340
+
341
+ return retracements;
342
+ }