@sgonzaloc/react-financial-charts-tooltip 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/LICENSE +24 -0
  2. package/README.md +5 -0
  3. package/lib/BollingerBandTooltip.d.ts +40 -0
  4. package/lib/BollingerBandTooltip.js +46 -0
  5. package/lib/BollingerBandTooltip.js.map +1 -0
  6. package/lib/GroupTooltip.d.ts +41 -0
  7. package/lib/GroupTooltip.js +81 -0
  8. package/lib/GroupTooltip.js.map +1 -0
  9. package/lib/HoverTooltip.d.ts +57 -0
  10. package/lib/HoverTooltip.js +175 -0
  11. package/lib/HoverTooltip.js.map +1 -0
  12. package/lib/MACDTooltip.d.ts +46 -0
  13. package/lib/MACDTooltip.js +35 -0
  14. package/lib/MACDTooltip.js.map +1 -0
  15. package/lib/MovingAverageTooltip.d.ts +55 -0
  16. package/lib/MovingAverageTooltip.js +56 -0
  17. package/lib/MovingAverageTooltip.js.map +1 -0
  18. package/lib/OHLCTooltip.d.ts +57 -0
  19. package/lib/OHLCTooltip.js +58 -0
  20. package/lib/OHLCTooltip.js.map +1 -0
  21. package/lib/RSITooltip.d.ts +32 -0
  22. package/lib/RSITooltip.js +34 -0
  23. package/lib/RSITooltip.js.map +1 -0
  24. package/lib/SingleTooltip.d.ts +29 -0
  25. package/lib/SingleTooltip.js +67 -0
  26. package/lib/SingleTooltip.js.map +1 -0
  27. package/lib/SingleValueTooltip.d.ts +38 -0
  28. package/lib/SingleValueTooltip.js +49 -0
  29. package/lib/SingleValueTooltip.js.map +1 -0
  30. package/lib/StochasticTooltip.d.ts +43 -0
  31. package/lib/StochasticTooltip.js +36 -0
  32. package/lib/StochasticTooltip.js.map +1 -0
  33. package/lib/ToolTipTSpanLabel.d.ts +8 -0
  34. package/lib/ToolTipTSpanLabel.js +24 -0
  35. package/lib/ToolTipTSpanLabel.js.map +1 -0
  36. package/lib/ToolTipText.d.ts +9 -0
  37. package/lib/ToolTipText.js +25 -0
  38. package/lib/ToolTipText.js.map +1 -0
  39. package/lib/index.d.ts +12 -0
  40. package/lib/index.js +13 -0
  41. package/lib/index.js.map +1 -0
  42. package/package.json +50 -0
  43. package/src/BollingerBandTooltip.tsx +99 -0
  44. package/src/GroupTooltip.tsx +156 -0
  45. package/src/HoverTooltip.tsx +270 -0
  46. package/src/MACDTooltip.tsx +116 -0
  47. package/src/MovingAverageTooltip.tsx +145 -0
  48. package/src/OHLCTooltip.tsx +138 -0
  49. package/src/RSITooltip.tsx +80 -0
  50. package/src/SingleTooltip.tsx +122 -0
  51. package/src/SingleValueTooltip.tsx +107 -0
  52. package/src/StochasticTooltip.tsx +97 -0
  53. package/src/ToolTipTSpanLabel.tsx +14 -0
  54. package/src/ToolTipText.tsx +15 -0
  55. package/src/index.ts +12 -0
