@tradingaction/tooltip 2.1.1 → 2.1.3
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/lib/IndicatorDisplayTooltip.js +9 -2
- package/lib/IndicatorDisplayTooltip.js.map +1 -1
- package/package.json +4 -5
- package/src/BollingerBandTooltip.tsx +0 -99
- package/src/GroupTooltip.tsx +0 -152
- package/src/HoverTooltip.tsx +0 -270
- package/src/IndicatorDisplayTooltip.tsx +0 -460
- package/src/MACDTooltip.tsx +0 -116
- package/src/MovingAverageTooltip.tsx +0 -167
- package/src/OHLCTooltip.tsx +0 -150
- package/src/RSITooltip.tsx +0 -80
- package/src/SingleTooltip.tsx +0 -122
- package/src/SingleValueTooltip.tsx +0 -131
- package/src/StochasticTooltip.tsx +0 -97
- package/src/ToolTipTSpanLabel.tsx +0 -14
- package/src/ToolTipText.tsx +0 -15
- package/src/index.ts +0 -13
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import { functor, GenericChartComponent, last, MoreProps } 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 SingleMAToolTipProps {
|
|
8
|
-
readonly color: string;
|
|
9
|
-
readonly displayName: string;
|
|
10
|
-
readonly fontFamily?: string;
|
|
11
|
-
readonly fontSize?: number;
|
|
12
|
-
readonly fontWeight?: number;
|
|
13
|
-
readonly forChart: number | string;
|
|
14
|
-
readonly labelFill?: string;
|
|
15
|
-
readonly labelFontWeight?: number;
|
|
16
|
-
readonly onClick?: (event: React.MouseEvent<SVGRectElement, MouseEvent>, details: any) => void;
|
|
17
|
-
readonly options: IMovingAverageTooltip;
|
|
18
|
-
readonly origin: [number, number];
|
|
19
|
-
readonly textFill?: string;
|
|
20
|
-
readonly value: string;
|
|
21
|
-
readonly icons?: SingleMATooltipIcon[];
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
interface SingleMATooltipIcon {
|
|
25
|
-
unicode: string;
|
|
26
|
-
onClick: (option: any) => void;
|
|
27
|
-
size?: any;
|
|
28
|
-
fillColor?: string;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export class SingleMAToolTip extends React.Component<SingleMAToolTipProps> {
|
|
32
|
-
public render() {
|
|
33
|
-
const { color, displayName, fontSize, fontFamily, fontWeight, textFill, labelFill, labelFontWeight, value } =
|
|
34
|
-
this.props;
|
|
35
|
-
|
|
36
|
-
const translate = "translate(" + this.props.origin[0] + ", " + this.props.origin[1] + ")";
|
|
37
|
-
|
|
38
|
-
const handleIconClick = (e: React.MouseEvent<SVGTSpanElement, MouseEvent>, icon: SingleMATooltipIcon) => {
|
|
39
|
-
if (typeof icon.onClick == "function") {
|
|
40
|
-
e.stopPropagation();
|
|
41
|
-
icon.onClick(this.props.options);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
return (
|
|
46
|
-
<g transform={translate} onClick={this.onClick}>
|
|
47
|
-
<line x1={0} y1={2} x2={0} y2={28} stroke={color} strokeWidth={4} />
|
|
48
|
-
<ToolTipText x={5} y={11} fontFamily={fontFamily} fontSize={fontSize} fontWeight={fontWeight}>
|
|
49
|
-
<ToolTipTSpanLabel fill={labelFill} fontWeight={labelFontWeight}>
|
|
50
|
-
{displayName}
|
|
51
|
-
</ToolTipTSpanLabel>
|
|
52
|
-
<tspan x={5} dy={15} fill={textFill}>
|
|
53
|
-
{value}
|
|
54
|
-
</tspan>
|
|
55
|
-
{this.props.icons?.map((i) => {
|
|
56
|
-
return <tspan fontSize={i.size} fill={i.fillColor || '#000'} onClick={(e) => handleIconClick(e, i)}> {i.unicode}</tspan>;
|
|
57
|
-
})}
|
|
58
|
-
</ToolTipText>
|
|
59
|
-
</g>
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
private readonly onClick = (event: React.MouseEvent<SVGRectElement, MouseEvent>) => {
|
|
64
|
-
const { onClick, forChart, options } = this.props;
|
|
65
|
-
if (onClick !== undefined) {
|
|
66
|
-
onClick(event, { chartId: forChart, ...options });
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
interface IMovingAverageTooltip {
|
|
72
|
-
data?: any;//from input data-structure
|
|
73
|
-
yAccessor: (data: any) => number;
|
|
74
|
-
type: string;
|
|
75
|
-
stroke: string;
|
|
76
|
-
windowSize: number;
|
|
77
|
-
icons?: SingleMATooltipIcon[];
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
interface MovingAverageTooltipProps {
|
|
81
|
-
readonly className?: string;
|
|
82
|
-
readonly displayFormat: (value: number) => string;
|
|
83
|
-
readonly origin: number[];
|
|
84
|
-
readonly displayInit?: string;
|
|
85
|
-
readonly displayValuesFor?: (props: MovingAverageTooltipProps, moreProps: any) => any;
|
|
86
|
-
readonly onClick?: (event: React.MouseEvent<SVGRectElement, MouseEvent>) => void;
|
|
87
|
-
readonly textFill?: string;
|
|
88
|
-
readonly labelFill?: string;
|
|
89
|
-
readonly fontFamily?: string;
|
|
90
|
-
readonly fontSize?: number;
|
|
91
|
-
readonly fontWeight?: number;
|
|
92
|
-
readonly width?: number;
|
|
93
|
-
readonly options: IMovingAverageTooltip[];
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// tslint:disable-next-line: max-classes-per-file
|
|
97
|
-
export class MovingAverageTooltip extends React.Component<MovingAverageTooltipProps> {
|
|
98
|
-
public static defaultProps = {
|
|
99
|
-
className: "react-financial-charts-tooltip react-financial-charts-moving-average-tooltip",
|
|
100
|
-
displayFormat: format(".2f"),
|
|
101
|
-
displayInit: "n/a",
|
|
102
|
-
displayValuesFor: (_: any, props: any) => props.currentItem,
|
|
103
|
-
origin: [0, 10],
|
|
104
|
-
width: 65,
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
public render() {
|
|
108
|
-
return <GenericChartComponent clip={false} svgDraw={this.renderSVG} drawOn={["mousemove"]} />;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
private readonly renderSVG = (moreProps: MoreProps) => {
|
|
112
|
-
const { chartId, chartConfig, chartConfig: { height = 0 } = {}, fullData } = moreProps;
|
|
113
|
-
|
|
114
|
-
const {
|
|
115
|
-
className,
|
|
116
|
-
displayInit = MovingAverageTooltip.defaultProps.displayInit,
|
|
117
|
-
onClick,
|
|
118
|
-
width = 65,
|
|
119
|
-
fontFamily,
|
|
120
|
-
fontSize,
|
|
121
|
-
fontWeight,
|
|
122
|
-
textFill,
|
|
123
|
-
labelFill,
|
|
124
|
-
origin: originProp,
|
|
125
|
-
displayFormat,
|
|
126
|
-
displayValuesFor = MovingAverageTooltip.defaultProps.displayValuesFor,
|
|
127
|
-
options,
|
|
128
|
-
} = this.props;
|
|
129
|
-
|
|
130
|
-
const currentItem = displayValuesFor(this.props, moreProps) ?? last(fullData);
|
|
131
|
-
|
|
132
|
-
const config = chartConfig!;
|
|
133
|
-
|
|
134
|
-
const origin = functor(originProp);
|
|
135
|
-
const [x, y] = origin(width, height);
|
|
136
|
-
const [ox, oy] = config.origin;
|
|
137
|
-
|
|
138
|
-
return (
|
|
139
|
-
<g transform={`translate(${ox + x}, ${oy + y})`} className={className}>
|
|
140
|
-
{options.map((each, idx) => {
|
|
141
|
-
const yValue = currentItem && each.yAccessor(currentItem);
|
|
142
|
-
|
|
143
|
-
const tooltipLabel = `${each.type} (${each.windowSize})`;
|
|
144
|
-
const yDisplayValue = yValue ? displayFormat(yValue) : displayInit;
|
|
145
|
-
return (
|
|
146
|
-
<SingleMAToolTip
|
|
147
|
-
key={idx}
|
|
148
|
-
origin={[width * idx, 0]}
|
|
149
|
-
color={each.stroke}
|
|
150
|
-
displayName={tooltipLabel}
|
|
151
|
-
value={yDisplayValue}
|
|
152
|
-
options={each}
|
|
153
|
-
forChart={chartId}
|
|
154
|
-
onClick={onClick}
|
|
155
|
-
fontFamily={fontFamily}
|
|
156
|
-
fontSize={fontSize}
|
|
157
|
-
fontWeight={fontWeight}
|
|
158
|
-
textFill={textFill}
|
|
159
|
-
labelFill={labelFill}
|
|
160
|
-
icons={each.icons}
|
|
161
|
-
/>
|
|
162
|
-
);
|
|
163
|
-
})}
|
|
164
|
-
</g>
|
|
165
|
-
);
|
|
166
|
-
};
|
|
167
|
-
}
|
package/src/OHLCTooltip.tsx
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
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
|
-
const displayTextsDefault = {
|
|
8
|
-
o: "O: ",
|
|
9
|
-
h: " H: ",
|
|
10
|
-
l: " L: ",
|
|
11
|
-
c: " C: ",
|
|
12
|
-
v: " Vol: ",
|
|
13
|
-
na: "n/a",
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export interface OHLCTooltipProps {
|
|
17
|
-
readonly accessor?: (data: any) => any;
|
|
18
|
-
readonly className?: string;
|
|
19
|
-
readonly changeFormat?: (n: number | { valueOf(): number }) => string;
|
|
20
|
-
readonly displayTexts?: {
|
|
21
|
-
o: string;
|
|
22
|
-
h: string;
|
|
23
|
-
l: string;
|
|
24
|
-
c: string;
|
|
25
|
-
v: string;
|
|
26
|
-
na: string;
|
|
27
|
-
};
|
|
28
|
-
readonly displayValuesFor?: (props: OHLCTooltipProps, moreProps: any) => any;
|
|
29
|
-
readonly fontFamily?: string;
|
|
30
|
-
readonly fontSize?: number;
|
|
31
|
-
readonly fontWeight?: number;
|
|
32
|
-
readonly labelFill?: string;
|
|
33
|
-
readonly labelFontWeight?: number;
|
|
34
|
-
readonly ohlcFormat?: (n: number | { valueOf(): number }) => string;
|
|
35
|
-
readonly onClick?: (event: React.MouseEvent<SVGGElement, MouseEvent>) => void;
|
|
36
|
-
readonly origin?: [number, number] | ((width: number, height: number) => [number, number]);
|
|
37
|
-
readonly percentFormat?: (n: number | { valueOf(): number }) => string;
|
|
38
|
-
readonly volumeFormat?: (n: number | { valueOf(): number }) => string;
|
|
39
|
-
readonly textFill?: string | ((item: any) => string);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export class OHLCTooltip extends React.Component<OHLCTooltipProps> {
|
|
43
|
-
public static defaultProps = {
|
|
44
|
-
accessor: (d: unknown) => d,
|
|
45
|
-
changeFormat: format("+.2f"),
|
|
46
|
-
className: "react-financial-charts-tooltip-hover",
|
|
47
|
-
displayTexts: displayTextsDefault,
|
|
48
|
-
displayValuesFor: (_: any, props: any) => props.currentItem,
|
|
49
|
-
fontFamily: "-apple-system, system-ui, 'Helvetica Neue', Ubuntu, sans-serif",
|
|
50
|
-
ohlcFormat: format(".2f"),
|
|
51
|
-
origin: [0, 0],
|
|
52
|
-
percentFormat: format("+.2%"),
|
|
53
|
-
volumeFormat: format("0.2s"),
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
public render() {
|
|
57
|
-
return <GenericChartComponent clip={false} svgDraw={this.renderSVG} drawOn={["mousemove"]} />;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
private readonly renderSVG = (moreProps: any) => {
|
|
61
|
-
const {
|
|
62
|
-
accessor,
|
|
63
|
-
changeFormat = OHLCTooltip.defaultProps.changeFormat,
|
|
64
|
-
className,
|
|
65
|
-
displayTexts = OHLCTooltip.defaultProps.displayTexts,
|
|
66
|
-
displayValuesFor = OHLCTooltip.defaultProps.displayValuesFor,
|
|
67
|
-
fontFamily,
|
|
68
|
-
fontSize,
|
|
69
|
-
fontWeight,
|
|
70
|
-
labelFill,
|
|
71
|
-
labelFontWeight,
|
|
72
|
-
ohlcFormat = OHLCTooltip.defaultProps.ohlcFormat,
|
|
73
|
-
onClick,
|
|
74
|
-
percentFormat = OHLCTooltip.defaultProps.percentFormat,
|
|
75
|
-
volumeFormat = OHLCTooltip.defaultProps.volumeFormat,
|
|
76
|
-
textFill,
|
|
77
|
-
} = this.props;
|
|
78
|
-
|
|
79
|
-
const {
|
|
80
|
-
chartConfig: { width, height },
|
|
81
|
-
fullData,
|
|
82
|
-
} = moreProps;
|
|
83
|
-
|
|
84
|
-
const currentItem = displayValuesFor(this.props, moreProps) ?? last(fullData);
|
|
85
|
-
|
|
86
|
-
let open: string = displayTexts.na;
|
|
87
|
-
let high: string = displayTexts.na;
|
|
88
|
-
let low: string = displayTexts.na;
|
|
89
|
-
let close: string = displayTexts.na;
|
|
90
|
-
let change: string = displayTexts.na;
|
|
91
|
-
|
|
92
|
-
if (currentItem !== undefined && accessor !== undefined) {
|
|
93
|
-
const item = accessor(currentItem);
|
|
94
|
-
let formatForChange = `${changeFormat(item.close - item.open)}`;
|
|
95
|
-
const percent = percentFormat((item.close - item.open) / item.open);
|
|
96
|
-
if (percent) {
|
|
97
|
-
formatForChange += ` (${percent})`;
|
|
98
|
-
}
|
|
99
|
-
const volumeValue = volumeFormat(item.volume || 0).replace(/G/, "B");
|
|
100
|
-
if (volumeValue) {
|
|
101
|
-
formatForChange += ` ${displayTexts.v}${volumeValue}`;
|
|
102
|
-
}
|
|
103
|
-
if (item !== undefined) {
|
|
104
|
-
open = ohlcFormat(item.open);
|
|
105
|
-
high = ohlcFormat(item.high);
|
|
106
|
-
low = ohlcFormat(item.low);
|
|
107
|
-
close = ohlcFormat(item.close);
|
|
108
|
-
change = formatForChange;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const { origin: originProp } = this.props;
|
|
113
|
-
const [x, y] = functor(originProp)(width, height);
|
|
114
|
-
const valueFill = functor(textFill)(currentItem);
|
|
115
|
-
|
|
116
|
-
return (
|
|
117
|
-
<g className={className} transform={`translate(${x}, ${y})`} onClick={onClick}>
|
|
118
|
-
<ToolTipText x={0} y={0} fontFamily={fontFamily} fontSize={fontSize} fontWeight={fontWeight}>
|
|
119
|
-
<ToolTipTSpanLabel fill={labelFill} fontWeight={labelFontWeight} key="label_O">
|
|
120
|
-
{displayTexts.o}
|
|
121
|
-
</ToolTipTSpanLabel>
|
|
122
|
-
<tspan key="value_O" fill={valueFill}>
|
|
123
|
-
{open}
|
|
124
|
-
</tspan>
|
|
125
|
-
<ToolTipTSpanLabel fill={labelFill} fontWeight={labelFontWeight} key="label_H">
|
|
126
|
-
{displayTexts.h}
|
|
127
|
-
</ToolTipTSpanLabel>
|
|
128
|
-
<tspan key="value_H" fill={valueFill}>
|
|
129
|
-
{high}
|
|
130
|
-
</tspan>
|
|
131
|
-
<ToolTipTSpanLabel fill={labelFill} fontWeight={labelFontWeight} key="label_L">
|
|
132
|
-
{displayTexts.l}
|
|
133
|
-
</ToolTipTSpanLabel>
|
|
134
|
-
<tspan key="value_L" fill={valueFill}>
|
|
135
|
-
{low}
|
|
136
|
-
</tspan>
|
|
137
|
-
<ToolTipTSpanLabel fill={labelFill} fontWeight={labelFontWeight} key="label_C">
|
|
138
|
-
{displayTexts.c}
|
|
139
|
-
</ToolTipTSpanLabel>
|
|
140
|
-
<tspan key="value_C" fill={valueFill}>
|
|
141
|
-
{close}
|
|
142
|
-
</tspan>
|
|
143
|
-
<tspan key="value_Change" fill={valueFill}>
|
|
144
|
-
{` ${change}`}
|
|
145
|
-
</tspan>
|
|
146
|
-
</ToolTipText>
|
|
147
|
-
</g>
|
|
148
|
-
);
|
|
149
|
-
};
|
|
150
|
-
}
|
package/src/RSITooltip.tsx
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { functor, isDefined, 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
|
-
|
|
7
|
-
export interface RSITooltipProps {
|
|
8
|
-
readonly className?: string;
|
|
9
|
-
readonly displayFormat: (value: number) => string;
|
|
10
|
-
readonly displayInit?: string;
|
|
11
|
-
readonly displayValuesFor: (props: RSITooltipProps, 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<SVGGElement, MouseEvent>) => void;
|
|
18
|
-
readonly origin: number[] | ((width: number, height: number) => number[]);
|
|
19
|
-
readonly options: {
|
|
20
|
-
windowSize: number;
|
|
21
|
-
};
|
|
22
|
-
readonly textFill?: string;
|
|
23
|
-
readonly yAccessor: (data: any) => number | undefined;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export class RSITooltip extends React.Component<RSITooltipProps> {
|
|
27
|
-
public static defaultProps = {
|
|
28
|
-
displayFormat: format(".2f"),
|
|
29
|
-
displayInit: "n/a",
|
|
30
|
-
displayValuesFor: (_: RSITooltipProps, props: any) => props.currentItem,
|
|
31
|
-
origin: [0, 0],
|
|
32
|
-
className: "react-financial-charts-tooltip",
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
public render() {
|
|
36
|
-
return <GenericChartComponent clip={false} svgDraw={this.renderSVG} drawOn={["mousemove"]} />;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
private readonly renderSVG = (moreProps: any) => {
|
|
40
|
-
const {
|
|
41
|
-
onClick,
|
|
42
|
-
displayInit,
|
|
43
|
-
fontFamily,
|
|
44
|
-
fontSize,
|
|
45
|
-
fontWeight,
|
|
46
|
-
yAccessor,
|
|
47
|
-
displayFormat,
|
|
48
|
-
className,
|
|
49
|
-
options,
|
|
50
|
-
labelFill,
|
|
51
|
-
labelFontWeight,
|
|
52
|
-
textFill,
|
|
53
|
-
displayValuesFor,
|
|
54
|
-
} = this.props;
|
|
55
|
-
|
|
56
|
-
const {
|
|
57
|
-
chartConfig: { width, height },
|
|
58
|
-
} = moreProps;
|
|
59
|
-
|
|
60
|
-
const currentItem = displayValuesFor(this.props, moreProps);
|
|
61
|
-
const rsi = isDefined(currentItem) && yAccessor(currentItem);
|
|
62
|
-
const value = (rsi && displayFormat(rsi)) || displayInit;
|
|
63
|
-
|
|
64
|
-
const { origin: originProp } = this.props;
|
|
65
|
-
const origin = functor(originProp);
|
|
66
|
-
const [x, y] = origin(width, height);
|
|
67
|
-
|
|
68
|
-
const tooltipLabel = `RSI (${options.windowSize}): `;
|
|
69
|
-
return (
|
|
70
|
-
<g className={className} transform={`translate(${x}, ${y})`} onClick={onClick}>
|
|
71
|
-
<ToolTipText x={0} y={0} fontFamily={fontFamily} fontSize={fontSize} fontWeight={fontWeight}>
|
|
72
|
-
<ToolTipTSpanLabel fill={labelFill} fontWeight={labelFontWeight}>
|
|
73
|
-
{tooltipLabel}
|
|
74
|
-
</ToolTipTSpanLabel>
|
|
75
|
-
<tspan fill={textFill}>{value}</tspan>
|
|
76
|
-
</ToolTipText>
|
|
77
|
-
</g>
|
|
78
|
-
);
|
|
79
|
-
};
|
|
80
|
-
}
|
package/src/SingleTooltip.tsx
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { ToolTipText } from "./ToolTipText";
|
|
3
|
-
import { ToolTipTSpanLabel } from "./ToolTipTSpanLabel";
|
|
4
|
-
|
|
5
|
-
export type layouts = "horizontal" | "horizontalRows" | "horizontalInline" | "vertical" | "verticalRows";
|
|
6
|
-
|
|
7
|
-
export interface SingleTooltipProps {
|
|
8
|
-
readonly origin: [number, number];
|
|
9
|
-
readonly yLabel: string;
|
|
10
|
-
readonly yValue: string;
|
|
11
|
-
readonly onClick?: (event: React.MouseEvent, details: any) => void;
|
|
12
|
-
readonly fontFamily?: string;
|
|
13
|
-
readonly fontSize?: number;
|
|
14
|
-
readonly fontWeight?: number;
|
|
15
|
-
readonly labelFill: string;
|
|
16
|
-
readonly valueFill: string;
|
|
17
|
-
readonly forChart: number | string;
|
|
18
|
-
readonly options: any;
|
|
19
|
-
readonly layout: layouts;
|
|
20
|
-
readonly withShape: boolean;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export class SingleTooltip extends React.Component<SingleTooltipProps> {
|
|
24
|
-
public static defaultProps = {
|
|
25
|
-
labelFill: "#4682B4",
|
|
26
|
-
valueFill: "#000000",
|
|
27
|
-
withShape: false,
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/*
|
|
31
|
-
* Renders the value next to the label.
|
|
32
|
-
*/
|
|
33
|
-
public renderValueNextToLabel() {
|
|
34
|
-
const { origin, yLabel, yValue, labelFill, valueFill, withShape, fontSize, fontFamily, fontWeight } =
|
|
35
|
-
this.props;
|
|
36
|
-
|
|
37
|
-
return (
|
|
38
|
-
<g transform={`translate(${origin[0]}, ${origin[1]})`} onClick={this.handleClick}>
|
|
39
|
-
{withShape ? <rect x="0" y="-6" width="6" height="6" fill={valueFill} /> : null}
|
|
40
|
-
<ToolTipText
|
|
41
|
-
x={withShape ? 8 : 0}
|
|
42
|
-
y={0}
|
|
43
|
-
fontFamily={fontFamily}
|
|
44
|
-
fontSize={fontSize}
|
|
45
|
-
fontWeight={fontWeight}
|
|
46
|
-
>
|
|
47
|
-
<ToolTipTSpanLabel fill={labelFill}>{yLabel}: </ToolTipTSpanLabel>
|
|
48
|
-
<tspan fill={valueFill}>{yValue}</tspan>
|
|
49
|
-
</ToolTipText>
|
|
50
|
-
</g>
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/*
|
|
55
|
-
* Renders the value beneath the label.
|
|
56
|
-
*/
|
|
57
|
-
public renderValueBeneathLabel() {
|
|
58
|
-
const { origin, yLabel, yValue, labelFill, valueFill, withShape, fontSize, fontFamily, fontWeight } =
|
|
59
|
-
this.props;
|
|
60
|
-
|
|
61
|
-
return (
|
|
62
|
-
<g transform={`translate(${origin[0]}, ${origin[1]})`} onClick={this.handleClick}>
|
|
63
|
-
{withShape ? <line x1={0} y1={2} x2={0} y2={28} stroke={valueFill} strokeWidth="4px" /> : null}
|
|
64
|
-
<ToolTipText x={5} y={11} fontFamily={fontFamily} fontSize={fontSize} fontWeight={fontWeight}>
|
|
65
|
-
<ToolTipTSpanLabel fill={labelFill}>{yLabel}</ToolTipTSpanLabel>
|
|
66
|
-
<tspan x="5" dy="15" fill={valueFill}>
|
|
67
|
-
{yValue}
|
|
68
|
-
</tspan>
|
|
69
|
-
</ToolTipText>
|
|
70
|
-
</g>
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/*
|
|
75
|
-
* Renders the value next to the label.
|
|
76
|
-
* The parent component must have a "text"-element.
|
|
77
|
-
*/
|
|
78
|
-
public renderInline() {
|
|
79
|
-
const { yLabel, yValue, labelFill, valueFill, fontSize, fontFamily, fontWeight } = this.props;
|
|
80
|
-
|
|
81
|
-
return (
|
|
82
|
-
<tspan onClick={this.handleClick} fontFamily={fontFamily} fontSize={fontSize} fontWeight={fontWeight}>
|
|
83
|
-
<ToolTipTSpanLabel fill={labelFill}>{yLabel}: </ToolTipTSpanLabel>
|
|
84
|
-
<tspan fill={valueFill}>{yValue} </tspan>
|
|
85
|
-
</tspan>
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
public render() {
|
|
90
|
-
const { layout } = this.props;
|
|
91
|
-
let comp: JSX.Element | null = null;
|
|
92
|
-
|
|
93
|
-
switch (layout) {
|
|
94
|
-
case "horizontal":
|
|
95
|
-
comp = this.renderValueNextToLabel();
|
|
96
|
-
break;
|
|
97
|
-
case "horizontalRows":
|
|
98
|
-
comp = this.renderValueBeneathLabel();
|
|
99
|
-
break;
|
|
100
|
-
case "horizontalInline":
|
|
101
|
-
comp = this.renderInline();
|
|
102
|
-
break;
|
|
103
|
-
case "vertical":
|
|
104
|
-
comp = this.renderValueNextToLabel();
|
|
105
|
-
break;
|
|
106
|
-
case "verticalRows":
|
|
107
|
-
comp = this.renderValueBeneathLabel();
|
|
108
|
-
break;
|
|
109
|
-
default:
|
|
110
|
-
comp = this.renderValueNextToLabel();
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return comp;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
private readonly handleClick = (event: React.MouseEvent) => {
|
|
117
|
-
const { onClick, forChart, options } = this.props;
|
|
118
|
-
if (onClick !== undefined) {
|
|
119
|
-
onClick(event, { chartId: forChart, ...options });
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { functor, identity, GenericChartComponent, noop, 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
|
-
interface SingleValueTooltipIcon {
|
|
8
|
-
unicode: string;
|
|
9
|
-
onClick: () => void;
|
|
10
|
-
size?: any;
|
|
11
|
-
fillColor?: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface SingleValueTooltipProps {
|
|
15
|
-
readonly xDisplayFormat?: (value: number) => string;
|
|
16
|
-
readonly yDisplayFormat?: (value: number) => string;
|
|
17
|
-
readonly xInitDisplay?: string;
|
|
18
|
-
readonly yInitDisplay?: string;
|
|
19
|
-
readonly xLabel?: string;
|
|
20
|
-
readonly yLabel: string;
|
|
21
|
-
readonly labelFill?: string;
|
|
22
|
-
readonly labelFontWeight?: number;
|
|
23
|
-
readonly valueFill?: string;
|
|
24
|
-
readonly origin?: [number, number] | ((width: number, height: number) => [number, number]);
|
|
25
|
-
readonly className?: string;
|
|
26
|
-
readonly fontFamily?: string;
|
|
27
|
-
readonly fontSize?: number;
|
|
28
|
-
readonly fontWeight?: number;
|
|
29
|
-
readonly onClick?: (event: React.MouseEvent<SVGGElement, MouseEvent>) => void;
|
|
30
|
-
readonly displayValuesFor?: (props: SingleValueTooltipProps, moreProps: any) => any;
|
|
31
|
-
readonly xAccessor?: (d: any) => number;
|
|
32
|
-
readonly yAccessor?: (d: any) => number;
|
|
33
|
-
readonly icons?: SingleValueTooltipIcon[];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export class SingleValueTooltip extends React.Component<SingleValueTooltipProps> {
|
|
37
|
-
public static defaultProps = {
|
|
38
|
-
className: "react-financial-charts-tooltip",
|
|
39
|
-
displayValuesFor: (_: any, props: any) => props.currentItem,
|
|
40
|
-
labelFill: "#4682B4",
|
|
41
|
-
origin: [0, 0],
|
|
42
|
-
valueFill: "#000000",
|
|
43
|
-
xAccessor: noop,
|
|
44
|
-
xDisplayFormat: identity as (value: number) => string,
|
|
45
|
-
xInitDisplay: "n/a",
|
|
46
|
-
yAccessor: identity as (d: any) => number,
|
|
47
|
-
yDisplayFormat: format(".2f") as (value: number) => string,
|
|
48
|
-
yInitDisplay: "n/a",
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
public render() {
|
|
52
|
-
return <GenericChartComponent clip={false} svgDraw={this.renderSVG} drawOn={["mousemove"]} />;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
private readonly renderSVG = (moreProps: any) => {
|
|
56
|
-
const {
|
|
57
|
-
onClick,
|
|
58
|
-
fontFamily,
|
|
59
|
-
fontSize,
|
|
60
|
-
fontWeight,
|
|
61
|
-
labelFill,
|
|
62
|
-
labelFontWeight,
|
|
63
|
-
valueFill,
|
|
64
|
-
className,
|
|
65
|
-
displayValuesFor = SingleValueTooltip.defaultProps.displayValuesFor,
|
|
66
|
-
origin: originProp,
|
|
67
|
-
xDisplayFormat = SingleValueTooltip.defaultProps.xDisplayFormat,
|
|
68
|
-
yDisplayFormat = SingleValueTooltip.defaultProps.yDisplayFormat,
|
|
69
|
-
xLabel,
|
|
70
|
-
yLabel,
|
|
71
|
-
xAccessor = SingleValueTooltip.defaultProps.xAccessor,
|
|
72
|
-
yAccessor = SingleValueTooltip.defaultProps.yAccessor,
|
|
73
|
-
xInitDisplay,
|
|
74
|
-
yInitDisplay,
|
|
75
|
-
} = this.props;
|
|
76
|
-
|
|
77
|
-
const {
|
|
78
|
-
chartConfig: { width, height },
|
|
79
|
-
fullData,
|
|
80
|
-
} = moreProps;
|
|
81
|
-
|
|
82
|
-
const currentItem = displayValuesFor(this.props, moreProps) ?? last(fullData);
|
|
83
|
-
|
|
84
|
-
let xDisplayValue = xInitDisplay;
|
|
85
|
-
let yDisplayValue = yInitDisplay;
|
|
86
|
-
if (currentItem !== undefined) {
|
|
87
|
-
const xItem = xAccessor(currentItem);
|
|
88
|
-
if (xItem !== undefined) {
|
|
89
|
-
xDisplayValue = xDisplayFormat(xItem);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const yItem = yAccessor(currentItem);
|
|
93
|
-
if (yItem !== undefined) {
|
|
94
|
-
yDisplayValue = yDisplayFormat(yItem);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const origin = functor(originProp);
|
|
99
|
-
|
|
100
|
-
const [x, y] = origin(width, height);
|
|
101
|
-
|
|
102
|
-
const handleIconClick = (e: React.MouseEvent<SVGTSpanElement, MouseEvent>, icon: SingleValueTooltipIcon) => {
|
|
103
|
-
if (typeof icon.onClick == "function") {
|
|
104
|
-
e.stopPropagation();
|
|
105
|
-
icon.onClick();
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
return (
|
|
110
|
-
<>
|
|
111
|
-
<g className={className} transform={`translate(${x}, ${y})`} onClick={onClick}>
|
|
112
|
-
<ToolTipText x={0} y={0} fontFamily={fontFamily} fontSize={fontSize} fontWeight={fontWeight}>
|
|
113
|
-
{xLabel ? (
|
|
114
|
-
<ToolTipTSpanLabel x={0} dy="5" fill={labelFill}>{`${xLabel}: `}</ToolTipTSpanLabel>
|
|
115
|
-
) : null}
|
|
116
|
-
{xLabel ? <tspan fill={valueFill}>{`${xDisplayValue} `}</tspan> : null}
|
|
117
|
-
<ToolTipTSpanLabel
|
|
118
|
-
fill={labelFill}
|
|
119
|
-
fontWeight={labelFontWeight}
|
|
120
|
-
>{`${yLabel} `}</ToolTipTSpanLabel>
|
|
121
|
-
<tspan fill={valueFill}>{yDisplayValue}</tspan>
|
|
122
|
-
|
|
123
|
-
{this.props.icons?.map((i) => {
|
|
124
|
-
return <tspan fill={i.fillColor || '#000'} fontSize={i.size} onClick={(e) => handleIconClick(e, i)}> {i.unicode}</tspan>;
|
|
125
|
-
})}
|
|
126
|
-
</ToolTipText>
|
|
127
|
-
</g>
|
|
128
|
-
</>
|
|
129
|
-
);
|
|
130
|
-
};
|
|
131
|
-
}
|