@ivanmatiaspascual/interactive 1.3.1-sp1-beta.0.1.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 (136) hide show
  1. package/CHANGELOG.md +190 -0
  2. package/LICENSE +24 -0
  3. package/README.md +5 -0
  4. package/lib/Brush.d.ts +35 -0
  5. package/lib/Brush.js +103 -0
  6. package/lib/Brush.js.map +1 -0
  7. package/lib/ClickCallback.d.ts +18 -0
  8. package/lib/ClickCallback.js +12 -0
  9. package/lib/ClickCallback.js.map +1 -0
  10. package/lib/DrawingObjectSelector.d.ts +18 -0
  11. package/lib/DrawingObjectSelector.js +73 -0
  12. package/lib/DrawingObjectSelector.js.map +1 -0
  13. package/lib/EquidistantChannel.d.ts +74 -0
  14. package/lib/EquidistantChannel.js +149 -0
  15. package/lib/EquidistantChannel.js.map +1 -0
  16. package/lib/FibonacciRetracement.d.ts +83 -0
  17. package/lib/FibonacciRetracement.js +163 -0
  18. package/lib/FibonacciRetracement.js.map +1 -0
  19. package/lib/GannFan.d.ts +78 -0
  20. package/lib/GannFan.js +128 -0
  21. package/lib/GannFan.js.map +1 -0
  22. package/lib/InteractiveText.d.ts +70 -0
  23. package/lib/InteractiveText.js +89 -0
  24. package/lib/InteractiveText.js.map +1 -0
  25. package/lib/InteractiveYCoordinate.d.ts +128 -0
  26. package/lib/InteractiveYCoordinate.js +106 -0
  27. package/lib/InteractiveYCoordinate.js.map +1 -0
  28. package/lib/StandardDeviationChannel.d.ts +74 -0
  29. package/lib/StandardDeviationChannel.js +125 -0
  30. package/lib/StandardDeviationChannel.js.map +1 -0
  31. package/lib/TrendLine.d.ts +77 -0
  32. package/lib/TrendLine.js +125 -0
  33. package/lib/TrendLine.js.map +1 -0
  34. package/lib/ZoomButtons.d.ts +37 -0
  35. package/lib/ZoomButtons.js +85 -0
  36. package/lib/ZoomButtons.js.map +1 -0
  37. package/lib/components/ChannelWithArea.d.ts +30 -0
  38. package/lib/components/ChannelWithArea.js +126 -0
  39. package/lib/components/ChannelWithArea.js.map +1 -0
  40. package/lib/components/ClickableCircle.d.ts +26 -0
  41. package/lib/components/ClickableCircle.js +48 -0
  42. package/lib/components/ClickableCircle.js.map +1 -0
  43. package/lib/components/ClickableShape.d.ts +33 -0
  44. package/lib/components/ClickableShape.js +64 -0
  45. package/lib/components/ClickableShape.js.map +1 -0
  46. package/lib/components/GannFan.d.ts +32 -0
  47. package/lib/components/GannFan.js +134 -0
  48. package/lib/components/GannFan.js.map +1 -0
  49. package/lib/components/HoverTextNearMouse.d.ts +35 -0
  50. package/lib/components/HoverTextNearMouse.js +113 -0
  51. package/lib/components/HoverTextNearMouse.js.map +1 -0
  52. package/lib/components/InteractiveStraightLine.d.ts +57 -0
  53. package/lib/components/InteractiveStraightLine.js +220 -0
  54. package/lib/components/InteractiveStraightLine.js.map +1 -0
  55. package/lib/components/InteractiveText.d.ts +37 -0
  56. package/lib/components/InteractiveText.js +84 -0
  57. package/lib/components/InteractiveText.js.map +1 -0
  58. package/lib/components/InteractiveYCoordinate.d.ts +46 -0
  59. package/lib/components/InteractiveYCoordinate.js +109 -0
  60. package/lib/components/InteractiveYCoordinate.js.map +1 -0
  61. package/lib/components/LinearRegressionChannelWithArea.d.ts +31 -0
  62. package/lib/components/LinearRegressionChannelWithArea.js +104 -0
  63. package/lib/components/LinearRegressionChannelWithArea.js.map +1 -0
  64. package/lib/components/MouseLocationIndicator.d.ts +34 -0
  65. package/lib/components/MouseLocationIndicator.js +79 -0
  66. package/lib/components/MouseLocationIndicator.js.map +1 -0
  67. package/lib/components/Text.d.ts +17 -0
  68. package/lib/components/Text.js +26 -0
  69. package/lib/components/Text.js.map +1 -0
  70. package/lib/components/index.d.ts +11 -0
  71. package/lib/components/index.js +12 -0
  72. package/lib/components/index.js.map +1 -0
  73. package/lib/index.d.ts +12 -0
  74. package/lib/index.js +13 -0
  75. package/lib/index.js.map +1 -0
  76. package/lib/utils.d.ts +7 -0
  77. package/lib/utils.js +84 -0
  78. package/lib/utils.js.map +1 -0
  79. package/lib/wrapper/EachEquidistantChannel.d.ts +59 -0
  80. package/lib/wrapper/EachEquidistantChannel.js +172 -0
  81. package/lib/wrapper/EachEquidistantChannel.js.map +1 -0
  82. package/lib/wrapper/EachFibRetracement.d.ts +77 -0
  83. package/lib/wrapper/EachFibRetracement.js +197 -0
  84. package/lib/wrapper/EachFibRetracement.js.map +1 -0
  85. package/lib/wrapper/EachGannFan.d.ts +81 -0
  86. package/lib/wrapper/EachGannFan.js +161 -0
  87. package/lib/wrapper/EachGannFan.js.map +1 -0
  88. package/lib/wrapper/EachInteractiveYCoordinate.d.ts +50 -0
  89. package/lib/wrapper/EachInteractiveYCoordinate.js +80 -0
  90. package/lib/wrapper/EachInteractiveYCoordinate.js.map +1 -0
  91. package/lib/wrapper/EachLinearRegressionChannel.d.ts +75 -0
  92. package/lib/wrapper/EachLinearRegressionChannel.js +89 -0
  93. package/lib/wrapper/EachLinearRegressionChannel.js.map +1 -0
  94. package/lib/wrapper/EachText.d.ts +58 -0
  95. package/lib/wrapper/EachText.js +79 -0
  96. package/lib/wrapper/EachText.js.map +1 -0
  97. package/lib/wrapper/EachTrendLine.d.ts +76 -0
  98. package/lib/wrapper/EachTrendLine.js +141 -0
  99. package/lib/wrapper/EachTrendLine.js.map +1 -0
  100. package/lib/wrapper/index.d.ts +7 -0
  101. package/lib/wrapper/index.js +8 -0
  102. package/lib/wrapper/index.js.map +1 -0
  103. package/package.json +55 -0
  104. package/src/Brush.tsx +177 -0
  105. package/src/ClickCallback.tsx +37 -0
  106. package/src/DrawingObjectSelector.tsx +97 -0
  107. package/src/EquidistantChannel.tsx +268 -0
  108. package/src/FibonacciRetracement.tsx +298 -0
  109. package/src/GannFan.tsx +233 -0
  110. package/src/InteractiveText.tsx +185 -0
  111. package/src/InteractiveYCoordinate.tsx +205 -0
  112. package/src/StandardDeviationChannel.tsx +269 -0
  113. package/src/TrendLine.tsx +283 -0
  114. package/src/ZoomButtons.tsx +172 -0
  115. package/src/components/ChannelWithArea.tsx +199 -0
  116. package/src/components/ClickableCircle.tsx +91 -0
  117. package/src/components/ClickableShape.tsx +114 -0
  118. package/src/components/GannFan.tsx +189 -0
  119. package/src/components/HoverTextNearMouse.tsx +174 -0
  120. package/src/components/InteractiveStraightLine.tsx +317 -0
  121. package/src/components/InteractiveText.tsx +153 -0
  122. package/src/components/InteractiveYCoordinate.tsx +205 -0
  123. package/src/components/LinearRegressionChannelWithArea.tsx +169 -0
  124. package/src/components/MouseLocationIndicator.tsx +128 -0
  125. package/src/components/Text.tsx +47 -0
  126. package/src/components/index.ts +11 -0
  127. package/src/index.ts +12 -0
  128. package/src/utils.ts +101 -0
  129. package/src/wrapper/EachEquidistantChannel.tsx +302 -0
  130. package/src/wrapper/EachFibRetracement.tsx +342 -0
  131. package/src/wrapper/EachGannFan.tsx +289 -0
  132. package/src/wrapper/EachInteractiveYCoordinate.tsx +198 -0
  133. package/src/wrapper/EachLinearRegressionChannel.tsx +202 -0
  134. package/src/wrapper/EachText.tsx +183 -0
  135. package/src/wrapper/EachTrendLine.tsx +297 -0
  136. package/src/wrapper/index.ts +7 -0
