@tradingaction/core 2.0.0 → 2.0.2

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 (57) hide show
  1. package/LICENSE +24 -24
  2. package/README.md +5 -5
  3. package/lib/CanvasContainer.d.ts +19 -19
  4. package/lib/CanvasContainer.js +27 -27
  5. package/lib/Chart.d.ts +32 -32
  6. package/lib/Chart.js +56 -56
  7. package/lib/Chart.js.map +1 -1
  8. package/lib/ChartCanvas.d.ts +235 -235
  9. package/lib/ChartCanvas.js +770 -770
  10. package/lib/ChartCanvas.js.map +1 -1
  11. package/lib/EventCapture.d.ts +131 -131
  12. package/lib/EventCapture.js +488 -488
  13. package/lib/GenericChartComponent.d.ts +21 -21
  14. package/lib/GenericChartComponent.js +74 -74
  15. package/lib/GenericComponent.d.ts +81 -81
  16. package/lib/GenericComponent.js +354 -354
  17. package/lib/GenericComponent.js.map +1 -1
  18. package/lib/MoreProps.d.ts +16 -16
  19. package/lib/MoreProps.js +1 -1
  20. package/lib/index.d.ts +7 -7
  21. package/lib/index.js +7 -7
  22. package/lib/useEvent.d.ts +1 -1
  23. package/lib/useEvent.js +12 -12
  24. package/lib/utils/ChartDataUtil.d.ts +49 -49
  25. package/lib/utils/ChartDataUtil.js +204 -204
  26. package/lib/utils/PureComponent.d.ts +4 -4
  27. package/lib/utils/PureComponent.js +9 -9
  28. package/lib/utils/accumulatingWindow.d.ts +15 -15
  29. package/lib/utils/accumulatingWindow.js +97 -97
  30. package/lib/utils/barWidth.d.ts +15 -15
  31. package/lib/utils/barWidth.js +26 -26
  32. package/lib/utils/closestItem.d.ts +5 -5
  33. package/lib/utils/closestItem.js +44 -44
  34. package/lib/utils/evaluator.d.ts +7 -7
  35. package/lib/utils/evaluator.js +93 -93
  36. package/lib/utils/identity.d.ts +1 -1
  37. package/lib/utils/identity.js +1 -1
  38. package/lib/utils/index.d.ts +46 -46
  39. package/lib/utils/index.js +125 -125
  40. package/lib/utils/noop.d.ts +1 -1
  41. package/lib/utils/noop.js +2 -2
  42. package/lib/utils/shallowEqual.d.ts +1 -1
  43. package/lib/utils/shallowEqual.js +21 -21
  44. package/lib/utils/slidingWindow.d.ts +19 -19
  45. package/lib/utils/slidingWindow.js +108 -108
  46. package/lib/utils/strokeDasharray.d.ts +3 -3
  47. package/lib/utils/strokeDasharray.js +36 -36
  48. package/lib/utils/zipper.d.ts +7 -7
  49. package/lib/utils/zipper.js +35 -35
  50. package/lib/zoom/index.d.ts +1 -1
  51. package/lib/zoom/index.js +1 -1
  52. package/lib/zoom/zoomBehavior.d.ts +10 -10
  53. package/lib/zoom/zoomBehavior.js +17 -17
  54. package/package.json +2 -2
  55. package/src/Chart.tsx +2 -2
  56. package/src/ChartCanvas.tsx +1 -1
  57. package/src/GenericComponent.tsx +1 -0
@@ -1,355 +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
- };
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
355
  //# sourceMappingURL=GenericComponent.js.map