@tradingaction/annotations 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/Annotate.d.ts +14 -0
- package/lib/Annotate.js +22 -0
- package/lib/Annotate.js.map +1 -0
- package/lib/BarAnnotation.d.ts +73 -0
- package/lib/BarAnnotation.js +48 -0
- package/lib/BarAnnotation.js.map +1 -0
- package/lib/Label.d.ts +33 -0
- package/lib/Label.js +69 -0
- package/lib/Label.js.map +1 -0
- package/lib/LabelAnnotation.d.ts +53 -0
- package/lib/LabelAnnotation.js +47 -0
- package/lib/LabelAnnotation.js.map +1 -0
- package/lib/SvgPathAnnotation.d.ts +47 -0
- package/lib/SvgPathAnnotation.js +41 -0
- package/lib/SvgPathAnnotation.js.map +1 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +6 -0
- package/lib/index.js.map +1 -0
- package/package.json +49 -0
- package/src/Annotate.tsx +51 -0
- package/src/BarAnnotation.tsx +181 -0
- package/src/Label.tsx +110 -0
- package/src/LabelAnnotation.tsx +125 -0
- package/src/SvgPathAnnotation.tsx +112 -0
- package/src/index.ts +5 -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,14 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export interface AnnotateProps {
|
|
3
|
+
readonly className?: string;
|
|
4
|
+
readonly with: React.ElementType;
|
|
5
|
+
readonly when: (value: any, index: number, array: any[]) => boolean;
|
|
6
|
+
readonly usingProps?: any;
|
|
7
|
+
}
|
|
8
|
+
export declare class Annotate extends React.Component<AnnotateProps> {
|
|
9
|
+
static defaultProps: {
|
|
10
|
+
className: string;
|
|
11
|
+
};
|
|
12
|
+
render(): JSX.Element;
|
|
13
|
+
private readonly renderSVG;
|
|
14
|
+
}
|
package/lib/Annotate.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { GenericChartComponent } from "@tradingaction/core";
|
|
3
|
+
export class Annotate extends React.Component {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
this.renderSVG = (moreProps) => {
|
|
7
|
+
const { xAccessor, xScale, chartConfig: { yScale }, plotData, } = moreProps;
|
|
8
|
+
const { className, usingProps, with: Annotation, when } = this.props;
|
|
9
|
+
const data = plotData.filter(when);
|
|
10
|
+
return (React.createElement("g", { className: className }, data.map((d, idx) => {
|
|
11
|
+
return (React.createElement(Annotation, Object.assign({ key: idx }, usingProps, { xScale: xScale, yScale: yScale, xAccessor: xAccessor, plotData: plotData, datum: d })));
|
|
12
|
+
})));
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
render() {
|
|
16
|
+
return React.createElement(GenericChartComponent, { svgDraw: this.renderSVG, drawOn: ["pan"] });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
Annotate.defaultProps = {
|
|
20
|
+
className: "react-financial-charts-enable-interaction react-financial-charts-annotate react-financial-charts-default-cursor",
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=Annotate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Annotate.js","sourceRoot":"","sources":["../src/Annotate.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAS5D,MAAM,OAAO,QAAS,SAAQ,KAAK,CAAC,SAAwB;IAA5D;;QAUqB,cAAS,GAAG,CAAC,SAAc,EAAE,EAAE;YAC5C,MAAM,EACF,SAAS,EACT,MAAM,EACN,WAAW,EAAE,EAAE,MAAM,EAAE,EACvB,QAAQ,GACX,GAAG,SAAS,CAAC;YAEd,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;YAErE,MAAM,IAAI,GAAI,QAAsB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAElD,OAAO,CACH,2BAAG,SAAS,EAAE,SAAS,IAClB,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE;gBACjB,OAAO,CACH,oBAAC,UAAU,kBACP,GAAG,EAAE,GAAG,IACJ,UAAU,IACd,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,CAAC,IACV,CACL,CAAC;YACN,CAAC,CAAC,CACF,CACP,CAAC;QACN,CAAC,CAAC;IACN,CAAC;IAlCU,MAAM;QACT,OAAO,oBAAC,qBAAqB,IAAC,OAAO,EAAE,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC,KAAK,CAAC,GAAI,CAAC;IAC/E,CAAC;;AAPa,qBAAY,GAAG;IACzB,SAAS,EACL,iHAAiH;CACxH,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { ScaleContinuousNumeric } from "d3-scale";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
export interface BarAnnotationProps {
|
|
4
|
+
readonly className?: string;
|
|
5
|
+
readonly path?: ({ x, y }: {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
}) => string;
|
|
9
|
+
readonly onClick?: (e: React.MouseEvent, data: {
|
|
10
|
+
xScale?: ScaleContinuousNumeric<number, number>;
|
|
11
|
+
yScale?: ScaleContinuousNumeric<number, number>;
|
|
12
|
+
datum: any;
|
|
13
|
+
}) => void;
|
|
14
|
+
readonly xAccessor?: (datum: any) => any;
|
|
15
|
+
readonly xScale?: ScaleContinuousNumeric<number, number>;
|
|
16
|
+
readonly yScale?: ScaleContinuousNumeric<number, number>;
|
|
17
|
+
readonly datum?: object;
|
|
18
|
+
readonly stroke?: string;
|
|
19
|
+
readonly fill?: string | ((datum: any) => string);
|
|
20
|
+
readonly opacity?: number;
|
|
21
|
+
readonly plotData: any[];
|
|
22
|
+
readonly text?: string;
|
|
23
|
+
readonly textAnchor?: string;
|
|
24
|
+
readonly fontFamily?: string;
|
|
25
|
+
readonly fontSize?: number;
|
|
26
|
+
readonly textOpacity?: number;
|
|
27
|
+
readonly textFill?: string;
|
|
28
|
+
readonly textRotate?: number;
|
|
29
|
+
readonly textXOffset?: number;
|
|
30
|
+
readonly textYOffset?: number;
|
|
31
|
+
readonly textIcon?: string;
|
|
32
|
+
readonly textIconFontSize?: number;
|
|
33
|
+
readonly textIconOpacity?: number;
|
|
34
|
+
readonly textIconFill?: string;
|
|
35
|
+
readonly textIconRotate?: number;
|
|
36
|
+
readonly textIconXOffset?: number;
|
|
37
|
+
readonly textIconYOffset?: number;
|
|
38
|
+
readonly textIconAnchor?: string;
|
|
39
|
+
readonly tooltip?: string | ((datum: any) => string);
|
|
40
|
+
readonly x?: number | (({ xScale, xAccessor, datum, plotData, }: {
|
|
41
|
+
xScale: ScaleContinuousNumeric<number, number>;
|
|
42
|
+
xAccessor: (datum: any) => any;
|
|
43
|
+
datum: any;
|
|
44
|
+
plotData: any[];
|
|
45
|
+
}) => number);
|
|
46
|
+
readonly y?: number | (({ yScale, datum, plotData, }: {
|
|
47
|
+
yScale: ScaleContinuousNumeric<number, number>;
|
|
48
|
+
datum: any;
|
|
49
|
+
plotData: any[];
|
|
50
|
+
}) => number);
|
|
51
|
+
}
|
|
52
|
+
export declare class BarAnnotation extends React.Component<BarAnnotationProps> {
|
|
53
|
+
static defaultProps: {
|
|
54
|
+
className: string;
|
|
55
|
+
opacity: number;
|
|
56
|
+
fill: string;
|
|
57
|
+
fontFamily: string;
|
|
58
|
+
fontSize: number;
|
|
59
|
+
textAnchor: string;
|
|
60
|
+
textFill: string;
|
|
61
|
+
textOpacity: number;
|
|
62
|
+
textIconFill: string;
|
|
63
|
+
textIconFontSize: number;
|
|
64
|
+
x: ({ xScale, xAccessor, datum, }: {
|
|
65
|
+
xScale: ScaleContinuousNumeric<number, number>;
|
|
66
|
+
xAccessor: any;
|
|
67
|
+
datum: any;
|
|
68
|
+
}) => number;
|
|
69
|
+
};
|
|
70
|
+
render(): JSX.Element;
|
|
71
|
+
private readonly onClick;
|
|
72
|
+
private readonly helper;
|
|
73
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { functor } from "@tradingaction/core";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
export class BarAnnotation extends React.Component {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
this.onClick = (e) => {
|
|
7
|
+
const { onClick, xScale, yScale, datum } = this.props;
|
|
8
|
+
if (onClick !== undefined) {
|
|
9
|
+
onClick(e, { xScale, yScale, datum });
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
this.helper = (props, xAccessor, xScale, yScale) => {
|
|
13
|
+
const { x, y, datum, fill, tooltip, plotData } = props;
|
|
14
|
+
const xFunc = functor(x);
|
|
15
|
+
const yFunc = functor(y);
|
|
16
|
+
const [xPos, yPos] = [xFunc({ xScale, xAccessor, datum, plotData }), yFunc({ yScale, datum, plotData })];
|
|
17
|
+
return {
|
|
18
|
+
x: xPos,
|
|
19
|
+
y: yPos,
|
|
20
|
+
fill: functor(fill)(datum),
|
|
21
|
+
tooltip: functor(tooltip)(datum),
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
render() {
|
|
26
|
+
const { className, stroke, opacity, xAccessor, xScale, yScale, path, text, textXOffset, textYOffset, textAnchor, fontFamily, fontSize, textFill, textOpacity, textRotate, textIcon, textIconFontSize, textIconFill, textIconOpacity, textIconRotate, textIconXOffset, textIconYOffset, } = this.props;
|
|
27
|
+
const { x, y, fill, tooltip } = this.helper(this.props, xAccessor, xScale, yScale);
|
|
28
|
+
return (React.createElement("g", { className: className, onClick: this.onClick },
|
|
29
|
+
tooltip !== undefined ? React.createElement("title", null, tooltip) : null,
|
|
30
|
+
text !== undefined ? (React.createElement("text", { x: x, y: y, dx: textXOffset, dy: textYOffset, fontFamily: fontFamily, fontSize: fontSize, fill: textFill, opacity: textOpacity, transform: textRotate != undefined ? `rotate(${textRotate}, ${x}, ${y})` : undefined, textAnchor: textAnchor }, text)) : null,
|
|
31
|
+
textIcon !== undefined ? (React.createElement("text", { x: x, y: y, dx: textIconXOffset, dy: textIconYOffset, fontSize: textIconFontSize, fill: textIconFill, opacity: textIconOpacity, transform: textIconRotate != undefined ? `rotate(${textIconRotate}, ${x}, ${y})` : undefined, textAnchor: textAnchor }, textIcon)) : null,
|
|
32
|
+
path !== undefined ? React.createElement("path", { d: path({ x, y }), stroke: stroke, fill: fill, opacity: opacity }) : null));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
BarAnnotation.defaultProps = {
|
|
36
|
+
className: "react-financial-charts-bar-annotation",
|
|
37
|
+
opacity: 1,
|
|
38
|
+
fill: "#000000",
|
|
39
|
+
fontFamily: "-apple-system, system-ui, Roboto, 'Helvetica Neue', Ubuntu, sans-serif",
|
|
40
|
+
fontSize: 10,
|
|
41
|
+
textAnchor: "middle",
|
|
42
|
+
textFill: "#000000",
|
|
43
|
+
textOpacity: 1,
|
|
44
|
+
textIconFill: "#000000",
|
|
45
|
+
textIconFontSize: 10,
|
|
46
|
+
x: ({ xScale, xAccessor, datum, }) => xScale(xAccessor(datum)),
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=BarAnnotation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BarAnnotation.js","sourceRoot":"","sources":["../src/BarAnnotation.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAiE/B,MAAM,OAAO,aAAc,SAAQ,KAAK,CAAC,SAA6B;IAAtE;;QA2FqB,YAAO,GAAG,CAAC,CAAmB,EAAE,EAAE;YAC/C,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;YACtD,IAAI,OAAO,KAAK,SAAS,EAAE;gBACvB,OAAO,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;aACzC;QACL,CAAC,CAAC;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AAxFa,0BAAY,GAAG;IACzB,SAAS,EAAE,uCAAuC;IAClD,OAAO,EAAE,CAAC;IACV,IAAI,EAAE,SAAS;IACf,UAAU,EAAE,wEAAwE;IACpF,QAAQ,EAAE,EAAE;IACZ,UAAU,EAAE,QAAQ;IACpB,QAAQ,EAAE,SAAS;IACnB,WAAW,EAAE,CAAC;IACd,YAAY,EAAE,SAAS;IACvB,gBAAgB,EAAE,EAAE;IACpB,CAAC,EAAE,CAAC,EACA,MAAM,EACN,SAAS,EACT,KAAK,GAKR,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;CACjC,CAAC"}
|
package/lib/Label.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ScaleContinuousNumeric } from "d3-scale";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
export interface LabelProps {
|
|
4
|
+
readonly datum?: any;
|
|
5
|
+
readonly fillStyle?: string | ((datum: any) => string);
|
|
6
|
+
readonly fontFamily?: string;
|
|
7
|
+
readonly fontSize?: number;
|
|
8
|
+
readonly fontWeight?: string;
|
|
9
|
+
readonly rotate?: number;
|
|
10
|
+
readonly selectCanvas?: (canvases: any) => any;
|
|
11
|
+
readonly text?: string | ((datum: any) => string);
|
|
12
|
+
readonly textAlign?: CanvasTextAlign;
|
|
13
|
+
readonly x: number | ((xScale: ScaleContinuousNumeric<number, number>, xAccessor: any, datum: any, plotData: any[]) => number);
|
|
14
|
+
readonly xAccessor?: (datum: any) => any;
|
|
15
|
+
readonly xScale?: ScaleContinuousNumeric<number, number>;
|
|
16
|
+
readonly y: number | ((yScale: ScaleContinuousNumeric<number, number>, datum: any, plotData: any[]) => number);
|
|
17
|
+
readonly yScale?: ScaleContinuousNumeric<number, number>;
|
|
18
|
+
}
|
|
19
|
+
export declare class Label extends React.Component<LabelProps> {
|
|
20
|
+
static defaultProps: {
|
|
21
|
+
fontFamily: string;
|
|
22
|
+
fontSize: number;
|
|
23
|
+
fontWeight: string;
|
|
24
|
+
fillStyle: string;
|
|
25
|
+
rotate: number;
|
|
26
|
+
x: ({ xScale, xAccessor, datum }: any) => any;
|
|
27
|
+
selectCanvas: (canvases: any) => any;
|
|
28
|
+
};
|
|
29
|
+
static contextType: React.Context<import("@tradingaction/core/lib/ChartCanvas").ChartCanvasContextType<number | Date>>;
|
|
30
|
+
render(): JSX.Element;
|
|
31
|
+
private readonly drawOnCanvas;
|
|
32
|
+
private readonly helper;
|
|
33
|
+
}
|
package/lib/Label.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { GenericComponent, functor, ChartCanvasContext } from "@tradingaction/core";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
export class Label extends React.Component {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
this.drawOnCanvas = (ctx, moreProps) => {
|
|
7
|
+
ctx.save();
|
|
8
|
+
const { textAlign = "center", fontFamily, fontSize, fontWeight, rotate } = this.props;
|
|
9
|
+
const { canvasOriginX, canvasOriginY, margin, ratio } = this.context;
|
|
10
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
11
|
+
ctx.scale(ratio, ratio);
|
|
12
|
+
if (canvasOriginX !== undefined) {
|
|
13
|
+
ctx.translate(canvasOriginX, canvasOriginY);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
ctx.translate(margin.left + 0.5 * ratio, margin.top + 0.5 * ratio);
|
|
17
|
+
}
|
|
18
|
+
const { xScale, chartConfig, xAccessor } = moreProps;
|
|
19
|
+
const yScale = Array.isArray(chartConfig) || !chartConfig ? undefined : chartConfig.yScale;
|
|
20
|
+
const { xPos, yPos, fillStyle, text } = this.helper(moreProps, xAccessor, xScale, yScale);
|
|
21
|
+
ctx.save();
|
|
22
|
+
ctx.translate(xPos, yPos);
|
|
23
|
+
if (rotate !== undefined) {
|
|
24
|
+
const radians = (rotate / 180) * Math.PI;
|
|
25
|
+
ctx.rotate(radians);
|
|
26
|
+
}
|
|
27
|
+
if (fontFamily !== undefined) {
|
|
28
|
+
ctx.font = `${fontWeight} ${fontSize}px ${fontFamily}`;
|
|
29
|
+
}
|
|
30
|
+
if (fillStyle !== undefined) {
|
|
31
|
+
ctx.fillStyle = fillStyle;
|
|
32
|
+
}
|
|
33
|
+
if (textAlign !== undefined) {
|
|
34
|
+
ctx.textAlign = textAlign;
|
|
35
|
+
}
|
|
36
|
+
ctx.beginPath();
|
|
37
|
+
ctx.fillText(text, 0, 0);
|
|
38
|
+
ctx.restore();
|
|
39
|
+
};
|
|
40
|
+
this.helper = (moreProps, xAccessor, xScale, yScale) => {
|
|
41
|
+
const { x, y, datum, fillStyle, text } = this.props;
|
|
42
|
+
const { plotData } = moreProps;
|
|
43
|
+
const xFunc = functor(x);
|
|
44
|
+
const yFunc = functor(y);
|
|
45
|
+
const [xPos, yPos] = [xFunc({ xScale, xAccessor, datum, plotData }), yFunc({ yScale, datum, plotData })];
|
|
46
|
+
return {
|
|
47
|
+
xPos,
|
|
48
|
+
yPos,
|
|
49
|
+
text: functor(text)(datum),
|
|
50
|
+
fillStyle: functor(fillStyle)(datum),
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
render() {
|
|
55
|
+
const { selectCanvas } = this.props;
|
|
56
|
+
return React.createElement(GenericComponent, { canvasToDraw: selectCanvas, canvasDraw: this.drawOnCanvas, drawOn: [] });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
Label.defaultProps = {
|
|
60
|
+
fontFamily: "-apple-system, system-ui, Roboto, 'Helvetica Neue', Ubuntu, sans-serif",
|
|
61
|
+
fontSize: 64,
|
|
62
|
+
fontWeight: "bold",
|
|
63
|
+
fillStyle: "#dcdcdc",
|
|
64
|
+
rotate: 0,
|
|
65
|
+
x: ({ xScale, xAccessor, datum }) => xScale(xAccessor(datum)),
|
|
66
|
+
selectCanvas: (canvases) => canvases.bg,
|
|
67
|
+
};
|
|
68
|
+
Label.contextType = ChartCanvas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AC;YACzB,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;YAEzB,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC;YAEzG,OAAO;gBACH,IAAI;gBACJ,IAAI;gBACJ,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC;gBAC1B,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC;aACvC,CAAC;QACN,CAAC,CAAC;IACN,CAAC;IAzEU,MAAM;QACT,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QAEpC,OAAO,oBAAC,gBAAgB,IAAC,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,IAAI,CAAC,YAAY,EAAE,MAAM,EAAE,EAAE,GAAI,CAAC;IACvG,CAAC;;AAhBa,kBAAY,GAAG;IACzB,UAAU,EAAE,wEAAwE;IACpF,QAAQ,EAAE,EAAE;IACZ,UAAU,EAAE,MAAM;IAClB,SAAS,EAAE,SAAS;IACpB,MAAM,EAAE,CAAC;IACT,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAO,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAClE,YAAY,EAAE,CAAC,QAAa,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE;CAC/C,CAAC;AAEY,iBAAW,GAAG,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { ScaleContinuousNumeric } from "d3-scale";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
export interface LabelAnnotationProps {
|
|
4
|
+
readonly className?: string;
|
|
5
|
+
readonly datum?: any;
|
|
6
|
+
readonly fill?: string | ((datum: any) => string);
|
|
7
|
+
readonly fontFamily?: string;
|
|
8
|
+
readonly fontSize?: number;
|
|
9
|
+
readonly onClick?: (e: React.MouseEvent, data: {
|
|
10
|
+
xScale?: ScaleContinuousNumeric<number, number>;
|
|
11
|
+
yScale?: ScaleContinuousNumeric<number, number>;
|
|
12
|
+
datum: any;
|
|
13
|
+
}) => void;
|
|
14
|
+
readonly opacity?: number;
|
|
15
|
+
readonly plotData: any[];
|
|
16
|
+
readonly rotate?: number;
|
|
17
|
+
readonly text?: string | ((datum: any) => string);
|
|
18
|
+
readonly textAnchor?: string;
|
|
19
|
+
readonly tooltip?: string | ((datum: any) => string);
|
|
20
|
+
readonly xAccessor?: (datum: any) => any;
|
|
21
|
+
readonly xScale?: ScaleContinuousNumeric<number, number>;
|
|
22
|
+
readonly x?: number | (({ xScale, xAccessor, datum, plotData, }: {
|
|
23
|
+
xScale: ScaleContinuousNumeric<number, number>;
|
|
24
|
+
xAccessor: (datum: any) => any;
|
|
25
|
+
datum: any;
|
|
26
|
+
plotData: any[];
|
|
27
|
+
}) => number);
|
|
28
|
+
readonly yScale?: ScaleContinuousNumeric<number, number>;
|
|
29
|
+
readonly y?: number | (({ yScale, datum, plotData, }: {
|
|
30
|
+
yScale: ScaleContinuousNumeric<number, number>;
|
|
31
|
+
datum: any;
|
|
32
|
+
plotData: any[];
|
|
33
|
+
}) => number);
|
|
34
|
+
}
|
|
35
|
+
export declare class LabelAnnotation extends React.Component<LabelAnnotationProps> {
|
|
36
|
+
static defaultProps: {
|
|
37
|
+
className: string;
|
|
38
|
+
textAnchor: string;
|
|
39
|
+
fontFamily: string;
|
|
40
|
+
fontSize: number;
|
|
41
|
+
fill: string;
|
|
42
|
+
opacity: number;
|
|
43
|
+
rotate: number;
|
|
44
|
+
x: ({ xScale, xAccessor, datum, }: {
|
|
45
|
+
xScale: ScaleContinuousNumeric<number, number>;
|
|
46
|
+
xAccessor: any;
|
|
47
|
+
datum: any;
|
|
48
|
+
}) => number;
|
|
49
|
+
};
|
|
50
|
+
render(): JSX.Element;
|
|
51
|
+
private readonly handleClick;
|
|
52
|
+
private readonly helper;
|
|
53
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { functor } from "@tradingaction/core";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
export class LabelAnnotation extends React.Component {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
this.handleClick = (e) => {
|
|
7
|
+
const { onClick, xScale, yScale, datum } = this.props;
|
|
8
|
+
if (onClick !== undefined) {
|
|
9
|
+
onClick(e, { xScale, yScale, datum });
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
this.helper = () => {
|
|
13
|
+
const { x, y, datum, fill, text, tooltip, xAccessor, xScale, yScale, plotData } = this.props;
|
|
14
|
+
const xFunc = functor(x);
|
|
15
|
+
const yFunc = functor(y);
|
|
16
|
+
const [xPos, yPos] = [
|
|
17
|
+
xFunc({ xScale, xAccessor, datum, plotData }),
|
|
18
|
+
yFunc({ yScale, datum, plotData }),
|
|
19
|
+
];
|
|
20
|
+
return {
|
|
21
|
+
xPos,
|
|
22
|
+
yPos,
|
|
23
|
+
text: functor(text)(datum),
|
|
24
|
+
fill: functor(fill)(datum),
|
|
25
|
+
tooltip: functor(tooltip)(datum),
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
render() {
|
|
30
|
+
const { className, textAnchor, fontFamily, fontSize, opacity, rotate } = this.props;
|
|
31
|
+
const { xPos, yPos, fill, text, tooltip } = this.helper();
|
|
32
|
+
return (React.createElement("g", { className: className },
|
|
33
|
+
React.createElement("title", null, tooltip),
|
|
34
|
+
React.createElement("text", { x: xPos, y: yPos, fontFamily: fontFamily, fontSize: fontSize, fill: fill, opacity: opacity, transform: `rotate(${rotate}, ${xPos}, ${yPos})`, onClick: this.handleClick, textAnchor: textAnchor }, text)));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
LabelAnnotation.defaultProps = {
|
|
38
|
+
className: "react-financial-charts-label-annotation",
|
|
39
|
+
textAnchor: "middle",
|
|
40
|
+
fontFamily: "-apple-system, system-ui, Roboto, 'Helvetica Neue', Ubuntu, sans-serif",
|
|
41
|
+
fontSize: 12,
|
|
42
|
+
fill: "#000000",
|
|
43
|
+
opacity: 1,
|
|
44
|
+
rotate: 0,
|
|
45
|
+
x: ({ xScale, xAccessor, datum, }) => xScale(xAccessor(datum)),
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=LabelAnnotation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LabelAnnotation.js","sourceRoot":"","sources":["../src/LabelAnnotation.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAmD/B,MAAM,OAAO,eAAgB,SAAQ,KAAK,CAAC,SAA+B;IAA1E;;QA6CqB,gBAAW,GAAG,CAAC,CAAmB,EAAE,EAAE;YACnD,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;YACtD,IAAI,OAAO,KAAK,SAAS,EAAE;gBACvB,OAAO,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;aACzC;QACL,CAAC,CAAC;QAEe,WAAM,GAAG,GAAG,EAAE;YAC3B,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;YAE7F,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;YACzB,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;YAEz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Z,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,CAAC;IACV,MAAM,EAAE,CAAC;IACT,CAAC,EAAE,CAAC,EACA,MAAM,EACN,SAAS,EACT,KAAK,GAKR,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;CACjC,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ScaleContinuousNumeric } from "d3-scale";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
export interface SvgPathAnnotationProps {
|
|
4
|
+
readonly className?: string;
|
|
5
|
+
readonly datum?: any;
|
|
6
|
+
readonly fill?: string | ((datum: any) => string);
|
|
7
|
+
readonly onClick?: (e: React.MouseEvent, data: {
|
|
8
|
+
xScale?: ScaleContinuousNumeric<number, number>;
|
|
9
|
+
yScale?: ScaleContinuousNumeric<number, number>;
|
|
10
|
+
datum: any;
|
|
11
|
+
}) => void;
|
|
12
|
+
readonly opacity?: number;
|
|
13
|
+
readonly path: (datum: any) => string;
|
|
14
|
+
readonly pathHeight: number;
|
|
15
|
+
readonly pathWidth: number;
|
|
16
|
+
readonly plotData: any[];
|
|
17
|
+
readonly stroke?: string;
|
|
18
|
+
readonly tooltip?: string | ((datum: any) => string);
|
|
19
|
+
readonly xAccessor?: (datum: any) => any;
|
|
20
|
+
readonly x?: number | (({ xScale, xAccessor, datum, plotData, }: {
|
|
21
|
+
xScale: ScaleContinuousNumeric<number, number>;
|
|
22
|
+
xAccessor: (datum: any) => any;
|
|
23
|
+
datum: any;
|
|
24
|
+
plotData: any[];
|
|
25
|
+
}) => number);
|
|
26
|
+
readonly xScale?: ScaleContinuousNumeric<number, number>;
|
|
27
|
+
readonly y?: number | (({ yScale, datum, plotData, }: {
|
|
28
|
+
yScale: ScaleContinuousNumeric<number, number>;
|
|
29
|
+
datum: any;
|
|
30
|
+
plotData: any[];
|
|
31
|
+
}) => number);
|
|
32
|
+
readonly yScale?: ScaleContinuousNumeric<number, number>;
|
|
33
|
+
}
|
|
34
|
+
export declare class SvgPathAnnotation extends React.Component<SvgPathAnnotationProps> {
|
|
35
|
+
static defaultProps: {
|
|
36
|
+
className: string;
|
|
37
|
+
opacity: number;
|
|
38
|
+
x: ({ xScale, xAccessor, datum, }: {
|
|
39
|
+
xScale: ScaleContinuousNumeric<number, number>;
|
|
40
|
+
xAccessor: any;
|
|
41
|
+
datum: any;
|
|
42
|
+
}) => number;
|
|
43
|
+
};
|
|
44
|
+
render(): JSX.Element;
|
|
45
|
+
private readonly handleClick;
|
|
46
|
+
private readonly helper;
|
|
47
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { functor } from "@tradingaction/core";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
export class SvgPathAnnotation extends React.Component {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
this.handleClick = (e) => {
|
|
7
|
+
const { onClick, xScale, yScale, datum } = this.props;
|
|
8
|
+
if (onClick !== undefined) {
|
|
9
|
+
onClick(e, { xScale, yScale, datum });
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
this.helper = () => {
|
|
13
|
+
const { x, y, datum, fill, tooltip, xAccessor, xScale, yScale, plotData } = this.props;
|
|
14
|
+
const xFunc = functor(x);
|
|
15
|
+
const yFunc = functor(y);
|
|
16
|
+
const [xPos, yPos] = [
|
|
17
|
+
xFunc({ xScale, xAccessor, datum, plotData }),
|
|
18
|
+
yFunc({ yScale, datum, plotData }),
|
|
19
|
+
];
|
|
20
|
+
return {
|
|
21
|
+
x: Math.round(xPos),
|
|
22
|
+
y: Math.round(yPos),
|
|
23
|
+
fill: functor(fill)(datum),
|
|
24
|
+
tooltip: functor(tooltip)(datum),
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
render() {
|
|
29
|
+
const { className, datum, stroke, opacity, path, pathWidth, pathHeight } = this.props;
|
|
30
|
+
const { x, y, fill, tooltip } = this.helper();
|
|
31
|
+
return (React.createElement("g", { className: className, onClick: this.handleClick },
|
|
32
|
+
React.createElement("title", null, tooltip),
|
|
33
|
+
React.createElement("path", { transform: `translate(${x - pathWidth},${y - pathHeight})`, d: path(datum), stroke: stroke, fill: fill, opacity: opacity })));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
SvgPathAnnotation.defaultProps = {
|
|
37
|
+
className: "react-financial-charts-svg-path-annotation",
|
|
38
|
+
opacity: 1,
|
|
39
|
+
x: ({ xScale, xAccessor, datum, }) => xScale(xAccessor(datum)),
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=SvgPathAnnotation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SvgPathAnnotation.js","sourceRoot":"","sources":["../src/SvgPathAnnotation.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAkD/B,MAAM,OAAO,iBAAkB,SAAQ,KAAK,CAAC,SAAiC;IAA9E;;QAkCqB,gBAAW,GAAG,CAAC,CAAmB,EAAE,EAAE;YACnD,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;YACtD,IAAI,OAAO,KAAK,SAAS,EAAE;gBACvB,OAAO,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;aACzC;QACL,CAAC,CAAC;QAEe,WAAM,GAAG,GAAG,EAAE;YAC3B,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;YAEvF,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;YACzB,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,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E,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;CACjC,CAAC"}
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,SAAS,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tradingaction/annotations",
|
|
3
|
+
"version": "2.0.13",
|
|
4
|
+
"description": "Annotations 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
|
+
"peerDependencies": {
|
|
41
|
+
"react": "^16.0.0 || ^17.0.0 || ^18.0.0",
|
|
42
|
+
"react-dom": "^16.0.0 || ^17.0.0 || ^18.0.0"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@tradingaction/core": "^2.0.13",
|
|
46
|
+
"@types/d3-scale": "^3.2.2"
|
|
47
|
+
},
|
|
48
|
+
"gitHead": "9c9bc635a2291c8da0e1dd5befa4000e96d83119"
|
|
49
|
+
}
|
package/src/Annotate.tsx
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { GenericChartComponent } from "@tradingaction/core";
|
|
3
|
+
|
|
4
|
+
export interface AnnotateProps {
|
|
5
|
+
readonly className?: string;
|
|
6
|
+
readonly with: React.ElementType;
|
|
7
|
+
readonly when: (value: any, index: number, array: any[]) => boolean;
|
|
8
|
+
readonly usingProps?: any;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class Annotate extends React.Component<AnnotateProps> {
|
|
12
|
+
public static defaultProps = {
|
|
13
|
+
className:
|
|
14
|
+
"react-financial-charts-enable-interaction react-financial-charts-annotate react-financial-charts-default-cursor",
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
public render() {
|
|
18
|
+
return <GenericChartComponent svgDraw={this.renderSVG} drawOn={["pan"]} />;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
private readonly renderSVG = (moreProps: any) => {
|
|
22
|
+
const {
|
|
23
|
+
xAccessor,
|
|
24
|
+
xScale,
|
|
25
|
+
chartConfig: { yScale },
|
|
26
|
+
plotData,
|
|
27
|
+
} = moreProps;
|
|
28
|
+
|
|
29
|
+
const { className, usingProps, with: Annotation, when } = this.props;
|
|
30
|
+
|
|
31
|
+
const data = (plotData as unknown[]).filter(when);
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<g className={className}>
|
|
35
|
+
{data.map((d, idx) => {
|
|
36
|
+
return (
|
|
37
|
+
<Annotation
|
|
38
|
+
key={idx}
|
|
39
|
+
{...usingProps}
|
|
40
|
+
xScale={xScale}
|
|
41
|
+
yScale={yScale}
|
|
42
|
+
xAccessor={xAccessor}
|
|
43
|
+
plotData={plotData}
|
|
44
|
+
datum={d}
|
|
45
|
+
/>
|
|
46
|
+
);
|
|
47
|
+
})}
|
|
48
|
+
</g>
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { functor } from "@tradingaction/core";
|
|
2
|
+
import { ScaleContinuousNumeric } from "d3-scale";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
|
|
5
|
+
export interface BarAnnotationProps {
|
|
6
|
+
readonly className?: string;
|
|
7
|
+
readonly path?: ({ x, y }: { x: number; y: number }) => string;
|
|
8
|
+
readonly onClick?: (
|
|
9
|
+
e: React.MouseEvent,
|
|
10
|
+
data: {
|
|
11
|
+
xScale?: ScaleContinuousNumeric<number, number>;
|
|
12
|
+
yScale?: ScaleContinuousNumeric<number, number>;
|
|
13
|
+
datum: any;
|
|
14
|
+
},
|
|
15
|
+
) => void;
|
|
16
|
+
readonly xAccessor?: (datum: any) => any;
|
|
17
|
+
readonly xScale?: ScaleContinuousNumeric<number, number>;
|
|
18
|
+
readonly yScale?: ScaleContinuousNumeric<number, number>;
|
|
19
|
+
readonly datum?: object;
|
|
20
|
+
readonly stroke?: string;
|
|
21
|
+
readonly fill?: string | ((datum: any) => string);
|
|
22
|
+
readonly opacity?: number;
|
|
23
|
+
readonly plotData: any[];
|
|
24
|
+
readonly text?: string;
|
|
25
|
+
readonly textAnchor?: string;
|
|
26
|
+
readonly fontFamily?: string;
|
|
27
|
+
readonly fontSize?: number;
|
|
28
|
+
readonly textOpacity?: number;
|
|
29
|
+
readonly textFill?: string;
|
|
30
|
+
readonly textRotate?: number;
|
|
31
|
+
readonly textXOffset?: number;
|
|
32
|
+
readonly textYOffset?: number;
|
|
33
|
+
readonly textIcon?: string;
|
|
34
|
+
readonly textIconFontSize?: number;
|
|
35
|
+
readonly textIconOpacity?: number;
|
|
36
|
+
readonly textIconFill?: string;
|
|
37
|
+
readonly textIconRotate?: number;
|
|
38
|
+
readonly textIconXOffset?: number;
|
|
39
|
+
readonly textIconYOffset?: number;
|
|
40
|
+
readonly textIconAnchor?: string;
|
|
41
|
+
readonly tooltip?: string | ((datum: any) => string);
|
|
42
|
+
readonly x?:
|
|
43
|
+
| number
|
|
44
|
+
| (({
|
|
45
|
+
xScale,
|
|
46
|
+
xAccessor,
|
|
47
|
+
datum,
|
|
48
|
+
plotData,
|
|
49
|
+
}: {
|
|
50
|
+
xScale: ScaleContinuousNumeric<number, number>;
|
|
51
|
+
xAccessor: (datum: any) => any;
|
|
52
|
+
datum: any;
|
|
53
|
+
plotData: any[];
|
|
54
|
+
}) => number);
|
|
55
|
+
readonly y?:
|
|
56
|
+
| number
|
|
57
|
+
| (({
|
|
58
|
+
yScale,
|
|
59
|
+
datum,
|
|
60
|
+
plotData,
|
|
61
|
+
}: {
|
|
62
|
+
yScale: ScaleContinuousNumeric<number, number>;
|
|
63
|
+
datum: any;
|
|
64
|
+
plotData: any[];
|
|
65
|
+
}) => number);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export class BarAnnotation extends React.Component<BarAnnotationProps> {
|
|
69
|
+
public static defaultProps = {
|
|
70
|
+
className: "react-financial-charts-bar-annotation",
|
|
71
|
+
opacity: 1,
|
|
72
|
+
fill: "#000000",
|
|
73
|
+
fontFamily: "-apple-system, system-ui, Roboto, 'Helvetica Neue', Ubuntu, sans-serif",
|
|
74
|
+
fontSize: 10,
|
|
75
|
+
textAnchor: "middle",
|
|
76
|
+
textFill: "#000000",
|
|
77
|
+
textOpacity: 1,
|
|
78
|
+
textIconFill: "#000000",
|
|
79
|
+
textIconFontSize: 10,
|
|
80
|
+
x: ({
|
|
81
|
+
xScale,
|
|
82
|
+
xAccessor,
|
|
83
|
+
datum,
|
|
84
|
+
}: {
|
|
85
|
+
xScale: ScaleContinuousNumeric<number, number>;
|
|
86
|
+
xAccessor: any;
|
|
87
|
+
datum: any;
|
|
88
|
+
}) => xScale(xAccessor(datum)),
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
public render() {
|
|
92
|
+
const {
|
|
93
|
+
className,
|
|
94
|
+
stroke,
|
|
95
|
+
opacity,
|
|
96
|
+
xAccessor,
|
|
97
|
+
xScale,
|
|
98
|
+
yScale,
|
|
99
|
+
path,
|
|
100
|
+
text,
|
|
101
|
+
textXOffset,
|
|
102
|
+
textYOffset,
|
|
103
|
+
textAnchor,
|
|
104
|
+
fontFamily,
|
|
105
|
+
fontSize,
|
|
106
|
+
textFill,
|
|
107
|
+
textOpacity,
|
|
108
|
+
textRotate,
|
|
109
|
+
textIcon,
|
|
110
|
+
textIconFontSize,
|
|
111
|
+
textIconFill,
|
|
112
|
+
textIconOpacity,
|
|
113
|
+
textIconRotate,
|
|
114
|
+
textIconXOffset,
|
|
115
|
+
textIconYOffset,
|
|
116
|
+
} = this.props;
|
|
117
|
+
|
|
118
|
+
const { x, y, fill, tooltip } = this.helper(this.props, xAccessor, xScale, yScale);
|
|
119
|
+
|
|
120
|
+
return (
|
|
121
|
+
<g className={className} onClick={this.onClick}>
|
|
122
|
+
{tooltip !== undefined ? <title>{tooltip}</title> : null}
|
|
123
|
+
{text !== undefined ? (
|
|
124
|
+
<text
|
|
125
|
+
x={x}
|
|
126
|
+
y={y}
|
|
127
|
+
dx={textXOffset}
|
|
128
|
+
dy={textYOffset}
|
|
129
|
+
fontFamily={fontFamily}
|
|
130
|
+
fontSize={fontSize}
|
|
131
|
+
fill={textFill}
|
|
132
|
+
opacity={textOpacity}
|
|
133
|
+
transform={textRotate != undefined ? `rotate(${textRotate}, ${x}, ${y})` : undefined}
|
|
134
|
+
textAnchor={textAnchor}
|
|
135
|
+
>
|
|
136
|
+
{text}
|
|
137
|
+
</text>
|
|
138
|
+
) : null}
|
|
139
|
+
{textIcon !== undefined ? (
|
|
140
|
+
<text
|
|
141
|
+
x={x}
|
|
142
|
+
y={y}
|
|
143
|
+
dx={textIconXOffset}
|
|
144
|
+
dy={textIconYOffset}
|
|
145
|
+
fontSize={textIconFontSize}
|
|
146
|
+
fill={textIconFill}
|
|
147
|
+
opacity={textIconOpacity}
|
|
148
|
+
transform={textIconRotate != undefined ? `rotate(${textIconRotate}, ${x}, ${y})` : undefined}
|
|
149
|
+
textAnchor={textAnchor}
|
|
150
|
+
>
|
|
151
|
+
{textIcon}
|
|
152
|
+
</text>
|
|
153
|
+
) : null}
|
|
154
|
+
{path !== undefined ? <path d={path({ x, y })} stroke={stroke} fill={fill} opacity={opacity} /> : null}
|
|
155
|
+
</g>
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
private readonly onClick = (e: React.MouseEvent) => {
|
|
160
|
+
const { onClick, xScale, yScale, datum } = this.props;
|
|
161
|
+
if (onClick !== undefined) {
|
|
162
|
+
onClick(e, { xScale, yScale, datum });
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
private readonly helper = (props: BarAnnotationProps, xAccessor: any, xScale: any, yScale: any) => {
|
|
167
|
+
const { x, y, datum, fill, tooltip, plotData } = props;
|
|
168
|
+
|
|
169
|
+
const xFunc = functor(x);
|
|
170
|
+
const yFunc = functor(y);
|
|
171
|
+
|
|
172
|
+
const [xPos, yPos] = [xFunc({ xScale, xAccessor, datum, plotData }), yFunc({ yScale, datum, plotData })];
|
|
173
|
+
|
|
174
|
+
return {
|
|
175
|
+
x: xPos,
|
|
176
|
+
y: yPos,
|
|
177
|
+
fill: functor(fill)(datum),
|
|
178
|
+
tooltip: functor(tooltip)(datum),
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
}
|
package/src/Label.tsx
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { GenericComponent, functor, ChartCanvasContext } from "@tradingaction/core";
|
|
2
|
+
import { ScaleContinuousNumeric } from "d3-scale";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
|
|
5
|
+
export interface LabelProps {
|
|
6
|
+
readonly datum?: any;
|
|
7
|
+
readonly fillStyle?: string | ((datum: any) => string);
|
|
8
|
+
readonly fontFamily?: string;
|
|
9
|
+
readonly fontSize?: number;
|
|
10
|
+
readonly fontWeight?: string;
|
|
11
|
+
readonly rotate?: number;
|
|
12
|
+
readonly selectCanvas?: (canvases: any) => any;
|
|
13
|
+
readonly text?: string | ((datum: any) => string);
|
|
14
|
+
readonly textAlign?: CanvasTextAlign;
|
|
15
|
+
readonly x:
|
|
16
|
+
| number
|
|
17
|
+
| ((xScale: ScaleContinuousNumeric<number, number>, xAccessor: any, datum: any, plotData: any[]) => number);
|
|
18
|
+
readonly xAccessor?: (datum: any) => any;
|
|
19
|
+
readonly xScale?: ScaleContinuousNumeric<number, number>;
|
|
20
|
+
readonly y: number | ((yScale: ScaleContinuousNumeric<number, number>, datum: any, plotData: any[]) => number);
|
|
21
|
+
readonly yScale?: ScaleContinuousNumeric<number, number>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class Label extends React.Component<LabelProps> {
|
|
25
|
+
public static defaultProps = {
|
|
26
|
+
fontFamily: "-apple-system, system-ui, Roboto, 'Helvetica Neue', Ubuntu, sans-serif",
|
|
27
|
+
fontSize: 64,
|
|
28
|
+
fontWeight: "bold",
|
|
29
|
+
fillStyle: "#dcdcdc",
|
|
30
|
+
rotate: 0,
|
|
31
|
+
x: ({ xScale, xAccessor, datum }: any) => xScale(xAccessor(datum)),
|
|
32
|
+
selectCanvas: (canvases: any) => canvases.bg,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
public static contextType = ChartCanvasContext;
|
|
36
|
+
|
|
37
|
+
public render() {
|
|
38
|
+
const { selectCanvas } = this.props;
|
|
39
|
+
|
|
40
|
+
return <GenericComponent canvasToDraw={selectCanvas} canvasDraw={this.drawOnCanvas} drawOn={[]} />;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private readonly drawOnCanvas = (ctx: CanvasRenderingContext2D, moreProps: any) => {
|
|
44
|
+
ctx.save();
|
|
45
|
+
|
|
46
|
+
const { textAlign = "center", fontFamily, fontSize, fontWeight, rotate } = this.props;
|
|
47
|
+
|
|
48
|
+
const { canvasOriginX, canvasOriginY, margin, ratio } = this.context;
|
|
49
|
+
|
|
50
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
51
|
+
ctx.scale(ratio, ratio);
|
|
52
|
+
|
|
53
|
+
if (canvasOriginX !== undefined) {
|
|
54
|
+
ctx.translate(canvasOriginX, canvasOriginY);
|
|
55
|
+
} else {
|
|
56
|
+
ctx.translate(margin.left + 0.5 * ratio, margin.top + 0.5 * ratio);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const { xScale, chartConfig, xAccessor } = moreProps;
|
|
60
|
+
|
|
61
|
+
const yScale = Array.isArray(chartConfig) || !chartConfig ? undefined : chartConfig.yScale;
|
|
62
|
+
|
|
63
|
+
const { xPos, yPos, fillStyle, text } = this.helper(moreProps, xAccessor, xScale, yScale);
|
|
64
|
+
|
|
65
|
+
ctx.save();
|
|
66
|
+
ctx.translate(xPos, yPos);
|
|
67
|
+
if (rotate !== undefined) {
|
|
68
|
+
const radians = (rotate / 180) * Math.PI;
|
|
69
|
+
|
|
70
|
+
ctx.rotate(radians);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (fontFamily !== undefined) {
|
|
74
|
+
ctx.font = `${fontWeight} ${fontSize}px ${fontFamily}`;
|
|
75
|
+
}
|
|
76
|
+
if (fillStyle !== undefined) {
|
|
77
|
+
ctx.fillStyle = fillStyle;
|
|
78
|
+
}
|
|
79
|
+
if (textAlign !== undefined) {
|
|
80
|
+
ctx.textAlign = textAlign;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
ctx.beginPath();
|
|
84
|
+
ctx.fillText(text, 0, 0);
|
|
85
|
+
ctx.restore();
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
private readonly helper = (
|
|
89
|
+
moreProps: any,
|
|
90
|
+
xAccessor: any,
|
|
91
|
+
xScale: ScaleContinuousNumeric<number, number>,
|
|
92
|
+
yScale: ScaleContinuousNumeric<number, number>,
|
|
93
|
+
) => {
|
|
94
|
+
const { x, y, datum, fillStyle, text } = this.props;
|
|
95
|
+
|
|
96
|
+
const { plotData } = moreProps;
|
|
97
|
+
|
|
98
|
+
const xFunc = functor(x);
|
|
99
|
+
const yFunc = functor(y);
|
|
100
|
+
|
|
101
|
+
const [xPos, yPos] = [xFunc({ xScale, xAccessor, datum, plotData }), yFunc({ yScale, datum, plotData })];
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
xPos,
|
|
105
|
+
yPos,
|
|
106
|
+
text: functor(text)(datum),
|
|
107
|
+
fillStyle: functor(fillStyle)(datum),
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { functor } from "@tradingaction/core";
|
|
2
|
+
import { ScaleContinuousNumeric } from "d3-scale";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
|
|
5
|
+
export interface LabelAnnotationProps {
|
|
6
|
+
readonly className?: string;
|
|
7
|
+
readonly datum?: any;
|
|
8
|
+
readonly fill?: string | ((datum: any) => string);
|
|
9
|
+
readonly fontFamily?: string;
|
|
10
|
+
readonly fontSize?: number;
|
|
11
|
+
readonly onClick?: (
|
|
12
|
+
e: React.MouseEvent,
|
|
13
|
+
data: {
|
|
14
|
+
xScale?: ScaleContinuousNumeric<number, number>;
|
|
15
|
+
yScale?: ScaleContinuousNumeric<number, number>;
|
|
16
|
+
datum: any;
|
|
17
|
+
},
|
|
18
|
+
) => void;
|
|
19
|
+
readonly opacity?: number;
|
|
20
|
+
readonly plotData: any[];
|
|
21
|
+
readonly rotate?: number;
|
|
22
|
+
readonly text?: string | ((datum: any) => string);
|
|
23
|
+
readonly textAnchor?: string;
|
|
24
|
+
readonly tooltip?: string | ((datum: any) => string);
|
|
25
|
+
readonly xAccessor?: (datum: any) => any;
|
|
26
|
+
readonly xScale?: ScaleContinuousNumeric<number, number>;
|
|
27
|
+
readonly x?:
|
|
28
|
+
| number
|
|
29
|
+
| (({
|
|
30
|
+
xScale,
|
|
31
|
+
xAccessor,
|
|
32
|
+
datum,
|
|
33
|
+
plotData,
|
|
34
|
+
}: {
|
|
35
|
+
xScale: ScaleContinuousNumeric<number, number>;
|
|
36
|
+
xAccessor: (datum: any) => any;
|
|
37
|
+
datum: any;
|
|
38
|
+
plotData: any[];
|
|
39
|
+
}) => number);
|
|
40
|
+
readonly yScale?: ScaleContinuousNumeric<number, number>;
|
|
41
|
+
readonly y?:
|
|
42
|
+
| number
|
|
43
|
+
| (({
|
|
44
|
+
yScale,
|
|
45
|
+
datum,
|
|
46
|
+
plotData,
|
|
47
|
+
}: {
|
|
48
|
+
yScale: ScaleContinuousNumeric<number, number>;
|
|
49
|
+
datum: any;
|
|
50
|
+
plotData: any[];
|
|
51
|
+
}) => number);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export class LabelAnnotation extends React.Component<LabelAnnotationProps> {
|
|
55
|
+
public static defaultProps = {
|
|
56
|
+
className: "react-financial-charts-label-annotation",
|
|
57
|
+
textAnchor: "middle",
|
|
58
|
+
fontFamily: "-apple-system, system-ui, Roboto, 'Helvetica Neue', Ubuntu, sans-serif",
|
|
59
|
+
fontSize: 12,
|
|
60
|
+
fill: "#000000",
|
|
61
|
+
opacity: 1,
|
|
62
|
+
rotate: 0,
|
|
63
|
+
x: ({
|
|
64
|
+
xScale,
|
|
65
|
+
xAccessor,
|
|
66
|
+
datum,
|
|
67
|
+
}: {
|
|
68
|
+
xScale: ScaleContinuousNumeric<number, number>;
|
|
69
|
+
xAccessor: any;
|
|
70
|
+
datum: any;
|
|
71
|
+
}) => xScale(xAccessor(datum)),
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
public render() {
|
|
75
|
+
const { className, textAnchor, fontFamily, fontSize, opacity, rotate } = this.props;
|
|
76
|
+
|
|
77
|
+
const { xPos, yPos, fill, text, tooltip } = this.helper();
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<g className={className}>
|
|
81
|
+
<title>{tooltip}</title>
|
|
82
|
+
<text
|
|
83
|
+
x={xPos}
|
|
84
|
+
y={yPos}
|
|
85
|
+
fontFamily={fontFamily}
|
|
86
|
+
fontSize={fontSize}
|
|
87
|
+
fill={fill}
|
|
88
|
+
opacity={opacity}
|
|
89
|
+
transform={`rotate(${rotate}, ${xPos}, ${yPos})`}
|
|
90
|
+
onClick={this.handleClick}
|
|
91
|
+
textAnchor={textAnchor}
|
|
92
|
+
>
|
|
93
|
+
{text}
|
|
94
|
+
</text>
|
|
95
|
+
</g>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
private readonly handleClick = (e: React.MouseEvent) => {
|
|
100
|
+
const { onClick, xScale, yScale, datum } = this.props;
|
|
101
|
+
if (onClick !== undefined) {
|
|
102
|
+
onClick(e, { xScale, yScale, datum });
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
private readonly helper = () => {
|
|
107
|
+
const { x, y, datum, fill, text, tooltip, xAccessor, xScale, yScale, plotData } = this.props;
|
|
108
|
+
|
|
109
|
+
const xFunc = functor(x);
|
|
110
|
+
const yFunc = functor(y);
|
|
111
|
+
|
|
112
|
+
const [xPos, yPos]: [number, number] = [
|
|
113
|
+
xFunc({ xScale, xAccessor, datum, plotData }),
|
|
114
|
+
yFunc({ yScale, datum, plotData }),
|
|
115
|
+
];
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
xPos,
|
|
119
|
+
yPos,
|
|
120
|
+
text: functor(text)(datum),
|
|
121
|
+
fill: functor(fill)(datum),
|
|
122
|
+
tooltip: functor(tooltip)(datum),
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { functor } from "@tradingaction/core";
|
|
2
|
+
import { ScaleContinuousNumeric } from "d3-scale";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
|
|
5
|
+
export interface SvgPathAnnotationProps {
|
|
6
|
+
readonly className?: string;
|
|
7
|
+
readonly datum?: any;
|
|
8
|
+
readonly fill?: string | ((datum: any) => string);
|
|
9
|
+
readonly onClick?: (
|
|
10
|
+
e: React.MouseEvent,
|
|
11
|
+
data: {
|
|
12
|
+
xScale?: ScaleContinuousNumeric<number, number>;
|
|
13
|
+
yScale?: ScaleContinuousNumeric<number, number>;
|
|
14
|
+
datum: any;
|
|
15
|
+
},
|
|
16
|
+
) => void;
|
|
17
|
+
readonly opacity?: number;
|
|
18
|
+
readonly path: (datum: any) => string;
|
|
19
|
+
readonly pathHeight: number;
|
|
20
|
+
readonly pathWidth: number;
|
|
21
|
+
readonly plotData: any[];
|
|
22
|
+
readonly stroke?: string;
|
|
23
|
+
readonly tooltip?: string | ((datum: any) => string);
|
|
24
|
+
readonly xAccessor?: (datum: any) => any;
|
|
25
|
+
readonly x?:
|
|
26
|
+
| number
|
|
27
|
+
| (({
|
|
28
|
+
xScale,
|
|
29
|
+
xAccessor,
|
|
30
|
+
datum,
|
|
31
|
+
plotData,
|
|
32
|
+
}: {
|
|
33
|
+
xScale: ScaleContinuousNumeric<number, number>;
|
|
34
|
+
xAccessor: (datum: any) => any;
|
|
35
|
+
datum: any;
|
|
36
|
+
plotData: any[];
|
|
37
|
+
}) => number);
|
|
38
|
+
readonly xScale?: ScaleContinuousNumeric<number, number>;
|
|
39
|
+
readonly y?:
|
|
40
|
+
| number
|
|
41
|
+
| (({
|
|
42
|
+
yScale,
|
|
43
|
+
datum,
|
|
44
|
+
plotData,
|
|
45
|
+
}: {
|
|
46
|
+
yScale: ScaleContinuousNumeric<number, number>;
|
|
47
|
+
datum: any;
|
|
48
|
+
plotData: any[];
|
|
49
|
+
}) => number);
|
|
50
|
+
readonly yScale?: ScaleContinuousNumeric<number, number>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export class SvgPathAnnotation extends React.Component<SvgPathAnnotationProps> {
|
|
54
|
+
public static defaultProps = {
|
|
55
|
+
className: "react-financial-charts-svg-path-annotation",
|
|
56
|
+
opacity: 1,
|
|
57
|
+
x: ({
|
|
58
|
+
xScale,
|
|
59
|
+
xAccessor,
|
|
60
|
+
datum,
|
|
61
|
+
}: {
|
|
62
|
+
xScale: ScaleContinuousNumeric<number, number>;
|
|
63
|
+
xAccessor: any;
|
|
64
|
+
datum: any;
|
|
65
|
+
}) => xScale(xAccessor(datum)),
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
public render() {
|
|
69
|
+
const { className, datum, stroke, opacity, path, pathWidth, pathHeight } = this.props;
|
|
70
|
+
|
|
71
|
+
const { x, y, fill, tooltip } = this.helper();
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<g className={className} onClick={this.handleClick}>
|
|
75
|
+
<title>{tooltip}</title>
|
|
76
|
+
<path
|
|
77
|
+
transform={`translate(${x - pathWidth},${y - pathHeight})`}
|
|
78
|
+
d={path(datum)}
|
|
79
|
+
stroke={stroke}
|
|
80
|
+
fill={fill}
|
|
81
|
+
opacity={opacity}
|
|
82
|
+
/>
|
|
83
|
+
</g>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private readonly handleClick = (e: React.MouseEvent) => {
|
|
88
|
+
const { onClick, xScale, yScale, datum } = this.props;
|
|
89
|
+
if (onClick !== undefined) {
|
|
90
|
+
onClick(e, { xScale, yScale, datum });
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
private readonly helper = () => {
|
|
95
|
+
const { x, y, datum, fill, tooltip, xAccessor, xScale, yScale, plotData } = this.props;
|
|
96
|
+
|
|
97
|
+
const xFunc = functor(x);
|
|
98
|
+
const yFunc = functor(y);
|
|
99
|
+
|
|
100
|
+
const [xPos, yPos]: [number, number] = [
|
|
101
|
+
xFunc({ xScale, xAccessor, datum, plotData }),
|
|
102
|
+
yFunc({ yScale, datum, plotData }),
|
|
103
|
+
];
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
x: Math.round(xPos),
|
|
107
|
+
y: Math.round(yPos),
|
|
108
|
+
fill: functor(fill)(datum),
|
|
109
|
+
tooltip: functor(tooltip)(datum),
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
}
|