@@ -0,0 +1,169 @@
1
+ import { deviation, sum, zip } from "d3-array";
2
+ import * as React from "react";
3
+ import { getClosestItemIndexes, getMouseCanvas, GenericChartComponent } from "@ivanmatiaspascual/core";
4
+ import { isHovering2 } from "./InteractiveStraightLine";
5
+
6
+ export interface LinearRegressionChannelWithAreaProps {
7
+ readonly x1Value: any;
8
+ readonly x2Value: any;
9
+ readonly type:
10
+ | "SD" // standard deviation channel
11
+ | "Raff"; // Raff Regression Channel
12
+ readonly interactiveCursorClass?: string;
13
+ readonly strokeStyle: string;
14
+ readonly strokeWidth: number;
15
+ readonly fillStyle: string;
16
+ readonly onDragStart?: (e: React.MouseEvent, moreProps: any) => void;
17
+ readonly onDrag?: (e: React.MouseEvent, moreProps: any) => void;
18
+ readonly onDragComplete?: (e: React.MouseEvent, moreProps: any) => void;
19
+ readonly onHover?: (e: React.MouseEvent, moreProps: any) => void;
20
+ readonly onUnHover?: (e: React.MouseEvent, moreProps: any) => void;
21
+ readonly defaultClassName?: string;
22
+ readonly tolerance: number;
23
+ readonly selected: boolean;
24
+ }
25
+
26
+ export class LinearRegressionChannelWithArea extends React.Component<LinearRegressionChannelWithAreaProps> {
27
+ public static defaultProps = {
28
+ type: "SD", // standard dev
29
+ strokeWidth: 1,
30
+ tolerance: 4,
31
+ selected: false,
32
+ };
33
+
34
+ public render() {
35
+ const { selected, interactiveCursorClass } = this.props;
36
+ const { onDragStart, onDrag, onDragComplete, onHover, onUnHover } = this.props;
37
+
38
+ return (
39
+ <GenericChartComponent
40
+ isHover={this.isHover}
41
+ canvasToDraw={getMouseCanvas}
42
+ canvasDraw={this.drawOnCanvas}
43
+ interactiveCursorClass={interactiveCursorClass}
44
+ selected={selected}
45
+ onDragStart={onDragStart}
46
+ onDrag={onDrag}
47
+ onDragComplete={onDragComplete}
48
+ onHover={onHover}
49
+ onUnHover={onUnHover}
50
+ drawOn={["mousemove", "mouseleave", "pan", "drag"]}
51
+ />
52
+ );
53
+ }
54
+
55
+ private readonly drawOnCanvas = (ctx: CanvasRenderingContext2D, moreProps: any) => {
56
+ const { strokeStyle, strokeWidth, fillStyle } = this.props;
57
+ const { x1, y1, x2, y2, dy } = helper(this.props, moreProps);
58
+
59
+ ctx.lineWidth = strokeWidth;
60
+ ctx.strokeStyle = strokeStyle;
61
+ ctx.fillStyle = fillStyle;
62
+
63
+ ctx.beginPath();
64
+ ctx.moveTo(x1, y1 - dy);
65
+ ctx.lineTo(x2, y2 - dy);
66
+ ctx.stroke();
67
+
68
+ ctx.beginPath();
69
+ ctx.moveTo(x2, y2 + dy);
70
+ ctx.lineTo(x1, y1 + dy);
71
+ ctx.stroke();
72
+
73
+ ctx.beginPath();
74
+ ctx.moveTo(x1, y1 - dy);
75
+ ctx.lineTo(x2, y2 - dy);
76
+ ctx.lineTo(x2, y2 + dy);
77
+ ctx.lineTo(x1, y1 + dy);
78
+ ctx.closePath();
79
+ ctx.fill();
80
+
81
+ ctx.beginPath();
82
+ ctx.moveTo(x2, y2);
83
+ ctx.lineTo(x1, y1);
84
+ ctx.stroke();
85
+ };
86
+
87
+ private readonly isHover = (moreProps: any) => {
88
+ const { tolerance, onHover } = this.props;
89
+
90
+ if (onHover !== undefined) {
91
+ const { mouseXY } = moreProps;
92
+
93
+ const { x1, y1, x2, y2, dy } = helper(this.props, moreProps);
94
+ const yDiffs = [-dy, 0, dy];
95
+
96
+ const hovering = yDiffs.reduce(
97
+ (result, diff) => result || isHovering2([x1, y1 + diff], [x2, y2 + diff], mouseXY, tolerance),
98
+ false,
99
+ );
100
+ return hovering;
101
+ }
102
+ return false;
103
+ };
104
+ }
105
+
106
+ export function edge1Provider(props: any) {
107
+ return function (moreProps: any) {
108
+ const { x1, y1 } = helper(props, moreProps);
109
+ return [x1, y1];
110
+ };
111
+ }
112
+
113
+ export function edge2Provider(props: any) {
114
+ return function (moreProps: any) {
115
+ const { x2, y2 } = helper(props, moreProps);
116
+ return [x2, y2];
117
+ };
118
+ }
119
+
120
+ function helper(props: any, moreProps: any) {
121
+ const { x1Value, x2Value, type } = props;
122
+
123
+ const {
124
+ xScale,
125
+ chartConfig: { yScale },
126
+ fullData,
127
+ } = moreProps;
128
+ const { xAccessor } = moreProps;
129
+
130
+ const { left } = getClosestItemIndexes(fullData, x1Value, xAccessor);
131
+ const { right } = getClosestItemIndexes(fullData, x2Value, xAccessor);
132
+
133
+ const startIndex = Math.min(left, right);
134
+ const endIndex = Math.max(left, right) + 1;
135
+
136
+ const array = fullData.slice(startIndex, endIndex);
137
+
138
+ const xs = array.map((d: any) => xAccessor(d).valueOf());
139
+ const ys = array.map((d: any) => d.close);
140
+ const n = array.length;
141
+
142
+ const xys = zip<number>(xs, ys).map((d) => {
143
+ return d[0] * d[1];
144
+ });
145
+ const xSquareds = xs.map((x: any) => Math.pow(x, 2));
146
+
147
+ const b = (n * sum(xys) - sum(xs) * sum(ys)) / (n * sum(xSquareds) - Math.pow(sum(xs), 2));
148
+ const a = (sum(ys) - b * sum(xs)) / n;
149
+
150
+ const newy1 = a + b * x1Value;
151
+ const newy2 = a + b * x2Value;
152
+
153
+ const x1 = xScale(x1Value);
154
+ const y1 = yScale(newy1);
155
+ const x2 = xScale(x2Value);
156
+ const y2 = yScale(newy2);
157
+
158
+ const stdDev = type === "SD" ? deviation<any>(array, (d) => d.close) : 0;
159
+
160
+ const dy = yScale(newy1 - stdDev!) - y1;
161
+
162
+ return {
163
+ x1,
164
+ y1,
165
+ x2,
166
+ y2,
167
+ dy,
168
+ };
169
+ }
@@ -0,0 +1,128 @@
1
+ import {
2
+ functor,
3
+ getClosestValue,
4
+ getMouseCanvas,
5
+ GenericChartComponent,
6
+ isDefined,
7
+ noop,
8
+ shallowEqual,
9
+ } from "@ivanmatiaspascual/core";
10
+ import * as React from "react";
11
+ import { getXValue } from "@ivanmatiaspascual/core/lib/utils/ChartDataUtil";
12
+
13
+ export interface MouseLocationIndicatorProps {
14
+ readonly enabled: boolean;
15
+ readonly snap: boolean;
16
+ readonly shouldDisableSnap: (e: React.MouseEvent) => boolean;
17
+ readonly snapTo?: (datum: any) => number | number[];
18
+ readonly onMouseMove: (e: React.MouseEvent, xyValue: number[], moreProps: any) => void;
19
+ readonly onMouseDown: (e: React.MouseEvent, xyValue: number[], moreProps: any) => void;
20
+ readonly onClick: (e: React.MouseEvent, xyValue: number[], moreProps: any) => void;
21
+ readonly r: number;
22
+ readonly stroke: string;
23
+ readonly strokeWidth: number;
24
+ readonly opacity: number;
25
+ readonly disablePan: boolean;
26
+ }
27
+
28
+ export class MouseLocationIndicator extends React.Component<MouseLocationIndicatorProps> {
29
+ public static defaultProps = {
30
+ onMouseMove: noop,
31
+ onMouseDown: noop,
32
+ onClick: noop,
33
+ shouldDisableSnap: functor(false),
34
+ stroke: "#000000",
35
+ strokeWidth: 1,
36
+ opacity: 1,
37
+ disablePan: true,
38
+ };
39
+
40
+ private mutableState: any = {};
41
+
42
+ public render() {
43
+ const { enabled, disablePan } = this.props;
44
+
45
+ return (
46
+ <GenericChartComponent
47
+ onMouseDown={this.handleMouseDown}
48
+ onClick={this.handleClick}
49
+ onMouseMove={this.handleMousePosChange}
50
+ onPan={this.handleMousePosChange}
51
+ disablePan={enabled && disablePan}
52
+ canvasDraw={this.drawOnCanvas}
53
+ canvasToDraw={getMouseCanvas}
54
+ drawOn={["mousemove", "pan"]}
55
+ />
56
+ );
57
+ }
58
+
59
+ private readonly xy = (e: React.MouseEvent, moreProps: any) => {
60
+ const { xAccessor, plotData } = moreProps;
61
+ const {
62
+ mouseXY,
63
+ currentItem,
64
+ xScale,
65
+ chartConfig: { yScale },
66
+ } = moreProps;
67
+ const { enabled, snap, shouldDisableSnap, snapTo } = this.props;
68
+
69
+ if (enabled && isDefined(currentItem) && isDefined(e)) {
70
+ const xValue =
71
+ snap && !shouldDisableSnap(e)
72
+ ? xAccessor(currentItem)
73
+ : getXValue(xScale, xAccessor, mouseXY, plotData);
74
+ const yValue =
75
+ snap && snapTo !== undefined && !shouldDisableSnap(e)
76
+ ? getClosestValue(snapTo(currentItem), yScale.invert(mouseXY[1]))
77
+ : yScale.invert(mouseXY[1]);
78
+
79
+ const x = xScale(xValue);
80
+ const y = yScale(yValue);
81
+
82
+ return { xValue, yValue, x, y };
83
+ }
84
+ };
85
+
86
+ private readonly handleClick = (e: React.MouseEvent, moreProps: any) => {
87
+ const pos = this.xy(e, moreProps);
88
+ if (pos !== undefined && isDefined(pos)) {
89
+ const { xValue, yValue, x, y } = pos;
90
+ this.mutableState = { x, y };
91
+ this.props.onClick(e, [xValue, yValue], moreProps);
92
+ }
93
+ };
94
+
95
+ private readonly handleMouseDown = (e: React.MouseEvent, moreProps: any) => {
96
+ const pos = this.xy(e, moreProps);
97
+ if (pos !== undefined && isDefined(pos)) {
98
+ const { xValue, yValue, x, y } = pos;
99
+ this.mutableState = { x, y };
100
+ this.props.onMouseDown(e, [xValue, yValue], moreProps);
101
+ }
102
+ };
103
+
104
+ private readonly handleMousePosChange = (e: React.MouseEvent, moreProps: any) => {
105
+ if (!shallowEqual(moreProps.mousXY, moreProps.prevMouseXY)) {
106
+ const pos = this.xy(e, moreProps);
107
+ if (pos !== undefined && isDefined(pos)) {
108
+ const { xValue, yValue, x, y } = pos;
109
+ this.mutableState = { x, y };
110
+ this.props.onMouseMove(e, [xValue, yValue], moreProps);
111
+ }
112
+ }
113
+ };
114
+
115
+ private readonly drawOnCanvas = (ctx: CanvasRenderingContext2D, moreProps: any) => {
116
+ const { enabled, r, stroke, strokeWidth } = this.props;
117
+ const { x, y } = this.mutableState;
118
+ const { show } = moreProps;
119
+ if (enabled && show && isDefined(x)) {
120
+ ctx.lineWidth = strokeWidth;
121
+ ctx.strokeStyle = stroke;
122
+ ctx.moveTo(x, y);
123
+ ctx.beginPath();
124
+ ctx.arc(x, y, r, 0, 2 * Math.PI, false);
125
+ ctx.stroke();
126
+ }
127
+ };
128
+ }
@@ -0,0 +1,47 @@
1
+ import * as React from "react";
2
+ import { getMouseCanvas, GenericChartComponent } from "@ivanmatiaspascual/core";
3
+
4
+ export interface TextProps {
5
+ readonly children: string;
6
+ readonly fontFamily: string;
7
+ readonly fontSize: number;
8
+ readonly fillStyle: string;
9
+ readonly selected?: boolean;
10
+ readonly xyProvider: (moreProps: any) => number[];
11
+ }
12
+
13
+ export class Text extends React.Component<TextProps> {
14
+ public static defaultProps = {
15
+ selected: false,
16
+ };
17
+
18
+ public render() {
19
+ const { selected } = this.props;
20
+
21
+ return (
22
+ <GenericChartComponent
23
+ isHover={this.isHover}
24
+ selected={selected}
25
+ canvasToDraw={getMouseCanvas}
26
+ canvasDraw={this.drawOnCanvas}
27
+ drawOn={["mousemove", "pan", "drag"]}
28
+ />
29
+ );
30
+ }
31
+
32
+ private readonly isHover = () => {
33
+ return false;
34
+ };
35
+
36
+ private readonly drawOnCanvas = (ctx: CanvasRenderingContext2D, moreProps: any) => {
37
+ const { xyProvider, fontFamily, fontSize, fillStyle, children } = this.props;
38
+
39
+ const [x, y] = xyProvider(moreProps);
40
+
41
+ ctx.font = `${fontSize}px ${fontFamily}`;
42
+ ctx.fillStyle = fillStyle;
43
+
44
+ ctx.beginPath();
45
+ ctx.fillText(children, x, y);
46
+ };
47
+ }
@@ -0,0 +1,11 @@
1
+ export * from "./ChannelWithArea";
2
+ export * from "./ClickableCircle";
3
+ export * from "./ClickableShape";
4
+ export * from "./GannFan";
5
+ export * from "./HoverTextNearMouse";
6
+ export * from "./InteractiveStraightLine";
7
+ export * from "./InteractiveText";
8
+ export * from "./InteractiveYCoordinate";
9
+ export * from "./LinearRegressionChannelWithArea";
10
+ export * from "./MouseLocationIndicator";
11
+ export * from "./Text";
package/src/index.ts ADDED
@@ -0,0 +1,12 @@
1
+ export { TrendLine } from "./TrendLine";
2
+ export { FibonacciRetracement } from "./FibonacciRetracement";
3
+ export { EquidistantChannel } from "./EquidistantChannel";
4
+ export { StandardDeviationChannel } from "./StandardDeviationChannel";
5
+ export { GannFan } from "./GannFan";
6
+ export { ClickCallback } from "./ClickCallback";
7
+ export { Brush } from "./Brush";
8
+ export { InteractiveText } from "./InteractiveText";
9
+ export { InteractiveYCoordinate } from "./InteractiveYCoordinate";
10
+ export { DrawingObjectSelector } from "./DrawingObjectSelector";
11
+ export { ZoomButtons } from "./ZoomButtons";
12
+ export * from "./utils";
package/src/utils.ts ADDED
@@ -0,0 +1,101 @@
1
+ import { isDefined, isNotDefined, mapObject } from "@ivanmatiaspascual/core";
2
+
3
+ export function getValueFromOverride(override: any, index: any, key: any, defaultValue: any) {
4
+ if (isDefined(override) && override.index === index) {
5
+ return override[key];
6
+ }
7
+ return defaultValue;
8
+ }
9
+
10
+ export function terminate() {
11
+ // @ts-ignore
12
+ this.setState({
13
+ current: null,
14
+ override: null,
15
+ });
16
+ }
17
+
18
+ export function saveNodeType(type: any) {
19
+ return (node: any) => {
20
+ // @ts-ignore
21
+ if (isDefined(this.nodes)) {
22
+ // @ts-ignore
23
+ if (isNotDefined(node) && isDefined(this.nodes[type])) {
24
+ // @ts-ignore
25
+ delete this.nodes[type];
26
+ } else {
27
+ // @ts-ignore
28
+ this.nodes[type] = node;
29
+ }
30
+ } else {
31
+ // @ts-ignore
32
+ this.nodes = [];
33
+ }
34
+ };
35
+ }
36
+ export function isHoverForInteractiveType(interactiveType: any) {
37
+ return function (moreProps: any) {
38
+ // this has to be function as it is bound to this
39
+
40
+ // @ts-ignore
41
+ if (isDefined(this.nodes)) {
42
+ // @ts-ignore
43
+ const selecedNodes = this.nodes.map((node) => node.isHover(moreProps));
44
+ // @ts-ignore
45
+ const interactive = this.props[interactiveType].map((t, idx) => {
46
+ return {
47
+ ...t,
48
+ selected: selecedNodes[idx],
49
+ };
50
+ });
51
+ return interactive;
52
+ }
53
+ };
54
+ }
55
+
56
+ export function isHover(moreProps: any) {
57
+ // @ts-ignore
58
+ const hovering = mapObject(this.nodes, (node) => node.isHover(moreProps)).reduce((a, b) => {
59
+ return a || b;
60
+ });
61
+ return hovering;
62
+ }
63
+
64
+ function getMouseXY(moreProps: any, [ox, oy]: any) {
65
+ if (Array.isArray(moreProps.mouseXY)) {
66
+ const {
67
+ mouseXY: [x, y],
68
+ } = moreProps;
69
+ const mouseXY = [x - ox, y - oy];
70
+ return mouseXY;
71
+ }
72
+ return moreProps.mouseXY;
73
+ }
74
+
75
+ export function getMorePropsForChart(moreProps: any, chartId: any) {
76
+ const { chartConfig: chartConfigList } = moreProps;
77
+ const chartConfig = chartConfigList.find((each: any) => each.id === chartId);
78
+
79
+ const { origin } = chartConfig;
80
+ const mouseXY = getMouseXY(moreProps, origin);
81
+ return {
82
+ ...moreProps,
83
+ chartConfig,
84
+ mouseXY,
85
+ };
86
+ }
87
+
88
+ export function getSelected(interactives: any) {
89
+ const selected = interactives
90
+ .map((each: any) => {
91
+ const objects = each.objects.filter((obj: any) => {
92
+ return obj.selected;
93
+ });
94
+ return {
95
+ ...each,
96
+ objects,
97
+ };
98
+ })
99
+ .filter((each: any) => each.objects.length > 0);
100
+ return selected;
101
+ }