@tradingaction/series 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 -0
- package/README.md +5 -0
- package/lib/AlternateDataSeries.d.ts +5 -0
- package/lib/AlternateDataSeries.js +16 -0
- package/lib/AlternateDataSeries.js.map +1 -0
- package/lib/AlternatingFillAreaSeries.d.ts +77 -0
- package/lib/AlternatingFillAreaSeries.js +69 -0
- package/lib/AlternatingFillAreaSeries.js.map +1 -0
- package/lib/AreaOnlySeries.d.ts +42 -0
- package/lib/AreaOnlySeries.js +53 -0
- package/lib/AreaOnlySeries.js.map +1 -0
- package/lib/AreaSeries.d.ts +46 -0
- package/lib/AreaSeries.js +21 -0
- package/lib/AreaSeries.js.map +1 -0
- package/lib/BarSeries.d.ts +36 -0
- package/lib/BarSeries.js +91 -0
- package/lib/BarSeries.js.map +1 -0
- package/lib/BollingerSeries.d.ts +33 -0
- package/lib/BollingerSeries.js +59 -0
- package/lib/BollingerSeries.js.map +1 -0
- package/lib/CandlestickSeries.d.ts +65 -0
- package/lib/CandlestickSeries.js +115 -0
- package/lib/CandlestickSeries.js.map +1 -0
- package/lib/ElderRaySeries.d.ts +45 -0
- package/lib/ElderRaySeries.js +66 -0
- package/lib/ElderRaySeries.js.map +1 -0
- package/lib/GroupedBarSeries.d.ts +33 -0
- package/lib/GroupedBarSeries.js +22 -0
- package/lib/GroupedBarSeries.js.map +1 -0
- package/lib/KagiSeries.d.ts +45 -0
- package/lib/KagiSeries.js +108 -0
- package/lib/KagiSeries.js.map +1 -0
- package/lib/LineSeries.d.ts +84 -0
- package/lib/LineSeries.js +102 -0
- package/lib/LineSeries.js.map +1 -0
- package/lib/MACDSeries.d.ts +55 -0
- package/lib/MACDSeries.js +62 -0
- package/lib/MACDSeries.js.map +1 -0
- package/lib/OHLCSeries.d.ts +32 -0
- package/lib/OHLCSeries.js +67 -0
- package/lib/OHLCSeries.js.map +1 -0
- package/lib/OverlayBarSeries.d.ts +35 -0
- package/lib/OverlayBarSeries.js +71 -0
- package/lib/OverlayBarSeries.js.map +1 -0
- package/lib/PointAndFigureSeries.d.ts +33 -0
- package/lib/PointAndFigureSeries.js +92 -0
- package/lib/PointAndFigureSeries.js.map +1 -0
- package/lib/RSISeries.d.ts +68 -0
- package/lib/RSISeries.js +82 -0
- package/lib/RSISeries.js.map +1 -0
- package/lib/RenkoSeries.d.ts +42 -0
- package/lib/RenkoSeries.js +65 -0
- package/lib/RenkoSeries.js.map +1 -0
- package/lib/SARSeries.d.ts +34 -0
- package/lib/SARSeries.js +69 -0
- package/lib/SARSeries.js.map +1 -0
- package/lib/SVGComponent.d.ts +8 -0
- package/lib/SVGComponent.js +9 -0
- package/lib/SVGComponent.js.map +1 -0
- package/lib/ScatterSeries.d.ts +24 -0
- package/lib/ScatterSeries.js +60 -0
- package/lib/ScatterSeries.js.map +1 -0
- package/lib/StackedBarSeries.d.ts +44 -0
- package/lib/StackedBarSeries.js +157 -0
- package/lib/StackedBarSeries.js.map +1 -0
- package/lib/StochasticSeries.d.ts +39 -0
- package/lib/StochasticSeries.js +42 -0
- package/lib/StochasticSeries.js.map +1 -0
- package/lib/StraightLine.d.ts +38 -0
- package/lib/StraightLine.js +81 -0
- package/lib/StraightLine.js.map +1 -0
- package/lib/VolumeProfileSeries.d.ts +45 -0
- package/lib/VolumeProfileSeries.js +161 -0
- package/lib/VolumeProfileSeries.js.map +1 -0
- package/lib/index.d.ts +23 -0
- package/lib/index.js +24 -0
- package/lib/index.js.map +1 -0
- package/lib/markers/CircleMarker.d.ts +25 -0
- package/lib/markers/CircleMarker.js +35 -0
- package/lib/markers/CircleMarker.js.map +1 -0
- package/lib/markers/SquareMarker.d.ts +25 -0
- package/lib/markers/SquareMarker.js +37 -0
- package/lib/markers/SquareMarker.js.map +1 -0
- package/lib/markers/TriangleMarker.d.ts +27 -0
- package/lib/markers/TriangleMarker.js +89 -0
- package/lib/markers/TriangleMarker.js.map +1 -0
- package/lib/markers/index.d.ts +3 -0
- package/lib/markers/index.js +4 -0
- package/lib/markers/index.js.map +1 -0
- package/package.json +52 -0
- package/src/AlternateDataSeries.tsx +29 -0
- package/src/AlternatingFillAreaSeries.tsx +159 -0
- package/src/AreaOnlySeries.tsx +106 -0
- package/src/AreaSeries.tsx +95 -0
- package/src/BarSeries.tsx +151 -0
- package/src/BollingerSeries.tsx +90 -0
- package/src/CandlestickSeries.tsx +188 -0
- package/src/ElderRaySeries.tsx +99 -0
- package/src/GroupedBarSeries.tsx +48 -0
- package/src/KagiSeries.tsx +155 -0
- package/src/LineSeries.tsx +223 -0
- package/src/MACDSeries.tsx +110 -0
- package/src/OHLCSeries.tsx +116 -0
- package/src/OverlayBarSeries.tsx +115 -0
- package/src/PointAndFigureSeries.tsx +140 -0
- package/src/RSISeries.tsx +158 -0
- package/src/RenkoSeries.tsx +118 -0
- package/src/SARSeries.tsx +111 -0
- package/src/SVGComponent.tsx +13 -0
- package/src/ScatterSeries.tsx +105 -0
- package/src/StackedBarSeries.tsx +272 -0
- package/src/StochasticSeries.tsx +70 -0
- package/src/StraightLine.tsx +166 -0
- package/src/VolumeProfileSeries.tsx +247 -0
- package/src/index.ts +23 -0
- package/src/markers/CircleMarker.tsx +69 -0
- package/src/markers/SquareMarker.tsx +71 -0
- package/src/markers/TriangleMarker.tsx +131 -0
- package/src/markers/index.ts +3 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
https://github.com/reactivemarkets/react-financial-charts
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2015-2018 Ragu Ramaswamy
|
|
5
|
+
Copyright (c) 2016 Julien Renaux
|
|
6
|
+
Copyright (c) 2019 Reactive Markets
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
in the Software without restriction, including without limitation the rights
|
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
furnished to do so, subject to the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be included in
|
|
16
|
+
all copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
24
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { ChartCanvasContext } from "@tradingaction/core";
|
|
3
|
+
export const AlternateDataSeries = ({ data, children, }) => {
|
|
4
|
+
const context = React.useContext(ChartCanvasContext);
|
|
5
|
+
const contextValue = React.useMemo(() => {
|
|
6
|
+
const { plotData, xAccessor } = context;
|
|
7
|
+
const startDate = xAccessor(plotData[0]);
|
|
8
|
+
const endDate = xAccessor(plotData[plotData.length - 1]);
|
|
9
|
+
return Object.assign(Object.assign({}, context), { plotData: data.filter((d) => {
|
|
10
|
+
const date = xAccessor(d);
|
|
11
|
+
return date > startDate && date < endDate;
|
|
12
|
+
}) });
|
|
13
|
+
}, [data, context]);
|
|
14
|
+
return React.createElement(ChartCanvasContext.Provider, { value: contextValue }, children);
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=AlternateDataSeries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AlternateDataSeries.js","sourceRoot":"","sources":["../src/AlternateDataSeries.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAMzD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAS,EACxC,IAAI,EACJ,QAAQ,GAC+C,EAAE,EAAE;IAC3D,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC;IACrD,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QACpC,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;QAExC,MAAM,SAAS,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;QACzC,MAAM,OAAO,GAAG,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;QAEzD,uCACO,OAAO,KACV,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE;gBACxB,MAAM,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;gBAC1B,OAAO,IAAI,GAAG,SAAS,IAAI,IAAI,GAAG,OAAO,CAAC;YAC9C,CAAC,CAAC,IACJ;IACN,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;IAEpB,OAAO,oBAAC,kBAAkB,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,IAAG,QAAQ,CAA+B,CAAC;AACtG,CAAC,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { strokeDashTypes } from "@tradingaction/core";
|
|
2
|
+
import { CurveFactory } from "d3-shape";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
export interface AlternatingFillAreaSeriesProps {
|
|
5
|
+
readonly baseAt: number;
|
|
6
|
+
/**
|
|
7
|
+
* Wether to connect the area between undefined data points.
|
|
8
|
+
*/
|
|
9
|
+
readonly connectNulls?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Color, gradient, or pattern to use for fill.
|
|
12
|
+
*/
|
|
13
|
+
readonly fillStyle?: {
|
|
14
|
+
top: string;
|
|
15
|
+
bottom: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* A factory for a curve generator for the area and line.
|
|
19
|
+
*/
|
|
20
|
+
readonly curve?: CurveFactory;
|
|
21
|
+
/**
|
|
22
|
+
* Color, gradient, or pattern to use for the stroke.
|
|
23
|
+
*/
|
|
24
|
+
readonly strokeStyle?: {
|
|
25
|
+
top: string;
|
|
26
|
+
bottom: string;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Stroke dash.
|
|
30
|
+
*/
|
|
31
|
+
readonly strokeDasharray?: {
|
|
32
|
+
top: strokeDashTypes;
|
|
33
|
+
bottom: strokeDashTypes;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Stroke width.
|
|
37
|
+
*/
|
|
38
|
+
readonly strokeWidth?: {
|
|
39
|
+
top: number;
|
|
40
|
+
bottom: number;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Selector for data to plot.
|
|
44
|
+
*/
|
|
45
|
+
readonly yAccessor: (data: any) => number | undefined;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* `AlternatingFillAreaSeries` component is similar to a `AreaSeries` but with different colors above and below the base.
|
|
49
|
+
*/
|
|
50
|
+
export declare class AlternatingFillAreaSeries extends React.Component<AlternatingFillAreaSeriesProps> {
|
|
51
|
+
static defaultProps: {
|
|
52
|
+
connectNulls: boolean;
|
|
53
|
+
fillStyle: {
|
|
54
|
+
top: string;
|
|
55
|
+
bottom: string;
|
|
56
|
+
};
|
|
57
|
+
strokeStyle: {
|
|
58
|
+
top: string;
|
|
59
|
+
bottom: string;
|
|
60
|
+
};
|
|
61
|
+
strokeWidth: {
|
|
62
|
+
top: number;
|
|
63
|
+
bottom: number;
|
|
64
|
+
};
|
|
65
|
+
strokeDasharray: {
|
|
66
|
+
top: strokeDashTypes;
|
|
67
|
+
bottom: strokeDashTypes;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
private clipPathId1;
|
|
71
|
+
private clipPathId2;
|
|
72
|
+
render(): JSX.Element;
|
|
73
|
+
private readonly baseAt;
|
|
74
|
+
private readonly renderClip;
|
|
75
|
+
private readonly bottomClip;
|
|
76
|
+
private readonly topClip;
|
|
77
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { AreaSeries } from "./AreaSeries";
|
|
3
|
+
import { SVGComponent } from "./SVGComponent";
|
|
4
|
+
/**
|
|
5
|
+
* `AlternatingFillAreaSeries` component is similar to a `AreaSeries` but with different colors above and below the base.
|
|
6
|
+
*/
|
|
7
|
+
export class AlternatingFillAreaSeries extends React.Component {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
this.clipPathId1 = `alternating-area-clip-${String(Math.round(Math.random() * 10000 * 10000))}`;
|
|
11
|
+
this.clipPathId2 = `alternating-area-clip-${String(Math.round(Math.random() * 10000 * 10000))}`;
|
|
12
|
+
this.baseAt = (yScale) => {
|
|
13
|
+
return yScale(this.props.baseAt);
|
|
14
|
+
};
|
|
15
|
+
this.renderClip = (moreProps) => {
|
|
16
|
+
const { chartConfig } = moreProps;
|
|
17
|
+
const { baseAt } = this.props;
|
|
18
|
+
const { yScale, width, height } = chartConfig;
|
|
19
|
+
return (React.createElement("defs", null,
|
|
20
|
+
React.createElement("clipPath", { id: this.clipPathId1 },
|
|
21
|
+
React.createElement("rect", { x: 0, y: 0, width: width, height: yScale(baseAt) })),
|
|
22
|
+
React.createElement("clipPath", { id: this.clipPathId2 },
|
|
23
|
+
React.createElement("rect", { x: 0, y: yScale(baseAt), width: width, height: height - yScale(baseAt) }))));
|
|
24
|
+
};
|
|
25
|
+
this.bottomClip = (ctx, moreProps) => {
|
|
26
|
+
const { chartConfig } = moreProps;
|
|
27
|
+
const { baseAt } = this.props;
|
|
28
|
+
const { yScale, width, height } = chartConfig;
|
|
29
|
+
ctx.beginPath();
|
|
30
|
+
ctx.rect(0, yScale(baseAt), width, height - yScale(baseAt));
|
|
31
|
+
ctx.clip();
|
|
32
|
+
};
|
|
33
|
+
this.topClip = (ctx, moreProps) => {
|
|
34
|
+
const { chartConfig } = moreProps;
|
|
35
|
+
const { baseAt } = this.props;
|
|
36
|
+
const { yScale, width } = chartConfig;
|
|
37
|
+
ctx.beginPath();
|
|
38
|
+
ctx.rect(0, 0, width, yScale(baseAt));
|
|
39
|
+
ctx.clip();
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
render() {
|
|
43
|
+
const { connectNulls, yAccessor, curve, strokeStyle = AlternatingFillAreaSeries.defaultProps.strokeStyle, strokeWidth = AlternatingFillAreaSeries.defaultProps.strokeWidth, strokeDasharray = AlternatingFillAreaSeries.defaultProps.strokeDasharray, fillStyle = AlternatingFillAreaSeries.defaultProps.fillStyle, } = this.props;
|
|
44
|
+
return (React.createElement("g", null,
|
|
45
|
+
React.createElement(SVGComponent, null, this.renderClip),
|
|
46
|
+
React.createElement(AreaSeries, { canvasClip: this.topClip, connectNulls: connectNulls, yAccessor: yAccessor, curve: curve, baseAt: this.baseAt, fillStyle: fillStyle.top, strokeStyle: strokeStyle.top, strokeDasharray: strokeDasharray.top, strokeWidth: strokeWidth.top }),
|
|
47
|
+
React.createElement(AreaSeries, { canvasClip: this.bottomClip, connectNulls: connectNulls, yAccessor: yAccessor, curve: curve, baseAt: this.baseAt, fillStyle: fillStyle.bottom, strokeStyle: strokeStyle.bottom, strokeDasharray: strokeDasharray.bottom, strokeWidth: strokeWidth.bottom })));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
AlternatingFillAreaSeries.defaultProps = {
|
|
51
|
+
connectNulls: false,
|
|
52
|
+
fillStyle: {
|
|
53
|
+
top: "rgba(38, 166, 154, 0.1)",
|
|
54
|
+
bottom: "rgba(239, 83, 80, 0.1)",
|
|
55
|
+
},
|
|
56
|
+
strokeStyle: {
|
|
57
|
+
top: "#26a69a",
|
|
58
|
+
bottom: "#ef5350",
|
|
59
|
+
},
|
|
60
|
+
strokeWidth: {
|
|
61
|
+
top: 2,
|
|
62
|
+
bottom: 2,
|
|
63
|
+
},
|
|
64
|
+
strokeDasharray: {
|
|
65
|
+
top: "Solid",
|
|
66
|
+
bottom: "Solid",
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=AlternatingFillAreaSeries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AlternatingFillAreaSeries.js","sourceRoot":"","sources":["../src/AlternatingFillAreaSeries.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AA8C9C;;GAEG;AACH,MAAM,OAAO,yBAA0B,SAAQ,KAAK,CAAC,SAAyC;IAA9F;;QAqBY,gBAAW,GAAG,yBAAyB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,KAAK,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC;QAC3F,gBAAW,GAAG,yBAAyB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,KAAK,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC;QA0ClF,WAAM,GAAG,CAAC,MAA8C,EAAE,EAAE;YACzE,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACrC,CAAC,CAAC;QAEe,eAAU,GAAG,CAAC,SAAc,EAAE,EAAE;Y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,EACvC,WAAW,EAAE,WAAW,CAAC,MAAM,GACjC,CACF,CACP,CAAC;IACN,CAAC;;AA7Da,sCAAY,GAAG;IACzB,YAAY,EAAE,KAAK;IACnB,SAAS,EAAE;QACP,GAAG,EAAE,yBAAyB;QAC9B,MAAM,EAAE,wBAAwB;KACnC;IACD,WAAW,EAAE;QACT,GAAG,EAAE,SAAS;QACd,MAAM,EAAE,SAAS;KACpB;IACD,WAAW,EAAE;QACT,GAAG,EAAE,CAAC;QACN,MAAM,EAAE,CAAC;KACZ;IACD,eAAe,EAAE;QACb,GAAG,EAAE,OAA0B;QAC/B,MAAM,EAAE,OAA0B;KACrC;CACJ,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ScaleContinuousNumeric } from "d3-scale";
|
|
2
|
+
import { CurveFactory } from "d3-shape";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
export interface AreaOnlySeriesProps {
|
|
5
|
+
/**
|
|
6
|
+
* The base y value to draw the area to.
|
|
7
|
+
*/
|
|
8
|
+
readonly base?: number | ((yScale: ScaleContinuousNumeric<number, number>, d: [number, number], moreProps: any) => number | undefined);
|
|
9
|
+
readonly canvasClip?: (context: CanvasRenderingContext2D, moreProps: any) => void;
|
|
10
|
+
/**
|
|
11
|
+
* Wether to connect the area between undefined data points.
|
|
12
|
+
*/
|
|
13
|
+
readonly connectNulls?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* A factory for a curve generator for the area.
|
|
16
|
+
*/
|
|
17
|
+
readonly curve?: CurveFactory;
|
|
18
|
+
/**
|
|
19
|
+
* The default accessor for defined returns not NaN, thus assumes that the input data is always a number.
|
|
20
|
+
*/
|
|
21
|
+
readonly defined?: (data: number | undefined) => boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Color, gradient, or pattern to use for fill.
|
|
24
|
+
*/
|
|
25
|
+
readonly fillStyle?: string | ((context: CanvasRenderingContext2D, moreProps: any) => string | CanvasGradient | CanvasPattern);
|
|
26
|
+
/**
|
|
27
|
+
* Selector for data to plot.
|
|
28
|
+
*/
|
|
29
|
+
readonly yAccessor: (data: any) => number | undefined;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* `AreaOnlySeries` component.
|
|
33
|
+
*/
|
|
34
|
+
export declare class AreaOnlySeries extends React.Component<AreaOnlySeriesProps> {
|
|
35
|
+
static defaultProps: {
|
|
36
|
+
connectNulls: boolean;
|
|
37
|
+
defined: (d: number | undefined) => boolean;
|
|
38
|
+
base: (yScale: ScaleContinuousNumeric<number, number>) => any;
|
|
39
|
+
};
|
|
40
|
+
render(): JSX.Element;
|
|
41
|
+
private readonly drawOnCanvas;
|
|
42
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { first, functor, getAxisCanvas, GenericChartComponent } from "@tradingaction/core";
|
|
2
|
+
import { area } from "d3-shape";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
/**
|
|
5
|
+
* `AreaOnlySeries` component.
|
|
6
|
+
*/
|
|
7
|
+
export class AreaOnlySeries extends React.Component {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
this.drawOnCanvas = (ctx, moreProps) => {
|
|
11
|
+
const { connectNulls, fillStyle, curve, canvasClip, yAccessor, defined = AreaOnlySeries.defaultProps.defined, base, } = this.props;
|
|
12
|
+
const { xScale, chartConfig: { yScale }, plotData, xAccessor, } = moreProps;
|
|
13
|
+
if (canvasClip !== undefined) {
|
|
14
|
+
ctx.save();
|
|
15
|
+
canvasClip(ctx, moreProps);
|
|
16
|
+
}
|
|
17
|
+
if (fillStyle !== undefined) {
|
|
18
|
+
if (typeof fillStyle === "string") {
|
|
19
|
+
ctx.fillStyle = fillStyle;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
ctx.fillStyle = fillStyle(ctx, moreProps);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const newBase = functor(base);
|
|
26
|
+
const areaSeries = area()
|
|
27
|
+
.x((d) => Math.round(xScale(xAccessor(d))))
|
|
28
|
+
.y0((d) => newBase(yScale, d, moreProps))
|
|
29
|
+
.y1((d) => Math.round(yScale(yAccessor(d))));
|
|
30
|
+
if (curve !== undefined) {
|
|
31
|
+
areaSeries.curve(curve);
|
|
32
|
+
}
|
|
33
|
+
if (!connectNulls) {
|
|
34
|
+
areaSeries.defined((d) => defined(yAccessor(d)));
|
|
35
|
+
}
|
|
36
|
+
ctx.beginPath();
|
|
37
|
+
areaSeries.context(ctx)(plotData);
|
|
38
|
+
ctx.fill();
|
|
39
|
+
if (canvasClip !== undefined) {
|
|
40
|
+
ctx.restore();
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
render() {
|
|
45
|
+
return React.createElement(GenericChartComponent, { canvasDraw: this.drawOnCanvas, canvasToDraw: getAxisCanvas, drawOn: ["pan"] });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
AreaOnlySeries.defaultProps = {
|
|
49
|
+
connectNulls: false,
|
|
50
|
+
defined: (d) => d !== undefined && !isNaN(d),
|
|
51
|
+
base: (yScale) => first(yScale.range()),
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=AreaOnlySeries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AreaOnlySeries.js","sourceRoot":"","sources":["../src/AreaOnlySeries.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAE3F,OAAO,EAAE,IAAI,EAAgB,MAAM,UAAU,CAAC;AAC9C,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAkC/B;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK,CAAC,SAA8B;IAAxE;;QAWqB,iBAAY,GAAG,CAAC,GAA6B,EAAE,SAAc,EAAE,EAAE;YAC9E,MAAM,EACF,YAAY,EACZ,SAAS,EACT,KAAK,EACL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CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;aACpD;YAED,GAAG,CAAC,SAAS,EAAE,CAAC;YAChB,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC;YAClC,GAAG,CAAC,IAAI,EAAE,CAAC;YAEX,IAAI,UAAU,KAAK,SAAS,EAAE;gBAC1B,GAAG,CAAC,OAAO,EAAE,CAAC;aACjB;QACL,CAAC,CAAC;IACN,CAAC;IA1DU,MAAM;QACT,OAAO,oBAAC,qBAAqB,IAAC,UAAU,EAAE,IAAI,CAAC,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC,KAAK,CAAC,GAAI,CAAC;IAClH,CAAC;;AARa,2BAAY,GAAG;IACzB,YAAY,EAAE,KAAK;IACnB,OAAO,EAAE,CAAC,CAAqB,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAChE,IAAI,EAAE,CAAC,MAA8C,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;CAClF,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { strokeDashTypes } from "@tradingaction/core";
|
|
2
|
+
import { ScaleContinuousNumeric } from "d3-scale";
|
|
3
|
+
import { CurveFactory } from "d3-shape";
|
|
4
|
+
import { Component } from "react";
|
|
5
|
+
export interface AreaSeriesProps {
|
|
6
|
+
/**
|
|
7
|
+
* The base y value to draw the area to.
|
|
8
|
+
*/
|
|
9
|
+
readonly baseAt?: number | ((yScale: ScaleContinuousNumeric<number, number>, d: [number, number], moreProps: any) => number);
|
|
10
|
+
readonly canvasClip?: (context: CanvasRenderingContext2D, moreProps: any) => void;
|
|
11
|
+
/**
|
|
12
|
+
* Whether to connect the area between undefined data points.
|
|
13
|
+
*/
|
|
14
|
+
readonly connectNulls?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Color, gradient, or pattern to use for fill.
|
|
17
|
+
*/
|
|
18
|
+
readonly fillStyle?: string | ((context: CanvasRenderingContext2D, moreProps: any) => string | CanvasGradient | CanvasPattern);
|
|
19
|
+
/**
|
|
20
|
+
* A factory for a curve generator for the area and line.
|
|
21
|
+
*/
|
|
22
|
+
readonly curve?: CurveFactory;
|
|
23
|
+
/**
|
|
24
|
+
* Color, gradient, or pattern to use for the stroke.
|
|
25
|
+
*/
|
|
26
|
+
readonly strokeStyle?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Stroke dash.
|
|
29
|
+
*/
|
|
30
|
+
readonly strokeDasharray?: strokeDashTypes;
|
|
31
|
+
/**
|
|
32
|
+
* Stroke width.
|
|
33
|
+
*/
|
|
34
|
+
readonly strokeWidth?: number;
|
|
35
|
+
/**
|
|
36
|
+
* Selector for data to plot.
|
|
37
|
+
*/
|
|
38
|
+
readonly yAccessor: (data: any) => number | undefined;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* `AreaSeries` component is similar to a `LineSeries` but with the area between the line and base filled.
|
|
42
|
+
*/
|
|
43
|
+
export declare class AreaSeries extends Component<AreaSeriesProps> {
|
|
44
|
+
static defaultProps: Partial<AreaSeriesProps>;
|
|
45
|
+
render(): JSX.Element;
|
|
46
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React, { Component } from "react";
|
|
2
|
+
import { AreaOnlySeries } from "./AreaOnlySeries";
|
|
3
|
+
import { LineSeries } from "./LineSeries";
|
|
4
|
+
/**
|
|
5
|
+
* `AreaSeries` component is similar to a `LineSeries` but with the area between the line and base filled.
|
|
6
|
+
*/
|
|
7
|
+
export class AreaSeries extends Component {
|
|
8
|
+
render() {
|
|
9
|
+
const { baseAt, connectNulls, strokeStyle, strokeWidth, strokeDasharray, fillStyle, curve, canvasClip, yAccessor, } = this.props;
|
|
10
|
+
return (React.createElement("g", null,
|
|
11
|
+
React.createElement(AreaOnlySeries, { connectNulls: connectNulls, yAccessor: yAccessor, curve: curve, base: baseAt, fillStyle: fillStyle, canvasClip: canvasClip }),
|
|
12
|
+
React.createElement(LineSeries, { connectNulls: connectNulls, yAccessor: yAccessor, strokeStyle: strokeStyle, strokeWidth: strokeWidth, strokeDasharray: strokeDasharray, curve: curve, canvasClip: canvasClip, highlightOnHover: false })));
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
AreaSeries.defaultProps = {
|
|
16
|
+
fillStyle: "rgba(33, 150, 243, 0.1)",
|
|
17
|
+
strokeStyle: "#2196f3",
|
|
18
|
+
strokeWidth: 3,
|
|
19
|
+
strokeDasharray: "Solid",
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=AreaSeries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AreaSeries.js","sourceRoot":"","sources":["../src/AreaSeries.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AA0C1C;;GAEG;AACH,MAAM,OAAO,UAAW,SAAQ,SAA0B;IAQ/C,MAAM;QACT,MAAM,EACF,MAAM,EACN,YAAY,EACZ,WAAW,EACX,WAAW,EACX,eAAe,EACf,SAAS,EACT,KAAK,EACL,UAAU,EACV,SAAS,GACZ,GAAG,IAAI,CAAC,KAAK,CAAC;QAEf,OAAO,CACH;YACI,oBAAC,cAAc,IACX,YAAY,EAAE,YAAY,EAC1B,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,UAAU,GACxB;YACF,oBAAC,UAAU,IACP,YAAY,EAAE,YAAY,EAC1B,SAAS,EAAE,SAAS,EACpB,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,EACxB,eAAe,EAAE,eAAe,EAChC,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,UAAU,EACtB,gBAAgB,EAAE,KAAK,GACzB,CACF,CACP,CAAC;IACN,CAAC;;AA1Ca,uBAAY,GAA6B;IACnD,SAAS,EAAE,yBAAyB;IACpC,WAAW,EAAE,SAAS;IACtB,WAAW,EAAE,CAAC;IACd,eAAe,EAAE,OAAO;CAC3B,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ScaleContinuousNumeric, ScaleTime } from "d3-scale";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
export interface BarSeriesProps {
|
|
4
|
+
readonly baseAt?: number | ((xScale: ScaleContinuousNumeric<number, number> | ScaleTime<number, number>, yScale: ScaleContinuousNumeric<number, number>, d: [number, number], moreProps: any) => number);
|
|
5
|
+
readonly clip?: boolean;
|
|
6
|
+
readonly fillStyle?: string | ((data: any) => string);
|
|
7
|
+
readonly strokeStyle?: string;
|
|
8
|
+
readonly swapScales?: boolean;
|
|
9
|
+
readonly width?: number | ((props: {
|
|
10
|
+
widthRatio: number;
|
|
11
|
+
}, moreProps: any) => number);
|
|
12
|
+
readonly widthRatio?: number;
|
|
13
|
+
readonly yAccessor: (data: any) => number | undefined;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A `BarSeries` component.
|
|
17
|
+
*/
|
|
18
|
+
export declare class BarSeries extends React.Component<BarSeriesProps> {
|
|
19
|
+
static defaultProps: {
|
|
20
|
+
baseAt: (xScale: ScaleContinuousNumeric<number, number>, yScale: ScaleContinuousNumeric<number, number>) => any;
|
|
21
|
+
clip: boolean;
|
|
22
|
+
fillStyle: string;
|
|
23
|
+
swapScales: boolean;
|
|
24
|
+
width: <T>(props: {
|
|
25
|
+
widthRatio: number;
|
|
26
|
+
}, moreProps: {
|
|
27
|
+
xAccessor: (datum: T) => number | Date;
|
|
28
|
+
xScale: ScaleContinuousNumeric<number, number, never> | ScaleTime<number, number, never>;
|
|
29
|
+
plotData: T[];
|
|
30
|
+
}) => number;
|
|
31
|
+
widthRatio: number;
|
|
32
|
+
};
|
|
33
|
+
render(): JSX.Element;
|
|
34
|
+
private readonly drawOnCanvas;
|
|
35
|
+
private readonly getBars;
|
|
36
|
+
}
|
package/lib/BarSeries.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { functor, head, getAxisCanvas, GenericChartComponent, plotDataLengthBarWidth } from "@tradingaction/core";
|
|
2
|
+
import { group } from "d3-array";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { drawOnCanvasHelper, identityStack } from "./StackedBarSeries";
|
|
5
|
+
/**
|
|
6
|
+
* A `BarSeries` component.
|
|
7
|
+
*/
|
|
8
|
+
export class BarSeries extends React.Component {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
this.drawOnCanvas = (ctx, moreProps) => {
|
|
12
|
+
if (this.props.swapScales) {
|
|
13
|
+
const { xAccessor } = moreProps;
|
|
14
|
+
drawOnCanvasHelper(ctx, this.props, moreProps, xAccessor, identityStack);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
const bars = this.getBars(moreProps);
|
|
18
|
+
const { strokeStyle } = this.props;
|
|
19
|
+
const nest = group(bars, (d) => d.fillStyle);
|
|
20
|
+
nest.forEach((values, key) => {
|
|
21
|
+
if (strokeStyle !== undefined) {
|
|
22
|
+
if (head(values).width > 1) {
|
|
23
|
+
ctx.strokeStyle = strokeStyle;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
ctx.fillStyle = key;
|
|
27
|
+
values.forEach((d) => {
|
|
28
|
+
if (d.width <= 1) {
|
|
29
|
+
ctx.fillRect(d.x - 0.5, d.y, 1, d.height);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
ctx.fillRect(d.x + 0.5, d.y + 0.5, d.width, d.height);
|
|
33
|
+
if (strokeStyle !== undefined) {
|
|
34
|
+
ctx.strokeRect(d.x, d.y, d.width, d.height);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
this.getBars = (moreProps) => {
|
|
42
|
+
const { baseAt, fillStyle, width, yAccessor } = this.props;
|
|
43
|
+
const { xScale, xAccessor, plotData, chartConfig: { yScale }, } = moreProps;
|
|
44
|
+
const getFill = functor(fillStyle);
|
|
45
|
+
const getBase = functor(baseAt);
|
|
46
|
+
const getWidth = functor(width);
|
|
47
|
+
const barWidth = getWidth(this.props, {
|
|
48
|
+
xScale,
|
|
49
|
+
xAccessor,
|
|
50
|
+
plotData,
|
|
51
|
+
});
|
|
52
|
+
const offset = 0.5 * barWidth;
|
|
53
|
+
return plotData
|
|
54
|
+
.map((d) => {
|
|
55
|
+
const yValue = yAccessor(d);
|
|
56
|
+
if (yValue === undefined) {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
const xValue = xAccessor(d);
|
|
60
|
+
const x = xScale(xValue) - offset;
|
|
61
|
+
let y = yScale(yValue);
|
|
62
|
+
let h = getBase(xScale, yScale, d) - yScale(yValue);
|
|
63
|
+
if (h < 0) {
|
|
64
|
+
y = y + h;
|
|
65
|
+
h = -h;
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
x,
|
|
69
|
+
y: Math.round(y),
|
|
70
|
+
height: Math.round(h),
|
|
71
|
+
width: offset * 2,
|
|
72
|
+
fillStyle: getFill(d),
|
|
73
|
+
};
|
|
74
|
+
})
|
|
75
|
+
.filter((d) => d !== undefined);
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
render() {
|
|
79
|
+
const { clip } = this.props;
|
|
80
|
+
return (React.createElement(GenericChartComponent, { clip: clip, canvasToDraw: getAxisCanvas, canvasDraw: this.drawOnCanvas, drawOn: ["pan"] }));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
BarSeries.defaultProps = {
|
|
84
|
+
baseAt: (xScale, yScale /* , d*/) => head(yScale.range()),
|
|
85
|
+
clip: true,
|
|
86
|
+
fillStyle: "rgba(70, 130, 180, 0.5)",
|
|
87
|
+
swapScales: false,
|
|
88
|
+
width: plotDataLengthBarWidth,
|
|
89
|
+
widthRatio: 0.8,
|
|
90
|
+
};
|
|
91
|
+
//# sourceMappingURL=BarSeries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BarSeries.js","sourceRoot":"","sources":["../src/BarSeries.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAClH,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AA4BvE;;GAEG;AACH,MAAM,OAAO,SAAU,SAAQ,KAAK,CAAC,SAAyB;IAA9D;;QA0BqB,iBAAY,GAAG,CAAC,GAA6B,EAAE,SAAc,EAAE,EAAE;YAC9E,IAAI,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE;gBACvB,MAAM,EAAE,SAAS,EAAE,GAAG,SAAS,CAAC;gBAEhC,kBAAkB,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;aAC5E;iBAAM;gBACH,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;gBAErC,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;gBAEnC,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;gBAElD,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE;oBACzB,IAAI,WAAW,KAAK,SAAS,EAAE;wBAC3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,IAClB,IAAI,EAAE,IAAI,EACV,YAAY,EAAE,aAAa,EAC3B,UAAU,EAAE,IAAI,CAAC,YAAY,EAC7B,MAAM,EAAE,CAAC,KAAK,CAAC,GACjB,CACL,CAAC;IACN,CAAC;;AAvBa,sBAAY,GAAG;IACzB,MAAM,EAAE,CACJ,MAA8C,EAC9C,MAA8C,CAAC,QAAQ,EACzD,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACzB,IAAI,EAAE,IAAI;IACV,SAAS,EAAE,yBAAyB;IACpC,UAAU,EAAE,KAAK;IACjB,KAAK,EAAE,sBAAsB;IAC7B,UAAU,EAAE,GAAG;CAClB,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export interface BollingerSeriesProps {
|
|
3
|
+
readonly areaClassName?: string;
|
|
4
|
+
readonly className?: string;
|
|
5
|
+
readonly fillStyle?: string;
|
|
6
|
+
readonly strokeStyle?: {
|
|
7
|
+
top: string;
|
|
8
|
+
middle: string;
|
|
9
|
+
bottom: string;
|
|
10
|
+
};
|
|
11
|
+
readonly yAccessor?: (data: any) => {
|
|
12
|
+
bottom: number;
|
|
13
|
+
middle: number;
|
|
14
|
+
top: number;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export declare class BollingerSeries extends React.Component<BollingerSeriesProps> {
|
|
18
|
+
static defaultProps: {
|
|
19
|
+
areaClassName: string;
|
|
20
|
+
fillStyle: string;
|
|
21
|
+
strokeStyle: {
|
|
22
|
+
top: string;
|
|
23
|
+
middle: string;
|
|
24
|
+
bottom: string;
|
|
25
|
+
};
|
|
26
|
+
yAccessor: (data: any) => any;
|
|
27
|
+
};
|
|
28
|
+
render(): JSX.Element;
|
|
29
|
+
private readonly yAccessorForScaledBottom;
|
|
30
|
+
private readonly yAccessorForBottom;
|
|
31
|
+
private readonly yAccessorForMiddle;
|
|
32
|
+
private readonly yAccessorForTop;
|
|
33
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { AreaOnlySeries } from "./AreaOnlySeries";
|
|
3
|
+
import { LineSeries } from "./LineSeries";
|
|
4
|
+
export class BollingerSeries extends React.Component {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
this.yAccessorForScaledBottom = (scale, d) => {
|
|
8
|
+
const { yAccessor = BollingerSeries.defaultProps.yAccessor } = this.props;
|
|
9
|
+
const bb = yAccessor(d);
|
|
10
|
+
if (bb === undefined) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
return scale(bb.bottom);
|
|
14
|
+
};
|
|
15
|
+
this.yAccessorForBottom = (d) => {
|
|
16
|
+
const { yAccessor = BollingerSeries.defaultProps.yAccessor } = this.props;
|
|
17
|
+
const bb = yAccessor(d);
|
|
18
|
+
if (bb === undefined) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
return bb.bottom;
|
|
22
|
+
};
|
|
23
|
+
this.yAccessorForMiddle = (d) => {
|
|
24
|
+
const { yAccessor = BollingerSeries.defaultProps.yAccessor } = this.props;
|
|
25
|
+
const bb = yAccessor(d);
|
|
26
|
+
if (bb === undefined) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
return bb.middle;
|
|
30
|
+
};
|
|
31
|
+
this.yAccessorForTop = (d) => {
|
|
32
|
+
const { yAccessor = BollingerSeries.defaultProps.yAccessor } = this.props;
|
|
33
|
+
const bb = yAccessor(d);
|
|
34
|
+
if (bb === undefined) {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
return bb.top;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
render() {
|
|
41
|
+
const { className, strokeStyle = BollingerSeries.defaultProps.strokeStyle, fillStyle } = this.props;
|
|
42
|
+
return (React.createElement("g", { className: className },
|
|
43
|
+
React.createElement(LineSeries, { yAccessor: this.yAccessorForTop, strokeStyle: strokeStyle.top }),
|
|
44
|
+
React.createElement(LineSeries, { yAccessor: this.yAccessorForMiddle, strokeStyle: strokeStyle.middle }),
|
|
45
|
+
React.createElement(LineSeries, { yAccessor: this.yAccessorForBottom, strokeStyle: strokeStyle.bottom }),
|
|
46
|
+
React.createElement(AreaOnlySeries, { yAccessor: this.yAccessorForTop, base: this.yAccessorForScaledBottom, fillStyle: fillStyle })));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
BollingerSeries.defaultProps = {
|
|
50
|
+
areaClassName: "react-financial-charts-bollinger-band-series-area",
|
|
51
|
+
fillStyle: "rgba(38, 166, 153, 0.05)",
|
|
52
|
+
strokeStyle: {
|
|
53
|
+
top: "#26a69a",
|
|
54
|
+
middle: "#812828",
|
|
55
|
+
bottom: "#26a69a",
|
|
56
|
+
},
|
|
57
|
+
yAccessor: (data) => data.bb,
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=BollingerSeries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BollingerSeries.js","sourceRoot":"","sources":["../src/BollingerSeries.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAc1C,MAAM,OAAO,eAAgB,SAAQ,KAAK,CAAC,SAA+B;IAA1E;;QA6BqB,6BAAwB,GAAG,CAAC,KAA6C,EAAE,CAAM,EAAE,EAAE;YAClG,MAAM,EAAE,SAAS,GAAG,eAAe,CAAC,YAAY,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;YAE1E,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;YACxB,IAAI,EAAE,KAAK,SAAS,EAAE;gBAClB,OAAO,SAAS,CAAC;aACpB;YAED,OAAO,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,CA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