@tradingaction/interactive 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.
Files changed (135) hide show
  1. package/LICENSE +24 -0
  2. package/README.md +5 -0
  3. package/lib/Brush.d.ts +35 -0
  4. package/lib/Brush.js +103 -0
  5. package/lib/Brush.js.map +1 -0
  6. package/lib/ClickCallback.d.ts +18 -0
  7. package/lib/ClickCallback.js +12 -0
  8. package/lib/ClickCallback.js.map +1 -0
  9. package/lib/DrawingObjectSelector.d.ts +18 -0
  10. package/lib/DrawingObjectSelector.js +73 -0
  11. package/lib/DrawingObjectSelector.js.map +1 -0
  12. package/lib/EquidistantChannel.d.ts +74 -0
  13. package/lib/EquidistantChannel.js +149 -0
  14. package/lib/EquidistantChannel.js.map +1 -0
  15. package/lib/FibonacciRetracement.d.ts +89 -0
  16. package/lib/FibonacciRetracement.js +184 -0
  17. package/lib/FibonacciRetracement.js.map +1 -0
  18. package/lib/GannFan.d.ts +78 -0
  19. package/lib/GannFan.js +128 -0
  20. package/lib/GannFan.js.map +1 -0
  21. package/lib/InteractiveText.d.ts +65 -0
  22. package/lib/InteractiveText.js +83 -0
  23. package/lib/InteractiveText.js.map +1 -0
  24. package/lib/InteractiveYCoordinate.d.ts +122 -0
  25. package/lib/InteractiveYCoordinate.js +100 -0
  26. package/lib/InteractiveYCoordinate.js.map +1 -0
  27. package/lib/StandardDeviationChannel.d.ts +74 -0
  28. package/lib/StandardDeviationChannel.js +125 -0
  29. package/lib/StandardDeviationChannel.js.map +1 -0
  30. package/lib/TrendLine.d.ts +84 -0
  31. package/lib/TrendLine.js +128 -0
  32. package/lib/TrendLine.js.map +1 -0
  33. package/lib/ZoomButtons.d.ts +30 -0
  34. package/lib/ZoomButtons.js +78 -0
  35. package/lib/ZoomButtons.js.map +1 -0
  36. package/lib/components/ChannelWithArea.d.ts +30 -0
  37. package/lib/components/ChannelWithArea.js +126 -0
  38. package/lib/components/ChannelWithArea.js.map +1 -0
  39. package/lib/components/ClickableCircle.d.ts +26 -0
  40. package/lib/components/ClickableCircle.js +48 -0
  41. package/lib/components/ClickableCircle.js.map +1 -0
  42. package/lib/components/ClickableShape.d.ts +33 -0
  43. package/lib/components/ClickableShape.js +64 -0
  44. package/lib/components/ClickableShape.js.map +1 -0
  45. package/lib/components/GannFan.d.ts +32 -0
  46. package/lib/components/GannFan.js +134 -0
  47. package/lib/components/GannFan.js.map +1 -0
  48. package/lib/components/HoverTextNearMouse.d.ts +35 -0
  49. package/lib/components/HoverTextNearMouse.js +113 -0
  50. package/lib/components/HoverTextNearMouse.js.map +1 -0
  51. package/lib/components/InteractiveStraightLine.d.ts +61 -0
  52. package/lib/components/InteractiveStraightLine.js +220 -0
  53. package/lib/components/InteractiveStraightLine.js.map +1 -0
  54. package/lib/components/InteractiveText.d.ts +38 -0
  55. package/lib/components/InteractiveText.js +84 -0
  56. package/lib/components/InteractiveText.js.map +1 -0
  57. package/lib/components/InteractiveYCoordinate.d.ts +46 -0
  58. package/lib/components/InteractiveYCoordinate.js +109 -0
  59. package/lib/components/InteractiveYCoordinate.js.map +1 -0
  60. package/lib/components/LinearRegressionChannelWithArea.d.ts +31 -0
  61. package/lib/components/LinearRegressionChannelWithArea.js +104 -0
  62. package/lib/components/LinearRegressionChannelWithArea.js.map +1 -0
  63. package/lib/components/MouseLocationIndicator.d.ts +34 -0
  64. package/lib/components/MouseLocationIndicator.js +79 -0
  65. package/lib/components/MouseLocationIndicator.js.map +1 -0
  66. package/lib/components/Text.d.ts +17 -0
  67. package/lib/components/Text.js +26 -0
  68. package/lib/components/Text.js.map +1 -0
  69. package/lib/components/index.d.ts +11 -0
  70. package/lib/components/index.js +12 -0
  71. package/lib/components/index.js.map +1 -0
  72. package/lib/index.d.ts +12 -0
  73. package/lib/index.js +13 -0
  74. package/lib/index.js.map +1 -0
  75. package/lib/utils.d.ts +7 -0
  76. package/lib/utils.js +84 -0
  77. package/lib/utils.js.map +1 -0
  78. package/lib/wrapper/EachEquidistantChannel.d.ts +59 -0
  79. package/lib/wrapper/EachEquidistantChannel.js +172 -0
  80. package/lib/wrapper/EachEquidistantChannel.js.map +1 -0
  81. package/lib/wrapper/EachFibRetracement.d.ts +81 -0
  82. package/lib/wrapper/EachFibRetracement.js +202 -0
  83. package/lib/wrapper/EachFibRetracement.js.map +1 -0
  84. package/lib/wrapper/EachGannFan.d.ts +81 -0
  85. package/lib/wrapper/EachGannFan.js +161 -0
  86. package/lib/wrapper/EachGannFan.js.map +1 -0
  87. package/lib/wrapper/EachInteractiveYCoordinate.d.ts +50 -0
  88. package/lib/wrapper/EachInteractiveYCoordinate.js +80 -0
  89. package/lib/wrapper/EachInteractiveYCoordinate.js.map +1 -0
  90. package/lib/wrapper/EachLinearRegressionChannel.d.ts +75 -0
  91. package/lib/wrapper/EachLinearRegressionChannel.js +89 -0
  92. package/lib/wrapper/EachLinearRegressionChannel.js.map +1 -0
  93. package/lib/wrapper/EachText.d.ts +59 -0
  94. package/lib/wrapper/EachText.js +83 -0
  95. package/lib/wrapper/EachText.js.map +1 -0
  96. package/lib/wrapper/EachTrendLine.d.ts +85 -0
  97. package/lib/wrapper/EachTrendLine.js +165 -0
  98. package/lib/wrapper/EachTrendLine.js.map +1 -0
  99. package/lib/wrapper/index.d.ts +7 -0
  100. package/lib/wrapper/index.js +8 -0
  101. package/lib/wrapper/index.js.map +1 -0
  102. package/package.json +53 -0
  103. package/src/Brush.tsx +172 -0
  104. package/src/ClickCallback.tsx +37 -0
  105. package/src/DrawingObjectSelector.tsx +97 -0
  106. package/src/EquidistantChannel.tsx +268 -0
  107. package/src/FibonacciRetracement.tsx +328 -0
  108. package/src/GannFan.tsx +233 -0
  109. package/src/InteractiveText.tsx +182 -0
  110. package/src/InteractiveYCoordinate.tsx +199 -0
  111. package/src/StandardDeviationChannel.tsx +269 -0
  112. package/src/TrendLine.tsx +294 -0
  113. package/src/ZoomButtons.tsx +165 -0
  114. package/src/components/ChannelWithArea.tsx +199 -0
  115. package/src/components/ClickableCircle.tsx +91 -0
  116. package/src/components/ClickableShape.tsx +114 -0
  117. package/src/components/GannFan.tsx +189 -0
  118. package/src/components/HoverTextNearMouse.tsx +174 -0
  119. package/src/components/InteractiveStraightLine.tsx +335 -0
  120. package/src/components/InteractiveText.tsx +146 -0
  121. package/src/components/InteractiveYCoordinate.tsx +200 -0
  122. package/src/components/LinearRegressionChannelWithArea.tsx +169 -0
  123. package/src/components/MouseLocationIndicator.tsx +128 -0
  124. package/src/components/Text.tsx +47 -0
  125. package/src/components/index.ts +11 -0
  126. package/src/index.ts +12 -0
  127. package/src/utils.ts +101 -0
  128. package/src/wrapper/EachEquidistantChannel.tsx +302 -0
  129. package/src/wrapper/EachFibRetracement.tsx +359 -0
  130. package/src/wrapper/EachGannFan.tsx +289 -0
  131. package/src/wrapper/EachInteractiveYCoordinate.tsx +198 -0
  132. package/src/wrapper/EachLinearRegressionChannel.tsx +202 -0
  133. package/src/wrapper/EachText.tsx +190 -0
  134. package/src/wrapper/EachTrendLine.tsx +331 -0
  135. package/src/wrapper/index.ts +7 -0
