@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,331 @@
1
+ import * as React from "react";
2
+ import { ascending as d3Ascending } from "d3-array";
3
+ import { noop, strokeDashTypes } from "@tradingaction/core";
4
+ import { getXValue } from "@tradingaction/core/lib/utils/ChartDataUtil";
5
+ import { isHover, saveNodeType } from "../utils";
6
+ import { ClickableCircle, HoverTextNearMouse, InteractiveStraightLine } from "../components";
7
+
8
+ export interface EachTrendLineProps {
9
+ readonly x1Value: any;
10
+ readonly x2Value: any;
11
+ readonly y1Value: any;
12
+ readonly y2Value: any;
13
+ readonly index?: number;
14
+ readonly type:
15
+ | "XLINE" // extends from -Infinity to +Infinity
16
+ | "RAY" // extends to +/-Infinity in one direction
17
+ | "LINE"; // extends between the set bounds
18
+ readonly onDrag: (e: React.MouseEvent, index: number | undefined, moreProps: any) => void;
19
+ readonly onEdge1Drag: any; // func
20
+ readonly onEdge2Drag: any; // func
21
+ readonly onDragComplete?: (e: React.MouseEvent, moreProps: any) => void;
22
+ readonly onSelect: (e: React.MouseEvent, interactives: any[], moreProps: any) => void;
23
+ readonly onDoubleClickWhenHover?: (e: React.MouseEvent, moreProps: any, index: any) => void;
24
+ readonly onClickWhenHover?: (e: React.MouseEvent, moreProps: any, index: any) => void;
25
+ readonly onClickOutside?: (e: React.MouseEvent, moreProps: any, index: any) => void;
26
+ readonly onContextMenuWhenHover?: (e: React.MouseEvent, moreProps: any, index: any) => void;
27
+ readonly?: (e: React.MouseEvent, moreProps: any, index: any) => void;
28
+ readonly r: number;
29
+ readonly strokeOpacity: number;
30
+ readonly defaultClassName?: string;
31
+ readonly selected?: boolean;
32
+ readonly strokeStyle: string;
33
+ readonly strokeWidth: number;
34
+ readonly strokeDasharray: strokeDashTypes;
35
+ readonly edgeStrokeWidth: number;
36
+ readonly edgeStroke: string;
37
+ readonly edgeInteractiveCursor: string;
38
+ readonly lineInteractiveCursor: string;
39
+ readonly edgeFill: string;
40
+ readonly hoverText: {
41
+ readonly enable: boolean;
42
+ readonly fontFamily: string;
43
+ readonly fontSize: number;
44
+ readonly fill: string;
45
+ readonly text: string;
46
+ readonly selectedText: string;
47
+ readonly bgFill: string;
48
+ readonly bgOpacity: number;
49
+ readonly bgWidth: number | string;
50
+ readonly bgHeight: number | string;
51
+ };
52
+ }
53
+
54
+ interface EachTrendLineState {
55
+ anchor?: string;
56
+ hover?: any;
57
+ }
58
+
59
+ export class EachTrendLine extends React.Component<EachTrendLineProps, EachTrendLineState> {
60
+ public static defaultProps = {
61
+ onDrag: noop,
62
+ onEdge1Drag: noop,
63
+ onEdge2Drag: noop,
64
+ onSelect: noop,
65
+ selected: false,
66
+ edgeStroke: "#000000",
67
+ edgeFill: "#FFFFFF",
68
+ edgeStrokeWidth: 2,
69
+ r: 5,
70
+ strokeWidth: 1,
71
+ strokeDasharray: "Solid",
72
+ hoverText: {
73
+ enable: false,
74
+ },
75
+ };
76
+
77
+ private dragStart: any;
78
+ // @ts-ignore
79
+ private isHover: any;
80
+ private saveNodeType: any;
81
+
82
+ public constructor(props: EachTrendLineProps) {
83
+ super(props);
84
+
85
+ this.isHover = isHover.bind(this);
86
+ this.saveNodeType = saveNodeType.bind(this);
87
+
88
+ this.state = {
89
+ hover: false,
90
+ };
91
+ }
92
+
93
+ public render() {
94
+ const {
95
+ x1Value,
96
+ y1Value,
97
+ x2Value,
98
+ y2Value,
99
+ type,
100
+ strokeStyle,
101
+ strokeWidth,
102
+ strokeDasharray,
103
+ r,
104
+ edgeStrokeWidth,
105
+ edgeFill,
106
+ edgeStroke,
107
+ edgeInteractiveCursor,
108
+ lineInteractiveCursor,
109
+ hoverText,
110
+ selected,
111
+ onDragComplete,
112
+ } = this.props;
113
+
114
+ const {
115
+ enable: hoverTextEnabled,
116
+ selectedText: hoverTextSelected,
117
+ text: hoverTextUnselected,
118
+ ...restHoverTextProps
119
+ } = hoverText;
120
+
121
+ const { hover, anchor } = this.state;
122
+
123
+ return (
124
+ <g>
125
+ <InteractiveStraightLine
126
+ ref={this.saveNodeType("line")}
127
+ selected={selected || hover}
128
+ onHover={this.handleHover}
129
+ onUnHover={this.handleHover}
130
+ x1Value={x1Value}
131
+ y1Value={y1Value}
132
+ x2Value={x2Value}
133
+ y2Value={y2Value}
134
+ type={type}
135
+ strokeStyle={strokeStyle}
136
+ strokeWidth={hover || selected ? strokeWidth + 1 : strokeWidth}
137
+ strokeDasharray={strokeDasharray}
138
+ interactiveCursorClass={lineInteractiveCursor}
139
+ onDragStart={this.handleLineDragStart}
140
+ onDrag={this.handleLineDrag}
141
+ onDragComplete={onDragComplete}
142
+ onDoubleClickWhenHover={this.handleDoubleClickWhenHover}
143
+ onClickWhenHover={this.handleClickWhenHover}
144
+ onClickOutside={this.handleClickOutside}
145
+ onContextMenuWhenHover={this.handleContextMenuWhenHover}
146
+ />
147
+ <ClickableCircle
148
+ ref={this.saveNodeType("edge1")}
149
+ show={selected || hover}
150
+ cx={x1Value}
151
+ cy={y1Value}
152
+ r={r}
153
+ fillStyle={edgeFill}
154
+ strokeStyle={anchor === "edge1" ? strokeStyle : edgeStroke}
155
+ strokeWidth={edgeStrokeWidth}
156
+ interactiveCursorClass={edgeInteractiveCursor}
157
+ onDragStart={this.handleEdge1DragStart}
158
+ onDrag={this.handleEdge1Drag}
159
+ onDragComplete={this.handleDragComplete}
160
+ />
161
+ <ClickableCircle
162
+ ref={this.saveNodeType("edge2")}
163
+ show={selected || hover}
164
+ cx={x2Value}
165
+ cy={y2Value}
166
+ r={r}
167
+ fillStyle={edgeFill}
168
+ strokeStyle={anchor === "edge2" ? strokeStyle : edgeStroke}
169
+ strokeWidth={edgeStrokeWidth}
170
+ interactiveCursorClass={edgeInteractiveCursor}
171
+ onDragStart={this.handleEdge2DragStart}
172
+ onDrag={this.handleEdge2Drag}
173
+ onDragComplete={this.handleDragComplete}
174
+ />
175
+ <HoverTextNearMouse
176
+ show={hoverTextEnabled && hover}
177
+ {...restHoverTextProps}
178
+ text={selected ? hoverTextSelected : hoverTextUnselected}
179
+ />
180
+ </g>
181
+ );
182
+ }
183
+
184
+ private readonly handleHover = (_: React.MouseEvent, moreProps: any) => {
185
+ if (this.state.hover !== moreProps.hovering) {
186
+ this.setState({
187
+ hover: moreProps.hovering,
188
+ });
189
+ }
190
+ };
191
+
192
+ private readonly handleEdge2Drag = (e: React.MouseEvent, moreProps: any) => {
193
+ const { index, onDrag, x1Value, y1Value } = this.props;
194
+
195
+ const [x2Value, y2Value] = getNewXY(moreProps);
196
+
197
+ onDrag(e, index, {
198
+ x1Value,
199
+ y1Value,
200
+ x2Value,
201
+ y2Value,
202
+ });
203
+ };
204
+
205
+ private readonly handleDoubleClickWhenHover = (e: React.MouseEvent, moreProps: any) => {
206
+ if (this.props.onDoubleClickWhenHover) {
207
+ const { index, onDoubleClickWhenHover } = this.props;
208
+ onDoubleClickWhenHover(e, moreProps, index);
209
+ }
210
+ };
211
+ private readonly handleClickWhenHover = (e: React.MouseEvent, moreProps: any) => {
212
+ if (this.props.onClickWhenHover) {
213
+ const { index, onClickWhenHover } = this.props;
214
+ onClickWhenHover(e, moreProps, index);
215
+ }
216
+ };
217
+ private readonly handleClickOutside = (e: React.MouseEvent, moreProps: any) => {
218
+ if (this.props.onClickOutside) {
219
+ const { index, onClickOutside } = this.props;
220
+ onClickOutside(e, moreProps, index);
221
+ }
222
+ };
223
+ private readonly handleContextMenuWhenHover = (e: React.MouseEvent, moreProps: any) => {
224
+ if (this.props.onContextMenuWhenHover) {
225
+ const { index, onContextMenuWhenHover } = this.props;
226
+ onContextMenuWhenHover(e, moreProps, index);
227
+ }
228
+ };
229
+
230
+ private readonly handleEdge1Drag = (e: React.MouseEvent, moreProps: any) => {
231
+ const { index, onDrag, x2Value, y2Value } = this.props;
232
+
233
+ const [x1Value, y1Value] = getNewXY(moreProps);
234
+
235
+ onDrag(e, index, {
236
+ x1Value,
237
+ y1Value,
238
+ x2Value,
239
+ y2Value,
240
+ });
241
+ };
242
+
243
+ private readonly handleDragComplete = (e: React.MouseEvent, moreProps: any) => {
244
+ this.setState({
245
+ anchor: undefined,
246
+ });
247
+
248
+ const { onDragComplete } = this.props;
249
+ if (onDragComplete === undefined) {
250
+ return;
251
+ }
252
+
253
+ onDragComplete(e, moreProps);
254
+ };
255
+
256
+ private readonly handleEdge2DragStart = () => {
257
+ this.setState({
258
+ anchor: "edge1",
259
+ });
260
+ };
261
+
262
+ private readonly handleEdge1DragStart = () => {
263
+ this.setState({
264
+ anchor: "edge2",
265
+ });
266
+ };
267
+
268
+ private readonly handleLineDrag = (e: React.MouseEvent, moreProps: any) => {
269
+ const { index, onDrag } = this.props;
270
+
271
+ const { x1Value, y1Value, x2Value, y2Value } = this.dragStart;
272
+
273
+ const {
274
+ xScale,
275
+ chartConfig: { yScale },
276
+ xAccessor,
277
+ fullData,
278
+ } = moreProps;
279
+ const { startPos, mouseXY } = moreProps;
280
+
281
+ const x1 = xScale(x1Value);
282
+ const y1 = yScale(y1Value);
283
+ const x2 = xScale(x2Value);
284
+ const y2 = yScale(y2Value);
285
+
286
+ const dx = startPos[0] - mouseXY[0];
287
+ const dy = startPos[1] - mouseXY[1];
288
+
289
+ const newX1Value = getXValue(xScale, xAccessor, [x1 - dx, y1 - dy], fullData);
290
+ const newY1Value = yScale.invert(y1 - dy);
291
+ const newX2Value = getXValue(xScale, xAccessor, [x2 - dx, y2 - dy], fullData);
292
+ const newY2Value = yScale.invert(y2 - dy);
293
+
294
+ onDrag(e, index, {
295
+ x1Value: newX1Value,
296
+ y1Value: newY1Value,
297
+ x2Value: newX2Value,
298
+ y2Value: newY2Value,
299
+ });
300
+ };
301
+
302
+ private readonly handleLineDragStart = () => {
303
+ const { x1Value, y1Value, x2Value, y2Value } = this.props;
304
+
305
+ this.dragStart = {
306
+ x1Value,
307
+ y1Value,
308
+ x2Value,
309
+ y2Value,
310
+ };
311
+ };
312
+ }
313
+
314
+ export function getNewXY(moreProps: any) {
315
+ const {
316
+ xScale,
317
+ chartConfig: { yScale },
318
+ xAccessor,
319
+ plotData,
320
+ mouseXY,
321
+ } = moreProps;
322
+ const mouseY = mouseXY[1];
323
+
324
+ const x = getXValue(xScale, xAccessor, mouseXY, plotData);
325
+
326
+ const [small, big] = yScale.domain().slice().sort(d3Ascending);
327
+ const y = yScale.invert(mouseY);
328
+ const newY = Math.min(Math.max(y, small), big);
329
+
330
+ return [x, newY];
331
+ }
@@ -0,0 +1,7 @@
1
+ export { EachEquidistantChannel } from "./EachEquidistantChannel";
2
+ export { EachFibRetracement } from "./EachFibRetracement";
3
+ export { EachGannFan } from "./EachGannFan";
4
+ export { EachInteractiveYCoordinate } from "./EachInteractiveYCoordinate";
5
+ export { EachLinearRegressionChannel } from "./EachLinearRegressionChannel";
6
+ export { EachText } from "./EachText";
7
+ export { EachTrendLine } from "./EachTrendLine";