@tradingaction/core 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 (99) hide show
  1. package/LICENSE +24 -0
  2. package/README.md +5 -0
  3. package/lib/CanvasContainer.d.ts +19 -0
  4. package/lib/CanvasContainer.js +28 -0
  5. package/lib/CanvasContainer.js.map +1 -0
  6. package/lib/Chart.d.ts +32 -0
  7. package/lib/Chart.js +57 -0
  8. package/lib/Chart.js.map +1 -0
  9. package/lib/ChartCanvas.d.ts +235 -0
  10. package/lib/ChartCanvas.js +810 -0
  11. package/lib/ChartCanvas.js.map +1 -0
  12. package/lib/EventCapture.d.ts +131 -0
  13. package/lib/EventCapture.js +489 -0
  14. package/lib/EventCapture.js.map +1 -0
  15. package/lib/GenericChartComponent.d.ts +21 -0
  16. package/lib/GenericChartComponent.js +75 -0
  17. package/lib/GenericChartComponent.js.map +1 -0
  18. package/lib/GenericComponent.d.ts +81 -0
  19. package/lib/GenericComponent.js +355 -0
  20. package/lib/GenericComponent.js.map +1 -0
  21. package/lib/MoreProps.d.ts +16 -0
  22. package/lib/MoreProps.js +2 -0
  23. package/lib/MoreProps.js.map +1 -0
  24. package/lib/index.d.ts +7 -0
  25. package/lib/index.js +8 -0
  26. package/lib/index.js.map +1 -0
  27. package/lib/useEvent.d.ts +1 -0
  28. package/lib/useEvent.js +13 -0
  29. package/lib/useEvent.js.map +1 -0
  30. package/lib/utils/ChartDataUtil.d.ts +49 -0
  31. package/lib/utils/ChartDataUtil.js +205 -0
  32. package/lib/utils/ChartDataUtil.js.map +1 -0
  33. package/lib/utils/PureComponent.d.ts +4 -0
  34. package/lib/utils/PureComponent.js +10 -0
  35. package/lib/utils/PureComponent.js.map +1 -0
  36. package/lib/utils/accumulatingWindow.d.ts +15 -0
  37. package/lib/utils/accumulatingWindow.js +98 -0
  38. package/lib/utils/accumulatingWindow.js.map +1 -0
  39. package/lib/utils/barWidth.d.ts +15 -0
  40. package/lib/utils/barWidth.js +27 -0
  41. package/lib/utils/barWidth.js.map +1 -0
  42. package/lib/utils/closestItem.d.ts +5 -0
  43. package/lib/utils/closestItem.js +45 -0
  44. package/lib/utils/closestItem.js.map +1 -0
  45. package/lib/utils/evaluator.d.ts +7 -0
  46. package/lib/utils/evaluator.js +94 -0
  47. package/lib/utils/evaluator.js.map +1 -0
  48. package/lib/utils/identity.d.ts +1 -0
  49. package/lib/utils/identity.js +2 -0
  50. package/lib/utils/identity.js.map +1 -0
  51. package/lib/utils/index.d.ts +46 -0
  52. package/lib/utils/index.js +126 -0
  53. package/lib/utils/index.js.map +1 -0
  54. package/lib/utils/noop.d.ts +1 -0
  55. package/lib/utils/noop.js +3 -0
  56. package/lib/utils/noop.js.map +1 -0
  57. package/lib/utils/shallowEqual.d.ts +1 -0
  58. package/lib/utils/shallowEqual.js +22 -0
  59. package/lib/utils/shallowEqual.js.map +1 -0
  60. package/lib/utils/slidingWindow.d.ts +19 -0
  61. package/lib/utils/slidingWindow.js +109 -0
  62. package/lib/utils/slidingWindow.js.map +1 -0
  63. package/lib/utils/strokeDasharray.d.ts +3 -0
  64. package/lib/utils/strokeDasharray.js +37 -0
  65. package/lib/utils/strokeDasharray.js.map +1 -0
  66. package/lib/utils/zipper.d.ts +7 -0
  67. package/lib/utils/zipper.js +36 -0
  68. package/lib/utils/zipper.js.map +1 -0
  69. package/lib/zoom/index.d.ts +1 -0
  70. package/lib/zoom/index.js +2 -0
  71. package/lib/zoom/index.js.map +1 -0
  72. package/lib/zoom/zoomBehavior.d.ts +10 -0
  73. package/lib/zoom/zoomBehavior.js +18 -0
  74. package/lib/zoom/zoomBehavior.js.map +1 -0
  75. package/package.json +52 -0
  76. package/src/CanvasContainer.tsx +44 -0
  77. package/src/Chart.tsx +114 -0
  78. package/src/ChartCanvas.tsx +1336 -0
  79. package/src/EventCapture.tsx +709 -0
  80. package/src/GenericChartComponent.tsx +98 -0
  81. package/src/GenericComponent.tsx +454 -0
  82. package/src/MoreProps.ts +17 -0
  83. package/src/index.ts +7 -0
  84. package/src/useEvent.ts +14 -0
  85. package/src/utils/ChartDataUtil.ts +297 -0
  86. package/src/utils/PureComponent.tsx +12 -0
  87. package/src/utils/accumulatingWindow.ts +118 -0
  88. package/src/utils/barWidth.ts +44 -0
  89. package/src/utils/closestItem.ts +60 -0
  90. package/src/utils/evaluator.ts +163 -0
  91. package/src/utils/identity.ts +1 -0
  92. package/src/utils/index.ts +153 -0
  93. package/src/utils/noop.ts +2 -0
  94. package/src/utils/shallowEqual.ts +25 -0
  95. package/src/utils/slidingWindow.ts +140 -0
  96. package/src/utils/strokeDasharray.ts +52 -0
  97. package/src/utils/zipper.ts +45 -0
  98. package/src/zoom/index.ts +1 -0
  99. package/src/zoom/zoomBehavior.ts +34 -0
