@tradingaction/coordinates 2.0.12 → 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/Cursor.js
CHANGED
|
@@ -1,122 +1,122 @@
|
|
|
1
|
-
import { ChartCanvasContext, first, GenericComponent, getMouseCanvas, getStrokeDasharrayCanvas, last, } from "@tradingaction/core";
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
const defaultCustomSnapX = (props, moreProps) => {
|
|
4
|
-
const { xScale, xAccessor, currentItem, mouseXY } = moreProps;
|
|
5
|
-
const { snapX } = props;
|
|
6
|
-
const x = snapX ? Math.round(xScale(xAccessor(currentItem))) : mouseXY[0];
|
|
7
|
-
return x;
|
|
8
|
-
};
|
|
9
|
-
export class Cursor extends React.Component {
|
|
10
|
-
constructor() {
|
|
11
|
-
super(...arguments);
|
|
12
|
-
this.drawOnCanvas = (ctx, moreProps) => {
|
|
13
|
-
const cursors = this.getXYCursor(this.props, moreProps);
|
|
14
|
-
if (cursors === undefined) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
const { useXCursorShape } = this.props;
|
|
18
|
-
const { margin, ratio } = this.context;
|
|
19
|
-
const originX = 0.5 * ratio + margin.left;
|
|
20
|
-
const originY = 0.5 * ratio + margin.top;
|
|
21
|
-
ctx.save();
|
|
22
|
-
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
23
|
-
ctx.scale(ratio, ratio);
|
|
24
|
-
ctx.translate(originX, originY);
|
|
25
|
-
cursors.forEach((line) => {
|
|
26
|
-
if (useXCursorShape && line.isXCursor) {
|
|
27
|
-
const { xCursorShapeStrokeDasharray } = this.props;
|
|
28
|
-
if (xCursorShapeStrokeDasharray !== undefined) {
|
|
29
|
-
const xShapeStrokeStyle = this.getXCursorShapeStroke(moreProps);
|
|
30
|
-
if (xShapeStrokeStyle !== undefined) {
|
|
31
|
-
ctx.strokeStyle = xShapeStrokeStyle;
|
|
32
|
-
}
|
|
33
|
-
ctx.setLineDash(getStrokeDasharrayCanvas(xCursorShapeStrokeDasharray));
|
|
34
|
-
}
|
|
35
|
-
ctx.beginPath();
|
|
36
|
-
const xShapeFillStyle = this.getXCursorShapeFill(moreProps);
|
|
37
|
-
if (xShapeFillStyle !== undefined) {
|
|
38
|
-
ctx.fillStyle = xShapeFillStyle;
|
|
39
|
-
}
|
|
40
|
-
ctx.beginPath();
|
|
41
|
-
const xShape = this.getXCursorShape(moreProps);
|
|
42
|
-
xCursorShapeStrokeDasharray === undefined
|
|
43
|
-
? ctx.fillRect(xShape.xPos, 0, xShape.shapeWidth, xShape.height)
|
|
44
|
-
: ctx.rect(xShape.xPos, 0, xShape.shapeWidth, xShape.height);
|
|
45
|
-
ctx.fill();
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
if (line.strokeStyle !== undefined) {
|
|
49
|
-
ctx.strokeStyle = line.strokeStyle;
|
|
50
|
-
}
|
|
51
|
-
const dashArray = getStrokeDasharrayCanvas(line.strokeDasharray);
|
|
52
|
-
ctx.setLineDash(dashArray);
|
|
53
|
-
ctx.beginPath();
|
|
54
|
-
ctx.moveTo(line.x1, line.y1);
|
|
55
|
-
ctx.lineTo(line.x2, line.y2);
|
|
56
|
-
}
|
|
57
|
-
ctx.stroke();
|
|
58
|
-
});
|
|
59
|
-
ctx.restore();
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
render() {
|
|
63
|
-
return (React.createElement(GenericComponent, { clip: false, canvasDraw: this.drawOnCanvas, canvasToDraw: getMouseCanvas, drawOn: ["mousemove", "pan", "drag"] }));
|
|
64
|
-
}
|
|
65
|
-
getXCursorShapeStroke({ currentItem }) {
|
|
66
|
-
const { xCursorShapeStrokeStyle } = this.props;
|
|
67
|
-
return xCursorShapeStrokeStyle instanceof Function
|
|
68
|
-
? xCursorShapeStrokeStyle(currentItem)
|
|
69
|
-
: xCursorShapeStrokeStyle;
|
|
70
|
-
}
|
|
71
|
-
getXCursorShapeFill({ currentItem }) {
|
|
72
|
-
const { xCursorShapeFillStyle } = this.props;
|
|
73
|
-
return xCursorShapeFillStyle instanceof Function ? xCursorShapeFillStyle(currentItem) : xCursorShapeFillStyle;
|
|
74
|
-
}
|
|
75
|
-
getXCursorShape(moreProps) {
|
|
76
|
-
const { height, xScale, currentItem, plotData } = moreProps;
|
|
77
|
-
const { xAccessor } = moreProps;
|
|
78
|
-
const xValue = xAccessor(currentItem);
|
|
79
|
-
const centerX = xScale(xValue);
|
|
80
|
-
const shapeWidth = Math.abs(xScale(xAccessor(last(plotData))) - xScale(xAccessor(first(plotData)))) / (plotData.length - 1);
|
|
81
|
-
const xPos = centerX - shapeWidth / 2;
|
|
82
|
-
return { height, xPos, shapeWidth };
|
|
83
|
-
}
|
|
84
|
-
getXYCursor(props, moreProps) {
|
|
85
|
-
const { mouseXY, currentItem, show, height, width } = moreProps;
|
|
86
|
-
const { customX = Cursor.defaultProps.customX, strokeStyle, strokeDasharray, disableYCursor } = props;
|
|
87
|
-
if (!show || currentItem === undefined) {
|
|
88
|
-
return undefined;
|
|
89
|
-
}
|
|
90
|
-
const yCursor = {
|
|
91
|
-
x1: 0,
|
|
92
|
-
x2: width,
|
|
93
|
-
y1: mouseXY[1] + 0.5,
|
|
94
|
-
y2: mouseXY[1] + 0.5,
|
|
95
|
-
strokeStyle,
|
|
96
|
-
strokeDasharray,
|
|
97
|
-
isXCursor: false,
|
|
98
|
-
};
|
|
99
|
-
const x = customX(props, moreProps);
|
|
100
|
-
const xCursor = {
|
|
101
|
-
x1: x,
|
|
102
|
-
x2: x,
|
|
103
|
-
y1: 0,
|
|
104
|
-
y2: height,
|
|
105
|
-
strokeStyle,
|
|
106
|
-
strokeDasharray,
|
|
107
|
-
isXCursor: true,
|
|
108
|
-
};
|
|
109
|
-
return disableYCursor ? [xCursor] : [yCursor, xCursor];
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
Cursor.defaultProps = {
|
|
113
|
-
strokeStyle: "rgba(55, 71, 79, 0.8)",
|
|
114
|
-
strokeDasharray: "ShortDash",
|
|
115
|
-
snapX: true,
|
|
116
|
-
customX: defaultCustomSnapX,
|
|
117
|
-
disableYCursor: false,
|
|
118
|
-
useXCursorShape: false,
|
|
119
|
-
xCursorShapeStrokeStyle: "rgba(0, 0, 0, 0.5)",
|
|
120
|
-
};
|
|
121
|
-
Cursor.contextType = ChartCanvasContext;
|
|
1
|
+
import { ChartCanvasContext, first, GenericComponent, getMouseCanvas, getStrokeDasharrayCanvas, last, } from "@tradingaction/core";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
const defaultCustomSnapX = (props, moreProps) => {
|
|
4
|
+
const { xScale, xAccessor, currentItem, mouseXY } = moreProps;
|
|
5
|
+
const { snapX } = props;
|
|
6
|
+
const x = snapX ? Math.round(xScale(xAccessor(currentItem))) : mouseXY[0];
|
|
7
|
+
return x;
|
|
8
|
+
};
|
|
9
|
+
export class Cursor extends React.Component {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
this.drawOnCanvas = (ctx, moreProps) => {
|
|
13
|
+
const cursors = this.getXYCursor(this.props, moreProps);
|
|
14
|
+
if (cursors === undefined) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const { useXCursorShape } = this.props;
|
|
18
|
+
const { margin, ratio } = this.context;
|
|
19
|
+
const originX = 0.5 * ratio + margin.left;
|
|
20
|
+
const originY = 0.5 * ratio + margin.top;
|
|
21
|
+
ctx.save();
|
|
22
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
23
|
+
ctx.scale(ratio, ratio);
|
|
24
|
+
ctx.translate(originX, originY);
|
|
25
|
+
cursors.forEach((line) => {
|
|
26
|
+
if (useXCursorShape && line.isXCursor) {
|
|
27
|
+
const { xCursorShapeStrokeDasharray } = this.props;
|
|
28
|
+
if (xCursorShapeStrokeDasharray !== undefined) {
|
|
29
|
+
const xShapeStrokeStyle = this.getXCursorShapeStroke(moreProps);
|
|
30
|
+
if (xShapeStrokeStyle !== undefined) {
|
|
31
|
+
ctx.strokeStyle = xShapeStrokeStyle;
|
|
32
|
+
}
|
|
33
|
+
ctx.setLineDash(getStrokeDasharrayCanvas(xCursorShapeStrokeDasharray));
|
|
34
|
+
}
|
|
35
|
+
ctx.beginPath();
|
|
36
|
+
const xShapeFillStyle = this.getXCursorShapeFill(moreProps);
|
|
37
|
+
if (xShapeFillStyle !== undefined) {
|
|
38
|
+
ctx.fillStyle = xShapeFillStyle;
|
|
39
|
+
}
|
|
40
|
+
ctx.beginPath();
|
|
41
|
+
const xShape = this.getXCursorShape(moreProps);
|
|
42
|
+
xCursorShapeStrokeDasharray === undefined
|
|
43
|
+
? ctx.fillRect(xShape.xPos, 0, xShape.shapeWidth, xShape.height)
|
|
44
|
+
: ctx.rect(xShape.xPos, 0, xShape.shapeWidth, xShape.height);
|
|
45
|
+
ctx.fill();
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
if (line.strokeStyle !== undefined) {
|
|
49
|
+
ctx.strokeStyle = line.strokeStyle;
|
|
50
|
+
}
|
|
51
|
+
const dashArray = getStrokeDasharrayCanvas(line.strokeDasharray);
|
|
52
|
+
ctx.setLineDash(dashArray);
|
|
53
|
+
ctx.beginPath();
|
|
54
|
+
ctx.moveTo(line.x1, line.y1);
|
|
55
|
+
ctx.lineTo(line.x2, line.y2);
|
|
56
|
+
}
|
|
57
|
+
ctx.stroke();
|
|
58
|
+
});
|
|
59
|
+
ctx.restore();
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
render() {
|
|
63
|
+
return (React.createElement(GenericComponent, { clip: false, canvasDraw: this.drawOnCanvas, canvasToDraw: getMouseCanvas, drawOn: ["mousemove", "pan", "drag"] }));
|
|
64
|
+
}
|
|
65
|
+
getXCursorShapeStroke({ currentItem }) {
|
|
66
|
+
const { xCursorShapeStrokeStyle } = this.props;
|
|
67
|
+
return xCursorShapeStrokeStyle instanceof Function
|
|
68
|
+
? xCursorShapeStrokeStyle(currentItem)
|
|
69
|
+
: xCursorShapeStrokeStyle;
|
|
70
|
+
}
|
|
71
|
+
getXCursorShapeFill({ currentItem }) {
|
|
72
|
+
const { xCursorShapeFillStyle } = this.props;
|
|
73
|
+
return xCursorShapeFillStyle instanceof Function ? xCursorShapeFillStyle(currentItem) : xCursorShapeFillStyle;
|
|
74
|
+
}
|
|
75
|
+
getXCursorShape(moreProps) {
|
|
76
|
+
const { height, xScale, currentItem, plotData } = moreProps;
|
|
77
|
+
const { xAccessor } = moreProps;
|
|
78
|
+
const xValue = xAccessor(currentItem);
|
|
79
|
+
const centerX = xScale(xValue);
|
|
80
|
+
const shapeWidth = Math.abs(xScale(xAccessor(last(plotData))) - xScale(xAccessor(first(plotData)))) / (plotData.length - 1);
|
|
81
|
+
const xPos = centerX - shapeWidth / 2;
|
|
82
|
+
return { height, xPos, shapeWidth };
|
|
83
|
+
}
|
|
84
|
+
getXYCursor(props, moreProps) {
|
|
85
|
+
const { mouseXY, currentItem, show, height, width } = moreProps;
|
|
86
|
+
const { customX = Cursor.defaultProps.customX, strokeStyle, strokeDasharray, disableYCursor } = props;
|
|
87
|
+
if (!show || currentItem === undefined) {
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
const yCursor = {
|
|
91
|
+
x1: 0,
|
|
92
|
+
x2: width,
|
|
93
|
+
y1: mouseXY[1] + 0.5,
|
|
94
|
+
y2: mouseXY[1] + 0.5,
|
|
95
|
+
strokeStyle,
|
|
96
|
+
strokeDasharray,
|
|
97
|
+
isXCursor: false,
|
|
98
|
+
};
|
|
99
|
+
const x = customX(props, moreProps);
|
|
100
|
+
const xCursor = {
|
|
101
|
+
x1: x,
|
|
102
|
+
x2: x,
|
|
103
|
+
y1: 0,
|
|
104
|
+
y2: height,
|
|
105
|
+
strokeStyle,
|
|
106
|
+
strokeDasharray,
|
|
107
|
+
isXCursor: true,
|
|
108
|
+
};
|
|
109
|
+
return disableYCursor ? [xCursor] : [yCursor, xCursor];
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
Cursor.defaultProps = {
|
|
113
|
+
strokeStyle: "rgba(55, 71, 79, 0.8)",
|
|
114
|
+
strokeDasharray: "ShortDash",
|
|
115
|
+
snapX: true,
|
|
116
|
+
customX: defaultCustomSnapX,
|
|
117
|
+
disableYCursor: false,
|
|
118
|
+
useXCursorShape: false,
|
|
119
|
+
xCursorShapeStrokeStyle: "rgba(0, 0, 0, 0.5)",
|
|
120
|
+
};
|
|
121
|
+
Cursor.contextType = ChartCanvasContext;
|
|
122
122
|
//# sourceMappingURL=Cursor.js.map
|
package/lib/EdgeCoordinate.d.ts
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
export interface EdgeCoordinateProps {
|
|
3
|
-
readonly className?: string;
|
|
4
|
-
readonly type: "vertical" | "horizontal";
|
|
5
|
-
readonly coordinate?: any;
|
|
6
|
-
readonly x1: number;
|
|
7
|
-
readonly y1: number;
|
|
8
|
-
readonly x2: number;
|
|
9
|
-
readonly y2: number;
|
|
10
|
-
readonly orient?: "bottom" | "top" | "left" | "right";
|
|
11
|
-
readonly rectWidth?: number;
|
|
12
|
-
readonly hideLine?: boolean;
|
|
13
|
-
readonly fill?: string;
|
|
14
|
-
readonly fontFamily: string;
|
|
15
|
-
readonly fontSize: number;
|
|
16
|
-
readonly lineStroke?: string;
|
|
17
|
-
}
|
|
18
|
-
export declare class EdgeCoordinate extends React.Component<EdgeCoordinateProps> {
|
|
19
|
-
static defaultProps: {
|
|
20
|
-
className: string;
|
|
21
|
-
orient: string;
|
|
22
|
-
hideLine: boolean;
|
|
23
|
-
fill: string;
|
|
24
|
-
fontFamily: string;
|
|
25
|
-
fontSize: number;
|
|
26
|
-
textFill: string;
|
|
27
|
-
lineStroke: string;
|
|
28
|
-
arrowWidth: number;
|
|
29
|
-
};
|
|
30
|
-
static drawOnCanvasStatic: (ctx: CanvasRenderingContext2D, props: any) => void;
|
|
31
|
-
render(): JSX.Element | null;
|
|
32
|
-
}
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export interface EdgeCoordinateProps {
|
|
3
|
+
readonly className?: string;
|
|
4
|
+
readonly type: "vertical" | "horizontal";
|
|
5
|
+
readonly coordinate?: any;
|
|
6
|
+
readonly x1: number;
|
|
7
|
+
readonly y1: number;
|
|
8
|
+
readonly x2: number;
|
|
9
|
+
readonly y2: number;
|
|
10
|
+
readonly orient?: "bottom" | "top" | "left" | "right";
|
|
11
|
+
readonly rectWidth?: number;
|
|
12
|
+
readonly hideLine?: boolean;
|
|
13
|
+
readonly fill?: string;
|
|
14
|
+
readonly fontFamily: string;
|
|
15
|
+
readonly fontSize: number;
|
|
16
|
+
readonly lineStroke?: string;
|
|
17
|
+
}
|
|
18
|
+
export declare class EdgeCoordinate extends React.Component<EdgeCoordinateProps> {
|
|
19
|
+
static defaultProps: {
|
|
20
|
+
className: string;
|
|
21
|
+
orient: string;
|
|
22
|
+
hideLine: boolean;
|
|
23
|
+
fill: string;
|
|
24
|
+
fontFamily: string;
|
|
25
|
+
fontSize: number;
|
|
26
|
+
textFill: string;
|
|
27
|
+
lineStroke: string;
|
|
28
|
+
arrowWidth: number;
|
|
29
|
+
};
|
|
30
|
+
static drawOnCanvasStatic: (ctx: CanvasRenderingContext2D, props: any) => void;
|
|
31
|
+
render(): JSX.Element | null;
|
|
32
|
+
}
|
package/lib/EdgeCoordinate.js
CHANGED
|
@@ -1,151 +1,151 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
const helper = (props) => {
|
|
3
|
-
const { coordinate: displayCoordinate, show, type, orient, edgeAt, hideLine } = props;
|
|
4
|
-
const { fill, fontFamily, fontSize, textFill, lineStroke, arrowWidth } = props;
|
|
5
|
-
const { rectWidth, rectHeight } = props;
|
|
6
|
-
const { x1, y1, x2, y2 } = props;
|
|
7
|
-
if (!show) {
|
|
8
|
-
return null;
|
|
9
|
-
}
|
|
10
|
-
let edgeXRect;
|
|
11
|
-
let edgeYRect;
|
|
12
|
-
let edgeXText;
|
|
13
|
-
let edgeYText;
|
|
14
|
-
if (type === "horizontal") {
|
|
15
|
-
edgeXRect = orient === "right" ? edgeAt + 1 : edgeAt - rectWidth - arrowWidth - 1;
|
|
16
|
-
edgeYRect = y1 - rectHeight / 2;
|
|
17
|
-
edgeXText = orient === "right" ? edgeAt + rectWidth / 2 + arrowWidth : edgeAt - rectWidth / 2 - arrowWidth;
|
|
18
|
-
edgeYText = y1;
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
edgeXRect = x1 - rectWidth / 2;
|
|
22
|
-
edgeYRect = orient === "bottom" ? edgeAt : edgeAt - rectHeight;
|
|
23
|
-
edgeXText = x1;
|
|
24
|
-
edgeYText = orient === "bottom" ? edgeAt + rectHeight / 2 : edgeAt - rectHeight / 2;
|
|
25
|
-
}
|
|
26
|
-
let coordinateBase;
|
|
27
|
-
let coordinate;
|
|
28
|
-
const textAnchor = "middle";
|
|
29
|
-
if (displayCoordinate !== undefined) {
|
|
30
|
-
coordinateBase = {
|
|
31
|
-
edgeXRect,
|
|
32
|
-
edgeYRect,
|
|
33
|
-
rectHeight,
|
|
34
|
-
rectWidth,
|
|
35
|
-
fill,
|
|
36
|
-
arrowWidth,
|
|
37
|
-
};
|
|
38
|
-
coordinate = {
|
|
39
|
-
edgeXText,
|
|
40
|
-
edgeYText,
|
|
41
|
-
textAnchor,
|
|
42
|
-
fontFamily,
|
|
43
|
-
fontSize,
|
|
44
|
-
textFill,
|
|
45
|
-
displayCoordinate,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
const line = hideLine
|
|
49
|
-
? undefined
|
|
50
|
-
: {
|
|
51
|
-
stroke: lineStroke,
|
|
52
|
-
x1,
|
|
53
|
-
y1,
|
|
54
|
-
x2,
|
|
55
|
-
y2,
|
|
56
|
-
};
|
|
57
|
-
return {
|
|
58
|
-
coordinateBase,
|
|
59
|
-
coordinate,
|
|
60
|
-
line,
|
|
61
|
-
orient,
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
export class EdgeCoordinate extends React.Component {
|
|
65
|
-
render() {
|
|
66
|
-
const { className } = this.props;
|
|
67
|
-
const edge = helper(this.props);
|
|
68
|
-
if (edge === null) {
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
let line;
|
|
72
|
-
let coordinateBase;
|
|
73
|
-
let coordinate;
|
|
74
|
-
if (edge.line !== undefined) {
|
|
75
|
-
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 }));
|
|
76
|
-
}
|
|
77
|
-
if (edge.coordinate !== undefined && edge.coordinateBase !== undefined) {
|
|
78
|
-
const { rectWidth, rectHeight, arrowWidth } = edge.coordinateBase;
|
|
79
|
-
const path = edge.orient === "left"
|
|
80
|
-
? `M0,0L0,${rectHeight}L${rectWidth},${rectHeight}L${rectWidth + arrowWidth},10L${rectWidth},0L0,0L0,0`
|
|
81
|
-
: `M0,${arrowWidth}L${arrowWidth},${rectHeight}L${rectWidth + arrowWidth},${rectHeight}L${rectWidth + arrowWidth},0L${arrowWidth},0L0,${arrowWidth}`;
|
|
82
|
-
coordinateBase =
|
|
83
|
-
edge.orient === "left" || edge.orient === "right" ? (React.createElement("g", { transform: `translate(${edge.coordinateBase.edgeXRect},${edge.coordinateBase.edgeYRect})` },
|
|
84
|
-
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 }));
|
|
85
|
-
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));
|
|
86
|
-
}
|
|
87
|
-
return (React.createElement("g", { className: className },
|
|
88
|
-
line,
|
|
89
|
-
coordinateBase,
|
|
90
|
-
coordinate));
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
EdgeCoordinate.defaultProps = {
|
|
94
|
-
className: "react-financial-charts-edgecoordinate",
|
|
95
|
-
orient: "left",
|
|
96
|
-
hideLine: false,
|
|
97
|
-
fill: "#8a8a8a",
|
|
98
|
-
fontFamily: "-apple-system, system-ui, Roboto, 'Helvetica Neue', Ubuntu, sans-serif",
|
|
99
|
-
fontSize: 13,
|
|
100
|
-
textFill: "#FFFFFF",
|
|
101
|
-
lineStroke: "rgba(0, 0, 0, 0.3)",
|
|
102
|
-
arrowWidth: 10,
|
|
103
|
-
};
|
|
104
|
-
EdgeCoordinate.drawOnCanvasStatic = (ctx, props) => {
|
|
105
|
-
props = Object.assign(Object.assign({}, EdgeCoordinate.defaultProps), props);
|
|
106
|
-
const edge = helper(props);
|
|
107
|
-
if (edge === null) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
if (edge.coordinate !== undefined && edge.coordinateBase !== undefined) {
|
|
111
|
-
const { rectWidth, rectHeight, arrowWidth } = edge.coordinateBase;
|
|
112
|
-
ctx.fillStyle = edge.coordinateBase.fill;
|
|
113
|
-
const x = edge.coordinateBase.edgeXRect;
|
|
114
|
-
const y = edge.coordinateBase.edgeYRect;
|
|
115
|
-
ctx.beginPath();
|
|
116
|
-
if (edge.orient === "right") {
|
|
117
|
-
ctx.moveTo(x, y + rectHeight / 2);
|
|
118
|
-
ctx.lineTo(x + arrowWidth, y);
|
|
119
|
-
ctx.lineTo(x + rectWidth + arrowWidth, y);
|
|
120
|
-
ctx.lineTo(x + rectWidth + arrowWidth, y + rectHeight);
|
|
121
|
-
ctx.lineTo(x + arrowWidth, y + rectHeight);
|
|
122
|
-
ctx.closePath();
|
|
123
|
-
}
|
|
124
|
-
else if (edge.orient === "left") {
|
|
125
|
-
ctx.moveTo(x, y);
|
|
126
|
-
ctx.lineTo(x + rectWidth, y);
|
|
127
|
-
ctx.lineTo(x + rectWidth + arrowWidth, y + rectHeight / 2);
|
|
128
|
-
ctx.lineTo(x + rectWidth, y + rectHeight);
|
|
129
|
-
ctx.lineTo(x, y + rectHeight);
|
|
130
|
-
ctx.closePath();
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
ctx.rect(x, y, rectWidth, rectHeight);
|
|
134
|
-
}
|
|
135
|
-
ctx.fill();
|
|
136
|
-
ctx.font = `${edge.coordinate.fontSize}px ${edge.coordinate.fontFamily}`;
|
|
137
|
-
ctx.fillStyle = edge.coordinate.textFill;
|
|
138
|
-
ctx.textAlign =
|
|
139
|
-
edge.coordinate.textAnchor === "middle" ? "center" : edge.coordinate.textAnchor;
|
|
140
|
-
ctx.textBaseline = "middle";
|
|
141
|
-
ctx.fillText(edge.coordinate.displayCoordinate, edge.coordinate.edgeXText, edge.coordinate.edgeYText);
|
|
142
|
-
}
|
|
143
|
-
if (edge.line !== undefined) {
|
|
144
|
-
ctx.strokeStyle = edge.line.stroke;
|
|
145
|
-
ctx.beginPath();
|
|
146
|
-
ctx.moveTo(edge.line.x1, edge.line.y1);
|
|
147
|
-
ctx.lineTo(edge.line.x2, edge.line.y2);
|
|
148
|
-
ctx.stroke();
|
|
149
|
-
}
|
|
150
|
-
};
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
const helper = (props) => {
|
|
3
|
+
const { coordinate: displayCoordinate, show, type, orient, edgeAt, hideLine } = props;
|
|
4
|
+
const { fill, fontFamily, fontSize, textFill, lineStroke, arrowWidth } = props;
|
|
5
|
+
const { rectWidth, rectHeight } = props;
|
|
6
|
+
const { x1, y1, x2, y2 } = props;
|
|
7
|
+
if (!show) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
let edgeXRect;
|
|
11
|
+
let edgeYRect;
|
|
12
|
+
let edgeXText;
|
|
13
|
+
let edgeYText;
|
|
14
|
+
if (type === "horizontal") {
|
|
15
|
+
edgeXRect = orient === "right" ? edgeAt + 1 : edgeAt - rectWidth - arrowWidth - 1;
|
|
16
|
+
edgeYRect = y1 - rectHeight / 2;
|
|
17
|
+
edgeXText = orient === "right" ? edgeAt + rectWidth / 2 + arrowWidth : edgeAt - rectWidth / 2 - arrowWidth;
|
|
18
|
+
edgeYText = y1;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
edgeXRect = x1 - rectWidth / 2;
|
|
22
|
+
edgeYRect = orient === "bottom" ? edgeAt : edgeAt - rectHeight;
|
|
23
|
+
edgeXText = x1;
|
|
24
|
+
edgeYText = orient === "bottom" ? edgeAt + rectHeight / 2 : edgeAt - rectHeight / 2;
|
|
25
|
+
}
|
|
26
|
+
let coordinateBase;
|
|
27
|
+
let coordinate;
|
|
28
|
+
const textAnchor = "middle";
|
|
29
|
+
if (displayCoordinate !== undefined) {
|
|
30
|
+
coordinateBase = {
|
|
31
|
+
edgeXRect,
|
|
32
|
+
edgeYRect,
|
|
33
|
+
rectHeight,
|
|
34
|
+
rectWidth,
|
|
35
|
+
fill,
|
|
36
|
+
arrowWidth,
|
|
37
|
+
};
|
|
38
|
+
coordinate = {
|
|
39
|
+
edgeXText,
|
|
40
|
+
edgeYText,
|
|
41
|
+
textAnchor,
|
|
42
|
+
fontFamily,
|
|
43
|
+
fontSize,
|
|
44
|
+
textFill,
|
|
45
|
+
displayCoordinate,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const line = hideLine
|
|
49
|
+
? undefined
|
|
50
|
+
: {
|
|
51
|
+
stroke: lineStroke,
|
|
52
|
+
x1,
|
|
53
|
+
y1,
|
|
54
|
+
x2,
|
|
55
|
+
y2,
|
|
56
|
+
};
|
|
57
|
+
return {
|
|
58
|
+
coordinateBase,
|
|
59
|
+
coordinate,
|
|
60
|
+
line,
|
|
61
|
+
orient,
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
export class EdgeCoordinate extends React.Component {
|
|
65
|
+
render() {
|
|
66
|
+
const { className } = this.props;
|
|
67
|
+
const edge = helper(this.props);
|
|
68
|
+
if (edge === null) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
let line;
|
|
72
|
+
let coordinateBase;
|
|
73
|
+
let coordinate;
|
|
74
|
+
if (edge.line !== undefined) {
|
|
75
|
+
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 }));
|
|
76
|
+
}
|
|
77
|
+
if (edge.coordinate !== undefined && edge.coordinateBase !== undefined) {
|
|
78
|
+
const { rectWidth, rectHeight, arrowWidth } = edge.coordinateBase;
|
|
79
|
+
const path = edge.orient === "left"
|
|
80
|
+
? `M0,0L0,${rectHeight}L${rectWidth},${rectHeight}L${rectWidth + arrowWidth},10L${rectWidth},0L0,0L0,0`
|
|
81
|
+
: `M0,${arrowWidth}L${arrowWidth},${rectHeight}L${rectWidth + arrowWidth},${rectHeight}L${rectWidth + arrowWidth},0L${arrowWidth},0L0,${arrowWidth}`;
|
|
82
|
+
coordinateBase =
|
|
83
|
+
edge.orient === "left" || edge.orient === "right" ? (React.createElement("g", { transform: `translate(${edge.coordinateBase.edgeXRect},${edge.coordinateBase.edgeYRect})` },
|
|
84
|
+
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 }));
|
|
85
|
+
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));
|
|
86
|
+
}
|
|
87
|
+
return (React.createElement("g", { className: className },
|
|
88
|
+
line,
|
|
89
|
+
coordinateBase,
|
|
90
|
+
coordinate));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
EdgeCoordinate.defaultProps = {
|
|
94
|
+
className: "react-financial-charts-edgecoordinate",
|
|
95
|
+
orient: "left",
|
|
96
|
+
hideLine: false,
|
|
97
|
+
fill: "#8a8a8a",
|
|
98
|
+
fontFamily: "-apple-system, system-ui, Roboto, 'Helvetica Neue', Ubuntu, sans-serif",
|
|
99
|
+
fontSize: 13,
|
|
100
|
+
textFill: "#FFFFFF",
|
|
101
|
+
lineStroke: "rgba(0, 0, 0, 0.3)",
|
|
102
|
+
arrowWidth: 10,
|
|
103
|
+
};
|
|
104
|
+
EdgeCoordinate.drawOnCanvasStatic = (ctx, props) => {
|
|
105
|
+
props = Object.assign(Object.assign({}, EdgeCoordinate.defaultProps), props);
|
|
106
|
+
const edge = helper(props);
|
|
107
|
+
if (edge === null) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (edge.coordinate !== undefined && edge.coordinateBase !== undefined) {
|
|
111
|
+
const { rectWidth, rectHeight, arrowWidth } = edge.coordinateBase;
|
|
112
|
+
ctx.fillStyle = edge.coordinateBase.fill;
|
|
113
|
+
const x = edge.coordinateBase.edgeXRect;
|
|
114
|
+
const y = edge.coordinateBase.edgeYRect;
|
|
115
|
+
ctx.beginPath();
|
|
116
|
+
if (edge.orient === "right") {
|
|
117
|
+
ctx.moveTo(x, y + rectHeight / 2);
|
|
118
|
+
ctx.lineTo(x + arrowWidth, y);
|
|
119
|
+
ctx.lineTo(x + rectWidth + arrowWidth, y);
|
|
120
|
+
ctx.lineTo(x + rectWidth + arrowWidth, y + rectHeight);
|
|
121
|
+
ctx.lineTo(x + arrowWidth, y + rectHeight);
|
|
122
|
+
ctx.closePath();
|
|
123
|
+
}
|
|
124
|
+
else if (edge.orient === "left") {
|
|
125
|
+
ctx.moveTo(x, y);
|
|
126
|
+
ctx.lineTo(x + rectWidth, y);
|
|
127
|
+
ctx.lineTo(x + rectWidth + arrowWidth, y + rectHeight / 2);
|
|
128
|
+
ctx.lineTo(x + rectWidth, y + rectHeight);
|
|
129
|
+
ctx.lineTo(x, y + rectHeight);
|
|
130
|
+
ctx.closePath();
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
ctx.rect(x, y, rectWidth, rectHeight);
|
|
134
|
+
}
|
|
135
|
+
ctx.fill();
|
|
136
|
+
ctx.font = `${edge.coordinate.fontSize}px ${edge.coordinate.fontFamily}`;
|
|
137
|
+
ctx.fillStyle = edge.coordinate.textFill;
|
|
138
|
+
ctx.textAlign =
|
|
139
|
+
edge.coordinate.textAnchor === "middle" ? "center" : edge.coordinate.textAnchor;
|
|
140
|
+
ctx.textBaseline = "middle";
|
|
141
|
+
ctx.fillText(edge.coordinate.displayCoordinate, edge.coordinate.edgeXText, edge.coordinate.edgeYText);
|
|
142
|
+
}
|
|
143
|
+
if (edge.line !== undefined) {
|
|
144
|
+
ctx.strokeStyle = edge.line.stroke;
|
|
145
|
+
ctx.beginPath();
|
|
146
|
+
ctx.moveTo(edge.line.x1, edge.line.y1);
|
|
147
|
+
ctx.lineTo(edge.line.x2, edge.line.y2);
|
|
148
|
+
ctx.stroke();
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
151
|
//# sourceMappingURL=EdgeCoordinate.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
export declare function renderSVG(props: any): JSX.Element | null;
|
|
3
|
-
export declare function drawOnCanvas(ctx: CanvasRenderingContext2D, props: any): void;
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare function renderSVG(props: any): JSX.Element | null;
|
|
3
|
+
export declare function drawOnCanvas(ctx: CanvasRenderingContext2D, props: any): void;
|