@tradingaction/tooltip 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/BollingerBandTooltip.d.ts +40 -0
- package/lib/BollingerBandTooltip.js +48 -0
- package/lib/BollingerBandTooltip.js.map +1 -0
- package/lib/GroupTooltip.d.ts +41 -0
- package/lib/GroupTooltip.js +80 -0
- package/lib/GroupTooltip.js.map +1 -0
- package/lib/HoverTooltip.d.ts +57 -0
- package/lib/HoverTooltip.js +174 -0
- package/lib/HoverTooltip.js.map +1 -0
- package/lib/MACDTooltip.d.ts +46 -0
- package/lib/MACDTooltip.js +58 -0
- package/lib/MACDTooltip.js.map +1 -0
- package/lib/MovingAverageTooltip.d.ts +65 -0
- package/lib/MovingAverageTooltip.js +71 -0
- package/lib/MovingAverageTooltip.js.map +1 -0
- package/lib/OHLCTooltip.d.ts +65 -0
- package/lib/OHLCTooltip.js +78 -0
- package/lib/OHLCTooltip.js.map +1 -0
- package/lib/RSITooltip.d.ts +32 -0
- package/lib/RSITooltip.js +36 -0
- package/lib/RSITooltip.js.map +1 -0
- package/lib/SingleTooltip.d.ts +29 -0
- package/lib/SingleTooltip.js +82 -0
- package/lib/SingleTooltip.js.map +1 -0
- package/lib/SingleValueTooltip.d.ts +46 -0
- package/lib/SingleValueTooltip.js +65 -0
- package/lib/SingleValueTooltip.js.map +1 -0
- package/lib/StochasticTooltip.d.ts +43 -0
- package/lib/StochasticTooltip.js +44 -0
- package/lib/StochasticTooltip.js.map +1 -0
- package/lib/ToolTipTSpanLabel.d.ts +8 -0
- package/lib/ToolTipTSpanLabel.js +23 -0
- package/lib/ToolTipTSpanLabel.js.map +1 -0
- package/lib/ToolTipText.d.ts +9 -0
- package/lib/ToolTipText.js +24 -0
- package/lib/ToolTipText.js.map +1 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +13 -0
- package/lib/index.js.map +1 -0
- package/package.json +51 -0
- package/src/BollingerBandTooltip.tsx +99 -0
- package/src/GroupTooltip.tsx +152 -0
- package/src/HoverTooltip.tsx +270 -0
- package/src/MACDTooltip.tsx +116 -0
- package/src/MovingAverageTooltip.tsx +167 -0
- package/src/OHLCTooltip.tsx +150 -0
- package/src/RSITooltip.tsx +80 -0
- package/src/SingleTooltip.tsx +122 -0
- package/src/SingleValueTooltip.tsx +131 -0
- package/src/StochasticTooltip.tsx +97 -0
- package/src/ToolTipTSpanLabel.tsx +14 -0
- package/src/ToolTipText.tsx +15 -0
- package/src/index.ts +12 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export interface StochasticTooltipProps {
|
|
3
|
+
readonly origin: number[] | ((width: number, height: number) => [number, number]);
|
|
4
|
+
readonly className?: string;
|
|
5
|
+
readonly fontFamily?: string;
|
|
6
|
+
readonly fontSize?: number;
|
|
7
|
+
readonly fontWeight?: number;
|
|
8
|
+
readonly labelFill?: string;
|
|
9
|
+
readonly onClick?: (event: React.MouseEvent) => void;
|
|
10
|
+
readonly yAccessor: (currentItem: any) => {
|
|
11
|
+
K: number;
|
|
12
|
+
D: number;
|
|
13
|
+
};
|
|
14
|
+
readonly options: {
|
|
15
|
+
windowSize: number;
|
|
16
|
+
kWindowSize: number;
|
|
17
|
+
dWindowSize: number;
|
|
18
|
+
};
|
|
19
|
+
readonly appearance: {
|
|
20
|
+
stroke: {
|
|
21
|
+
dLine: string;
|
|
22
|
+
kLine: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
readonly displayFormat: (value: number) => string;
|
|
26
|
+
readonly displayInit?: string;
|
|
27
|
+
readonly displayValuesFor?: (props: StochasticTooltipProps, moreProps: any) => any;
|
|
28
|
+
readonly label: string;
|
|
29
|
+
}
|
|
30
|
+
export declare class StochasticTooltip extends React.Component<StochasticTooltipProps> {
|
|
31
|
+
static defaultProps: {
|
|
32
|
+
className: string;
|
|
33
|
+
displayFormat: (n: number | {
|
|
34
|
+
valueOf(): number;
|
|
35
|
+
}) => string;
|
|
36
|
+
displayInit: string;
|
|
37
|
+
displayValuesFor: (_: any, props: any) => any;
|
|
38
|
+
label: string;
|
|
39
|
+
origin: number[];
|
|
40
|
+
};
|
|
41
|
+
render(): JSX.Element;
|
|
42
|
+
private readonly renderSVG;
|
|
43
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { functor, GenericChartComponent } from "@tradingaction/core";
|
|
2
|
+
import { format } from "d3-format";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { ToolTipText } from "./ToolTipText";
|
|
5
|
+
import { ToolTipTSpanLabel } from "./ToolTipTSpanLabel";
|
|
6
|
+
export class StochasticTooltip extends React.Component {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.renderSVG = (moreProps) => {
|
|
10
|
+
var _a, _b, _c;
|
|
11
|
+
const { onClick, fontFamily, fontSize, fontWeight, yAccessor, displayFormat, origin: originProp, label, className, displayInit, displayValuesFor = StochasticTooltip.defaultProps.displayValuesFor, options, appearance, labelFill, } = this.props;
|
|
12
|
+
const { chartConfig: { width, height }, fullData, } = moreProps;
|
|
13
|
+
const currentItem = (_a = displayValuesFor(this.props, moreProps)) !== null && _a !== void 0 ? _a : fullData[fullData.length - 1];
|
|
14
|
+
const stochastic = currentItem && yAccessor(currentItem);
|
|
15
|
+
const K = (_b = ((stochastic === null || stochastic === void 0 ? void 0 : stochastic.K) && displayFormat(stochastic.K))) !== null && _b !== void 0 ? _b : displayInit;
|
|
16
|
+
const D = (_c = ((stochastic === null || stochastic === void 0 ? void 0 : stochastic.D) && displayFormat(stochastic.D))) !== null && _c !== void 0 ? _c : displayInit;
|
|
17
|
+
const origin = functor(originProp);
|
|
18
|
+
const [x, y] = origin(width, height);
|
|
19
|
+
const { stroke } = appearance;
|
|
20
|
+
return (React.createElement("g", { className: className, transform: `translate(${x}, ${y})`, onClick: onClick },
|
|
21
|
+
React.createElement(ToolTipText, { x: 0, y: 0, fontFamily: fontFamily, fontSize: fontSize, fontWeight: fontWeight },
|
|
22
|
+
React.createElement(ToolTipTSpanLabel, { fill: labelFill }, `${label} %K(`),
|
|
23
|
+
React.createElement("tspan", { fill: stroke.kLine }, `${options.windowSize}, ${options.kWindowSize}`),
|
|
24
|
+
React.createElement(ToolTipTSpanLabel, { fill: labelFill }, "): "),
|
|
25
|
+
React.createElement("tspan", { fill: stroke.kLine }, K),
|
|
26
|
+
React.createElement(ToolTipTSpanLabel, { fill: labelFill }, " %D ("),
|
|
27
|
+
React.createElement("tspan", { fill: stroke.dLine }, options.dWindowSize),
|
|
28
|
+
React.createElement(ToolTipTSpanLabel, { fill: labelFill }, "): "),
|
|
29
|
+
React.createElement("tspan", { fill: stroke.dLine }, D))));
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
render() {
|
|
33
|
+
return React.createElement(GenericChartComponent, { clip: false, svgDraw: this.renderSVG, drawOn: ["mousemove"] });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
StochasticTooltip.defaultProps = {
|
|
37
|
+
className: "react-financial-charts-tooltip",
|
|
38
|
+
displayFormat: format(".2f"),
|
|
39
|
+
displayInit: "n/a",
|
|
40
|
+
displayValuesFor: (_, props) => props.currentItem,
|
|
41
|
+
label: "STO",
|
|
42
|
+
origin: [0, 0],
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=StochasticTooltip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StochasticTooltip.js","sourceRoot":"","sources":["../src/StochasticTooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,iBAAiB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E,CAAC,CAAC,EAAE,CAAC,CAAC;CACjB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import * as React from "react";
|
|
13
|
+
export class ToolTipTSpanLabel extends React.PureComponent {
|
|
14
|
+
render() {
|
|
15
|
+
const _a = this.props, { children } = _a, rest = __rest(_a, ["children"]);
|
|
16
|
+
return React.createElement("tspan", Object.assign({}, rest), children);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
ToolTipTSpanLabel.defaultProps = {
|
|
20
|
+
className: "react-financial-charts-tooltip-label",
|
|
21
|
+
fill: "#4682B4",
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=ToolTipTSpanLabel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolTipTSpanLabel.js","sourceRoot":"","sources":["../src/ToolTipTSpanLabel.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,MAAM,OAAO,iBAAkB,SAAQ,KAAK,CAAC,aAA8C;IAMhF,MAAM;QACT,MAAM,KAAwB,IAAI,CAAC,KAAK,EAAlC,EAAE,QAAQ,OAAwB,EAAnB,IAAI,cAAnB,YAAqB,CAAa,CAAC;QAEzC,OAAO,+CAAW,IAAI,GAAG,QAAQ,CAAS,CAAC;IAC/C,CAAC;;AATa,8BAAY,GAAG;IACzB,SAAS,EAAE,sCAAsC;IACjD,IAAI,EAAE,SAAS;CAClB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import * as React from "react";
|
|
13
|
+
export class ToolTipText extends React.PureComponent {
|
|
14
|
+
render() {
|
|
15
|
+
const _a = this.props, { children } = _a, rest = __rest(_a, ["children"]);
|
|
16
|
+
return React.createElement("text", Object.assign({}, rest), children);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
ToolTipText.defaultProps = {
|
|
20
|
+
className: "react-financial-charts-tooltip",
|
|
21
|
+
fontFamily: "-apple-system, system-ui, 'Helvetica Neue', Ubuntu, sans-serif",
|
|
22
|
+
fontSize: 11,
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=ToolTipText.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolTipText.js","sourceRoot":"","sources":["../src/ToolTipText.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,MAAM,OAAO,WAAY,SAAQ,KAAK,CAAC,aAA6C;IAOzE,MAAM;QACT,MAAM,KAAwB,IAAI,CAAC,KAAK,EAAlC,EAAE,QAAQ,OAAwB,EAAnB,IAAI,cAAnB,YAAqB,CAAa,CAAC;QAEzC,OAAO,8CAAU,IAAI,GAAG,QAAQ,CAAQ,CAAC;IAC7C,CAAC;;AAVa,wBAAY,GAAG;IACzB,SAAS,EAAE,gCAAgC;IAC3C,UAAU,EAAE,gEAAgE;IAC5E,QAAQ,EAAE,EAAE;CACf,CAAC"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from "./BollingerBandTooltip";
|
|
2
|
+
export * from "./GroupTooltip";
|
|
3
|
+
export * from "./HoverTooltip";
|
|
4
|
+
export * from "./MACDTooltip";
|
|
5
|
+
export * from "./MovingAverageTooltip";
|
|
6
|
+
export * from "./OHLCTooltip";
|
|
7
|
+
export * from "./RSITooltip";
|
|
8
|
+
export * from "./SingleTooltip";
|
|
9
|
+
export * from "./SingleValueTooltip";
|
|
10
|
+
export * from "./StochasticTooltip";
|
|
11
|
+
export * from "./ToolTipText";
|
|
12
|
+
export * from "./ToolTipTSpanLabel";
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from "./BollingerBandTooltip";
|
|
2
|
+
export * from "./GroupTooltip";
|
|
3
|
+
export * from "./HoverTooltip";
|
|
4
|
+
export * from "./MACDTooltip";
|
|
5
|
+
export * from "./MovingAverageTooltip";
|
|
6
|
+
export * from "./OHLCTooltip";
|
|
7
|
+
export * from "./RSITooltip";
|
|
8
|
+
export * from "./SingleTooltip";
|
|
9
|
+
export * from "./SingleValueTooltip";
|
|
10
|
+
export * from "./StochasticTooltip";
|
|
11
|
+
export * from "./ToolTipText";
|
|
12
|
+
export * from "./ToolTipTSpanLabel";
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tradingaction/tooltip",
|
|
3
|
+
"version": "2.0.13",
|
|
4
|
+
"description": "Tooltips 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
|
+
"d3-array": "^2.9.1",
|
|
43
|
+
"d3-format": "^2.0.0",
|
|
44
|
+
"d3-time-format": "^3.0.0"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"react": "^16.0.0 || ^17.0.0 || ^18.0.0",
|
|
48
|
+
"react-dom": "^16.0.0 || ^17.0.0 || ^18.0.0"
|
|
49
|
+
},
|
|
50
|
+
"gitHead": "9c9bc635a2291c8da0e1dd5befa4000e96d83119"
|
|
51
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { functor, GenericChartComponent, last } from "@tradingaction/core";
|
|
2
|
+
import { format } from "d3-format";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { ToolTipText } from "./ToolTipText";
|
|
5
|
+
import { ToolTipTSpanLabel } from "./ToolTipTSpanLabel";
|
|
6
|
+
|
|
7
|
+
export interface BollingerBandTooltipProps {
|
|
8
|
+
readonly className?: string;
|
|
9
|
+
readonly displayFormat: (value: number) => string;
|
|
10
|
+
readonly displayInit?: string;
|
|
11
|
+
readonly displayValuesFor?: (props: BollingerBandTooltipProps, moreProps: any) => any;
|
|
12
|
+
readonly fontFamily?: string;
|
|
13
|
+
readonly fontSize?: number;
|
|
14
|
+
readonly fontWeight?: number;
|
|
15
|
+
readonly labelFill?: string;
|
|
16
|
+
readonly labelFontWeight?: number;
|
|
17
|
+
readonly onClick?: (event: React.MouseEvent) => void;
|
|
18
|
+
readonly options: {
|
|
19
|
+
movingAverageType: string;
|
|
20
|
+
multiplier: number;
|
|
21
|
+
sourcePath: string;
|
|
22
|
+
windowSize: number;
|
|
23
|
+
};
|
|
24
|
+
readonly origin?: [number, number] | ((width: number, height: number) => [number, number]);
|
|
25
|
+
readonly textFill?: string;
|
|
26
|
+
readonly yAccessor?: (data: any) => { bottom: number; middle: number; top: number };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export class BollingerBandTooltip extends React.Component<BollingerBandTooltipProps> {
|
|
30
|
+
public static defaultProps = {
|
|
31
|
+
className: "react-financial-charts-tooltip react-financial-charts-bollingerband-tooltip",
|
|
32
|
+
displayFormat: format(".2f"),
|
|
33
|
+
displayValuesFor: (_: any, props: any) => props.currentItem,
|
|
34
|
+
displayInit: "n/a",
|
|
35
|
+
origin: [8, 8],
|
|
36
|
+
yAccessor: (data: any) => data.bb,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
public render() {
|
|
40
|
+
return <GenericChartComponent clip={false} svgDraw={this.renderSVG} drawOn={["mousemove"]} />;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private readonly renderSVG = (moreProps: any) => {
|
|
44
|
+
const {
|
|
45
|
+
onClick,
|
|
46
|
+
displayFormat,
|
|
47
|
+
yAccessor = BollingerBandTooltip.defaultProps.yAccessor,
|
|
48
|
+
options,
|
|
49
|
+
origin: originProp,
|
|
50
|
+
textFill,
|
|
51
|
+
labelFill,
|
|
52
|
+
labelFontWeight,
|
|
53
|
+
className,
|
|
54
|
+
displayValuesFor = BollingerBandTooltip.defaultProps.displayValuesFor,
|
|
55
|
+
displayInit,
|
|
56
|
+
fontFamily,
|
|
57
|
+
fontSize,
|
|
58
|
+
fontWeight,
|
|
59
|
+
} = this.props;
|
|
60
|
+
|
|
61
|
+
const {
|
|
62
|
+
chartConfig: { width, height },
|
|
63
|
+
fullData,
|
|
64
|
+
} = moreProps;
|
|
65
|
+
|
|
66
|
+
const currentItem = displayValuesFor(this.props, moreProps) ?? last(fullData);
|
|
67
|
+
|
|
68
|
+
let top = displayInit;
|
|
69
|
+
let middle = displayInit;
|
|
70
|
+
let bottom = displayInit;
|
|
71
|
+
|
|
72
|
+
if (currentItem !== undefined) {
|
|
73
|
+
const item = yAccessor(currentItem);
|
|
74
|
+
if (item !== undefined) {
|
|
75
|
+
top = displayFormat(item.top);
|
|
76
|
+
middle = displayFormat(item.middle);
|
|
77
|
+
bottom = displayFormat(item.bottom);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const origin = functor(originProp);
|
|
82
|
+
const [x, y] = origin(width, height);
|
|
83
|
+
|
|
84
|
+
const { sourcePath, windowSize, multiplier, movingAverageType } = options;
|
|
85
|
+
const tooltipLabel = `BB(${sourcePath}, ${windowSize}, ${multiplier}, ${movingAverageType}): `;
|
|
86
|
+
const tooltipValue = `${top}, ${middle}, ${bottom}`;
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<g transform={`translate(${x}, ${y})`} className={className} onClick={onClick}>
|
|
90
|
+
<ToolTipText x={0} y={0} fontFamily={fontFamily} fontSize={fontSize} fontWeight={fontWeight}>
|
|
91
|
+
<ToolTipTSpanLabel fill={labelFill} fontWeight={labelFontWeight}>
|
|
92
|
+
{tooltipLabel}
|
|
93
|
+
</ToolTipTSpanLabel>
|
|
94
|
+
<tspan fill={textFill}>{tooltipValue}</tspan>
|
|
95
|
+
</ToolTipText>
|
|
96
|
+
</g>
|
|
97
|
+
);
|
|
98
|
+
};
|
|
99
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { GenericChartComponent, last } from "@tradingaction/core";
|
|
2
|
+
import { format } from "d3-format";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { layouts, SingleTooltip } from "./SingleTooltip";
|
|
5
|
+
import { ToolTipText } from "./ToolTipText";
|
|
6
|
+
|
|
7
|
+
export interface GroupTooltipProps {
|
|
8
|
+
readonly className?: string;
|
|
9
|
+
readonly fontFamily?: string;
|
|
10
|
+
readonly fontSize?: number;
|
|
11
|
+
readonly fontWeight?: number;
|
|
12
|
+
readonly displayFormat: (value: number) => string;
|
|
13
|
+
readonly displayInit?: string;
|
|
14
|
+
readonly displayValuesFor: (props: GroupTooltipProps, moreProps: any) => any;
|
|
15
|
+
readonly layout: layouts;
|
|
16
|
+
readonly onClick?: (event: React.MouseEvent, details: any) => void;
|
|
17
|
+
readonly options: {
|
|
18
|
+
labelFill?: string;
|
|
19
|
+
yLabel: string;
|
|
20
|
+
yAccessor: (data: any) => number;
|
|
21
|
+
valueFill?: string;
|
|
22
|
+
withShape?: boolean;
|
|
23
|
+
}[];
|
|
24
|
+
readonly origin: [number, number];
|
|
25
|
+
readonly position?: "topRight" | "bottomLeft" | "bottomRight";
|
|
26
|
+
readonly verticalSize?: number; // "verticalSize" only be used, if layout is "vertical", "verticalRows".
|
|
27
|
+
readonly width?: number; // "width" only be used, if layout is "horizontal" or "horizontalRows".
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class GroupTooltip extends React.Component<GroupTooltipProps> {
|
|
31
|
+
public static defaultProps = {
|
|
32
|
+
className: "react-financial-charts-tooltip react-financial-charts-group-tooltip",
|
|
33
|
+
layout: "horizontal",
|
|
34
|
+
displayFormat: format(".2f"),
|
|
35
|
+
displayInit: "",
|
|
36
|
+
displayValuesFor: (_: any, props: any) => props.currentItem,
|
|
37
|
+
origin: [0, 0],
|
|
38
|
+
width: 60,
|
|
39
|
+
verticalSize: 13,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
public render() {
|
|
43
|
+
return <GenericChartComponent clip={false} svgDraw={this.renderSVG} drawOn={["mousemove"]} />;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private readonly getPosition = (moreProps: any) => {
|
|
47
|
+
const { position } = this.props;
|
|
48
|
+
const { height, width } = moreProps.chartConfig;
|
|
49
|
+
|
|
50
|
+
const dx = 20;
|
|
51
|
+
const dy = 40;
|
|
52
|
+
let textAnchor: string | undefined;
|
|
53
|
+
let xyPos: (number | null)[] | null = null;
|
|
54
|
+
|
|
55
|
+
if (position !== undefined) {
|
|
56
|
+
switch (position) {
|
|
57
|
+
case "topRight":
|
|
58
|
+
xyPos = [width - dx, null];
|
|
59
|
+
textAnchor = "end";
|
|
60
|
+
break;
|
|
61
|
+
case "bottomLeft":
|
|
62
|
+
xyPos = [null, height - dy];
|
|
63
|
+
break;
|
|
64
|
+
case "bottomRight":
|
|
65
|
+
xyPos = [width - dx, height - dy];
|
|
66
|
+
textAnchor = "end";
|
|
67
|
+
break;
|
|
68
|
+
default:
|
|
69
|
+
xyPos = [null, null];
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
xyPos = [null, null];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return { xyPos, textAnchor };
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
private readonly renderSVG = (moreProps: any) => {
|
|
79
|
+
const { chartId, fullData } = moreProps;
|
|
80
|
+
|
|
81
|
+
const {
|
|
82
|
+
className,
|
|
83
|
+
displayInit = GroupTooltip.defaultProps.displayInit,
|
|
84
|
+
displayValuesFor,
|
|
85
|
+
onClick,
|
|
86
|
+
width = 60,
|
|
87
|
+
verticalSize = 13,
|
|
88
|
+
fontFamily,
|
|
89
|
+
fontSize,
|
|
90
|
+
fontWeight,
|
|
91
|
+
layout,
|
|
92
|
+
origin,
|
|
93
|
+
displayFormat,
|
|
94
|
+
options,
|
|
95
|
+
} = this.props;
|
|
96
|
+
|
|
97
|
+
const currentItem = displayValuesFor(this.props, moreProps) ?? last(fullData);
|
|
98
|
+
|
|
99
|
+
const { xyPos, textAnchor } = this.getPosition(moreProps);
|
|
100
|
+
|
|
101
|
+
const xPos = xyPos != null && xyPos[0] != null ? xyPos[0] : origin[0];
|
|
102
|
+
const yPos = xyPos != null && xyPos[1] != null ? xyPos[1] : origin[1];
|
|
103
|
+
|
|
104
|
+
const singleTooltip = options.map((each, idx) => {
|
|
105
|
+
const yValue = currentItem && each.yAccessor(currentItem);
|
|
106
|
+
const yDisplayValue = yValue ? displayFormat(yValue) : displayInit;
|
|
107
|
+
|
|
108
|
+
const orig: () => [number, number] = () => {
|
|
109
|
+
if (layout === "horizontal" || layout === "horizontalRows") {
|
|
110
|
+
return [width * idx, 0];
|
|
111
|
+
}
|
|
112
|
+
if (layout === "vertical") {
|
|
113
|
+
return [0, verticalSize * idx];
|
|
114
|
+
}
|
|
115
|
+
if (layout === "verticalRows") {
|
|
116
|
+
return [0, verticalSize * 2.3 * idx];
|
|
117
|
+
}
|
|
118
|
+
return [0, 0];
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
return (
|
|
122
|
+
<SingleTooltip
|
|
123
|
+
key={idx}
|
|
124
|
+
layout={layout}
|
|
125
|
+
origin={orig()}
|
|
126
|
+
yLabel={each.yLabel}
|
|
127
|
+
yValue={yDisplayValue}
|
|
128
|
+
options={each}
|
|
129
|
+
forChart={chartId}
|
|
130
|
+
onClick={onClick}
|
|
131
|
+
fontFamily={fontFamily}
|
|
132
|
+
fontSize={fontSize}
|
|
133
|
+
labelFill={each.labelFill}
|
|
134
|
+
valueFill={each.valueFill}
|
|
135
|
+
withShape={each.withShape}
|
|
136
|
+
/>
|
|
137
|
+
);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<g transform={`translate(${xPos}, ${yPos})`} className={className} textAnchor={textAnchor}>
|
|
142
|
+
{layout === "horizontalInline" ? (
|
|
143
|
+
<ToolTipText x={0} y={0} fontFamily={fontFamily} fontSize={fontSize} fontWeight={fontWeight}>
|
|
144
|
+
{singleTooltip}
|
|
145
|
+
</ToolTipText>
|
|
146
|
+
) : (
|
|
147
|
+
singleTooltip
|
|
148
|
+
)}
|
|
149
|
+
</g>
|
|
150
|
+
);
|
|
151
|
+
};
|
|
152
|
+
}
|