@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,64 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { getMouseCanvas, GenericChartComponent } from "@ivanmatiaspascual/core";
|
|
3
|
+
import { isHovering2 } from "./InteractiveStraightLine";
|
|
4
|
+
export class ClickableShape extends React.Component {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
this.drawOnCanvas = (ctx, moreProps) => {
|
|
8
|
+
const { strokeStyle, strokeWidth, hovering, textBox } = this.props;
|
|
9
|
+
const [x, y] = this.helper(this.props, moreProps, ctx);
|
|
10
|
+
this.closeIcon = { x, y };
|
|
11
|
+
ctx.beginPath();
|
|
12
|
+
ctx.lineWidth = hovering ? strokeWidth + 1 : strokeWidth;
|
|
13
|
+
ctx.strokeStyle = strokeStyle;
|
|
14
|
+
const halfWidth = textBox.closeIcon.width / 2;
|
|
15
|
+
ctx.moveTo(x - halfWidth, y - halfWidth);
|
|
16
|
+
ctx.lineTo(x + halfWidth, y + halfWidth);
|
|
17
|
+
ctx.moveTo(x - halfWidth, y + halfWidth);
|
|
18
|
+
ctx.lineTo(x + halfWidth, y - halfWidth);
|
|
19
|
+
ctx.stroke();
|
|
20
|
+
};
|
|
21
|
+
this.isHover = (moreProps) => {
|
|
22
|
+
const { mouseXY } = moreProps;
|
|
23
|
+
if (this.closeIcon) {
|
|
24
|
+
const { textBox } = this.props;
|
|
25
|
+
const { x, y } = this.closeIcon;
|
|
26
|
+
const halfWidth = textBox.closeIcon.width / 2;
|
|
27
|
+
const start1 = [x - halfWidth, y - halfWidth];
|
|
28
|
+
const end1 = [x + halfWidth, y + halfWidth];
|
|
29
|
+
const start2 = [x - halfWidth, y + halfWidth];
|
|
30
|
+
const end2 = [x + halfWidth, y - halfWidth];
|
|
31
|
+
if (isHovering2(start1, end1, mouseXY, 3) || isHovering2(start2, end2, mouseXY, 3)) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return false;
|
|
36
|
+
};
|
|
37
|
+
this.helper = (props, moreProps, ctx) => {
|
|
38
|
+
const { yValue, text, textBox } = props;
|
|
39
|
+
const { fontFamily, fontStyle, fontWeight, fontSize } = props;
|
|
40
|
+
ctx.font = `${fontStyle} ${fontWeight} ${fontSize}px ${fontFamily}`;
|
|
41
|
+
const { chartConfig: { yScale }, } = moreProps;
|
|
42
|
+
const x = textBox.left +
|
|
43
|
+
textBox.padding.left +
|
|
44
|
+
ctx.measureText(text).width +
|
|
45
|
+
textBox.padding.right +
|
|
46
|
+
textBox.closeIcon.padding.left +
|
|
47
|
+
textBox.closeIcon.width / 2;
|
|
48
|
+
const y = yScale(yValue);
|
|
49
|
+
return [x, y];
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
render() {
|
|
53
|
+
const { interactiveCursorClass, onHover, onUnHover, onClick, show } = this.props;
|
|
54
|
+
if (!show) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
return (React.createElement(GenericChartComponent, { interactiveCursorClass: interactiveCursorClass, isHover: this.isHover, onClickWhenHover: onClick, canvasDraw: this.drawOnCanvas, canvasToDraw: getMouseCanvas, onHover: onHover, onUnHover: onUnHover, drawOn: ["pan", "mousemove", "drag"] }));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
ClickableShape.defaultProps = {
|
|
61
|
+
show: false,
|
|
62
|
+
strokeWidth: 1,
|
|
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+1,32 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export interface GannFanProps {
|
|
3
|
+
readonly startXY: number[];
|
|
4
|
+
readonly defaultClassName?: string;
|
|
5
|
+
readonly endXY: number[];
|
|
6
|
+
readonly fillStyle: Array<string>;
|
|
7
|
+
readonly fontFamily: string;
|
|
8
|
+
readonly fontSize: number;
|
|
9
|
+
readonly fontFill: string;
|
|
10
|
+
readonly interactiveCursorClass?: 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 selected: boolean;
|
|
17
|
+
readonly strokeStyle: string;
|
|
18
|
+
readonly strokeWidth: number;
|
|
19
|
+
readonly tolerance: number;
|
|
20
|
+
}
|
|
21
|
+
export declare class GannFan extends React.Component<GannFanProps> {
|
|
22
|
+
static defaultProps: {
|
|
23
|
+
strokeWidth: number;
|
|
24
|
+
tolerance: number;
|
|
25
|
+
selected: boolean;
|
|
26
|
+
};
|
|
27
|
+
render(): JSX.Element;
|
|
28
|
+
private readonly drawOnCanvas;
|
|
29
|
+
private readonly isHover;
|
|
30
|
+
private readonly getLineCoordinates;
|
|
31
|
+
private readonly helper;
|
|
32
|
+
}
|
|
@@ -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 "@ivanmatiaspascual/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,yBAAyB,CAAC;AAsBzG,MAAM,OAAO,OAAQ,SAAQ,KAAK,CAAC,SAAuB;IAA1D;;QA4BqB,iBAAY,GAAG,CAAC,GAA6B,EAAE,SAAc,EAAE,EAAE;YAC9E,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;YAE3F,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;YAEjD,GAAG,CAAC,SAAS,GAAG,WAAW,CAAC;YAC5B,GAAG,CAAC,WAAW,GAAG,WAAW,CAAC;YAC9B,GAAG,CAAC,IAAI,GAAG,GAAG,QAAQ,MAAM,UAAU,EAAE,CAAC;YACzC,GAAG,CAAC,SAAS,GAAG,QAAQ,CAAC;YAEzB,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;gBACnB,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;gBAEvC,GAAG,CAAC,SAAS,EAAE,CAA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KAAK,EAAE;4BACH,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;4BACtB,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;4BACtB,IAAI,EAAE,IAAI,CAAC,IAAI;yBAClB;qBACJ,CAAC;gBACN,CAAC,CAAC,CAAC;gBACH,OAAO,SAAS,CAAC;aACpB;YACD,OAAO,EAAE,CAAC;QACd,CAAC,CAAC;IACN,CAAC;IA5JU,MAAM;QACT,MAAM,EAAE,QAAQ,EAAE,sBAAsB,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QACxD,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QAE/E,OAAO,CACH,oBAAC,qBAAqB,IAClB,OAAO,EAAE,IAAI,CAAC,OAAO,EACrB,YAAY,EAAE,cAAc,EAC5B,UAAU,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 "@ivanmatiaspascual/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,yBAAyB,CAAC;AAE3E,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,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;YAErE,MAAM,YAAY,GAAG,MAAM,iCAEhB,IAAI,CAAC,KAAK,KACb,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,EAC1B,QAAQ,EAAE,IAAI,CAAC,WAAW,EAAE,KAEhC,SAAS,CACZ,CAAC;YAEF,IAAI,YAAY,KAAK,SAAS,IAAI,SAAS,CAAC,YAAY,CAAC,EAAE;gBACvD,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,YAAY,CAAC;gBACpC,OAAO,CACH;oBACI,4CAAM,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,IAAM,IAAI,EAAI;oBACxE,8BACI,GAAG,EAAE,IAAI,CAAC,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,UAAU,EACtB,UAAU,EAAC,OAAO,EAClB,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,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC;QAEvB,MAAM,EAAE,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,OAAO,CAAC;QAE/D,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,QAAQ,GAAG,OAAO,CAAC;QAEjE,MAAM,IAAI,GAAG;YACT,CAAC,EAAE,EAAE;YACL,CAAC,EAAE,EAAE;YACL,KAAK,EAAE,OAAO;YACd,MAAM,EAAE,QAAQ;SACnB,CAAC;QAEF,MAAM,IAAI,GAAG;YACT,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,CAAC,EAAE,EAAE,GAAG,OAAO,GAAG,CAAC;YACnB,CAAC,EAAE,EAAE,GAAG,QAAQ,GAAG,CAAC;SACvB,CAAC;QAEF,OAAO;YACH,IAAI;YACJ,IAAI;SACP,CAAC;KACL;AACL,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { strokeDashTypes } from "@ivanmatiaspascual/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 defaultClassName?: string;
|
|
21
|
+
readonly r?: number;
|
|
22
|
+
readonly edgeFill?: string;
|
|
23
|
+
readonly edgeStroke?: string;
|
|
24
|
+
readonly edgeStrokeWidth?: number;
|
|
25
|
+
readonly withEdge?: boolean;
|
|
26
|
+
readonly tolerance?: number;
|
|
27
|
+
readonly selected?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export declare class InteractiveStraightLine extends React.Component<StraightLineProps> {
|
|
30
|
+
static defaultProps: {
|
|
31
|
+
onEdge1Drag: () => void;
|
|
32
|
+
onEdge2Drag: () => void;
|
|
33
|
+
edgeStrokeWidth: number;
|
|
34
|
+
edgeStroke: string;
|
|
35
|
+
edgeFill: string;
|
|
36
|
+
r: number;
|
|
37
|
+
withEdge: boolean;
|
|
38
|
+
strokeWidth: number;
|
|
39
|
+
strokeDasharray: string;
|
|
40
|
+
children: () => void;
|
|
41
|
+
tolerance: number;
|
|
42
|
+
selected: boolean;
|
|
43
|
+
};
|
|
44
|
+
render(): JSX.Element;
|
|
45
|
+
private readonly isHover;
|
|
46
|
+
private readonly drawOnCanvas;
|
|
47
|
+
}
|
|
48
|
+
export declare function isHovering2(start: any, end: any, [mouseX, mouseY]: any, tolerance: any): boolean;
|
|
49
|
+
export declare function isHovering({ x1Value, y1Value, x2Value, y2Value, mouseXY, type, tolerance, xScale, yScale }: any): boolean;
|
|
50
|
+
export declare function getSlope(start: any, end: any): number | undefined;
|
|
51
|
+
export declare function getYIntercept(m: any, end: any): any;
|
|
52
|
+
export declare function generateLine({ type, start, end, xScale, yScale }: any): {
|
|
53
|
+
x1: any;
|
|
54
|
+
y1: any;
|
|
55
|
+
x2: any;
|
|
56
|
+
y2: any;
|
|
57
|
+
};
|