@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.
Files changed (51) hide show
  1. package/LICENSE +24 -0
  2. package/README.md +5 -0
  3. package/lib/CrossHairCursor.d.ts +22 -0
  4. package/lib/CrossHairCursor.js +76 -0
  5. package/lib/CrossHairCursor.js.map +1 -0
  6. package/lib/CurrentCoordinate.d.ts +31 -0
  7. package/lib/CurrentCoordinate.js +54 -0
  8. package/lib/CurrentCoordinate.js.map +1 -0
  9. package/lib/Cursor.d.ts +31 -0
  10. package/lib/Cursor.js +122 -0
  11. package/lib/Cursor.js.map +1 -0
  12. package/lib/EdgeCoordinate.d.ts +32 -0
  13. package/lib/EdgeCoordinate.js +151 -0
  14. package/lib/EdgeCoordinate.js.map +1 -0
  15. package/lib/EdgeCoordinateV2.d.ts +3 -0
  16. package/lib/EdgeCoordinateV2.js +138 -0
  17. package/lib/EdgeCoordinateV2.js.map +1 -0
  18. package/lib/EdgeCoordinateV3.d.ts +3 -0
  19. package/lib/EdgeCoordinateV3.js +176 -0
  20. package/lib/EdgeCoordinateV3.js.map +1 -0
  21. package/lib/EdgeIndicator.d.ts +55 -0
  22. package/lib/EdgeIndicator.js +85 -0
  23. package/lib/EdgeIndicator.js.map +1 -0
  24. package/lib/MouseCoordinateX.d.ts +49 -0
  25. package/lib/MouseCoordinateX.js +85 -0
  26. package/lib/MouseCoordinateX.js.map +1 -0
  27. package/lib/MouseCoordinateXV2.d.ts +61 -0
  28. package/lib/MouseCoordinateXV2.js +92 -0
  29. package/lib/MouseCoordinateXV2.js.map +1 -0
  30. package/lib/MouseCoordinateY.d.ts +68 -0
  31. package/lib/MouseCoordinateY.js +91 -0
  32. package/lib/MouseCoordinateY.js.map +1 -0
  33. package/lib/PriceCoordinate.d.ts +53 -0
  34. package/lib/PriceCoordinate.js +81 -0
  35. package/lib/PriceCoordinate.js.map +1 -0
  36. package/lib/index.d.ts +8 -0
  37. package/lib/index.js +9 -0
  38. package/lib/index.js.map +1 -0
  39. package/package.json +49 -0
  40. package/src/CrossHairCursor.tsx +116 -0
  41. package/src/CurrentCoordinate.tsx +95 -0
  42. package/src/Cursor.tsx +174 -0
  43. package/src/EdgeCoordinate.tsx +239 -0
  44. package/src/EdgeCoordinateV2.tsx +204 -0
  45. package/src/EdgeCoordinateV3.tsx +284 -0
  46. package/src/EdgeIndicator.tsx +161 -0
  47. package/src/MouseCoordinateX.tsx +127 -0
  48. package/src/MouseCoordinateXV2.tsx +161 -0
  49. package/src/MouseCoordinateY.tsx +141 -0
  50. package/src/PriceCoordinate.tsx +121 -0
  51. package/src/index.ts +8 -0
