@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,198 @@
1
+ import * as React from "react";
2
+ import { strokeDashTypes } from "@tradingaction/core";
3
+ import { isHover, saveNodeType } from "../utils";
4
+ import { ClickableShape, InteractiveYCoordinate } from "../components";
5
+
6
+ export interface EachInteractiveYCoordinateProps {
7
+ readonly index?: number;
8
+ readonly draggable: boolean;
9
+ readonly yValue: number;
10
+ readonly bgFill: string;
11
+ readonly stroke: string;
12
+ readonly strokeWidth: number;
13
+ readonly strokeDasharray: strokeDashTypes;
14
+ readonly textFill: string;
15
+ readonly fontWeight: string;
16
+ readonly fontFamily: string;
17
+ readonly fontStyle: string;
18
+ readonly fontSize: number;
19
+ readonly text: string;
20
+ readonly selected: boolean;
21
+ readonly edge: object;
22
+ readonly textBox: {
23
+ readonly closeIcon: any;
24
+ readonly left: number;
25
+ readonly height: number;
26
+ readonly padding: any;
27
+ };
28
+ readonly onDrag?: (e: React.MouseEvent, index: number | undefined, moreProps: any) => void;
29
+ readonly onDragComplete?: (e: React.MouseEvent, moreProps: any) => void;
30
+ readonly onDelete?: (e: React.MouseEvent, index: number | undefined, moreProps: any) => void;
31
+ }
32
+
33
+ interface EachInteractiveYCoordinateState {
34
+ closeIconHover: boolean;
35
+ hover: boolean;
36
+ }
37
+
38
+ export class EachInteractiveYCoordinate extends React.Component<
39
+ EachInteractiveYCoordinateProps,
40
+ EachInteractiveYCoordinateState
41
+ > {
42
+ public static defaultProps = {
43
+ strokeWidth: 1,
44
+ selected: false,
45
+ draggable: false,
46
+ };
47
+
48
+ private dragStartPosition: any;
49
+ // @ts-ignore
50
+ private isHover: any;
51
+ private saveNodeType: any;
52
+
53
+ public constructor(props: EachInteractiveYCoordinateProps) {
54
+ super(props);
55
+
56
+ this.isHover = isHover.bind(this);
57
+ this.saveNodeType = saveNodeType.bind(this);
58
+
59
+ this.state = {
60
+ hover: false,
61
+ closeIconHover: false,
62
+ };
63
+ }
64
+
65
+ public render() {
66
+ const {
67
+ yValue,
68
+ bgFill,
69
+ textFill,
70
+ fontFamily,
71
+ fontSize,
72
+ fontWeight,
73
+ fontStyle,
74
+ text,
75
+ selected,
76
+ onDragComplete,
77
+ stroke,
78
+ strokeDasharray,
79
+ strokeWidth,
80
+ edge,
81
+ textBox,
82
+ draggable,
83
+ } = this.props;
84
+
85
+ const { hover, closeIconHover } = this.state;
86
+
87
+ const hoverHandler = {
88
+ onHover: this.handleHover,
89
+ onUnHover: this.handleHover,
90
+ };
91
+
92
+ const dragProps = draggable
93
+ ? {
94
+ onDragStart: this.handleDragStart,
95
+ onDrag: this.handleDrag,
96
+ onDragComplete,
97
+ }
98
+ : {};
99
+ return (
100
+ <g>
101
+ <InteractiveYCoordinate
102
+ ref={this.saveNodeType("priceCoordinate")}
103
+ selected={selected && !closeIconHover}
104
+ hovering={hover || closeIconHover}
105
+ interactiveCursorClass="react-financial-charts-move-cursor"
106
+ {...hoverHandler}
107
+ {...dragProps}
108
+ yValue={yValue}
109
+ bgFillStyle={bgFill}
110
+ textFill={textFill}
111
+ fontFamily={fontFamily}
112
+ fontStyle={fontStyle}
113
+ fontWeight={fontWeight}
114
+ fontSize={fontSize}
115
+ strokeStyle={stroke}
116
+ strokeDasharray={strokeDasharray}
117
+ strokeWidth={strokeWidth}
118
+ text={text}
119
+ textBox={textBox}
120
+ edge={edge}
121
+ />
122
+ <ClickableShape
123
+ show
124
+ hovering={closeIconHover}
125
+ text={text}
126
+ yValue={yValue}
127
+ fontFamily={fontFamily}
128
+ fontStyle={fontStyle}
129
+ fontWeight={fontWeight}
130
+ fontSize={fontSize}
131
+ textBox={textBox}
132
+ strokeStyle={stroke}
133
+ onHover={this.handleCloseIconHover}
134
+ onUnHover={this.handleCloseIconHover}
135
+ onClick={this.handleDelete}
136
+ />
137
+ </g>
138
+ );
139
+ }
140
+
141
+ private readonly handleCloseIconHover = (_: React.MouseEvent, moreProps: any) => {
142
+ if (this.state.closeIconHover !== moreProps.hovering) {
143
+ this.setState({
144
+ closeIconHover: moreProps.hovering,
145
+ });
146
+ }
147
+ };
148
+
149
+ private readonly handleHover = (e: React.MouseEvent, moreProps: any) => {
150
+ if (this.state.hover !== moreProps.hovering) {
151
+ this.setState({
152
+ hover: moreProps.hovering,
153
+ closeIconHover: moreProps.hovering ? this.state.closeIconHover : false,
154
+ });
155
+ }
156
+ };
157
+
158
+ private readonly handleDelete = (e: React.MouseEvent, moreProps: any) => {
159
+ const { index, onDelete } = this.props;
160
+ if (onDelete !== undefined) {
161
+ onDelete(e, index, moreProps);
162
+ }
163
+ };
164
+
165
+ private readonly handleDrag = (e: React.MouseEvent, moreProps: any) => {
166
+ const { index, onDrag } = this.props;
167
+ if (onDrag === undefined) {
168
+ return;
169
+ }
170
+
171
+ const {
172
+ mouseXY: [, mouseY],
173
+ chartConfig: { yScale },
174
+ } = moreProps;
175
+
176
+ const { dy } = this.dragStartPosition;
177
+
178
+ const newYValue = yScale.invert(mouseY - dy);
179
+
180
+ onDrag(e, index, newYValue);
181
+ };
182
+
183
+ private readonly handleDragStart = (_: React.MouseEvent, moreProps: any) => {
184
+ const { yValue } = this.props;
185
+ const { mouseXY } = moreProps;
186
+ const {
187
+ chartConfig: { yScale },
188
+ } = moreProps;
189
+ const [, mouseY] = mouseXY;
190
+
191
+ const dy = mouseY - yScale(yValue);
192
+
193
+ this.dragStartPosition = {
194
+ yValue,
195
+ dy,
196
+ };
197
+ };
198
+ }
@@ -0,0 +1,202 @@
1
+ import { getCurrentItem } from "@tradingaction/core/lib/utils/ChartDataUtil";
2
+ import * as React from "react";
3
+ import { isHover, saveNodeType } from "../utils";
4
+ import { HoverTextNearMouse, ClickableCircle } from "../components";
5
+ import {
6
+ edge1Provider,
7
+ edge2Provider,
8
+ LinearRegressionChannelWithArea,
9
+ } from "../components/LinearRegressionChannelWithArea";
10
+
11
+ export interface EachLinearRegressionChannelProps {
12
+ readonly defaultClassName?: string;
13
+ readonly x1Value: any;
14
+ readonly x2Value: any;
15
+ readonly index?: number;
16
+ readonly appearance: {
17
+ readonly stroke: string;
18
+ readonly strokeWidth: number;
19
+ readonly fill: string;
20
+ readonly edgeStrokeWidth: number;
21
+ readonly edgeStroke: string;
22
+ readonly edgeFill: string;
23
+ readonly r: number;
24
+ };
25
+ readonly edgeInteractiveCursor?: string;
26
+ readonly onDrag?: (e: React.MouseEvent, index: number | undefined, x1y1: { x1Value: any; x2Value: any }) => void;
27
+ readonly onDragComplete?: (e: React.MouseEvent, moreProps: any) => void;
28
+ readonly snapTo?: (datum: any) => number;
29
+ readonly interactive: boolean;
30
+ readonly selected: boolean;
31
+ readonly hoverText: {
32
+ readonly enable: boolean;
33
+ readonly fontFamily: string;
34
+ readonly fontSize: number;
35
+ readonly fill: string;
36
+ readonly text: string;
37
+ readonly bgFill: string;
38
+ readonly bgOpacity: number;
39
+ readonly bgWidth: number | string;
40
+ readonly bgHeight: number | string;
41
+ readonly selectedText: string;
42
+ };
43
+ }
44
+
45
+ interface EachLinearRegressionChannelState {
46
+ hover: boolean;
47
+ }
48
+
49
+ export class EachLinearRegressionChannel extends React.Component<
50
+ EachLinearRegressionChannelProps,
51
+ EachLinearRegressionChannelState
52
+ > {
53
+ public static defaultProps = {
54
+ appearance: {
55
+ stroke: "#000000",
56
+ strokeWidth: 1,
57
+ fill: "rgba(138, 175, 226, 0.7)",
58
+ edgeStrokeWidth: 2,
59
+ edgeStroke: "#000000",
60
+ edgeFill: "#FFFFFF",
61
+ r: 5,
62
+ },
63
+ interactive: true,
64
+ selected: false,
65
+ hoverText: {
66
+ ...HoverTextNearMouse.defaultProps,
67
+ enable: true,
68
+ bgHeight: 18,
69
+ bgWidth: 175,
70
+ text: "Click and drag the edge circles",
71
+ },
72
+ };
73
+
74
+ // @ts-ignore
75
+ private isHover: any;
76
+ private saveNodeType: any;
77
+
78
+ public constructor(props: EachLinearRegressionChannelProps) {
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 {
91
+ x1Value,
92
+ x2Value,
93
+ appearance,
94
+ edgeInteractiveCursor,
95
+ hoverText,
96
+ interactive,
97
+ selected,
98
+ onDragComplete,
99
+ } = this.props;
100
+ const { stroke, strokeWidth, fill, r, edgeStrokeWidth, edgeFill, edgeStroke } = appearance;
101
+ const { hover } = this.state;
102
+
103
+ const hoverHandler = interactive ? { onHover: this.handleHover, onUnHover: this.handleHover } : {};
104
+
105
+ const {
106
+ enable: hoverTextEnabled,
107
+ selectedText: hoverTextSelected,
108
+ text: hoverTextUnselected,
109
+ ...restHoverTextProps
110
+ } = hoverText;
111
+
112
+ return (
113
+ <g>
114
+ <LinearRegressionChannelWithArea
115
+ ref={this.saveNodeType("area")}
116
+ selected={selected || hover}
117
+ {...hoverHandler}
118
+ x1Value={x1Value}
119
+ x2Value={x2Value}
120
+ fillStyle={fill}
121
+ strokeStyle={stroke}
122
+ strokeWidth={hover || selected ? strokeWidth + 1 : strokeWidth}
123
+ />
124
+ <ClickableCircle
125
+ ref={this.saveNodeType("edge1")}
126
+ show={selected || hover}
127
+ xyProvider={edge1Provider(this.props)}
128
+ r={r}
129
+ fillStyle={edgeFill}
130
+ strokeStyle={edgeStroke}
131
+ strokeWidth={edgeStrokeWidth}
132
+ interactiveCursorClass={edgeInteractiveCursor}
133
+ onDrag={this.handleEdge1Drag}
134
+ onDragComplete={onDragComplete}
135
+ />
136
+ <ClickableCircle
137
+ ref={this.saveNodeType("edge2")}
138
+ show={selected || hover}
139
+ xyProvider={edge2Provider(this.props)}
140
+ r={r}
141
+ fillStyle={edgeFill}
142
+ strokeStyle={edgeStroke}
143
+ strokeWidth={edgeStrokeWidth}
144
+ interactiveCursorClass={edgeInteractiveCursor}
145
+ onDrag={this.handleEdge2Drag}
146
+ onDragComplete={onDragComplete}
147
+ />
148
+ <HoverTextNearMouse
149
+ show={hoverTextEnabled && hover}
150
+ {...restHoverTextProps}
151
+ text={selected ? hoverTextSelected : hoverTextUnselected}
152
+ />
153
+ </g>
154
+ );
155
+ }
156
+
157
+ private readonly handleHover = (_: React.MouseEvent, moreProps: any) => {
158
+ if (this.state.hover !== moreProps.hovering) {
159
+ this.setState({
160
+ hover: moreProps.hovering,
161
+ });
162
+ }
163
+ };
164
+
165
+ private readonly handleEdge2Drag = (e: React.MouseEvent, moreProps: any) => {
166
+ const { index, onDrag, snapTo, x1Value } = this.props;
167
+ if (onDrag === undefined) {
168
+ return;
169
+ }
170
+
171
+ const [x2Value] = getNewXY(moreProps, snapTo);
172
+
173
+ onDrag(e, index, {
174
+ x1Value,
175
+ x2Value,
176
+ });
177
+ };
178
+
179
+ private readonly handleEdge1Drag = (e: React.MouseEvent, moreProps: any) => {
180
+ const { index, onDrag, snapTo, x2Value } = this.props;
181
+ if (onDrag === undefined) {
182
+ return;
183
+ }
184
+
185
+ const [x1Value] = getNewXY(moreProps, snapTo);
186
+
187
+ onDrag(e, index, {
188
+ x1Value,
189
+ x2Value,
190
+ });
191
+ };
192
+ }
193
+
194
+ export function getNewXY(moreProps: any, snapTo: any) {
195
+ const { xScale, xAccessor, plotData, mouseXY } = moreProps;
196
+
197
+ const currentItem = getCurrentItem(xScale, xAccessor, mouseXY, plotData);
198
+ const x = xAccessor(currentItem);
199
+ const y = snapTo(currentItem);
200
+
201
+ return [x, y];
202
+ }
@@ -0,0 +1,190 @@
1
+ import * as React from "react";
2
+ import { getXValue } from "@tradingaction/core/lib/utils/ChartDataUtil";
3
+ import { isHover, saveNodeType } from "../utils";
4
+ import { HoverTextNearMouse, InteractiveText } from "../components";
5
+
6
+ export interface EachTextProps {
7
+ readonly index?: number;
8
+ readonly position?: any;
9
+ readonly bgFill: string;
10
+ readonly bgStrokeWidth: number;
11
+ readonly bgStroke?: string;
12
+ readonly textFill: string;
13
+ readonly fontWeight: string;
14
+ readonly fontFamily: string;
15
+ readonly fontStyle: string;
16
+ readonly fontSize: number;
17
+ readonly text: string;
18
+ readonly selected: boolean;
19
+ readonly onDrag?: (e: React.MouseEvent, index: number | undefined, xyValue: number[]) => void;
20
+ readonly onDragComplete?: (e: React.MouseEvent, moreProps: any) => void;
21
+ readonly onDoubleClick?: (e: React.MouseEvent, moreProps: any, index?: number) => void; //a1
22
+ readonly hoverText: {
23
+ readonly enable: boolean;
24
+ readonly fontFamily: string;
25
+ readonly fontSize: number;
26
+ readonly fill: string;
27
+ readonly text: string;
28
+ readonly selectedText: string;
29
+ readonly bgFill: string;
30
+ readonly bgOpacity: number;
31
+ readonly bgWidth: number | string;
32
+ readonly bgHeight: number | string;
33
+ };
34
+ }
35
+
36
+ interface EachTextState {
37
+ hover: boolean;
38
+ }
39
+
40
+ export class EachText extends React.Component<EachTextProps, EachTextState> {
41
+ public static defaultProps = {
42
+ bgStrokeWidth: 1,
43
+ selected: false,
44
+ hoverText: {
45
+ ...HoverTextNearMouse.defaultProps,
46
+ enable: true,
47
+ bgHeight: "auto",
48
+ bgWidth: "auto",
49
+ text: "Click to select object",
50
+ },
51
+ };
52
+
53
+ private dragStartPosition: any;
54
+ // @ts-ignore
55
+ private isHover: any;
56
+ private saveNodeType: any;
57
+
58
+ public constructor(props: EachTextProps) {
59
+ super(props);
60
+
61
+ this.handleHover = this.handleHover.bind(this);
62
+
63
+ this.handleDragStart = this.handleDragStart.bind(this);
64
+ this.handleDrag = this.handleDrag.bind(this);
65
+
66
+ this.isHover = isHover.bind(this);
67
+ this.saveNodeType = saveNodeType.bind(this);
68
+
69
+ this.state = {
70
+ hover: false,
71
+ };
72
+ }
73
+
74
+ public render() {
75
+ const {
76
+ position,
77
+ bgFill,
78
+ bgStroke,
79
+ bgStrokeWidth,
80
+ textFill,
81
+ fontFamily,
82
+ fontSize,
83
+ fontWeight,
84
+ fontStyle,
85
+ text,
86
+ hoverText,
87
+ selected,
88
+ onDragComplete,
89
+ onDoubleClick,
90
+ } = this.props;
91
+ const { hover } = this.state;
92
+
93
+ const hoverHandler = {
94
+ onHover: this.handleHover,
95
+ onUnHover: this.handleHover,
96
+ };
97
+
98
+ const {
99
+ enable: hoverTextEnabled,
100
+ selectedText: hoverTextSelected,
101
+ text: hoverTextUnselected,
102
+ ...restHoverTextProps
103
+ } = hoverText;
104
+
105
+ return (
106
+ <g>
107
+ <InteractiveText
108
+ ref={this.saveNodeType("text")}
109
+ selected={selected || hover}
110
+ interactiveCursorClass="react-financial-charts-move-cursor"
111
+ {...hoverHandler}
112
+ onDragStart={this.handleDragStart}
113
+ onDrag={this.handleDrag}
114
+ onDragComplete={onDragComplete}
115
+ onDoubleClick={(e, moreProps) => {
116
+ if (onDoubleClick) {
117
+ onDoubleClick(e, moreProps, this.props.index);
118
+ }
119
+ }}
120
+ position={position}
121
+ bgFillStyle={bgFill}
122
+ bgStroke={bgStroke || textFill}
123
+ bgStrokeWidth={bgStrokeWidth}
124
+ textFill={textFill}
125
+ fontFamily={fontFamily}
126
+ fontStyle={fontStyle}
127
+ fontWeight={fontWeight}
128
+ fontSize={fontSize}
129
+ text={text}
130
+ />
131
+ <HoverTextNearMouse
132
+ show={hoverTextEnabled && hover}
133
+ {...restHoverTextProps}
134
+ text={selected ? hoverTextSelected : hoverTextUnselected}
135
+ />
136
+ </g>
137
+ );
138
+ }
139
+
140
+ private readonly handleHover = (_: React.MouseEvent, moreProps: any) => {
141
+ if (this.state.hover !== moreProps.hovering) {
142
+ this.setState({
143
+ hover: moreProps.hovering,
144
+ });
145
+ }
146
+ };
147
+
148
+ private readonly handleDrag = (e: React.MouseEvent, moreProps: any) => {
149
+ const { index, onDrag } = this.props;
150
+ if (onDrag === undefined) {
151
+ return;
152
+ }
153
+
154
+ const {
155
+ mouseXY: [, mouseY],
156
+ chartConfig: { yScale },
157
+ xAccessor,
158
+ mouseXY,
159
+ plotData,
160
+ xScale,
161
+ } = moreProps;
162
+
163
+ const { dx, dy } = this.dragStartPosition;
164
+ const xValue = xScale.invert(xScale(getXValue(xScale, xAccessor, mouseXY, plotData)) - dx);
165
+ // xScale.invert(xScale(xAccessor(currentItem)) - dx);
166
+ const xyValue = [xValue, yScale.invert(mouseY - dy)];
167
+
168
+ onDrag(e, index, xyValue);
169
+ };
170
+
171
+ private readonly handleDragStart = (_: React.MouseEvent, moreProps: any) => {
172
+ const { position } = this.props;
173
+ const { mouseXY } = moreProps;
174
+ const {
175
+ chartConfig: { yScale },
176
+ xScale,
177
+ } = moreProps;
178
+ const [mouseX, mouseY] = mouseXY;
179
+
180
+ const [textCX, textCY] = position;
181
+ const dx = mouseX - xScale(textCX);
182
+ const dy = mouseY - yScale(textCY);
183
+
184
+ this.dragStartPosition = {
185
+ position,
186
+ dx,
187
+ dy,
188
+ };
189
+ };
190
+ }