@tradingaction/interactive 2.0.13

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 (135) hide show
  1. package/LICENSE +24 -0
  2. package/README.md +5 -0
  3. package/lib/Brush.d.ts +35 -0
  4. package/lib/Brush.js +103 -0
  5. package/lib/Brush.js.map +1 -0
  6. package/lib/ClickCallback.d.ts +18 -0
  7. package/lib/ClickCallback.js +12 -0
  8. package/lib/ClickCallback.js.map +1 -0
  9. package/lib/DrawingObjectSelector.d.ts +18 -0
  10. package/lib/DrawingObjectSelector.js +73 -0
  11. package/lib/DrawingObjectSelector.js.map +1 -0
  12. package/lib/EquidistantChannel.d.ts +74 -0
  13. package/lib/EquidistantChannel.js +149 -0
  14. package/lib/EquidistantChannel.js.map +1 -0
  15. package/lib/FibonacciRetracement.d.ts +89 -0
  16. package/lib/FibonacciRetracement.js +184 -0
  17. package/lib/FibonacciRetracement.js.map +1 -0
  18. package/lib/GannFan.d.ts +78 -0
  19. package/lib/GannFan.js +128 -0
  20. package/lib/GannFan.js.map +1 -0
  21. package/lib/InteractiveText.d.ts +65 -0
  22. package/lib/InteractiveText.js +83 -0
  23. package/lib/InteractiveText.js.map +1 -0
  24. package/lib/InteractiveYCoordinate.d.ts +122 -0
  25. package/lib/InteractiveYCoordinate.js +100 -0
  26. package/lib/InteractiveYCoordinate.js.map +1 -0
  27. package/lib/StandardDeviationChannel.d.ts +74 -0
  28. package/lib/StandardDeviationChannel.js +125 -0
  29. package/lib/StandardDeviationChannel.js.map +1 -0
  30. package/lib/TrendLine.d.ts +84 -0
  31. package/lib/TrendLine.js +128 -0
  32. package/lib/TrendLine.js.map +1 -0
  33. package/lib/ZoomButtons.d.ts +30 -0
  34. package/lib/ZoomButtons.js +78 -0
  35. package/lib/ZoomButtons.js.map +1 -0
  36. package/lib/components/ChannelWithArea.d.ts +30 -0
  37. package/lib/components/ChannelWithArea.js +126 -0
  38. package/lib/components/ChannelWithArea.js.map +1 -0
  39. package/lib/components/ClickableCircle.d.ts +26 -0
  40. package/lib/components/ClickableCircle.js +48 -0
  41. package/lib/components/ClickableCircle.js.map +1 -0
  42. package/lib/components/ClickableShape.d.ts +33 -0
  43. package/lib/components/ClickableShape.js +64 -0
  44. package/lib/components/ClickableShape.js.map +1 -0
  45. package/lib/components/GannFan.d.ts +32 -0
  46. package/lib/components/GannFan.js +134 -0
  47. package/lib/components/GannFan.js.map +1 -0
  48. package/lib/components/HoverTextNearMouse.d.ts +35 -0
  49. package/lib/components/HoverTextNearMouse.js +113 -0
  50. package/lib/components/HoverTextNearMouse.js.map +1 -0
  51. package/lib/components/InteractiveStraightLine.d.ts +61 -0
  52. package/lib/components/InteractiveStraightLine.js +220 -0
  53. package/lib/components/InteractiveStraightLine.js.map +1 -0
  54. package/lib/components/InteractiveText.d.ts +38 -0
  55. package/lib/components/InteractiveText.js +84 -0
  56. package/lib/components/InteractiveText.js.map +1 -0
  57. package/lib/components/InteractiveYCoordinate.d.ts +46 -0
  58. package/lib/components/InteractiveYCoordinate.js +109 -0
  59. package/lib/components/InteractiveYCoordinate.js.map +1 -0
  60. package/lib/components/LinearRegressionChannelWithArea.d.ts +31 -0
  61. package/lib/components/LinearRegressionChannelWithArea.js +104 -0
  62. package/lib/components/LinearRegressionChannelWithArea.js.map +1 -0
  63. package/lib/components/MouseLocationIndicator.d.ts +34 -0
  64. package/lib/components/MouseLocationIndicator.js +79 -0
  65. package/lib/components/MouseLocationIndicator.js.map +1 -0
  66. package/lib/components/Text.d.ts +17 -0
  67. package/lib/components/Text.js +26 -0
  68. package/lib/components/Text.js.map +1 -0
  69. package/lib/components/index.d.ts +11 -0
  70. package/lib/components/index.js +12 -0
  71. package/lib/components/index.js.map +1 -0
  72. package/lib/index.d.ts +12 -0
  73. package/lib/index.js +13 -0
  74. package/lib/index.js.map +1 -0
  75. package/lib/utils.d.ts +7 -0
  76. package/lib/utils.js +84 -0
  77. package/lib/utils.js.map +1 -0
  78. package/lib/wrapper/EachEquidistantChannel.d.ts +59 -0
  79. package/lib/wrapper/EachEquidistantChannel.js +172 -0
  80. package/lib/wrapper/EachEquidistantChannel.js.map +1 -0
  81. package/lib/wrapper/EachFibRetracement.d.ts +81 -0
  82. package/lib/wrapper/EachFibRetracement.js +202 -0
  83. package/lib/wrapper/EachFibRetracement.js.map +1 -0
  84. package/lib/wrapper/EachGannFan.d.ts +81 -0
  85. package/lib/wrapper/EachGannFan.js +161 -0
  86. package/lib/wrapper/EachGannFan.js.map +1 -0
  87. package/lib/wrapper/EachInteractiveYCoordinate.d.ts +50 -0
  88. package/lib/wrapper/EachInteractiveYCoordinate.js +80 -0
  89. package/lib/wrapper/EachInteractiveYCoordinate.js.map +1 -0
  90. package/lib/wrapper/EachLinearRegressionChannel.d.ts +75 -0
  91. package/lib/wrapper/EachLinearRegressionChannel.js +89 -0
  92. package/lib/wrapper/EachLinearRegressionChannel.js.map +1 -0
  93. package/lib/wrapper/EachText.d.ts +59 -0
  94. package/lib/wrapper/EachText.js +83 -0
  95. package/lib/wrapper/EachText.js.map +1 -0
  96. package/lib/wrapper/EachTrendLine.d.ts +85 -0
  97. package/lib/wrapper/EachTrendLine.js +165 -0
  98. package/lib/wrapper/EachTrendLine.js.map +1 -0
  99. package/lib/wrapper/index.d.ts +7 -0
  100. package/lib/wrapper/index.js +8 -0
  101. package/lib/wrapper/index.js.map +1 -0
  102. package/package.json +53 -0
  103. package/src/Brush.tsx +172 -0
  104. package/src/ClickCallback.tsx +37 -0
  105. package/src/DrawingObjectSelector.tsx +97 -0
  106. package/src/EquidistantChannel.tsx +268 -0
  107. package/src/FibonacciRetracement.tsx +328 -0
  108. package/src/GannFan.tsx +233 -0
  109. package/src/InteractiveText.tsx +182 -0
  110. package/src/InteractiveYCoordinate.tsx +199 -0
  111. package/src/StandardDeviationChannel.tsx +269 -0
  112. package/src/TrendLine.tsx +294 -0
  113. package/src/ZoomButtons.tsx +165 -0
  114. package/src/components/ChannelWithArea.tsx +199 -0
  115. package/src/components/ClickableCircle.tsx +91 -0
  116. package/src/components/ClickableShape.tsx +114 -0
  117. package/src/components/GannFan.tsx +189 -0
  118. package/src/components/HoverTextNearMouse.tsx +174 -0
  119. package/src/components/InteractiveStraightLine.tsx +335 -0
  120. package/src/components/InteractiveText.tsx +146 -0
  121. package/src/components/InteractiveYCoordinate.tsx +200 -0
  122. package/src/components/LinearRegressionChannelWithArea.tsx +169 -0
  123. package/src/components/MouseLocationIndicator.tsx +128 -0
  124. package/src/components/Text.tsx +47 -0
  125. package/src/components/index.ts +11 -0
  126. package/src/index.ts +12 -0
  127. package/src/utils.ts +101 -0
  128. package/src/wrapper/EachEquidistantChannel.tsx +302 -0
  129. package/src/wrapper/EachFibRetracement.tsx +359 -0
  130. package/src/wrapper/EachGannFan.tsx +289 -0
  131. package/src/wrapper/EachInteractiveYCoordinate.tsx +198 -0
  132. package/src/wrapper/EachLinearRegressionChannel.tsx +202 -0
  133. package/src/wrapper/EachText.tsx +190 -0
  134. package/src/wrapper/EachTrendLine.tsx +331 -0
  135. package/src/wrapper/index.ts +7 -0
