@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,134 @@
|
|
|
1
|
+
import { pairs } from "d3-array";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { generateLine, isHovering2 } from "./InteractiveStraightLine";
|
|
4
|
+
import { isDefined, isNotDefined, getMouseCanvas, GenericChartComponent } from "@tradingaction/core";
|
|
5
|
+
export class GannFan extends React.Component {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.drawOnCanvas = (ctx, moreProps) => {
|
|
9
|
+
const { strokeStyle, strokeWidth, fillStyle, fontFamily, fontSize, fontFill } = this.props;
|
|
10
|
+
const lines = this.helper(this.props, moreProps);
|
|
11
|
+
ctx.lineWidth = strokeWidth;
|
|
12
|
+
ctx.strokeStyle = strokeStyle;
|
|
13
|
+
ctx.font = `${fontSize}px ${fontFamily}`;
|
|
14
|
+
ctx.fillStyle = fontFill;
|
|
15
|
+
lines.forEach((line) => {
|
|
16
|
+
const { x1, y1, x2, y2, label } = line;
|
|
17
|
+
ctx.beginPath();
|
|
18
|
+
ctx.moveTo(x1, y1);
|
|
19
|
+
ctx.lineTo(x2, y2);
|
|
20
|
+
ctx.stroke();
|
|
21
|
+
ctx.beginPath();
|
|
22
|
+
ctx.fillText(label.text, label.x, label.y);
|
|
23
|
+
});
|
|
24
|
+
const pairsOfLines = pairs(lines);
|
|
25
|
+
pairsOfLines.forEach(([line1, line2], idx) => {
|
|
26
|
+
ctx.fillStyle = fillStyle[idx];
|
|
27
|
+
ctx.beginPath();
|
|
28
|
+
ctx.moveTo(line1.x1, line1.y1);
|
|
29
|
+
ctx.lineTo(line1.x2, line1.y2);
|
|
30
|
+
ctx.lineTo(line2.x2, line2.y2);
|
|
31
|
+
ctx.closePath();
|
|
32
|
+
ctx.fill();
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
this.isHover = (moreProps) => {
|
|
36
|
+
const { tolerance, onHover } = this.props;
|
|
37
|
+
const { mouseXY } = moreProps;
|
|
38
|
+
const [mouseX, mouseY] = mouseXY;
|
|
39
|
+
let hovering = false;
|
|
40
|
+
if (isDefined(onHover)) {
|
|
41
|
+
const lines = this.helper(this.props, moreProps);
|
|
42
|
+
// tslint:disable-next-line: prefer-for-of
|
|
43
|
+
for (let i = 0; i < lines.length; i++) {
|
|
44
|
+
const line1 = lines[i];
|
|
45
|
+
const left = Math.min(line1.x1, line1.x2);
|
|
46
|
+
const right = Math.max(line1.x1, line1.x2);
|
|
47
|
+
const top = Math.min(line1.y1, line1.y2);
|
|
48
|
+
const bottom = Math.max(line1.y1, line1.y2);
|
|
49
|
+
const isWithinLineBounds = mouseX >= left && mouseX <= right && mouseY >= top && mouseY <= bottom;
|
|
50
|
+
hovering =
|
|
51
|
+
isWithinLineBounds && isHovering2([line1.x1, line1.y1], [line1.x2, line1.y2], mouseXY, tolerance);
|
|
52
|
+
if (hovering) {
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return hovering;
|
|
58
|
+
};
|
|
59
|
+
this.getLineCoordinates = (start, endX, endY, text) => {
|
|
60
|
+
const end = [endX, endY];
|
|
61
|
+
return {
|
|
62
|
+
start,
|
|
63
|
+
end,
|
|
64
|
+
text,
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
this.helper = (props, moreProps) => {
|
|
68
|
+
const { startXY, endXY } = props;
|
|
69
|
+
const { xScale, chartConfig: { yScale }, } = moreProps;
|
|
70
|
+
if (isNotDefined(startXY) || isNotDefined(endXY)) {
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
73
|
+
const [x1, y1] = startXY;
|
|
74
|
+
const [x2, y2] = endXY;
|
|
75
|
+
const dx = x2 - x1;
|
|
76
|
+
const dy = y2 - y1;
|
|
77
|
+
if (dx !== 0 && dy !== 0) {
|
|
78
|
+
const halfY = this.getLineCoordinates(startXY, x2, y1 + dy / 2, "2/1");
|
|
79
|
+
const oneThirdY = this.getLineCoordinates(startXY, x2, y1 + dy / 3, "3/1");
|
|
80
|
+
const oneFourthY = this.getLineCoordinates(startXY, x2, y1 + dy / 4, "4/1");
|
|
81
|
+
const oneEighthY = this.getLineCoordinates(startXY, x2, y1 + dy / 8, "8/1");
|
|
82
|
+
const halfX = this.getLineCoordinates(startXY, x1 + dx / 2, y2, "1/2");
|
|
83
|
+
const oneThirdX = this.getLineCoordinates(startXY, x1 + dx / 3, y2, "1/3");
|
|
84
|
+
const oneFourthX = this.getLineCoordinates(startXY, x1 + dx / 4, y2, "1/4");
|
|
85
|
+
const oneEighthX = this.getLineCoordinates(startXY, x1 + dx / 8, y2, "1/8");
|
|
86
|
+
const lines = [
|
|
87
|
+
oneEighthX,
|
|
88
|
+
oneFourthX,
|
|
89
|
+
oneThirdX,
|
|
90
|
+
halfX,
|
|
91
|
+
{ start: startXY, end: endXY, text: "1/1" },
|
|
92
|
+
halfY,
|
|
93
|
+
oneThirdY,
|
|
94
|
+
oneFourthY,
|
|
95
|
+
oneEighthY,
|
|
96
|
+
];
|
|
97
|
+
const lineCoods = lines.map((line) => {
|
|
98
|
+
// tslint:disable-next-line: no-shadowed-variable
|
|
99
|
+
const { x1, y1, x2, y2 } = generateLine({
|
|
100
|
+
type: "RAY",
|
|
101
|
+
start: line.start,
|
|
102
|
+
end: line.end,
|
|
103
|
+
xScale,
|
|
104
|
+
yScale,
|
|
105
|
+
});
|
|
106
|
+
return {
|
|
107
|
+
x1: xScale(x1),
|
|
108
|
+
y1: yScale(y1),
|
|
109
|
+
x2: xScale(x2),
|
|
110
|
+
y2: yScale(y2),
|
|
111
|
+
label: {
|
|
112
|
+
x: xScale(line.end[0]),
|
|
113
|
+
y: yScale(line.end[1]),
|
|
114
|
+
text: line.text,
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
});
|
|
118
|
+
return lineCoods;
|
|
119
|
+
}
|
|
120
|
+
return [];
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
render() {
|
|
124
|
+
const { selected, interactiveCursorClass } = this.props;
|
|
125
|
+
const { onDragStart, onDrag, onDragComplete, onHover, onUnHover } = this.props;
|
|
126
|
+
return (React.createElement(GenericChartComponent, { isHover: this.isHover, canvasToDraw: getMouseCanvas, canvasDraw: this.drawOnCanvas, interactiveCursorClass: interactiveCursorClass, selected: selected, onDragStart: onDragStart, onDrag: onDrag, onDragComplete: onDragComplete, onHover: onHover, onUnHover: onUnHover, drawOn: ["mousemove", "mouseleave", "pan", "drag"] }));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
GannFan.defaultProps = {
|
|
130
|
+
strokeWidth: 1,
|
|
131
|
+
tolerance: 4,
|
|
132
|
+
selected: false,
|
|
133
|
+
};
|
|
134
|
+
//# sourceMappingURL=GannFan.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GannFan.js","sourceRoot":"","sources":["../../src/components/GannFan.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAsBrG,MAAM,OAAO,OAAQ,SAAQ,KAAK,CAAC,SAAuB;IAA1D;;QA4BqB,iBAAY,GAAG,CAAC,GAA6B,EAAE,SAAc,EAAE,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EAAE,IAAI,CAAC,YAAY,EAC7B,sBAAsB,EAAE,sBAAsB,EAC9C,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,cAAc,EAC9B,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,CAAC,WAAW,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,CAAC,GACpD,CACL,CAAC;IACN,CAAC;;AAzBa,oBAAY,GAAG;IACzB,WAAW,EAAE,CAAC;IACd,SAAS,EAAE,CAAC;IACZ,QAAQ,EAAE,KAAK;CAClB,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export interface HoverTextNearMouseProps {
|
|
3
|
+
readonly fontFamily?: string;
|
|
4
|
+
readonly fontSize?: number;
|
|
5
|
+
readonly fill?: string;
|
|
6
|
+
readonly text?: string;
|
|
7
|
+
readonly bgFill?: string;
|
|
8
|
+
readonly bgOpacity?: number;
|
|
9
|
+
readonly bgWidth: number | string;
|
|
10
|
+
readonly bgHeight: number | string;
|
|
11
|
+
readonly show: boolean;
|
|
12
|
+
}
|
|
13
|
+
interface HoverTextNearMouseState {
|
|
14
|
+
textHeight?: number;
|
|
15
|
+
textWidth?: number;
|
|
16
|
+
}
|
|
17
|
+
export declare class HoverTextNearMouse extends React.Component<HoverTextNearMouseProps, HoverTextNearMouseState> {
|
|
18
|
+
static defaultProps: {
|
|
19
|
+
fontFamily: string;
|
|
20
|
+
fontSize: number;
|
|
21
|
+
fill: string;
|
|
22
|
+
bgFill: string;
|
|
23
|
+
bgOpacity: number;
|
|
24
|
+
};
|
|
25
|
+
private readonly textNode;
|
|
26
|
+
constructor(props: HoverTextNearMouseProps);
|
|
27
|
+
componentDidMount(): void;
|
|
28
|
+
componentDidUpdate(): void;
|
|
29
|
+
render(): JSX.Element | null;
|
|
30
|
+
private readonly renderSVG;
|
|
31
|
+
private readonly getBgHeight;
|
|
32
|
+
private readonly getBgWidth;
|
|
33
|
+
private readonly updateTextSize;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { isDefined, GenericChartComponent } from "@tradingaction/core";
|
|
3
|
+
const PADDING = 10;
|
|
4
|
+
const MIN_WIDTH = PADDING;
|
|
5
|
+
export class HoverTextNearMouse extends React.Component {
|
|
6
|
+
constructor(props) {
|
|
7
|
+
super(props);
|
|
8
|
+
this.textNode = React.createRef();
|
|
9
|
+
this.renderSVG = (moreProps) => {
|
|
10
|
+
const { fontFamily, fontSize, fill, bgFill, bgOpacity } = this.props;
|
|
11
|
+
const textMetaData = helper(Object.assign(Object.assign({}, this.props), { bgWidth: this.getBgWidth(), bgHeight: this.getBgHeight() }), moreProps);
|
|
12
|
+
if (textMetaData !== undefined && isDefined(textMetaData)) {
|
|
13
|
+
const { rect, text } = textMetaData;
|
|
14
|
+
return (React.createElement("g", null,
|
|
15
|
+
React.createElement("rect", Object.assign({ fill: bgFill, fillOpacity: bgOpacity, stroke: bgFill }, rect)),
|
|
16
|
+
React.createElement("text", { ref: this.textNode, fontSize: fontSize, fontFamily: fontFamily, textAnchor: "start", alignmentBaseline: "central", fill: fill, x: text.x, y: text.y }, text.text)));
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
};
|
|
20
|
+
this.getBgHeight = () => {
|
|
21
|
+
const { bgHeight } = this.props;
|
|
22
|
+
const { textHeight } = this.state;
|
|
23
|
+
if (bgHeight !== "auto") {
|
|
24
|
+
return bgHeight;
|
|
25
|
+
}
|
|
26
|
+
else if (textHeight !== undefined) {
|
|
27
|
+
return textHeight + PADDING;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return MIN_WIDTH;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
this.getBgWidth = () => {
|
|
34
|
+
const { bgWidth } = this.props;
|
|
35
|
+
const { textWidth } = this.state;
|
|
36
|
+
if (bgWidth !== "auto") {
|
|
37
|
+
return bgWidth;
|
|
38
|
+
}
|
|
39
|
+
else if (textWidth !== undefined) {
|
|
40
|
+
return textWidth + PADDING;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return MIN_WIDTH;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
this.updateTextSize = () => {
|
|
47
|
+
const { bgWidth, bgHeight } = this.props;
|
|
48
|
+
if (bgWidth === "auto" || bgHeight === "auto") {
|
|
49
|
+
const textNode = this.textNode.current;
|
|
50
|
+
if (textNode !== null) {
|
|
51
|
+
const { width, height } = textNode.getBBox();
|
|
52
|
+
if (this.state.textWidth !== width || this.state.textHeight !== height) {
|
|
53
|
+
this.setState({
|
|
54
|
+
textWidth: width,
|
|
55
|
+
textHeight: height,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
this.state = {
|
|
62
|
+
textWidth: undefined,
|
|
63
|
+
textHeight: undefined,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
componentDidMount() {
|
|
67
|
+
this.updateTextSize();
|
|
68
|
+
}
|
|
69
|
+
componentDidUpdate() {
|
|
70
|
+
this.updateTextSize();
|
|
71
|
+
}
|
|
72
|
+
render() {
|
|
73
|
+
const { text } = this.props;
|
|
74
|
+
if (text) {
|
|
75
|
+
return React.createElement(GenericChartComponent, { svgDraw: this.renderSVG, drawOn: ["mousemove"] });
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
HoverTextNearMouse.defaultProps = {
|
|
83
|
+
fontFamily: "-apple-system, system-ui, Roboto, 'Helvetica Neue', Ubuntu, sans-serif",
|
|
84
|
+
fontSize: 12,
|
|
85
|
+
fill: "#000000",
|
|
86
|
+
bgFill: "#FA9325",
|
|
87
|
+
bgOpacity: 0.5,
|
|
88
|
+
};
|
|
89
|
+
function helper(props, moreProps) {
|
|
90
|
+
const { show, bgWidth, bgHeight } = props;
|
|
91
|
+
const { mouseXY, chartConfig: { height, width }, show: mouseInsideCanvas, } = moreProps;
|
|
92
|
+
if (show && mouseInsideCanvas) {
|
|
93
|
+
const [x, y] = mouseXY;
|
|
94
|
+
const cx = x < width / 2 ? x + PADDING : x - bgWidth - PADDING;
|
|
95
|
+
const cy = y < height / 2 ? y + PADDING : y - bgHeight - PADDING;
|
|
96
|
+
const rect = {
|
|
97
|
+
x: cx,
|
|
98
|
+
y: cy,
|
|
99
|
+
width: bgWidth,
|
|
100
|
+
height: bgHeight,
|
|
101
|
+
};
|
|
102
|
+
const text = {
|
|
103
|
+
text: props.text,
|
|
104
|
+
x: cx + PADDING / 2,
|
|
105
|
+
y: cy + bgHeight / 2,
|
|
106
|
+
};
|
|
107
|
+
return {
|
|
108
|
+
rect,
|
|
109
|
+
text,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=HoverTextNearMouse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HoverTextNearMouse.js","sourceRoot":"","sources":["../../src/components/HoverTextNearMouse.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAEvE,MAAM,OAAO,GAAG,EAAE,CAAC;AACnB,MAAM,SAAS,GAAG,OAAO,CAAC;AAmB1B,MAAM,OAAO,kBAAmB,SAAQ,KAAK,CAAC,SAA2D;IAWrG,YAAmB,KAA8B;QAC7C,KAAK,CAAC,KAAK,CAAC,CAAC;QAHA,aAAQ,GAAG,KAAK,CAAC,SAAS,EAAkB,CAAC;QA4B7C,cAAS,GAAG,CAAC,SAAc,EAAE,EAAE;YAC5C,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE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AEF,OAAO;YACH,IAAI;YACJ,IAAI;SACP,CAAC;KACL;AACL,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { strokeDashTypes } from "@tradingaction/core";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
export interface StraightLineProps {
|
|
4
|
+
readonly x1Value: any;
|
|
5
|
+
readonly x2Value: any;
|
|
6
|
+
readonly y1Value: any;
|
|
7
|
+
readonly y2Value: any;
|
|
8
|
+
readonly interactiveCursorClass?: string;
|
|
9
|
+
readonly strokeStyle: string;
|
|
10
|
+
readonly strokeWidth?: number;
|
|
11
|
+
readonly strokeDasharray?: strokeDashTypes;
|
|
12
|
+
readonly type: "XLINE" | "RAY" | "LINE";
|
|
13
|
+
readonly onEdge1Drag?: any;
|
|
14
|
+
readonly onEdge2Drag?: any;
|
|
15
|
+
readonly onDragStart?: (e: React.MouseEvent, moreProps: any) => void;
|
|
16
|
+
readonly onDrag?: (e: React.MouseEvent, moreProps: any) => void;
|
|
17
|
+
readonly onDragComplete?: (e: React.MouseEvent, moreProps: any) => void;
|
|
18
|
+
readonly onHover?: (e: React.MouseEvent, moreProps: any) => void;
|
|
19
|
+
readonly onUnHover?: (e: React.MouseEvent, moreProps: any) => void;
|
|
20
|
+
readonly onDoubleClickWhenHover?: (e: React.MouseEvent, moreProps: any) => void;
|
|
21
|
+
readonly onClickWhenHover?: (e: React.MouseEvent, moreProps: any) => void;
|
|
22
|
+
readonly onClickOutside?: (e: React.MouseEvent, moreProps: any) => void;
|
|
23
|
+
readonly onContextMenuWhenHover?: (e: React.MouseEvent, moreProps: any) => void;
|
|
24
|
+
readonly defaultClassName?: string;
|
|
25
|
+
readonly r?: number;
|
|
26
|
+
readonly edgeFill?: string;
|
|
27
|
+
readonly edgeStroke?: string;
|
|
28
|
+
readonly edgeStrokeWidth?: number;
|
|
29
|
+
readonly withEdge?: boolean;
|
|
30
|
+
readonly tolerance?: number;
|
|
31
|
+
readonly selected?: boolean;
|
|
32
|
+
}
|
|
33
|
+
export declare class InteractiveStraightLine extends React.Component<StraightLineProps> {
|
|
34
|
+
static defaultProps: {
|
|
35
|
+
onEdge1Drag: () => void;
|
|
36
|
+
onEdge2Drag: () => void;
|
|
37
|
+
edgeStrokeWidth: number;
|
|
38
|
+
edgeStroke: string;
|
|
39
|
+
edgeFill: string;
|
|
40
|
+
r: number;
|
|
41
|
+
withEdge: boolean;
|
|
42
|
+
strokeWidth: number;
|
|
43
|
+
strokeDasharray: string;
|
|
44
|
+
children: () => void;
|
|
45
|
+
tolerance: number;
|
|
46
|
+
selected: boolean;
|
|
47
|
+
};
|
|
48
|
+
render(): JSX.Element;
|
|
49
|
+
private readonly isHover;
|
|
50
|
+
private readonly drawOnCanvas;
|
|
51
|
+
}
|
|
52
|
+
export declare function isHovering2(start: any, end: any, [mouseX, mouseY]: any, tolerance: any): boolean;
|
|
53
|
+
export declare function isHovering({ x1Value, y1Value, x2Value, y2Value, mouseXY, type, tolerance, xScale, yScale }: any): boolean;
|
|
54
|
+
export declare function getSlope(start: any, end: any): number | undefined;
|
|
55
|
+
export declare function getYIntercept(m: any, end: any): any;
|
|
56
|
+
export declare function generateLine({ type, start, end, xScale, yScale }: any): {
|
|
57
|
+
x1: any;
|
|
58
|
+
y1: any;
|
|
59
|
+
x2: any;
|
|
60
|
+
y2: any;
|
|
61
|
+
};
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { getStrokeDasharrayCanvas, getMouseCanvas, GenericChartComponent, noop, } from "@tradingaction/core";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
export class InteractiveStraightLine extends React.Component {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
this.isHover = (moreProps) => {
|
|
7
|
+
const { tolerance, onHover } = this.props;
|
|
8
|
+
if (onHover !== undefined) {
|
|
9
|
+
const { x1Value, x2Value, y1Value, y2Value, type } = this.props;
|
|
10
|
+
const { mouseXY, xScale } = moreProps;
|
|
11
|
+
const { chartConfig: { yScale }, } = moreProps;
|
|
12
|
+
const hovering = isHovering({
|
|
13
|
+
x1Value,
|
|
14
|
+
y1Value,
|
|
15
|
+
x2Value,
|
|
16
|
+
y2Value,
|
|
17
|
+
mouseXY,
|
|
18
|
+
type,
|
|
19
|
+
tolerance,
|
|
20
|
+
xScale,
|
|
21
|
+
yScale,
|
|
22
|
+
});
|
|
23
|
+
return hovering;
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
};
|
|
27
|
+
this.drawOnCanvas = (ctx, moreProps) => {
|
|
28
|
+
const { strokeWidth = InteractiveStraightLine.defaultProps.strokeWidth, strokeDasharray, strokeStyle, } = this.props;
|
|
29
|
+
const { x1, y1, x2, y2 } = helper(this.props, moreProps);
|
|
30
|
+
ctx.lineWidth = strokeWidth;
|
|
31
|
+
ctx.strokeStyle = strokeStyle;
|
|
32
|
+
const lineDash = getStrokeDasharrayCanvas(strokeDasharray);
|
|
33
|
+
ctx.setLineDash(lineDash);
|
|
34
|
+
ctx.beginPath();
|
|
35
|
+
ctx.moveTo(x1, y1);
|
|
36
|
+
ctx.lineTo(x2, y2);
|
|
37
|
+
ctx.stroke();
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
render() {
|
|
41
|
+
const { selected, interactiveCursorClass } = this.props;
|
|
42
|
+
const { onDragStart, onDrag, onDragComplete, onHover, onUnHover, onDoubleClickWhenHover, onClickWhenHover, onClickOutside, onContextMenuWhenHover, } = this.props;
|
|
43
|
+
return (React.createElement(GenericChartComponent, { isHover: this.isHover, canvasToDraw: getMouseCanvas, canvasDraw: this.drawOnCanvas, interactiveCursorClass: interactiveCursorClass, selected: selected, onDragStart: onDragStart, onDrag: onDrag, onDragComplete: onDragComplete, onHover: onHover, onUnHover: onUnHover, drawOn: ["mousemove", "pan", "drag"], onDoubleClickWhenHover: onDoubleClickWhenHover, onClickWhenHover: onClickWhenHover, onClickOutside: onClickOutside, onContextMenuWhenHover: onContextMenuWhenHover }));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
InteractiveStraightLine.defaultProps = {
|
|
47
|
+
onEdge1Drag: noop,
|
|
48
|
+
onEdge2Drag: noop,
|
|
49
|
+
edgeStrokeWidth: 3,
|
|
50
|
+
edgeStroke: "#000000",
|
|
51
|
+
edgeFill: "#FFFFFF",
|
|
52
|
+
r: 10,
|
|
53
|
+
withEdge: false,
|
|
54
|
+
strokeWidth: 1,
|
|
55
|
+
strokeDasharray: "Solid",
|
|
56
|
+
children: noop,
|
|
57
|
+
tolerance: 7,
|
|
58
|
+
selected: false,
|
|
59
|
+
};
|
|
60
|
+
export function isHovering2(start, end, [mouseX, mouseY], tolerance) {
|
|
61
|
+
const m = getSlope(start, end);
|
|
62
|
+
if (m !== undefined) {
|
|
63
|
+
const b = getYIntercept(m, end);
|
|
64
|
+
const y = m * mouseX + b;
|
|
65
|
+
return (mouseY < y + tolerance &&
|
|
66
|
+
mouseY > y - tolerance &&
|
|
67
|
+
mouseX > Math.min(start[0], end[0]) - tolerance &&
|
|
68
|
+
mouseX < Math.max(start[0], end[0]) + tolerance);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
return (mouseY >= Math.min(start[1], end[1]) &&
|
|
72
|
+
mouseY <= Math.max(start[1], end[1]) &&
|
|
73
|
+
mouseX < start[0] + tolerance &&
|
|
74
|
+
mouseX > start[0] - tolerance);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
export function isHovering({ x1Value, y1Value, x2Value, y2Value, mouseXY, type, tolerance, xScale, yScale }) {
|
|
78
|
+
const line = generateLine({
|
|
79
|
+
type,
|
|
80
|
+
start: [x1Value, y1Value],
|
|
81
|
+
end: [x2Value, y2Value],
|
|
82
|
+
xScale,
|
|
83
|
+
yScale,
|
|
84
|
+
});
|
|
85
|
+
const start = [xScale(line.x1), yScale(line.y1)];
|
|
86
|
+
const end = [xScale(line.x2), yScale(line.y2)];
|
|
87
|
+
const m = getSlope(start, end);
|
|
88
|
+
const [mouseX, mouseY] = mouseXY;
|
|
89
|
+
if (m !== undefined) {
|
|
90
|
+
const b = getYIntercept(m, end);
|
|
91
|
+
const y = m * mouseX + b;
|
|
92
|
+
return (mouseY < y + tolerance &&
|
|
93
|
+
mouseY > y - tolerance &&
|
|
94
|
+
mouseX > Math.min(start[0], end[0]) - tolerance &&
|
|
95
|
+
mouseX < Math.max(start[0], end[0]) + tolerance);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
return (mouseY >= Math.min(start[1], end[1]) &&
|
|
99
|
+
mouseY <= Math.max(start[1], end[1]) &&
|
|
100
|
+
mouseX < start[0] + tolerance &&
|
|
101
|
+
mouseX > start[0] - tolerance);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function helper(props, moreProps) {
|
|
105
|
+
const { x1Value, x2Value, y1Value, y2Value, type } = props;
|
|
106
|
+
const { xScale, chartConfig: { yScale }, } = moreProps;
|
|
107
|
+
const modLine = generateLine({
|
|
108
|
+
type,
|
|
109
|
+
start: [x1Value, y1Value],
|
|
110
|
+
end: [x2Value, y2Value],
|
|
111
|
+
xScale,
|
|
112
|
+
yScale,
|
|
113
|
+
});
|
|
114
|
+
const x1 = xScale(modLine.x1);
|
|
115
|
+
const y1 = yScale(modLine.y1);
|
|
116
|
+
const x2 = xScale(modLine.x2);
|
|
117
|
+
const y2 = yScale(modLine.y2);
|
|
118
|
+
return {
|
|
119
|
+
x1,
|
|
120
|
+
y1,
|
|
121
|
+
x2,
|
|
122
|
+
y2,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
export function getSlope(start, end) {
|
|
126
|
+
const m /* slope */ = end[0] === start[0] ? undefined : (end[1] - start[1]) / (end[0] - start[0]);
|
|
127
|
+
return m;
|
|
128
|
+
}
|
|
129
|
+
export function getYIntercept(m, end) {
|
|
130
|
+
const b /* y intercept */ = -1 * m * end[0] + end[1];
|
|
131
|
+
return b;
|
|
132
|
+
}
|
|
133
|
+
export function generateLine({ type, start, end, xScale, yScale }) {
|
|
134
|
+
const m /* slope */ = getSlope(start, end);
|
|
135
|
+
const b /* y intercept */ = getYIntercept(m, start);
|
|
136
|
+
switch (type) {
|
|
137
|
+
case "XLINE":
|
|
138
|
+
return getXLineCoordinates({
|
|
139
|
+
start,
|
|
140
|
+
end,
|
|
141
|
+
xScale,
|
|
142
|
+
yScale,
|
|
143
|
+
m,
|
|
144
|
+
b,
|
|
145
|
+
});
|
|
146
|
+
case "RAY":
|
|
147
|
+
return getRayCoordinates({
|
|
148
|
+
start,
|
|
149
|
+
end,
|
|
150
|
+
xScale,
|
|
151
|
+
yScale,
|
|
152
|
+
m,
|
|
153
|
+
b,
|
|
154
|
+
});
|
|
155
|
+
default:
|
|
156
|
+
case "LINE":
|
|
157
|
+
return getLineCoordinates({
|
|
158
|
+
start,
|
|
159
|
+
end,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function getXLineCoordinates({ start, end, xScale, yScale, m, b }) {
|
|
164
|
+
const [xBegin, xFinish] = xScale.domain();
|
|
165
|
+
const [yBegin, yFinish] = yScale.domain();
|
|
166
|
+
if (end[0] === start[0]) {
|
|
167
|
+
return {
|
|
168
|
+
x1: end[0],
|
|
169
|
+
y1: yBegin,
|
|
170
|
+
x2: end[0],
|
|
171
|
+
y2: yFinish,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
const [x1, x2] = end[0] > start[0] ? [xBegin, xFinish] : [xFinish, xBegin];
|
|
175
|
+
return {
|
|
176
|
+
x1,
|
|
177
|
+
y1: m * x1 + b,
|
|
178
|
+
x2,
|
|
179
|
+
y2: m * x2 + b,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
function getRayCoordinates({ start, end, xScale, yScale, m, b }) {
|
|
183
|
+
const [xBegin, xFinish] = xScale.domain();
|
|
184
|
+
const [yBegin, yFinish] = yScale.domain();
|
|
185
|
+
const x1 = start[0];
|
|
186
|
+
if (end[0] === start[0]) {
|
|
187
|
+
return {
|
|
188
|
+
x1,
|
|
189
|
+
y1: start[1],
|
|
190
|
+
x2: x1,
|
|
191
|
+
y2: end[1] > start[1] ? yFinish : yBegin,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
const x2 = end[0] > start[0] ? xFinish : xBegin;
|
|
195
|
+
return {
|
|
196
|
+
x1,
|
|
197
|
+
y1: m * x1 + b,
|
|
198
|
+
x2,
|
|
199
|
+
y2: m * x2 + b,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
function getLineCoordinates({ start, end }) {
|
|
203
|
+
const [x1, y1] = start;
|
|
204
|
+
const [x2, y2] = end;
|
|
205
|
+
if (end[0] === start[0]) {
|
|
206
|
+
return {
|
|
207
|
+
x1,
|
|
208
|
+
y1: start[1],
|
|
209
|
+
x2: x1,
|
|
210
|
+
y2: end[1],
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
return {
|
|
214
|
+
x1,
|
|
215
|
+
y1,
|
|
216
|
+
x2,
|
|
217
|
+
y2,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
//# sourceMappingURL=InteractiveStraightLine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InteractiveStraightLine.js","sourceRoot":"","sources":["../../src/components/InteractiveStraightLine.tsx"],"names":[],"mappings":"AAAA,OAAO,EACH,wBAAwB,EACxB,cAAc,EACd,qBAAqB,EACrB,IAAI,GAEP,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAoC/B,MAAM,OAAO,uBAAwB,SAAQ,KAAK,CAAC,SAA4B;IAA/E;;QAmDqB,YAAO,GAAG,CAAC,SAAc,EAAE,EAAE;YAC1C,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;YAE1C,IAAI,OAAO,KAAK,SAAS,EAAE;gBACvB,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EA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MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC;IACrB,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,EAAE;QACrB,OAAO;YACH,EAAE;YACF,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC;YACZ,EAAE,EAAE,EAAE;YACN,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC;SACb,CAAC;KACL;IAED,OAAO;QACH,EAAE;QACF,EAAE;QACF,EAAE;QACF,EAAE;KACL,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export interface InteractiveTextProps {
|
|
3
|
+
readonly bgFillStyle: string;
|
|
4
|
+
readonly bgStrokeWidth: number;
|
|
5
|
+
readonly bgStroke: string;
|
|
6
|
+
readonly defaultClassName?: string;
|
|
7
|
+
readonly fontFamily: string;
|
|
8
|
+
readonly fontSize: number;
|
|
9
|
+
readonly fontWeight: number | string;
|
|
10
|
+
readonly fontStyle: string;
|
|
11
|
+
readonly onDragStart?: (e: React.MouseEvent, moreProps: any) => void;
|
|
12
|
+
readonly onDrag?: (e: React.MouseEvent, moreProps: any) => void;
|
|
13
|
+
readonly onDragComplete?: (e: React.MouseEvent, moreProps: any) => void;
|
|
14
|
+
readonly onHover?: (e: React.MouseEvent, moreProps: any) => void;
|
|
15
|
+
readonly onUnHover?: (e: React.MouseEvent, moreProps: any) => void;
|
|
16
|
+
readonly onDoubleClick?: (e: React.MouseEvent, moreProps: any) => void;
|
|
17
|
+
readonly position?: any;
|
|
18
|
+
readonly interactiveCursorClass?: string;
|
|
19
|
+
readonly selected: boolean;
|
|
20
|
+
readonly text: string;
|
|
21
|
+
readonly textFill: string;
|
|
22
|
+
readonly tolerance: number;
|
|
23
|
+
}
|
|
24
|
+
export declare class InteractiveText extends React.Component<InteractiveTextProps> {
|
|
25
|
+
static defaultProps: {
|
|
26
|
+
type: string;
|
|
27
|
+
fontWeight: string;
|
|
28
|
+
tolerance: number;
|
|
29
|
+
selected: boolean;
|
|
30
|
+
};
|
|
31
|
+
private calculateTextWidth;
|
|
32
|
+
private textWidth?;
|
|
33
|
+
componentDidUpdate(previousProps: InteractiveTextProps): void;
|
|
34
|
+
render(): JSX.Element;
|
|
35
|
+
private readonly isHover;
|
|
36
|
+
private readonly drawOnCanvas;
|
|
37
|
+
private readonly helper;
|
|
38
|
+
}
|