@tradingaction/coordinates 2.0.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/LICENSE +24 -0
- package/README.md +5 -0
- package/lib/CrossHairCursor.d.ts +22 -0
- package/lib/CrossHairCursor.js +76 -0
- package/lib/CrossHairCursor.js.map +1 -0
- package/lib/CurrentCoordinate.d.ts +31 -0
- package/lib/CurrentCoordinate.js +54 -0
- package/lib/CurrentCoordinate.js.map +1 -0
- package/lib/Cursor.d.ts +31 -0
- package/lib/Cursor.js +122 -0
- package/lib/Cursor.js.map +1 -0
- package/lib/EdgeCoordinate.d.ts +32 -0
- package/lib/EdgeCoordinate.js +151 -0
- package/lib/EdgeCoordinate.js.map +1 -0
- package/lib/EdgeCoordinateV2.d.ts +3 -0
- package/lib/EdgeCoordinateV2.js +138 -0
- package/lib/EdgeCoordinateV2.js.map +1 -0
- package/lib/EdgeCoordinateV3.d.ts +3 -0
- package/lib/EdgeCoordinateV3.js +176 -0
- package/lib/EdgeCoordinateV3.js.map +1 -0
- package/lib/EdgeIndicator.d.ts +55 -0
- package/lib/EdgeIndicator.js +85 -0
- package/lib/EdgeIndicator.js.map +1 -0
- package/lib/MouseCoordinateX.d.ts +49 -0
- package/lib/MouseCoordinateX.js +85 -0
- package/lib/MouseCoordinateX.js.map +1 -0
- package/lib/MouseCoordinateXV2.d.ts +61 -0
- package/lib/MouseCoordinateXV2.js +92 -0
- package/lib/MouseCoordinateXV2.js.map +1 -0
- package/lib/MouseCoordinateY.d.ts +68 -0
- package/lib/MouseCoordinateY.js +91 -0
- package/lib/MouseCoordinateY.js.map +1 -0
- package/lib/PriceCoordinate.d.ts +53 -0
- package/lib/PriceCoordinate.js +81 -0
- package/lib/PriceCoordinate.js.map +1 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +9 -0
- package/lib/index.js.map +1 -0
- package/package.json +49 -0
- package/src/CrossHairCursor.tsx +116 -0
- package/src/CurrentCoordinate.tsx +95 -0
- package/src/Cursor.tsx +174 -0
- package/src/EdgeCoordinate.tsx +239 -0
- package/src/EdgeCoordinateV2.tsx +204 -0
- package/src/EdgeCoordinateV3.tsx +284 -0
- package/src/EdgeIndicator.tsx +161 -0
- package/src/MouseCoordinateX.tsx +127 -0
- package/src/MouseCoordinateXV2.tsx +161 -0
- package/src/MouseCoordinateY.tsx +141 -0
- package/src/PriceCoordinate.tsx +121 -0
- package/src/index.ts +8 -0
|
@@ -0,0 +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
|
+
}
|
|
138
|
+
//# sourceMappingURL=EdgeCoordinateV2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EdgeCoordinateV2.js","sourceRoot":"","sources":["../src/EdgeCoordinateV2.ts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U,CAAC,QAAQ,CAAC;QACzC,GAAG,CAAC,SAAS;YACT,IAAI,CAAC,UAAU,CAAC,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAE,IAAI,CAAC,UAAU,CAAC,UAA8B,CAAC;QACzG,GAAG,CAAC,YAAY,GAAG,QAAQ,CAAC;QAE5B,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,iBAAiB,EAAE,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;KACzG;IACD,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE;QACzB,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;QAEnC,GAAG,CAAC,SAAS,EAAE,CAAC;QAChB,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACvC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACvC,GAAG,CAAC,MAAM,EAAE,CAAC;KAChB;AACL,CAAC"}
|
|
@@ -0,0 +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
|
+
};
|
|
176
|
+
//# sourceMappingURL=EdgeCoordinateV3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EdgeCoordinateV3.js","sourceRoot":"","sources":["../src/EdgeCoordinateV3.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAE9F,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAU,EAAE,EAAE;IACpC,MAAM,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC;IAE5B,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC3B,IAAI,IAAI,KAAK,IAAI,EAAE;QACf,OAAO,IAAI,CAAC;KACf;IAED,IAAI,IAAI,CAAC;IACT,IAAI,cAAc,CAAC;IAC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AAC,GAAG,KAAK,EAAE,CAAC,GAAG,MAAM,GAAG,MAAM,CAAC,CAAC;IAC3C,GAAG,CAAC,gBAAgB,CAAC,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,GAAG,KAAK,GAAG,MAAM,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC;IAC5E,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,MAAM,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC;IACnC,GAAG,CAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,CAAC,GAAG,MAAM,GAAG,MAAM,CAAC,CAAC;IAC5D,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC;IAC1B,GAAG,CAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,CAAC,CAAC;IAC1C,GAAG,CAAC,SAAS,EAAE,CAAC;AACpB,CAAC,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { strokeDashTypes } from "@tradingaction/core";
|
|
3
|
+
export interface EdgeIndicatorProps {
|
|
4
|
+
readonly arrowWidth?: number;
|
|
5
|
+
readonly displayFormat?: (n: number) => string;
|
|
6
|
+
readonly edgeAt?: "left" | "right";
|
|
7
|
+
readonly fill?: string | ((datum: any) => string);
|
|
8
|
+
readonly fitToText?: boolean;
|
|
9
|
+
readonly fontFamily?: string;
|
|
10
|
+
readonly fontSize?: number;
|
|
11
|
+
readonly fullWidth?: boolean;
|
|
12
|
+
readonly itemType: "first" | "last";
|
|
13
|
+
readonly lineStroke?: string | ((datum: any) => string);
|
|
14
|
+
readonly lineStrokeDasharray?: strokeDashTypes;
|
|
15
|
+
readonly orient?: "left" | "right";
|
|
16
|
+
readonly rectHeight?: number;
|
|
17
|
+
readonly rectWidth?: number;
|
|
18
|
+
readonly stroke?: string | ((datum: any) => string);
|
|
19
|
+
readonly textFill?: string | ((datum: any) => string);
|
|
20
|
+
readonly type?: "horizontal";
|
|
21
|
+
readonly yAccessor: (data: any) => number | undefined;
|
|
22
|
+
readonly yAxisPad?: number;
|
|
23
|
+
}
|
|
24
|
+
export declare class EdgeIndicator extends React.Component<EdgeIndicatorProps> {
|
|
25
|
+
static defaultProps: {
|
|
26
|
+
fitToText: boolean;
|
|
27
|
+
lineStroke: string;
|
|
28
|
+
lineOpacity: number;
|
|
29
|
+
lineStrokeDasharray: string;
|
|
30
|
+
orient: string;
|
|
31
|
+
displayFormat: (n: number | {
|
|
32
|
+
valueOf(): number;
|
|
33
|
+
}) => string;
|
|
34
|
+
edgeAt: string;
|
|
35
|
+
yAxisPad: number;
|
|
36
|
+
rectHeight: number;
|
|
37
|
+
rectWidth: number;
|
|
38
|
+
arrowWidth: number;
|
|
39
|
+
fontFamily: string;
|
|
40
|
+
fontSize: number;
|
|
41
|
+
dx: number;
|
|
42
|
+
hideLine: boolean;
|
|
43
|
+
fill: string;
|
|
44
|
+
opacity: number;
|
|
45
|
+
stroke: () => void;
|
|
46
|
+
strokeOpacity: number;
|
|
47
|
+
strokeWidth: number;
|
|
48
|
+
textFill: string;
|
|
49
|
+
type: string;
|
|
50
|
+
};
|
|
51
|
+
render(): JSX.Element;
|
|
52
|
+
private readonly drawOnCanvas;
|
|
53
|
+
private readonly helper;
|
|
54
|
+
private readonly getEdge;
|
|
55
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { format } from "d3-format";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { first, functor, getAxisCanvas, GenericChartComponent, last, noop, } from "@tradingaction/core";
|
|
4
|
+
import { drawOnCanvas } from "./EdgeCoordinateV3";
|
|
5
|
+
export class EdgeIndicator extends React.Component {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.drawOnCanvas = (ctx, moreProps) => {
|
|
9
|
+
const edge = this.helper(this.props, moreProps);
|
|
10
|
+
if (edge === undefined) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const props = Object.assign(Object.assign({}, this.props), edge);
|
|
14
|
+
drawOnCanvas(ctx, props);
|
|
15
|
+
};
|
|
16
|
+
this.helper = (props, moreProps) => {
|
|
17
|
+
const { itemType, yAccessor } = props;
|
|
18
|
+
const { plotData } = moreProps;
|
|
19
|
+
const item = itemType === "first" ? first(plotData, yAccessor) : last(plotData, yAccessor);
|
|
20
|
+
const edge = item !== undefined ? this.getEdge(moreProps, item) : undefined;
|
|
21
|
+
return edge;
|
|
22
|
+
};
|
|
23
|
+
this.getEdge = (moreProps, item) => {
|
|
24
|
+
const { fontFamily, fontSize, type: edgeType, displayFormat = EdgeIndicator.defaultProps.displayFormat, edgeAt, yAxisPad = EdgeIndicator.defaultProps.yAxisPad, orient, lineStroke, yAccessor, fill, fullWidth, textFill, rectHeight, rectWidth, arrowWidth, stroke, } = this.props;
|
|
25
|
+
const { xScale, chartConfig: { yScale }, xAccessor, width, } = moreProps;
|
|
26
|
+
const yValue = yAccessor(item);
|
|
27
|
+
if (yValue === undefined) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
const xValue = xAccessor(item);
|
|
31
|
+
const x1 = fullWidth ? 0 : Math.round(xScale(xValue));
|
|
32
|
+
const y1 = Math.round(yScale(yValue));
|
|
33
|
+
const [left, right] = [0, width];
|
|
34
|
+
const edgeX = edgeAt === "left" ? left - yAxisPad : right + yAxisPad;
|
|
35
|
+
return {
|
|
36
|
+
coordinate: displayFormat(yValue),
|
|
37
|
+
show: true,
|
|
38
|
+
type: edgeType,
|
|
39
|
+
orient,
|
|
40
|
+
edgeAt: edgeX,
|
|
41
|
+
fill: functor(fill)(item),
|
|
42
|
+
lineStroke: functor(lineStroke)(item),
|
|
43
|
+
stroke: functor(stroke)(item),
|
|
44
|
+
fontFamily,
|
|
45
|
+
fontSize,
|
|
46
|
+
textFill: functor(textFill)(item),
|
|
47
|
+
rectHeight,
|
|
48
|
+
rectWidth,
|
|
49
|
+
arrowWidth,
|
|
50
|
+
x1,
|
|
51
|
+
y1,
|
|
52
|
+
x2: right,
|
|
53
|
+
y2: y1,
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
render() {
|
|
58
|
+
return (React.createElement(GenericChartComponent, { edgeClip: true, clip: false, canvasDraw: this.drawOnCanvas, canvasToDraw: getAxisCanvas, drawOn: ["pan"] }));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
EdgeIndicator.defaultProps = {
|
|
62
|
+
fitToText: false,
|
|
63
|
+
lineStroke: "#000000",
|
|
64
|
+
lineOpacity: 1,
|
|
65
|
+
lineStrokeDasharray: "ShortDot",
|
|
66
|
+
orient: "right",
|
|
67
|
+
displayFormat: format(".2f"),
|
|
68
|
+
edgeAt: "right",
|
|
69
|
+
yAxisPad: 0,
|
|
70
|
+
rectHeight: 20,
|
|
71
|
+
rectWidth: 50,
|
|
72
|
+
arrowWidth: 0,
|
|
73
|
+
fontFamily: "-apple-system, system-ui, Roboto, 'Helvetica Neue', Ubuntu, sans-serif",
|
|
74
|
+
fontSize: 13,
|
|
75
|
+
dx: 0,
|
|
76
|
+
hideLine: false,
|
|
77
|
+
fill: "#8a8a8a",
|
|
78
|
+
opacity: 1,
|
|
79
|
+
stroke: noop,
|
|
80
|
+
strokeOpacity: 1,
|
|
81
|
+
strokeWidth: 1,
|
|
82
|
+
textFill: "#FFFFFF",
|
|
83
|
+
type: "horizontal",
|
|
84
|
+
};
|
|
85
|
+
//# sourceMappingURL=EdgeIndicator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EdgeIndicator.js","sourceRoot":"","sources":["../src/EdgeIndicator.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EACH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;gBACV,QAAQ;gBACR,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC;gBACjC,UAAU;gBACV,SAAS;gBACT,UAAU;gBACV,EAAE;gBACF,EAAE;gBACF,EAAE,EAAE,KAAK;gBACT,EAAE,EAAE,EAAE;aACT,CAAC;QACN,CAAC,CAAC;IACN,CAAC;IAnGU,MAAM;QACT,OAAO,CACH,oBAAC,qBAAqB,IAClB,QAAQ,QACR,IAAI,EAAE,KAAK,EACX,UAAU,EAAE,IAAI,CAAC,YAAY,EAC7B,YAAY,EAAE,aAAa,EAC3B,MAAM,EAAE,CAAC,KAAK,CAAC,GACjB,CACL,CAAC;IACN,CAAC;;AAnCa,0BAAY,GAAG;IACzB,SAAS,EAAE,KAAK;IAChB,UAAU,EAAE,SAAS;IACrB,WAAW,EAAE,CAAC;IACd,mBAAmB,EAAE,UAAU;IAC/B,MAAM,EAAE,OAAO;IACf,aAAa,EAAE,MAAM,CAAC,KAAK,CAAC;IAC5B,MAAM,EAAE,OAAO;IACf,QAAQ,EAAE,CAAC;IACX,UAAU,EAAE,EAAE;IACd,SAAS,EAAE,EAAE;IACb,UAAU,EAAE,CAAC;IACb,UAAU,EAAE,wEAAwE;IACpF,QAAQ,EAAE,EAAE;IACZ,EAAE,EAAE,CAAC;IACL,QAAQ,EAAE,KAAK;IACf,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,CAAC;IACV,MAAM,EAAE,IAAI;IACZ,aAAa,EAAE,CAAC;IAChB,WAAW,EAAE,CAAC;IACd,QAAQ,EAAE,SAAS;IACnB,IAAI,EAAE,YAAY;CACrB,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export interface MouseCoordinateXProps {
|
|
3
|
+
readonly at?: "bottom" | "top";
|
|
4
|
+
readonly customX: (props: MouseCoordinateXProps, moreProps: any) => {
|
|
5
|
+
x: number;
|
|
6
|
+
coordinate: string;
|
|
7
|
+
};
|
|
8
|
+
readonly displayFormat: (item: any) => string;
|
|
9
|
+
readonly fill?: string;
|
|
10
|
+
readonly fitToText?: boolean;
|
|
11
|
+
readonly fontFamily?: string;
|
|
12
|
+
readonly fontSize?: number;
|
|
13
|
+
readonly opacity?: number;
|
|
14
|
+
readonly orient?: "bottom" | "top";
|
|
15
|
+
readonly rectRadius?: number;
|
|
16
|
+
readonly rectWidth?: number;
|
|
17
|
+
readonly rectHeight?: number;
|
|
18
|
+
readonly snapX?: boolean;
|
|
19
|
+
readonly stroke?: string;
|
|
20
|
+
readonly strokeOpacity?: number;
|
|
21
|
+
readonly strokeWidth?: number;
|
|
22
|
+
readonly textFill?: string;
|
|
23
|
+
readonly yAxisPad?: number;
|
|
24
|
+
}
|
|
25
|
+
export declare class MouseCoordinateX extends React.Component<MouseCoordinateXProps> {
|
|
26
|
+
static defaultProps: {
|
|
27
|
+
at: string;
|
|
28
|
+
customX: (props: MouseCoordinateXProps, moreProps: any) => {
|
|
29
|
+
x: any;
|
|
30
|
+
coordinate: string;
|
|
31
|
+
};
|
|
32
|
+
fill: string;
|
|
33
|
+
fitToText: boolean;
|
|
34
|
+
fontFamily: string;
|
|
35
|
+
fontSize: number;
|
|
36
|
+
opacity: number;
|
|
37
|
+
orient: string;
|
|
38
|
+
rectWidth: number;
|
|
39
|
+
rectHeight: number;
|
|
40
|
+
snapX: boolean;
|
|
41
|
+
strokeOpacity: number;
|
|
42
|
+
strokeWidth: number;
|
|
43
|
+
textFill: string;
|
|
44
|
+
yAxisPad: number;
|
|
45
|
+
};
|
|
46
|
+
render(): JSX.Element;
|
|
47
|
+
private readonly drawOnCanvas;
|
|
48
|
+
private readonly helper;
|
|
49
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { isNotDefined, getMouseCanvas, GenericChartComponent } from "@tradingaction/core";
|
|
3
|
+
import { drawOnCanvas } from "./EdgeCoordinateV3";
|
|
4
|
+
const defaultCustomX = (props, moreProps) => {
|
|
5
|
+
const { xScale, xAccessor, currentItem, mouseXY } = moreProps;
|
|
6
|
+
const { snapX } = props;
|
|
7
|
+
const x = snapX ? xScale(xAccessor(currentItem)) : mouseXY[0];
|
|
8
|
+
const { displayXAccessor } = moreProps;
|
|
9
|
+
const { displayFormat } = props;
|
|
10
|
+
const coordinate = snapX ? displayFormat(displayXAccessor(currentItem)) : displayFormat(xScale.invert(x));
|
|
11
|
+
return { x, coordinate };
|
|
12
|
+
};
|
|
13
|
+
export class MouseCoordinateX extends React.Component {
|
|
14
|
+
constructor() {
|
|
15
|
+
super(...arguments);
|
|
16
|
+
this.drawOnCanvas = (ctx, moreProps) => {
|
|
17
|
+
const props = this.helper(this.props, moreProps);
|
|
18
|
+
if (props === null) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
drawOnCanvas(ctx, props);
|
|
22
|
+
};
|
|
23
|
+
this.helper = (props, moreProps) => {
|
|
24
|
+
const { show, currentItem, chartConfig: { height }, } = moreProps;
|
|
25
|
+
if (isNotDefined(currentItem)) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const { customX, orient, at, rectRadius, rectWidth, rectHeight, stroke, strokeOpacity, strokeWidth } = props;
|
|
29
|
+
const { fill, opacity, fitToText, fontFamily, fontSize, textFill } = props;
|
|
30
|
+
const edgeAt = at === "bottom" ? height : 0;
|
|
31
|
+
const { x, coordinate } = customX(props, moreProps);
|
|
32
|
+
const type = "vertical";
|
|
33
|
+
const y1 = 0;
|
|
34
|
+
const y2 = height;
|
|
35
|
+
const hideLine = true;
|
|
36
|
+
const coordinateProps = {
|
|
37
|
+
coordinate,
|
|
38
|
+
fitToText,
|
|
39
|
+
show,
|
|
40
|
+
type,
|
|
41
|
+
orient,
|
|
42
|
+
edgeAt,
|
|
43
|
+
hideLine,
|
|
44
|
+
fill,
|
|
45
|
+
opacity,
|
|
46
|
+
fontFamily,
|
|
47
|
+
fontSize,
|
|
48
|
+
textFill,
|
|
49
|
+
stroke,
|
|
50
|
+
strokeOpacity,
|
|
51
|
+
strokeWidth,
|
|
52
|
+
rectWidth,
|
|
53
|
+
rectHeight,
|
|
54
|
+
rectRadius,
|
|
55
|
+
arrowWidth: 0,
|
|
56
|
+
x1: x,
|
|
57
|
+
x2: x,
|
|
58
|
+
y1,
|
|
59
|
+
y2,
|
|
60
|
+
};
|
|
61
|
+
return coordinateProps;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
render() {
|
|
65
|
+
return (React.createElement(GenericChartComponent, { clip: false, canvasDraw: this.drawOnCanvas, canvasToDraw: getMouseCanvas, drawOn: ["mousemove", "pan", "drag"] }));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
MouseCoordinateX.defaultProps = {
|
|
69
|
+
at: "bottom",
|
|
70
|
+
customX: defaultCustomX,
|
|
71
|
+
fill: "#4C525E",
|
|
72
|
+
fitToText: true,
|
|
73
|
+
fontFamily: "-apple-system, system-ui, Roboto, 'Helvetica Neue', Ubuntu, sans-serif",
|
|
74
|
+
fontSize: 13,
|
|
75
|
+
opacity: 1,
|
|
76
|
+
orient: "bottom",
|
|
77
|
+
rectWidth: 80,
|
|
78
|
+
rectHeight: 20,
|
|
79
|
+
snapX: true,
|
|
80
|
+
strokeOpacity: 1,
|
|
81
|
+
strokeWidth: 1,
|
|
82
|
+
textFill: "#FFFFFF",
|
|
83
|
+
yAxisPad: 0,
|
|
84
|
+
};
|
|
85
|
+
//# sourceMappingURL=MouseCoordinateX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MouseCoordinateX.js","sourceRoot":"","sources":["../src/MouseCoordinateX.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC1F,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAuBlD,MAAM,cAAc,G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