@tradingaction/core 2.0.11 → 2.0.13
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 -24
- package/README.md +5 -5
- package/lib/CanvasContainer.d.ts +19 -19
- package/lib/CanvasContainer.js +27 -27
- package/lib/Chart.d.ts +32 -32
- package/lib/Chart.js +56 -56
- package/lib/Chart.js.map +1 -1
- package/lib/ChartCanvas.d.ts +235 -235
- package/lib/ChartCanvas.js +770 -770
- package/lib/ChartCanvas.js.map +1 -1
- package/lib/EventCapture.d.ts +131 -131
- package/lib/EventCapture.js +488 -488
- package/lib/GenericChartComponent.d.ts +21 -21
- package/lib/GenericChartComponent.js +74 -74
- package/lib/GenericComponent.d.ts +81 -81
- package/lib/GenericComponent.js +354 -354
- package/lib/GenericComponent.js.map +1 -1
- package/lib/MoreProps.d.ts +16 -16
- package/lib/MoreProps.js +1 -1
- package/lib/index.d.ts +7 -7
- package/lib/index.js +7 -7
- package/lib/useEvent.d.ts +1 -1
- package/lib/useEvent.js +12 -12
- package/lib/utils/ChartDataUtil.d.ts +49 -49
- package/lib/utils/ChartDataUtil.js +204 -204
- package/lib/utils/PureComponent.d.ts +4 -4
- package/lib/utils/PureComponent.js +9 -9
- package/lib/utils/accumulatingWindow.d.ts +15 -15
- package/lib/utils/accumulatingWindow.js +97 -97
- package/lib/utils/barWidth.d.ts +15 -15
- package/lib/utils/barWidth.js +26 -26
- package/lib/utils/closestItem.d.ts +5 -5
- package/lib/utils/closestItem.js +44 -44
- package/lib/utils/evaluator.d.ts +7 -7
- package/lib/utils/evaluator.js +93 -93
- package/lib/utils/identity.d.ts +1 -1
- package/lib/utils/identity.js +1 -1
- package/lib/utils/index.d.ts +46 -46
- package/lib/utils/index.js +125 -125
- package/lib/utils/noop.d.ts +1 -1
- package/lib/utils/noop.js +2 -2
- package/lib/utils/shallowEqual.d.ts +1 -1
- package/lib/utils/shallowEqual.js +21 -21
- package/lib/utils/slidingWindow.d.ts +19 -19
- package/lib/utils/slidingWindow.js +108 -108
- package/lib/utils/strokeDasharray.d.ts +3 -3
- package/lib/utils/strokeDasharray.js +36 -36
- package/lib/utils/zipper.d.ts +7 -7
- package/lib/utils/zipper.js +35 -35
- package/lib/zoom/index.d.ts +1 -1
- package/lib/zoom/index.js +1 -1
- package/lib/zoom/zoomBehavior.d.ts +10 -10
- package/lib/zoom/zoomBehavior.js +17 -17
- package/package.json +2 -2
- package/src/Chart.tsx +2 -2
- package/src/ChartCanvas.tsx +1 -1
- package/src/GenericComponent.tsx +1 -0
|
@@ -1,205 +1,205 @@
|
|
|
1
|
-
import { extent } from "d3-array";
|
|
2
|
-
import { scaleLinear } from "d3-scale";
|
|
3
|
-
import flattenDeep from "lodash.flattendeep";
|
|
4
|
-
import * as React from "react";
|
|
5
|
-
import { functor, getClosestItem, isNotDefined, isObject, last, mapObject, shallowEqual, zipper } from "./index";
|
|
6
|
-
export const ChartDefaultConfig = {
|
|
7
|
-
flipYScale: false,
|
|
8
|
-
id: 0,
|
|
9
|
-
origin: [0, 0],
|
|
10
|
-
padding: 0,
|
|
11
|
-
yPan: true,
|
|
12
|
-
yPanEnabled: false,
|
|
13
|
-
yScale: scaleLinear(),
|
|
14
|
-
};
|
|
15
|
-
export function getChartOrigin(origin, contextWidth, contextHeight) {
|
|
16
|
-
const originCoordinates = typeof origin === "function" ? origin(contextWidth, contextHeight) : origin;
|
|
17
|
-
return originCoordinates;
|
|
18
|
-
}
|
|
19
|
-
export function getDimensions({ width, height }, chartProps) {
|
|
20
|
-
const chartHeight = chartProps.height || height;
|
|
21
|
-
return {
|
|
22
|
-
availableHeight: height,
|
|
23
|
-
width,
|
|
24
|
-
height: chartHeight,
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
function values(func) {
|
|
28
|
-
return (d) => {
|
|
29
|
-
const obj = func(d);
|
|
30
|
-
if (isObject(obj)) {
|
|
31
|
-
return mapObject(obj);
|
|
32
|
-
}
|
|
33
|
-
return obj;
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
function isArraySize2AndNumber(yExtentsProp) {
|
|
37
|
-
if (Array.isArray(yExtentsProp) && yExtentsProp.length === 2) {
|
|
38
|
-
const [a, b] = yExtentsProp;
|
|
39
|
-
return typeof a === "number" && typeof b === "number";
|
|
40
|
-
}
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
const isChartProps = (props) => {
|
|
44
|
-
if (props === undefined) {
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
const chartProps = props;
|
|
48
|
-
if (chartProps.id === undefined) {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
return true;
|
|
52
|
-
};
|
|
53
|
-
export function getNewChartConfig(innerDimension, children, existingChartConfig = []) {
|
|
54
|
-
return React.Children.map(children, (each) => {
|
|
55
|
-
if (!each || !isChartProps(each.props)) {
|
|
56
|
-
return undefined;
|
|
57
|
-
}
|
|
58
|
-
const chartProps = Object.assign(Object.assign({}, ChartDefaultConfig), each.props);
|
|
59
|
-
const { id, origin, padding, yExtents: yExtentsProp, yScale: yScaleProp = ChartDefaultConfig.yScale, flipYScale, yExtentsCalculator, } = chartProps;
|
|
60
|
-
const yScale = yScaleProp.copy();
|
|
61
|
-
const { width, height, availableHeight } = getDimensions(innerDimension, chartProps);
|
|
62
|
-
const { yPan } = chartProps;
|
|
63
|
-
let { yPanEnabled } = chartProps;
|
|
64
|
-
const yExtents = yExtentsProp
|
|
65
|
-
? (Array.isArray(yExtentsProp) ? yExtentsProp : [yExtentsProp]).map(functor)
|
|
66
|
-
: undefined;
|
|
67
|
-
const prevChartConfig = existingChartConfig.find((d) => d.id === id);
|
|
68
|
-
if (isArraySize2AndNumber(yExtentsProp)) {
|
|
69
|
-
if (!!prevChartConfig &&
|
|
70
|
-
prevChartConfig.yPan &&
|
|
71
|
-
prevChartConfig.yPanEnabled &&
|
|
72
|
-
yPan &&
|
|
73
|
-
yPanEnabled &&
|
|
74
|
-
shallowEqual(prevChartConfig.originalYExtentsProp, yExtentsProp)) {
|
|
75
|
-
yScale.domain(prevChartConfig.yScale.domain());
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
const [a, b] = yExtentsProp;
|
|
79
|
-
yScale.domain([a, b]);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
else if (!!prevChartConfig && prevChartConfig.yPanEnabled) {
|
|
83
|
-
if (isArraySize2AndNumber(prevChartConfig.originalYExtentsProp)) {
|
|
84
|
-
// do nothing
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
yScale.domain(prevChartConfig.yScale.domain());
|
|
88
|
-
yPanEnabled = true;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return {
|
|
92
|
-
id,
|
|
93
|
-
origin: functor(origin)(width, availableHeight),
|
|
94
|
-
padding,
|
|
95
|
-
originalYExtentsProp: yExtentsProp,
|
|
96
|
-
yExtents,
|
|
97
|
-
yExtentsCalculator,
|
|
98
|
-
flipYScale,
|
|
99
|
-
yScale,
|
|
100
|
-
yPan,
|
|
101
|
-
yPanEnabled,
|
|
102
|
-
width,
|
|
103
|
-
height,
|
|
104
|
-
};
|
|
105
|
-
}).filter((each) => each !== undefined);
|
|
106
|
-
}
|
|
107
|
-
export function getCurrentCharts(chartConfig, mouseXY) {
|
|
108
|
-
const currentCharts = chartConfig
|
|
109
|
-
.filter((eachConfig) => {
|
|
110
|
-
const top = eachConfig.origin[1];
|
|
111
|
-
const bottom = top + eachConfig.height;
|
|
112
|
-
return mouseXY[1] > top && mouseXY[1] < bottom;
|
|
113
|
-
})
|
|
114
|
-
.map((config) => config.id);
|
|
115
|
-
return currentCharts;
|
|
116
|
-
}
|
|
117
|
-
function setRange(scale, height, padding, flipYScale) {
|
|
118
|
-
if (scale.rangeRoundPoints || isNotDefined(scale.invert)) {
|
|
119
|
-
if (isNaN(padding)) {
|
|
120
|
-
throw new Error("padding has to be a number for ordinal scale");
|
|
121
|
-
}
|
|
122
|
-
if (scale.rangeRoundPoints) {
|
|
123
|
-
scale.rangeRoundPoints(flipYScale ? [0, height] : [height, 0], padding);
|
|
124
|
-
}
|
|
125
|
-
if (scale.rangeRound) {
|
|
126
|
-
scale.range(flipYScale ? [0, height] : [height, 0]).padding(padding);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
const { top, bottom } = isNaN(padding) ? padding : { top: padding, bottom: padding };
|
|
131
|
-
scale.range(flipYScale ? [top, height - bottom] : [height - bottom, top]);
|
|
132
|
-
}
|
|
133
|
-
return scale;
|
|
134
|
-
}
|
|
135
|
-
function yDomainFromYExtents(yExtents, yScale, plotData) {
|
|
136
|
-
const yValues = yExtents.map((eachExtent) => plotData.map(values(eachExtent)));
|
|
137
|
-
const allYValues = flattenDeep(yValues);
|
|
138
|
-
const realYDomain = yScale.invert ? extent(allYValues) : [...new Set(allYValues).values()];
|
|
139
|
-
return realYDomain;
|
|
140
|
-
}
|
|
141
|
-
export function getChartConfigWithUpdatedYScales(chartConfig, { plotData, xAccessor, displayXAccessor, fullData }, xDomain, dy, chartsToPan) {
|
|
142
|
-
const yDomains = chartConfig.map(({ yExtentsCalculator, yExtents, yScale }) => {
|
|
143
|
-
const realYDomain = yExtentsCalculator
|
|
144
|
-
? yExtentsCalculator({ plotData, xDomain, xAccessor, displayXAccessor, fullData })
|
|
145
|
-
: yDomainFromYExtents(yExtents, yScale, plotData);
|
|
146
|
-
const yDomainDY = dy !== undefined
|
|
147
|
-
? yScale
|
|
148
|
-
.range()
|
|
149
|
-
.map((each) => each - dy)
|
|
150
|
-
.map(yScale.invert)
|
|
151
|
-
: yScale.domain();
|
|
152
|
-
return {
|
|
153
|
-
realYDomain,
|
|
154
|
-
yDomainDY,
|
|
155
|
-
prevYDomain: yScale.domain(),
|
|
156
|
-
};
|
|
157
|
-
});
|
|
158
|
-
const combine = zipper().combine((config, { realYDomain, yDomainDY, prevYDomain }) => {
|
|
159
|
-
const { id, padding, height, yScale, yPan, flipYScale, yPanEnabled = false } = config;
|
|
160
|
-
const another = chartsToPan !== undefined ? chartsToPan.indexOf(id) > -1 : true;
|
|
161
|
-
const domain = yPan && yPanEnabled ? (another ? yDomainDY : prevYDomain) : realYDomain;
|
|
162
|
-
const newYScale = setRange(yScale.copy().domain(domain), height, padding, flipYScale);
|
|
163
|
-
return Object.assign(Object.assign({}, config), { yScale: newYScale, realYDomain });
|
|
164
|
-
});
|
|
165
|
-
const updatedChartConfig = combine(chartConfig, yDomains);
|
|
166
|
-
return updatedChartConfig;
|
|
167
|
-
}
|
|
168
|
-
export function getCurrentItem(xScale, xAccessor, mouseXY, plotData) {
|
|
169
|
-
let xValue;
|
|
170
|
-
let item;
|
|
171
|
-
if (xScale.invert) {
|
|
172
|
-
xValue = xScale.invert(mouseXY[0]);
|
|
173
|
-
item = getClosestItem(plotData, xValue, xAccessor);
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
const dr = xScale
|
|
177
|
-
.range()
|
|
178
|
-
.map((d, idx) => ({ x: Math.abs(d - mouseXY[0]), idx }))
|
|
179
|
-
.reduce((a, b) => (a.x < b.x ? a : b));
|
|
180
|
-
item = dr !== undefined ? plotData[dr.idx] : plotData[0];
|
|
181
|
-
}
|
|
182
|
-
return item;
|
|
183
|
-
}
|
|
184
|
-
export function getXValue(xScale, xAccessor, mouseXY, plotData) {
|
|
185
|
-
let xValue;
|
|
186
|
-
let item;
|
|
187
|
-
if (xScale.invert) {
|
|
188
|
-
xValue = xScale.invert(mouseXY[0]);
|
|
189
|
-
if (xValue > xAccessor(last(plotData))) {
|
|
190
|
-
return Math.round(xValue.valueOf());
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
item = getClosestItem(plotData, xValue, xAccessor);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
const dr = xScale
|
|
198
|
-
.range()
|
|
199
|
-
.map((d, idx) => ({ x: Math.abs(d - mouseXY[0]), idx }))
|
|
200
|
-
.reduce((a, b) => (a.x < b.x ? a : b));
|
|
201
|
-
item = dr !== undefined ? plotData[dr.idx] : plotData[0];
|
|
202
|
-
}
|
|
203
|
-
return xAccessor(item);
|
|
204
|
-
}
|
|
1
|
+
import { extent } from "d3-array";
|
|
2
|
+
import { scaleLinear } from "d3-scale";
|
|
3
|
+
import flattenDeep from "lodash.flattendeep";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { functor, getClosestItem, isNotDefined, isObject, last, mapObject, shallowEqual, zipper } from "./index";
|
|
6
|
+
export const ChartDefaultConfig = {
|
|
7
|
+
flipYScale: false,
|
|
8
|
+
id: 0,
|
|
9
|
+
origin: [0, 0],
|
|
10
|
+
padding: 0,
|
|
11
|
+
yPan: true,
|
|
12
|
+
yPanEnabled: false,
|
|
13
|
+
yScale: scaleLinear(),
|
|
14
|
+
};
|
|
15
|
+
export function getChartOrigin(origin, contextWidth, contextHeight) {
|
|
16
|
+
const originCoordinates = typeof origin === "function" ? origin(contextWidth, contextHeight) : origin;
|
|
17
|
+
return originCoordinates;
|
|
18
|
+
}
|
|
19
|
+
export function getDimensions({ width, height }, chartProps) {
|
|
20
|
+
const chartHeight = chartProps.height || height;
|
|
21
|
+
return {
|
|
22
|
+
availableHeight: height,
|
|
23
|
+
width,
|
|
24
|
+
height: chartHeight,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function values(func) {
|
|
28
|
+
return (d) => {
|
|
29
|
+
const obj = func(d);
|
|
30
|
+
if (isObject(obj)) {
|
|
31
|
+
return mapObject(obj);
|
|
32
|
+
}
|
|
33
|
+
return obj;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function isArraySize2AndNumber(yExtentsProp) {
|
|
37
|
+
if (Array.isArray(yExtentsProp) && yExtentsProp.length === 2) {
|
|
38
|
+
const [a, b] = yExtentsProp;
|
|
39
|
+
return typeof a === "number" && typeof b === "number";
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
const isChartProps = (props) => {
|
|
44
|
+
if (props === undefined) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
const chartProps = props;
|
|
48
|
+
if (chartProps.id === undefined) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
return true;
|
|
52
|
+
};
|
|
53
|
+
export function getNewChartConfig(innerDimension, children, existingChartConfig = []) {
|
|
54
|
+
return React.Children.map(children, (each) => {
|
|
55
|
+
if (!each || !isChartProps(each.props)) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
const chartProps = Object.assign(Object.assign({}, ChartDefaultConfig), each.props);
|
|
59
|
+
const { id, origin, padding, yExtents: yExtentsProp, yScale: yScaleProp = ChartDefaultConfig.yScale, flipYScale, yExtentsCalculator, } = chartProps;
|
|
60
|
+
const yScale = yScaleProp.copy();
|
|
61
|
+
const { width, height, availableHeight } = getDimensions(innerDimension, chartProps);
|
|
62
|
+
const { yPan } = chartProps;
|
|
63
|
+
let { yPanEnabled } = chartProps;
|
|
64
|
+
const yExtents = yExtentsProp
|
|
65
|
+
? (Array.isArray(yExtentsProp) ? yExtentsProp : [yExtentsProp]).map(functor)
|
|
66
|
+
: undefined;
|
|
67
|
+
const prevChartConfig = existingChartConfig.find((d) => d.id === id);
|
|
68
|
+
if (isArraySize2AndNumber(yExtentsProp)) {
|
|
69
|
+
if (!!prevChartConfig &&
|
|
70
|
+
prevChartConfig.yPan &&
|
|
71
|
+
prevChartConfig.yPanEnabled &&
|
|
72
|
+
yPan &&
|
|
73
|
+
yPanEnabled &&
|
|
74
|
+
shallowEqual(prevChartConfig.originalYExtentsProp, yExtentsProp)) {
|
|
75
|
+
yScale.domain(prevChartConfig.yScale.domain());
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
const [a, b] = yExtentsProp;
|
|
79
|
+
yScale.domain([a, b]);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else if (!!prevChartConfig && prevChartConfig.yPanEnabled) {
|
|
83
|
+
if (isArraySize2AndNumber(prevChartConfig.originalYExtentsProp)) {
|
|
84
|
+
// do nothing
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
yScale.domain(prevChartConfig.yScale.domain());
|
|
88
|
+
yPanEnabled = true;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
id,
|
|
93
|
+
origin: functor(origin)(width, availableHeight),
|
|
94
|
+
padding,
|
|
95
|
+
originalYExtentsProp: yExtentsProp,
|
|
96
|
+
yExtents,
|
|
97
|
+
yExtentsCalculator,
|
|
98
|
+
flipYScale,
|
|
99
|
+
yScale,
|
|
100
|
+
yPan,
|
|
101
|
+
yPanEnabled,
|
|
102
|
+
width,
|
|
103
|
+
height,
|
|
104
|
+
};
|
|
105
|
+
}).filter((each) => each !== undefined);
|
|
106
|
+
}
|
|
107
|
+
export function getCurrentCharts(chartConfig, mouseXY) {
|
|
108
|
+
const currentCharts = chartConfig
|
|
109
|
+
.filter((eachConfig) => {
|
|
110
|
+
const top = eachConfig.origin[1];
|
|
111
|
+
const bottom = top + eachConfig.height;
|
|
112
|
+
return mouseXY[1] > top && mouseXY[1] < bottom;
|
|
113
|
+
})
|
|
114
|
+
.map((config) => config.id);
|
|
115
|
+
return currentCharts;
|
|
116
|
+
}
|
|
117
|
+
function setRange(scale, height, padding, flipYScale) {
|
|
118
|
+
if (scale.rangeRoundPoints || isNotDefined(scale.invert)) {
|
|
119
|
+
if (isNaN(padding)) {
|
|
120
|
+
throw new Error("padding has to be a number for ordinal scale");
|
|
121
|
+
}
|
|
122
|
+
if (scale.rangeRoundPoints) {
|
|
123
|
+
scale.rangeRoundPoints(flipYScale ? [0, height] : [height, 0], padding);
|
|
124
|
+
}
|
|
125
|
+
if (scale.rangeRound) {
|
|
126
|
+
scale.range(flipYScale ? [0, height] : [height, 0]).padding(padding);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
const { top, bottom } = isNaN(padding) ? padding : { top: padding, bottom: padding };
|
|
131
|
+
scale.range(flipYScale ? [top, height - bottom] : [height - bottom, top]);
|
|
132
|
+
}
|
|
133
|
+
return scale;
|
|
134
|
+
}
|
|
135
|
+
function yDomainFromYExtents(yExtents, yScale, plotData) {
|
|
136
|
+
const yValues = yExtents.map((eachExtent) => plotData.map(values(eachExtent)));
|
|
137
|
+
const allYValues = flattenDeep(yValues);
|
|
138
|
+
const realYDomain = yScale.invert ? extent(allYValues) : [...new Set(allYValues).values()];
|
|
139
|
+
return realYDomain;
|
|
140
|
+
}
|
|
141
|
+
export function getChartConfigWithUpdatedYScales(chartConfig, { plotData, xAccessor, displayXAccessor, fullData }, xDomain, dy, chartsToPan) {
|
|
142
|
+
const yDomains = chartConfig.map(({ yExtentsCalculator, yExtents, yScale }) => {
|
|
143
|
+
const realYDomain = yExtentsCalculator
|
|
144
|
+
? yExtentsCalculator({ plotData, xDomain, xAccessor, displayXAccessor, fullData })
|
|
145
|
+
: yDomainFromYExtents(yExtents, yScale, plotData);
|
|
146
|
+
const yDomainDY = dy !== undefined
|
|
147
|
+
? yScale
|
|
148
|
+
.range()
|
|
149
|
+
.map((each) => each - dy)
|
|
150
|
+
.map(yScale.invert)
|
|
151
|
+
: yScale.domain();
|
|
152
|
+
return {
|
|
153
|
+
realYDomain,
|
|
154
|
+
yDomainDY,
|
|
155
|
+
prevYDomain: yScale.domain(),
|
|
156
|
+
};
|
|
157
|
+
});
|
|
158
|
+
const combine = zipper().combine((config, { realYDomain, yDomainDY, prevYDomain }) => {
|
|
159
|
+
const { id, padding, height, yScale, yPan, flipYScale, yPanEnabled = false } = config;
|
|
160
|
+
const another = chartsToPan !== undefined ? chartsToPan.indexOf(id) > -1 : true;
|
|
161
|
+
const domain = yPan && yPanEnabled ? (another ? yDomainDY : prevYDomain) : realYDomain;
|
|
162
|
+
const newYScale = setRange(yScale.copy().domain(domain), height, padding, flipYScale);
|
|
163
|
+
return Object.assign(Object.assign({}, config), { yScale: newYScale, realYDomain });
|
|
164
|
+
});
|
|
165
|
+
const updatedChartConfig = combine(chartConfig, yDomains);
|
|
166
|
+
return updatedChartConfig;
|
|
167
|
+
}
|
|
168
|
+
export function getCurrentItem(xScale, xAccessor, mouseXY, plotData) {
|
|
169
|
+
let xValue;
|
|
170
|
+
let item;
|
|
171
|
+
if (xScale.invert) {
|
|
172
|
+
xValue = xScale.invert(mouseXY[0]);
|
|
173
|
+
item = getClosestItem(plotData, xValue, xAccessor);
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
const dr = xScale
|
|
177
|
+
.range()
|
|
178
|
+
.map((d, idx) => ({ x: Math.abs(d - mouseXY[0]), idx }))
|
|
179
|
+
.reduce((a, b) => (a.x < b.x ? a : b));
|
|
180
|
+
item = dr !== undefined ? plotData[dr.idx] : plotData[0];
|
|
181
|
+
}
|
|
182
|
+
return item;
|
|
183
|
+
}
|
|
184
|
+
export function getXValue(xScale, xAccessor, mouseXY, plotData) {
|
|
185
|
+
let xValue;
|
|
186
|
+
let item;
|
|
187
|
+
if (xScale.invert) {
|
|
188
|
+
xValue = xScale.invert(mouseXY[0]);
|
|
189
|
+
if (xValue > xAccessor(last(plotData))) {
|
|
190
|
+
return Math.round(xValue.valueOf());
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
item = getClosestItem(plotData, xValue, xAccessor);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
const dr = xScale
|
|
198
|
+
.range()
|
|
199
|
+
.map((d, idx) => ({ x: Math.abs(d - mouseXY[0]), idx }))
|
|
200
|
+
.reduce((a, b) => (a.x < b.x ? a : b));
|
|
201
|
+
item = dr !== undefined ? plotData[dr.idx] : plotData[0];
|
|
202
|
+
}
|
|
203
|
+
return xAccessor(item);
|
|
204
|
+
}
|
|
205
205
|
//# sourceMappingURL=ChartDataUtil.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
export declare class PureComponent<T, S = {}, SS = any> extends React.Component<T, S, SS> {
|
|
3
|
-
shouldComponentUpdate(nextProps: T, nextState: S, nextContext: SS): boolean;
|
|
4
|
-
}
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export declare class PureComponent<T, S = {}, SS = any> extends React.Component<T, S, SS> {
|
|
3
|
+
shouldComponentUpdate(nextProps: T, nextState: S, nextContext: SS): boolean;
|
|
4
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { shallowEqual } from "./shallowEqual";
|
|
3
|
-
export class PureComponent extends React.Component {
|
|
4
|
-
shouldComponentUpdate(nextProps, nextState, nextContext) {
|
|
5
|
-
return (!shallowEqual(this.props, nextProps) ||
|
|
6
|
-
!shallowEqual(this.state, nextState) ||
|
|
7
|
-
!shallowEqual(this.context, nextContext));
|
|
8
|
-
}
|
|
9
|
-
}
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { shallowEqual } from "./shallowEqual";
|
|
3
|
+
export class PureComponent extends React.Component {
|
|
4
|
+
shouldComponentUpdate(nextProps, nextState, nextContext) {
|
|
5
|
+
return (!shallowEqual(this.props, nextProps) ||
|
|
6
|
+
!shallowEqual(this.state, nextState) ||
|
|
7
|
+
!shallowEqual(this.context, nextContext));
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
10
|
//# sourceMappingURL=PureComponent.js.map
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
interface AccumulatingWindow {
|
|
2
|
-
(data: any[]): any[];
|
|
3
|
-
accumulateTill(): any;
|
|
4
|
-
accumulateTill(x: any): AccumulatingWindow;
|
|
5
|
-
accumulator(): any;
|
|
6
|
-
accumulator(x: any): AccumulatingWindow;
|
|
7
|
-
value(): any;
|
|
8
|
-
value(x: any): AccumulatingWindow;
|
|
9
|
-
discardTillStart(): boolean;
|
|
10
|
-
discardTillStart(x: boolean): AccumulatingWindow;
|
|
11
|
-
discardTillEnd(): boolean;
|
|
12
|
-
discardTillEnd(x: boolean): AccumulatingWindow;
|
|
13
|
-
}
|
|
14
|
-
export default function (): AccumulatingWindow;
|
|
15
|
-
export {};
|
|
1
|
+
interface AccumulatingWindow {
|
|
2
|
+
(data: any[]): any[];
|
|
3
|
+
accumulateTill(): any;
|
|
4
|
+
accumulateTill(x: any): AccumulatingWindow;
|
|
5
|
+
accumulator(): any;
|
|
6
|
+
accumulator(x: any): AccumulatingWindow;
|
|
7
|
+
value(): any;
|
|
8
|
+
value(x: any): AccumulatingWindow;
|
|
9
|
+
discardTillStart(): boolean;
|
|
10
|
+
discardTillStart(x: boolean): AccumulatingWindow;
|
|
11
|
+
discardTillEnd(): boolean;
|
|
12
|
+
discardTillEnd(x: boolean): AccumulatingWindow;
|
|
13
|
+
}
|
|
14
|
+
export default function (): AccumulatingWindow;
|
|
15
|
+
export {};
|
|
@@ -1,98 +1,98 @@
|
|
|
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
|
-
import { identity } from "./identity";
|
|
29
|
-
import { functor } from "./index";
|
|
30
|
-
import { noop } from "./noop";
|
|
31
|
-
export default function () {
|
|
32
|
-
let accumulateTill = functor(false);
|
|
33
|
-
let accumulator = noop;
|
|
34
|
-
let value = identity;
|
|
35
|
-
let discardTillStart = false;
|
|
36
|
-
let discardTillEnd = false;
|
|
37
|
-
const accumulatingWindow = function (data) {
|
|
38
|
-
let accumulatedWindow = discardTillStart ? undefined : [];
|
|
39
|
-
const response = [];
|
|
40
|
-
let accumulatorIdx = 0;
|
|
41
|
-
let i = 0;
|
|
42
|
-
for (i = 0; i < data.length; i++) {
|
|
43
|
-
const d = data[i];
|
|
44
|
-
if (accumulateTill(d, i, accumulatedWindow || [])) {
|
|
45
|
-
if (accumulatedWindow && accumulatedWindow.length > 0) {
|
|
46
|
-
// @ts-ignore
|
|
47
|
-
response.push(accumulator(accumulatedWindow, i, accumulatorIdx++));
|
|
48
|
-
}
|
|
49
|
-
accumulatedWindow = [value(d)];
|
|
50
|
-
}
|
|
51
|
-
else if (accumulatedWindow) {
|
|
52
|
-
accumulatedWindow.push(value(d));
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
if (!discardTillEnd) {
|
|
56
|
-
// @ts-ignore
|
|
57
|
-
response.push(accumulator(accumulatedWindow, i, accumulatorIdx));
|
|
58
|
-
}
|
|
59
|
-
return response;
|
|
60
|
-
};
|
|
61
|
-
accumulatingWindow.accumulateTill = function (x) {
|
|
62
|
-
if (!arguments.length) {
|
|
63
|
-
return accumulateTill;
|
|
64
|
-
}
|
|
65
|
-
accumulateTill = functor(x);
|
|
66
|
-
return accumulatingWindow;
|
|
67
|
-
};
|
|
68
|
-
accumulatingWindow.accumulator = function (x) {
|
|
69
|
-
if (!arguments.length) {
|
|
70
|
-
return accumulator;
|
|
71
|
-
}
|
|
72
|
-
accumulator = x;
|
|
73
|
-
return accumulatingWindow;
|
|
74
|
-
};
|
|
75
|
-
accumulatingWindow.value = function (x) {
|
|
76
|
-
if (!arguments.length) {
|
|
77
|
-
return value;
|
|
78
|
-
}
|
|
79
|
-
value = x;
|
|
80
|
-
return accumulatingWindow;
|
|
81
|
-
};
|
|
82
|
-
accumulatingWindow.discardTillStart = function (x) {
|
|
83
|
-
if (!arguments.length) {
|
|
84
|
-
return discardTillStart;
|
|
85
|
-
}
|
|
86
|
-
discardTillStart = x;
|
|
87
|
-
return accumulatingWindow;
|
|
88
|
-
};
|
|
89
|
-
accumulatingWindow.discardTillEnd = function (x) {
|
|
90
|
-
if (!arguments.length) {
|
|
91
|
-
return discardTillEnd;
|
|
92
|
-
}
|
|
93
|
-
discardTillEnd = x;
|
|
94
|
-
return accumulatingWindow;
|
|
95
|
-
};
|
|
96
|
-
return accumulatingWindow;
|
|
97
|
-
}
|
|
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
|
+
import { identity } from "./identity";
|
|
29
|
+
import { functor } from "./index";
|
|
30
|
+
import { noop } from "./noop";
|
|
31
|
+
export default function () {
|
|
32
|
+
let accumulateTill = functor(false);
|
|
33
|
+
let accumulator = noop;
|
|
34
|
+
let value = identity;
|
|
35
|
+
let discardTillStart = false;
|
|
36
|
+
let discardTillEnd = false;
|
|
37
|
+
const accumulatingWindow = function (data) {
|
|
38
|
+
let accumulatedWindow = discardTillStart ? undefined : [];
|
|
39
|
+
const response = [];
|
|
40
|
+
let accumulatorIdx = 0;
|
|
41
|
+
let i = 0;
|
|
42
|
+
for (i = 0; i < data.length; i++) {
|
|
43
|
+
const d = data[i];
|
|
44
|
+
if (accumulateTill(d, i, accumulatedWindow || [])) {
|
|
45
|
+
if (accumulatedWindow && accumulatedWindow.length > 0) {
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
response.push(accumulator(accumulatedWindow, i, accumulatorIdx++));
|
|
48
|
+
}
|
|
49
|
+
accumulatedWindow = [value(d)];
|
|
50
|
+
}
|
|
51
|
+
else if (accumulatedWindow) {
|
|
52
|
+
accumulatedWindow.push(value(d));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (!discardTillEnd) {
|
|
56
|
+
// @ts-ignore
|
|
57
|
+
response.push(accumulator(accumulatedWindow, i, accumulatorIdx));
|
|
58
|
+
}
|
|
59
|
+
return response;
|
|
60
|
+
};
|
|
61
|
+
accumulatingWindow.accumulateTill = function (x) {
|
|
62
|
+
if (!arguments.length) {
|
|
63
|
+
return accumulateTill;
|
|
64
|
+
}
|
|
65
|
+
accumulateTill = functor(x);
|
|
66
|
+
return accumulatingWindow;
|
|
67
|
+
};
|
|
68
|
+
accumulatingWindow.accumulator = function (x) {
|
|
69
|
+
if (!arguments.length) {
|
|
70
|
+
return accumulator;
|
|
71
|
+
}
|
|
72
|
+
accumulator = x;
|
|
73
|
+
return accumulatingWindow;
|
|
74
|
+
};
|
|
75
|
+
accumulatingWindow.value = function (x) {
|
|
76
|
+
if (!arguments.length) {
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
value = x;
|
|
80
|
+
return accumulatingWindow;
|
|
81
|
+
};
|
|
82
|
+
accumulatingWindow.discardTillStart = function (x) {
|
|
83
|
+
if (!arguments.length) {
|
|
84
|
+
return discardTillStart;
|
|
85
|
+
}
|
|
86
|
+
discardTillStart = x;
|
|
87
|
+
return accumulatingWindow;
|
|
88
|
+
};
|
|
89
|
+
accumulatingWindow.discardTillEnd = function (x) {
|
|
90
|
+
if (!arguments.length) {
|
|
91
|
+
return discardTillEnd;
|
|
92
|
+
}
|
|
93
|
+
discardTillEnd = x;
|
|
94
|
+
return accumulatingWindow;
|
|
95
|
+
};
|
|
96
|
+
return accumulatingWindow;
|
|
97
|
+
}
|
|
98
98
|
//# sourceMappingURL=accumulatingWindow.js.map
|