package/src/Chart.tsx ADDED
@@ -0,0 +1,114 @@
1
+ import { ScaleContinuousNumeric } from "d3-scale";
2
+ import * as React from "react";
3
+ import { ChartCanvasContext, chartCanvasContextDefaultValue, ChartCanvasContextType } from "./ChartCanvas";
4
+ import type { ChartConfig } from "./utils/ChartDataUtil";
5
+
6
+ export type ChartContextType = Omit<ChartCanvasContextType<number | Date>, "chartConfig"> & {
7
+ chartConfig: ChartConfig;
8
+ };
9
+ export const ChartContext = React.createContext<ChartContextType>({
10
+ ...chartCanvasContextDefaultValue,
11
+ // @ts-ignore
12
+ chartConfig: {},
13
+ chartId: 0,
14
+ });
15
+
16
+ export interface ChartProps {
17
+ readonly flipYScale?: boolean;
18
+ readonly height?: number;
19
+ readonly id: number | string;
20
+ readonly onContextMenu?: (event: React.MouseEvent, moreProps: any) => void;
21
+ readonly onDoubleClick?: (event: React.MouseEvent, moreProps: any) => void;
22
+ readonly origin?: number[] | ((width: number, height: number) => number[]);
23
+ readonly padding?: number | { top: number; bottom: number };
24
+ readonly yExtents?: number[] | ((data: any) => number) | ((data: any) => number[]);
25
+ readonly yExtentsCalculator?: (options: {
26
+ plotData: any[];
27
+ xDomain: any;
28
+ xAccessor: any;
29
+ displayXAccessor: any;
30
+ fullData: any[];
31
+ }) => number[];
32
+ readonly yPan?: boolean;
33
+ readonly yPanEnabled?: boolean;
34
+ readonly yScale?: ScaleContinuousNumeric<number, number>;
35
+ }
36
+
37
+ export const Chart = React.memo((props: React.PropsWithChildren<ChartProps>) => {
38
+ const {
39
+ // flipYScale = false,
40
+ id = 0,
41
+ // origin = [0, 0],
42
+ // padding = 0,
43
+ // yPan = true,
44
+ // yPanEnabled = false,
45
+ // yScale = scaleLinear(),
46
+ onContextMenu,
47
+ onDoubleClick,
48
+ } = props;
49
+
50
+ const chartCanvasContextValue = React.useContext(ChartCanvasContext);
51
+ const { subscribe, unsubscribe, chartConfigs } = chartCanvasContextValue;
52
+
53
+ const listener = React.useCallback(
54
+ (type: string, moreProps: any, _: any, e: React.MouseEvent) => {
55
+ switch (type) {
56
+ case "contextmenu": {
57
+ if (onContextMenu === undefined) {
58
+ return;
59
+ }
60
+
61
+ const { currentCharts } = moreProps;
62
+ if (currentCharts.indexOf(id) > -1) {
63
+ onContextMenu(e, moreProps);
64
+ }
65
+
66
+ break;
67
+ }
68
+ case "dblclick": {
69
+ if (onDoubleClick === undefined) {
70
+ return;
71
+ }
72
+
73
+ const { currentCharts } = moreProps;
74
+ if (currentCharts.indexOf(id) > -1) {
75
+ onDoubleClick(e, moreProps);
76
+ }
77
+
78
+ break;
79
+ }
80
+ }
81
+ },
82
+ [onContextMenu, onDoubleClick, id],
83
+ );
84
+
85
+ React.useEffect(() => {
86
+ subscribe(`chart_${id}`, {
87
+ listener,
88
+ });
89
+ return () => unsubscribe(`chart_${id}`);
90
+ }, [subscribe, unsubscribe, id, listener]);
91
+
92
+ const config = chartConfigs.find(({ id }) => id === props.id)!;
93
+ const contextValue = React.useMemo(() => {
94
+ return {
95
+ ...chartCanvasContextValue,
96
+ chartId: id,
97
+ chartConfig: config,
98
+ };
99
+ }, [id, config, chartCanvasContextValue]);
100
+
101
+ const {
102
+ origin: [x, y],
103
+ } = config;
104
+
105
+ return (
106
+ <ChartContext.Provider value={contextValue}>
107
+ <g transform={`translate(${x}, ${y})`} id={`chart_${id}`}>
108
+ {props.children}
109
+ </g>
110
+ </ChartContext.Provider>
111
+ );
112
+ });
113
+
114
+ Chart.displayName = "Chart";