@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
package/src/index.ts ADDED
@@ -0,0 +1,12 @@
1
+ export { TrendLine } from "./TrendLine";
2
+ export { FibonacciRetracement } from "./FibonacciRetracement";
3
+ export { EquidistantChannel } from "./EquidistantChannel";
4
+ export { StandardDeviationChannel } from "./StandardDeviationChannel";
5
+ export { GannFan } from "./GannFan";
6
+ export { ClickCallback } from "./ClickCallback";
7
+ export { Brush } from "./Brush";
8
+ export { InteractiveText } from "./InteractiveText";
9
+ export { InteractiveYCoordinate } from "./InteractiveYCoordinate";
10
+ export { DrawingObjectSelector } from "./DrawingObjectSelector";
11
+ export { ZoomButtons } from "./ZoomButtons";
12
+ export * from "./utils";
package/src/utils.ts ADDED
@@ -0,0 +1,101 @@
1
+ import { isDefined, isNotDefined, mapObject } from "@tradingaction/core";
2
+
3
+ export function getValueFromOverride(override: any, index: any, key: any, defaultValue: any) {
4
+ if (isDefined(override) && override.index === index) {
5
+ return override[key];
6
+ }
7
+ return defaultValue;
8
+ }
9
+
10
+ export function terminate() {
11
+ // @ts-ignore
12
+ this.setState({
13
+ current: null,
14
+ override: null,
15
+ });
16
+ }
17
+
18
+ export function saveNodeType(type: any) {
19
+ return (node: any) => {
20
+ // @ts-ignore
21
+ if (isDefined(this.nodes)) {
22
+ // @ts-ignore
23
+ if (isNotDefined(node) && isDefined(this.nodes[type])) {
24
+ // @ts-ignore
25
+ delete this.nodes[type];
26
+ } else {
27
+ // @ts-ignore
28
+ this.nodes[type] = node;
29
+ }
30
+ } else {
31
+ // @ts-ignore
32
+ this.nodes = [];
33
+ }
34
+ };
35
+ }
36
+ export function isHoverForInteractiveType(interactiveType: any) {
37
+ return function (moreProps: any) {
38
+ // this has to be function as it is bound to this
39
+
40
+ // @ts-ignore
41
+ if (isDefined(this.nodes)) {
42
+ // @ts-ignore
43
+ const selecedNodes = this.nodes.map((node) => node.isHover(moreProps));
44
+ // @ts-ignore
45
+ const interactive = this.props[interactiveType].map((t, idx) => {
46
+ return {
47
+ ...t,
48
+ selected: selecedNodes[idx],
49
+ };
50
+ });
51
+ return interactive;
52
+ }
53
+ };
54
+ }
55
+
56
+ export function isHover(moreProps: any) {
57
+ // @ts-ignore
58
+ const hovering = mapObject(this.nodes, (node) => node.isHover(moreProps)).reduce((a, b) => {
59
+ return a || b;
60
+ });
61
+ return hovering;
62
+ }
63
+
64
+ function getMouseXY(moreProps: any, [ox, oy]: any) {
65
+ if (Array.isArray(moreProps.mouseXY)) {
66
+ const {
67
+ mouseXY: [x, y],
68
+ } = moreProps;
69
+ const mouseXY = [x - ox, y - oy];
70
+ return mouseXY;
71
+ }
72
+ return moreProps.mouseXY;
73
+ }
74
+
75
+ export function getMorePropsForChart(moreProps: any, chartId: any) {
76
+ const { chartConfig: chartConfigList } = moreProps;
77
+ const chartConfig = chartConfigList.find((each: any) => each.id === chartId);
78
+
79
+ const { origin } = chartConfig;
80
+ const mouseXY = getMouseXY(moreProps, origin);
81
+ return {
82
+ ...moreProps,
83
+ chartConfig,
84
+ mouseXY,
85
+ };
86
+ }
87
+
88
+ export function getSelected(interactives: any) {
89
+ const selected = interactives
90
+ .map((each: any) => {
91
+ const objects = each.objects.filter((obj: any) => {
92
+ return obj.selected;
93
+ });
94
+ return {
95
+ ...each,
96
+ objects,
97
+ };
98
+ })
99
+ .filter((each: any) => each.objects.length > 0);
100
+ return selected;
101
+ }
@@ -0,0 +1,302 @@
1
+ import * as React from "react";
2
+ import { isDefined, noop } from "@tradingaction/core";
3
+ import { getXValue } from "@tradingaction/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
+ }