@@ -0,0 +1,116 @@
1
+ import { functor, GenericChartComponent, last } from "@sgonzaloc/react-financial-charts-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 MACDTooltipProps {
8
+ readonly origin: number[] | ((width: number, height: number) => [number, number]);
9
+ readonly className?: string;
10
+ readonly fontFamily?: string;
11
+ readonly fontSize?: number;
12
+ readonly fontWeight?: number;
13
+ readonly labelFill?: string;
14
+ readonly labelFontWeight?: number;
15
+ readonly onClick?: (event: React.MouseEvent) => void;
16
+ readonly options: {
17
+ slow: number;
18
+ fast: number;
19
+ signal: number;
20
+ };
21
+ readonly appearance: {
22
+ strokeStyle: {
23
+ macd: string;
24
+ signal: string;
25
+ };
26
+ fillStyle: {
27
+ divergence: string;
28
+ };
29
+ };
30
+ readonly displayFormat: (value: number) => string;
31
+ readonly displayInit?: string;
32
+ readonly displayValuesFor: (props: MACDTooltipProps, moreProps: any) => any | undefined;
33
+ readonly yAccessor: (data: any) => { macd: number; signal: number; divergence: number };
34
+ }
35
+
36
+ export class MACDTooltip extends React.Component<MACDTooltipProps> {
37
+ public static defaultProps = {
38
+ className: "react-financial-charts-tooltip",
39
+ displayFormat: format(".2f"),
40
+ displayInit: "n/a",
41
+ displayValuesFor: (_: any, props: any) => props.currentItem,
42
+ origin: [0, 0],
43
+ };
44
+
45
+ public render() {
46
+ return <GenericChartComponent clip={false} svgDraw={this.renderSVG} drawOn={["mousemove"]} />;
47
+ }
48
+
49
+ private readonly renderSVG = (moreProps: any) => {
50
+ const {
51
+ onClick,
52
+ displayInit,
53
+ fontFamily,
54
+ fontSize,
55
+ fontWeight,
56
+ displayValuesFor,
57
+ displayFormat,
58
+ className,
59
+ yAccessor,
60
+ options,
61
+ origin: originProp,
62
+ appearance,
63
+ labelFill,
64
+ labelFontWeight,
65
+ } = this.props;
66
+
67
+ const {
68
+ chartConfig: { width, height },
69
+ fullData,
70
+ } = moreProps;
71
+
72
+ const currentItem = displayValuesFor(this.props, moreProps) ?? last(fullData);
73
+
74
+ const macdValue = currentItem && yAccessor(currentItem);
75
+
76
+ const macd = (macdValue?.macd && displayFormat(macdValue.macd)) || displayInit;
77
+ const signal = (macdValue?.signal && displayFormat(macdValue.signal)) || displayInit;
78
+ const divergence = (macdValue?.divergence && displayFormat(macdValue.divergence)) || displayInit;
79
+
80
+ const origin = functor(originProp);
81
+ const [x, y] = origin(width, height);
82
+
83
+ return (
84
+ <g className={className} transform={`translate(${x}, ${y})`} onClick={onClick}>
85
+ <ToolTipText x={0} y={0} fontFamily={fontFamily} fontSize={fontSize} fontWeight={fontWeight}>
86
+ <ToolTipTSpanLabel fill={labelFill} fontWeight={labelFontWeight}>
87
+ MACD (
88
+ </ToolTipTSpanLabel>
89
+ <tspan fill={appearance.strokeStyle.macd}>{options.slow}</tspan>
90
+ <ToolTipTSpanLabel fill={labelFill} fontWeight={labelFontWeight}>
91
+ ,{" "}
92
+ </ToolTipTSpanLabel>
93
+ <tspan fill={appearance.strokeStyle.macd}>{options.fast}</tspan>
94
+ <ToolTipTSpanLabel fill={labelFill} fontWeight={labelFontWeight}>
95
+ ):{" "}
96
+ </ToolTipTSpanLabel>
97
+ <tspan fill={appearance.strokeStyle.macd}>{macd}</tspan>
98
+ <ToolTipTSpanLabel fill={labelFill} fontWeight={labelFontWeight}>
99
+ {" "}
100
+ Signal (
101
+ </ToolTipTSpanLabel>
102
+ <tspan fill={appearance.strokeStyle.signal}>{options.signal}</tspan>
103
+ <ToolTipTSpanLabel fill={labelFill} fontWeight={labelFontWeight}>
104
+ ):{" "}
105
+ </ToolTipTSpanLabel>
106
+ <tspan fill={appearance.strokeStyle.signal}>{signal}</tspan>
107
+ <ToolTipTSpanLabel fill={labelFill} fontWeight={labelFontWeight}>
108
+ {" "}
109
+ Divergence:{" "}
110
+ </ToolTipTSpanLabel>
111
+ <tspan fill={appearance.fillStyle.divergence}>{divergence}</tspan>
112
+ </ToolTipText>
113
+ </g>
114
+ );
115
+ };
116
+ }
@@ -0,0 +1,145 @@
1
+ import { functor, GenericChartComponent, last, MoreProps } from "@sgonzaloc/react-financial-charts-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: any;
18
+ readonly origin: [number, number];
19
+ readonly textFill?: string;
20
+ readonly value: string;
21
+ }
22
+
23
+ export class SingleMAToolTip extends React.Component<SingleMAToolTipProps> {
24
+ public render() {
25
+ const { color, displayName, fontSize, fontFamily, fontWeight, textFill, labelFill, labelFontWeight, value } =
26
+ this.props;
27
+
28
+ const translate = "translate(" + this.props.origin[0] + ", " + this.props.origin[1] + ")";
29
+
30
+ return (
31
+ <g transform={translate}>
32
+ <line x1={0} y1={2} x2={0} y2={28} stroke={color} strokeWidth={4} />
33
+ <ToolTipText x={5} y={11} fontFamily={fontFamily} fontSize={fontSize} fontWeight={fontWeight}>
34
+ <ToolTipTSpanLabel fill={labelFill} fontWeight={labelFontWeight}>
35
+ {displayName}
36
+ </ToolTipTSpanLabel>
37
+ <tspan x={5} dy={15} fill={textFill}>
38
+ {value}
39
+ </tspan>
40
+ </ToolTipText>
41
+ <rect x={0} y={0} width={55} height={30} onClick={this.onClick} fill="none" stroke="none" />
42
+ </g>
43
+ );
44
+ }
45
+
46
+ private readonly onClick = (event: React.MouseEvent<SVGRectElement, MouseEvent>) => {
47
+ const { onClick, forChart, options } = this.props;
48
+ if (onClick !== undefined) {
49
+ onClick(event, { chartId: forChart, ...options });
50
+ }
51
+ };
52
+ }
53
+
54
+ interface MovingAverageTooltipProps {
55
+ readonly className?: string;
56
+ readonly displayFormat: (value: number) => string;
57
+ readonly origin: number[];
58
+ readonly displayInit?: string;
59
+ readonly displayValuesFor?: (props: MovingAverageTooltipProps, moreProps: any) => any;
60
+ readonly onClick?: (event: React.MouseEvent<SVGRectElement, MouseEvent>) => void;
61
+ readonly textFill?: string;
62
+ readonly labelFill?: string;
63
+ readonly fontFamily?: string;
64
+ readonly fontSize?: number;
65
+ readonly fontWeight?: number;
66
+ readonly width?: number;
67
+ readonly options: {
68
+ yAccessor: (data: any) => number;
69
+ type: string;
70
+ stroke: string;
71
+ windowSize: number;
72
+ }[];
73
+ }
74
+
75
+ // tslint:disable-next-line: max-classes-per-file
76
+ export class MovingAverageTooltip extends React.Component<MovingAverageTooltipProps> {
77
+ public static defaultProps = {
78
+ className: "react-financial-charts-tooltip react-financial-charts-moving-average-tooltip",
79
+ displayFormat: format(".2f"),
80
+ displayInit: "n/a",
81
+ displayValuesFor: (_: any, props: any) => props.currentItem,
82
+ origin: [0, 10],
83
+ width: 65,
84
+ };
85
+
86
+ public render() {
87
+ return <GenericChartComponent clip={false} svgDraw={this.renderSVG} drawOn={["mousemove"]} />;
88
+ }
89
+
90
+ private readonly renderSVG = (moreProps: MoreProps) => {
91
+ const { chartId, chartConfig, chartConfig: { height = 0 } = {}, fullData } = moreProps;
92
+
93
+ const {
94
+ className,
95
+ displayInit = MovingAverageTooltip.defaultProps.displayInit,
96
+ onClick,
97
+ width = 65,
98
+ fontFamily,
99
+ fontSize,
100
+ fontWeight,
101
+ textFill,
102
+ labelFill,
103
+ origin: originProp,
104
+ displayFormat,
105
+ displayValuesFor = MovingAverageTooltip.defaultProps.displayValuesFor,
106
+ options,
107
+ } = this.props;
108
+
109
+ const currentItem = displayValuesFor(this.props, moreProps) ?? last(fullData);
110
+
111
+ const config = chartConfig!;
112
+
113
+ const origin = functor(originProp);
114
+ const [x, y] = origin(width, height);
115
+ const [ox, oy] = config.origin;
116
+
117
+ return (
118
+ <g transform={`translate(${ox + x}, ${oy + y})`} className={className}>
119
+ {options.map((each, idx) => {
120
+ const yValue = currentItem && each.yAccessor(currentItem);
121
+
122
+ const tooltipLabel = `${each.type} (${each.windowSize})`;
123
+ const yDisplayValue = yValue ? displayFormat(yValue) : displayInit;
124
+ return (
125
+ <SingleMAToolTip
126
+ key={idx}
127
+ origin={[width * idx, 0]}
128
+ color={each.stroke}
129
+ displayName={tooltipLabel}
130
+ value={yDisplayValue}
131
+ options={each}
132
+ forChart={chartId}
133
+ onClick={onClick}
134
+ fontFamily={fontFamily}
135
+ fontSize={fontSize}
136
+ fontWeight={fontWeight}
137
+ textFill={textFill}
138
+ labelFill={labelFill}
139
+ />
140
+ );
141
+ })}
142
+ </g>
143
+ );
144
+ };
145
+ }
@@ -0,0 +1,138 @@
1
+ import { functor, GenericChartComponent, last } from "@sgonzaloc/react-financial-charts-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
+ na: "n/a",
13
+ };
14
+
15
+ export interface OHLCTooltipProps {
16
+ readonly accessor?: (data: any) => any;
17
+ readonly className?: string;
18
+ readonly changeFormat?: (n: number | { valueOf(): number }) => string;
19
+ readonly displayTexts?: {
20
+ o: string;
21
+ h: string;
22
+ l: string;
23
+ c: string;
24
+ na: string;
25
+ };
26
+ readonly displayValuesFor?: (props: OHLCTooltipProps, moreProps: any) => any;
27
+ readonly fontFamily?: string;
28
+ readonly fontSize?: number;
29
+ readonly fontWeight?: number;
30
+ readonly labelFill?: string;
31
+ readonly labelFontWeight?: number;
32
+ readonly ohlcFormat?: (n: number | { valueOf(): number }) => string;
33
+ readonly onClick?: (event: React.MouseEvent<SVGGElement, MouseEvent>) => void;
34
+ readonly origin?: [number, number] | ((width: number, height: number) => [number, number]);
35
+ readonly percentFormat?: (n: number | { valueOf(): number }) => string;
36
+ readonly textFill?: string | ((item: any) => string);
37
+ }
38
+
39
+ export class OHLCTooltip extends React.Component<OHLCTooltipProps> {
40
+ public static defaultProps = {
41
+ accessor: (d: unknown) => d,
42
+ changeFormat: format("+.2f"),
43
+ className: "react-financial-charts-tooltip-hover",
44
+ displayTexts: displayTextsDefault,
45
+ displayValuesFor: (_: any, props: any) => props.currentItem,
46
+ fontFamily: "-apple-system, system-ui, 'Helvetica Neue', Ubuntu, sans-serif",
47
+ ohlcFormat: format(".2f"),
48
+ origin: [0, 0],
49
+ percentFormat: format("+.2%"),
50
+ };
51
+
52
+ public render() {
53
+ return <GenericChartComponent clip={false} svgDraw={this.renderSVG} drawOn={["mousemove"]} />;
54
+ }
55
+
56
+ private readonly renderSVG = (moreProps: any) => {
57
+ const {
58
+ accessor,
59
+ changeFormat = OHLCTooltip.defaultProps.changeFormat,
60
+ className,
61
+ displayTexts = OHLCTooltip.defaultProps.displayTexts,
62
+ displayValuesFor = OHLCTooltip.defaultProps.displayValuesFor,
63
+ fontFamily,
64
+ fontSize,
65
+ fontWeight,
66
+ labelFill,
67
+ labelFontWeight,
68
+ ohlcFormat = OHLCTooltip.defaultProps.ohlcFormat,
69
+ onClick,
70
+ percentFormat = OHLCTooltip.defaultProps.percentFormat,
71
+ textFill,
72
+ } = this.props;
73
+
74
+ const {
75
+ chartConfig: { width, height },
76
+ fullData,
77
+ } = moreProps;
78
+
79
+ const currentItem = displayValuesFor(this.props, moreProps) ?? last(fullData);
80
+
81
+ let open: string = displayTexts.na;
82
+ let high: string = displayTexts.na;
83
+ let low: string = displayTexts.na;
84
+ let close: string = displayTexts.na;
85
+ let change: string = displayTexts.na;
86
+
87
+ if (currentItem !== undefined && accessor !== undefined) {
88
+ const item = accessor(currentItem);
89
+ if (item !== undefined) {
90
+ open = ohlcFormat(item.open);
91
+ high = ohlcFormat(item.high);
92
+ low = ohlcFormat(item.low);
93
+ close = ohlcFormat(item.close);
94
+ change = `${changeFormat(item.close - item.open)} (${percentFormat(
95
+ (item.close - item.open) / item.open,
96
+ )})`;
97
+ }
98
+ }
99
+
100
+ const { origin: originProp } = this.props;
101
+ const [x, y] = functor(originProp)(width, height);
102
+ const valueFill = functor(textFill)(currentItem);
103
+
104
+ return (
105
+ <g className={className} transform={`translate(${x}, ${y})`} onClick={onClick}>
106
+ <ToolTipText x={0} y={0} fontFamily={fontFamily} fontSize={fontSize} fontWeight={fontWeight}>
107
+ <ToolTipTSpanLabel fill={labelFill} fontWeight={labelFontWeight} key="label_O">
108
+ {displayTexts.o}
109
+ </ToolTipTSpanLabel>
110
+ <tspan key="value_O" fill={valueFill}>
111
+ {open}
112
+ </tspan>
113
+ <ToolTipTSpanLabel fill={labelFill} fontWeight={labelFontWeight} key="label_H">
114
+ {displayTexts.h}
115
+ </ToolTipTSpanLabel>
116
+ <tspan key="value_H" fill={valueFill}>
117
+ {high}
118
+ </tspan>
119
+ <ToolTipTSpanLabel fill={labelFill} fontWeight={labelFontWeight} key="label_L">
120
+ {displayTexts.l}
121
+ </ToolTipTSpanLabel>
122
+ <tspan key="value_L" fill={valueFill}>
123
+ {low}
124
+ </tspan>
125
+ <ToolTipTSpanLabel fill={labelFill} fontWeight={labelFontWeight} key="label_C">
126
+ {displayTexts.c}
127
+ </ToolTipTSpanLabel>
128
+ <tspan key="value_C" fill={valueFill}>
129
+ {close}
130
+ </tspan>
131
+ <tspan key="value_Change" fill={valueFill}>
132
+ {` ${change}`}
133
+ </tspan>
134
+ </ToolTipText>
135
+ </g>
136
+ );
137
+ };
138
+ }
@@ -0,0 +1,80 @@
1
+ import { functor, isDefined, GenericChartComponent } from "@sgonzaloc/react-financial-charts-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
+ }
@@ -0,0 +1,122 @@
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}:&nbsp;</ToolTipTSpanLabel>
84
+ <tspan fill={valueFill}>{yValue}&nbsp;&nbsp;</tspan>
85
+ </tspan>
86
+ );
87
+ }
88
+
89
+ public render() {
90
+ const { layout } = this.props;
91
+ let comp: React.ReactElement | 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
+ }