@tradingaction/interactive 2.0.13 → 2.0.16
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/lib/Rectangle.d.ts +86 -0
- package/lib/Rectangle.js +129 -0
- package/lib/Rectangle.js.map +1 -0
- package/lib/components/InteractiveRectangle.d.ts +67 -0
- package/lib/components/InteractiveRectangle.js +265 -0
- package/lib/components/InteractiveRectangle.js.map +1 -0
- package/lib/components/index.d.ts +1 -0
- package/lib/components/index.js +1 -0
- package/lib/components/index.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/wrapper/EachRectangle.d.ts +88 -0
- package/lib/wrapper/EachRectangle.js +145 -0
- package/lib/wrapper/EachRectangle.js.map +1 -0
- package/lib/wrapper/index.d.ts +1 -0
- package/lib/wrapper/index.js +1 -0
- package/lib/wrapper/index.js.map +1 -1
- package/package.json +4 -4
- package/src/Rectangle.tsx +309 -0
- package/src/components/InteractiveRectangle.tsx +401 -0
- package/src/components/index.ts +1 -0
- package/src/index.ts +1 -0
- package/src/wrapper/EachRectangle.tsx +352 -0
- package/src/wrapper/index.ts +1 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { strokeDashTypes } from "@tradingaction/core";
|
|
3
|
+
export interface EachRectangleProps {
|
|
4
|
+
readonly topLeftX: any;
|
|
5
|
+
readonly topRightX: any;
|
|
6
|
+
readonly topLeftY: any;
|
|
7
|
+
readonly topRightY: any;
|
|
8
|
+
readonly bottomLeftX: any;
|
|
9
|
+
readonly bottomLeftY: any;
|
|
10
|
+
readonly bottomRightX: any;
|
|
11
|
+
readonly bottomRightY: any;
|
|
12
|
+
readonly index?: number;
|
|
13
|
+
readonly type: "XLINE" | "RAY" | "LINE";
|
|
14
|
+
readonly onDrag: (e: React.MouseEvent, index: number | undefined, moreProps: any) => void;
|
|
15
|
+
readonly onEdge1Drag: any;
|
|
16
|
+
readonly onEdge2Drag: any;
|
|
17
|
+
readonly onDragComplete?: (e: React.MouseEvent, moreProps: any) => void;
|
|
18
|
+
readonly onSelect: (e: React.MouseEvent, interactives: any[], moreProps: any) => void;
|
|
19
|
+
readonly onDoubleClickWhenHover?: (e: React.MouseEvent, moreProps: any, index: any) => void;
|
|
20
|
+
readonly onClickWhenHover?: (e: React.MouseEvent, moreProps: any, index: any) => void;
|
|
21
|
+
readonly onClickOutside?: (e: React.MouseEvent, moreProps: any, index: any) => void;
|
|
22
|
+
readonly onContextMenuWhenHover?: (e: React.MouseEvent, moreProps: any, index: any) => void;
|
|
23
|
+
readonly?: (e: React.MouseEvent, moreProps: any, index: any) => void;
|
|
24
|
+
readonly r: number;
|
|
25
|
+
readonly strokeOpacity: number;
|
|
26
|
+
readonly defaultClassName?: string;
|
|
27
|
+
readonly selected?: boolean;
|
|
28
|
+
readonly strokeStyle: string;
|
|
29
|
+
readonly strokeWidth: number;
|
|
30
|
+
readonly strokeDasharray: strokeDashTypes;
|
|
31
|
+
readonly edgeStrokeWidth: number;
|
|
32
|
+
readonly rectangleFill: string;
|
|
33
|
+
readonly edgeStroke: string;
|
|
34
|
+
readonly edgeInteractiveCursor: string;
|
|
35
|
+
readonly lineInteractiveCursor: string;
|
|
36
|
+
readonly edgeFill: string;
|
|
37
|
+
readonly hoverText: {
|
|
38
|
+
readonly enable: boolean;
|
|
39
|
+
readonly fontFamily: string;
|
|
40
|
+
readonly fontSize: number;
|
|
41
|
+
readonly fill: string;
|
|
42
|
+
readonly text: string;
|
|
43
|
+
readonly selectedText: string;
|
|
44
|
+
readonly bgFill: string;
|
|
45
|
+
readonly bgOpacity: number;
|
|
46
|
+
readonly bgWidth: number | string;
|
|
47
|
+
readonly bgHeight: number | string;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
interface EachRectangleState {
|
|
51
|
+
anchor?: string;
|
|
52
|
+
hover?: any;
|
|
53
|
+
}
|
|
54
|
+
export declare class EachRectangle extends React.Component<EachRectangleProps, EachRectangleState> {
|
|
55
|
+
static defaultProps: {
|
|
56
|
+
onDrag: () => void;
|
|
57
|
+
onEdge1Drag: () => void;
|
|
58
|
+
onEdge2Drag: () => void;
|
|
59
|
+
onSelect: () => void;
|
|
60
|
+
selected: boolean;
|
|
61
|
+
edgeStroke: string;
|
|
62
|
+
edgeFill: string;
|
|
63
|
+
edgeStrokeWidth: number;
|
|
64
|
+
rectangleFill: string;
|
|
65
|
+
r: number;
|
|
66
|
+
strokeWidth: number;
|
|
67
|
+
strokeDasharray: string;
|
|
68
|
+
hoverText: {
|
|
69
|
+
enable: boolean;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
private isHover;
|
|
73
|
+
private saveNodeType;
|
|
74
|
+
constructor(props: EachRectangleProps);
|
|
75
|
+
render(): JSX.Element;
|
|
76
|
+
private readonly handleHover;
|
|
77
|
+
private readonly handleEdge2Drag;
|
|
78
|
+
private readonly handleDoubleClickWhenHover;
|
|
79
|
+
private readonly handleClickWhenHover;
|
|
80
|
+
private readonly handleClickOutside;
|
|
81
|
+
private readonly handleContextMenuWhenHover;
|
|
82
|
+
private readonly handleEdge1Drag;
|
|
83
|
+
private readonly handleDragComplete;
|
|
84
|
+
private readonly handleEdge2DragStart;
|
|
85
|
+
private readonly handleEdge1DragStart;
|
|
86
|
+
}
|
|
87
|
+
export declare function getNewXY(moreProps: any): any[];
|
|
88
|
+
export {};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import * as React from "react";
|
|
13
|
+
import { ascending as d3Ascending } from "d3-array";
|
|
14
|
+
import { noop } from "@tradingaction/core";
|
|
15
|
+
import { getXValue } from "@tradingaction/core/lib/utils/ChartDataUtil";
|
|
16
|
+
import { isHover, saveNodeType } from "../utils";
|
|
17
|
+
import { ClickableCircle, HoverTextNearMouse, InteractiveRectangle } from "../components";
|
|
18
|
+
export class EachRectangle extends React.Component {
|
|
19
|
+
constructor(props) {
|
|
20
|
+
super(props);
|
|
21
|
+
this.handleHover = (_, moreProps) => {
|
|
22
|
+
if (this.state.hover !== moreProps.hovering) {
|
|
23
|
+
this.setState({
|
|
24
|
+
hover: moreProps.hovering,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
this.handleEdge2Drag = (e, moreProps) => {
|
|
29
|
+
const { index, onDrag, topLeftX, topLeftY } = this.props;
|
|
30
|
+
const [topRightX, topRightY] = getNewXY(moreProps);
|
|
31
|
+
onDrag(e, index, {
|
|
32
|
+
topLeftX,
|
|
33
|
+
topLeftY,
|
|
34
|
+
topRightX,
|
|
35
|
+
topRightY,
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
this.handleDoubleClickWhenHover = (e, moreProps) => {
|
|
39
|
+
if (this.props.onDoubleClickWhenHover) {
|
|
40
|
+
const { index, onDoubleClickWhenHover } = this.props;
|
|
41
|
+
onDoubleClickWhenHover(e, moreProps, index);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
this.handleClickWhenHover = (e, moreProps) => {
|
|
45
|
+
if (this.props.onClickWhenHover) {
|
|
46
|
+
const { index, onClickWhenHover } = this.props;
|
|
47
|
+
onClickWhenHover(e, moreProps, index);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
this.handleClickOutside = (e, moreProps) => {
|
|
51
|
+
if (this.props.onClickOutside) {
|
|
52
|
+
const { index, onClickOutside } = this.props;
|
|
53
|
+
onClickOutside(e, moreProps, index);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
this.handleContextMenuWhenHover = (e, moreProps) => {
|
|
57
|
+
if (this.props.onContextMenuWhenHover) {
|
|
58
|
+
const { index, onContextMenuWhenHover } = this.props;
|
|
59
|
+
onContextMenuWhenHover(e, moreProps, index);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
this.handleEdge1Drag = (e, moreProps) => {
|
|
63
|
+
const { index, onDrag, topRightX, topRightY } = this.props;
|
|
64
|
+
const [topLeftX, topLeftY] = getNewXY(moreProps);
|
|
65
|
+
onDrag(e, index, {
|
|
66
|
+
topLeftX,
|
|
67
|
+
topLeftY,
|
|
68
|
+
topRightX,
|
|
69
|
+
topRightY,
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
this.handleDragComplete = (e, moreProps) => {
|
|
73
|
+
this.setState({
|
|
74
|
+
anchor: undefined,
|
|
75
|
+
});
|
|
76
|
+
const { onDragComplete } = this.props;
|
|
77
|
+
if (onDragComplete === undefined) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
onDragComplete(e, moreProps);
|
|
81
|
+
};
|
|
82
|
+
this.handleEdge2DragStart = () => {
|
|
83
|
+
this.setState({
|
|
84
|
+
anchor: "edge1",
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
this.handleEdge1DragStart = () => {
|
|
88
|
+
this.setState({
|
|
89
|
+
anchor: "edge2",
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
this.isHover = isHover.bind(this);
|
|
93
|
+
this.saveNodeType = saveNodeType.bind(this);
|
|
94
|
+
this.state = {
|
|
95
|
+
hover: false,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
render() {
|
|
99
|
+
const { topLeftX, topLeftY, topRightX, topRightY, bottomLeftX, bottomLeftY, bottomRightX, bottomRightY, type, strokeStyle, strokeWidth, strokeDasharray, r, edgeStrokeWidth, edgeFill, edgeStroke, edgeInteractiveCursor, rectangleFill, lineInteractiveCursor, //may need adjustment in future
|
|
100
|
+
hoverText, selected,
|
|
101
|
+
// onDragComplete, //code: drag_disabled_for_now
|
|
102
|
+
} = this.props;
|
|
103
|
+
const { enable: hoverTextEnabled, selectedText: hoverTextSelected, text: hoverTextUnselected } = hoverText, restHoverTextProps = __rest(hoverText, ["enable", "selectedText", "text"]);
|
|
104
|
+
const { hover, anchor } = this.state;
|
|
105
|
+
return (React.createElement("g", null,
|
|
106
|
+
React.createElement(InteractiveRectangle, { ref: this.saveNodeType("line"), selected: selected || hover, onHover: this.handleHover, onUnHover: this.handleHover, topLeftX: topLeftX, topLeftY: topLeftY, topRightX: topRightX, topRightY: topRightY, bottomLeftX: bottomLeftX, bottomLeftY: bottomLeftY, bottomRightX: bottomRightX, bottomRightY: bottomRightY, type: type, strokeStyle: strokeStyle, strokeWidth: hover || selected ? strokeWidth + 1 : strokeWidth, rectangleFill: rectangleFill, strokeDasharray: strokeDasharray, interactiveCursorClass: lineInteractiveCursor,
|
|
107
|
+
////////////////////////////////////////////////////////////////
|
|
108
|
+
// code: drag_disabled_for_now
|
|
109
|
+
// onDragStart={this.handleLineDragStart}
|
|
110
|
+
// onDrag={this.handleLineDrag}
|
|
111
|
+
// onDragComplete={onDragComplete}
|
|
112
|
+
////////////////////////////////////////////////////////////////
|
|
113
|
+
onDoubleClickWhenHover: this.handleDoubleClickWhenHover, onClickWhenHover: this.handleClickWhenHover, onClickOutside: this.handleClickOutside, onContextMenuWhenHover: this.handleContextMenuWhenHover }),
|
|
114
|
+
React.createElement(ClickableCircle, { ref: this.saveNodeType("edge1"), show: selected || hover, cx: topLeftX, cy: topLeftY, r: r, fillStyle: edgeFill, strokeStyle: anchor === "edge1" ? strokeStyle : edgeStroke, strokeWidth: edgeStrokeWidth, interactiveCursorClass: edgeInteractiveCursor, onDragStart: this.handleEdge1DragStart, onDrag: this.handleEdge1Drag, onDragComplete: this.handleDragComplete }),
|
|
115
|
+
React.createElement(ClickableCircle, { ref: this.saveNodeType("edge2"), show: selected || hover, cx: topRightX, cy: topRightY, r: r, fillStyle: edgeFill, strokeStyle: anchor === "edge2" ? strokeStyle : edgeStroke, strokeWidth: edgeStrokeWidth, interactiveCursorClass: edgeInteractiveCursor, onDragStart: this.handleEdge2DragStart, onDrag: this.handleEdge2Drag, onDragComplete: this.handleDragComplete }),
|
|
116
|
+
React.createElement(HoverTextNearMouse, Object.assign({ show: hoverTextEnabled && hover }, restHoverTextProps, { text: selected ? hoverTextSelected : hoverTextUnselected }))));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
EachRectangle.defaultProps = {
|
|
120
|
+
onDrag: noop,
|
|
121
|
+
onEdge1Drag: noop,
|
|
122
|
+
onEdge2Drag: noop,
|
|
123
|
+
onSelect: noop,
|
|
124
|
+
selected: false,
|
|
125
|
+
edgeStroke: "#000000",
|
|
126
|
+
edgeFill: "#FFFFFF",
|
|
127
|
+
edgeStrokeWidth: 2,
|
|
128
|
+
rectangleFill: 'transparent',
|
|
129
|
+
r: 5,
|
|
130
|
+
strokeWidth: 1,
|
|
131
|
+
strokeDasharray: "Solid",
|
|
132
|
+
hoverText: {
|
|
133
|
+
enable: false,
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
export function getNewXY(moreProps) {
|
|
137
|
+
const { xScale, chartConfig: { yScale }, xAccessor, plotData, mouseXY, } = moreProps;
|
|
138
|
+
const mouseY = mouseXY[1];
|
|
139
|
+
const x = getXValue(xScale, xAccessor, mouseXY, plotData);
|
|
140
|
+
const [small, big] = yScale.domain().slice().sort(d3Ascending);
|
|
141
|
+
const y = yScale.invert(mouseY);
|
|
142
|
+
const newY = Math.min(Math.max(y, small), big);
|
|
143
|
+
return [x, newY];
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=EachRectangle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EachR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aAAa,EAAE,aAAa;IAC5B,CAAC,EAAE,CAAC;IACJ,WAAW,EAAE,CAAC;IACd,eAAe,EAAE,OAAO;IACxB,SAAS,EAAE;QACP,MAAM,EAAE,KAAK;KAChB;CACJ,CAAC;AA8PN,MAAM,UAAU,QAAQ,CAAC,SAAc;IACnC,MAAM,EACF,MAAM,EACN,WAAW,EAAE,EAAE,MAAM,EAAE,EACvB,SAAS,EACT,QAAQ,EACR,OAAO,GACV,GAAG,SAAS,CAAC;IACd,MAAM,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAE1B,MAAM,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IAE1D,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC/D,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAChC,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC;IAE/C,OAAO,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;AACrB,CAAC"}
|
package/lib/wrapper/index.d.ts
CHANGED
|
@@ -5,3 +5,4 @@ export { EachInteractiveYCoordinate } from "./EachInteractiveYCoordinate";
|
|
|
5
5
|
export { EachLinearRegressionChannel } from "./EachLinearRegressionChannel";
|
|
6
6
|
export { EachText } from "./EachText";
|
|
7
7
|
export { EachTrendLine } from "./EachTrendLine";
|
|
8
|
+
export { EachRectangle } from "./EachRectangle";
|
package/lib/wrapper/index.js
CHANGED
|
@@ -5,4 +5,5 @@ export { EachInteractiveYCoordinate } from "./EachInteractiveYCoordinate";
|
|
|
5
5
|
export { EachLinearRegressionChannel } from "./EachLinearRegressionChannel";
|
|
6
6
|
export { EachText } from "./EachText";
|
|
7
7
|
export { EachTrendLine } from "./EachTrendLine";
|
|
8
|
+
export { EachRectangle } from "./EachRectangle";
|
|
8
9
|
//# sourceMappingURL=index.js.map
|
package/lib/wrapper/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/wrapper/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/wrapper/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tradingaction/interactive",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.16",
|
|
4
4
|
"description": "Interactive features for react-financial-charts",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"watch": "tsc -p tsconfig.json --watch --preserveWatchOutput"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@tradingaction/coordinates": "^2.0.
|
|
42
|
-
"@tradingaction/core": "^2.0.
|
|
41
|
+
"@tradingaction/coordinates": "^2.0.15",
|
|
42
|
+
"@tradingaction/core": "^2.0.15",
|
|
43
43
|
"d3-array": "^2.9.1",
|
|
44
44
|
"d3-format": "^2.0.0",
|
|
45
45
|
"d3-interpolate": "^2.0.1",
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"react": "^16.0.0 || ^17.0.0 || ^18.0.0",
|
|
50
50
|
"react-dom": "^16.0.0 || ^17.0.0 || ^18.0.0"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "946010fcbe99456d2e3962061540a9dc6d00eb55"
|
|
53
53
|
}
|
|
@@ -0,0 +1,309 @@
|
|
|
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, InteractiveRectangle } from "./components";
|
|
5
|
+
import { EachRectangle } from "./wrapper";
|
|
6
|
+
|
|
7
|
+
export interface RectangleProps {
|
|
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
|
+
readonly rectangleFill: string;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface RectangleState {
|
|
41
|
+
current?: any;
|
|
42
|
+
override?: any;
|
|
43
|
+
trends?: any;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export class Rectangle extends React.Component<RectangleProps, RectangleState> {
|
|
47
|
+
public static defaultProps = {
|
|
48
|
+
type: "XLINE",
|
|
49
|
+
onStart: noop,
|
|
50
|
+
onSelect: noop,
|
|
51
|
+
onDoubleClickWhenHover: noop,
|
|
52
|
+
onClickWhenHover: noop,
|
|
53
|
+
onClickOutside: noop,
|
|
54
|
+
currentPositionStroke: "#000000",
|
|
55
|
+
currentPositionstrokeOpacity: 1,
|
|
56
|
+
currentPositionStrokeWidth: 3,
|
|
57
|
+
currentPositionRadius: 0,
|
|
58
|
+
shouldDisableSnap: (e: React.MouseEvent) => e.button === 2 || e.shiftKey,
|
|
59
|
+
hoverText: {
|
|
60
|
+
...HoverTextNearMouse.defaultProps,
|
|
61
|
+
enable: true,
|
|
62
|
+
bgHeight: "auto",
|
|
63
|
+
bgWidth: "auto",
|
|
64
|
+
text: "Click to select object",
|
|
65
|
+
selectedText: "",
|
|
66
|
+
},
|
|
67
|
+
trends: [],
|
|
68
|
+
appearance: {
|
|
69
|
+
strokeStyle: "#000000",
|
|
70
|
+
strokeWidth: 1,
|
|
71
|
+
strokeDasharray: "Solid",
|
|
72
|
+
edgeStrokeWidth: 1,
|
|
73
|
+
edgeFill: "#FFFFFF",
|
|
74
|
+
edgeStroke: "#000000",
|
|
75
|
+
rectangleFill: "transparent",
|
|
76
|
+
r: 6,
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
private getSelectionState: any;
|
|
82
|
+
private mouseMoved: any;
|
|
83
|
+
private saveNodeType: any;
|
|
84
|
+
// @ts-ignore
|
|
85
|
+
private terminate: any;
|
|
86
|
+
|
|
87
|
+
public constructor(props: RectangleProps) {
|
|
88
|
+
super(props);
|
|
89
|
+
|
|
90
|
+
this.terminate = terminate.bind(this);
|
|
91
|
+
this.saveNodeType = saveNodeType.bind(this);
|
|
92
|
+
|
|
93
|
+
this.getSelectionState = isHoverForInteractiveType("trends").bind(this);
|
|
94
|
+
|
|
95
|
+
this.state = {};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public render() {
|
|
99
|
+
const {
|
|
100
|
+
appearance,
|
|
101
|
+
currentPositionstrokeOpacity,
|
|
102
|
+
currentPositionRadius = Rectangle.defaultProps.currentPositionRadius,
|
|
103
|
+
currentPositionStroke,
|
|
104
|
+
currentPositionStrokeWidth,
|
|
105
|
+
enabled,
|
|
106
|
+
hoverText,
|
|
107
|
+
shouldDisableSnap,
|
|
108
|
+
snap,
|
|
109
|
+
snapTo,
|
|
110
|
+
trends,
|
|
111
|
+
type,
|
|
112
|
+
} = this.props;
|
|
113
|
+
|
|
114
|
+
const { current, override } = this.state;
|
|
115
|
+
|
|
116
|
+
const tempLine =
|
|
117
|
+
isDefined(current) && isDefined(current.topRight) ? (
|
|
118
|
+
<InteractiveRectangle
|
|
119
|
+
type={type}
|
|
120
|
+
topLeftX={current.topLeft[0]}
|
|
121
|
+
topLeftY={current.topLeft[1]}
|
|
122
|
+
topRightX={current.topRight[0]}
|
|
123
|
+
topRightY={current.topRight[1]}
|
|
124
|
+
|
|
125
|
+
bottomLeftX={current.bottomLeft[0]}
|
|
126
|
+
bottomLeftY={current.bottomLeft[1]}
|
|
127
|
+
bottomRightX={current.bottomRight[0]}
|
|
128
|
+
bottomRightY={current.bottomRight[1]}
|
|
129
|
+
|
|
130
|
+
strokeStyle={appearance.strokeStyle}
|
|
131
|
+
strokeWidth={appearance.strokeWidth}
|
|
132
|
+
/>
|
|
133
|
+
) : null;
|
|
134
|
+
|
|
135
|
+
return (
|
|
136
|
+
<g>
|
|
137
|
+
{trends.map((each, idx) => {
|
|
138
|
+
const eachAppearance = isDefined(each.appearance)
|
|
139
|
+
? { ...appearance, ...each.appearance }
|
|
140
|
+
: appearance;
|
|
141
|
+
|
|
142
|
+
const hoverTextWithDefault = {
|
|
143
|
+
...Rectangle.defaultProps.hoverText,
|
|
144
|
+
...hoverText,
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
return (
|
|
148
|
+
<EachRectangle
|
|
149
|
+
key={idx}
|
|
150
|
+
ref={this.saveNodeType(idx)}
|
|
151
|
+
index={idx}
|
|
152
|
+
type={each.type}
|
|
153
|
+
selected={each.selected}
|
|
154
|
+
topLeftX={getValueFromOverride(override, idx, "topLeftX", each.topLeft[0])}
|
|
155
|
+
topLeftY={getValueFromOverride(override, idx, "topLeftY", each.topLeft[1])}
|
|
156
|
+
topRightX={getValueFromOverride(override, idx, "topRightX", each.topRight[0])}
|
|
157
|
+
topRightY={getValueFromOverride(override, idx, "topRightY", each.topRight[1])}
|
|
158
|
+
|
|
159
|
+
bottomLeftX={getValueFromOverride(override, idx, "bottomLeftX", each.bottomLeft[0])}
|
|
160
|
+
bottomLeftY={getValueFromOverride(override, idx, "bottomLeftY", each.bottomLeft[1])}
|
|
161
|
+
bottomRightX={getValueFromOverride(override, idx, "bottomRightX", each.bottomRight[0])}
|
|
162
|
+
bottomRightY={getValueFromOverride(override, idx, "bottomRightY", each.bottomRight[1])}
|
|
163
|
+
|
|
164
|
+
strokeStyle={eachAppearance.strokeStyle}
|
|
165
|
+
strokeWidth={eachAppearance.strokeWidth}
|
|
166
|
+
strokeOpacity={eachAppearance.strokeOpacity}
|
|
167
|
+
strokeDasharray={eachAppearance.strokeDasharray}
|
|
168
|
+
edgeStroke={eachAppearance.edgeStroke}
|
|
169
|
+
edgeFill={eachAppearance.edgeFill}
|
|
170
|
+
edgeStrokeWidth={eachAppearance.edgeStrokeWidth}
|
|
171
|
+
rectangleFill={eachAppearance.rectangleFill}
|
|
172
|
+
r={eachAppearance.r}
|
|
173
|
+
hoverText={hoverTextWithDefault}
|
|
174
|
+
onDrag={this.handleDragLine}
|
|
175
|
+
onDragComplete={this.handleDragLineComplete}
|
|
176
|
+
edgeInteractiveCursor="react-financial-charts-move-cursor"
|
|
177
|
+
lineInteractiveCursor="react-financial-charts-move-cursor"
|
|
178
|
+
onDoubleClickWhenHover={this.props.onDoubleClickWhenHover}
|
|
179
|
+
onClickWhenHover={this.props.onClickWhenHover}
|
|
180
|
+
onClickOutside={this.props.onClickOutside}
|
|
181
|
+
onContextMenuWhenHover={this.props.onContextMenuWhenHover}
|
|
182
|
+
/>
|
|
183
|
+
);
|
|
184
|
+
})}
|
|
185
|
+
{tempLine}
|
|
186
|
+
<MouseLocationIndicator
|
|
187
|
+
enabled={enabled}
|
|
188
|
+
snap={snap}
|
|
189
|
+
shouldDisableSnap={shouldDisableSnap}
|
|
190
|
+
snapTo={snapTo}
|
|
191
|
+
r={currentPositionRadius}
|
|
192
|
+
stroke={currentPositionStroke}
|
|
193
|
+
opacity={currentPositionstrokeOpacity}
|
|
194
|
+
strokeWidth={currentPositionStrokeWidth}
|
|
195
|
+
onMouseDown={this.handleStart}
|
|
196
|
+
onClick={this.handleEnd}
|
|
197
|
+
onMouseMove={this.handleDrawLine}
|
|
198
|
+
/>
|
|
199
|
+
</g>
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
private readonly handleEnd = (e: React.MouseEvent, xyValue: any, moreProps: any) => {
|
|
204
|
+
const { current } = this.state;
|
|
205
|
+
const { trends, appearance, type } = this.props;
|
|
206
|
+
|
|
207
|
+
if (this.mouseMoved && isDefined(current) && isDefined(current.topLeft)) {
|
|
208
|
+
const newTrends = [
|
|
209
|
+
...trends.map((d) => ({ ...d, selected: false })),
|
|
210
|
+
{
|
|
211
|
+
topLeft: current.topLeft,
|
|
212
|
+
topRight: xyValue,
|
|
213
|
+
selected: true,
|
|
214
|
+
appearance,
|
|
215
|
+
type,
|
|
216
|
+
},
|
|
217
|
+
];
|
|
218
|
+
this.setState(
|
|
219
|
+
{
|
|
220
|
+
current: null,
|
|
221
|
+
trends: newTrends,
|
|
222
|
+
},
|
|
223
|
+
() => {
|
|
224
|
+
const { onComplete } = this.props;
|
|
225
|
+
if (onComplete !== undefined) {
|
|
226
|
+
onComplete(e, newTrends, moreProps);
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
private readonly handleStart = (e: React.MouseEvent, xyValue: any, moreProps: any) => {
|
|
234
|
+
const { current } = this.state;
|
|
235
|
+
|
|
236
|
+
if (isNotDefined(current) || isNotDefined(current.topLeft)) {
|
|
237
|
+
this.mouseMoved = false;
|
|
238
|
+
|
|
239
|
+
this.setState(
|
|
240
|
+
{
|
|
241
|
+
current: {
|
|
242
|
+
topLeft: xyValue,
|
|
243
|
+
topRight: null,
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
() => {
|
|
247
|
+
const { onStart } = this.props;
|
|
248
|
+
if (onStart !== undefined) {
|
|
249
|
+
onStart(e, moreProps);
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
private readonly handleDrawLine = (_: React.MouseEvent, xyValue: any) => {
|
|
257
|
+
const { current } = this.state;
|
|
258
|
+
if (isDefined(current) && isDefined(current.topLeft)) {
|
|
259
|
+
this.mouseMoved = true;
|
|
260
|
+
this.setState({
|
|
261
|
+
current: {
|
|
262
|
+
topLeft: current.topLeft,
|
|
263
|
+
topRight: xyValue,
|
|
264
|
+
},
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
private readonly handleDragLineComplete = (e: React.MouseEvent, moreProps: any) => {
|
|
270
|
+
const { override } = this.state;
|
|
271
|
+
if (isDefined(override)) {
|
|
272
|
+
const { trends } = this.props;
|
|
273
|
+
const newTrends = trends.map((each, idx) =>
|
|
274
|
+
idx === override.index
|
|
275
|
+
? {
|
|
276
|
+
...each,
|
|
277
|
+
topLeft: [override.topLeft, override.topRight],
|
|
278
|
+
topRight: [override.topRightX, override.topRightY],
|
|
279
|
+
selected: true,
|
|
280
|
+
}
|
|
281
|
+
: {
|
|
282
|
+
...each,
|
|
283
|
+
selected: false,
|
|
284
|
+
},
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
this.setState(
|
|
288
|
+
{
|
|
289
|
+
override: null,
|
|
290
|
+
},
|
|
291
|
+
() => {
|
|
292
|
+
const { onComplete } = this.props;
|
|
293
|
+
if (onComplete !== undefined) {
|
|
294
|
+
onComplete(e, newTrends, moreProps);
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
private readonly handleDragLine = (_: React.MouseEvent, index: number | undefined, newXYValue: any) => {
|
|
302
|
+
this.setState({
|
|
303
|
+
override: {
|
|
304
|
+
index,
|
|
305
|
+
...newXYValue,
|
|
306
|
+
},
|
|
307
|
+
});
|
|
308
|
+
};
|
|
309
|
+
}
|