@@ -0,0 +1,83 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import * as React from "react";
13
+ import { getXValue } from "@tradingaction/core/lib/utils/ChartDataUtil";
14
+ import { isHover, saveNodeType } from "../utils";
15
+ import { HoverTextNearMouse, InteractiveText } from "../components";
16
+ export class EachText extends React.Component {
17
+ constructor(props) {
18
+ super(props);
19
+ this.handleHover = (_, moreProps) => {
20
+ if (this.state.hover !== moreProps.hovering) {
21
+ this.setState({
22
+ hover: moreProps.hovering,
23
+ });
24
+ }
25
+ };
26
+ this.handleDrag = (e, moreProps) => {
27
+ const { index, onDrag } = this.props;
28
+ if (onDrag === undefined) {
29
+ return;
30
+ }
31
+ const { mouseXY: [, mouseY], chartConfig: { yScale }, xAccessor, mouseXY, plotData, xScale, } = moreProps;
32
+ const { dx, dy } = this.dragStartPosition;
33
+ const xValue = xScale.invert(xScale(getXValue(xScale, xAccessor, mouseXY, plotData)) - dx);
34
+ // xScale.invert(xScale(xAccessor(currentItem)) - dx);
35
+ const xyValue = [xValue, yScale.invert(mouseY - dy)];
36
+ onDrag(e, index, xyValue);
37
+ };
38
+ this.handleDragStart = (_, moreProps) => {
39
+ const { position } = this.props;
40
+ const { mouseXY } = moreProps;
41
+ const { chartConfig: { yScale }, xScale, } = moreProps;
42
+ const [mouseX, mouseY] = mouseXY;
43
+ const [textCX, textCY] = position;
44
+ const dx = mouseX - xScale(textCX);
45
+ const dy = mouseY - yScale(textCY);
46
+ this.dragStartPosition = {
47
+ position,
48
+ dx,
49
+ dy,
50
+ };
51
+ };
52
+ this.handleHover = this.handleHover.bind(this);
53
+ this.handleDragStart = this.handleDragStart.bind(this);
54
+ this.handleDrag = this.handleDrag.bind(this);
55
+ this.isHover = isHover.bind(this);
56
+ this.saveNodeType = saveNodeType.bind(this);
57
+ this.state = {
58
+ hover: false,
59
+ };
60
+ }
61
+ render() {
62
+ const { position, bgFill, bgStroke, bgStrokeWidth, textFill, fontFamily, fontSize, fontWeight, fontStyle, text, hoverText, selected, onDragComplete, onDoubleClick, } = this.props;
63
+ const { hover } = this.state;
64
+ const hoverHandler = {
65
+ onHover: this.handleHover,
66
+ onUnHover: this.handleHover,
67
+ };
68
+ const { enable: hoverTextEnabled, selectedText: hoverTextSelected, text: hoverTextUnselected } = hoverText, restHoverTextProps = __rest(hoverText, ["enable", "selectedText", "text"]);
69
+ return (React.createElement("g", null,
70
+ React.createElement(InteractiveText, Object.assign({ ref: this.saveNodeType("text"), selected: selected || hover, interactiveCursorClass: "react-financial-charts-move-cursor" }, hoverHandler, { onDragStart: this.handleDragStart, onDrag: this.handleDrag, onDragComplete: onDragComplete, onDoubleClick: (e, moreProps) => {
71
+ if (onDoubleClick) {
72
+ onDoubleClick(e, moreProps, this.props.index);
73
+ }
74
+ }, position: position, bgFillStyle: bgFill, bgStroke: bgStroke || textFill, bgStrokeWidth: bgStrokeWidth, textFill: textFill, fontFamily: fontFamily, fontStyle: fontStyle, fontWeight: fontWeight, fontSize: fontSize, text: text })),
75
+ React.createElement(HoverTextNearMouse, Object.assign({ show: hoverTextEnabled && hover }, restHoverTextProps, { text: selected ? hoverTextSelected : hoverTextUnselected }))));
76
+ }
77
+ }
78
+ EachText.defaultProps = {
79
+ bgStrokeWidth: 1,
80
+ selected: false,
81
+ hoverText: Object.assign(Object.assign({}, HoverTextNearMouse.defaultProps), { enable: true, bgHeight: "auto", bgWidth: "auto", text: "Click to select object" }),
82
+ };
83
+ //# sourceMappingURL=EachText.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EachText.js","sourceRoot":"","sources":["../../src/wrapper/EachText.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,6CAA6C,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAoCpE,MAAM,OAAO,QAAS,SAAQ,KAAK,CAAC,SAAuC;IAkBvE,YAAmB,KAAoB;QACnC,KAAK,CAAC,KAAK,CAAC,CAAC;QAiFA,gBAAW,GAAG,CAAC,CAAmB,EAAE,SAAc,EAAE,EAAE;YACnE,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,QAAQ,EAAE;gBACzC,IAAI,CAAC,QAAQ,CAAC;oBACV,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value: any;
5
+ readonly x2Value: any;
6
+ readonly y1Value: any;
7
+ readonly y2Value: any;
8
+ readonly index?: number;
9
+ readonly type: "XLINE" | "RAY" | "LINE";
10
+ readonly onDrag: (e: React.MouseEvent, index: number | undefined, moreProps: any) => void;
11
+ readonly onEdge1Drag: any;
12
+ readonly onEdge2Drag: any;
13
+ readonly onDragComplete?: (e: React.MouseEvent, moreProps: any) => void;
14
+ readonly onSelect: (e: React.MouseEvent, interactives: any[], moreProps: any) => void;
15
+ readonly onDoubleClickWhenHover?: (e: React.MouseEvent, moreProps: any, index: any) => void;
16
+ readonly onClickWhenHover?: (e: React.MouseEvent, moreProps: any, index: any) => void;
17
+ readonly onClickOutside?: (e: React.MouseEvent, moreProps: any, index: any) => void;
18
+ readonly onContextMenuWhenHover?: (e: React.MouseEvent, moreProps: any, index: any) => void;
19
+ readonly?: (e: React.MouseEvent, moreProps: any, index: any) => void;
20
+ readonly r: number;
21
+ readonly strokeOpacity: number;
22
+ readonly defaultClassName?: string;
23
+ readonly selected?: boolean;
24
+ readonly strokeStyle: string;
25
+ readonly strokeWidth: number;
26
+ readonly strokeDasharray: strokeDashTypes;
27
+ readonly edgeStrokeWidth: number;
28
+ readonly edgeStroke: string;
29
+ readonly edgeInteractiveCursor: string;
30
+ readonly lineInteractiveCursor: string;
31
+ readonly edgeFill: string;
32
+ readonly hoverText: {
33
+ readonly enable: boolean;
34
+ readonly fontFamily: string;
35
+ readonly fontSize: number;
36
+ readonly fill: string;
37
+ readonly text: string;
38
+ readonly selectedText: string;
39
+ readonly bgFill: string;
40
+ readonly bgOpacity: number;
41
+ readonly bgWidth: number | string;
42
+ readonly bgHeight: number | string;
43
+ };
44
+ }
45
+ interface EachTrendLineState {
46
+ anchor?: string;
47
+ hover?: any;
48
+ }
49
+ export declare class EachTrendLine extends React.Component<EachTrendLineProps, EachTrendLineState> {
50
+ static defaultProps: {
51
+ onDrag: () => void;
52
+ onEdge1Drag: () => void;
53
+ onEdge2Drag: () => void;
54
+ onSelect: () => void;
55
+ selected: boolean;
56
+ edgeStroke: string;
57
+ edgeFill: string;
58
+ edgeStrokeWidth: number;
59
+ r: number;
60
+ strokeWidth: number;
61
+ strokeDasharray: string;
62
+ hoverText: {
63
+ enable: boolean;
64
+ };
65
+ };
66
+ private dragStart;
67
+ private isHover;
68
+ private saveNodeType;
69
+ constructor(props: EachTrendLineProps);
70
+ render(): JSX.Element;
71
+ private readonly handleHover;
72
+ private readonly handleEdge2Drag;
73
+ private readonly handleDoubleClickWhenHover;
74
+ private readonly handleClickWhenHover;
75
+ private readonly handleClickOutside;
76
+ private readonly handleContextMenuWhenHover;
77
+ private readonly handleEdge1Drag;
78
+ private readonly handleDragComplete;
79
+ private readonly handleEdge2DragStart;
80
+ private readonly handleEdge1DragStart;
81
+ private readonly handleLineDrag;
82
+ private readonly handleLineDragStart;
83
+ }
84
+ export declare function getNewXY(moreProps: any): any[];
85
+ export {};
@@ -0,0 +1,165 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import * as React from "react";
13
+ import { ascending as d3Ascending } from "d3-array";
14
+ import { noop } from "@tradingaction/core";
15
+ import { getXValue } from "@tradingaction/core/lib/utils/ChartDataUtil";
16
+ import { isHover, saveNodeType } from "../utils";
17
+ import { ClickableCircle, HoverTextNearMouse, InteractiveStraightLine } from "../components";
18
+ export class EachTrendLine extends React.Component {
19
+ constructor(props) {
20
+ super(props);
21
+ this.handleHover = (_, moreProps) => {
22
+ if (this.state.hover !== moreProps.hovering) {
23
+ this.setState({
24
+ hover: moreProps.hovering,
25
+ });
26
+ }
27
+ };
28
+ this.handleEdge2Drag = (e, moreProps) => {
29
+ const { index, onDrag, x1Value, y1Value } = this.props;
30
+ const [x2Value, y2Value] = getNewXY(moreProps);
31
+ onDrag(e, index, {
32
+ x1Value,
33
+ y1Value,
34
+ x2Value,
35
+ y2Value,
36
+ });
37
+ };
38
+ this.handleDoubleClickWhenHover = (e, moreProps) => {
39
+ if (this.props.onDoubleClickWhenHover) {
40
+ const { index, onDoubleClickWhenHover } = this.props;
41
+ onDoubleClickWhenHover(e, moreProps, index);
42
+ }
43
+ };
44
+ this.handleClickWhenHover = (e, moreProps) => {
45
+ if (this.props.onClickWhenHover) {
46
+ const { index, onClickWhenHover } = this.props;
47
+ onClickWhenHover(e, moreProps, index);
48
+ }
49
+ };
50
+ this.handleClickOutside = (e, moreProps) => {
51
+ if (this.props.onClickOutside) {
52
+ const { index, onClickOutside } = this.props;
53
+ onClickOutside(e, moreProps, index);
54
+ }
55
+ };
56
+ this.handleContextMenuWhenHover = (e, moreProps) => {
57
+ if (this.props.onContextMenuWhenHover) {
58
+ const { index, onContextMenuWhenHover } = this.props;
59
+ onContextMenuWhenHover(e, moreProps, index);
60
+ }
61
+ };
62
+ this.handleEdge1Drag = (e, moreProps) => {
63
+ const { index, onDrag, x2Value, y2Value } = this.props;
64
+ const [x1Value, y1Value] = getNewXY(moreProps);
65
+ onDrag(e, index, {
66
+ x1Value,
67
+ y1Value,
68
+ x2Value,
69
+ y2Value,
70
+ });
71
+ };
72
+ this.handleDragComplete = (e, moreProps) => {
73
+ this.setState({
74
+ anchor: undefined,
75
+ });
76
+ const { onDragComplete } = this.props;
77
+ if (onDragComplete === undefined) {
78
+ return;
79
+ }
80
+ onDragComplete(e, moreProps);
81
+ };
82
+ this.handleEdge2DragStart = () => {
83
+ this.setState({
84
+ anchor: "edge1",
85
+ });
86
+ };
87
+ this.handleEdge1DragStart = () => {
88
+ this.setState({
89
+ anchor: "edge2",
90
+ });
91
+ };
92
+ this.handleLineDrag = (e, moreProps) => {
93
+ const { index, onDrag } = this.props;
94
+ const { x1Value, y1Value, x2Value, y2Value } = this.dragStart;
95
+ const { xScale, chartConfig: { yScale }, xAccessor, fullData, } = moreProps;
96
+ const { startPos, mouseXY } = moreProps;
97
+ const x1 = xScale(x1Value);
98
+ const y1 = yScale(y1Value);
99
+ const x2 = xScale(x2Value);
100
+ const y2 = yScale(y2Value);
101
+ const dx = startPos[0] - mouseXY[0];
102
+ const dy = startPos[1] - mouseXY[1];
103
+ const newX1Value = getXValue(xScale, xAccessor, [x1 - dx, y1 - dy], fullData);
104
+ const newY1Value = yScale.invert(y1 - dy);
105
+ const newX2Value = getXValue(xScale, xAccessor, [x2 - dx, y2 - dy], fullData);
106
+ const newY2Value = yScale.invert(y2 - dy);
107
+ onDrag(e, index, {
108
+ x1Value: newX1Value,
109
+ y1Value: newY1Value,
110
+ x2Value: newX2Value,
111
+ y2Value: newY2Value,
112
+ });
113
+ };
114
+ this.handleLineDragStart = () => {
115
+ const { x1Value, y1Value, x2Value, y2Value } = this.props;
116
+ this.dragStart = {
117
+ x1Value,
118
+ y1Value,
119
+ x2Value,
120
+ y2Value,
121
+ };
122
+ };
123
+ this.isHover = isHover.bind(this);
124
+ this.saveNodeType = saveNodeType.bind(this);
125
+ this.state = {
126
+ hover: false,
127
+ };
128
+ }
129
+ render() {
130
+ const { x1Value, y1Value, x2Value, y2Value, type, strokeStyle, strokeWidth, strokeDasharray, r, edgeStrokeWidth, edgeFill, edgeStroke, edgeInteractiveCursor, lineInteractiveCursor, hoverText, selected, onDragComplete, } = this.props;
131
+ const { enable: hoverTextEnabled, selectedText: hoverTextSelected, text: hoverTextUnselected } = hoverText, restHoverTextProps = __rest(hoverText, ["enable", "selectedText", "text"]);
132
+ const { hover, anchor } = this.state;
133
+ return (React.createElement("g", null,
134
+ React.createElement(InteractiveStraightLine, { ref: this.saveNodeType("line"), selected: selected || hover, onHover: this.handleHover, onUnHover: this.handleHover, x1Value: x1Value, y1Value: y1Value, x2Value: x2Value, y2Value: y2Value, type: type, strokeStyle: strokeStyle, strokeWidth: hover || selected ? strokeWidth + 1 : strokeWidth, strokeDasharray: strokeDasharray, interactiveCursorClass: lineInteractiveCursor, onDragStart: this.handleLineDragStart, onDrag: this.handleLineDrag, onDragComplete: onDragComplete, onDoubleClickWhenHover: this.handleDoubleClickWhenHover, onClickWhenHover: this.handleClickWhenHover, onClickOutside: this.handleClickOutside, onContextMenuWhenHover: this.handleContextMenuWhenHover }),
135
+ React.createElement(ClickableCircle, { ref: this.saveNodeType("edge1"), show: selected || hover, cx: x1Value, cy: y1Value, r: r, fillStyle: edgeFill, strokeStyle: anchor === "edge1" ? strokeStyle : edgeStroke, strokeWidth: edgeStrokeWidth, interactiveCursorClass: edgeInteractiveCursor, onDragStart: this.handleEdge1DragStart, onDrag: this.handleEdge1Drag, onDragComplete: this.handleDragComplete }),
136
+ React.createElement(ClickableCircle, { ref: this.saveNodeType("edge2"), show: selected || hover, cx: x2Value, cy: y2Value, r: r, fillStyle: edgeFill, strokeStyle: anchor === "edge2" ? strokeStyle : edgeStroke, strokeWidth: edgeStrokeWidth, interactiveCursorClass: edgeInteractiveCursor, onDragStart: this.handleEdge2DragStart, onDrag: this.handleEdge2Drag, onDragComplete: this.handleDragComplete }),
137
+ React.createElement(HoverTextNearMouse, Object.assign({ show: hoverTextEnabled && hover }, restHoverTextProps, { text: selected ? hoverTextSelected : hoverTextUnselected }))));
138
+ }
139
+ }
140
+ EachTrendLine.defaultProps = {
141
+ onDrag: noop,
142
+ onEdge1Drag: noop,
143
+ onEdge2Drag: noop,
144
+ onSelect: noop,
145
+ selected: false,
146
+ edgeStroke: "#000000",
147
+ edgeFill: "#FFFFFF",
148
+ edgeStrokeWidth: 2,
149
+ r: 5,
150
+ strokeWidth: 1,
151
+ strokeDasharray: "Solid",
152
+ hoverText: {
153
+ enable: false,
154
+ },
155
+ };
156
+ export function getNewXY(moreProps) {
157
+ const { xScale, chartConfig: { yScale }, xAccessor, plotData, mouseXY, } = moreProps;
158
+ const mouseY = mouseXY[1];
159
+ const x = getXValue(xScale, xAccessor, mouseXY, plotData);
160
+ const [small, big] = yScale.domain().slice().sort(d3Ascending);
161
+ const y = yScale.invert(mouseY);
162
+ const newY = Math.min(Math.max(y, small), big);
163
+ return [x, newY];
164
+ }
165
+ //# sourceMappingURL=EachTrendLine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EachTrendLine.js","sourceRoot":"","sources":["../../src/wrapper/EachTrendLine.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,SAAS,IAAI,WAAW,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,IAAI,EAAmB,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,6CAA6C,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAqD7F,MAAM,OAAO,aAAc,SAAQ,KAAK,CAAC,SAAiD;IAuBtF,YAAmB,KAAyB;QACxC,KAAK,CAAC,KAAK,CAAC,CAAC;QAqGA,gBAAW,GAAG,CAAC,CAAmB,EAAE,SAAc,EAAE,EAAE;YACnE,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,QAAQ,EAAE;gBACzC,IAAI,CAAC,QAAQ,CAAC;oBACV,KAAK,EAAE,SAAS,CAAC,QAAQ;iBAC5B,CAAC,CAAC;aACN;QACL,CAAC,CAAC;QAEe,oBAAe,GAAG,CAAC,CAAmB,EAAE,SAAc,EAAE,EAAE;YACvE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;YAEvD,MAAM,CAAC,OAAO,EAAE,O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E,IAAI,CAAC,CAAC;AACrB,CAAC"}
@@ -0,0 +1,7 @@
1
+ export { EachEquidistantChannel } from "./EachEquidistantChannel";
2
+ export { EachFibRetracement } from "./EachFibRetracement";
3
+ export { EachGannFan } from "./EachGannFan";
4
+ export { EachInteractiveYCoordinate } from "./EachInteractiveYCoordinate";
5
+ export { EachLinearRegressionChannel } from "./EachLinearRegressionChannel";
6
+ export { EachText } from "./EachText";
7
+ export { EachTrendLine } from "./EachTrendLine";
@@ -0,0 +1,8 @@
1
+ export { EachEquidistantChannel } from "./EachEquidistantChannel";
2
+ export { EachFibRetracement } from "./EachFibRetracement";
3
+ export { EachGannFan } from "./EachGannFan";
4
+ export { EachInteractiveYCoordinate } from "./EachInteractiveYCoordinate";
5
+ export { EachLinearRegressionChannel } from "./EachLinearRegressionChannel";
6
+ export { EachText } from "./EachText";
7
+ export { EachTrendLine } from "./EachTrendLine";
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/wrapper/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@tradingaction/interactive",
3
+ "version": "2.0.13",
4
+ "description": "Interactive features 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/coordinates": "^2.0.13",
42
+ "@tradingaction/core": "^2.0.13",
43
+ "d3-array": "^2.9.1",
44
+ "d3-format": "^2.0.0",
45
+ "d3-interpolate": "^2.0.1",
46
+ "d3-path": "^2.0.0"
47
+ },
48
+ "peerDependencies": {
49
+ "react": "^16.0.0 || ^17.0.0 || ^18.0.0",
50
+ "react-dom": "^16.0.0 || ^17.0.0 || ^18.0.0"
51
+ },
52
+ "gitHead": "9c9bc635a2291c8da0e1dd5befa4000e96d83119"
53
+ }
package/src/Brush.tsx ADDED
@@ -0,0 +1,172 @@
1
+ import * as React from "react";
2
+ import { getStrokeDasharrayCanvas, getMouseCanvas, GenericChartComponent, strokeDashTypes } from "@tradingaction/core";
3
+
4
+ interface BrushProps {
5
+ readonly enabled: boolean;
6
+ readonly onBrush: ({ start, end }: any, moreProps: any) => void;
7
+ readonly type?: "1D" | "2D";
8
+ readonly strokeStyle?: string;
9
+ readonly fillStyle?: string;
10
+ readonly interactiveState: object;
11
+ readonly strokeDashArray?: strokeDashTypes;
12
+ }
13
+
14
+ interface BrushState {
15
+ end?: any;
16
+ rect: any | null;
17
+ selected?: boolean;
18
+ start?: any;
19
+ x1y1?: any;
20
+ }
21
+
22
+ export class Brush extends React.Component<BrushProps, BrushState> {
23
+ public static defaultProps = {
24
+ type: "2D",
25
+ strokeStyle: "#000000",
26
+ fillStyle: "#3h3h3h",
27
+ strokeDashArray: "ShortDash",
28
+ };
29
+
30
+ private zoomHappening?: boolean;
31
+
32
+ public constructor(props: BrushProps) {
33
+ super(props);
34
+
35
+ this.terminate = this.terminate.bind(this);
36
+ this.state = {
37
+ rect: null,
38
+ };
39
+ }
40
+
41
+ public terminate() {
42
+ this.zoomHappening = false;
43
+ this.setState({
44
+ x1y1: null,
45
+ start: null,
46
+ end: null,
47
+ rect: null,
48
+ });
49
+ }
50
+
51
+ public render() {
52
+ const { enabled } = this.props;
53
+ if (!enabled) {
54
+ return null;
55
+ }
56
+
57
+ return (
58
+ <GenericChartComponent
59
+ disablePan={enabled}
60
+ canvasToDraw={getMouseCanvas}
61
+ canvasDraw={this.drawOnCanvas}
62
+ onMouseDown={this.handleZoomStart}
63
+ onMouseMove={this.handleDrawSquare}
64
+ onClick={this.handleZoomComplete}
65
+ drawOn={["mousemove", "pan", "drag"]}
66
+ />
67
+ );
68
+ }
69
+
70
+ private readonly drawOnCanvas = (ctx: CanvasRenderingContext2D) => {
71
+ const { rect } = this.state;
72
+ if (rect === null) {
73
+ return;
74
+ }
75
+
76
+ const { x, y, height, width } = rect;
77
+ const {
78
+ strokeStyle = Brush.defaultProps.strokeStyle,
79
+ fillStyle = Brush.defaultProps.fillStyle,
80
+ strokeDashArray,
81
+ } = this.props;
82
+
83
+ const dashArray = getStrokeDasharrayCanvas(strokeDashArray);
84
+
85
+ ctx.strokeStyle = strokeStyle;
86
+ ctx.fillStyle = fillStyle;
87
+ ctx.setLineDash(dashArray);
88
+ ctx.beginPath();
89
+ ctx.fillRect(x, y, width, height);
90
+ ctx.strokeRect(x, y, width, height);
91
+ };
92
+
93
+ private readonly handleZoomStart = (_: React.MouseEvent, moreProps: any) => {
94
+ this.zoomHappening = false;
95
+ const {
96
+ mouseXY: [, mouseY],
97
+ currentItem,
98
+ chartConfig: { yScale },
99
+ xAccessor,
100
+ xScale,
101
+ } = moreProps;
102
+
103
+ const x1y1 = [xScale(xAccessor(currentItem)), mouseY];
104
+
105
+ this.setState({
106
+ selected: true,
107
+ x1y1,
108
+ start: {
109
+ item: currentItem,
110
+ xValue: xAccessor(currentItem),
111
+ yValue: yScale.invert(mouseY),
112
+ },
113
+ });
114
+ };
115
+
116
+ private readonly handleDrawSquare = (_: React.MouseEvent, moreProps: any) => {
117
+ if (this.state.x1y1 == null) {
118
+ return;
119
+ }
120
+
121
+ this.zoomHappening = true;
122
+
123
+ const {
124
+ mouseXY: [, mouseY],
125
+ currentItem,
126
+ chartConfig: { yScale },
127
+ xAccessor,
128
+ xScale,
129
+ } = moreProps;
130
+
131
+ const [x2, y2] = [xScale(xAccessor(currentItem)), mouseY];
132
+
133
+ const {
134
+ x1y1: [x1, y1],
135
+ } = this.state;
136
+
137
+ const x = Math.min(x1, x2);
138
+ const y = Math.min(y1, y2);
139
+ const height = Math.abs(y2 - y1);
140
+ const width = Math.abs(x2 - x1);
141
+
142
+ this.setState({
143
+ selected: true,
144
+ end: {
145
+ item: currentItem,
146
+ xValue: xAccessor(currentItem),
147
+ yValue: yScale.invert(mouseY),
148
+ },
149
+ rect: {
150
+ x,
151
+ y,
152
+ height,
153
+ width,
154
+ },
155
+ });
156
+ };
157
+
158
+ private readonly handleZoomComplete = (_: React.MouseEvent, moreProps: any) => {
159
+ if (this.zoomHappening) {
160
+ const { onBrush } = this.props;
161
+ if (onBrush !== undefined) {
162
+ const { start, end } = this.state;
163
+ onBrush({ start, end }, moreProps);
164
+ }
165
+ }
166
+
167
+ this.setState({
168
+ selected: false,
169
+ rect: null,
170
+ });
171
+ };
172
+ }
@@ -0,0 +1,37 @@
1
+ import * as React from "react";
2
+ import { getMouseCanvas, GenericChartComponent } from "@tradingaction/core";
3
+
4
+ interface ClickCallbackProps {
5
+ readonly disablePan: boolean;
6
+ readonly onMouseDown?: (e: React.MouseEvent<Element, MouseEvent>, moreProps: any) => void;
7
+ readonly onClick?: (e: React.MouseEvent<Element, MouseEvent>, moreProps: any) => void;
8
+ readonly onDoubleClick?: (e: React.MouseEvent<Element, MouseEvent>, moreProps: any) => void;
9
+ readonly onContextMenu?: (e: React.MouseEvent<Element, MouseEvent>, moreProps: any) => void;
10
+ readonly onMouseMove?: (e: React.MouseEvent<Element, MouseEvent>, moreProps: any) => void;
11
+ readonly onPan?: (e: React.MouseEvent<Element, MouseEvent>, moreProps: any) => void;
12
+ readonly onPanEnd?: (e: React.MouseEvent<Element, MouseEvent>, moreProps: any) => void;
13
+ }
14
+
15
+ export class ClickCallback extends React.Component<ClickCallbackProps> {
16
+ public static defaultProps = {
17
+ disablePan: false,
18
+ };
19
+
20
+ public render() {
21
+ const { onMouseDown, onClick, onDoubleClick, onContextMenu, onMouseMove, onPan, onPanEnd } = this.props;
22
+
23
+ return (
24
+ <GenericChartComponent
25
+ onMouseDown={onMouseDown}
26
+ onClick={onClick}
27
+ onDoubleClick={onDoubleClick}
28
+ onContextMenu={onContextMenu}
29
+ onMouseMove={onMouseMove}
30
+ onPan={onPan}
31
+ onPanEnd={onPanEnd}
32
+ canvasToDraw={getMouseCanvas}
33
+ drawOn={["mousemove", "pan"]}
34
+ />
35
+ );
36
+ }
37
+ }