@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.
- package/LICENSE +24 -0
- package/README.md +5 -0
- package/lib/Brush.d.ts +35 -0
- package/lib/Brush.js +103 -0
- package/lib/Brush.js.map +1 -0
- package/lib/ClickCallback.d.ts +18 -0
- package/lib/ClickCallback.js +12 -0
- package/lib/ClickCallback.js.map +1 -0
- package/lib/DrawingObjectSelector.d.ts +18 -0
- package/lib/DrawingObjectSelector.js +73 -0
- package/lib/DrawingObjectSelector.js.map +1 -0
- package/lib/EquidistantChannel.d.ts +74 -0
- package/lib/EquidistantChannel.js +149 -0
- package/lib/EquidistantChannel.js.map +1 -0
- package/lib/FibonacciRetracement.d.ts +89 -0
- package/lib/FibonacciRetracement.js +184 -0
- package/lib/FibonacciRetracement.js.map +1 -0
- package/lib/GannFan.d.ts +78 -0
- package/lib/GannFan.js +128 -0
- package/lib/GannFan.js.map +1 -0
- package/lib/InteractiveText.d.ts +65 -0
- package/lib/InteractiveText.js +83 -0
- package/lib/InteractiveText.js.map +1 -0
- package/lib/InteractiveYCoordinate.d.ts +122 -0
- package/lib/InteractiveYCoordinate.js +100 -0
- package/lib/InteractiveYCoordinate.js.map +1 -0
- package/lib/StandardDeviationChannel.d.ts +74 -0
- package/lib/StandardDeviationChannel.js +125 -0
- package/lib/StandardDeviationChannel.js.map +1 -0
- package/lib/TrendLine.d.ts +84 -0
- package/lib/TrendLine.js +128 -0
- package/lib/TrendLine.js.map +1 -0
- package/lib/ZoomButtons.d.ts +30 -0
- package/lib/ZoomButtons.js +78 -0
- package/lib/ZoomButtons.js.map +1 -0
- package/lib/components/ChannelWithArea.d.ts +30 -0
- package/lib/components/ChannelWithArea.js +126 -0
- package/lib/components/ChannelWithArea.js.map +1 -0
- package/lib/components/ClickableCircle.d.ts +26 -0
- package/lib/components/ClickableCircle.js +48 -0
- package/lib/components/ClickableCircle.js.map +1 -0
- package/lib/components/ClickableShape.d.ts +33 -0
- package/lib/components/ClickableShape.js +64 -0
- package/lib/components/ClickableShape.js.map +1 -0
- package/lib/components/GannFan.d.ts +32 -0
- package/lib/components/GannFan.js +134 -0
- package/lib/components/GannFan.js.map +1 -0
- package/lib/components/HoverTextNearMouse.d.ts +35 -0
- package/lib/components/HoverTextNearMouse.js +113 -0
- package/lib/components/HoverTextNearMouse.js.map +1 -0
- package/lib/components/InteractiveStraightLine.d.ts +61 -0
- package/lib/components/InteractiveStraightLine.js +220 -0
- package/lib/components/InteractiveStraightLine.js.map +1 -0
- package/lib/components/InteractiveText.d.ts +38 -0
- package/lib/components/InteractiveText.js +84 -0
- package/lib/components/InteractiveText.js.map +1 -0
- package/lib/components/InteractiveYCoordinate.d.ts +46 -0
- package/lib/components/InteractiveYCoordinate.js +109 -0
- package/lib/components/InteractiveYCoordinate.js.map +1 -0
- package/lib/components/LinearRegressionChannelWithArea.d.ts +31 -0
- package/lib/components/LinearRegressionChannelWithArea.js +104 -0
- package/lib/components/LinearRegressionChannelWithArea.js.map +1 -0
- package/lib/components/MouseLocationIndicator.d.ts +34 -0
- package/lib/components/MouseLocationIndicator.js +79 -0
- package/lib/components/MouseLocationIndicator.js.map +1 -0
- package/lib/components/Text.d.ts +17 -0
- package/lib/components/Text.js +26 -0
- package/lib/components/Text.js.map +1 -0
- package/lib/components/index.d.ts +11 -0
- package/lib/components/index.js +12 -0
- package/lib/components/index.js.map +1 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +13 -0
- package/lib/index.js.map +1 -0
- package/lib/utils.d.ts +7 -0
- package/lib/utils.js +84 -0
- package/lib/utils.js.map +1 -0
- package/lib/wrapper/EachEquidistantChannel.d.ts +59 -0
- package/lib/wrapper/EachEquidistantChannel.js +172 -0
- package/lib/wrapper/EachEquidistantChannel.js.map +1 -0
- package/lib/wrapper/EachFibRetracement.d.ts +81 -0
- package/lib/wrapper/EachFibRetracement.js +202 -0
- package/lib/wrapper/EachFibRetracement.js.map +1 -0
- package/lib/wrapper/EachGannFan.d.ts +81 -0
- package/lib/wrapper/EachGannFan.js +161 -0
- package/lib/wrapper/EachGannFan.js.map +1 -0
- package/lib/wrapper/EachInteractiveYCoordinate.d.ts +50 -0
- package/lib/wrapper/EachInteractiveYCoordinate.js +80 -0
- package/lib/wrapper/EachInteractiveYCoordinate.js.map +1 -0
- package/lib/wrapper/EachLinearRegressionChannel.d.ts +75 -0
- package/lib/wrapper/EachLinearRegressionChannel.js +89 -0
- package/lib/wrapper/EachLinearRegressionChannel.js.map +1 -0
- package/lib/wrapper/EachText.d.ts +59 -0
- package/lib/wrapper/EachText.js +83 -0
- package/lib/wrapper/EachText.js.map +1 -0
- package/lib/wrapper/EachTrendLine.d.ts +85 -0
- package/lib/wrapper/EachTrendLine.js +165 -0
- package/lib/wrapper/EachTrendLine.js.map +1 -0
- package/lib/wrapper/index.d.ts +7 -0
- package/lib/wrapper/index.js +8 -0
- package/lib/wrapper/index.js.map +1 -0
- package/package.json +53 -0
- package/src/Brush.tsx +172 -0
- package/src/ClickCallback.tsx +37 -0
- package/src/DrawingObjectSelector.tsx +97 -0
- package/src/EquidistantChannel.tsx +268 -0
- package/src/FibonacciRetracement.tsx +328 -0
- package/src/GannFan.tsx +233 -0
- package/src/InteractiveText.tsx +182 -0
- package/src/InteractiveYCoordinate.tsx +199 -0
- package/src/StandardDeviationChannel.tsx +269 -0
- package/src/TrendLine.tsx +294 -0
- package/src/ZoomButtons.tsx +165 -0
- package/src/components/ChannelWithArea.tsx +199 -0
- package/src/components/ClickableCircle.tsx +91 -0
- package/src/components/ClickableShape.tsx +114 -0
- package/src/components/GannFan.tsx +189 -0
- package/src/components/HoverTextNearMouse.tsx +174 -0
- package/src/components/InteractiveStraightLine.tsx +335 -0
- package/src/components/InteractiveText.tsx +146 -0
- package/src/components/InteractiveYCoordinate.tsx +200 -0
- package/src/components/LinearRegressionChannelWithArea.tsx +169 -0
- package/src/components/MouseLocationIndicator.tsx +128 -0
- package/src/components/Text.tsx +47 -0
- package/src/components/index.ts +11 -0
- package/src/index.ts +12 -0
- package/src/utils.ts +101 -0
- package/src/wrapper/EachEquidistantChannel.tsx +302 -0
- package/src/wrapper/EachFibRetracement.tsx +359 -0
- package/src/wrapper/EachGannFan.tsx +289 -0
- package/src/wrapper/EachInteractiveYCoordinate.tsx +198 -0
- package/src/wrapper/EachLinearRegressionChannel.tsx +202 -0
- package/src/wrapper/EachText.tsx +190 -0
- package/src/wrapper/EachTrendLine.tsx +331 -0
- 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
|
+
}
|