@@ -0,0 +1,269 @@
1
+ import * as React from "react";
2
+ import { isDefined, isNotDefined } from "@tradingaction/core";
3
+ import { getValueFromOverride, isHoverForInteractiveType, saveNodeType, terminate } from "./utils";
4
+ import { HoverTextNearMouse, MouseLocationIndicator } from "./components";
5
+ import { EachLinearRegressionChannel } from "./wrapper";
6
+
7
+ export interface StandardDeviationChannelProps {
8
+ readonly enabled: boolean;
9
+ readonly snapTo?: (datum: any) => number;
10
+ readonly onStart?: () => void;
11
+ readonly onComplete?: (e: React.MouseEvent, newChannels: any, moreProps: any) => void;
12
+ readonly onSelect?: (e: React.MouseEvent, interactives: any[], moreProps: any) => void;
13
+ readonly currentPositionStroke?: string;
14
+ readonly currentPositionStrokeWidth?: number;
15
+ readonly currentPositionOpacity?: number;
16
+ readonly currentPositionRadius?: number;
17
+ readonly appearance: {
18
+ readonly stroke?: string;
19
+ readonly strokeOpacity?: number;
20
+ readonly strokeWidth?: number;
21
+ readonly fill?: string;
22
+ readonly fillOpacity?: number;
23
+ readonly edgeStrokeWidth?: number;
24
+ readonly edgeStroke?: string;
25
+ readonly edgeFill?: string;
26
+ readonly r?: number;
27
+ };
28
+ readonly hoverText: object;
29
+ readonly channels: any[];
30
+ }
31
+
32
+ interface StandardDeviationChannelState {
33
+ current?: any;
34
+ override?: any;
35
+ }
36
+
37
+ export class StandardDeviationChannel extends React.Component<
38
+ StandardDeviationChannelProps,
39
+ StandardDeviationChannelState
40
+ > {
41
+ public static defaultProps = {
42
+ snapTo: (d: any) => d.close,
43
+ appearance: {
44
+ stroke: "#000000",
45
+ fillOpacity: 0.2,
46
+ strokeOpacity: 1,
47
+ strokeWidth: 1,
48
+ fill: "#8AAFE2",
49
+ edgeStrokeWidth: 2,
50
+ edgeStroke: "#000000",
51
+ edgeFill: "#FFFFFF",
52
+ r: 5,
53
+ },
54
+ currentPositionStroke: "#000000",
55
+ currentPositionOpacity: 1,
56
+ currentPositionStrokeWidth: 3,
57
+ currentPositionRadius: 4,
58
+ hoverText: {
59
+ ...HoverTextNearMouse.defaultProps,
60
+ enable: true,
61
+ bgHeight: "auto",
62
+ bgWidth: "auto",
63
+ text: "Click and drag the edge circles",
64
+ selectedText: "",
65
+ },
66
+ channels: [],
67
+ };
68
+
69
+ // @ts-ignore
70
+ private getSelectionState: any;
71
+ private mouseMoved: any;
72
+ private saveNodeType: any;
73
+
74
+ // @ts-ignore
75
+ private terminate: any;
76
+
77
+ public constructor(props: StandardDeviationChannelProps) {
78
+ super(props);
79
+
80
+ this.terminate = terminate.bind(this);
81
+ this.saveNodeType = saveNodeType.bind(this);
82
+ this.getSelectionState = isHoverForInteractiveType("channels").bind(this);
83
+
84
+ this.state = {};
85
+ }
86
+
87
+ public render() {
88
+ const {
89
+ appearance,
90
+ channels,
91
+ currentPositionOpacity,
92
+ currentPositionRadius = StandardDeviationChannel.defaultProps.currentPositionRadius,
93
+ currentPositionStroke,
94
+ currentPositionStrokeWidth,
95
+ enabled,
96
+ hoverText,
97
+ snapTo,
98
+ } = this.props;
99
+ const { current, override } = this.state;
100
+
101
+ const eachDefaultAppearance = {
102
+ ...StandardDeviationChannel.defaultProps.appearance,
103
+ ...appearance,
104
+ };
105
+
106
+ const hoverTextDefault = {
107
+ ...StandardDeviationChannel.defaultProps.hoverText,
108
+ ...hoverText,
109
+ };
110
+
111
+ const tempLine =
112
+ isDefined(current) && isDefined(current.end) ? (
113
+ <EachLinearRegressionChannel
114
+ interactive={false}
115
+ x1Value={current.start[0]}
116
+ x2Value={current.end[0]}
117
+ appearance={eachDefaultAppearance}
118
+ hoverText={hoverTextDefault}
119
+ />
120
+ ) : null;
121
+
122
+ return (
123
+ <g>
124
+ {channels.map((each, idx) => {
125
+ const eachAppearance = isDefined(each.appearance)
126
+ ? { ...eachDefaultAppearance, ...each.appearance }
127
+ : eachDefaultAppearance;
128
+
129
+ const eachHoverText = isDefined(each.hoverText)
130
+ ? { ...hoverTextDefault, ...each.hoverText }
131
+ : hoverTextDefault;
132
+
133
+ return (
134
+ <EachLinearRegressionChannel
135
+ key={idx}
136
+ ref={this.saveNodeType(idx)}
137
+ index={idx}
138
+ selected={each.selected}
139
+ x1Value={getValueFromOverride(override, idx, "x1Value", each.start[0])}
140
+ x2Value={getValueFromOverride(override, idx, "x2Value", each.end[0])}
141
+ appearance={eachAppearance}
142
+ snapTo={snapTo}
143
+ hoverText={eachHoverText}
144
+ onDrag={this.handleDragLine}
145
+ onDragComplete={this.handleDragLineComplete}
146
+ edgeInteractiveCursor="react-financial-charts-move-cursor"
147
+ />
148
+ );
149
+ })}
150
+ {tempLine}
151
+ <MouseLocationIndicator
152
+ enabled={enabled}
153
+ snap
154
+ snapTo={snapTo}
155
+ r={currentPositionRadius}
156
+ stroke={currentPositionStroke}
157
+ opacity={currentPositionOpacity}
158
+ strokeWidth={currentPositionStrokeWidth}
159
+ onMouseDown={this.handleStart}
160
+ onClick={this.handleEnd}
161
+ onMouseMove={this.handleDrawLine}
162
+ />
163
+ </g>
164
+ );
165
+ }
166
+
167
+ private handleEnd = (e: React.MouseEvent, xyValue: any, moreProps: any) => {
168
+ const { current } = this.state;
169
+ const { appearance, channels } = this.props;
170
+
171
+ if (this.mouseMoved && isDefined(current) && isDefined(current.start)) {
172
+ const newChannels = [
173
+ ...channels.map((d) => ({ ...d, selected: false })),
174
+ {
175
+ start: current.start,
176
+ end: xyValue,
177
+ selected: true,
178
+ appearance,
179
+ },
180
+ ];
181
+
182
+ this.setState(
183
+ {
184
+ current: null,
185
+ },
186
+ () => {
187
+ const { onComplete } = this.props;
188
+ if (onComplete !== undefined) {
189
+ onComplete(e, newChannels, moreProps);
190
+ }
191
+ },
192
+ );
193
+ }
194
+ };
195
+
196
+ private readonly handleStart = (_: React.MouseEvent, xyValue: any) => {
197
+ const { current } = this.state;
198
+
199
+ if (isNotDefined(current) || isNotDefined(current.start)) {
200
+ this.mouseMoved = false;
201
+
202
+ this.setState(
203
+ {
204
+ current: {
205
+ start: xyValue,
206
+ end: null,
207
+ },
208
+ },
209
+ () => {
210
+ const { onStart } = this.props;
211
+ if (onStart !== undefined) {
212
+ onStart();
213
+ }
214
+ },
215
+ );
216
+ }
217
+ };
218
+
219
+ private readonly handleDrawLine = (e: React.MouseEvent, xyValue: any) => {
220
+ const { current } = this.state;
221
+
222
+ if (isDefined(current) && isDefined(current.start)) {
223
+ this.mouseMoved = true;
224
+ this.setState({
225
+ current: {
226
+ start: current.start,
227
+ end: xyValue,
228
+ },
229
+ });
230
+ }
231
+ };
232
+
233
+ private readonly handleDragLineComplete = (e: React.MouseEvent, moreProps: any) => {
234
+ const { override } = this.state;
235
+ const { channels } = this.props;
236
+ if (isDefined(override)) {
237
+ const newChannels = channels.map((each, idx) =>
238
+ idx === override.index
239
+ ? {
240
+ ...each,
241
+ start: [override.x1Value, override.y1Value],
242
+ end: [override.x2Value, override.y2Value],
243
+ selected: true,
244
+ }
245
+ : each,
246
+ );
247
+ this.setState(
248
+ {
249
+ override: null,
250
+ },
251
+ () => {
252
+ const { onComplete } = this.props;
253
+ if (onComplete !== undefined) {
254
+ onComplete(e, newChannels, moreProps);
255
+ }
256
+ },
257
+ );
258
+ }
259
+ };
260
+
261
+ private readonly handleDragLine = (e: React.MouseEvent, index: number | undefined, newXYValue: any) => {
262
+ this.setState({
263
+ override: {
264
+ index,
265
+ ...newXYValue,
266
+ },
267
+ });
268
+ };
269
+ }
@@ -0,0 +1,294 @@
1
+ import * as React from "react";
2
+ import { isDefined, isNotDefined, noop, strokeDashTypes } from "@tradingaction/core";
3
+ import { getValueFromOverride, isHoverForInteractiveType, saveNodeType, terminate } from "./utils";
4
+ import { HoverTextNearMouse, MouseLocationIndicator, InteractiveStraightLine } from "./components";
5
+ import { EachTrendLine } from "./wrapper";
6
+
7
+ export interface TrendLineProps {
8
+ readonly snap: boolean;
9
+ readonly enabled: boolean;
10
+ readonly snapTo?: (datum: any) => number | number[];
11
+ readonly shouldDisableSnap?: (e: React.MouseEvent) => boolean;
12
+ readonly onStart: (e: React.MouseEvent, moreProps: any) => void;
13
+ readonly onComplete?: (e: React.MouseEvent, newTrends: any[], moreProps: any) => void;
14
+ readonly onSelect?: (e: React.MouseEvent, interactives: any[], moreProps: any) => void;
15
+ readonly onDoubleClickWhenHover?: (e: React.MouseEvent, moreProps: any, index: any) => void;
16
+ readonly onClickWhenHover?: (e: React.MouseEvent, moreProps: any, index: any) => void;
17
+ readonly onClickOutside?: (e: React.MouseEvent, moreProps: any, index: any) => void;
18
+ readonly onContextMenuWhenHover?: (e: React.MouseEvent, moreProps: any, index: any) => void;
19
+ readonly currentPositionStroke?: string;
20
+ readonly currentPositionStrokeWidth?: number;
21
+ readonly currentPositionstrokeOpacity?: number;
22
+ readonly currentPositionRadius?: number;
23
+ readonly type:
24
+ | "XLINE" // extends from -Infinity to +Infinity
25
+ | "RAY" // extends to +/-Infinity in one direction
26
+ | "LINE"; // extends between the set bounds
27
+ readonly hoverText: object;
28
+ readonly trends: any[];
29
+ readonly appearance: {
30
+ readonly strokeStyle: string;
31
+ readonly strokeWidth: number;
32
+ readonly strokeDasharray: strokeDashTypes;
33
+ readonly edgeStrokeWidth: number;
34
+ readonly edgeFill: string;
35
+ readonly edgeStroke: string;
36
+ };
37
+ }
38
+
39
+ interface TrendLineState {
40
+ current?: any;
41
+ override?: any;
42
+ trends?: any;
43
+ }
44
+
45
+ export class TrendLine extends React.Component<TrendLineProps, TrendLineState> {
46
+ public static defaultProps = {
47
+ type: "XLINE",
48
+ onStart: noop,
49
+ onSelect: noop,
50
+ onDoubleClickWhenHover: noop,
51
+ onClickWhenHover: noop,
52
+ onClickOutside: noop,
53
+ currentPositionStroke: "#000000",
54
+ currentPositionstrokeOpacity: 1,
55
+ currentPositionStrokeWidth: 3,
56
+ currentPositionRadius: 0,
57
+ shouldDisableSnap: (e: React.MouseEvent) => e.button === 2 || e.shiftKey,
58
+ hoverText: {
59
+ ...HoverTextNearMouse.defaultProps,
60
+ enable: true,
61
+ bgHeight: "auto",
62
+ bgWidth: "auto",
63
+ text: "Click to select object",
64
+ selectedText: "",
65
+ },
66
+ trends: [],
67
+ appearance: {
68
+ strokeStyle: "#000000",
69
+ strokeWidth: 1,
70
+ strokeDasharray: "Solid",
71
+ edgeStrokeWidth: 1,
72
+ edgeFill: "#FFFFFF",
73
+ edgeStroke: "#000000",
74
+ r: 6,
75
+ },
76
+ };
77
+
78
+ // @ts-ignore
79
+ private getSelectionState: any;
80
+ private mouseMoved: any;
81
+ private saveNodeType: any;
82
+ // @ts-ignore
83
+ private terminate: any;
84
+
85
+ public constructor(props: TrendLineProps) {
86
+ super(props);
87
+
88
+ this.terminate = terminate.bind(this);
89
+ this.saveNodeType = saveNodeType.bind(this);
90
+
91
+ this.getSelectionState = isHoverForInteractiveType("trends").bind(this);
92
+
93
+ this.state = {};
94
+ }
95
+
96
+ public render() {
97
+ const {
98
+ appearance,
99
+ currentPositionstrokeOpacity,
100
+ currentPositionRadius = TrendLine.defaultProps.currentPositionRadius,
101
+ currentPositionStroke,
102
+ currentPositionStrokeWidth,
103
+ enabled,
104
+ hoverText,
105
+ shouldDisableSnap,
106
+ snap,
107
+ snapTo,
108
+ trends,
109
+ type,
110
+ } = this.props;
111
+
112
+ const { current, override } = this.state;
113
+
114
+ const tempLine =
115
+ isDefined(current) && isDefined(current.end) ? (
116
+ <InteractiveStraightLine
117
+ type={type}
118
+ x1Value={current.start[0]}
119
+ y1Value={current.start[1]}
120
+ x2Value={current.end[0]}
121
+ y2Value={current.end[1]}
122
+ strokeStyle={appearance.strokeStyle}
123
+ strokeWidth={appearance.strokeWidth}
124
+ />
125
+ ) : null;
126
+
127
+ return (
128
+ <g>
129
+ {trends.map((each, idx) => {
130
+ const eachAppearance = isDefined(each.appearance)
131
+ ? { ...appearance, ...each.appearance }
132
+ : appearance;
133
+
134
+ const hoverTextWithDefault = {
135
+ ...TrendLine.defaultProps.hoverText,
136
+ ...hoverText,
137
+ };
138
+
139
+ return (
140
+ <EachTrendLine
141
+ key={idx}
142
+ ref={this.saveNodeType(idx)}
143
+ index={idx}
144
+ type={each.type}
145
+ selected={each.selected}
146
+ x1Value={getValueFromOverride(override, idx, "x1Value", each.start[0])}
147
+ y1Value={getValueFromOverride(override, idx, "y1Value", each.start[1])}
148
+ x2Value={getValueFromOverride(override, idx, "x2Value", each.end[0])}
149
+ y2Value={getValueFromOverride(override, idx, "y2Value", each.end[1])}
150
+ strokeStyle={eachAppearance.strokeStyle}
151
+ strokeWidth={eachAppearance.strokeWidth}
152
+ strokeOpacity={eachAppearance.strokeOpacity}
153
+ strokeDasharray={eachAppearance.strokeDasharray}
154
+ edgeStroke={eachAppearance.edgeStroke}
155
+ edgeFill={eachAppearance.edgeFill}
156
+ edgeStrokeWidth={eachAppearance.edgeStrokeWidth}
157
+ r={eachAppearance.r}
158
+ hoverText={hoverTextWithDefault}
159
+ onDrag={this.handleDragLine}
160
+ onDragComplete={this.handleDragLineComplete}
161
+ edgeInteractiveCursor="react-financial-charts-move-cursor"
162
+ lineInteractiveCursor="react-financial-charts-move-cursor"
163
+ onDoubleClickWhenHover={this.props.onDoubleClickWhenHover}
164
+ onClickWhenHover={this.props.onClickWhenHover}
165
+ onClickOutside={this.props.onClickOutside}
166
+ onContextMenuWhenHover={this.props.onContextMenuWhenHover}
167
+ />
168
+ );
169
+ })}
170
+ {tempLine}
171
+ <MouseLocationIndicator
172
+ enabled={enabled}
173
+ snap={snap}
174
+ shouldDisableSnap={shouldDisableSnap}
175
+ snapTo={snapTo}
176
+ r={currentPositionRadius}
177
+ stroke={currentPositionStroke}
178
+ opacity={currentPositionstrokeOpacity}
179
+ strokeWidth={currentPositionStrokeWidth}
180
+ onMouseDown={this.handleStart}
181
+ onClick={this.handleEnd}
182
+ onMouseMove={this.handleDrawLine}
183
+ />
184
+ </g>
185
+ );
186
+ }
187
+
188
+ private readonly handleEnd = (e: React.MouseEvent, xyValue: any, moreProps: any) => {
189
+ const { current } = this.state;
190
+ const { trends, appearance, type } = this.props;
191
+
192
+ if (this.mouseMoved && isDefined(current) && isDefined(current.start)) {
193
+ const newTrends = [
194
+ ...trends.map((d) => ({ ...d, selected: false })),
195
+ {
196
+ start: current.start,
197
+ end: xyValue,
198
+ selected: true,
199
+ appearance,
200
+ type,
201
+ },
202
+ ];
203
+ this.setState(
204
+ {
205
+ current: null,
206
+ trends: newTrends,
207
+ },
208
+ () => {
209
+ const { onComplete } = this.props;
210
+ if (onComplete !== undefined) {
211
+ onComplete(e, newTrends, moreProps);
212
+ }
213
+ },
214
+ );
215
+ }
216
+ };
217
+
218
+ private readonly handleStart = (e: React.MouseEvent, xyValue: any, moreProps: any) => {
219
+ const { current } = this.state;
220
+
221
+ if (isNotDefined(current) || isNotDefined(current.start)) {
222
+ this.mouseMoved = false;
223
+
224
+ this.setState(
225
+ {
226
+ current: {
227
+ start: xyValue,
228
+ end: null,
229
+ },
230
+ },
231
+ () => {
232
+ const { onStart } = this.props;
233
+ if (onStart !== undefined) {
234
+ onStart(e, moreProps);
235
+ }
236
+ },
237
+ );
238
+ }
239
+ };
240
+
241
+ private readonly handleDrawLine = (_: React.MouseEvent, xyValue: any) => {
242
+ const { current } = this.state;
243
+ if (isDefined(current) && isDefined(current.start)) {
244
+ this.mouseMoved = true;
245
+ this.setState({
246
+ current: {
247
+ start: current.start,
248
+ end: xyValue,
249
+ },
250
+ });
251
+ }
252
+ };
253
+
254
+ private readonly handleDragLineComplete = (e: React.MouseEvent, moreProps: any) => {
255
+ const { override } = this.state;
256
+ if (isDefined(override)) {
257
+ const { trends } = this.props;
258
+ const newTrends = trends.map((each, idx) =>
259
+ idx === override.index
260
+ ? {
261
+ ...each,
262
+ start: [override.x1Value, override.y1Value],
263
+ end: [override.x2Value, override.y2Value],
264
+ selected: true,
265
+ }
266
+ : {
267
+ ...each,
268
+ selected: false,
269
+ },
270
+ );
271
+
272
+ this.setState(
273
+ {
274
+ override: null,
275
+ },
276
+ () => {
277
+ const { onComplete } = this.props;
278
+ if (onComplete !== undefined) {
279
+ onComplete(e, newTrends, moreProps);
280
+ }
281
+ },
282
+ );
283
+ }
284
+ };
285
+
286
+ private readonly handleDragLine = (_: React.MouseEvent, index: number | undefined, newXYValue: any) => {
287
+ this.setState({
288
+ override: {
289
+ index,
290
+ ...newXYValue,
291
+ },
292
+ });
293
+ };
294
+ }