package/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ The MIT License (MIT)
2
+ https://github.com/reactivemarkets/react-financial-charts
3
+
4
+ Copyright (c) 2015-2018 Ragu Ramaswamy
5
+ Copyright (c) 2016 Julien Renaux
6
+ Copyright (c) 2019 Reactive Markets
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in
16
+ all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # Coordinates
2
+
3
+ ```bash
4
+ npm i @react-financial-charts/coordinates
5
+ ```
@@ -0,0 +1,22 @@
1
+ import * as React from "react";
2
+ import { strokeDashTypes } from "@tradingaction/core";
3
+ export interface CrossHairCursorProps {
4
+ readonly customX?: (props: CrossHairCursorProps, moreProps: any) => number;
5
+ readonly snapX?: boolean;
6
+ readonly strokeStyle?: string;
7
+ readonly strokeDasharray?: strokeDashTypes;
8
+ readonly strokeWidth?: number;
9
+ }
10
+ export declare class CrossHairCursor extends React.Component<CrossHairCursorProps> {
11
+ static defaultProps: {
12
+ customX: (props: CrossHairCursorProps, moreProps: any) => any;
13
+ snapX: boolean;
14
+ strokeStyle: string;
15
+ strokeDasharray: string;
16
+ strokeWidth: number;
17
+ };
18
+ static contextType: React.Context<import("@tradingaction/core/lib/ChartCanvas").ChartCanvasContextType<number | Date>>;
19
+ render(): JSX.Element;
20
+ private readonly drawOnCanvas;
21
+ private readonly getLines;
22
+ }
@@ -0,0 +1,76 @@
1
+ import * as React from "react";
2
+ import { getStrokeDasharrayCanvas, GenericComponent, getMouseCanvas, ChartCanvasContext, } from "@tradingaction/core";
3
+ const defaultCustomX = (props, moreProps) => {
4
+ const { xScale, xAccessor, currentItem, mouseXY } = moreProps;
5
+ const { snapX } = props;
6
+ const x = snapX ? Math.round(xScale(xAccessor(currentItem))) : mouseXY[0] + 0.5;
7
+ return x;
8
+ };
9
+ export class CrossHairCursor extends React.Component {
10
+ constructor() {
11
+ super(...arguments);
12
+ this.drawOnCanvas = (ctx, moreProps) => {
13
+ const lines = this.getLines(this.props, moreProps);
14
+ if (lines === undefined) {
15
+ return;
16
+ }
17
+ const { margin, ratio } = this.context;
18
+ const originX = 0.5 * ratio + margin.left;
19
+ const originY = 0.5 * ratio + margin.top;
20
+ ctx.save();
21
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
22
+ ctx.scale(ratio, ratio);
23
+ ctx.translate(originX, originY);
24
+ lines.forEach((line) => {
25
+ const dashArray = getStrokeDasharrayCanvas(line.strokeDasharray);
26
+ ctx.strokeStyle = line.strokeStyle;
27
+ ctx.lineWidth = line.strokeWidth;
28
+ ctx.setLineDash(dashArray);
29
+ ctx.beginPath();
30
+ ctx.moveTo(line.x1, line.y1);
31
+ ctx.lineTo(line.x2, line.y2);
32
+ ctx.stroke();
33
+ });
34
+ ctx.restore();
35
+ };
36
+ this.getLines = (props, moreProps) => {
37
+ const { mouseXY, currentItem, show, height, width } = moreProps;
38
+ const { customX = CrossHairCursor.defaultProps.customX, strokeStyle = CrossHairCursor.defaultProps.strokeStyle, strokeDasharray, strokeWidth = CrossHairCursor.defaultProps.strokeWidth, } = props;
39
+ if (!show || currentItem === undefined) {
40
+ return undefined;
41
+ }
42
+ const line1 = {
43
+ x1: 0,
44
+ x2: width,
45
+ y1: mouseXY[1] + 0.5,
46
+ y2: mouseXY[1] + 0.5,
47
+ strokeStyle,
48
+ strokeDasharray,
49
+ strokeWidth,
50
+ };
51
+ const x = customX(props, moreProps);
52
+ const line2 = {
53
+ x1: x,
54
+ x2: x,
55
+ y1: 0,
56
+ y2: height,
57
+ strokeStyle,
58
+ strokeDasharray,
59
+ strokeWidth,
60
+ };
61
+ return [line1, line2];
62
+ };
63
+ }
64
+ render() {
65
+ return (React.createElement(GenericComponent, { clip: false, canvasDraw: this.drawOnCanvas, canvasToDraw: getMouseCanvas, drawOn: ["mousemove", "pan", "drag"] }));
66
+ }
67
+ }
68
+ CrossHairCursor.defaultProps = {
69
+ customX: defaultCustomX,
70
+ snapX: true,
71
+ strokeStyle: "rgba(55, 71, 79, 0.8)",
72
+ strokeDasharray: "Dash",
73
+ strokeWidth: 1,
74
+ };
75
+ CrossHairCursor.contextType = ChartCanvasContext;
76
+ //# sourceMappingURL=CrossHairCursor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CrossHairCursor.js","sourceRoot":"","sources":["../src/CrossH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,CAAC,CAAC,CAAC,GAAG,GAAG;gBACpB,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,GAAG;gBACpB,WAAW;gBACX,eAAe;gBACf,WAAW;aACd,CAAC;YAEF,MAAM,CAAC,GAAG,OAAO,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;YAEpC,MAAM,KAAK,GAAG;gBACV,EAAE,EAAE,CAAC;gBACL,EAAE,EAAE,CAAC;gBACL,EAAE,EAAE,CAAC;gBACL,EAAE,EAAE,MAAM;gBACV,WAAW;gBACX,eAAe;gBACf,WAAW;aACd,CAAC;YAEF,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAC1B,CAAC,CAAC;IACN,CAAC;IAhFU,MAAM;QACT,OAAO,CACH,oBAAC,gBAAgB,IACb,IAAI,EAAE,KAAK,EACX,UAAU,EAAE,IAAI,CAAC,YAAY,EAC7B,YAAY,EAAE,cAAc,EAC5B,MAAM,EAAE,CAAC,WAAW,EAAE,KAAK,EAAE,MAAM,CAAC,GACtC,CACL,CAAC;IACN,CAAC;;AAnBa,4BAAY,GAAG;IACzB,OAAO,EAAE,cAAc;IACvB,KAAK,EAAE,IAAI;IACX,WAAW,EAAE,uBAAuB;IACpC,eAAe,EAAE,MAAM;IACvB,WAAW,EAAE,CAAC;CACjB,CAAC;AAEY,2BAAW,GAAG,kBAAkB,CAAC"}
@@ -0,0 +1,31 @@
1
+ import * as React from "react";
2
+ export interface CurrentCoordinateProps {
3
+ /**
4
+ * Fill style for the circle.
5
+ */
6
+ readonly fillStyle?: string | ((datum: any) => string);
7
+ /**
8
+ * The radius to draw the circle
9
+ */
10
+ readonly r: number;
11
+ /**
12
+ * Stroke of the circle
13
+ */
14
+ readonly strokeStyle?: string | ((datum: any) => string);
15
+ /**
16
+ * Y accessor to use for the circle.
17
+ */
18
+ readonly yAccessor: (item: any) => number;
19
+ }
20
+ /**
21
+ * Draws a circle at the current x location of radius `r`.
22
+ */
23
+ export declare class CurrentCoordinate extends React.Component<CurrentCoordinateProps> {
24
+ static defaultProps: {
25
+ fillStyle: string;
26
+ r: number;
27
+ };
28
+ render(): JSX.Element;
29
+ private readonly drawOnCanvas;
30
+ private readonly getCircle;
31
+ }
@@ -0,0 +1,54 @@
1
+ import { getMouseCanvas, GenericChartComponent } from "@tradingaction/core";
2
+ import * as React from "react";
3
+ /**
4
+ * Draws a circle at the current x location of radius `r`.
5
+ */
6
+ export class CurrentCoordinate extends React.Component {
7
+ constructor() {
8
+ super(...arguments);
9
+ this.drawOnCanvas = (ctx, moreProps) => {
10
+ const circle = this.getCircle(moreProps);
11
+ if (circle === undefined) {
12
+ return;
13
+ }
14
+ const { fillStyle, r, strokeStyle } = this.props;
15
+ const fillColor = fillStyle instanceof Function ? fillStyle(moreProps.currentItem) : fillStyle;
16
+ if (fillColor !== undefined) {
17
+ ctx.fillStyle = fillColor;
18
+ }
19
+ const strokeColor = strokeStyle instanceof Function ? strokeStyle(moreProps.currentItem) : strokeStyle;
20
+ if (strokeColor !== undefined) {
21
+ ctx.strokeStyle = strokeColor;
22
+ }
23
+ ctx.beginPath();
24
+ ctx.arc(circle.x, circle.y, r, 0, 2 * Math.PI, false);
25
+ ctx.fill();
26
+ if (strokeColor !== undefined) {
27
+ ctx.stroke();
28
+ }
29
+ };
30
+ this.getCircle = (moreProps) => {
31
+ const { show, xScale, chartConfig: { yScale }, currentItem, xAccessor, } = moreProps;
32
+ if (!show || currentItem === undefined) {
33
+ return undefined;
34
+ }
35
+ const { yAccessor } = this.props;
36
+ const xValue = xAccessor(currentItem);
37
+ const yValue = yAccessor(currentItem);
38
+ if (yValue === undefined) {
39
+ return undefined;
40
+ }
41
+ const x = Math.round(xScale(xValue));
42
+ const y = Math.round(yScale(yValue));
43
+ return { x, y };
44
+ };
45
+ }
46
+ render() {
47
+ return (React.createElement(GenericChartComponent, { canvasDraw: this.drawOnCanvas, canvasToDraw: getMouseCanvas, drawOn: ["mousemove", "pan"] }));
48
+ }
49
+ }
50
+ CurrentCoordinate.defaultProps = {
51
+ fillStyle: "#2196f3",
52
+ r: 3,
53
+ };
54
+ //# sourceMappingURL=CurrentCoordinate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CurrentCoordinate.js","sourceRoot":"","sources":["../src/CurrentCoordinate.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAqB/B;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,KAAK,CAAC,SAAiC;IAA9E;;QAgBqB,iBAAY,GAAG,CAAC,GAA6B,EAAE,SAAc,EAAE,EAAE;YAC9E,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;YACzC,IAAI,MAAM,KAAK,SAAS,EAAE;gBACtB,OAAO;aACV;YAED,MAAM,EAAE,SAAS,EAAE,CAAC,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;YAEjD,MAAM,SAAS,GAAG,SAAS,YAAY,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YAC/F,IAAI,SAAS,KAAK,SAAS,EAAE;gBACzB,GAAG,CAAC,SAAS,GAAG,SAAS,CAAC;aAC7B;YAED,MAAM,WAAW,GAAG,WAAW,YAAY,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;YACvG,IAAI,WAAW,KAAK,SAAS,EAAE;gBAC3B,GAAG,CAAC,WAAW,GAAG,WAAW,CAAC;aACjC;YAED,GAAG,CAAC,SAAS,EAAE,CAAC;YAChB,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;YACtD,GAAG,CAAC,IAAI,EAAE,CAAC;YACX,IAAI,WAAW,KAAK,SAAS,EAAE;gBAC3B,GAAG,CAAC,MAAM,EAAE,CAAC;aAChB;QACL,CAAC,CAAC;QAEe,cAAS,GAAG,CAAC,SAAc,EAAE,EAAE;YAC5C,MAAM,EACF,IAAI,EACJ,MAAM,EACN,WAAW,EAAE,EAAE,MAAM,EAAE,EACvB,WAAW,EACX,SAAS,GACZ,GAAG,SAAS,CAAC;YAEd,IAAI,CAAC,IAAI,IAAI,WAAW,KAAK,SAAS,EAAE;gBACpC,OAAO,SAAS,CAAC;aACpB;YAED,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;YAEjC,MAAM,MAAM,GAAG,SAAS,CAAC,WAAW,CAAC,CAAC;YACtC,MAAM,MAAM,GAAG,SAAS,CAAC,WAAW,CAAC,CAAC;YAEtC,IAAI,MAAM,KAAK,SAAS,EAAE;gBACtB,OAAO,SAAS,CAAC;aACpB;YAED,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;YACrC,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;YAErC,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;QACpB,CAAC,CAAC;IACN,CAAC;IA/DU,MAAM;QACT,OAAO,CACH,oBAAC,qBAAqB,IAClB,UAAU,EAAE,IAAI,CAAC,YAAY,EAC7B,YAAY,EAAE,cAAc,EAC5B,MAAM,EAAE,CAAC,WAAW,EAAE,KAAK,CAAC,GAC9B,CACL,CAAC;IACN,CAAC;;AAba,8BAAY,GAAG;IACzB,SAAS,EAAE,SAAS;IACpB,CAAC,EAAE,CAAC;CACP,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { strokeDashTypes } from "@tradingaction/core";
2
+ import * as React from "react";
3
+ export interface CursorProps {
4
+ readonly customX?: (props: CursorProps, moreProps: any) => number;
5
+ readonly disableYCursor?: boolean;
6
+ readonly snapX?: boolean;
7
+ readonly strokeDasharray?: strokeDashTypes;
8
+ readonly strokeStyle?: string;
9
+ readonly useXCursorShape?: boolean;
10
+ readonly xCursorShapeFillStyle?: string | ((currentItem: any) => string);
11
+ readonly xCursorShapeStrokeStyle?: string | ((currentItem: any) => string);
12
+ readonly xCursorShapeStrokeDasharray?: strokeDashTypes;
13
+ }
14
+ export declare class Cursor extends React.Component<CursorProps> {
15
+ static defaultProps: {
16
+ strokeStyle: string;
17
+ strokeDasharray: string;
18
+ snapX: boolean;
19
+ customX: (props: CursorProps, moreProps: any) => any;
20
+ disableYCursor: boolean;
21
+ useXCursorShape: boolean;
22
+ xCursorShapeStrokeStyle: string;
23
+ };
24
+ static contextType: React.Context<import("@tradingaction/core/lib/ChartCanvas").ChartCanvasContextType<number | Date>>;
25
+ render(): JSX.Element;
26
+ private getXCursorShapeStroke;
27
+ private getXCursorShapeFill;
28
+ private getXCursorShape;
29
+ private getXYCursor;
30
+ private readonly drawOnCanvas;
31
+ }
package/lib/Cursor.js ADDED
@@ -0,0 +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;
122
+ //# sourceMappingURL=Cursor.js.map
@@ -0,0 +1 @@
1
+ {"version":3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G;YACpB,WAAW;YACX,eAAe;YACf,SAAS,EAAE,KAAK;SACnB,CAAC;QAEF,MAAM,CAAC,GAAG,OAAO,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;QAEpC,MAAM,OAAO,GAAG;YACZ,EAAE,EAAE,CAAC;YACL,EAAE,EAAE,CAAC;YACL,EAAE,EAAE,CAAC;YACL,EAAE,EAAE,MAAM;YACV,WAAW;YACX,eAAe;YACf,SAAS,EAAE,IAAI;SAClB,CAAC;QAEF,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC3D,CAAC;;AAjFa,mBAAY,GAAG;IACzB,WAAW,EAAE,uBAAuB;IACpC,eAAe,EAAE,WAAW;IAC5B,KAAK,EAAE,IAAI;IACX,OAAO,EAAE,kBAAkB;IAC3B,cAAc,EAAE,KAAK;IACrB,eAAe,EAAE,KAAK;IACtB,uBAAuB,EAAE,oBAAoB;CAChD,CAAC;AAEY,kBAAW,GAAG,kBAAkB,CAAC"}
@@ -0,0 +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
+ }
@@ -0,0 +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
+ };
151
+ //# sourceMappingURL=EdgeCoordinate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EdgeCoordinate.js","sourceRoot":"","sources":["../src/EdgeCoordinate.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,MAAM,MAAM,GAAG,CAAC,KAAU,EAAE,EAAE;IAC1B,MAAM,EAAE,UAAU,EAAE,iBAAiB,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IACtF,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,KAAK,CAAC;IAC/E,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,KAAK,CAAC;IACxC,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,KAAK,CAAC;IAEjC,IAAI,CAAC,IAAI,EAAE;QACP,OAAO,IAAI,CAAC;KACf;IAED,IAAI,SAAS,CAAC;IACd,IAAI,SAAS,CAAC;IACd,IAAI,SAAS,CAAC;IACd,IAAI,SAAS,CAAC;IAEd,IAAI,IAAI,KAAK,YAAY,EAAE;QACvB,SAAS,GAAG,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,SAAS,GAAG,UAAU,GAAG,CAAC,CAAC;QAClF,SAAS,GAAG,EAAE,GAAG,UAAU,GAAG,CAAC,CAAC;QAChC,SAAS,GAAG,MAAM,KAAK,OAAO,C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AAC,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,CAAC"}
@@ -0,0 +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;