@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,61 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
interface MouseCoordinateXV2Props {
|
|
3
|
+
readonly at?: "bottom" | "top";
|
|
4
|
+
readonly bg: {
|
|
5
|
+
readonly fill: string | ((moreProps: any, ctx: CanvasRenderingContext2D) => string);
|
|
6
|
+
readonly stroke: string | ((moreProps: any, ctx: CanvasRenderingContext2D) => string);
|
|
7
|
+
readonly strokeWidth: number | ((moreProps: any) => number);
|
|
8
|
+
readonly padding: {
|
|
9
|
+
left: number;
|
|
10
|
+
right: number;
|
|
11
|
+
top: number;
|
|
12
|
+
bottom: number;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
readonly drawCoordinate: (ctx: CanvasRenderingContext2D, shape: any, props: any, moreProps: any) => void;
|
|
16
|
+
readonly displayFormat: (value: number) => string;
|
|
17
|
+
readonly dx: number;
|
|
18
|
+
readonly dy: number;
|
|
19
|
+
readonly orient?: "bottom" | "top";
|
|
20
|
+
readonly text: {
|
|
21
|
+
readonly fontStyle: string;
|
|
22
|
+
readonly fontWeight: string;
|
|
23
|
+
readonly fontFamily: string;
|
|
24
|
+
readonly fontSize: number;
|
|
25
|
+
readonly fill: string | ((moreProps: any, ctx: CanvasRenderingContext2D) => string);
|
|
26
|
+
};
|
|
27
|
+
readonly xPosition: (props: MouseCoordinateXV2Props, moreProps: any) => number;
|
|
28
|
+
}
|
|
29
|
+
export declare class MouseCoordinateXV2 extends React.Component<MouseCoordinateXV2Props> {
|
|
30
|
+
static defaultProps: {
|
|
31
|
+
xPosition: typeof defaultXPosition;
|
|
32
|
+
drawCoordinate: typeof defaultDrawCoordinate;
|
|
33
|
+
at: string;
|
|
34
|
+
orient: string;
|
|
35
|
+
text: {
|
|
36
|
+
fontStyle: string;
|
|
37
|
+
fontWeight: string;
|
|
38
|
+
fontFamily: string;
|
|
39
|
+
fontSize: number;
|
|
40
|
+
fill: string;
|
|
41
|
+
};
|
|
42
|
+
bg: {
|
|
43
|
+
fill: string;
|
|
44
|
+
stroke: string;
|
|
45
|
+
strokeWidth: number;
|
|
46
|
+
padding: {
|
|
47
|
+
left: number;
|
|
48
|
+
right: number;
|
|
49
|
+
top: number;
|
|
50
|
+
bottom: number;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
dx: number;
|
|
54
|
+
dy: number;
|
|
55
|
+
};
|
|
56
|
+
render(): JSX.Element;
|
|
57
|
+
private readonly drawOnCanvas;
|
|
58
|
+
}
|
|
59
|
+
declare function defaultXPosition(props: MouseCoordinateXV2Props, moreProps: any): any;
|
|
60
|
+
declare function defaultDrawCoordinate(ctx: CanvasRenderingContext2D, shape: any, props: MouseCoordinateXV2Props, moreProps: any): void;
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { getMouseCanvas, GenericChartComponent } from "@tradingaction/core";
|
|
3
|
+
export class MouseCoordinateXV2 extends React.Component {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
this.drawOnCanvas = (ctx, moreProps) => {
|
|
7
|
+
const { show, currentItem } = moreProps;
|
|
8
|
+
const { drawCoordinate } = this.props;
|
|
9
|
+
if (show && currentItem != null) {
|
|
10
|
+
const shape = getXCoordinateInfo(ctx, this.props, moreProps);
|
|
11
|
+
drawCoordinate(ctx, shape, this.props, moreProps);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
render() {
|
|
16
|
+
return (React.createElement(GenericChartComponent, { clip: false, canvasDraw: this.drawOnCanvas, canvasToDraw: getMouseCanvas, drawOn: ["mousemove", "pan", "drag"] }));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
MouseCoordinateXV2.defaultProps = {
|
|
20
|
+
xPosition: defaultXPosition,
|
|
21
|
+
drawCoordinate: defaultDrawCoordinate,
|
|
22
|
+
at: "bottom",
|
|
23
|
+
orient: "bottom",
|
|
24
|
+
text: {
|
|
25
|
+
fontStyle: "",
|
|
26
|
+
fontWeight: "",
|
|
27
|
+
fontFamily: "-apple-system, system-ui, Roboto, 'Helvetica Neue', Ubuntu, sans-serif",
|
|
28
|
+
fontSize: 13,
|
|
29
|
+
fill: "rgb(35, 35, 35)",
|
|
30
|
+
},
|
|
31
|
+
bg: {
|
|
32
|
+
fill: "rgb(255, 255, 255)",
|
|
33
|
+
stroke: "rgb(35, 35, 35)",
|
|
34
|
+
strokeWidth: 1,
|
|
35
|
+
padding: {
|
|
36
|
+
left: 7,
|
|
37
|
+
right: 7,
|
|
38
|
+
top: 4,
|
|
39
|
+
bottom: 4,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
dx: 7,
|
|
43
|
+
dy: 7,
|
|
44
|
+
};
|
|
45
|
+
function defaultXPosition(props, moreProps) {
|
|
46
|
+
const { currentItem, xAccessor } = moreProps;
|
|
47
|
+
return xAccessor(currentItem);
|
|
48
|
+
}
|
|
49
|
+
function getXCoordinateInfo(ctx, props, moreProps) {
|
|
50
|
+
const { at, displayFormat, text, xPosition } = props;
|
|
51
|
+
const xValue = xPosition(props, moreProps);
|
|
52
|
+
const { xScale, chartConfig: { height }, } = moreProps;
|
|
53
|
+
ctx.font = `${text.fontStyle} ${text.fontWeight} ${text.fontSize}px ${text.fontFamily}`;
|
|
54
|
+
const t = displayFormat(xValue);
|
|
55
|
+
const textWidth = ctx.measureText(t).width;
|
|
56
|
+
const y = at === "bottom" ? height : 0;
|
|
57
|
+
const x = Math.round(xScale(xValue));
|
|
58
|
+
return {
|
|
59
|
+
x,
|
|
60
|
+
y,
|
|
61
|
+
textWidth,
|
|
62
|
+
text: t,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function defaultDrawCoordinate(ctx, shape, props, moreProps) {
|
|
66
|
+
const { x, y, textWidth, text } = shape;
|
|
67
|
+
const { orient, dx, dy, bg: { padding, fill, stroke, strokeWidth }, text: { fontSize, fill: textFill }, } = props;
|
|
68
|
+
ctx.textAlign = "center";
|
|
69
|
+
const sign = orient === "top" ? -1 : 1;
|
|
70
|
+
const halfWidth = Math.round(textWidth / 2 + padding.right);
|
|
71
|
+
const height = Math.round(fontSize + padding.top + padding.bottom);
|
|
72
|
+
ctx.strokeStyle = typeof stroke === "function" ? stroke(moreProps, ctx) : stroke;
|
|
73
|
+
ctx.fillStyle = typeof fill === "function" ? fill(moreProps, ctx) : fill;
|
|
74
|
+
ctx.lineWidth = typeof strokeWidth === "function" ? strokeWidth(moreProps) : strokeWidth;
|
|
75
|
+
ctx.beginPath();
|
|
76
|
+
ctx.moveTo(x, y);
|
|
77
|
+
ctx.lineTo(x + dx, y + sign * dy);
|
|
78
|
+
ctx.lineTo(x + halfWidth, y + sign * dy);
|
|
79
|
+
ctx.lineTo(x + halfWidth, y + sign * (dy + height));
|
|
80
|
+
ctx.lineTo(x - halfWidth, y + sign * (dy + height));
|
|
81
|
+
ctx.lineTo(x - halfWidth, y + sign * dy);
|
|
82
|
+
ctx.lineTo(x - dx, y + sign * dy);
|
|
83
|
+
ctx.closePath();
|
|
84
|
+
ctx.stroke();
|
|
85
|
+
ctx.fill();
|
|
86
|
+
ctx.beginPath();
|
|
87
|
+
ctx.fillStyle = typeof textFill === "function" ? textFill(moreProps, ctx) : textFill;
|
|
88
|
+
ctx.textBaseline = orient === "top" ? "alphabetic" : "hanging";
|
|
89
|
+
const pad = orient === "top" ? padding.bottom : padding.top;
|
|
90
|
+
ctx.fillText(text, x, y + sign * (dy + pad + 2));
|
|
91
|
+
}
|
|
92
|
+
//# sourceMapp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AC,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,EAAE,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export interface MouseCoordinateYProps {
|
|
3
|
+
readonly arrowWidth?: number;
|
|
4
|
+
readonly at?: "left" | "right";
|
|
5
|
+
readonly displayFormat: (value: number) => string;
|
|
6
|
+
readonly dx?: number;
|
|
7
|
+
readonly fontFamily?: string;
|
|
8
|
+
readonly fontSize?: number;
|
|
9
|
+
readonly fill?: string;
|
|
10
|
+
readonly fitToText?: boolean;
|
|
11
|
+
readonly opacity?: number;
|
|
12
|
+
readonly orient?: "left" | "right";
|
|
13
|
+
readonly rectWidth?: number;
|
|
14
|
+
readonly rectHeight?: number;
|
|
15
|
+
readonly stroke?: string;
|
|
16
|
+
readonly strokeOpacity?: number;
|
|
17
|
+
readonly strokeWidth?: number;
|
|
18
|
+
readonly textFill?: string;
|
|
19
|
+
readonly yAccessor?: (data: any) => number | undefined;
|
|
20
|
+
readonly yAxisPad?: number;
|
|
21
|
+
}
|
|
22
|
+
export declare class MouseCoordinateY extends React.Component<MouseCoordinateYProps> {
|
|
23
|
+
static defaultProps: {
|
|
24
|
+
arrowWidth: number;
|
|
25
|
+
at: string;
|
|
26
|
+
dx: number;
|
|
27
|
+
fill: string;
|
|
28
|
+
fitToText: boolean;
|
|
29
|
+
fontFamily: string;
|
|
30
|
+
fontSize: number;
|
|
31
|
+
opacity: number;
|
|
32
|
+
orient: string;
|
|
33
|
+
rectWidth: number;
|
|
34
|
+
rectHeight: number;
|
|
35
|
+
strokeOpacity: number;
|
|
36
|
+
strokeWidth: number;
|
|
37
|
+
textFill: string;
|
|
38
|
+
yAxisPad: number;
|
|
39
|
+
};
|
|
40
|
+
render(): JSX.Element;
|
|
41
|
+
private readonly drawOnCanvas;
|
|
42
|
+
private readonly helper;
|
|
43
|
+
}
|
|
44
|
+
export declare function getYCoordinate(y: number, coordinate: string, props: any, moreProps: any): {
|
|
45
|
+
coordinate: string;
|
|
46
|
+
show: boolean;
|
|
47
|
+
fitToText: any;
|
|
48
|
+
type: string;
|
|
49
|
+
orient: any;
|
|
50
|
+
edgeAt: any;
|
|
51
|
+
hideLine: boolean;
|
|
52
|
+
fill: any;
|
|
53
|
+
opacity: any;
|
|
54
|
+
fontFamily: any;
|
|
55
|
+
fontSize: any;
|
|
56
|
+
textFill: any;
|
|
57
|
+
stroke: any;
|
|
58
|
+
strokeOpacity: any;
|
|
59
|
+
strokeWidth: any;
|
|
60
|
+
rectWidth: any;
|
|
61
|
+
rectHeight: any;
|
|
62
|
+
arrowWidth: any;
|
|
63
|
+
dx: any;
|
|
64
|
+
x1: number;
|
|
65
|
+
x2: any;
|
|
66
|
+
y1: number;
|
|
67
|
+
y2: number;
|
|
68
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { getMouseCanvas, GenericChartComponent, isNotDefined } from "@tradingaction/core";
|
|
3
|
+
import { drawOnCanvas } from "./EdgeCoordinateV3";
|
|
4
|
+
export class MouseCoordinateY extends React.Component {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
this.drawOnCanvas = (ctx, moreProps) => {
|
|
8
|
+
const props = this.helper(this.props, moreProps);
|
|
9
|
+
if (props === undefined) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
drawOnCanvas(ctx, props);
|
|
13
|
+
};
|
|
14
|
+
this.helper = (props, moreProps) => {
|
|
15
|
+
const { chartConfig: { yScale }, chartId, currentItem, currentCharts, mouseXY, show, } = moreProps;
|
|
16
|
+
if (!show) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
if (isNotDefined(mouseXY)) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
if (currentCharts.indexOf(chartId) < 0) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
const { displayFormat, yAccessor } = props;
|
|
26
|
+
if (yAccessor && !currentItem) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
const y = yAccessor ? yScale(yAccessor(currentItem)) : mouseXY[1];
|
|
30
|
+
const coordinate = displayFormat(yScale.invert(y));
|
|
31
|
+
return getYCoordinate(y, coordinate, props, moreProps);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
render() {
|
|
35
|
+
return (React.createElement(GenericChartComponent, { clip: false, canvasDraw: this.drawOnCanvas, canvasToDraw: getMouseCanvas, drawOn: ["mousemove", "pan", "drag"] }));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
MouseCoordinateY.defaultProps = {
|
|
39
|
+
arrowWidth: 0,
|
|
40
|
+
at: "right",
|
|
41
|
+
dx: 0,
|
|
42
|
+
fill: "#4C525E",
|
|
43
|
+
fitToText: false,
|
|
44
|
+
fontFamily: "-apple-system, system-ui, Roboto, 'Helvetica Neue', Ubuntu, sans-serif",
|
|
45
|
+
fontSize: 13,
|
|
46
|
+
opacity: 1,
|
|
47
|
+
orient: "right",
|
|
48
|
+
rectWidth: 50,
|
|
49
|
+
rectHeight: 20,
|
|
50
|
+
strokeOpacity: 1,
|
|
51
|
+
strokeWidth: 1,
|
|
52
|
+
textFill: "#FFFFFF",
|
|
53
|
+
yAxisPad: 0,
|
|
54
|
+
};
|
|
55
|
+
export function getYCoordinate(y, coordinate, props, moreProps) {
|
|
56
|
+
const { width } = moreProps;
|
|
57
|
+
const { orient, at, rectWidth, rectHeight, dx, stroke, strokeOpacity, strokeWidth } = props;
|
|
58
|
+
const { fill, opacity, fitToText, fontFamily, fontSize, textFill, arrowWidth } = props;
|
|
59
|
+
const x1 = 0;
|
|
60
|
+
const x2 = width;
|
|
61
|
+
const edgeAt = at === "right" ? width : 0;
|
|
62
|
+
const type = "horizontal";
|
|
63
|
+
const hideLine = true;
|
|
64
|
+
const coordinateProps = {
|
|
65
|
+
coordinate,
|
|
66
|
+
show: true,
|
|
67
|
+
fitToText,
|
|
68
|
+
type,
|
|
69
|
+
orient,
|
|
70
|
+
edgeAt,
|
|
71
|
+
hideLine,
|
|
72
|
+
fill,
|
|
73
|
+
opacity,
|
|
74
|
+
fontFamily,
|
|
75
|
+
fontSize,
|
|
76
|
+
textFill,
|
|
77
|
+
stroke,
|
|
78
|
+
strokeOpacity,
|
|
79
|
+
strokeWidth,
|
|
80
|
+
rectWidth,
|
|
81
|
+
rectHeight,
|
|
82
|
+
arrowWidth,
|
|
83
|
+
dx,
|
|
84
|
+
x1,
|
|
85
|
+
x2,
|
|
86
|
+
y1: y,
|
|
87
|
+
y2: y,
|
|
88
|
+
};
|
|
89
|
+
return coordinateProps;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=MouseCoordinateY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MouseCoordinateY.js","sourceRoot":"","sources":["../src/MouseCoordinateY.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC1F,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAuBlD,MAAM,OAAO,gBAAiB,SAAQ,KAAK,CAAC,SAAgC;IAA5E;;QA8BqB,iBAAY,GAAG,CAAC,GAA6B,EAAE,SAAc,EAAE,EAAE;YAC9E,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;YACjD,IAAI,KAAK,KAAK,SAAS,EAAE;gBACrB,OAAO;aACV;YAED,YAAY,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC7B,CAAC,CAAC;QAEe,WAAM,GAAG,CAAC,KAA4B,EAAE,SAAc,EAAE,EAAE;YACvE,MAAM,EACF,WAAW,EAAE,EAAE,MAA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ction/core";
|
|
3
|
+
interface PriceCoordinateProps {
|
|
4
|
+
readonly arrowWidth?: number;
|
|
5
|
+
readonly at?: "bottom" | "top" | "left" | "right";
|
|
6
|
+
readonly displayFormat: (n: number) => string;
|
|
7
|
+
readonly dx?: number;
|
|
8
|
+
readonly fontFamily?: string;
|
|
9
|
+
readonly fontSize?: number;
|
|
10
|
+
readonly fill?: string | ((price: number) => string);
|
|
11
|
+
readonly lineOpacity?: number;
|
|
12
|
+
readonly lineStroke?: string;
|
|
13
|
+
readonly opacity?: number;
|
|
14
|
+
readonly orient?: "bottom" | "top" | "left" | "right";
|
|
15
|
+
readonly price: number;
|
|
16
|
+
readonly rectWidth?: number;
|
|
17
|
+
readonly rectHeight?: number;
|
|
18
|
+
readonly strokeDasharray?: strokeDashTypes;
|
|
19
|
+
readonly stroke?: string;
|
|
20
|
+
readonly strokeOpacity?: number;
|
|
21
|
+
readonly strokeWidth?: number;
|
|
22
|
+
readonly textFill?: string | ((price: number) => string);
|
|
23
|
+
readonly yAxisPad?: number;
|
|
24
|
+
}
|
|
25
|
+
export declare class PriceCoordinate extends React.Component<PriceCoordinateProps> {
|
|
26
|
+
static defaultProps: {
|
|
27
|
+
displayFormat: (n: number | {
|
|
28
|
+
valueOf(): number;
|
|
29
|
+
}) => string;
|
|
30
|
+
yAxisPad: number;
|
|
31
|
+
rectWidth: number;
|
|
32
|
+
rectHeight: number;
|
|
33
|
+
orient: string;
|
|
34
|
+
at: string;
|
|
35
|
+
price: number;
|
|
36
|
+
dx: number;
|
|
37
|
+
arrowWidth: number;
|
|
38
|
+
fill: string;
|
|
39
|
+
opacity: number;
|
|
40
|
+
lineOpacity: number;
|
|
41
|
+
lineStroke: string;
|
|
42
|
+
fontFamily: string;
|
|
43
|
+
fontSize: number;
|
|
44
|
+
textFill: string;
|
|
45
|
+
strokeOpacity: number;
|
|
46
|
+
strokeWidth: number;
|
|
47
|
+
strokeDasharray: string;
|
|
48
|
+
};
|
|
49
|
+
render(): JSX.Element;
|
|
50
|
+
private readonly drawOnCanvas;
|
|
51
|
+
private readonly helper;
|
|
52
|
+
}
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { format } from "d3-format";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { getAxisCanvas, GenericChartComponent, functor } from "@tradingaction/core";
|
|
4
|
+
import { drawOnCanvas } from "./EdgeCoordinateV3";
|
|
5
|
+
export class PriceCoordinate extends React.Component {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.drawOnCanvas = (ctx, moreProps) => {
|
|
9
|
+
const props = this.helper(this.props, moreProps);
|
|
10
|
+
drawOnCanvas(ctx, props);
|
|
11
|
+
};
|
|
12
|
+
this.helper = (props, moreProps) => {
|
|
13
|
+
const { chartConfig: { yScale }, width, } = moreProps;
|
|
14
|
+
const [lowerYValue, upperYValue] = yScale.domain();
|
|
15
|
+
const { price, stroke, strokeDasharray, strokeOpacity, strokeWidth } = props;
|
|
16
|
+
const { orient, at, rectWidth, rectHeight, displayFormat, dx } = props;
|
|
17
|
+
const { fill, opacity, fontFamily, fontSize, textFill, arrowWidth, lineOpacity, lineStroke } = props;
|
|
18
|
+
const x1 = 0;
|
|
19
|
+
const x2 = width;
|
|
20
|
+
const edgeAt = at === "right" ? width : 0;
|
|
21
|
+
const type = "horizontal";
|
|
22
|
+
const y = yScale(price);
|
|
23
|
+
const show = price <= upperYValue && price >= lowerYValue;
|
|
24
|
+
const coordinate = displayFormat(yScale.invert(y));
|
|
25
|
+
const hideLine = false;
|
|
26
|
+
const coordinateProps = {
|
|
27
|
+
coordinate,
|
|
28
|
+
show,
|
|
29
|
+
type,
|
|
30
|
+
orient,
|
|
31
|
+
edgeAt,
|
|
32
|
+
hideLine,
|
|
33
|
+
lineOpacity,
|
|
34
|
+
lineStroke,
|
|
35
|
+
lineStrokeDasharray: strokeDasharray,
|
|
36
|
+
stroke,
|
|
37
|
+
strokeOpacity,
|
|
38
|
+
strokeWidth,
|
|
39
|
+
fill: functor(fill)(price),
|
|
40
|
+
textFill: functor(textFill)(price),
|
|
41
|
+
opacity,
|
|
42
|
+
fontFamily,
|
|
43
|
+
fontSize,
|
|
44
|
+
rectWidth,
|
|
45
|
+
rectHeight,
|
|
46
|
+
arrowWidth,
|
|
47
|
+
dx,
|
|
48
|
+
x1,
|
|
49
|
+
x2,
|
|
50
|
+
y1: y,
|
|
51
|
+
y2: y,
|
|
52
|
+
};
|
|
53
|
+
return coordinateProps;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
render() {
|
|
57
|
+
return (React.createElement(GenericChartComponent, { clip: false, canvasDraw: this.drawOnCanvas, canvasToDraw: getAxisCanvas, drawOn: ["pan"] }));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
PriceCoordinate.defaultProps = {
|
|
61
|
+
displayFormat: format(".2f"),
|
|
62
|
+
yAxisPad: 0,
|
|
63
|
+
rectWidth: 50,
|
|
64
|
+
rectHeight: 20,
|
|
65
|
+
orient: "left",
|
|
66
|
+
at: "left",
|
|
67
|
+
price: 0,
|
|
68
|
+
dx: 0,
|
|
69
|
+
arrowWidth: 0,
|
|
70
|
+
fill: "#BAB8b8",
|
|
71
|
+
opacity: 1,
|
|
72
|
+
lineOpacity: 0.2,
|
|
73
|
+
lineStroke: "#000000",
|
|
74
|
+
fontFamily: "-apple-system, system-ui, Roboto, 'Helvetica Neue', Ubuntu, sans-serif",
|
|
75
|
+
fontSize: 13,
|
|
76
|
+
textFill: "#FFFFFF",
|
|
77
|
+
strokeOpacity: 1,
|
|
78
|
+
strokeWidth: 1,
|
|
79
|
+
strokeDasharray: "Solid",
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=PriceCoordinate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PriceCoordinate.js","sourceRoot":"","sources":["../src/PriceCoordinate.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM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IAAI,EAAE,SAAS;IACf,OAAO,EAAE,CAAC;IACV,WAAW,EAAE,GAAG;IAChB,UAAU,EAAE,SAAS;IACrB,UAAU,EAAE,wEAAwE;IACpF,QAAQ,EAAE,EAAE;IACZ,QAAQ,EAAE,SAAS;IACnB,aAAa,EAAE,CAAC;IAChB,WAAW,EAAE,CAAC;IACd,eAAe,EAAE,OAAO;CAC3B,CAAC"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./EdgeIndicator";
|
|
2
|
+
export * from "./CrossHairCursor";
|
|
3
|
+
export * from "./CurrentCoordinate";
|
|
4
|
+
export * from "./Cursor";
|
|
5
|
+
export * from "./MouseCoordinateX";
|
|
6
|
+
export { MouseCoordinateXV2 } from "./MouseCoordinateXV2";
|
|
7
|
+
export { MouseCoordinateY } from "./MouseCoordinateY";
|
|
8
|
+
export * from "./PriceCoordinate";
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./EdgeIndicator";
|
|
2
|
+
export * from "./CrossHairCursor";
|
|
3
|
+
export * from "./CurrentCoordinate";
|
|
4
|
+
export * from "./Cursor";
|
|
5
|
+
export * from "./MouseCoordinateX";
|
|
6
|
+
export { MouseCoordinateXV2 } from "./MouseCoordinateXV2";
|
|
7
|
+
export { MouseCoordinateY } from "./MouseCoordinateY";
|
|
8
|
+
export * from "./PriceCoordinate";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,UAAU,CAAC;AACzB,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,cAAc,mBAAmB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tradingaction/coordinates",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Coordinates for react-financial-charts",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"main": "./lib/index.js",
|
|
9
|
+
"typings": "./lib/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"lib",
|
|
12
|
+
"src"
|
|
13
|
+
],
|
|
14
|
+
"sideEffects": false,
|
|
15
|
+
"author": "Reactive Markets",
|
|
16
|
+
"keywords": [
|
|
17
|
+
"charts",
|
|
18
|
+
"charting",
|
|
19
|
+
"stockcharts",
|
|
20
|
+
"finance",
|
|
21
|
+
"financial",
|
|
22
|
+
"finance-chart",
|
|
23
|
+
"react",
|
|
24
|
+
"d3"
|
|
25
|
+
],
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "https://github.com/reactivemarkets/react-financial-charts.git"
|
|
30
|
+
},
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/reactivemarkets/react-financial-charts/issues"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "npm run clean && npm run compile",
|
|
36
|
+
"clean": "rimraf lib",
|
|
37
|
+
"compile": "tsc -p tsconfig.json",
|
|
38
|
+
"watch": "tsc -p tsconfig.json --watch --preserveWatchOutput"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@tradingaction/core": "^2.0.0",
|
|
42
|
+
"d3-format": "^2.0.0"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"react": "^16.0.0 || ^17.0.0 || ^18.0.0",
|
|
46
|
+
"react-dom": "^16.0.0 || ^17.0.0 || ^18.0.0"
|
|
47
|
+
},
|
|
48
|
+
"gitHead": "928c231405fcf3e2eff3585c69123776dcb76b34"
|
|
49
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import {
|
|
3
|
+
getStrokeDasharrayCanvas,
|
|
4
|
+
strokeDashTypes,
|
|
5
|
+
GenericComponent,
|
|
6
|
+
getMouseCanvas,
|
|
7
|
+
ChartCanvasContext,
|
|
8
|
+
} from "@tradingaction/core";
|
|
9
|
+
|
|
10
|
+
const defaultCustomX = (props: CrossHairCursorProps, moreProps: any) => {
|
|
11
|
+
const { xScale, xAccessor, currentItem, mouseXY } = moreProps;
|
|
12
|
+
const { snapX } = props;
|
|
13
|
+
const x = snapX ? Math.round(xScale(xAccessor(currentItem))) : mouseXY[0] + 0.5;
|
|
14
|
+
return x;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export interface CrossHairCursorProps {
|
|
18
|
+
readonly customX?: (props: CrossHairCursorProps, moreProps: any) => number;
|
|
19
|
+
readonly snapX?: boolean;
|
|
20
|
+
readonly strokeStyle?: string;
|
|
21
|
+
readonly strokeDasharray?: strokeDashTypes;
|
|
22
|
+
readonly strokeWidth?: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class CrossHairCursor extends React.Component<CrossHairCursorProps> {
|
|
26
|
+
public static defaultProps = {
|
|
27
|
+
customX: defaultCustomX,
|
|
28
|
+
snapX: true,
|
|
29
|
+
strokeStyle: "rgba(55, 71, 79, 0.8)",
|
|
30
|
+
strokeDasharray: "Dash",
|
|
31
|
+
strokeWidth: 1,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
public static contextType = ChartCanvasContext;
|
|
35
|
+
|
|
36
|
+
public render() {
|
|
37
|
+
return (
|
|
38
|
+
<GenericComponent
|
|
39
|
+
clip={false}
|
|
40
|
+
canvasDraw={this.drawOnCanvas}
|
|
41
|
+
canvasToDraw={getMouseCanvas}
|
|
42
|
+
drawOn={["mousemove", "pan", "drag"]}
|
|
43
|
+
/>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private readonly drawOnCanvas = (ctx: CanvasRenderingContext2D, moreProps: any) => {
|
|
48
|
+
const lines = this.getLines(this.props, moreProps);
|
|
49
|
+
if (lines === undefined) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const { margin, ratio } = this.context;
|
|
54
|
+
|
|
55
|
+
const originX = 0.5 * ratio + margin.left;
|
|
56
|
+
const originY = 0.5 * ratio + margin.top;
|
|
57
|
+
|
|
58
|
+
ctx.save();
|
|
59
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
60
|
+
ctx.scale(ratio, ratio);
|
|
61
|
+
ctx.translate(originX, originY);
|
|
62
|
+
|
|
63
|
+
lines.forEach((line) => {
|
|
64
|
+
const dashArray = getStrokeDasharrayCanvas(line.strokeDasharray);
|
|
65
|
+
|
|
66
|
+
ctx.strokeStyle = line.strokeStyle;
|
|
67
|
+
ctx.lineWidth = line.strokeWidth;
|
|
68
|
+
ctx.setLineDash(dashArray);
|
|
69
|
+
ctx.beginPath();
|
|
70
|
+
ctx.moveTo(line.x1, line.y1);
|
|
71
|
+
ctx.lineTo(line.x2, line.y2);
|
|
72
|
+
ctx.stroke();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
ctx.restore();
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
private readonly getLines = (props: CrossHairCursorProps, moreProps: any) => {
|
|
79
|
+
const { mouseXY, currentItem, show, height, width } = moreProps;
|
|
80
|
+
|
|
81
|
+
const {
|
|
82
|
+
customX = CrossHairCursor.defaultProps.customX,
|
|
83
|
+
strokeStyle = CrossHairCursor.defaultProps.strokeStyle,
|
|
84
|
+
strokeDasharray,
|
|
85
|
+
strokeWidth = CrossHairCursor.defaultProps.strokeWidth,
|
|
86
|
+
} = props;
|
|
87
|
+
|
|
88
|
+
if (!show || currentItem === undefined) {
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const line1 = {
|
|
93
|
+
x1: 0,
|
|
94
|
+
x2: width,
|
|
95
|
+
y1: mouseXY[1] + 0.5,
|
|
96
|
+
y2: mouseXY[1] + 0.5,
|
|
97
|
+
strokeStyle,
|
|
98
|
+
strokeDasharray,
|
|
99
|
+
strokeWidth,
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const x = customX(props, moreProps);
|
|
103
|
+
|
|
104
|
+
const line2 = {
|
|
105
|
+
x1: x,
|
|
106
|
+
x2: x,
|
|
107
|
+
y1: 0,
|
|
108
|
+
y2: height,
|
|
109
|
+
strokeStyle,
|
|
110
|
+
strokeDasharray,
|
|
111
|
+
strokeWidth,
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
return [line1, line2];
|
|
115
|
+
};
|
|
116
|
+
}
|