@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 @@
|
|
|
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"}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ivanmatiaspascual/interactive",
|
|
3
|
+
"version": "1.3.1-sp1-beta.0.1.0",
|
|
4
|
+
"description": "Interactive features for react-financial-charts",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "./lib/index.js",
|
|
10
|
+
"typings": "./lib/index.d.ts",
|
|
11
|
+
"files": [
|
|
12
|
+
"lib",
|
|
13
|
+
"src"
|
|
14
|
+
],
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"author": "Reactive Markets",
|
|
17
|
+
"keywords": [
|
|
18
|
+
"charts",
|
|
19
|
+
"charting",
|
|
20
|
+
"stockcharts",
|
|
21
|
+
"finance",
|
|
22
|
+
"financial",
|
|
23
|
+
"finance-chart",
|
|
24
|
+
"react",
|
|
25
|
+
"d3"
|
|
26
|
+
],
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/ivanmatiaspascual/react-financial-charts.git"
|
|
31
|
+
},
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/reactivemarkets/react-financial-charts/issues"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "npm run clean && npm run compile",
|
|
37
|
+
"clean": "rimraf lib",
|
|
38
|
+
"compile": "tsc -p tsconfig.json",
|
|
39
|
+
"watch": "tsc -p tsconfig.json --watch --preserveWatchOutput"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@ivanmatiaspascual/coordinates": "^1.3.1-sp1-beta.0.1.0",
|
|
43
|
+
"@ivanmatiaspascual/core": "^1.3.1-sp1-beta.0.1.0",
|
|
44
|
+
"d3-array": "^2.9.1",
|
|
45
|
+
"d3-format": "^2.0.0",
|
|
46
|
+
"d3-interpolate": "^2.0.1",
|
|
47
|
+
"d3-path": "^2.0.0",
|
|
48
|
+
"prop-types": "^15.7.2"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"react": "^16.0.0 || ^17.0.0",
|
|
52
|
+
"react-dom": "^16.0.0 || ^17.0.0"
|
|
53
|
+
},
|
|
54
|
+
"gitHead": "1d582c75091a920b628171c4a7f948aa15362e2b"
|
|
55
|
+
}
|
package/src/Brush.tsx
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import {
|
|
3
|
+
getStrokeDasharrayCanvas,
|
|
4
|
+
getMouseCanvas,
|
|
5
|
+
GenericChartComponent,
|
|
6
|
+
strokeDashTypes,
|
|
7
|
+
} from "@ivanmatiaspascual/core";
|
|
8
|
+
|
|
9
|
+
interface BrushProps {
|
|
10
|
+
readonly enabled: boolean;
|
|
11
|
+
readonly onBrush: ({ start, end }: any, moreProps: any) => void;
|
|
12
|
+
readonly type?: "1D" | "2D";
|
|
13
|
+
readonly strokeStyle?: string;
|
|
14
|
+
readonly fillStyle?: string;
|
|
15
|
+
readonly interactiveState: object;
|
|
16
|
+
readonly strokeDashArray?: strokeDashTypes;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface BrushState {
|
|
20
|
+
end?: any;
|
|
21
|
+
rect: any | null;
|
|
22
|
+
selected?: boolean;
|
|
23
|
+
start?: any;
|
|
24
|
+
x1y1?: any;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class Brush extends React.Component<BrushProps, BrushState> {
|
|
28
|
+
public static defaultProps = {
|
|
29
|
+
type: "2D",
|
|
30
|
+
strokeStyle: "#000000",
|
|
31
|
+
fillStyle: "#3h3h3h",
|
|
32
|
+
strokeDashArray: "ShortDash",
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
private zoomHappening?: boolean;
|
|
36
|
+
|
|
37
|
+
public constructor(props: BrushProps) {
|
|
38
|
+
super(props);
|
|
39
|
+
|
|
40
|
+
this.terminate = this.terminate.bind(this);
|
|
41
|
+
this.state = {
|
|
42
|
+
rect: null,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public terminate() {
|
|
47
|
+
this.zoomHappening = false;
|
|
48
|
+
this.setState({
|
|
49
|
+
x1y1: null,
|
|
50
|
+
start: null,
|
|
51
|
+
end: null,
|
|
52
|
+
rect: null,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public render() {
|
|
57
|
+
const { enabled } = this.props;
|
|
58
|
+
if (!enabled) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<GenericChartComponent
|
|
64
|
+
disablePan={enabled}
|
|
65
|
+
canvasToDraw={getMouseCanvas}
|
|
66
|
+
canvasDraw={this.drawOnCanvas}
|
|
67
|
+
onMouseDown={this.handleZoomStart}
|
|
68
|
+
onMouseMove={this.handleDrawSquare}
|
|
69
|
+
onClick={this.handleZoomComplete}
|
|
70
|
+
drawOn={["mousemove", "pan", "drag"]}
|
|
71
|
+
/>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
private readonly drawOnCanvas = (ctx: CanvasRenderingContext2D) => {
|
|
76
|
+
const { rect } = this.state;
|
|
77
|
+
if (rect === null) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const { x, y, height, width } = rect;
|
|
82
|
+
const {
|
|
83
|
+
strokeStyle = Brush.defaultProps.strokeStyle,
|
|
84
|
+
fillStyle = Brush.defaultProps.fillStyle,
|
|
85
|
+
strokeDashArray,
|
|
86
|
+
} = this.props;
|
|
87
|
+
|
|
88
|
+
const dashArray = getStrokeDasharrayCanvas(strokeDashArray);
|
|
89
|
+
|
|
90
|
+
ctx.strokeStyle = strokeStyle;
|
|
91
|
+
ctx.fillStyle = fillStyle;
|
|
92
|
+
ctx.setLineDash(dashArray);
|
|
93
|
+
ctx.beginPath();
|
|
94
|
+
ctx.fillRect(x, y, width, height);
|
|
95
|
+
ctx.strokeRect(x, y, width, height);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
private readonly handleZoomStart = (_: React.MouseEvent, moreProps: any) => {
|
|
99
|
+
this.zoomHappening = false;
|
|
100
|
+
const {
|
|
101
|
+
mouseXY: [, mouseY],
|
|
102
|
+
currentItem,
|
|
103
|
+
chartConfig: { yScale },
|
|
104
|
+
xAccessor,
|
|
105
|
+
xScale,
|
|
106
|
+
} = moreProps;
|
|
107
|
+
|
|
108
|
+
const x1y1 = [xScale(xAccessor(currentItem)), mouseY];
|
|
109
|
+
|
|
110
|
+
this.setState({
|
|
111
|
+
selected: true,
|
|
112
|
+
x1y1,
|
|
113
|
+
start: {
|
|
114
|
+
item: currentItem,
|
|
115
|
+
xValue: xAccessor(currentItem),
|
|
116
|
+
yValue: yScale.invert(mouseY),
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
private readonly handleDrawSquare = (_: React.MouseEvent, moreProps: any) => {
|
|
122
|
+
if (this.state.x1y1 == null) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
this.zoomHappening = true;
|
|
127
|
+
|
|
128
|
+
const {
|
|
129
|
+
mouseXY: [, mouseY],
|
|
130
|
+
currentItem,
|
|
131
|
+
chartConfig: { yScale },
|
|
132
|
+
xAccessor,
|
|
133
|
+
xScale,
|
|
134
|
+
} = moreProps;
|
|
135
|
+
|
|
136
|
+
const [x2, y2] = [xScale(xAccessor(currentItem)), mouseY];
|
|
137
|
+
|
|
138
|
+
const {
|
|
139
|
+
x1y1: [x1, y1],
|
|
140
|
+
} = this.state;
|
|
141
|
+
|
|
142
|
+
const x = Math.min(x1, x2);
|
|
143
|
+
const y = Math.min(y1, y2);
|
|
144
|
+
const height = Math.abs(y2 - y1);
|
|
145
|
+
const width = Math.abs(x2 - x1);
|
|
146
|
+
|
|
147
|
+
this.setState({
|
|
148
|
+
selected: true,
|
|
149
|
+
end: {
|
|
150
|
+
item: currentItem,
|
|
151
|
+
xValue: xAccessor(currentItem),
|
|
152
|
+
yValue: yScale.invert(mouseY),
|
|
153
|
+
},
|
|
154
|
+
rect: {
|
|
155
|
+
x,
|
|
156
|
+
y,
|
|
157
|
+
height,
|
|
158
|
+
width,
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
private readonly handleZoomComplete = (_: React.MouseEvent, moreProps: any) => {
|
|
164
|
+
if (this.zoomHappening) {
|
|
165
|
+
const { onBrush } = this.props;
|
|
166
|
+
if (onBrush !== undefined) {
|
|
167
|
+
const { start, end } = this.state;
|
|
168
|
+
onBrush({ start, end }, moreProps);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
this.setState({
|
|
173
|
+
selected: false,
|
|
174
|
+
rect: null,
|
|
175
|
+
});
|
|
176
|
+
};
|
|
177
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { getMouseCanvas, GenericChartComponent } from "@ivanmatiaspascual/core";
|
|
3
|
+
|
|
4
|
+
interface ClickCallbackProps {
|
|
5
|
+
readonly disablePan: boolean;
|
|
6
|
+
readonly onMouseDown?: (e: React.MouseEvent<Element, MouseEvent>, moreProps: any) => void;
|
|
7
|
+
readonly onClick?: (e: React.MouseEvent<Element, MouseEvent>, moreProps: any) => void;
|
|
8
|
+
readonly onDoubleClick?: (e: React.MouseEvent<Element, MouseEvent>, moreProps: any) => void;
|
|
9
|
+
readonly onContextMenu?: (e: React.MouseEvent<Element, MouseEvent>, moreProps: any) => void;
|
|
10
|
+
readonly onMouseMove?: (e: React.MouseEvent<Element, MouseEvent>, moreProps: any) => void;
|
|
11
|
+
readonly onPan?: (e: React.MouseEvent<Element, MouseEvent>, moreProps: any) => void;
|
|
12
|
+
readonly onPanEnd?: (e: React.MouseEvent<Element, MouseEvent>, moreProps: any) => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class ClickCallback extends React.Component<ClickCallbackProps> {
|
|
16
|
+
public static defaultProps = {
|
|
17
|
+
disablePan: false,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
public render() {
|
|
21
|
+
const { onMouseDown, onClick, onDoubleClick, onContextMenu, onMouseMove, onPan, onPanEnd } = this.props;
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<GenericChartComponent
|
|
25
|
+
onMouseDown={onMouseDown}
|
|
26
|
+
onClick={onClick}
|
|
27
|
+
onDoubleClick={onDoubleClick}
|
|
28
|
+
onContextMenu={onContextMenu}
|
|
29
|
+
onMouseMove={onMouseMove}
|
|
30
|
+
onPan={onPan}
|
|
31
|
+
onPanEnd={onPanEnd}
|
|
32
|
+
canvasToDraw={getMouseCanvas}
|
|
33
|
+
drawOn={["mousemove", "pan"]}
|
|
34
|
+
/>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { head, isDefined, mapObject, GenericComponent, getMouseCanvas } from "@ivanmatiaspascual/core";
|
|
3
|
+
import { getMorePropsForChart, getSelected } from "./utils";
|
|
4
|
+
|
|
5
|
+
interface DrawingObjectSelectorProps {
|
|
6
|
+
readonly getInteractiveNodes: () => any[];
|
|
7
|
+
readonly onSelect?: (e: React.MouseEvent, interactives: any[], moreProps: any) => void;
|
|
8
|
+
readonly onDoubleClick?: (e: React.MouseEvent, item: any, moreProps: any) => void;
|
|
9
|
+
readonly drawingObjectMap: any;
|
|
10
|
+
readonly enabled: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class DrawingObjectSelector extends React.Component<DrawingObjectSelectorProps> {
|
|
14
|
+
public static defaultProps = {
|
|
15
|
+
enabled: true,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
public render() {
|
|
19
|
+
return (
|
|
20
|
+
<GenericComponent
|
|
21
|
+
canvasToDraw={getMouseCanvas}
|
|
22
|
+
onMouseDown={this.handleClick}
|
|
23
|
+
onDoubleClick={this.handleDoubleClick}
|
|
24
|
+
drawOn={["mousemove", "pan", "drag"]}
|
|
25
|
+
/>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
private readonly getInteraction = (moreProps: any) => {
|
|
30
|
+
const { getInteractiveNodes, drawingObjectMap } = this.props;
|
|
31
|
+
const interactiveNodes = getInteractiveNodes();
|
|
32
|
+
const interactives = mapObject(interactiveNodes, (each) => {
|
|
33
|
+
const key = drawingObjectMap[each.type];
|
|
34
|
+
|
|
35
|
+
const valueArray = isDefined(key) ? each.node.props[key] : undefined;
|
|
36
|
+
|
|
37
|
+
const valuePresent = isDefined(valueArray) && Array.isArray(valueArray) && valueArray.length > 0;
|
|
38
|
+
if (valuePresent) {
|
|
39
|
+
const morePropsForChart = getMorePropsForChart(moreProps, each.chartId);
|
|
40
|
+
|
|
41
|
+
const objects = each.node.getSelectionState(morePropsForChart);
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
type: each.type,
|
|
45
|
+
chartId: each.chartId,
|
|
46
|
+
objects,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
type: each.type,
|
|
51
|
+
chartId: each.chartId,
|
|
52
|
+
objects: [],
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
return interactives;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
private readonly handleClick = (e: React.MouseEvent, moreProps: any) => {
|
|
60
|
+
e.preventDefault();
|
|
61
|
+
const { onSelect } = this.props;
|
|
62
|
+
const { enabled } = this.props;
|
|
63
|
+
if (!enabled) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const interactives = this.getInteraction(moreProps);
|
|
68
|
+
if (onSelect !== undefined) {
|
|
69
|
+
onSelect(e, interactives, moreProps);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
private readonly handleDoubleClick = (e: React.MouseEvent, moreProps: any) => {
|
|
74
|
+
e.preventDefault();
|
|
75
|
+
const { onDoubleClick } = this.props;
|
|
76
|
+
const { enabled } = this.props;
|
|
77
|
+
if (!enabled) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const interactives = this.getInteraction(moreProps);
|
|
82
|
+
const allSelected = getSelected(interactives);
|
|
83
|
+
|
|
84
|
+
if (allSelected.length > 0) {
|
|
85
|
+
const selected = head(allSelected);
|
|
86
|
+
const item = {
|
|
87
|
+
type: selected.type,
|
|
88
|
+
chartId: selected.chartId,
|
|
89
|
+
object: head(selected.objects),
|
|
90
|
+
};
|
|
91
|
+
const morePropsForChart = getMorePropsForChart(moreProps, selected.chartId);
|
|
92
|
+
if (onDoubleClick !== undefined) {
|
|
93
|
+
onDoubleClick(e, item, morePropsForChart);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { isDefined, isNotDefined, noop } from "@ivanmatiaspascual/core";
|
|
3
|
+
import { HoverTextNearMouse, MouseLocationIndicator } from "./components";
|
|
4
|
+
import { getSlope, getYIntercept } from "./components/InteractiveStraightLine";
|
|
5
|
+
import { isHoverForInteractiveType, saveNodeType, terminate } from "./utils";
|
|
6
|
+
import { EachEquidistantChannel } from "./wrapper";
|
|
7
|
+
|
|
8
|
+
interface EquidistantChannelProps {
|
|
9
|
+
readonly enabled: boolean;
|
|
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 hoverText: object;
|
|
18
|
+
readonly channels: any[];
|
|
19
|
+
readonly appearance: {
|
|
20
|
+
readonly stroke: string;
|
|
21
|
+
readonly strokeOpacity: number;
|
|
22
|
+
readonly strokeWidth: number;
|
|
23
|
+
readonly fill: string;
|
|
24
|
+
readonly fillOpacity: number;
|
|
25
|
+
readonly edgeStroke: string;
|
|
26
|
+
readonly edgeFill: string;
|
|
27
|
+
readonly edgeFill2: string;
|
|
28
|
+
readonly edgeStrokeWidth: number;
|
|
29
|
+
readonly r: number;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface EquidistantChannelState {
|
|
34
|
+
current?: any;
|
|
35
|
+
override?: any;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export class EquidistantChannel extends React.Component<EquidistantChannelProps, EquidistantChannelState> {
|
|
39
|
+
public static defaultProps = {
|
|
40
|
+
onSelect: noop,
|
|
41
|
+
currentPositionStroke: "#000000",
|
|
42
|
+
currentPositionOpacity: 1,
|
|
43
|
+
currentPositionStrokeWidth: 3,
|
|
44
|
+
currentPositionRadius: 4,
|
|
45
|
+
hoverText: {
|
|
46
|
+
...HoverTextNearMouse.defaultProps,
|
|
47
|
+
enable: true,
|
|
48
|
+
bgHeight: 18,
|
|
49
|
+
bgWidth: 120,
|
|
50
|
+
text: "Click to select object",
|
|
51
|
+
},
|
|
52
|
+
channels: [],
|
|
53
|
+
appearance: {
|
|
54
|
+
stroke: "#000000",
|
|
55
|
+
strokeOpacity: 1,
|
|
56
|
+
strokeWidth: 1,
|
|
57
|
+
fill: "#8AAFE2",
|
|
58
|
+
fillOpacity: 0.7,
|
|
59
|
+
edgeStroke: "#000000",
|
|
60
|
+
edgeFill: "#FFFFFF",
|
|
61
|
+
edgeFill2: "#250B98",
|
|
62
|
+
edgeStrokeWidth: 1,
|
|
63
|
+
r: 5,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// @ts-ignore
|
|
68
|
+
private terminate: () => void;
|
|
69
|
+
private saveNodeType: any;
|
|
70
|
+
// @ts-ignore
|
|
71
|
+
private getSelectionState: any;
|
|
72
|
+
private mouseMoved: any;
|
|
73
|
+
|
|
74
|
+
public constructor(props: EquidistantChannelProps) {
|
|
75
|
+
super(props);
|
|
76
|
+
|
|
77
|
+
this.terminate = terminate.bind(this);
|
|
78
|
+
this.saveNodeType = saveNodeType.bind(this);
|
|
79
|
+
this.getSelectionState = isHoverForInteractiveType("channels").bind(this);
|
|
80
|
+
|
|
81
|
+
this.state = {};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public render() {
|
|
85
|
+
const {
|
|
86
|
+
appearance,
|
|
87
|
+
channels,
|
|
88
|
+
currentPositionOpacity,
|
|
89
|
+
currentPositionRadius = EquidistantChannel.defaultProps.currentPositionRadius,
|
|
90
|
+
currentPositionStroke,
|
|
91
|
+
currentPositionStrokeWidth,
|
|
92
|
+
enabled,
|
|
93
|
+
hoverText,
|
|
94
|
+
} = this.props;
|
|
95
|
+
|
|
96
|
+
const { current, override } = this.state;
|
|
97
|
+
|
|
98
|
+
const overrideIndex = isDefined(override) ? override.index : null;
|
|
99
|
+
|
|
100
|
+
const tempChannel =
|
|
101
|
+
isDefined(current) && isDefined(current.endXY) ? (
|
|
102
|
+
<EachEquidistantChannel
|
|
103
|
+
interactive={false}
|
|
104
|
+
{...current}
|
|
105
|
+
appearance={appearance}
|
|
106
|
+
hoverText={hoverText}
|
|
107
|
+
/>
|
|
108
|
+
) : null;
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<g>
|
|
112
|
+
{channels.map((each, idx) => {
|
|
113
|
+
const eachAppearance = isDefined(each.appearance)
|
|
114
|
+
? { ...appearance, ...each.appearance }
|
|
115
|
+
: appearance;
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<EachEquidistantChannel
|
|
119
|
+
key={idx}
|
|
120
|
+
ref={this.saveNodeType(idx)}
|
|
121
|
+
index={idx}
|
|
122
|
+
selected={each.selected}
|
|
123
|
+
hoverText={hoverText}
|
|
124
|
+
{...(idx === overrideIndex ? override : each)}
|
|
125
|
+
appearance={eachAppearance}
|
|
126
|
+
onDrag={this.handleDragChannel}
|
|
127
|
+
onDragComplete={this.handleDragChannelComplete}
|
|
128
|
+
/>
|
|
129
|
+
);
|
|
130
|
+
})}
|
|
131
|
+
{tempChannel}
|
|
132
|
+
<MouseLocationIndicator
|
|
133
|
+
enabled={enabled}
|
|
134
|
+
snap={false}
|
|
135
|
+
r={currentPositionRadius}
|
|
136
|
+
stroke={currentPositionStroke}
|
|
137
|
+
opacity={currentPositionOpacity}
|
|
138
|
+
strokeWidth={currentPositionStrokeWidth}
|
|
139
|
+
onMouseDown={this.handleStart}
|
|
140
|
+
onClick={this.handleEnd}
|
|
141
|
+
onMouseMove={this.handleDrawChannel}
|
|
142
|
+
/>
|
|
143
|
+
</g>
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
private readonly handleDragChannel = (_: React.MouseEvent, index: any, newXYValue: any) => {
|
|
148
|
+
this.setState({
|
|
149
|
+
override: {
|
|
150
|
+
index,
|
|
151
|
+
...newXYValue,
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
private readonly handleDragChannelComplete = (e: React.MouseEvent, moreProps: any) => {
|
|
157
|
+
const { override } = this.state;
|
|
158
|
+
const { channels } = this.props;
|
|
159
|
+
|
|
160
|
+
if (isDefined(override)) {
|
|
161
|
+
const { index, ...rest } = override;
|
|
162
|
+
const newChannels = channels.map((each, idx) =>
|
|
163
|
+
idx === index ? { ...each, ...rest, selected: true } : each,
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
this.setState(
|
|
167
|
+
{
|
|
168
|
+
override: null,
|
|
169
|
+
},
|
|
170
|
+
() => {
|
|
171
|
+
const { onComplete } = this.props;
|
|
172
|
+
if (onComplete !== undefined) {
|
|
173
|
+
onComplete(e, newChannels, moreProps);
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
private readonly handleStart = (_: React.MouseEvent, xyValue: any) => {
|
|
181
|
+
const { current } = this.state;
|
|
182
|
+
|
|
183
|
+
if (isNotDefined(current) || isNotDefined(current.startXY)) {
|
|
184
|
+
this.mouseMoved = false;
|
|
185
|
+
this.setState(
|
|
186
|
+
{
|
|
187
|
+
current: {
|
|
188
|
+
startXY: xyValue,
|
|
189
|
+
endXY: null,
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
() => {
|
|
193
|
+
const { onStart } = this.props;
|
|
194
|
+
if (onStart !== undefined) {
|
|
195
|
+
onStart();
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
private readonly handleEnd = (e: React.MouseEvent, _: any, moreProps: any) => {
|
|
203
|
+
const { current } = this.state;
|
|
204
|
+
const { channels, appearance } = this.props;
|
|
205
|
+
|
|
206
|
+
if (this.mouseMoved && isDefined(current) && isDefined(current.startXY)) {
|
|
207
|
+
if (isNotDefined(current.dy)) {
|
|
208
|
+
this.setState({
|
|
209
|
+
current: {
|
|
210
|
+
...current,
|
|
211
|
+
dy: 0,
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
} else {
|
|
215
|
+
const newChannels = [
|
|
216
|
+
...channels.map((d) => ({ ...d, selected: false })),
|
|
217
|
+
{
|
|
218
|
+
...current,
|
|
219
|
+
selected: true,
|
|
220
|
+
appearance,
|
|
221
|
+
},
|
|
222
|
+
];
|
|
223
|
+
|
|
224
|
+
this.setState(
|
|
225
|
+
{
|
|
226
|
+
current: null,
|
|
227
|
+
},
|
|
228
|
+
() => {
|
|
229
|
+
const { onComplete } = this.props;
|
|
230
|
+
if (onComplete !== undefined) {
|
|
231
|
+
onComplete(e, newChannels, moreProps);
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
private readonly handleDrawChannel = (_: React.MouseEvent, xyValue: any) => {
|
|
240
|
+
const { current } = this.state;
|
|
241
|
+
|
|
242
|
+
if (isDefined(current) && isDefined(current.startXY)) {
|
|
243
|
+
this.mouseMoved = true;
|
|
244
|
+
if (isNotDefined(current.dy)) {
|
|
245
|
+
this.setState({
|
|
246
|
+
current: {
|
|
247
|
+
startXY: current.startXY,
|
|
248
|
+
endXY: xyValue,
|
|
249
|
+
},
|
|
250
|
+
});
|
|
251
|
+
} else {
|
|
252
|
+
const m = getSlope(current.startXY, current.endXY);
|
|
253
|
+
const b = getYIntercept(m, current.endXY);
|
|
254
|
+
|
|
255
|
+
// @ts-ignore
|
|
256
|
+
const y = m * xyValue[0] + b;
|
|
257
|
+
const dy = xyValue[1] - y;
|
|
258
|
+
|
|
259
|
+
this.setState({
|
|
260
|
+
current: {
|
|
261
|
+
...current,
|
|
262
|
+
dy,
|
|
263
|
+
},
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
}
|