@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,185 @@
|
|
|
1
|
+
import * as PropTypes from "prop-types";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { isDefined, noop, getMouseCanvas, GenericChartComponent } from "@ivanmatiaspascual/core";
|
|
4
|
+
import { HoverTextNearMouse } from "./components";
|
|
5
|
+
import { getValueFromOverride, isHoverForInteractiveType, saveNodeType, terminate } from "./utils";
|
|
6
|
+
import { EachText } from "./wrapper";
|
|
7
|
+
|
|
8
|
+
interface InteractiveTextProps {
|
|
9
|
+
readonly onChoosePosition: (e: React.MouseEvent, newText: any, moreProps: any) => void;
|
|
10
|
+
readonly onDragComplete?: (e: React.MouseEvent, newTextList: any[], moreProps: any) => void;
|
|
11
|
+
readonly onSelect?: (e: React.MouseEvent, interactives: any[], moreProps: any) => void;
|
|
12
|
+
readonly defaultText: {
|
|
13
|
+
readonly bgFill: string;
|
|
14
|
+
readonly bgOpacity: number;
|
|
15
|
+
readonly bgStrokeWidth?: number;
|
|
16
|
+
readonly bgStroke?: string;
|
|
17
|
+
readonly textFill: string;
|
|
18
|
+
readonly fontFamily: string;
|
|
19
|
+
readonly fontWeight: string;
|
|
20
|
+
readonly fontStyle: string;
|
|
21
|
+
readonly fontSize: number;
|
|
22
|
+
readonly text: string;
|
|
23
|
+
};
|
|
24
|
+
readonly hoverText: object;
|
|
25
|
+
readonly textList: any[];
|
|
26
|
+
readonly enabled: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface InteractiveTextState {
|
|
30
|
+
current?: any;
|
|
31
|
+
override?: any;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export class InteractiveText extends React.Component<InteractiveTextProps, InteractiveTextState> {
|
|
35
|
+
public static defaultProps = {
|
|
36
|
+
onSelect: noop,
|
|
37
|
+
defaultText: {
|
|
38
|
+
bgFill: "#D3D3D3",
|
|
39
|
+
bgOpacity: 1,
|
|
40
|
+
bgStrokeWidth: 1,
|
|
41
|
+
textFill: "#F10040",
|
|
42
|
+
fontFamily: "-apple-system, system-ui, Roboto, 'Helvetica Neue', Ubuntu, sans-serif",
|
|
43
|
+
fontSize: 12,
|
|
44
|
+
fontStyle: "normal",
|
|
45
|
+
fontWeight: "normal",
|
|
46
|
+
text: "Lorem ipsum...",
|
|
47
|
+
},
|
|
48
|
+
hoverText: {
|
|
49
|
+
...HoverTextNearMouse.defaultProps,
|
|
50
|
+
enable: true,
|
|
51
|
+
bgHeight: "auto",
|
|
52
|
+
bgWidth: "auto",
|
|
53
|
+
text: "Click to select object",
|
|
54
|
+
selectedText: "",
|
|
55
|
+
},
|
|
56
|
+
textList: [],
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
public static contextTypes = {
|
|
60
|
+
subscribe: PropTypes.func.isRequired,
|
|
61
|
+
unsubscribe: PropTypes.func.isRequired,
|
|
62
|
+
generateSubscriptionId: PropTypes.func.isRequired,
|
|
63
|
+
chartId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// @ts-ignore
|
|
67
|
+
private getSelectionState: any;
|
|
68
|
+
private saveNodeType: any;
|
|
69
|
+
|
|
70
|
+
// @ts-ignore
|
|
71
|
+
private terminate: any;
|
|
72
|
+
|
|
73
|
+
public constructor(props: InteractiveTextProps) {
|
|
74
|
+
super(props);
|
|
75
|
+
|
|
76
|
+
this.terminate = terminate.bind(this);
|
|
77
|
+
this.saveNodeType = saveNodeType.bind(this);
|
|
78
|
+
this.getSelectionState = isHoverForInteractiveType("textList").bind(this);
|
|
79
|
+
|
|
80
|
+
this.state = {};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public render() {
|
|
84
|
+
const { textList, defaultText, hoverText } = this.props;
|
|
85
|
+
const { override } = this.state;
|
|
86
|
+
return (
|
|
87
|
+
<g>
|
|
88
|
+
{textList.map((each, idx) => {
|
|
89
|
+
const defaultHoverText = InteractiveText.defaultProps.hoverText;
|
|
90
|
+
const props = {
|
|
91
|
+
...defaultText,
|
|
92
|
+
...each,
|
|
93
|
+
hoverText: {
|
|
94
|
+
...defaultHoverText,
|
|
95
|
+
...hoverText,
|
|
96
|
+
...(each.hoverText || {}),
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
return (
|
|
100
|
+
<EachText
|
|
101
|
+
key={idx}
|
|
102
|
+
ref={this.saveNodeType(idx)}
|
|
103
|
+
index={idx}
|
|
104
|
+
{...props}
|
|
105
|
+
selected={each.selected}
|
|
106
|
+
position={getValueFromOverride(override, idx, "position", each.position)}
|
|
107
|
+
onDrag={this.handleDrag}
|
|
108
|
+
onDragComplete={this.handleDragComplete}
|
|
109
|
+
edgeInteractiveCursor="react-financial-charts-move-cursor"
|
|
110
|
+
/>
|
|
111
|
+
);
|
|
112
|
+
})}
|
|
113
|
+
<GenericChartComponent
|
|
114
|
+
onClick={this.handleDraw}
|
|
115
|
+
canvasToDraw={getMouseCanvas}
|
|
116
|
+
drawOn={["mousemove", "pan"]}
|
|
117
|
+
/>
|
|
118
|
+
;
|
|
119
|
+
</g>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
private readonly handleDraw = (e: React.MouseEvent, moreProps: any) => {
|
|
124
|
+
const { enabled } = this.props;
|
|
125
|
+
if (enabled) {
|
|
126
|
+
const {
|
|
127
|
+
mouseXY: [, mouseY],
|
|
128
|
+
chartConfig: { yScale },
|
|
129
|
+
xAccessor,
|
|
130
|
+
currentItem,
|
|
131
|
+
} = moreProps;
|
|
132
|
+
|
|
133
|
+
const { defaultText, onChoosePosition } = this.props;
|
|
134
|
+
|
|
135
|
+
if (onChoosePosition !== undefined) {
|
|
136
|
+
const xyValue = [xAccessor(currentItem), yScale.invert(mouseY)];
|
|
137
|
+
const newText = {
|
|
138
|
+
...defaultText,
|
|
139
|
+
position: xyValue,
|
|
140
|
+
};
|
|
141
|
+
onChoosePosition(e, newText, moreProps);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
private readonly handleDragComplete = (e: React.MouseEvent, moreProps: any) => {
|
|
147
|
+
const { override } = this.state;
|
|
148
|
+
if (isDefined(override)) {
|
|
149
|
+
const { textList } = this.props;
|
|
150
|
+
const newTextList = textList.map((each, idx) => {
|
|
151
|
+
const selected = idx === override.index;
|
|
152
|
+
return selected
|
|
153
|
+
? {
|
|
154
|
+
...each,
|
|
155
|
+
position: override.position,
|
|
156
|
+
selected,
|
|
157
|
+
}
|
|
158
|
+
: {
|
|
159
|
+
...each,
|
|
160
|
+
selected,
|
|
161
|
+
};
|
|
162
|
+
});
|
|
163
|
+
this.setState(
|
|
164
|
+
{
|
|
165
|
+
override: null,
|
|
166
|
+
},
|
|
167
|
+
() => {
|
|
168
|
+
const { onDragComplete } = this.props;
|
|
169
|
+
if (onDragComplete !== undefined) {
|
|
170
|
+
onDragComplete(e, newTextList, moreProps);
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
private readonly handleDrag = (_: React.MouseEvent, index: any, position: any) => {
|
|
178
|
+
this.setState({
|
|
179
|
+
override: {
|
|
180
|
+
index,
|
|
181
|
+
position,
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
};
|
|
185
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { format } from "d3-format";
|
|
2
|
+
import * as PropTypes from "prop-types";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { isDefined, strokeDashTypes } from "@ivanmatiaspascual/core";
|
|
5
|
+
import { HoverTextNearMouse } from "./components";
|
|
6
|
+
import { getValueFromOverride, isHoverForInteractiveType, saveNodeType, terminate } from "./utils";
|
|
7
|
+
import { EachInteractiveYCoordinate } from "./wrapper";
|
|
8
|
+
|
|
9
|
+
interface InteractiveYCoordinateProps {
|
|
10
|
+
readonly onChoosePosition: (e: React.MouseEvent, newText: any, moreProps: any) => void;
|
|
11
|
+
readonly onDragComplete: (e: React.MouseEvent, newAlertList: any[], moreProps: any, draggedAlert: any) => void;
|
|
12
|
+
readonly onSelect?: (e: React.MouseEvent, interactives: any[], moreProps: any) => void;
|
|
13
|
+
readonly onDelete?: (e: React.MouseEvent, yCoordinate: any, moreProps: any) => void;
|
|
14
|
+
readonly defaultPriceCoordinate: {
|
|
15
|
+
readonly bgFill: string;
|
|
16
|
+
readonly bgOpacity: number;
|
|
17
|
+
readonly stroke: string;
|
|
18
|
+
readonly strokeDasharray: strokeDashTypes;
|
|
19
|
+
readonly strokeOpacity: number;
|
|
20
|
+
readonly strokeWidth: number;
|
|
21
|
+
readonly textFill: string;
|
|
22
|
+
readonly fontFamily: string;
|
|
23
|
+
readonly fontWeight: string;
|
|
24
|
+
readonly fontStyle: string;
|
|
25
|
+
readonly fontSize: number;
|
|
26
|
+
readonly text: string;
|
|
27
|
+
readonly textBox: {
|
|
28
|
+
readonly height: number;
|
|
29
|
+
readonly left: number;
|
|
30
|
+
readonly padding: {
|
|
31
|
+
left: number;
|
|
32
|
+
right: number;
|
|
33
|
+
};
|
|
34
|
+
readonly closeIcon: {
|
|
35
|
+
padding: {
|
|
36
|
+
left: number;
|
|
37
|
+
right: number;
|
|
38
|
+
};
|
|
39
|
+
width: number;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
readonly edge: {
|
|
43
|
+
readonly stroke: string;
|
|
44
|
+
readonly strokeOpacity: number;
|
|
45
|
+
readonly strokeWidth: number;
|
|
46
|
+
readonly fill: string;
|
|
47
|
+
readonly fillOpacity: number;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
readonly hoverText: object;
|
|
51
|
+
readonly yCoordinateList: any[];
|
|
52
|
+
readonly enabled: boolean;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface InteractiveYCoordinateState {
|
|
56
|
+
current?: any;
|
|
57
|
+
override?: any;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export class InteractiveYCoordinate extends React.Component<InteractiveYCoordinateProps, InteractiveYCoordinateState> {
|
|
61
|
+
public static defaultProps = {
|
|
62
|
+
defaultPriceCoordinate: {
|
|
63
|
+
bgFill: "#FFFFFF",
|
|
64
|
+
bgOpacity: 1,
|
|
65
|
+
stroke: "#6574CD",
|
|
66
|
+
strokeOpacity: 1,
|
|
67
|
+
strokeDasharray: "ShortDash2",
|
|
68
|
+
strokeWidth: 1,
|
|
69
|
+
textFill: "#6574CD",
|
|
70
|
+
fontFamily: "-apple-system, system-ui, Roboto, 'Helvetica Neue', Ubuntu, sans-serif",
|
|
71
|
+
fontSize: 12,
|
|
72
|
+
fontStyle: "normal",
|
|
73
|
+
fontWeight: "normal",
|
|
74
|
+
text: "Alert",
|
|
75
|
+
textBox: {
|
|
76
|
+
height: 24,
|
|
77
|
+
left: 20,
|
|
78
|
+
padding: { left: 10, right: 5 },
|
|
79
|
+
closeIcon: {
|
|
80
|
+
padding: { left: 5, right: 8 },
|
|
81
|
+
width: 8,
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
edge: {
|
|
85
|
+
stroke: "#6574CD",
|
|
86
|
+
strokeOpacity: 1,
|
|
87
|
+
strokeWidth: 1,
|
|
88
|
+
fill: "#FFFFFF",
|
|
89
|
+
fillOpacity: 1,
|
|
90
|
+
orient: "right",
|
|
91
|
+
at: "right",
|
|
92
|
+
arrowWidth: 10,
|
|
93
|
+
dx: 0,
|
|
94
|
+
rectWidth: 50,
|
|
95
|
+
rectHeight: 20,
|
|
96
|
+
displayFormat: format(".2f"),
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
hoverText: {
|
|
100
|
+
...HoverTextNearMouse.defaultProps,
|
|
101
|
+
enable: true,
|
|
102
|
+
bgHeight: 18,
|
|
103
|
+
bgWidth: 175,
|
|
104
|
+
text: "Click and drag the edge circles",
|
|
105
|
+
},
|
|
106
|
+
yCoordinateList: [],
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
public static contextTypes = {
|
|
110
|
+
subscribe: PropTypes.func.isRequired,
|
|
111
|
+
unsubscribe: PropTypes.func.isRequired,
|
|
112
|
+
generateSubscriptionId: PropTypes.func.isRequired,
|
|
113
|
+
chartId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// @ts-ignore
|
|
117
|
+
private getSelectionState: any;
|
|
118
|
+
private saveNodeType: any;
|
|
119
|
+
// @ts-ignore
|
|
120
|
+
private terminate: any;
|
|
121
|
+
|
|
122
|
+
public constructor(props: InteractiveYCoordinateProps) {
|
|
123
|
+
super(props);
|
|
124
|
+
|
|
125
|
+
this.terminate = terminate.bind(this);
|
|
126
|
+
this.saveNodeType = saveNodeType.bind(this);
|
|
127
|
+
this.getSelectionState = isHoverForInteractiveType("yCoordinateList").bind(this);
|
|
128
|
+
|
|
129
|
+
this.state = {};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
public render() {
|
|
133
|
+
const { yCoordinateList } = this.props;
|
|
134
|
+
const { override } = this.state;
|
|
135
|
+
return (
|
|
136
|
+
<g>
|
|
137
|
+
{yCoordinateList.map((each, idx) => {
|
|
138
|
+
const props = each;
|
|
139
|
+
return (
|
|
140
|
+
<EachInteractiveYCoordinate
|
|
141
|
+
key={each.id}
|
|
142
|
+
ref={this.saveNodeType(idx)}
|
|
143
|
+
index={idx}
|
|
144
|
+
{...props}
|
|
145
|
+
selected={each.selected}
|
|
146
|
+
yValue={getValueFromOverride(override, idx, "yValue", each.yValue)}
|
|
147
|
+
onDelete={this.handleDelete}
|
|
148
|
+
onDrag={this.handleDrag}
|
|
149
|
+
onDragComplete={this.handleDragComplete}
|
|
150
|
+
edgeInteractiveCursor="react-financial-charts-move-cursor"
|
|
151
|
+
/>
|
|
152
|
+
);
|
|
153
|
+
})}
|
|
154
|
+
</g>
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
private readonly handleDelete = (e: React.MouseEvent, index: number | undefined, moreProps: any) => {
|
|
159
|
+
const { onDelete, yCoordinateList } = this.props;
|
|
160
|
+
if (onDelete !== undefined && index !== undefined) {
|
|
161
|
+
onDelete(e, yCoordinateList[index], moreProps);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
private readonly handleDragComplete = (e: React.MouseEvent, moreProps: any) => {
|
|
166
|
+
const { override } = this.state;
|
|
167
|
+
if (isDefined(override)) {
|
|
168
|
+
const { yCoordinateList } = this.props;
|
|
169
|
+
const newAlertList = yCoordinateList.map((each, idx) => {
|
|
170
|
+
const selected = idx === override.index;
|
|
171
|
+
return selected
|
|
172
|
+
? {
|
|
173
|
+
...each,
|
|
174
|
+
yValue: override.yValue,
|
|
175
|
+
selected,
|
|
176
|
+
}
|
|
177
|
+
: {
|
|
178
|
+
...each,
|
|
179
|
+
selected,
|
|
180
|
+
};
|
|
181
|
+
});
|
|
182
|
+
const draggedAlert = newAlertList[override.index];
|
|
183
|
+
this.setState(
|
|
184
|
+
{
|
|
185
|
+
override: null,
|
|
186
|
+
},
|
|
187
|
+
() => {
|
|
188
|
+
const { onDragComplete } = this.props;
|
|
189
|
+
if (onDragComplete !== undefined) {
|
|
190
|
+
onDragComplete(e, newAlertList, moreProps, draggedAlert);
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
private readonly handleDrag = (_: React.MouseEvent, index: any, yValue: any) => {
|
|
198
|
+
this.setState({
|
|
199
|
+
override: {
|
|
200
|
+
index,
|
|
201
|
+
yValue,
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
};
|
|
205
|
+
}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { isDefined, isNotDefined } from "@ivanmatiaspascual/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
|
+
}
|