@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.
- package/CHANGELOG.md +190 -0
- 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 +83 -0
- package/lib/FibonacciRetracement.js +163 -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 +70 -0
- package/lib/InteractiveText.js +89 -0
- package/lib/InteractiveText.js.map +1 -0
- package/lib/InteractiveYCoordinate.d.ts +128 -0
- package/lib/InteractiveYCoordinate.js +106 -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 +77 -0
- package/lib/TrendLine.js +125 -0
- package/lib/TrendLine.js.map +1 -0
- package/lib/ZoomButtons.d.ts +37 -0
- package/lib/ZoomButtons.js +85 -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 +57 -0
- package/lib/components/InteractiveStraightLine.js +220 -0
- package/lib/components/InteractiveStraightLine.js.map +1 -0
- package/lib/components/InteractiveText.d.ts +37 -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 +77 -0
- package/lib/wrapper/EachFibRetracement.js +197 -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 +58 -0
- package/lib/wrapper/EachText.js +79 -0
- package/lib/wrapper/EachText.js.map +1 -0
- package/lib/wrapper/EachTrendLine.d.ts +76 -0
- package/lib/wrapper/EachTrendLine.js +141 -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 +55 -0
- package/src/Brush.tsx +177 -0
- package/src/ClickCallback.tsx +37 -0
- package/src/DrawingObjectSelector.tsx +97 -0
- package/src/EquidistantChannel.tsx +268 -0
- package/src/FibonacciRetracement.tsx +298 -0
- package/src/GannFan.tsx +233 -0
- package/src/InteractiveText.tsx +185 -0
- package/src/InteractiveYCoordinate.tsx +205 -0
- package/src/StandardDeviationChannel.tsx +269 -0
- package/src/TrendLine.tsx +283 -0
- package/src/ZoomButtons.tsx +172 -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 +317 -0
- package/src/components/InteractiveText.tsx +153 -0
- package/src/components/InteractiveYCoordinate.tsx +205 -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 +342 -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 +183 -0
- package/src/wrapper/EachTrendLine.tsx +297 -0
- package/src/wrapper/index.ts +7 -0
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { isDefined, noop } from "@ivanmatiaspascual/core";
|
|
3
|
+
import { getXValue } from "@ivanmatiaspascual/core/lib/utils/ChartDataUtil";
|
|
4
|
+
import { isHover, saveNodeType } from "../utils";
|
|
5
|
+
import { ClickableCircle, GannFan, HoverTextNearMouse } from "../components";
|
|
6
|
+
|
|
7
|
+
export interface EachGannFanProps {
|
|
8
|
+
readonly startXY: number[];
|
|
9
|
+
readonly endXY: number[];
|
|
10
|
+
readonly dy?: number;
|
|
11
|
+
readonly interactive: boolean;
|
|
12
|
+
readonly selected: boolean;
|
|
13
|
+
readonly appearance: {
|
|
14
|
+
readonly stroke: string;
|
|
15
|
+
readonly strokeWidth: number;
|
|
16
|
+
readonly edgeStroke: string;
|
|
17
|
+
readonly edgeFill: string;
|
|
18
|
+
readonly edgeStrokeWidth: number;
|
|
19
|
+
readonly r: number;
|
|
20
|
+
readonly fill: Array<string>;
|
|
21
|
+
readonly fontFamily: string;
|
|
22
|
+
readonly fontSize: number;
|
|
23
|
+
readonly fontFill: string;
|
|
24
|
+
};
|
|
25
|
+
readonly hoverText: {
|
|
26
|
+
readonly enable: boolean;
|
|
27
|
+
readonly fontFamily: string;
|
|
28
|
+
readonly fontSize: number;
|
|
29
|
+
readonly fill: string;
|
|
30
|
+
readonly text: string;
|
|
31
|
+
readonly bgFill: string;
|
|
32
|
+
readonly bgOpacity: number;
|
|
33
|
+
readonly bgWidth: number | string;
|
|
34
|
+
readonly bgHeight: number | string;
|
|
35
|
+
readonly selectedText: string;
|
|
36
|
+
};
|
|
37
|
+
readonly index?: number;
|
|
38
|
+
readonly onDrag: (e: React.MouseEvent, index: number | undefined, moreProps: any) => void;
|
|
39
|
+
readonly onDragComplete?: (e: React.MouseEvent, moreProps: any) => void;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface EachGannFanState {
|
|
43
|
+
hover: boolean;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export class EachGannFan extends React.Component<EachGannFanProps, EachGannFanState> {
|
|
47
|
+
public static defaultProps = {
|
|
48
|
+
yDisplayFormat: (d: number) => d.toFixed(2),
|
|
49
|
+
interactive: true,
|
|
50
|
+
selected: false,
|
|
51
|
+
appearance: {
|
|
52
|
+
stroke: "#000000",
|
|
53
|
+
strokeWidth: 1,
|
|
54
|
+
edgeStroke: "#000000",
|
|
55
|
+
edgeFill: "#FFFFFF",
|
|
56
|
+
edgeStrokeWidth: 1,
|
|
57
|
+
r: 5,
|
|
58
|
+
fill: [
|
|
59
|
+
"rgba(31, 119, 180, 0.2)",
|
|
60
|
+
"rgba(255, 126, 14, 0.2)",
|
|
61
|
+
"rgba(44, 160, 44, 0.2)",
|
|
62
|
+
"rgba(214, 39, 39, 0.2)",
|
|
63
|
+
"rgba(148, 103, 189, 0.2)",
|
|
64
|
+
"rgba(140, 86, 75, 0.2)",
|
|
65
|
+
"rgba(227, 119, 194, 0.2)",
|
|
66
|
+
"rgba(127, 127, 127, 0.2)",
|
|
67
|
+
],
|
|
68
|
+
fontFamily: "-apple-system, system-ui, Roboto, 'Helvetica Neue', Ubuntu, sans-serif",
|
|
69
|
+
fontSize: 10,
|
|
70
|
+
fontFill: "#000000",
|
|
71
|
+
},
|
|
72
|
+
onDrag: noop,
|
|
73
|
+
hoverText: {
|
|
74
|
+
...HoverTextNearMouse.defaultProps,
|
|
75
|
+
enable: true,
|
|
76
|
+
bgHeight: 18,
|
|
77
|
+
bgWidth: 120,
|
|
78
|
+
text: "Click to select object",
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// @ts-ignore
|
|
83
|
+
private isHover: any;
|
|
84
|
+
private dragStart: any;
|
|
85
|
+
private saveNodeType: any;
|
|
86
|
+
|
|
87
|
+
public constructor(props: EachGannFanProps) {
|
|
88
|
+
super(props);
|
|
89
|
+
|
|
90
|
+
this.isHover = isHover.bind(this);
|
|
91
|
+
this.saveNodeType = saveNodeType.bind(this);
|
|
92
|
+
|
|
93
|
+
this.state = {
|
|
94
|
+
hover: false,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public render() {
|
|
99
|
+
const { startXY, endXY } = this.props;
|
|
100
|
+
const { interactive, appearance } = this.props;
|
|
101
|
+
const { edgeFill, stroke, strokeWidth, fill } = appearance;
|
|
102
|
+
const { fontFamily, fontSize, fontFill } = appearance;
|
|
103
|
+
const { hoverText, selected } = this.props;
|
|
104
|
+
const { onDragComplete } = this.props;
|
|
105
|
+
const { hover } = this.state;
|
|
106
|
+
const { enable: hoverTextEnabled, ...restHoverTextProps } = hoverText;
|
|
107
|
+
|
|
108
|
+
const hoverHandler = interactive ? { onHover: this.handleHover, onUnHover: this.handleHover } : {};
|
|
109
|
+
|
|
110
|
+
const line1Edge =
|
|
111
|
+
isDefined(startXY) && isDefined(endXY) ? (
|
|
112
|
+
<g>
|
|
113
|
+
{this.getEdgeCircle({
|
|
114
|
+
xy: startXY,
|
|
115
|
+
dragHandler: this.handleLine1Edge1Drag,
|
|
116
|
+
cursor: "react-financial-charts-move-cursor",
|
|
117
|
+
fill: edgeFill,
|
|
118
|
+
edge: "edge1",
|
|
119
|
+
})}
|
|
120
|
+
{this.getEdgeCircle({
|
|
121
|
+
xy: endXY,
|
|
122
|
+
dragHandler: this.handleLine1Edge2Drag,
|
|
123
|
+
cursor: "react-financial-charts-move-cursor",
|
|
124
|
+
fill: edgeFill,
|
|
125
|
+
edge: "edge2",
|
|
126
|
+
})}
|
|
127
|
+
</g>
|
|
128
|
+
) : null;
|
|
129
|
+
|
|
130
|
+
return (
|
|
131
|
+
<g>
|
|
132
|
+
<GannFan
|
|
133
|
+
ref={this.saveNodeType("fan")}
|
|
134
|
+
selected={hover || selected}
|
|
135
|
+
{...hoverHandler}
|
|
136
|
+
startXY={startXY}
|
|
137
|
+
endXY={endXY}
|
|
138
|
+
strokeStyle={stroke}
|
|
139
|
+
strokeWidth={hover || selected ? strokeWidth + 1 : strokeWidth}
|
|
140
|
+
fillStyle={fill}
|
|
141
|
+
fontFamily={fontFamily}
|
|
142
|
+
fontSize={fontSize}
|
|
143
|
+
fontFill={fontFill}
|
|
144
|
+
interactiveCursorClass="react-financial-charts-move-cursor"
|
|
145
|
+
onDragStart={this.handleDragStart}
|
|
146
|
+
onDrag={this.handleFanDrag}
|
|
147
|
+
onDragComplete={onDragComplete}
|
|
148
|
+
/>
|
|
149
|
+
{line1Edge}
|
|
150
|
+
<HoverTextNearMouse show={hoverTextEnabled && hover && !selected} {...restHoverTextProps} />
|
|
151
|
+
</g>
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
private readonly getEdgeCircle = ({ xy, dragHandler, cursor, fill, edge }: any) => {
|
|
156
|
+
const { hover } = this.state;
|
|
157
|
+
const { selected, appearance } = this.props;
|
|
158
|
+
const { edgeStroke, edgeStrokeWidth, r } = appearance;
|
|
159
|
+
const { onDragComplete } = this.props;
|
|
160
|
+
|
|
161
|
+
return (
|
|
162
|
+
<ClickableCircle
|
|
163
|
+
ref={this.saveNodeType(edge)}
|
|
164
|
+
show={selected || hover}
|
|
165
|
+
cx={xy[0]}
|
|
166
|
+
cy={xy[1]}
|
|
167
|
+
r={r}
|
|
168
|
+
fillStyle={fill}
|
|
169
|
+
strokeStyle={edgeStroke}
|
|
170
|
+
strokeWidth={edgeStrokeWidth}
|
|
171
|
+
interactiveCursorClass={cursor}
|
|
172
|
+
onDragStart={this.handleDragStart}
|
|
173
|
+
onDrag={dragHandler}
|
|
174
|
+
onDragComplete={onDragComplete}
|
|
175
|
+
/>
|
|
176
|
+
);
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
private readonly handleLine1Edge2Drag = (e: React.MouseEvent, moreProps: any) => {
|
|
180
|
+
const { index, onDrag } = this.props;
|
|
181
|
+
const { endXY } = this.dragStart;
|
|
182
|
+
|
|
183
|
+
const {
|
|
184
|
+
startPos,
|
|
185
|
+
mouseXY,
|
|
186
|
+
xAccessor,
|
|
187
|
+
xScale,
|
|
188
|
+
fullData,
|
|
189
|
+
chartConfig: { yScale },
|
|
190
|
+
} = moreProps;
|
|
191
|
+
|
|
192
|
+
const dx = startPos[0] - mouseXY[0];
|
|
193
|
+
const dy = startPos[1] - mouseXY[1];
|
|
194
|
+
|
|
195
|
+
const x1 = xScale(endXY[0]);
|
|
196
|
+
const y1 = yScale(endXY[1]);
|
|
197
|
+
|
|
198
|
+
const newX1Value = getXValue(xScale, xAccessor, [x1 - dx, y1 - dy], fullData);
|
|
199
|
+
const newY1Value = yScale.invert(y1 - dy);
|
|
200
|
+
|
|
201
|
+
onDrag(e, index, {
|
|
202
|
+
startXY: this.dragStart.startXY,
|
|
203
|
+
endXY: [newX1Value, newY1Value],
|
|
204
|
+
dy: this.dragStart.dy,
|
|
205
|
+
});
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
private readonly handleLine1Edge1Drag = (e: React.MouseEvent, moreProps: any) => {
|
|
209
|
+
const { index, onDrag } = this.props;
|
|
210
|
+
const { startXY } = this.dragStart;
|
|
211
|
+
|
|
212
|
+
const {
|
|
213
|
+
startPos,
|
|
214
|
+
mouseXY,
|
|
215
|
+
xAccessor,
|
|
216
|
+
xScale,
|
|
217
|
+
fullData,
|
|
218
|
+
chartConfig: { yScale },
|
|
219
|
+
} = moreProps;
|
|
220
|
+
|
|
221
|
+
const dx = startPos[0] - mouseXY[0];
|
|
222
|
+
const dy = startPos[1] - mouseXY[1];
|
|
223
|
+
|
|
224
|
+
const x1 = xScale(startXY[0]);
|
|
225
|
+
const y1 = yScale(startXY[1]);
|
|
226
|
+
|
|
227
|
+
const newX1Value = getXValue(xScale, xAccessor, [x1 - dx, y1 - dy], fullData);
|
|
228
|
+
const newY1Value = yScale.invert(y1 - dy);
|
|
229
|
+
|
|
230
|
+
onDrag(e, index, {
|
|
231
|
+
startXY: [newX1Value, newY1Value],
|
|
232
|
+
endXY: this.dragStart.endXY,
|
|
233
|
+
dy: this.dragStart.dy,
|
|
234
|
+
});
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
private readonly handleFanDrag = (e: React.MouseEvent, moreProps: any) => {
|
|
238
|
+
const { index, onDrag } = this.props;
|
|
239
|
+
|
|
240
|
+
const { startXY, endXY } = this.dragStart;
|
|
241
|
+
|
|
242
|
+
const {
|
|
243
|
+
xScale,
|
|
244
|
+
chartConfig: { yScale },
|
|
245
|
+
xAccessor,
|
|
246
|
+
fullData,
|
|
247
|
+
} = moreProps;
|
|
248
|
+
const { startPos, mouseXY } = moreProps;
|
|
249
|
+
|
|
250
|
+
const x1 = xScale(startXY[0]);
|
|
251
|
+
const y1 = yScale(startXY[1]);
|
|
252
|
+
const x2 = xScale(endXY[0]);
|
|
253
|
+
const y2 = yScale(endXY[1]);
|
|
254
|
+
|
|
255
|
+
const dx = startPos[0] - mouseXY[0];
|
|
256
|
+
const dy = startPos[1] - mouseXY[1];
|
|
257
|
+
|
|
258
|
+
const newX1Value = getXValue(xScale, xAccessor, [x1 - dx, y1 - dy], fullData);
|
|
259
|
+
const newY1Value = yScale.invert(y1 - dy);
|
|
260
|
+
const newX2Value = getXValue(xScale, xAccessor, [x2 - dx, y2 - dy], fullData);
|
|
261
|
+
const newY2Value = yScale.invert(y2 - dy);
|
|
262
|
+
|
|
263
|
+
// const newDy = newY2Value - endXY[1] + this.dragStart.dy;
|
|
264
|
+
|
|
265
|
+
onDrag(e, index, {
|
|
266
|
+
startXY: [newX1Value, newY1Value],
|
|
267
|
+
endXY: [newX2Value, newY2Value],
|
|
268
|
+
dy: this.dragStart.dy,
|
|
269
|
+
});
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
private readonly handleDragStart = () => {
|
|
273
|
+
const { startXY, endXY, dy } = this.props;
|
|
274
|
+
|
|
275
|
+
this.dragStart = {
|
|
276
|
+
startXY,
|
|
277
|
+
endXY,
|
|
278
|
+
dy,
|
|
279
|
+
};
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
private readonly handleHover = (moreProps: any) => {
|
|
283
|
+
if (this.state.hover !== moreProps.hovering) {
|
|
284
|
+
this.setState({
|
|
285
|
+
hover: moreProps.hovering,
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { strokeDashTypes } from "@ivanmatiaspascual/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 "@ivanmatiaspascual/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
|
+
}
|