@tradingaction/coordinates 2.0.11 → 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 -24
- package/README.md +5 -5
- package/lib/CrossHairCursor.d.ts +22 -22
- package/lib/CrossHairCursor.js +75 -75
- package/lib/CurrentCoordinate.d.ts +31 -31
- package/lib/CurrentCoordinate.js +53 -53
- package/lib/Cursor.d.ts +31 -31
- package/lib/Cursor.js +121 -121
- package/lib/EdgeCoordinate.d.ts +32 -32
- package/lib/EdgeCoordinate.js +150 -150
- package/lib/EdgeCoordinateV2.d.ts +3 -3
- package/lib/EdgeCoordinateV2.js +137 -137
- package/lib/EdgeCoordinateV3.d.ts +3 -3
- package/lib/EdgeCoordinateV3.js +175 -175
- package/lib/EdgeIndicator.d.ts +55 -55
- package/lib/EdgeIndicator.js +84 -84
- package/lib/EdgeIndicator.js.map +1 -1
- package/lib/MouseCoordinateX.d.ts +49 -49
- package/lib/MouseCoordinateX.js +84 -84
- package/lib/MouseCoordinateXV2.d.ts +61 -61
- package/lib/MouseCoordinateXV2.js +91 -91
- package/lib/MouseCoordinateY.d.ts +68 -68
- package/lib/MouseCoordinateY.js +90 -90
- package/lib/PriceCoordinate.d.ts +53 -53
- package/lib/PriceCoordinate.js +80 -80
- package/lib/index.d.ts +8 -8
- package/lib/index.js +8 -8
- package/package.json +3 -3
- package/src/EdgeIndicator.tsx +1 -9
package/lib/EdgeCoordinateV2.js
CHANGED
|
@@ -1,138 +1,138 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
export function renderSVG(props) {
|
|
3
|
-
const { className } = props;
|
|
4
|
-
const edge = helper(props);
|
|
5
|
-
if (edge === null) {
|
|
6
|
-
return null;
|
|
7
|
-
}
|
|
8
|
-
let line;
|
|
9
|
-
let coordinateBase;
|
|
10
|
-
let coordinate;
|
|
11
|
-
if (edge.line !== undefined) {
|
|
12
|
-
line = (React.createElement("line", { className: "react-financial-charts-cross-hair", stroke: edge.line.stroke, x1: edge.line.x1, y1: edge.line.y1, x2: edge.line.x2, y2: edge.line.y2 }));
|
|
13
|
-
}
|
|
14
|
-
if (edge.coordinate !== undefined && edge.coordinateBase !== undefined) {
|
|
15
|
-
const { rectWidth, rectHeight, arrowWidth } = edge.coordinateBase;
|
|
16
|
-
const path = edge.orient === "left"
|
|
17
|
-
? `M0,0L0,${rectHeight}L${rectWidth},${rectHeight}L${rectWidth + arrowWidth},10L${rectWidth},0L0,0L0,0`
|
|
18
|
-
: `M0,${arrowWidth}L${arrowWidth},${rectHeight}L${rectWidth + arrowWidth},${rectHeight}L${rectWidth + arrowWidth},0L${arrowWidth},0L0,${arrowWidth}`;
|
|
19
|
-
coordinateBase =
|
|
20
|
-
edge.orient === "left" || edge.orient === "right" ? (React.createElement("g", { transform: `translate(${edge.coordinateBase.edgeXRect},${edge.coordinateBase.edgeYRect})` },
|
|
21
|
-
React.createElement("path", { d: path, key: 1, className: "react-financial-charts-text-background", height: rectHeight, width: rectWidth, fill: edge.coordinateBase.fill }))) : (React.createElement("rect", { key: 1, className: "react-financial-charts-text-background", x: edge.coordinateBase.edgeXRect, y: edge.coordinateBase.edgeYRect, height: rectHeight, width: rectWidth, fill: edge.coordinateBase.fill }));
|
|
22
|
-
coordinate = (React.createElement("text", { key: 2, x: edge.coordinate.edgeXText, y: edge.coordinate.edgeYText, textAnchor: edge.coordinate.textAnchor, fontFamily: edge.coordinate.fontFamily, fontSize: edge.coordinate.fontSize, dy: ".32em", fill: edge.coordinate.textFill }, edge.coordinate.displayCoordinate));
|
|
23
|
-
}
|
|
24
|
-
return (React.createElement("g", { className: className },
|
|
25
|
-
line,
|
|
26
|
-
coordinateBase,
|
|
27
|
-
coordinate));
|
|
28
|
-
}
|
|
29
|
-
function helper(props) {
|
|
30
|
-
const { coordinate: displayCoordinate, show, type, orient, edgeAt, hideLine } = props;
|
|
31
|
-
const { fill, fontFamily, fontSize, textFill, lineStroke, arrowWidth } = props;
|
|
32
|
-
const { rectWidth, rectHeight } = props;
|
|
33
|
-
const { x1, y1, x2, y2, dx } = props;
|
|
34
|
-
if (!show) {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
let edgeXRect;
|
|
38
|
-
let edgeYRect;
|
|
39
|
-
let edgeXText;
|
|
40
|
-
let edgeYText;
|
|
41
|
-
if (type === "horizontal") {
|
|
42
|
-
edgeXRect = dx + (orient === "right" ? edgeAt + 1 : edgeAt - rectWidth - arrowWidth - 1);
|
|
43
|
-
edgeYRect = y1 - rectHeight / 2;
|
|
44
|
-
edgeXText =
|
|
45
|
-
dx + (orient === "right" ? edgeAt + rectWidth / 2 + arrowWidth : edgeAt - rectWidth / 2 - arrowWidth);
|
|
46
|
-
edgeYText = y1;
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
edgeXRect = x1 - rectWidth / 2;
|
|
50
|
-
edgeYRect = orient === "bottom" ? edgeAt : edgeAt - rectHeight;
|
|
51
|
-
edgeXText = x1;
|
|
52
|
-
edgeYText = orient === "bottom" ? edgeAt + rectHeight / 2 : edgeAt - rectHeight / 2;
|
|
53
|
-
}
|
|
54
|
-
let coordinateBase;
|
|
55
|
-
let coordinate;
|
|
56
|
-
const textAnchor = "middle";
|
|
57
|
-
if (displayCoordinate !== undefined) {
|
|
58
|
-
coordinateBase = {
|
|
59
|
-
edgeXRect,
|
|
60
|
-
edgeYRect,
|
|
61
|
-
rectHeight,
|
|
62
|
-
rectWidth,
|
|
63
|
-
fill,
|
|
64
|
-
arrowWidth,
|
|
65
|
-
};
|
|
66
|
-
coordinate = {
|
|
67
|
-
edgeXText,
|
|
68
|
-
edgeYText,
|
|
69
|
-
textAnchor,
|
|
70
|
-
fontFamily,
|
|
71
|
-
fontSize,
|
|
72
|
-
textFill,
|
|
73
|
-
displayCoordinate,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
const line = hideLine
|
|
77
|
-
? undefined
|
|
78
|
-
: {
|
|
79
|
-
stroke: lineStroke,
|
|
80
|
-
x1,
|
|
81
|
-
y1,
|
|
82
|
-
x2,
|
|
83
|
-
y2,
|
|
84
|
-
};
|
|
85
|
-
return {
|
|
86
|
-
coordinateBase,
|
|
87
|
-
coordinate,
|
|
88
|
-
line,
|
|
89
|
-
orient,
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
export function drawOnCanvas(ctx, props) {
|
|
93
|
-
const edge = helper(props);
|
|
94
|
-
if (edge === null) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
if (edge.coordinate !== undefined && edge.coordinateBase !== undefined) {
|
|
98
|
-
const { rectWidth, rectHeight, arrowWidth } = edge.coordinateBase;
|
|
99
|
-
ctx.fillStyle = edge.coordinateBase.fill;
|
|
100
|
-
const x = edge.coordinateBase.edgeXRect;
|
|
101
|
-
const y = edge.coordinateBase.edgeYRect;
|
|
102
|
-
ctx.beginPath();
|
|
103
|
-
if (edge.orient === "right") {
|
|
104
|
-
ctx.moveTo(x, y + rectHeight / 2);
|
|
105
|
-
ctx.lineTo(x + arrowWidth, y);
|
|
106
|
-
ctx.lineTo(x + rectWidth + arrowWidth, y);
|
|
107
|
-
ctx.lineTo(x + rectWidth + arrowWidth, y + rectHeight);
|
|
108
|
-
ctx.lineTo(x + arrowWidth, y + rectHeight);
|
|
109
|
-
ctx.closePath();
|
|
110
|
-
}
|
|
111
|
-
else if (edge.orient === "left") {
|
|
112
|
-
ctx.moveTo(x, y);
|
|
113
|
-
ctx.lineTo(x + rectWidth, y);
|
|
114
|
-
ctx.lineTo(x + rectWidth + arrowWidth, y + rectHeight / 2);
|
|
115
|
-
ctx.lineTo(x + rectWidth, y + rectHeight);
|
|
116
|
-
ctx.lineTo(x, y + rectHeight);
|
|
117
|
-
ctx.closePath();
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
ctx.rect(x, y, rectWidth, rectHeight);
|
|
121
|
-
}
|
|
122
|
-
ctx.fill();
|
|
123
|
-
ctx.font = `${edge.coordinate.fontSize}px ${edge.coordinate.fontFamily}`;
|
|
124
|
-
ctx.fillStyle = edge.coordinate.textFill;
|
|
125
|
-
ctx.textAlign =
|
|
126
|
-
edge.coordinate.textAnchor === "middle" ? "center" : edge.coordinate.textAnchor;
|
|
127
|
-
ctx.textBaseline = "middle";
|
|
128
|
-
ctx.fillText(edge.coordinate.displayCoordinate, edge.coordinate.edgeXText, edge.coordinate.edgeYText);
|
|
129
|
-
}
|
|
130
|
-
if (edge.line !== undefined) {
|
|
131
|
-
ctx.strokeStyle = edge.line.stroke;
|
|
132
|
-
ctx.beginPath();
|
|
133
|
-
ctx.moveTo(edge.line.x1, edge.line.y1);
|
|
134
|
-
ctx.lineTo(edge.line.x2, edge.line.y2);
|
|
135
|
-
ctx.stroke();
|
|
136
|
-
}
|
|
137
|
-
}
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export function renderSVG(props) {
|
|
3
|
+
const { className } = props;
|
|
4
|
+
const edge = helper(props);
|
|
5
|
+
if (edge === null) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
let line;
|
|
9
|
+
let coordinateBase;
|
|
10
|
+
let coordinate;
|
|
11
|
+
if (edge.line !== undefined) {
|
|
12
|
+
line = (React.createElement("line", { className: "react-financial-charts-cross-hair", stroke: edge.line.stroke, x1: edge.line.x1, y1: edge.line.y1, x2: edge.line.x2, y2: edge.line.y2 }));
|
|
13
|
+
}
|
|
14
|
+
if (edge.coordinate !== undefined && edge.coordinateBase !== undefined) {
|
|
15
|
+
const { rectWidth, rectHeight, arrowWidth } = edge.coordinateBase;
|
|
16
|
+
const path = edge.orient === "left"
|
|
17
|
+
? `M0,0L0,${rectHeight}L${rectWidth},${rectHeight}L${rectWidth + arrowWidth},10L${rectWidth},0L0,0L0,0`
|
|
18
|
+
: `M0,${arrowWidth}L${arrowWidth},${rectHeight}L${rectWidth + arrowWidth},${rectHeight}L${rectWidth + arrowWidth},0L${arrowWidth},0L0,${arrowWidth}`;
|
|
19
|
+
coordinateBase =
|
|
20
|
+
edge.orient === "left" || edge.orient === "right" ? (React.createElement("g", { transform: `translate(${edge.coordinateBase.edgeXRect},${edge.coordinateBase.edgeYRect})` },
|
|
21
|
+
React.createElement("path", { d: path, key: 1, className: "react-financial-charts-text-background", height: rectHeight, width: rectWidth, fill: edge.coordinateBase.fill }))) : (React.createElement("rect", { key: 1, className: "react-financial-charts-text-background", x: edge.coordinateBase.edgeXRect, y: edge.coordinateBase.edgeYRect, height: rectHeight, width: rectWidth, fill: edge.coordinateBase.fill }));
|
|
22
|
+
coordinate = (React.createElement("text", { key: 2, x: edge.coordinate.edgeXText, y: edge.coordinate.edgeYText, textAnchor: edge.coordinate.textAnchor, fontFamily: edge.coordinate.fontFamily, fontSize: edge.coordinate.fontSize, dy: ".32em", fill: edge.coordinate.textFill }, edge.coordinate.displayCoordinate));
|
|
23
|
+
}
|
|
24
|
+
return (React.createElement("g", { className: className },
|
|
25
|
+
line,
|
|
26
|
+
coordinateBase,
|
|
27
|
+
coordinate));
|
|
28
|
+
}
|
|
29
|
+
function helper(props) {
|
|
30
|
+
const { coordinate: displayCoordinate, show, type, orient, edgeAt, hideLine } = props;
|
|
31
|
+
const { fill, fontFamily, fontSize, textFill, lineStroke, arrowWidth } = props;
|
|
32
|
+
const { rectWidth, rectHeight } = props;
|
|
33
|
+
const { x1, y1, x2, y2, dx } = props;
|
|
34
|
+
if (!show) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
let edgeXRect;
|
|
38
|
+
let edgeYRect;
|
|
39
|
+
let edgeXText;
|
|
40
|
+
let edgeYText;
|
|
41
|
+
if (type === "horizontal") {
|
|
42
|
+
edgeXRect = dx + (orient === "right" ? edgeAt + 1 : edgeAt - rectWidth - arrowWidth - 1);
|
|
43
|
+
edgeYRect = y1 - rectHeight / 2;
|
|
44
|
+
edgeXText =
|
|
45
|
+
dx + (orient === "right" ? edgeAt + rectWidth / 2 + arrowWidth : edgeAt - rectWidth / 2 - arrowWidth);
|
|
46
|
+
edgeYText = y1;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
edgeXRect = x1 - rectWidth / 2;
|
|
50
|
+
edgeYRect = orient === "bottom" ? edgeAt : edgeAt - rectHeight;
|
|
51
|
+
edgeXText = x1;
|
|
52
|
+
edgeYText = orient === "bottom" ? edgeAt + rectHeight / 2 : edgeAt - rectHeight / 2;
|
|
53
|
+
}
|
|
54
|
+
let coordinateBase;
|
|
55
|
+
let coordinate;
|
|
56
|
+
const textAnchor = "middle";
|
|
57
|
+
if (displayCoordinate !== undefined) {
|
|
58
|
+
coordinateBase = {
|
|
59
|
+
edgeXRect,
|
|
60
|
+
edgeYRect,
|
|
61
|
+
rectHeight,
|
|
62
|
+
rectWidth,
|
|
63
|
+
fill,
|
|
64
|
+
arrowWidth,
|
|
65
|
+
};
|
|
66
|
+
coordinate = {
|
|
67
|
+
edgeXText,
|
|
68
|
+
edgeYText,
|
|
69
|
+
textAnchor,
|
|
70
|
+
fontFamily,
|
|
71
|
+
fontSize,
|
|
72
|
+
textFill,
|
|
73
|
+
displayCoordinate,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const line = hideLine
|
|
77
|
+
? undefined
|
|
78
|
+
: {
|
|
79
|
+
stroke: lineStroke,
|
|
80
|
+
x1,
|
|
81
|
+
y1,
|
|
82
|
+
x2,
|
|
83
|
+
y2,
|
|
84
|
+
};
|
|
85
|
+
return {
|
|
86
|
+
coordinateBase,
|
|
87
|
+
coordinate,
|
|
88
|
+
line,
|
|
89
|
+
orient,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
export function drawOnCanvas(ctx, props) {
|
|
93
|
+
const edge = helper(props);
|
|
94
|
+
if (edge === null) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (edge.coordinate !== undefined && edge.coordinateBase !== undefined) {
|
|
98
|
+
const { rectWidth, rectHeight, arrowWidth } = edge.coordinateBase;
|
|
99
|
+
ctx.fillStyle = edge.coordinateBase.fill;
|
|
100
|
+
const x = edge.coordinateBase.edgeXRect;
|
|
101
|
+
const y = edge.coordinateBase.edgeYRect;
|
|
102
|
+
ctx.beginPath();
|
|
103
|
+
if (edge.orient === "right") {
|
|
104
|
+
ctx.moveTo(x, y + rectHeight / 2);
|
|
105
|
+
ctx.lineTo(x + arrowWidth, y);
|
|
106
|
+
ctx.lineTo(x + rectWidth + arrowWidth, y);
|
|
107
|
+
ctx.lineTo(x + rectWidth + arrowWidth, y + rectHeight);
|
|
108
|
+
ctx.lineTo(x + arrowWidth, y + rectHeight);
|
|
109
|
+
ctx.closePath();
|
|
110
|
+
}
|
|
111
|
+
else if (edge.orient === "left") {
|
|
112
|
+
ctx.moveTo(x, y);
|
|
113
|
+
ctx.lineTo(x + rectWidth, y);
|
|
114
|
+
ctx.lineTo(x + rectWidth + arrowWidth, y + rectHeight / 2);
|
|
115
|
+
ctx.lineTo(x + rectWidth, y + rectHeight);
|
|
116
|
+
ctx.lineTo(x, y + rectHeight);
|
|
117
|
+
ctx.closePath();
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
ctx.rect(x, y, rectWidth, rectHeight);
|
|
121
|
+
}
|
|
122
|
+
ctx.fill();
|
|
123
|
+
ctx.font = `${edge.coordinate.fontSize}px ${edge.coordinate.fontFamily}`;
|
|
124
|
+
ctx.fillStyle = edge.coordinate.textFill;
|
|
125
|
+
ctx.textAlign =
|
|
126
|
+
edge.coordinate.textAnchor === "middle" ? "center" : edge.coordinate.textAnchor;
|
|
127
|
+
ctx.textBaseline = "middle";
|
|
128
|
+
ctx.fillText(edge.coordinate.displayCoordinate, edge.coordinate.edgeXText, edge.coordinate.edgeYText);
|
|
129
|
+
}
|
|
130
|
+
if (edge.line !== undefined) {
|
|
131
|
+
ctx.strokeStyle = edge.line.stroke;
|
|
132
|
+
ctx.beginPath();
|
|
133
|
+
ctx.moveTo(edge.line.x1, edge.line.y1);
|
|
134
|
+
ctx.lineTo(edge.line.x2, edge.line.y2);
|
|
135
|
+
ctx.stroke();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
138
|
//# sourceMappingURL=EdgeCoordinateV2.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
export declare const renderSVG: (props: any) => JSX.Element | null;
|
|
3
|
-
export declare const drawOnCanvas: (ctx: CanvasRenderingContext2D, props: any) => void;
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const renderSVG: (props: any) => JSX.Element | null;
|
|
3
|
+
export declare const drawOnCanvas: (ctx: CanvasRenderingContext2D, props: any) => void;
|
package/lib/EdgeCoordinateV3.js
CHANGED
|
@@ -1,176 +1,176 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { getStrokeDasharray, getStrokeDasharrayCanvas, isDefined } from "@tradingaction/core";
|
|
3
|
-
export const renderSVG = (props) => {
|
|
4
|
-
const { className } = props;
|
|
5
|
-
const edge = helper(props);
|
|
6
|
-
if (edge === null) {
|
|
7
|
-
return null;
|
|
8
|
-
}
|
|
9
|
-
let line;
|
|
10
|
-
let coordinateBase;
|
|
11
|
-
let coordinate;
|
|
12
|
-
if (edge.line !== undefined) {
|
|
13
|
-
line = (React.createElement("line", { className: "react-financial-charts-cross-hair", stroke: edge.line.stroke, strokeDasharray: getStrokeDasharray(edge.line.strokeDasharray), x1: edge.line.x1, y1: edge.line.y1, x2: edge.line.x2, y2: edge.line.y2 }));
|
|
14
|
-
}
|
|
15
|
-
if (edge.coordinate !== undefined && edge.coordinateBase !== undefined) {
|
|
16
|
-
const { rectWidth, rectHeight, arrowWidth } = edge.coordinateBase;
|
|
17
|
-
const path = edge.orient === "left"
|
|
18
|
-
? `M0,0L0,${rectHeight}L${rectWidth},${rectHeight}L${rectWidth + arrowWidth},10L${rectWidth},0L0,0L0,0`
|
|
19
|
-
: `M0,${arrowWidth}L${arrowWidth},${rectHeight}L${rectWidth + arrowWidth},${rectHeight}L${rectWidth + arrowWidth},0L${arrowWidth},0L0,${arrowWidth}`;
|
|
20
|
-
coordinateBase =
|
|
21
|
-
edge.orient === "left" || edge.orient === "right" ? (React.createElement("g", { key: 1, transform: `translate(${edge.coordinateBase.edgeXRect},${edge.coordinateBase.edgeYRect})` },
|
|
22
|
-
React.createElement("path", { d: path, className: "react-financial-charts-text-background", height: rectHeight, width: rectWidth, stroke: edge.coordinateBase.stroke, strokeLinejoin: "miter", strokeWidth: edge.coordinateBase.strokeWidth, fill: edge.coordinateBase.fill }))) : (React.createElement("rect", { key: 1, className: "react-financial-charts-text-background", x: edge.coordinateBase.edgeXRect, y: edge.coordinateBase.edgeYRect, height: rectHeight, width: rectWidth, fill: edge.coordinateBase.fill }));
|
|
23
|
-
coordinate = (React.createElement("text", { key: 2, x: edge.coordinate.edgeXText, y: edge.coordinate.edgeYText, textAnchor: edge.coordinate.textAnchor, fontFamily: edge.coordinate.fontFamily, fontSize: edge.coordinate.fontSize, dy: ".32em", fill: edge.coordinate.textFill }, edge.coordinate.displayCoordinate));
|
|
24
|
-
}
|
|
25
|
-
return (React.createElement("g", { className: className },
|
|
26
|
-
line,
|
|
27
|
-
coordinateBase,
|
|
28
|
-
coordinate));
|
|
29
|
-
};
|
|
30
|
-
const helper = (props) => {
|
|
31
|
-
const { coordinate: displayCoordinate, show, type, orient, edgeAt, hideLine, lineStrokeDasharray, fill, fontFamily, fontSize, textFill, lineStroke, stroke, strokeWidth, arrowWidth, rectWidth, rectHeight, rectRadius, x1, y1, x2, y2, dx, } = props;
|
|
32
|
-
if (!show) {
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
let coordinateBase;
|
|
36
|
-
let coordinate;
|
|
37
|
-
if (displayCoordinate !== undefined) {
|
|
38
|
-
const textAnchor = "middle";
|
|
39
|
-
let edgeXRect;
|
|
40
|
-
let edgeYRect;
|
|
41
|
-
let edgeXText;
|
|
42
|
-
let edgeYText;
|
|
43
|
-
if (type === "horizontal") {
|
|
44
|
-
edgeXRect = dx + (orient === "right" ? edgeAt + 1 : edgeAt - rectWidth - 1);
|
|
45
|
-
edgeYRect = y1 - rectHeight / 2 - strokeWidth;
|
|
46
|
-
edgeXText = dx + (orient === "right" ? edgeAt + rectWidth / 2 : edgeAt - rectWidth / 2);
|
|
47
|
-
edgeYText = y1;
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
const dy = orient === "bottom" ? strokeWidth - 1 : -strokeWidth + 1;
|
|
51
|
-
edgeXRect = x1 - rectWidth / 2;
|
|
52
|
-
edgeYRect = (orient === "bottom" ? edgeAt : edgeAt - rectHeight) + dy;
|
|
53
|
-
edgeXText = x1;
|
|
54
|
-
edgeYText = (orient === "bottom" ? edgeAt + rectHeight / 2 : edgeAt - rectHeight / 2) + dy;
|
|
55
|
-
}
|
|
56
|
-
coordinateBase = {
|
|
57
|
-
edgeXRect,
|
|
58
|
-
edgeYRect,
|
|
59
|
-
rectHeight: rectHeight + strokeWidth,
|
|
60
|
-
rectWidth,
|
|
61
|
-
rectRadius,
|
|
62
|
-
fill,
|
|
63
|
-
arrowWidth,
|
|
64
|
-
stroke,
|
|
65
|
-
strokeWidth,
|
|
66
|
-
};
|
|
67
|
-
coordinate = {
|
|
68
|
-
edgeXText,
|
|
69
|
-
edgeYText,
|
|
70
|
-
textAnchor,
|
|
71
|
-
fontFamily,
|
|
72
|
-
fontSize,
|
|
73
|
-
textFill,
|
|
74
|
-
displayCoordinate,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
const line = hideLine
|
|
78
|
-
? undefined
|
|
79
|
-
: {
|
|
80
|
-
stroke: lineStroke,
|
|
81
|
-
strokeDasharray: lineStrokeDasharray,
|
|
82
|
-
x1,
|
|
83
|
-
y1,
|
|
84
|
-
x2,
|
|
85
|
-
y2,
|
|
86
|
-
};
|
|
87
|
-
return {
|
|
88
|
-
coordinateBase,
|
|
89
|
-
coordinate,
|
|
90
|
-
line,
|
|
91
|
-
orient,
|
|
92
|
-
};
|
|
93
|
-
};
|
|
94
|
-
export const drawOnCanvas = (ctx, props) => {
|
|
95
|
-
const { coordinate, fitToText, fontSize, fontFamily, rectWidth } = props;
|
|
96
|
-
ctx.font = `${fontSize}px ${fontFamily}`;
|
|
97
|
-
ctx.textBaseline = "middle";
|
|
98
|
-
let width = rectWidth;
|
|
99
|
-
if (fitToText) {
|
|
100
|
-
width = Math.round(ctx.measureText(coordinate).width + 10);
|
|
101
|
-
}
|
|
102
|
-
const edge = helper(Object.assign(Object.assign({}, props), { rectWidth: width }));
|
|
103
|
-
if (edge === null) {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
if (edge.line !== undefined && isDefined(edge.line)) {
|
|
107
|
-
const dashArray = getStrokeDasharrayCanvas(edge.line.strokeDasharray);
|
|
108
|
-
ctx.setLineDash(dashArray);
|
|
109
|
-
ctx.strokeStyle = edge.line.stroke;
|
|
110
|
-
ctx.lineWidth = 1;
|
|
111
|
-
ctx.beginPath();
|
|
112
|
-
ctx.moveTo(edge.line.x1, edge.line.y1);
|
|
113
|
-
ctx.lineTo(edge.line.x2, edge.line.y2);
|
|
114
|
-
ctx.stroke();
|
|
115
|
-
}
|
|
116
|
-
ctx.setLineDash([]);
|
|
117
|
-
if (edge.coordinateBase !== undefined) {
|
|
118
|
-
const { arrowWidth, rectWidth, rectHeight, rectRadius } = edge.coordinateBase;
|
|
119
|
-
ctx.fillStyle = edge.coordinateBase.fill;
|
|
120
|
-
if (edge.coordinateBase.stroke !== undefined) {
|
|
121
|
-
ctx.strokeStyle = edge.coordinateBase.stroke;
|
|
122
|
-
ctx.lineWidth = edge.coordinateBase.strokeWidth;
|
|
123
|
-
}
|
|
124
|
-
let x = edge.coordinateBase.edgeXRect;
|
|
125
|
-
const y = edge.coordinateBase.edgeYRect;
|
|
126
|
-
const halfHeight = rectHeight / 2;
|
|
127
|
-
ctx.beginPath();
|
|
128
|
-
if (arrowWidth > 0 && edge.orient === "right") {
|
|
129
|
-
x -= arrowWidth;
|
|
130
|
-
ctx.moveTo(x, y + halfHeight);
|
|
131
|
-
ctx.lineTo(x + arrowWidth, y);
|
|
132
|
-
ctx.lineTo(x + rectWidth + arrowWidth, y);
|
|
133
|
-
ctx.lineTo(x + rectWidth + arrowWidth, y + rectHeight);
|
|
134
|
-
ctx.lineTo(x + arrowWidth, y + rectHeight);
|
|
135
|
-
ctx.closePath();
|
|
136
|
-
}
|
|
137
|
-
else if (arrowWidth > 0 && edge.orient === "left") {
|
|
138
|
-
ctx.moveTo(x, y);
|
|
139
|
-
ctx.lineTo(x + rectWidth, y);
|
|
140
|
-
ctx.lineTo(x + rectWidth + arrowWidth, y + halfHeight);
|
|
141
|
-
ctx.lineTo(x + rectWidth, y + rectHeight);
|
|
142
|
-
ctx.lineTo(x, y + rectHeight);
|
|
143
|
-
ctx.closePath();
|
|
144
|
-
}
|
|
145
|
-
else if (rectRadius) {
|
|
146
|
-
roundRect(ctx, x - 0.5, y - 0.5, rectWidth, rectHeight, 3);
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
ctx.rect(x - 0.5, y, rectWidth, rectHeight);
|
|
150
|
-
}
|
|
151
|
-
ctx.fill();
|
|
152
|
-
if (edge.coordinateBase.stroke !== undefined) {
|
|
153
|
-
ctx.stroke();
|
|
154
|
-
}
|
|
155
|
-
if (edge.coordinate !== undefined) {
|
|
156
|
-
ctx.fillStyle = edge.coordinate.textFill;
|
|
157
|
-
ctx.textAlign =
|
|
158
|
-
edge.coordinate.textAnchor === "middle" ? "center" : edge.coordinate.textAnchor;
|
|
159
|
-
ctx.fillText(edge.coordinate.displayCoordinate, edge.coordinate.edgeXText, edge.coordinate.edgeYText);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
const roundRect = (ctx, x, y, width, height, radius) => {
|
|
164
|
-
ctx.beginPath();
|
|
165
|
-
ctx.moveTo(x + radius, y);
|
|
166
|
-
ctx.lineTo(x + width - radius, y);
|
|
167
|
-
ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
|
|
168
|
-
ctx.lineTo(x + width, y + height - radius);
|
|
169
|
-
ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
|
|
170
|
-
ctx.lineTo(x + radius, y + height);
|
|
171
|
-
ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
|
|
172
|
-
ctx.lineTo(x, y + radius);
|
|
173
|
-
ctx.quadraticCurveTo(x, y, x + radius, y);
|
|
174
|
-
ctx.closePath();
|
|
175
|
-
};
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { getStrokeDasharray, getStrokeDasharrayCanvas, isDefined } from "@tradingaction/core";
|
|
3
|
+
export const renderSVG = (props) => {
|
|
4
|
+
const { className } = props;
|
|
5
|
+
const edge = helper(props);
|
|
6
|
+
if (edge === null) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
let line;
|
|
10
|
+
let coordinateBase;
|
|
11
|
+
let coordinate;
|
|
12
|
+
if (edge.line !== undefined) {
|
|
13
|
+
line = (React.createElement("line", { className: "react-financial-charts-cross-hair", stroke: edge.line.stroke, strokeDasharray: getStrokeDasharray(edge.line.strokeDasharray), x1: edge.line.x1, y1: edge.line.y1, x2: edge.line.x2, y2: edge.line.y2 }));
|
|
14
|
+
}
|
|
15
|
+
if (edge.coordinate !== undefined && edge.coordinateBase !== undefined) {
|
|
16
|
+
const { rectWidth, rectHeight, arrowWidth } = edge.coordinateBase;
|
|
17
|
+
const path = edge.orient === "left"
|
|
18
|
+
? `M0,0L0,${rectHeight}L${rectWidth},${rectHeight}L${rectWidth + arrowWidth},10L${rectWidth},0L0,0L0,0`
|
|
19
|
+
: `M0,${arrowWidth}L${arrowWidth},${rectHeight}L${rectWidth + arrowWidth},${rectHeight}L${rectWidth + arrowWidth},0L${arrowWidth},0L0,${arrowWidth}`;
|
|
20
|
+
coordinateBase =
|
|
21
|
+
edge.orient === "left" || edge.orient === "right" ? (React.createElement("g", { key: 1, transform: `translate(${edge.coordinateBase.edgeXRect},${edge.coordinateBase.edgeYRect})` },
|
|
22
|
+
React.createElement("path", { d: path, className: "react-financial-charts-text-background", height: rectHeight, width: rectWidth, stroke: edge.coordinateBase.stroke, strokeLinejoin: "miter", strokeWidth: edge.coordinateBase.strokeWidth, fill: edge.coordinateBase.fill }))) : (React.createElement("rect", { key: 1, className: "react-financial-charts-text-background", x: edge.coordinateBase.edgeXRect, y: edge.coordinateBase.edgeYRect, height: rectHeight, width: rectWidth, fill: edge.coordinateBase.fill }));
|
|
23
|
+
coordinate = (React.createElement("text", { key: 2, x: edge.coordinate.edgeXText, y: edge.coordinate.edgeYText, textAnchor: edge.coordinate.textAnchor, fontFamily: edge.coordinate.fontFamily, fontSize: edge.coordinate.fontSize, dy: ".32em", fill: edge.coordinate.textFill }, edge.coordinate.displayCoordinate));
|
|
24
|
+
}
|
|
25
|
+
return (React.createElement("g", { className: className },
|
|
26
|
+
line,
|
|
27
|
+
coordinateBase,
|
|
28
|
+
coordinate));
|
|
29
|
+
};
|
|
30
|
+
const helper = (props) => {
|
|
31
|
+
const { coordinate: displayCoordinate, show, type, orient, edgeAt, hideLine, lineStrokeDasharray, fill, fontFamily, fontSize, textFill, lineStroke, stroke, strokeWidth, arrowWidth, rectWidth, rectHeight, rectRadius, x1, y1, x2, y2, dx, } = props;
|
|
32
|
+
if (!show) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
let coordinateBase;
|
|
36
|
+
let coordinate;
|
|
37
|
+
if (displayCoordinate !== undefined) {
|
|
38
|
+
const textAnchor = "middle";
|
|
39
|
+
let edgeXRect;
|
|
40
|
+
let edgeYRect;
|
|
41
|
+
let edgeXText;
|
|
42
|
+
let edgeYText;
|
|
43
|
+
if (type === "horizontal") {
|
|
44
|
+
edgeXRect = dx + (orient === "right" ? edgeAt + 1 : edgeAt - rectWidth - 1);
|
|
45
|
+
edgeYRect = y1 - rectHeight / 2 - strokeWidth;
|
|
46
|
+
edgeXText = dx + (orient === "right" ? edgeAt + rectWidth / 2 : edgeAt - rectWidth / 2);
|
|
47
|
+
edgeYText = y1;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
const dy = orient === "bottom" ? strokeWidth - 1 : -strokeWidth + 1;
|
|
51
|
+
edgeXRect = x1 - rectWidth / 2;
|
|
52
|
+
edgeYRect = (orient === "bottom" ? edgeAt : edgeAt - rectHeight) + dy;
|
|
53
|
+
edgeXText = x1;
|
|
54
|
+
edgeYText = (orient === "bottom" ? edgeAt + rectHeight / 2 : edgeAt - rectHeight / 2) + dy;
|
|
55
|
+
}
|
|
56
|
+
coordinateBase = {
|
|
57
|
+
edgeXRect,
|
|
58
|
+
edgeYRect,
|
|
59
|
+
rectHeight: rectHeight + strokeWidth,
|
|
60
|
+
rectWidth,
|
|
61
|
+
rectRadius,
|
|
62
|
+
fill,
|
|
63
|
+
arrowWidth,
|
|
64
|
+
stroke,
|
|
65
|
+
strokeWidth,
|
|
66
|
+
};
|
|
67
|
+
coordinate = {
|
|
68
|
+
edgeXText,
|
|
69
|
+
edgeYText,
|
|
70
|
+
textAnchor,
|
|
71
|
+
fontFamily,
|
|
72
|
+
fontSize,
|
|
73
|
+
textFill,
|
|
74
|
+
displayCoordinate,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
const line = hideLine
|
|
78
|
+
? undefined
|
|
79
|
+
: {
|
|
80
|
+
stroke: lineStroke,
|
|
81
|
+
strokeDasharray: lineStrokeDasharray,
|
|
82
|
+
x1,
|
|
83
|
+
y1,
|
|
84
|
+
x2,
|
|
85
|
+
y2,
|
|
86
|
+
};
|
|
87
|
+
return {
|
|
88
|
+
coordinateBase,
|
|
89
|
+
coordinate,
|
|
90
|
+
line,
|
|
91
|
+
orient,
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
export const drawOnCanvas = (ctx, props) => {
|
|
95
|
+
const { coordinate, fitToText, fontSize, fontFamily, rectWidth } = props;
|
|
96
|
+
ctx.font = `${fontSize}px ${fontFamily}`;
|
|
97
|
+
ctx.textBaseline = "middle";
|
|
98
|
+
let width = rectWidth;
|
|
99
|
+
if (fitToText) {
|
|
100
|
+
width = Math.round(ctx.measureText(coordinate).width + 10);
|
|
101
|
+
}
|
|
102
|
+
const edge = helper(Object.assign(Object.assign({}, props), { rectWidth: width }));
|
|
103
|
+
if (edge === null) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (edge.line !== undefined && isDefined(edge.line)) {
|
|
107
|
+
const dashArray = getStrokeDasharrayCanvas(edge.line.strokeDasharray);
|
|
108
|
+
ctx.setLineDash(dashArray);
|
|
109
|
+
ctx.strokeStyle = edge.line.stroke;
|
|
110
|
+
ctx.lineWidth = 1;
|
|
111
|
+
ctx.beginPath();
|
|
112
|
+
ctx.moveTo(edge.line.x1, edge.line.y1);
|
|
113
|
+
ctx.lineTo(edge.line.x2, edge.line.y2);
|
|
114
|
+
ctx.stroke();
|
|
115
|
+
}
|
|
116
|
+
ctx.setLineDash([]);
|
|
117
|
+
if (edge.coordinateBase !== undefined) {
|
|
118
|
+
const { arrowWidth, rectWidth, rectHeight, rectRadius } = edge.coordinateBase;
|
|
119
|
+
ctx.fillStyle = edge.coordinateBase.fill;
|
|
120
|
+
if (edge.coordinateBase.stroke !== undefined) {
|
|
121
|
+
ctx.strokeStyle = edge.coordinateBase.stroke;
|
|
122
|
+
ctx.lineWidth = edge.coordinateBase.strokeWidth;
|
|
123
|
+
}
|
|
124
|
+
let x = edge.coordinateBase.edgeXRect;
|
|
125
|
+
const y = edge.coordinateBase.edgeYRect;
|
|
126
|
+
const halfHeight = rectHeight / 2;
|
|
127
|
+
ctx.beginPath();
|
|
128
|
+
if (arrowWidth > 0 && edge.orient === "right") {
|
|
129
|
+
x -= arrowWidth;
|
|
130
|
+
ctx.moveTo(x, y + halfHeight);
|
|
131
|
+
ctx.lineTo(x + arrowWidth, y);
|
|
132
|
+
ctx.lineTo(x + rectWidth + arrowWidth, y);
|
|
133
|
+
ctx.lineTo(x + rectWidth + arrowWidth, y + rectHeight);
|
|
134
|
+
ctx.lineTo(x + arrowWidth, y + rectHeight);
|
|
135
|
+
ctx.closePath();
|
|
136
|
+
}
|
|
137
|
+
else if (arrowWidth > 0 && edge.orient === "left") {
|
|
138
|
+
ctx.moveTo(x, y);
|
|
139
|
+
ctx.lineTo(x + rectWidth, y);
|
|
140
|
+
ctx.lineTo(x + rectWidth + arrowWidth, y + halfHeight);
|
|
141
|
+
ctx.lineTo(x + rectWidth, y + rectHeight);
|
|
142
|
+
ctx.lineTo(x, y + rectHeight);
|
|
143
|
+
ctx.closePath();
|
|
144
|
+
}
|
|
145
|
+
else if (rectRadius) {
|
|
146
|
+
roundRect(ctx, x - 0.5, y - 0.5, rectWidth, rectHeight, 3);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
ctx.rect(x - 0.5, y, rectWidth, rectHeight);
|
|
150
|
+
}
|
|
151
|
+
ctx.fill();
|
|
152
|
+
if (edge.coordinateBase.stroke !== undefined) {
|
|
153
|
+
ctx.stroke();
|
|
154
|
+
}
|
|
155
|
+
if (edge.coordinate !== undefined) {
|
|
156
|
+
ctx.fillStyle = edge.coordinate.textFill;
|
|
157
|
+
ctx.textAlign =
|
|
158
|
+
edge.coordinate.textAnchor === "middle" ? "center" : edge.coordinate.textAnchor;
|
|
159
|
+
ctx.fillText(edge.coordinate.displayCoordinate, edge.coordinate.edgeXText, edge.coordinate.edgeYText);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
const roundRect = (ctx, x, y, width, height, radius) => {
|
|
164
|
+
ctx.beginPath();
|
|
165
|
+
ctx.moveTo(x + radius, y);
|
|
166
|
+
ctx.lineTo(x + width - radius, y);
|
|
167
|
+
ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
|
|
168
|
+
ctx.lineTo(x + width, y + height - radius);
|
|
169
|
+
ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
|
|
170
|
+
ctx.lineTo(x + radius, y + height);
|
|
171
|
+
ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
|
|
172
|
+
ctx.lineTo(x, y + radius);
|
|
173
|
+
ctx.quadraticCurveTo(x, y, x + radius, y);
|
|
174
|
+
ctx.closePath();
|
|
175
|
+
};
|
|
176
176
|
//# sourceMappingURL=EdgeCoordinateV3.js.map
|