@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.
Files changed (119) hide show
  1. package/LICENSE +24 -0
  2. package/README.md +5 -0
  3. package/lib/AlternateDataSeries.d.ts +5 -0
  4. package/lib/AlternateDataSeries.js +16 -0
  5. package/lib/AlternateDataSeries.js.map +1 -0
  6. package/lib/AlternatingFillAreaSeries.d.ts +77 -0
  7. package/lib/AlternatingFillAreaSeries.js +69 -0
  8. package/lib/AlternatingFillAreaSeries.js.map +1 -0
  9. package/lib/AreaOnlySeries.d.ts +42 -0
  10. package/lib/AreaOnlySeries.js +53 -0
  11. package/lib/AreaOnlySeries.js.map +1 -0
  12. package/lib/AreaSeries.d.ts +46 -0
  13. package/lib/AreaSeries.js +21 -0
  14. package/lib/AreaSeries.js.map +1 -0
  15. package/lib/BarSeries.d.ts +36 -0
  16. package/lib/BarSeries.js +91 -0
  17. package/lib/BarSeries.js.map +1 -0
  18. package/lib/BollingerSeries.d.ts +33 -0
  19. package/lib/BollingerSeries.js +59 -0
  20. package/lib/BollingerSeries.js.map +1 -0
  21. package/lib/CandlestickSeries.d.ts +65 -0
  22. package/lib/CandlestickSeries.js +115 -0
  23. package/lib/CandlestickSeries.js.map +1 -0
  24. package/lib/ElderRaySeries.d.ts +45 -0
  25. package/lib/ElderRaySeries.js +66 -0
  26. package/lib/ElderRaySeries.js.map +1 -0
  27. package/lib/GroupedBarSeries.d.ts +33 -0
  28. package/lib/GroupedBarSeries.js +22 -0
  29. package/lib/GroupedBarSeries.js.map +1 -0
  30. package/lib/KagiSeries.d.ts +45 -0
  31. package/lib/KagiSeries.js +108 -0
  32. package/lib/KagiSeries.js.map +1 -0
  33. package/lib/LineSeries.d.ts +84 -0
  34. package/lib/LineSeries.js +102 -0
  35. package/lib/LineSeries.js.map +1 -0
  36. package/lib/MACDSeries.d.ts +55 -0
  37. package/lib/MACDSeries.js +62 -0
  38. package/lib/MACDSeries.js.map +1 -0
  39. package/lib/OHLCSeries.d.ts +32 -0
  40. package/lib/OHLCSeries.js +67 -0
  41. package/lib/OHLCSeries.js.map +1 -0
  42. package/lib/OverlayBarSeries.d.ts +35 -0
  43. package/lib/OverlayBarSeries.js +71 -0
  44. package/lib/OverlayBarSeries.js.map +1 -0
  45. package/lib/PointAndFigureSeries.d.ts +33 -0
  46. package/lib/PointAndFigureSeries.js +92 -0
  47. package/lib/PointAndFigureSeries.js.map +1 -0
  48. package/lib/RSISeries.d.ts +68 -0
  49. package/lib/RSISeries.js +82 -0
  50. package/lib/RSISeries.js.map +1 -0
  51. package/lib/RenkoSeries.d.ts +42 -0
  52. package/lib/RenkoSeries.js +65 -0
  53. package/lib/RenkoSeries.js.map +1 -0
  54. package/lib/SARSeries.d.ts +34 -0
  55. package/lib/SARSeries.js +69 -0
  56. package/lib/SARSeries.js.map +1 -0
  57. package/lib/SVGComponent.d.ts +8 -0
  58. package/lib/SVGComponent.js +9 -0
  59. package/lib/SVGComponent.js.map +1 -0
  60. package/lib/ScatterSeries.d.ts +24 -0
  61. package/lib/ScatterSeries.js +60 -0
  62. package/lib/ScatterSeries.js.map +1 -0
  63. package/lib/StackedBarSeries.d.ts +44 -0
  64. package/lib/StackedBarSeries.js +157 -0
  65. package/lib/StackedBarSeries.js.map +1 -0
  66. package/lib/StochasticSeries.d.ts +39 -0
  67. package/lib/StochasticSeries.js +42 -0
  68. package/lib/StochasticSeries.js.map +1 -0
  69. package/lib/StraightLine.d.ts +38 -0
  70. package/lib/StraightLine.js +81 -0
  71. package/lib/StraightLine.js.map +1 -0
  72. package/lib/VolumeProfileSeries.d.ts +45 -0
  73. package/lib/VolumeProfileSeries.js +161 -0
  74. package/lib/VolumeProfileSeries.js.map +1 -0
  75. package/lib/index.d.ts +23 -0
  76. package/lib/index.js +24 -0
  77. package/lib/index.js.map +1 -0
  78. package/lib/markers/CircleMarker.d.ts +25 -0
  79. package/lib/markers/CircleMarker.js +35 -0
  80. package/lib/markers/CircleMarker.js.map +1 -0
  81. package/lib/markers/SquareMarker.d.ts +25 -0
  82. package/lib/markers/SquareMarker.js +37 -0
  83. package/lib/markers/SquareMarker.js.map +1 -0
  84. package/lib/markers/TriangleMarker.d.ts +27 -0
  85. package/lib/markers/TriangleMarker.js +89 -0
  86. package/lib/markers/TriangleMarker.js.map +1 -0
  87. package/lib/markers/index.d.ts +3 -0
  88. package/lib/markers/index.js +4 -0
  89. package/lib/markers/index.js.map +1 -0
  90. package/package.json +52 -0
  91. package/src/AlternateDataSeries.tsx +29 -0
  92. package/src/AlternatingFillAreaSeries.tsx +159 -0
  93. package/src/AreaOnlySeries.tsx +106 -0
  94. package/src/AreaSeries.tsx +95 -0
  95. package/src/BarSeries.tsx +151 -0
  96. package/src/BollingerSeries.tsx +90 -0
  97. package/src/CandlestickSeries.tsx +188 -0
  98. package/src/ElderRaySeries.tsx +99 -0
  99. package/src/GroupedBarSeries.tsx +48 -0
  100. package/src/KagiSeries.tsx +155 -0
  101. package/src/LineSeries.tsx +223 -0
  102. package/src/MACDSeries.tsx +110 -0
  103. package/src/OHLCSeries.tsx +116 -0
  104. package/src/OverlayBarSeries.tsx +115 -0
  105. package/src/PointAndFigureSeries.tsx +140 -0
  106. package/src/RSISeries.tsx +158 -0
  107. package/src/RenkoSeries.tsx +118 -0
  108. package/src/SARSeries.tsx +111 -0
  109. package/src/SVGComponent.tsx +13 -0
  110. package/src/ScatterSeries.tsx +105 -0
  111. package/src/StackedBarSeries.tsx +272 -0
  112. package/src/StochasticSeries.tsx +70 -0
  113. package/src/StraightLine.tsx +166 -0
  114. package/src/VolumeProfileSeries.tsx +247 -0
  115. package/src/index.ts +23 -0
  116. package/src/markers/CircleMarker.tsx +69 -0
  117. package/src/markers/SquareMarker.tsx +71 -0
  118. package/src/markers/TriangleMarker.tsx +131 -0
  119. package/src/markers/index.ts +3 -0
