@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,298 @@
1
+ import * as React from "react";
2
+ import { isDefined, isNotDefined, noop } from "@ivanmatiaspascual/core";
3
+ import { HoverTextNearMouse, MouseLocationIndicator } from "./components";
4
+ import { isHoverForInteractiveType, saveNodeType, terminate } from "./utils";
5
+ import { EachFibRetracement } from "./wrapper";
6
+
7
+ interface FibonacciRetracementProps {
8
+ readonly enabled: boolean;
9
+ readonly width?: number;
10
+ readonly onStart?: (moreProps: any) => void;
11
+ readonly onComplete?: (e: React.MouseEvent, newRetracements: any[], moreProps: any) => void;
12
+ readonly onSelect?: (e: React.MouseEvent, interactives: any[], moreProps: any) => void;
13
+ readonly type:
14
+ | "EXTEND" // extends from -Infinity to +Infinity
15
+ | "RAY" // extends to +/-Infinity in one direction
16
+ | "BOUND"; // extends between the set bounds
17
+ readonly hoverText: object;
18
+ readonly currentPositionStroke?: string;
19
+ readonly currentPositionStrokeWidth?: number;
20
+ readonly currentPositionOpacity?: number;
21
+ readonly currentPositionRadius?: number;
22
+ readonly retracements: any[];
23
+ readonly appearance: {
24
+ readonly stroke: string;
25
+ readonly strokeWidth: number;
26
+ readonly strokeOpacity: number;
27
+ readonly fontFamily: string;
28
+ readonly fontSize: number;
29
+ readonly fontFill: string;
30
+ readonly edgeStroke: string;
31
+ readonly edgeFill: string;
32
+ readonly nsEdgeFill: string;
33
+ readonly edgeStrokeWidth: number;
34
+ readonly r: number;
35
+ };
36
+ }
37
+
38
+ interface FibonacciRetracementState {
39
+ current?: any;
40
+ override?: any;
41
+ }
42
+
43
+ export class FibonacciRetracement extends React.Component<FibonacciRetracementProps, FibonacciRetracementState> {
44
+ public static defaultProps = {
45
+ enabled: true,
46
+ type: "RAY",
47
+ retracements: [],
48
+ onSelect: noop,
49
+ hoverText: {
50
+ ...HoverTextNearMouse.defaultProps,
51
+ enable: true,
52
+ bgHeight: "auto",
53
+ bgWidth: "auto",
54
+ text: "Click to select object",
55
+ selectedText: "",
56
+ },
57
+ currentPositionStroke: "#000000",
58
+ currentPositionOpacity: 1,
59
+ currentPositionStrokeWidth: 3,
60
+ currentPositionRadius: 4,
61
+ appearance: {
62
+ stroke: "#000000",
63
+ strokeWidth: 1,
64
+ strokeOpacity: 1,
65
+ fontFamily: "-apple-system, system-ui, Roboto, 'Helvetica Neue', Ubuntu, sans-serif",
66
+ fontSize: 11,
67
+ fontFill: "#000000",
68
+ edgeStroke: "#000000",
69
+ edgeFill: "#FFFFFF",
70
+ nsEdgeFill: "#000000",
71
+ edgeStrokeWidth: 1,
72
+ r: 5,
73
+ },
74
+ };
75
+
76
+ // @ts-ignore
77
+ private getSelectionState: any;
78
+ private mouseMoved: any;
79
+ private saveNodeType: any;
80
+ // @ts-ignore
81
+ private terminate: any;
82
+
83
+ public constructor(props: FibonacciRetracementProps) {
84
+ super(props);
85
+
86
+ this.handleEdge1Drag = this.handleEdge1Drag.bind(this);
87
+ this.handleEdge2Drag = this.handleEdge2Drag.bind(this);
88
+
89
+ this.terminate = terminate.bind(this);
90
+ this.getSelectionState = isHoverForInteractiveType("retracements").bind(this);
91
+
92
+ this.saveNodeType = saveNodeType.bind(this);
93
+ this.state = {};
94
+ }
95
+
96
+ public render() {
97
+ const { current, override } = this.state;
98
+
99
+ const {
100
+ appearance,
101
+ currentPositionStroke,
102
+ currentPositionOpacity,
103
+ currentPositionStrokeWidth,
104
+ currentPositionRadius = FibonacciRetracement.defaultProps.currentPositionRadius,
105
+ retracements,
106
+ type,
107
+ } = this.props;
108
+
109
+ const { enabled, hoverText } = this.props;
110
+ const overrideIndex = isDefined(override) ? override.index : null;
111
+ const hoverTextWidthDefault = {
112
+ ...FibonacciRetracement.defaultProps.hoverText,
113
+ ...hoverText,
114
+ };
115
+
116
+ const currentRetracement =
117
+ isDefined(current) && isDefined(current.x2) ? (
118
+ <EachFibRetracement
119
+ interactive={false}
120
+ type={type}
121
+ appearance={appearance}
122
+ hoverText={hoverTextWidthDefault}
123
+ {...current}
124
+ />
125
+ ) : null;
126
+ return (
127
+ <g>
128
+ {retracements.map((each, idx) => {
129
+ const eachAppearance = isDefined(each.appearance)
130
+ ? { ...appearance, ...each.appearance }
131
+ : appearance;
132
+
133
+ const eachHoverText = isDefined(each.hoverText)
134
+ ? { ...hoverTextWidthDefault, ...each.hoverText }
135
+ : hoverTextWidthDefault;
136
+
137
+ return (
138
+ <EachFibRetracement
139
+ key={idx}
140
+ ref={this.saveNodeType(idx)}
141
+ index={idx}
142
+ type={each.type}
143
+ selected={each.selected}
144
+ {...(idx === overrideIndex ? override : each)}
145
+ hoverText={eachHoverText}
146
+ appearance={eachAppearance}
147
+ onDrag={this.handleDrag}
148
+ onDragComplete={this.handleDragComplete}
149
+ />
150
+ );
151
+ })}
152
+ {currentRetracement}
153
+ <MouseLocationIndicator
154
+ enabled={enabled}
155
+ snap={false}
156
+ r={currentPositionRadius}
157
+ stroke={currentPositionStroke}
158
+ opacity={currentPositionOpacity}
159
+ strokeWidth={currentPositionStrokeWidth}
160
+ onMouseDown={this.handleStart}
161
+ onClick={this.handleEnd}
162
+ onMouseMove={this.handleDrawRetracement}
163
+ />
164
+ </g>
165
+ );
166
+ }
167
+
168
+ private readonly handleDrawRetracement = (_: React.MouseEvent, xyValue: any) => {
169
+ const { current } = this.state;
170
+ if (isDefined(current) && isDefined(current.x1)) {
171
+ this.mouseMoved = true;
172
+ this.setState({
173
+ current: {
174
+ ...current,
175
+ x2: xyValue[0],
176
+ y2: xyValue[1],
177
+ },
178
+ });
179
+ }
180
+ };
181
+
182
+ private readonly handleEdge1Drag = (_: React.MouseEvent, echo: any, newXYValue: any, origXYValue: any) => {
183
+ const { retracements } = this.props;
184
+ const { index } = echo;
185
+
186
+ const dx = origXYValue.x1Value - newXYValue.x1Value;
187
+
188
+ this.setState({
189
+ override: {
190
+ index,
191
+ x1: retracements[index].x1 - dx,
192
+ y1: retracements[index].y1,
193
+ x2: retracements[index].x2,
194
+ y2: retracements[index].y2,
195
+ },
196
+ });
197
+ };
198
+
199
+ private readonly handleDrag = (_: React.MouseEvent, index: any, xy: any) => {
200
+ this.setState({
201
+ override: {
202
+ index,
203
+ ...xy,
204
+ },
205
+ });
206
+ };
207
+
208
+ private readonly handleEdge2Drag = (_: React.MouseEvent, echo: any, newXYValue: any, origXYValue: any) => {
209
+ const { retracements } = this.props;
210
+ const { index } = echo;
211
+
212
+ const dx = origXYValue.x2Value - newXYValue.x2Value;
213
+
214
+ this.setState({
215
+ override: {
216
+ index,
217
+ x1: retracements[index].x1,
218
+ y1: retracements[index].y1,
219
+ x2: retracements[index].x2 - dx,
220
+ y2: retracements[index].y2,
221
+ },
222
+ });
223
+ };
224
+
225
+ private readonly handleDragComplete = (e: React.MouseEvent, moreProps: any) => {
226
+ const { retracements } = this.props;
227
+ const { override } = this.state;
228
+ if (isDefined(override)) {
229
+ const { index, ...rest } = override;
230
+
231
+ const newRetracements = retracements.map((each, idx) =>
232
+ idx === index ? { ...each, ...rest, selected: true } : each,
233
+ );
234
+ this.setState(
235
+ {
236
+ override: null,
237
+ },
238
+ () => {
239
+ const { onComplete } = this.props;
240
+ if (onComplete !== undefined) {
241
+ onComplete(e, newRetracements, moreProps);
242
+ }
243
+ },
244
+ );
245
+ }
246
+ };
247
+
248
+ private readonly handleStart = (e: React.MouseEvent, xyValue: any, moreProps: any) => {
249
+ const { current } = this.state;
250
+ if (isNotDefined(current) || isNotDefined(current.x1)) {
251
+ this.mouseMoved = false;
252
+ this.setState(
253
+ {
254
+ current: {
255
+ x1: xyValue[0],
256
+ y1: xyValue[1],
257
+ x2: null,
258
+ y2: null,
259
+ },
260
+ },
261
+ () => {
262
+ const { onStart } = this.props;
263
+ if (onStart !== undefined) {
264
+ onStart(moreProps);
265
+ }
266
+ },
267
+ );
268
+ }
269
+ };
270
+
271
+ private readonly handleEnd = (e: React.MouseEvent, xyValue: any, moreProps: any) => {
272
+ const { retracements, appearance, type } = this.props;
273
+ const { current } = this.state;
274
+
275
+ if (this.mouseMoved && isDefined(current) && isDefined(current.x1)) {
276
+ const newRetracements = retracements.concat({
277
+ ...current,
278
+ x2: xyValue[0],
279
+ y2: xyValue[1],
280
+ selected: true,
281
+ appearance,
282
+ type,
283
+ });
284
+
285
+ this.setState(
286
+ {
287
+ current: null,
288
+ },
289
+ () => {
290
+ const { onComplete } = this.props;
291
+ if (onComplete !== undefined) {
292
+ onComplete(e, newRetracements, moreProps);
293
+ }
294
+ },
295
+ );
296
+ }
297
+ };
298
+ }
@@ -0,0 +1,233 @@
1
+ import * as React from "react";
2
+ import { isDefined, isNotDefined, noop } from "@ivanmatiaspascual/core";
3
+ import { HoverTextNearMouse, MouseLocationIndicator } from "./components";
4
+ import { isHoverForInteractiveType, saveNodeType, terminate } from "./utils";
5
+ import { EachGannFan } from "./wrapper";
6
+
7
+ export interface GannFanProps {
8
+ readonly enabled: boolean;
9
+ readonly onStart?: () => void;
10
+ readonly onComplete: (e: React.MouseEvent, newfans: any[], moreProps: any) => void;
11
+ readonly onSelect?: (e: React.MouseEvent, interactives: any[], moreProps: any) => void;
12
+ readonly currentPositionStroke?: string;
13
+ readonly currentPositionStrokeWidth?: number;
14
+ readonly currentPositionOpacity?: number;
15
+ readonly currentPositionRadius?: number;
16
+ readonly appearance: {
17
+ readonly stroke: string;
18
+ readonly strokeOpacity: number;
19
+ readonly fillOpacity: number;
20
+ readonly strokeWidth: number;
21
+ readonly edgeStroke: string;
22
+ readonly edgeFill: string;
23
+ readonly edgeStrokeWidth: number;
24
+ readonly r: number;
25
+ readonly fill: string[];
26
+ readonly fontFamily: string;
27
+ readonly fontSize: number;
28
+ readonly fontFill: string;
29
+ };
30
+ readonly hoverText: object;
31
+ readonly fans: any[];
32
+ }
33
+
34
+ interface GannFanState {
35
+ current?: any;
36
+ override?: any;
37
+ }
38
+
39
+ export class GannFan extends React.Component<GannFanProps, GannFanState> {
40
+ public static defaultProps = {
41
+ appearance: {
42
+ stroke: "#000000",
43
+ fillOpacity: 0.2,
44
+ strokeOpacity: 1,
45
+ strokeWidth: 1,
46
+ edgeStroke: "#000000",
47
+ edgeFill: "#FFFFFF",
48
+ edgeStrokeWidth: 1,
49
+ r: 5,
50
+ fill: ["#e41a1c", "#377eb8", "#4daf4a", "#984ea3", "#ff7f00", "#ffff33", "#a65628", "#f781bf"],
51
+ fontFamily: "-apple-system, system-ui, Roboto, 'Helvetica Neue', Ubuntu, sans-serif",
52
+ fontSize: 12,
53
+ fontFill: "#000000",
54
+ },
55
+ onSelect: noop,
56
+ currentPositionStroke: "#000000",
57
+ currentPositionOpacity: 1,
58
+ currentPositionStrokeWidth: 3,
59
+ currentPositionRadius: 4,
60
+ hoverText: {
61
+ ...HoverTextNearMouse.defaultProps,
62
+ enable: true,
63
+ bgHeight: 18,
64
+ bgWidth: 120,
65
+ text: "Click to select object",
66
+ },
67
+ fans: [],
68
+ };
69
+
70
+ private mouseMoved: any;
71
+ // @ts-ignore
72
+ private getSelectionState: any;
73
+ private saveNodeType: any;
74
+
75
+ // @ts-ignore
76
+ private terminate: any;
77
+
78
+ public constructor(props: GannFanProps) {
79
+ super(props);
80
+
81
+ this.terminate = terminate.bind(this);
82
+ this.saveNodeType = saveNodeType.bind(this);
83
+
84
+ this.getSelectionState = isHoverForInteractiveType("fans").bind(this);
85
+
86
+ this.state = {};
87
+ }
88
+
89
+ public render() {
90
+ const {
91
+ appearance,
92
+ currentPositionOpacity,
93
+ currentPositionRadius = GannFan.defaultProps.currentPositionRadius,
94
+ currentPositionStroke,
95
+ currentPositionStrokeWidth,
96
+ enabled,
97
+ fans,
98
+ hoverText,
99
+ } = this.props;
100
+
101
+ const { current, override } = this.state;
102
+ const overrideIndex = isDefined(override) ? override.index : null;
103
+
104
+ const tempChannel =
105
+ isDefined(current) && isDefined(current.endXY) ? (
106
+ <EachGannFan interactive={false} {...current} appearance={appearance} hoverText={hoverText} />
107
+ ) : null;
108
+
109
+ return (
110
+ <g>
111
+ {fans.map((each, idx) => {
112
+ const eachAppearance = isDefined(each.appearance)
113
+ ? { ...appearance, ...each.appearance }
114
+ : appearance;
115
+
116
+ return (
117
+ <EachGannFan
118
+ key={idx}
119
+ ref={this.saveNodeType(idx)}
120
+ index={idx}
121
+ selected={each.selected}
122
+ {...(idx === overrideIndex ? override : each)}
123
+ appearance={eachAppearance}
124
+ hoverText={hoverText}
125
+ onDrag={this.handleDragFan}
126
+ onDragComplete={this.handleDragFanComplete}
127
+ />
128
+ );
129
+ })}
130
+ {tempChannel}
131
+ <MouseLocationIndicator
132
+ enabled={enabled}
133
+ snap={false}
134
+ r={currentPositionRadius}
135
+ stroke={currentPositionStroke}
136
+ opacity={currentPositionOpacity}
137
+ strokeWidth={currentPositionStrokeWidth}
138
+ onMouseDown={this.handleStart}
139
+ onClick={this.handleEnd}
140
+ onMouseMove={this.handleDrawFan}
141
+ />
142
+ </g>
143
+ );
144
+ }
145
+
146
+ private readonly handleEnd = (e: React.MouseEvent, _: any, moreProps: any) => {
147
+ const { current } = this.state;
148
+ const { fans, appearance } = this.props;
149
+
150
+ if (this.mouseMoved && isDefined(current) && isDefined(current.startXY)) {
151
+ const newfans = [
152
+ ...fans.map((d) => ({ ...d, selected: false })),
153
+ { ...current, selected: true, appearance },
154
+ ];
155
+ this.setState(
156
+ {
157
+ current: null,
158
+ },
159
+ () => {
160
+ const { onComplete } = this.props;
161
+ if (onComplete !== undefined) {
162
+ onComplete(e, newfans, moreProps);
163
+ }
164
+ },
165
+ );
166
+ }
167
+ };
168
+
169
+ private readonly handleStart = (_: React.MouseEvent, xyValue: any) => {
170
+ const { current } = this.state;
171
+
172
+ if (isNotDefined(current) || isNotDefined(current.startXY)) {
173
+ this.mouseMoved = false;
174
+
175
+ this.setState(
176
+ {
177
+ current: {
178
+ startXY: xyValue,
179
+ endXY: null,
180
+ },
181
+ },
182
+ () => {
183
+ const { onStart } = this.props;
184
+ if (onStart !== undefined) {
185
+ onStart();
186
+ }
187
+ },
188
+ );
189
+ }
190
+ };
191
+
192
+ private readonly handleDrawFan = (_: React.MouseEvent, xyValue: any) => {
193
+ const { current } = this.state;
194
+
195
+ if (isDefined(current) && isDefined(current.startXY)) {
196
+ this.mouseMoved = true;
197
+
198
+ this.setState({
199
+ current: {
200
+ startXY: current.startXY,
201
+ endXY: xyValue,
202
+ },
203
+ });
204
+ }
205
+ };
206
+
207
+ private readonly handleDragFanComplete = (e: React.MouseEvent, moreProps: any) => {
208
+ const { override } = this.state;
209
+ const { fans } = this.props;
210
+
211
+ if (isDefined(override)) {
212
+ const { index, ...rest } = override;
213
+ const newfans = fans.map((each, idx) => (idx === index ? { ...each, ...rest, selected: true } : each));
214
+ this.setState(
215
+ {
216
+ override: null,
217
+ },
218
+ () => {
219
+ this.props.onComplete(e, newfans, moreProps);
220
+ },
221
+ );
222
+ }
223
+ };
224
+
225
+ private readonly handleDragFan = (_: React.MouseEvent, index: number | undefined, newXYValue: any) => {
226
+ this.setState({
227
+ override: {
228
+ index,
229
+ ...newXYValue,
230
+ },
231
+ });
232
+ };
233
+ }