@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,153 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export { default as zipper } from "./zipper";
|
|
3
|
+
export { default as slidingWindow } from "./slidingWindow";
|
|
4
|
+
export * from "./closestItem";
|
|
5
|
+
export * from "./identity";
|
|
6
|
+
export * from "./noop";
|
|
7
|
+
export * from "./shallowEqual";
|
|
8
|
+
export { default as accumulatingWindow } from "./accumulatingWindow";
|
|
9
|
+
export * from "./barWidth";
|
|
10
|
+
export * from "./strokeDasharray";
|
|
11
|
+
export * from "./PureComponent";
|
|
12
|
+
|
|
13
|
+
export const sign = (x: any) => {
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
return (x > 0) - (x < 0);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const path = (loc = []) => {
|
|
19
|
+
const key = Array.isArray(loc) ? loc : [loc];
|
|
20
|
+
const length = key.length;
|
|
21
|
+
|
|
22
|
+
return function (obj: any, defaultValue?: any) {
|
|
23
|
+
if (length === 0) {
|
|
24
|
+
return isDefined(obj) ? obj : defaultValue;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let index = 0;
|
|
28
|
+
while (obj != null && index < length) {
|
|
29
|
+
obj = obj[key[index++]];
|
|
30
|
+
}
|
|
31
|
+
return index === length ? obj : defaultValue;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const functor = (v: any) => {
|
|
36
|
+
return typeof v === "function" ? v : () => v;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export function getClosestValue(inputValue: any, currentValue: any) {
|
|
40
|
+
const values = Array.isArray(inputValue) ? inputValue : [inputValue];
|
|
41
|
+
|
|
42
|
+
const diff = values
|
|
43
|
+
.map((each) => each - currentValue)
|
|
44
|
+
.reduce((diff1, diff2) => (Math.abs(diff1) < Math.abs(diff2) ? diff1 : diff2));
|
|
45
|
+
return currentValue + diff;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function d3Window(node: any) {
|
|
49
|
+
const d3win =
|
|
50
|
+
node && ((node.ownerDocument && node.ownerDocument.defaultView) || (node.document && node) || node.defaultView);
|
|
51
|
+
return d3win;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const MOUSEENTER = "mouseenter.interaction";
|
|
55
|
+
export const MOUSELEAVE = "mouseleave.interaction";
|
|
56
|
+
export const MOUSEMOVE = "mousemove.pan";
|
|
57
|
+
export const MOUSEUP = "mouseup.pan";
|
|
58
|
+
export const TOUCHMOVE = "touchmove.pan";
|
|
59
|
+
export const TOUCHEND = "touchend.pan touchcancel.pan";
|
|
60
|
+
|
|
61
|
+
export function getTouchProps(touch: any) {
|
|
62
|
+
return {
|
|
63
|
+
pageX: touch.pageX,
|
|
64
|
+
pageY: touch.pageY,
|
|
65
|
+
clientX: touch.clientX,
|
|
66
|
+
clientY: touch.clientY,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function head(array: any[], accessor?: any) {
|
|
71
|
+
if (accessor && array) {
|
|
72
|
+
let value: any;
|
|
73
|
+
// tslint:disable-next-line: prefer-for-of
|
|
74
|
+
for (let i = 0; i < array.length; i++) {
|
|
75
|
+
value = array[i];
|
|
76
|
+
if (isDefined(accessor(value))) {
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return array ? array[0] : undefined;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export const first = head;
|
|
88
|
+
|
|
89
|
+
export function last(array: any[], accessor?: any) {
|
|
90
|
+
if (accessor && array) {
|
|
91
|
+
let value;
|
|
92
|
+
for (let i = array.length - 1; i >= 0; i--) {
|
|
93
|
+
value = array[i];
|
|
94
|
+
if (isDefined(accessor(value))) {
|
|
95
|
+
return value;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
const length = array ? array.length : 0;
|
|
101
|
+
return length ? array[length - 1] : undefined;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export const isDefined = <T>(d: T): d is NonNullable<T> => {
|
|
105
|
+
return d !== null && d !== undefined;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export function isNotDefined<T>(d: T) {
|
|
109
|
+
return !isDefined(d);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function isObject(d: any) {
|
|
113
|
+
return isDefined(d) && typeof d === "object" && !Array.isArray(d);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function touchPosition(touch: { clientX: number; clientY: number }, e: React.TouchEvent): [number, number] {
|
|
117
|
+
const container = e.currentTarget;
|
|
118
|
+
const rect = container.getBoundingClientRect();
|
|
119
|
+
const x = touch.clientX - rect.left - container.clientLeft;
|
|
120
|
+
const y = touch.clientY - rect.top - container.clientTop;
|
|
121
|
+
return [Math.round(x), Math.round(y)];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function mousePosition(
|
|
125
|
+
e: React.MouseEvent,
|
|
126
|
+
defaultRect?: { height: number; width: number; left: number; top: number },
|
|
127
|
+
): [number, number] {
|
|
128
|
+
const container = e.currentTarget;
|
|
129
|
+
const rect = defaultRect ?? container.getBoundingClientRect();
|
|
130
|
+
const x = e.clientX - rect.left - container.clientLeft;
|
|
131
|
+
const y = e.clientY - rect.top - container.clientTop;
|
|
132
|
+
return [Math.round(x), Math.round(y)];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function clearCanvas(canvasList: CanvasRenderingContext2D[], ratio: number) {
|
|
136
|
+
canvasList.forEach((each) => {
|
|
137
|
+
each.setTransform(1, 0, 0, 1, 0, 0);
|
|
138
|
+
each.clearRect(-1, -1, each.canvas.width + 2, each.canvas.height + 2);
|
|
139
|
+
each.scale(ratio, ratio);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// copied from https://github.com/lodash/lodash/blob/master/mapObject.js
|
|
144
|
+
export function mapObject(object = {}, iteratee = (x: any) => x) {
|
|
145
|
+
const props = Object.keys(object);
|
|
146
|
+
const result = new Array(props.length);
|
|
147
|
+
|
|
148
|
+
props.forEach((key, index) => {
|
|
149
|
+
// @ts-ignore
|
|
150
|
+
result[index] = iteratee(object[key], key, object);
|
|
151
|
+
});
|
|
152
|
+
return result;
|
|
153
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export const shallowEqual = (a: any, b: any) => {
|
|
2
|
+
if (a === b) {
|
|
3
|
+
return true;
|
|
4
|
+
}
|
|
5
|
+
if (!(a instanceof Object) || !(b instanceof Object)) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const keys = Object.keys(a);
|
|
10
|
+
const length = keys.length;
|
|
11
|
+
|
|
12
|
+
for (let i = 0; i < length; i++) {
|
|
13
|
+
if (!(keys[i] in b)) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
for (let i = 0; i < length; i++) {
|
|
19
|
+
if (a[keys[i]] !== b[keys[i]]) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return length === Object.keys(b).length;
|
|
25
|
+
};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
Taken from https://github.com/ScottLogic/d3fc/blob/master/src/indicator/algorithm/calculator/slidingWindow.js
|
|
4
|
+
|
|
5
|
+
The MIT License (MIT)
|
|
6
|
+
|
|
7
|
+
Copyright (c) 2014-2015 Scott Logic Ltd.
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in
|
|
17
|
+
all copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
25
|
+
THE SOFTWARE.
|
|
26
|
+
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import { functor, path } from "./index";
|
|
30
|
+
import { noop } from "./noop";
|
|
31
|
+
|
|
32
|
+
interface SlidingWindow {
|
|
33
|
+
(data: any[]): any[];
|
|
34
|
+
misc(): any;
|
|
35
|
+
misc(x: any): SlidingWindow;
|
|
36
|
+
accumulator(): any;
|
|
37
|
+
accumulator(x: any): SlidingWindow;
|
|
38
|
+
skipInitial(): number;
|
|
39
|
+
skipInitial(x: number): SlidingWindow;
|
|
40
|
+
source(): any;
|
|
41
|
+
source(source: any): SlidingWindow;
|
|
42
|
+
sourcePath(): any;
|
|
43
|
+
sourcePath(x: any): SlidingWindow;
|
|
44
|
+
windowSize(): number;
|
|
45
|
+
windowSize(windowSize: number): SlidingWindow;
|
|
46
|
+
undefinedValue(): any;
|
|
47
|
+
undefinedValue(x: any): SlidingWindow;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export default function () {
|
|
51
|
+
let undefinedValue: any;
|
|
52
|
+
let windowSize = 10;
|
|
53
|
+
let accumulator = noop;
|
|
54
|
+
let sourcePath: any;
|
|
55
|
+
let source: any;
|
|
56
|
+
let skipInitial = 0;
|
|
57
|
+
let misc: any;
|
|
58
|
+
|
|
59
|
+
const slidingWindow = (data: any[]) => {
|
|
60
|
+
const sourceFunction = source || path(sourcePath);
|
|
61
|
+
|
|
62
|
+
// @ts-ignore
|
|
63
|
+
const size = functor(windowSize).apply(this, arguments);
|
|
64
|
+
const windowData = data.slice(skipInitial, size + skipInitial).map(sourceFunction);
|
|
65
|
+
|
|
66
|
+
let accumulatorIdx = 0;
|
|
67
|
+
const undef = functor(undefinedValue);
|
|
68
|
+
return data.map((d, i) => {
|
|
69
|
+
if (i < skipInitial + size - 1) {
|
|
70
|
+
return undef(sourceFunction(d), i, misc);
|
|
71
|
+
}
|
|
72
|
+
if (i >= skipInitial + size) {
|
|
73
|
+
// Treat windowData as FIFO rolling buffer
|
|
74
|
+
windowData.shift();
|
|
75
|
+
windowData.push(sourceFunction(d, i));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// @ts-ignore
|
|
79
|
+
return accumulator(windowData, i, accumulatorIdx++, misc);
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
slidingWindow.undefinedValue = function (x: any) {
|
|
84
|
+
if (!arguments.length) {
|
|
85
|
+
return undefinedValue;
|
|
86
|
+
}
|
|
87
|
+
undefinedValue = x;
|
|
88
|
+
return slidingWindow;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
slidingWindow.windowSize = function (x: any) {
|
|
92
|
+
if (!arguments.length) {
|
|
93
|
+
return windowSize;
|
|
94
|
+
}
|
|
95
|
+
windowSize = x;
|
|
96
|
+
return slidingWindow;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
slidingWindow.misc = function (x: any) {
|
|
100
|
+
if (!arguments.length) {
|
|
101
|
+
return misc;
|
|
102
|
+
}
|
|
103
|
+
misc = x;
|
|
104
|
+
return slidingWindow;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
slidingWindow.accumulator = function (x: any) {
|
|
108
|
+
if (!arguments.length) {
|
|
109
|
+
return accumulator;
|
|
110
|
+
}
|
|
111
|
+
accumulator = x;
|
|
112
|
+
return slidingWindow;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
slidingWindow.skipInitial = function (x: any) {
|
|
116
|
+
if (!arguments.length) {
|
|
117
|
+
return skipInitial;
|
|
118
|
+
}
|
|
119
|
+
skipInitial = x;
|
|
120
|
+
return slidingWindow;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
slidingWindow.sourcePath = function (x: any) {
|
|
124
|
+
if (!arguments.length) {
|
|
125
|
+
return sourcePath;
|
|
126
|
+
}
|
|
127
|
+
sourcePath = x;
|
|
128
|
+
return slidingWindow;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
slidingWindow.source = function (x: any) {
|
|
132
|
+
if (!arguments.length) {
|
|
133
|
+
return source;
|
|
134
|
+
}
|
|
135
|
+
source = x;
|
|
136
|
+
return slidingWindow;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
return slidingWindow as SlidingWindow;
|
|
140
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export type strokeDashTypes =
|
|
2
|
+
| "Solid"
|
|
3
|
+
| "ShortDash"
|
|
4
|
+
| "ShortDash2"
|
|
5
|
+
| "ShortDot"
|
|
6
|
+
| "ShortDashDot"
|
|
7
|
+
| "ShortDashDotDot"
|
|
8
|
+
| "Dot"
|
|
9
|
+
| "Dash"
|
|
10
|
+
| "LongDash"
|
|
11
|
+
| "DashDot"
|
|
12
|
+
| "LongDashDot"
|
|
13
|
+
| "LongDashDotDot";
|
|
14
|
+
|
|
15
|
+
export const getStrokeDasharrayCanvas = (type?: strokeDashTypes) => {
|
|
16
|
+
const a = getStrokeDasharray(type).split(",");
|
|
17
|
+
if (a.length === 1) {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return a.map((d) => Number(d));
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const getStrokeDasharray = (type?: strokeDashTypes) => {
|
|
25
|
+
switch (type) {
|
|
26
|
+
default:
|
|
27
|
+
case "Solid":
|
|
28
|
+
return "none";
|
|
29
|
+
case "ShortDash":
|
|
30
|
+
return "6, 2";
|
|
31
|
+
case "ShortDash2":
|
|
32
|
+
return "6, 3";
|
|
33
|
+
case "ShortDot":
|
|
34
|
+
return "2, 2";
|
|
35
|
+
case "ShortDashDot":
|
|
36
|
+
return "6, 2, 2, 2";
|
|
37
|
+
case "ShortDashDotDot":
|
|
38
|
+
return "6, 2, 2, 2, 2, 2";
|
|
39
|
+
case "Dot":
|
|
40
|
+
return "2, 6";
|
|
41
|
+
case "Dash":
|
|
42
|
+
return "4, 6";
|
|
43
|
+
case "LongDash":
|
|
44
|
+
return "16, 6";
|
|
45
|
+
case "DashDot":
|
|
46
|
+
return "8, 6, 2, 6";
|
|
47
|
+
case "LongDashDot":
|
|
48
|
+
return "16, 6, 2, 6";
|
|
49
|
+
case "LongDashDotDot":
|
|
50
|
+
return "16, 6, 2, 6, 2, 6";
|
|
51
|
+
}
|
|
52
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/* an extension to d3.zip so we call a function instead of an array */
|
|
2
|
+
|
|
3
|
+
import { min } from "d3-array";
|
|
4
|
+
import { identity } from "./identity";
|
|
5
|
+
|
|
6
|
+
interface Zip {
|
|
7
|
+
(...args: any[]): any[];
|
|
8
|
+
combine(): any;
|
|
9
|
+
combine(x: any): Zip;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default function zipper() {
|
|
13
|
+
let combine = identity;
|
|
14
|
+
|
|
15
|
+
function zip() {
|
|
16
|
+
const n = arguments.length;
|
|
17
|
+
if (n === 0) {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
const m = min(arguments, d3_zipLength) ?? 0;
|
|
21
|
+
|
|
22
|
+
const zips = new Array(m);
|
|
23
|
+
for (let i = -1; ++i < m; ) {
|
|
24
|
+
// tslint:disable-next-line: no-shadowed-variable
|
|
25
|
+
for (let j = -1, zip = (zips[i] = new Array(n)); ++j < n; ) {
|
|
26
|
+
zip[j] = arguments[j][i];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
zips[i] = combine.apply(this, zips[i]);
|
|
31
|
+
}
|
|
32
|
+
return zips;
|
|
33
|
+
}
|
|
34
|
+
function d3_zipLength(d: any[]) {
|
|
35
|
+
return d.length;
|
|
36
|
+
}
|
|
37
|
+
zip.combine = function (x: any) {
|
|
38
|
+
if (!arguments.length) {
|
|
39
|
+
return combine;
|
|
40
|
+
}
|
|
41
|
+
combine = x;
|
|
42
|
+
return zip;
|
|
43
|
+
};
|
|
44
|
+
return zip as Zip;
|
|
45
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./zoomBehavior";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ScaleContinuousNumeric, ScaleTime } from "d3-scale";
|
|
2
|
+
import { getCurrentItem } from "../utils/ChartDataUtil";
|
|
3
|
+
import { last } from "../utils/index";
|
|
4
|
+
|
|
5
|
+
export interface IZoomAnchorOptions<TData, TXAxis extends number | Date> {
|
|
6
|
+
readonly plotData: TData[];
|
|
7
|
+
readonly mouseXY: number[];
|
|
8
|
+
readonly xAccessor: (data: TData) => TXAxis;
|
|
9
|
+
readonly xScale: ScaleContinuousNumeric<number, number> | ScaleTime<number, number>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const mouseBasedZoomAnchor = <TData, TXAxis extends number | Date>(
|
|
13
|
+
options: IZoomAnchorOptions<TData, TXAxis>,
|
|
14
|
+
) => {
|
|
15
|
+
const { xScale, xAccessor, mouseXY, plotData } = options;
|
|
16
|
+
const currentItem = getCurrentItem(xScale, xAccessor, mouseXY, plotData);
|
|
17
|
+
return xAccessor(currentItem);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const lastVisibleItemBasedZoomAnchor = <TData, TXAxis extends number | Date>(
|
|
21
|
+
options: IZoomAnchorOptions<TData, TXAxis>,
|
|
22
|
+
) => {
|
|
23
|
+
const { xAccessor, plotData } = options;
|
|
24
|
+
const lastItem = last(plotData);
|
|
25
|
+
return xAccessor(lastItem);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const rightDomainBasedZoomAnchor = <TData, TXAxis extends number | Date>(
|
|
29
|
+
options: IZoomAnchorOptions<TData, TXAxis>,
|
|
30
|
+
) => {
|
|
31
|
+
const { xScale } = options;
|
|
32
|
+
const [, end] = xScale.domain();
|
|
33
|
+
return end;
|
|
34
|
+
};
|