package/lib/index.js ADDED
@@ -0,0 +1,24 @@
1
+ export * from "./AlternateDataSeries";
2
+ export * from "./AlternatingFillAreaSeries";
3
+ export * from "./AreaOnlySeries";
4
+ export * from "./AreaSeries";
5
+ export * from "./markers";
6
+ export * from "./LineSeries";
7
+ export * from "./CandlestickSeries";
8
+ export * from "./OHLCSeries";
9
+ export * from "./BarSeries";
10
+ export { StackedBarSeries } from "./StackedBarSeries";
11
+ export * from "./GroupedBarSeries";
12
+ export * from "./KagiSeries";
13
+ export * from "./PointAndFigureSeries";
14
+ export * from "./RenkoSeries";
15
+ export * from "./MACDSeries";
16
+ export * from "./BollingerSeries";
17
+ export * from "./RSISeries";
18
+ export * from "./StochasticSeries";
19
+ export * from "./ElderRaySeries";
20
+ export * from "./VolumeProfileSeries";
21
+ export * from "./ScatterSeries";
22
+ export * from "./StraightLine";
23
+ export * from "./SARSeries";
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,gBAAgB,EAAyB,MAAM,oBAAoB,CAAC;AAC7E,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,wBAAwB,CAAC;AACvC,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC"}
@@ -0,0 +1,25 @@
1
+ import * as React from "react";
2
+ export interface CircleMarkerProps {
3
+ readonly className?: string;
4
+ readonly fillStyle?: string;
5
+ readonly point: {
6
+ x: number;
7
+ y: number;
8
+ datum: any;
9
+ };
10
+ readonly r: number | ((datum: any) => number);
11
+ readonly strokeStyle?: string;
12
+ readonly strokeWidth?: number;
13
+ }
14
+ export declare class CircleMarker extends React.Component<CircleMarkerProps> {
15
+ static defaultProps: {
16
+ fillStyle: string;
17
+ className: string;
18
+ };
19
+ static drawOnCanvas: (props: CircleMarkerProps, point: {
20
+ x: number;
21
+ y: number;
22
+ datum: unknown;
23
+ }, ctx: CanvasRenderingContext2D) => void;
24
+ render(): JSX.Element;
25
+ }
@@ -0,0 +1,35 @@
1
+ import { functor } from "@tradingaction/core";
2
+ import * as React from "react";
3
+ export class CircleMarker extends React.Component {
4
+ render() {
5
+ const { className, strokeStyle, strokeWidth, fillStyle, point, r } = this.props;
6
+ const radius = functor(r)(point.datum);
7
+ return (React.createElement("circle", { className: className, cx: point.x, cy: point.y, stroke: strokeStyle, strokeWidth: strokeWidth, fill: fillStyle, r: radius }));
8
+ }
9
+ }
10
+ CircleMarker.defaultProps = {
11
+ fillStyle: "#4682B4",
12
+ className: "react-financial-charts-marker-circle",
13
+ };
14
+ CircleMarker.drawOnCanvas = (props, point, ctx) => {
15
+ const { strokeStyle, fillStyle, r, strokeWidth } = props;
16
+ if (strokeStyle !== undefined) {
17
+ ctx.strokeStyle = strokeStyle;
18
+ }
19
+ if (strokeWidth !== undefined) {
20
+ ctx.lineWidth = strokeWidth;
21
+ }
22
+ if (fillStyle !== undefined) {
23
+ ctx.fillStyle = fillStyle;
24
+ }
25
+ const { datum, x, y } = point;
26
+ const radius = functor(r)(datum);
27
+ ctx.moveTo(x, y);
28
+ ctx.beginPath();
29
+ ctx.arc(x, y, radius, 0, 2 * Math.PI, false);
30
+ ctx.fill();
31
+ if (strokeStyle !== undefined) {
32
+ ctx.stroke();
33
+ }
34
+ };
35
+ //# sourceMappingURL=CircleMarker.js.map
@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AC,EAAE,GAAG,KAAK,CAAC;IAE9B,MAAM,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAEjC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACjB,GAAG,CAAC,SAAS,EAAE,CAAC;IAChB,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;IAC7C,GAAG,CAAC,IAAI,EAAE,CAAC;IACX,IAAI,WAAW,KAAK,SAAS,EAAE;QAC3B,GAAG,CAAC,MAAM,EAAE,CAAC;KAChB;AACL,CAAC,CAAC"}
@@ -0,0 +1,25 @@
1
+ import * as React from "react";
2
+ export interface SquareProps {
3
+ readonly className?: string;
4
+ readonly fillStyle?: string;
5
+ readonly point: {
6
+ x: number;
7
+ y: number;
8
+ datum: any;
9
+ };
10
+ readonly strokeStyle?: string;
11
+ readonly strokeWidth?: number;
12
+ readonly width: number | ((datum: any) => number);
13
+ }
14
+ export declare class Square extends React.Component<SquareProps> {
15
+ static defaultProps: {
16
+ fillStyle: string;
17
+ className: string;
18
+ };
19
+ static drawOnCanvas: (props: SquareProps, point: {
20
+ x: number;
21
+ y: number;
22
+ datum: unknown;
23
+ }, ctx: CanvasRenderingContext2D) => void;
24
+ render(): JSX.Element;
25
+ }
@@ -0,0 +1,37 @@
1
+ import * as React from "react";
2
+ import { functor } from "@tradingaction/core";
3
+ export class Square extends React.Component {
4
+ render() {
5
+ const { className, strokeStyle, strokeWidth, fillStyle, point, width } = this.props;
6
+ const w = functor(width)(point.datum);
7
+ const x = point.x - w / 2;
8
+ const y = point.y - w / 2;
9
+ return (React.createElement("rect", { className: className, x: x, y: y, stroke: strokeStyle, strokeWidth: strokeWidth, fill: fillStyle, width: w, height: w }));
10
+ }
11
+ }
12
+ Square.defaultProps = {
13
+ fillStyle: "#4682B4",
14
+ className: "react-financial-charts-marker-rect",
15
+ };
16
+ Square.drawOnCanvas = (props, point, ctx) => {
17
+ const { strokeStyle, fillStyle, strokeWidth, width } = props;
18
+ if (strokeStyle !== undefined) {
19
+ ctx.strokeStyle = strokeStyle;
20
+ }
21
+ if (strokeWidth !== undefined) {
22
+ ctx.lineWidth = strokeWidth;
23
+ }
24
+ if (fillStyle !== undefined) {
25
+ ctx.fillStyle = fillStyle;
26
+ }
27
+ const w = functor(width)(point.datum);
28
+ const x = point.x - w / 2;
29
+ const y = point.y - w / 2;
30
+ ctx.beginPath();
31
+ ctx.rect(x, y, w, w);
32
+ ctx.fill();
33
+ if (strokeStyle !== undefined) {
34
+ ctx.stroke();
35
+ }
36
+ };
37
+ //# sourceMappingURL=SquareMarker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SquareMarker.js","sourceRoot":"","sources":["../../src/markers/SquareMarker.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAe9C,MAAM,OAAO,MAAO,SAAQ,KAAK,CAAC,SAAsB;IAmC7C,MAAM;QACT,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QACpF,MAAM,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACtC,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC1B,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAE1B,OAAO,CACH,8BACI,SAAS,EAAE,SAAS,EACpB,CAAC,EAAE,CAAC,EACJ,CAAC,EAAE,CAAC,EACJ,MAAM,EAAE,WAAW,EACnB,WAAW,EAAE,WAAW,EACxB,IAAI,EAAE,SAAS,EACf,KAAK,EAAE,CAAC,EACR,MAAM,EAAE,CAAC,GACX,CACL,CAAC;IACN,CAAC;;AApDa,mBAAY,GAAG;IACzB,SAAS,EAAE,SAAS;IACpB,SAAS,EAAE,oCAAoC;CAClD,CAAC;AAEY,mBAAY,GAAG,CACzB,KAAkB,EAClB,KAA+C,EAC/C,GAA6B,EAC/B,EAAE;IACA,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;IAE7D,IAAI,WAAW,KAAK,SAAS,EAAE;QAC3B,GAAG,CAAC,WAAW,GAAG,WAAW,CAAC;KACjC;IACD,IAAI,WAAW,KAAK,SAAS,EAAE;QAC3B,GAAG,CAAC,SAAS,GAAG,WAAW,CAAC;KAC/B;IACD,IAAI,SAAS,KAAK,SAAS,EAAE;QACzB,GAAG,CAAC,SAAS,GAAG,SAAS,CAAC;KAC7B;IAED,MAAM,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACtC,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC1B,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC1B,GAAG,CAAC,SAAS,EAAE,CAAC;IAChB,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACrB,GAAG,CAAC,IAAI,EAAE,CAAC;IAEX,IAAI,WAAW,KAAK,SAAS,EAAE;QAC3B,GAAG,CAAC,MAAM,EAAE,CAAC;KAChB;AACL,CAAC,CAAC"}
@@ -0,0 +1,27 @@
1
+ import * as React from "react";
2
+ export interface TriangleProps {
3
+ readonly className?: string;
4
+ readonly direction?: "top" | "bottom" | "left" | "right" | "hide" | ((datum: any) => any);
5
+ readonly fillStyle?: string | ((datum: any) => string);
6
+ readonly point: {
7
+ x: number;
8
+ y: number;
9
+ datum: any;
10
+ };
11
+ readonly strokeStyle?: string | ((datum: any) => string);
12
+ readonly strokeWidth?: number;
13
+ readonly width?: number | ((datum: any) => number);
14
+ }
15
+ export declare class Triangle extends React.Component<TriangleProps> {
16
+ static defaultProps: {
17
+ direction: string;
18
+ fillStyle: string;
19
+ className: string;
20
+ };
21
+ static drawOnCanvas: (props: TriangleProps, point: {
22
+ x: number;
23
+ y: number;
24
+ datum: unknown;
25
+ }, ctx: CanvasRenderingContext2D) => void;
26
+ render(): JSX.Element | null;
27
+ }
@@ -0,0 +1,89 @@
1
+ import * as React from "react";
2
+ import { functor } from "@tradingaction/core";
3
+ export class Triangle extends React.Component {
4
+ render() {
5
+ const { className, fillStyle, strokeStyle, strokeWidth, point, width } = this.props;
6
+ const rotation = getRotationInDegrees(this.props, point);
7
+ if (rotation == null) {
8
+ return null;
9
+ }
10
+ const fillColor = functor(fillStyle)(point.datum);
11
+ const strokeColor = functor(strokeStyle)(point.datum);
12
+ const w = functor(width)(point.datum);
13
+ const { x, y } = point;
14
+ const { innerOpposite, innerHypotenuse } = getTrianglePoints(w);
15
+ const points = `
16
+ ${x} ${y - innerHypotenuse},
17
+ ${x + w / 2} ${y + innerOpposite},
18
+ ${x - w / 2} ${y + innerOpposite}
19
+ `;
20
+ return (React.createElement("polygon", { className: className, points: points, stroke: strokeColor, strokeWidth: strokeWidth, fill: fillColor, transform: rotation !== 0 ? `rotate(${rotation}, ${x}, ${y})` : undefined }));
21
+ }
22
+ }
23
+ Triangle.defaultProps = {
24
+ direction: "top",
25
+ fillStyle: "#4682B4",
26
+ className: "react-financial-charts-marker-triangle",
27
+ };
28
+ Triangle.drawOnCanvas = (props, point, ctx) => {
29
+ const { fillStyle, strokeStyle, strokeWidth, width } = props;
30
+ if (strokeStyle !== undefined) {
31
+ ctx.strokeStyle = functor(strokeStyle)(point.datum);
32
+ }
33
+ if (strokeWidth !== undefined) {
34
+ ctx.lineWidth = strokeWidth;
35
+ }
36
+ if (fillStyle !== undefined) {
37
+ ctx.fillStyle = functor(fillStyle)(point.datum);
38
+ }
39
+ const w = functor(width)(point.datum);
40
+ const { x, y } = point;
41
+ const { innerOpposite, innerHypotenuse } = getTrianglePoints(w);
42
+ const rotationDeg = getRotationInDegrees(props, point);
43
+ ctx.beginPath();
44
+ ctx.moveTo(x, y - innerHypotenuse);
45
+ ctx.lineTo(x + w / 2, y + innerOpposite);
46
+ ctx.lineTo(x - w / 2, y + innerOpposite);
47
+ // TODO: rotation does not work
48
+ // example: https://gist.github.com/geoffb/6392450
49
+ if (rotationDeg !== null && rotationDeg !== 0) {
50
+ ctx.save();
51
+ ctx.translate(x, y);
52
+ ctx.rotate((rotationDeg * Math.PI) / 180); // 45 degrees
53
+ ctx.fill();
54
+ ctx.restore();
55
+ }
56
+ ctx.fill();
57
+ if (strokeStyle !== undefined) {
58
+ ctx.stroke();
59
+ }
60
+ };
61
+ const getTrianglePoints = (width) => {
62
+ const innerHypotenuse = (width / 2) * (1 / Math.cos((30 * Math.PI) / 180));
63
+ const innerOpposite = (width / 2) * (1 / Math.tan((60 * Math.PI) / 180));
64
+ return {
65
+ innerOpposite,
66
+ innerHypotenuse,
67
+ };
68
+ };
69
+ const getRotationInDegrees = (props, point) => {
70
+ const { direction = Triangle.defaultProps.direction } = props;
71
+ const directionVal = functor(direction)(point.datum);
72
+ if (directionVal === "hide") {
73
+ return null;
74
+ }
75
+ let rotate = 0;
76
+ switch (directionVal) {
77
+ case "bottom":
78
+ rotate = 180;
79
+ break;
80
+ case "left":
81
+ rotate = -90;
82
+ break;
83
+ case "right":
84
+ rotate = 90;
85
+ break;
86
+ }
87
+ return rotate;
88
+ };
89
+ //# sourceMappingURL=TriangleMarker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TriangleMarker.js","sourceRoot":"","sources":["../../src/markers/TriangleMarker.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAA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,EAAE;QACzB,OAAO,IAAI,CAAC;KACf;IAED,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,QAAQ,YAAY,EAAE;QAClB,KAAK,QAAQ;YACT,MAAM,GAAG,GAAG,CAAC;YACb,MAAM;QACV,KAAK,MAAM;YACP,MAAM,GAAG,CAAC,EAAE,CAAC;YACb,MAAM;QACV,KAAK,OAAO;YACR,MAAM,GAAG,EAAE,CAAC;YACZ,MAAM;KACb;IACD,OAAO,MAAM,CAAC;AAClB,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from "./CircleMarker";
2
+ export * from "./SquareMarker";
3
+ export * from "./TriangleMarker";
@@ -0,0 +1,4 @@
1
+ export * from "./CircleMarker";
2
+ export * from "./SquareMarker";
3
+ export * from "./TriangleMarker";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/markers/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@tradingaction/series",
3
+ "version": "2.0.13",
4
+ "description": "Series for react-financial-charts",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "main": "./lib/index.js",
9
+ "typings": "./lib/index.d.ts",
10
+ "files": [
11
+ "lib",
12
+ "src"
13
+ ],
14
+ "sideEffects": false,
15
+ "author": "Reactive Markets",
16
+ "keywords": [
17
+ "charts",
18
+ "charting",
19
+ "stockcharts",
20
+ "finance",
21
+ "financial",
22
+ "finance-chart",
23
+ "react",
24
+ "d3"
25
+ ],
26
+ "license": "MIT",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "https://github.com/reactivemarkets/react-financial-charts.git"
30
+ },
31
+ "bugs": {
32
+ "url": "https://github.com/reactivemarkets/react-financial-charts/issues"
33
+ },
34
+ "scripts": {
35
+ "build": "npm run clean && npm run compile",
36
+ "clean": "rimraf lib",
37
+ "compile": "tsc -p tsconfig.json",
38
+ "watch": "tsc -p tsconfig.json --watch --preserveWatchOutput"
39
+ },
40
+ "dependencies": {
41
+ "@tradingaction/core": "^2.0.13",
42
+ "@types/d3-scale": "^3.2.2",
43
+ "d3-array": "^2.9.1",
44
+ "d3-scale": "^3.2.3",
45
+ "d3-shape": "^2.0.0"
46
+ },
47
+ "peerDependencies": {
48
+ "react": "^16.0.0 || ^17.0.0 || ^18.0.0",
49
+ "react-dom": "^16.0.0 || ^17.0.0 || ^18.0.0"
50
+ },
51
+ "gitHead": "9c9bc635a2291c8da0e1dd5befa4000e96d83119"
52
+ }
@@ -0,0 +1,29 @@
1
+ import * as React from "react";
2
+ import { ChartCanvasContext } from "@tradingaction/core";
3
+
4
+ export interface AlternateDataSeriesProps<TData> {
5
+ readonly data: TData[];
6
+ }
7
+
8
+ export const AlternateDataSeries = <TData,>({
9
+ data,
10
+ children,
11
+ }: React.PropsWithChildren<AlternateDataSeriesProps<TData>>) => {
12
+ const context = React.useContext(ChartCanvasContext);
13
+ const contextValue = React.useMemo(() => {
14
+ const { plotData, xAccessor } = context;
15
+
16
+ const startDate = xAccessor(plotData[0]);
17
+ const endDate = xAccessor(plotData[plotData.length - 1]);
18
+
19
+ return {
20
+ ...context,
21
+ plotData: data.filter((d) => {
22
+ const date = xAccessor(d);
23
+ return date > startDate && date < endDate;
24
+ }),
25
+ };
26
+ }, [data, context]);
27
+
28
+ return <ChartCanvasContext.Provider value={contextValue}>{children}</ChartCanvasContext.Provider>;
29
+ };
@@ -0,0 +1,159 @@
1
+ import { strokeDashTypes } from "@tradingaction/core";
2
+ import { ScaleContinuousNumeric } from "d3-scale";
3
+ import { CurveFactory } from "d3-shape";
4
+ import * as React from "react";
5
+ import { AreaSeries } from "./AreaSeries";
6
+ import { SVGComponent } from "./SVGComponent";
7
+
8
+ export interface AlternatingFillAreaSeriesProps {
9
+ readonly baseAt: number;
10
+ /**
11
+ * Wether to connect the area between undefined data points.
12
+ */
13
+ readonly connectNulls?: boolean;
14
+ /**
15
+ * Color, gradient, or pattern to use for fill.
16
+ */
17
+ readonly fillStyle?: {
18
+ top: string;
19
+ bottom: string;
20
+ };
21
+ /**
22
+ * A factory for a curve generator for the area and line.
23
+ */
24
+ readonly curve?: CurveFactory;
25
+ /**
26
+ * Color, gradient, or pattern to use for the stroke.
27
+ */
28
+ readonly strokeStyle?: {
29
+ top: string;
30
+ bottom: string;
31
+ };
32
+ /**
33
+ * Stroke dash.
34
+ */
35
+ readonly strokeDasharray?: {
36
+ top: strokeDashTypes;
37
+ bottom: strokeDashTypes;
38
+ };
39
+ /**
40
+ * Stroke width.
41
+ */
42
+ readonly strokeWidth?: {
43
+ top: number;
44
+ bottom: number;
45
+ };
46
+ /**
47
+ * Selector for data to plot.
48
+ */
49
+ readonly yAccessor: (data: any) => number | undefined;
50
+ }
51
+
52
+ /**
53
+ * `AlternatingFillAreaSeries` component is similar to a `AreaSeries` but with different colors above and below the base.
54
+ */
55
+ export class AlternatingFillAreaSeries extends React.Component<AlternatingFillAreaSeriesProps> {
56
+ public static defaultProps = {
57
+ connectNulls: false,
58
+ fillStyle: {
59
+ top: "rgba(38, 166, 154, 0.1)",
60
+ bottom: "rgba(239, 83, 80, 0.1)",
61
+ },
62
+ strokeStyle: {
63
+ top: "#26a69a",
64
+ bottom: "#ef5350",
65
+ },
66
+ strokeWidth: {
67
+ top: 2,
68
+ bottom: 2,
69
+ },
70
+ strokeDasharray: {
71
+ top: "Solid" as strokeDashTypes,
72
+ bottom: "Solid" as strokeDashTypes,
73
+ },
74
+ };
75
+
76
+ private clipPathId1 = `alternating-area-clip-${String(Math.round(Math.random() * 10000 * 10000))}`;
77
+ private clipPathId2 = `alternating-area-clip-${String(Math.round(Math.random() * 10000 * 10000))}`;
78
+
79
+ public render() {
80
+ const {
81
+ connectNulls,
82
+ yAccessor,
83
+ curve,
84
+ strokeStyle = AlternatingFillAreaSeries.defaultProps.strokeStyle,
85
+ strokeWidth = AlternatingFillAreaSeries.defaultProps.strokeWidth,
86
+ strokeDasharray = AlternatingFillAreaSeries.defaultProps.strokeDasharray,
87
+ fillStyle = AlternatingFillAreaSeries.defaultProps.fillStyle,
88
+ } = this.props;
89
+
90
+ return (
91
+ <g>
92
+ <SVGComponent>{this.renderClip}</SVGComponent>
93
+ <AreaSeries
94
+ canvasClip={this.topClip}
95
+ connectNulls={connectNulls}
96
+ yAccessor={yAccessor}
97
+ curve={curve}
98
+ baseAt={this.baseAt}
99
+ fillStyle={fillStyle.top}
100
+ strokeStyle={strokeStyle.top}
101
+ strokeDasharray={strokeDasharray.top}
102
+ strokeWidth={strokeWidth.top}
103
+ />
104
+ <AreaSeries
105
+ canvasClip={this.bottomClip}
106
+ connectNulls={connectNulls}
107
+ yAccessor={yAccessor}
108
+ curve={curve}
109
+ baseAt={this.baseAt}
110
+ fillStyle={fillStyle.bottom}
111
+ strokeStyle={strokeStyle.bottom}
112
+ strokeDasharray={strokeDasharray.bottom}
113
+ strokeWidth={strokeWidth.bottom}
114
+ />
115
+ </g>
116
+ );
117
+ }
118
+
119
+ private readonly baseAt = (yScale: ScaleContinuousNumeric<number, number>) => {
120
+ return yScale(this.props.baseAt);
121
+ };
122
+
123
+ private readonly renderClip = (moreProps: any) => {
124
+ const { chartConfig } = moreProps;
125
+ const { baseAt } = this.props;
126
+ const { yScale, width, height } = chartConfig;
127
+
128
+ return (
129
+ <defs>
130
+ <clipPath id={this.clipPathId1}>
131
+ <rect x={0} y={0} width={width} height={yScale(baseAt)} />
132
+ </clipPath>
133
+ <clipPath id={this.clipPathId2}>
134
+ <rect x={0} y={yScale(baseAt)} width={width} height={height - yScale(baseAt)} />
135
+ </clipPath>
136
+ </defs>
137
+ );
138
+ };
139
+
140
+ private readonly bottomClip = (ctx: CanvasRenderingContext2D, moreProps: any) => {
141
+ const { chartConfig } = moreProps;
142
+ const { baseAt } = this.props;
143
+ const { yScale, width, height } = chartConfig;
144
+
145
+ ctx.beginPath();
146
+ ctx.rect(0, yScale(baseAt), width, height - yScale(baseAt));
147
+ ctx.clip();
148
+ };
149
+
150
+ private readonly topClip = (ctx: CanvasRenderingContext2D, moreProps: any) => {
151
+ const { chartConfig } = moreProps;
152
+ const { baseAt } = this.props;
153
+ const { yScale, width } = chartConfig;
154
+
155
+ ctx.beginPath();
156
+ ctx.rect(0, 0, width, yScale(baseAt));
157
+ ctx.clip();
158
+ };
159
+ }
@@ -0,0 +1,106 @@
1
+ import { first, functor, getAxisCanvas, GenericChartComponent } from "@tradingaction/core";
2
+ import { ScaleContinuousNumeric } from "d3-scale";
3
+ import { area, CurveFactory } from "d3-shape";
4
+ import * as React from "react";
5
+
6
+ export interface AreaOnlySeriesProps {
7
+ /**
8
+ * The base y value to draw the area to.
9
+ */
10
+ readonly base?:
11
+ | number
12
+ | ((yScale: ScaleContinuousNumeric<number, number>, d: [number, number], moreProps: any) => number | undefined);
13
+ readonly canvasClip?: (context: CanvasRenderingContext2D, moreProps: any) => void;
14
+ /**
15
+ * Wether to connect the area between undefined data points.
16
+ */
17
+ readonly connectNulls?: boolean;
18
+ /**
19
+ * A factory for a curve generator for the area.
20
+ */
21
+ readonly curve?: CurveFactory;
22
+ /**
23
+ * The default accessor for defined returns not NaN, thus assumes that the input data is always a number.
24
+ */
25
+ readonly defined?: (data: number | undefined) => boolean;
26
+ /**
27
+ * Color, gradient, or pattern to use for fill.
28
+ */
29
+ readonly fillStyle?:
30
+ | string
31
+ | ((context: CanvasRenderingContext2D, moreProps: any) => string | CanvasGradient | CanvasPattern);
32
+ /**
33
+ * Selector for data to plot.
34
+ */
35
+ readonly yAccessor: (data: any) => number | undefined;
36
+ }
37
+
38
+ /**
39
+ * `AreaOnlySeries` component.
40
+ */
41
+ export class AreaOnlySeries extends React.Component<AreaOnlySeriesProps> {
42
+ public static defaultProps = {
43
+ connectNulls: false,
44
+ defined: (d: number | undefined) => d !== undefined && !isNaN(d),
45
+ base: (yScale: ScaleContinuousNumeric<number, number>) => first(yScale.range()),
46
+ };
47
+
48
+ public render() {
49
+ return <GenericChartComponent canvasDraw={this.drawOnCanvas} canvasToDraw={getAxisCanvas} drawOn={["pan"]} />;
50
+ }
51
+
52
+ private readonly drawOnCanvas = (ctx: CanvasRenderingContext2D, moreProps: any) => {
53
+ const {
54
+ connectNulls,
55
+ fillStyle,
56
+ curve,
57
+ canvasClip,
58
+ yAccessor,
59
+ defined = AreaOnlySeries.defaultProps.defined,
60
+ base,
61
+ } = this.props;
62
+
63
+ const {
64
+ xScale,
65
+ chartConfig: { yScale },
66
+ plotData,
67
+ xAccessor,
68
+ } = moreProps;
69
+
70
+ if (canvasClip !== undefined) {
71
+ ctx.save();
72
+ canvasClip(ctx, moreProps);
73
+ }
74
+
75
+ if (fillStyle !== undefined) {
76
+ if (typeof fillStyle === "string") {
77
+ ctx.fillStyle = fillStyle;
78
+ } else {
79
+ ctx.fillStyle = fillStyle(ctx, moreProps);
80
+ }
81
+ }
82
+
83
+ const newBase = functor(base);
84
+
85
+ const areaSeries = area()
86
+ .x((d) => Math.round(xScale(xAccessor(d))))
87
+ .y0((d) => newBase(yScale, d, moreProps))
88
+ .y1((d) => Math.round(yScale(yAccessor(d))));
89
+
90
+ if (curve !== undefined) {
91
+ areaSeries.curve(curve);
92
+ }
93
+
94
+ if (!connectNulls) {
95
+ areaSeries.defined((d) => defined(yAccessor(d)));
96
+ }
97
+
98
+ ctx.beginPath();
99
+ areaSeries.context(ctx)(plotData);
100
+ ctx.fill();
101
+
102
+ if (canvasClip !== undefined) {
103
+ ctx.restore();
104
+ }
105
+ };
106
+ }