@@ -26,12 +26,16 @@ import {
26
26
ChartLabelProps ,
27
27
ChartLine ,
28
28
ChartLineProps ,
29
+ ChartLegend ,
30
+ ChartLegendProps ,
29
31
ChartLegendTooltip ,
30
32
ChartLegendTooltipContent ,
31
33
ChartLegendTooltipContentProps ,
32
34
ChartLegendTooltipLabel ,
33
35
ChartLegendTooltipProps ,
34
36
ChartLegendLabelProps ,
37
+ ChartPoint ,
38
+ ChartPointProps ,
35
39
createContainer ,
36
40
} from "@patternfly/react-charts"
37
41
@@ -45,32 +49,54 @@ class MyTooltipLabel extends React.PureComponent<ChartLabelProps> {
45
49
}
46
50
}
47
51
52
+ function scaleOne ( x : number ) : number {
53
+ return ( ( x || 0 ) * BaseChart . legendLabelStyle . fontSize ) / 14
54
+ }
55
+
56
+ function scale ( props : { x ?: ChartLegendLabelProps [ "x" ] ; dx ?: ChartLegendLabelProps [ "dx" ] } ) {
57
+ const dx = typeof props . dx === "number" ? props . dx : typeof props . dx === "string" ? parseInt ( props . dx , 10 ) : 0
58
+
59
+ const x = typeof props . x === "number" ? props . x : typeof props . x === "string" ? parseInt ( props . x , 10 ) : 0
60
+
61
+ return {
62
+ x : scaleOne ( x ) ,
63
+ dx : scaleOne ( dx ) ,
64
+ }
65
+ }
66
+
48
67
class MyTooltipLegendLabel extends React . PureComponent <
49
68
ChartLegendLabelProps & { styleOverride ?: ChartLegendLabelProps [ "style" ] }
50
69
> {
51
70
public render ( ) {
52
- const dx =
53
- typeof this . props . dx === "number"
54
- ? this . props . dx
55
- : typeof this . props . dx === "string"
56
- ? parseInt ( this . props . dx , 10 )
57
- : 0
58
71
return (
59
72
< ChartLegendTooltipLabel
60
73
{ ...this . props }
61
- dx = { ( ( dx || 0 ) * BaseChart . legendLabelStyle . fontSize ) / 14 }
74
+ { ... scale ( this . props ) }
62
75
style = { this . props . styleOverride || BaseChart . legendLabelStyle }
63
76
legendLabelComponent = { < MyTooltipLabel /> }
64
77
/>
65
78
)
66
79
}
67
80
}
68
81
82
+ class MyChartPoint extends React . PureComponent < ChartPointProps > {
83
+ public render ( ) {
84
+ return < ChartPoint { ...this . props } { ...scale ( this . props ) } />
85
+ }
86
+ }
87
+
88
+ class MyChartLegend extends React . PureComponent < ChartLegendProps > {
89
+ public render ( ) {
90
+ return < ChartLegend { ...this . props } dataComponent = { < MyChartPoint /> } />
91
+ }
92
+ }
93
+
69
94
class MyTooltipContent extends React . PureComponent < ChartLegendTooltipContentProps > {
70
95
public render ( ) {
71
96
return (
72
97
< ChartLegendTooltipContent
73
98
{ ...this . props }
99
+ legendComponent = { < MyChartLegend /> }
74
100
labelComponent = { < MyTooltipLegendLabel /> }
75
101
titleComponent = { < MyTooltipLegendLabel styleOverride = { BaseChart . legendTitleStyle } /> }
76
102
/>
0 commit comments