@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.
- package/LICENSE +24 -0
- package/README.md +5 -0
- package/lib/CanvasContainer.d.ts +19 -0
- package/lib/CanvasContainer.js +28 -0
- package/lib/CanvasContainer.js.map +1 -0
- package/lib/Chart.d.ts +32 -0
- package/lib/Chart.js +57 -0
- package/lib/Chart.js.map +1 -0
- package/lib/ChartCanvas.d.ts +235 -0
- package/lib/ChartCanvas.js +810 -0
- package/lib/ChartCanvas.js.map +1 -0
- package/lib/EventCapture.d.ts +131 -0
- package/lib/EventCapture.js +489 -0
- package/lib/EventCapture.js.map +1 -0
- package/lib/GenericChartComponent.d.ts +21 -0
- package/lib/GenericChartComponent.js +75 -0
- package/lib/GenericChartComponent.js.map +1 -0
- package/lib/GenericComponent.d.ts +81 -0
- package/lib/GenericComponent.js +355 -0
- package/lib/GenericComponent.js.map +1 -0
- package/lib/MoreProps.d.ts +16 -0
- package/lib/MoreProps.js +2 -0
- package/lib/MoreProps.js.map +1 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.js +8 -0
- package/lib/index.js.map +1 -0
- package/lib/useEvent.d.ts +1 -0
- package/lib/useEvent.js +13 -0
- package/lib/useEvent.js.map +1 -0
- package/lib/utils/ChartDataUtil.d.ts +49 -0
- package/lib/utils/ChartDataUtil.js +205 -0
- package/lib/utils/ChartDataUtil.js.map +1 -0
- package/lib/utils/PureComponent.d.ts +4 -0
- package/lib/utils/PureComponent.js +10 -0
- package/lib/utils/PureComponent.js.map +1 -0
- package/lib/utils/accumulatingWindow.d.ts +15 -0
- package/lib/utils/accumulatingWindow.js +98 -0
- package/lib/utils/accumulatingWindow.js.map +1 -0
- package/lib/utils/barWidth.d.ts +15 -0
- package/lib/utils/barWidth.js +27 -0
- package/lib/utils/barWidth.js.map +1 -0
- package/lib/utils/closestItem.d.ts +5 -0
- package/lib/utils/closestItem.js +45 -0
- package/lib/utils/closestItem.js.map +1 -0
- package/lib/utils/evaluator.d.ts +7 -0
- package/lib/utils/evaluator.js +94 -0
- package/lib/utils/evaluator.js.map +1 -0
- package/lib/utils/identity.d.ts +1 -0
- package/lib/utils/identity.js +2 -0
- package/lib/utils/identity.js.map +1 -0
- package/lib/utils/index.d.ts +46 -0
- package/lib/utils/index.js +126 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/noop.d.ts +1 -0
- package/lib/utils/noop.js +3 -0
- package/lib/utils/noop.js.map +1 -0
- package/lib/utils/shallowEqual.d.ts +1 -0
- package/lib/utils/shallowEqual.js +22 -0
- package/lib/utils/shallowEqual.js.map +1 -0
- package/lib/utils/slidingWindow.d.ts +19 -0
- package/lib/utils/slidingWindow.js +109 -0
- package/lib/utils/slidingWindow.js.map +1 -0
- package/lib/utils/strokeDasharray.d.ts +3 -0
- package/lib/utils/strokeDasharray.js +37 -0
- package/lib/utils/strokeDasharray.js.map +1 -0
- package/lib/utils/zipper.d.ts +7 -0
- package/lib/utils/zipper.js +36 -0
- package/lib/utils/zipper.js.map +1 -0
- package/lib/zoom/index.d.ts +1 -0
- package/lib/zoom/index.js +2 -0
- package/lib/zoom/index.js.map +1 -0
- package/lib/zoom/zoomBehavior.d.ts +10 -0
- package/lib/zoom/zoomBehavior.js +18 -0
- package/lib/zoom/zoomBehavior.js.map +1 -0
- package/package.json +52 -0
- package/src/CanvasContainer.tsx +44 -0
- package/src/Chart.tsx +114 -0
- package/src/ChartCanvas.tsx +1336 -0
- package/src/EventCapture.tsx +709 -0
- package/src/GenericChartComponent.tsx +98 -0
- package/src/GenericComponent.tsx +454 -0
- package/src/MoreProps.ts +17 -0
- package/src/index.ts +7 -0
- package/src/useEvent.ts +14 -0
- package/src/utils/ChartDataUtil.ts +297 -0
- package/src/utils/PureComponent.tsx +12 -0
- package/src/utils/accumulatingWindow.ts +118 -0
- package/src/utils/barWidth.ts +44 -0
- package/src/utils/closestItem.ts +60 -0
- package/src/utils/evaluator.ts +163 -0
- package/src/utils/identity.ts +1 -0
- package/src/utils/index.ts +153 -0
- package/src/utils/noop.ts +2 -0
- package/src/utils/shallowEqual.ts +25 -0
- package/src/utils/slidingWindow.ts +140 -0
- package/src/utils/strokeDasharray.ts +52 -0
- package/src/utils/zipper.ts +45 -0
- package/src/zoom/index.ts +1 -0
- 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";
|