@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
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { ICanvasContexts } from "./CanvasContainer";
|
|
3
|
+
import { ChartCanvasContext } from "./ChartCanvas";
|
|
4
|
+
interface GenericComponentProps {
|
|
5
|
+
readonly svgDraw?: (moreProps: any) => React.ReactNode;
|
|
6
|
+
readonly canvasDraw?: (ctx: CanvasRenderingContext2D, moreProps: any) => void;
|
|
7
|
+
readonly canvasToDraw?: (contexts: ICanvasContexts) => CanvasRenderingContext2D | undefined;
|
|
8
|
+
readonly clip?: boolean;
|
|
9
|
+
readonly disablePan?: boolean;
|
|
10
|
+
readonly drawOn: string[];
|
|
11
|
+
readonly edgeClip?: boolean;
|
|
12
|
+
readonly enableDragOnHover?: boolean;
|
|
13
|
+
readonly interactiveCursorClass?: string;
|
|
14
|
+
readonly isHover?: (moreProps: any, e: React.MouseEvent) => boolean;
|
|
15
|
+
readonly onClick?: (e: React.MouseEvent, moreProps: any) => void;
|
|
16
|
+
readonly onClickWhenHover?: (e: React.MouseEvent, moreProps: any) => void;
|
|
17
|
+
readonly onClickOutside?: (e: React.MouseEvent, moreProps: any) => void;
|
|
18
|
+
readonly onPan?: (e: React.MouseEvent, moreProps: any) => void;
|
|
19
|
+
readonly onPanEnd?: (e: React.MouseEvent, moreProps: any) => void;
|
|
20
|
+
readonly onDragStart?: (e: React.MouseEvent, moreProps: any) => void;
|
|
21
|
+
readonly onDrag?: (e: React.MouseEvent, moreProps: any) => void;
|
|
22
|
+
readonly onDragComplete?: (e: React.MouseEvent, moreProps: any) => void;
|
|
23
|
+
readonly onDoubleClick?: (e: React.MouseEvent, moreProps: any) => void;
|
|
24
|
+
readonly onDoubleClickWhenHover?: (e: React.MouseEvent, moreProps: any) => void;
|
|
25
|
+
readonly onContextMenu?: (e: React.MouseEvent, moreProps: any) => void;
|
|
26
|
+
readonly onContextMenuWhenHover?: (e: React.MouseEvent, moreProps: any) => void;
|
|
27
|
+
readonly onMouseMove?: (e: React.MouseEvent, moreProps: any) => void;
|
|
28
|
+
readonly onMouseDown?: (e: React.MouseEvent, moreProps: any) => void;
|
|
29
|
+
readonly onHover?: (e: React.MouseEvent, moreProps: any) => void;
|
|
30
|
+
readonly onUnHover?: (e: React.MouseEvent, moreProps: any) => void;
|
|
31
|
+
readonly selected?: boolean;
|
|
32
|
+
}
|
|
33
|
+
interface GenericComponentState {
|
|
34
|
+
updateCount: number;
|
|
35
|
+
}
|
|
36
|
+
export declare class GenericComponent extends React.Component<GenericComponentProps, GenericComponentState> {
|
|
37
|
+
static defaultProps: {
|
|
38
|
+
svgDraw: any;
|
|
39
|
+
draw: never[];
|
|
40
|
+
canvasToDraw: (contexts: ICanvasContexts) => CanvasRenderingContext2D | undefined;
|
|
41
|
+
clip: boolean;
|
|
42
|
+
edgeClip: boolean;
|
|
43
|
+
selected: boolean;
|
|
44
|
+
disablePan: boolean;
|
|
45
|
+
enableDragOnHover: boolean;
|
|
46
|
+
};
|
|
47
|
+
context: React.ContextType<typeof ChartCanvasContext>;
|
|
48
|
+
moreProps: any;
|
|
49
|
+
private dragInProgress;
|
|
50
|
+
private evaluationInProgress;
|
|
51
|
+
private iSetTheCursorClass;
|
|
52
|
+
private readonly subscriberId;
|
|
53
|
+
constructor(props: GenericComponentProps, context: any);
|
|
54
|
+
updateMoreProps(moreProps: any): void;
|
|
55
|
+
shouldTypeProceed(type: string, moreProps: any): boolean;
|
|
56
|
+
preEvaluate(type: string, moreProps: any, e: any): void;
|
|
57
|
+
listener: (type: string, moreProps: any, state: any, e: any) => void;
|
|
58
|
+
evaluateType(type: string, e: any): void;
|
|
59
|
+
isHover(e: React.MouseEvent): boolean;
|
|
60
|
+
getPanConditions(): {
|
|
61
|
+
draggable: any;
|
|
62
|
+
panEnabled: boolean;
|
|
63
|
+
};
|
|
64
|
+
draw({ trigger, force }: {
|
|
65
|
+
force: boolean;
|
|
66
|
+
trigger: string;
|
|
67
|
+
}): void;
|
|
68
|
+
UNSAFE_componentWillMount(): void;
|
|
69
|
+
componentWillUnmount(): void;
|
|
70
|
+
componentDidMount(): void;
|
|
71
|
+
componentDidUpdate(prevProps: GenericComponentProps): void;
|
|
72
|
+
UNSAFE_componentWillReceiveProps(nextProps: GenericComponentProps, nextContext: any): void;
|
|
73
|
+
getMoreProps(): any;
|
|
74
|
+
preCanvasDraw(ctx: CanvasRenderingContext2D, moreProps: any): void;
|
|
75
|
+
postCanvasDraw(ctx: CanvasRenderingContext2D, moreProps: any): void;
|
|
76
|
+
drawOnCanvas(): void;
|
|
77
|
+
render(): JSX.Element | null;
|
|
78
|
+
}
|
|
79
|
+
export declare const getAxisCanvas: (contexts: ICanvasContexts) => CanvasRenderingContext2D | undefined;
|
|
80
|
+
export declare const getMouseCanvas: (contexts: ICanvasContexts) => CanvasRenderingContext2D | undefined;
|
|
81
|
+
export {};
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { functor, identity } from "./utils";
|
|
4
|
+
import { ChartCanvasContext } from "./ChartCanvas";
|
|
5
|
+
const aliases = {
|
|
6
|
+
mouseleave: "mousemove",
|
|
7
|
+
panend: "pan",
|
|
8
|
+
pinchzoom: "pan",
|
|
9
|
+
mousedown: "mousemove",
|
|
10
|
+
click: "mousemove",
|
|
11
|
+
contextmenu: "mousemove",
|
|
12
|
+
dblclick: "mousemove",
|
|
13
|
+
dragstart: "drag",
|
|
14
|
+
dragend: "drag",
|
|
15
|
+
dragcancel: "drag",
|
|
16
|
+
zoom: "zoom",
|
|
17
|
+
};
|
|
18
|
+
export class GenericComponent extends React.Component {
|
|
19
|
+
constructor(props, context) {
|
|
20
|
+
super(props, context);
|
|
21
|
+
this.moreProps = {};
|
|
22
|
+
this.dragInProgress = false;
|
|
23
|
+
this.evaluationInProgress = false;
|
|
24
|
+
this.iSetTheCursorClass = false;
|
|
25
|
+
this.listener = (type, moreProps, state, e) => {
|
|
26
|
+
if (moreProps !== undefined) {
|
|
27
|
+
this.updateMoreProps(moreProps);
|
|
28
|
+
}
|
|
29
|
+
this.evaluationInProgress = true;
|
|
30
|
+
this.evaluateType(type, e);
|
|
31
|
+
this.evaluationInProgress = false;
|
|
32
|
+
};
|
|
33
|
+
this.drawOnCanvas = this.drawOnCanvas.bind(this);
|
|
34
|
+
this.getMoreProps = this.getMoreProps.bind(this);
|
|
35
|
+
this.draw = this.draw.bind(this);
|
|
36
|
+
this.updateMoreProps = this.updateMoreProps.bind(this);
|
|
37
|
+
this.evaluateType = this.evaluateType.bind(this);
|
|
38
|
+
this.isHover = this.isHover.bind(this);
|
|
39
|
+
this.preCanvasDraw = this.preCanvasDraw.bind(this);
|
|
40
|
+
this.postCanvasDraw = this.postCanvasDraw.bind(this);
|
|
41
|
+
this.getPanConditions = this.getPanConditions.bind(this);
|
|
42
|
+
this.shouldTypeProceed = this.shouldTypeProceed.bind(this);
|
|
43
|
+
this.preEvaluate = this.preEvaluate.bind(this);
|
|
44
|
+
const { generateSubscriptionId } = context;
|
|
45
|
+
this.subscriberId = generateSubscriptionId();
|
|
46
|
+
this.state = {
|
|
47
|
+
updateCount: 0,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
updateMoreProps(moreProps) {
|
|
51
|
+
Object.keys(moreProps).forEach((key) => {
|
|
52
|
+
this.moreProps[key] = moreProps[key];
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
shouldTypeProceed(type, moreProps) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
preEvaluate(type, moreProps, e) {
|
|
59
|
+
/// empty
|
|
60
|
+
}
|
|
61
|
+
evaluateType(type, e) {
|
|
62
|
+
// @ts-ignore
|
|
63
|
+
const newType = aliases[type] || type;
|
|
64
|
+
const proceed = this.props.drawOn.indexOf(newType) > -1;
|
|
65
|
+
if (!proceed) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
this.preEvaluate(type, this.moreProps, e);
|
|
69
|
+
if (!this.shouldTypeProceed(type, this.moreProps)) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
switch (type) {
|
|
73
|
+
case "zoom":
|
|
74
|
+
case "mouseenter":
|
|
75
|
+
// DO NOT DRAW FOR THESE EVENTS
|
|
76
|
+
break;
|
|
77
|
+
case "mouseleave": {
|
|
78
|
+
this.moreProps.hovering = false;
|
|
79
|
+
if (this.props.onUnHover) {
|
|
80
|
+
this.props.onUnHover(e, this.getMoreProps());
|
|
81
|
+
}
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
case "contextmenu": {
|
|
85
|
+
if (this.props.onContextMenu) {
|
|
86
|
+
this.props.onContextMenu(e, this.getMoreProps());
|
|
87
|
+
}
|
|
88
|
+
if (this.moreProps.hovering && this.props.onContextMenuWhenHover) {
|
|
89
|
+
this.props.onContextMenuWhenHover(e, this.getMoreProps());
|
|
90
|
+
}
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
case "mousedown": {
|
|
94
|
+
if (this.props.onMouseDown) {
|
|
95
|
+
this.props.onMouseDown(e, this.getMoreProps());
|
|
96
|
+
}
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
case "click": {
|
|
100
|
+
const { onClick, onClickOutside, onClickWhenHover } = this.props;
|
|
101
|
+
const moreProps = this.getMoreProps();
|
|
102
|
+
if (moreProps.hovering && onClickWhenHover !== undefined) {
|
|
103
|
+
onClickWhenHover(e, moreProps);
|
|
104
|
+
}
|
|
105
|
+
else if (onClickOutside !== undefined) {
|
|
106
|
+
onClickOutside(e, moreProps);
|
|
107
|
+
}
|
|
108
|
+
if (onClick !== undefined) {
|
|
109
|
+
onClick(e, moreProps);
|
|
110
|
+
}
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
case "mousemove": {
|
|
114
|
+
const prevHover = this.moreProps.hovering;
|
|
115
|
+
this.moreProps.hovering = this.isHover(e);
|
|
116
|
+
const { amIOnTop, setCursorClass } = this.context;
|
|
117
|
+
if (this.moreProps.hovering &&
|
|
118
|
+
!this.props.selected &&
|
|
119
|
+
/* && !prevHover */
|
|
120
|
+
amIOnTop(this.subscriberId) &&
|
|
121
|
+
this.props.onHover !== undefined) {
|
|
122
|
+
setCursorClass("react-financial-charts-pointer-cursor");
|
|
123
|
+
this.iSetTheCursorClass = true;
|
|
124
|
+
}
|
|
125
|
+
else if (this.moreProps.hovering && this.props.selected && amIOnTop(this.subscriberId)) {
|
|
126
|
+
setCursorClass(this.props.interactiveCursorClass);
|
|
127
|
+
this.iSetTheCursorClass = true;
|
|
128
|
+
}
|
|
129
|
+
else if (prevHover && !this.moreProps.hovering && this.iSetTheCursorClass) {
|
|
130
|
+
this.iSetTheCursorClass = false;
|
|
131
|
+
setCursorClass(null);
|
|
132
|
+
}
|
|
133
|
+
const moreProps = this.getMoreProps();
|
|
134
|
+
if (this.moreProps.hovering && !prevHover) {
|
|
135
|
+
if (this.props.onHover) {
|
|
136
|
+
this.props.onHover(e, moreProps);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (prevHover && !this.moreProps.hovering) {
|
|
140
|
+
if (this.props.onUnHover) {
|
|
141
|
+
this.props.onUnHover(e, moreProps);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (this.props.onMouseMove) {
|
|
145
|
+
this.props.onMouseMove(e, moreProps);
|
|
146
|
+
}
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
case "dblclick": {
|
|
150
|
+
const moreProps = this.getMoreProps();
|
|
151
|
+
if (this.props.onDoubleClick) {
|
|
152
|
+
this.props.onDoubleClick(e, moreProps);
|
|
153
|
+
}
|
|
154
|
+
if (this.moreProps.hovering && this.props.onDoubleClickWhenHover) {
|
|
155
|
+
this.props.onDoubleClickWhenHover(e, moreProps);
|
|
156
|
+
}
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
case "pan": {
|
|
160
|
+
this.moreProps.hovering = false;
|
|
161
|
+
if (this.props.onPan) {
|
|
162
|
+
this.props.onPan(e, this.getMoreProps());
|
|
163
|
+
}
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
case "panend": {
|
|
167
|
+
if (this.props.onPanEnd) {
|
|
168
|
+
this.props.onPanEnd(e, this.getMoreProps());
|
|
169
|
+
}
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
case "dragstart": {
|
|
173
|
+
if (this.getPanConditions().draggable) {
|
|
174
|
+
const { amIOnTop } = this.context;
|
|
175
|
+
if (amIOnTop(this.subscriberId)) {
|
|
176
|
+
this.dragInProgress = true;
|
|
177
|
+
if (this.props.onDragStart !== undefined) {
|
|
178
|
+
this.props.onDragStart(e, this.getMoreProps());
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
case "drag": {
|
|
185
|
+
if (this.dragInProgress && this.props.onDrag) {
|
|
186
|
+
this.props.onDrag(e, this.getMoreProps());
|
|
187
|
+
}
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
case "dragend": {
|
|
191
|
+
if (this.dragInProgress && this.props.onDragComplete) {
|
|
192
|
+
this.props.onDragComplete(e, this.getMoreProps());
|
|
193
|
+
}
|
|
194
|
+
this.dragInProgress = false;
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
case "dragcancel": {
|
|
198
|
+
if (this.dragInProgress || this.iSetTheCursorClass) {
|
|
199
|
+
const { setCursorClass } = this.context;
|
|
200
|
+
setCursorClass(null);
|
|
201
|
+
}
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
isHover(e) {
|
|
207
|
+
const { isHover } = this.props;
|
|
208
|
+
if (isHover === undefined) {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
return isHover(this.getMoreProps(), e);
|
|
212
|
+
}
|
|
213
|
+
getPanConditions() {
|
|
214
|
+
const draggable = !!(this.props.selected && this.moreProps.hovering) ||
|
|
215
|
+
(this.props.enableDragOnHover && this.moreProps.hovering);
|
|
216
|
+
return {
|
|
217
|
+
draggable,
|
|
218
|
+
panEnabled: !this.props.disablePan,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
draw({ trigger, force = false }) {
|
|
222
|
+
const type = aliases[trigger] || trigger;
|
|
223
|
+
const proceed = this.props.drawOn.indexOf(type) > -1;
|
|
224
|
+
if (proceed || this.props.selected /* this is to draw as soon as you select */ || force) {
|
|
225
|
+
const { canvasDraw } = this.props;
|
|
226
|
+
if (canvasDraw === undefined) {
|
|
227
|
+
const { updateCount } = this.state;
|
|
228
|
+
this.setState({
|
|
229
|
+
updateCount: updateCount + 1,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
this.drawOnCanvas();
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
UNSAFE_componentWillMount() {
|
|
238
|
+
const { subscribe, chartId } = this.context;
|
|
239
|
+
const { clip, edgeClip } = this.props;
|
|
240
|
+
subscribe(this.subscriberId, {
|
|
241
|
+
chartId,
|
|
242
|
+
clip,
|
|
243
|
+
edgeClip,
|
|
244
|
+
listener: this.listener,
|
|
245
|
+
draw: this.draw,
|
|
246
|
+
getPanConditions: this.getPanConditions,
|
|
247
|
+
});
|
|
248
|
+
this.UNSAFE_componentWillReceiveProps(this.props, this.context);
|
|
249
|
+
}
|
|
250
|
+
componentWillUnmount() {
|
|
251
|
+
const { unsubscribe } = this.context;
|
|
252
|
+
unsubscribe(this.subscriberId);
|
|
253
|
+
if (this.iSetTheCursorClass) {
|
|
254
|
+
const { setCursorClass } = this.context;
|
|
255
|
+
setCursorClass(null);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
componentDidMount() {
|
|
259
|
+
this.componentDidUpdate(this.props);
|
|
260
|
+
}
|
|
261
|
+
componentDidUpdate(prevProps) {
|
|
262
|
+
const { canvasDraw, selected, interactiveCursorClass } = this.props;
|
|
263
|
+
if (prevProps.selected !== selected) {
|
|
264
|
+
const { setCursorClass } = this.context;
|
|
265
|
+
if (selected && this.moreProps.hovering) {
|
|
266
|
+
this.iSetTheCursorClass = true;
|
|
267
|
+
setCursorClass(interactiveCursorClass);
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
this.iSetTheCursorClass = false;
|
|
271
|
+
setCursorClass(null);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
if (canvasDraw !== undefined && !this.evaluationInProgress) {
|
|
275
|
+
this.updateMoreProps(this.moreProps);
|
|
276
|
+
this.drawOnCanvas();
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
UNSAFE_componentWillReceiveProps(nextProps, nextContext) {
|
|
280
|
+
const { xScale, plotData, chartConfig, getMutableState } = nextContext;
|
|
281
|
+
this.moreProps = Object.assign(Object.assign(Object.assign({}, this.moreProps), getMutableState()), {
|
|
282
|
+
/*
|
|
283
|
+
^ this is so
|
|
284
|
+
mouseXY, currentCharts, currentItem are available to
|
|
285
|
+
newly created components like MouseHoverText which
|
|
286
|
+
is created right after a new interactive object is drawn
|
|
287
|
+
*/
|
|
288
|
+
xScale,
|
|
289
|
+
plotData,
|
|
290
|
+
chartConfig });
|
|
291
|
+
}
|
|
292
|
+
getMoreProps() {
|
|
293
|
+
const { xScale, plotData, chartConfigs, morePropsDecorator, xAccessor, displayXAccessor, width, height } = this.context;
|
|
294
|
+
const { chartId, fullData } = this.context;
|
|
295
|
+
const moreProps = Object.assign({ xScale,
|
|
296
|
+
plotData,
|
|
297
|
+
chartConfigs,
|
|
298
|
+
xAccessor,
|
|
299
|
+
displayXAccessor,
|
|
300
|
+
width,
|
|
301
|
+
height,
|
|
302
|
+
chartId,
|
|
303
|
+
fullData }, this.moreProps);
|
|
304
|
+
return (morePropsDecorator || identity)(moreProps);
|
|
305
|
+
}
|
|
306
|
+
preCanvasDraw(ctx, moreProps) {
|
|
307
|
+
// do nothing
|
|
308
|
+
}
|
|
309
|
+
postCanvasDraw(ctx, moreProps) {
|
|
310
|
+
// empty
|
|
311
|
+
}
|
|
312
|
+
drawOnCanvas() {
|
|
313
|
+
const { canvasDraw, canvasToDraw } = this.props;
|
|
314
|
+
if (canvasDraw === undefined || canvasToDraw === undefined) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
const { getCanvasContexts } = this.context;
|
|
318
|
+
const moreProps = this.getMoreProps();
|
|
319
|
+
const contexts = getCanvasContexts();
|
|
320
|
+
const ctx = canvasToDraw(contexts);
|
|
321
|
+
if (ctx !== undefined) {
|
|
322
|
+
this.preCanvasDraw(ctx, moreProps);
|
|
323
|
+
canvasDraw(ctx, moreProps);
|
|
324
|
+
this.postCanvasDraw(ctx, moreProps);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
render() {
|
|
328
|
+
const { canvasDraw, clip, svgDraw } = this.props;
|
|
329
|
+
if (canvasDraw !== undefined || svgDraw === undefined) {
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
332
|
+
const { chartId } = this.context;
|
|
333
|
+
const suffix = chartId !== undefined ? "-" + chartId : "";
|
|
334
|
+
const style = clip ? { clipPath: `url(#chart-area-clip${suffix})` } : undefined;
|
|
335
|
+
return React.createElement("g", { style: style }, svgDraw(this.getMoreProps()));
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
GenericComponent.defaultProps = {
|
|
339
|
+
svgDraw: functor(null),
|
|
340
|
+
draw: [],
|
|
341
|
+
canvasToDraw: (contexts) => contexts.mouseCoord,
|
|
342
|
+
clip: true,
|
|
343
|
+
edgeClip: false,
|
|
344
|
+
selected: false,
|
|
345
|
+
disablePan: false,
|
|
346
|
+
enableDragOnHover: false,
|
|
347
|
+
};
|
|
348
|
+
GenericComponent.contextType = ChartCanvasContext;
|
|
349
|
+
export const getAxisCanvas = (contexts) => {
|
|
350
|
+
return contexts.axes;
|
|
351
|
+
};
|
|
352
|
+
export const getMouseCanvas = (contexts) => {
|
|
353
|
+
return contexts.mouseCoord;
|
|
354
|
+
};
|
|
355
|
+
//# sourceMappingURL=GenericComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GenericComponent.js","sourceRoot":"","sources":["../src/GenericComponent.tsx"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD,MAAM,OAAO,GAA2B;IACpC,UAAU,EAAE,WAAW;IACvB,MAAM,EAAE,KAAK;IACb,SAAS,EAAE,KAAK;IAChB,SAAS,EAAE,WAAW;IACtB,KAAK,EAAE,WAAW;IAClB,WAAW,EAAE,WAAW;IACxB,QAAQ,EAAE,WAAW;IACrB,SAAS,EAAE,MAAM;IACjB,OAAO,EAAE,MAAM;IACf,UAAU,EAAE,MAAM;IAClB,IAAI,EAAE,MAAM;CACf,CAAC;AAoCF,MAAM,OAAO,gBAAiB,SAAQ,KAAK,CAAC,SAAuD;IAqB/F,YAAmB,KAA4B,EAAE,OAAY;QACzD,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QARnB,cAAS,GAAQ,EAAE,CAAC;QAEnB,mBAAc,GAAG,KAAK,CAAC;QACvB,yBAAoB,GAAG,KAAK,CAAC;QAC7B,uBAAkB,GAAG,KAAK,CAAC;QAwC5B,aAAQ,GAAG,CAAC,IAAY,EAAE,SAAc,EAAE,KAAU,EAAE,CAAM,EAAE,EAAE;YACnE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AC;AAElD,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,QAAyB,EAAE,EAAE;IACvD,OAAO,QAAQ,CAAC,IAAI,CAAC;AACzB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,QAAyB,EAAE,EAAE;IACxD,OAAO,QAAQ,CAAC,UAAU,CAAC;AAC/B,CAAC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ScaleContinuousNumeric } from "d3-scale";
|
|
2
|
+
import type { ChartConfig } from "./utils/ChartDataUtil";
|
|
3
|
+
export interface MoreProps {
|
|
4
|
+
chartId: string | number;
|
|
5
|
+
hovering: boolean;
|
|
6
|
+
currentCharts: (string | number)[];
|
|
7
|
+
startPos?: [number, number];
|
|
8
|
+
mouseXY?: [number, number];
|
|
9
|
+
chartConfigs: ChartConfig[];
|
|
10
|
+
chartConfig?: ChartConfig;
|
|
11
|
+
fullData: any[];
|
|
12
|
+
plotData: any[];
|
|
13
|
+
xAccessor: (datum: any) => any;
|
|
14
|
+
xScale: Function;
|
|
15
|
+
yScale?: ScaleContinuousNumeric<number, number>;
|
|
16
|
+
}
|
package/lib/MoreProps.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MoreProps.js","sourceRoot":"","sources":["../src/MoreProps.ts"],"names":[],"mappings":""}
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { ChartCanvas, ChartCanvasContext } from "./ChartCanvas";
|
|
2
|
+
export * from "./Chart";
|
|
3
|
+
export * from "./GenericChartComponent";
|
|
4
|
+
export * from "./GenericComponent";
|
|
5
|
+
export * from "./MoreProps";
|
|
6
|
+
export * from "./utils";
|
|
7
|
+
export * from "./zoom";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAChE,cAAc,SAAS,CAAC;AACxB,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useEvent<F extends (...args: any[]) => any>(handler: F): (...args: Parameters<F>) => ReturnType<F>;
|
package/lib/useEvent.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useCallback, useLayoutEffect, useRef } from "react";
|
|
2
|
+
// Based on https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md#internal-implementation
|
|
3
|
+
export function useEvent(handler) {
|
|
4
|
+
const handlerRef = useRef();
|
|
5
|
+
useLayoutEffect(() => {
|
|
6
|
+
handlerRef.current = handler;
|
|
7
|
+
});
|
|
8
|
+
return useCallback((...args) => {
|
|
9
|
+
const fn = handlerRef.current;
|
|
10
|
+
return fn(...args);
|
|
11
|
+
}, []);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=useEvent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEvent.js","sourceRoot":"","sources":["../src/useEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC7D,uGAAuG;AACvG,MAAM,UAAU,QAAQ,CAAoC,OAAU;IAClE,MAAM,UAAU,GAAG,MAAM,EAAK,CAAC;IAE/B,eAAe,CAAC,GAAG,EAAE;QACjB,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC;IACjC,CAAC,CAAC,CAAC;IAEH,OAAO,WAAW,CAAC,CAAC,GAAG,IAAmB,EAAE,EAAE;QAC1C,MAAM,EAAE,GAAG,UAAU,CAAC,OAAQ,CAAC;QAC/B,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;IACvB,CAAC,EAAE,EAAE,CAAC,CAAC;AACX,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ScaleContinuousNumeric, ScaleTime } from "d3-scale";
|
|
2
|
+
export interface ChartConfig {
|
|
3
|
+
id: number | string;
|
|
4
|
+
readonly origin: number[];
|
|
5
|
+
readonly padding: number | {
|
|
6
|
+
top: number;
|
|
7
|
+
bottom: number;
|
|
8
|
+
};
|
|
9
|
+
readonly originalYExtentsProp?: number[] | ((data: any) => number) | ((data: any) => number[]);
|
|
10
|
+
readonly yExtents?: number[] | ((data: any) => number) | ((data: any) => number[]);
|
|
11
|
+
readonly yExtentsCalculator?: (options: {
|
|
12
|
+
plotData: any[];
|
|
13
|
+
xDomain: any;
|
|
14
|
+
xAccessor: any;
|
|
15
|
+
displayXAccessor: any;
|
|
16
|
+
fullData: any[];
|
|
17
|
+
}) => number[];
|
|
18
|
+
readonly flipYScale?: boolean;
|
|
19
|
+
readonly yScale: ScaleContinuousNumeric<number, number>;
|
|
20
|
+
readonly yPan: boolean;
|
|
21
|
+
readonly yPanEnabled: boolean;
|
|
22
|
+
readonly realYDomain?: number[];
|
|
23
|
+
readonly width: number;
|
|
24
|
+
readonly height: number;
|
|
25
|
+
mouseCoordinates?: {
|
|
26
|
+
at: string;
|
|
27
|
+
format: () => unknown;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export declare const ChartDefaultConfig: {
|
|
31
|
+
flipYScale: boolean;
|
|
32
|
+
id: number;
|
|
33
|
+
origin: number[];
|
|
34
|
+
padding: number;
|
|
35
|
+
yPan: boolean;
|
|
36
|
+
yPanEnabled: boolean;
|
|
37
|
+
yScale: import("d3-scale").ScaleLinear<number, number, never>;
|
|
38
|
+
};
|
|
39
|
+
export declare function getChartOrigin(origin: any, contextWidth: number, contextHeight: number): any;
|
|
40
|
+
export declare function getDimensions({ width, height }: any, chartProps: any): {
|
|
41
|
+
availableHeight: any;
|
|
42
|
+
width: any;
|
|
43
|
+
height: any;
|
|
44
|
+
};
|
|
45
|
+
export declare function getNewChartConfig(innerDimension: any, children: any, existingChartConfig?: ChartConfig[]): any;
|
|
46
|
+
export declare function getCurrentCharts(chartConfig: ChartConfig[], mouseXY: number[]): any[];
|
|
47
|
+
export declare function getChartConfigWithUpdatedYScales(chartConfig: ChartConfig[], { plotData, xAccessor, displayXAccessor, fullData }: any, xDomain: any, dy?: number, chartsToPan?: (string | number)[]): ChartConfig[];
|
|
48
|
+
export declare function getCurrentItem(xScale: ScaleContinuousNumeric<number, number> | ScaleTime<number, number>, xAccessor: any, mouseXY: number[], plotData: any[]): any;
|
|
49
|
+
export declare function getXValue(xScale: ScaleContinuousNumeric<number, number> | ScaleTime<number, number>, xAccessor: any, mouseXY: number[], plotData: any[]): any;
|