@@ -26,12 +26,16 @@ import {
2626 ChartLabelProps ,
2727 ChartLine ,
2828 ChartLineProps ,
29+ ChartLegend ,
30+ ChartLegendProps ,
2931 ChartLegendTooltip ,
3032 ChartLegendTooltipContent ,
3133 ChartLegendTooltipContentProps ,
3234 ChartLegendTooltipLabel ,
3335 ChartLegendTooltipProps ,
3436 ChartLegendLabelProps ,
37+ ChartPoint ,
38+ ChartPointProps ,
3539 createContainer ,
3640} from "@patternfly/react-charts"
3741
@@ -45,32 +49,54 @@ class MyTooltipLabel extends React.PureComponent<ChartLabelProps> {
4549 }
4650}
4751
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+
4867class MyTooltipLegendLabel extends React . PureComponent <
4968 ChartLegendLabelProps & { styleOverride ?: ChartLegendLabelProps [ "style" ] }
5069> {
5170 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
5871 return (
5972 < ChartLegendTooltipLabel
6073 { ...this . props }
61- dx = { ( ( dx || 0 ) * BaseChart . legendLabelStyle . fontSize ) / 14 }
74+ { ... scale ( this . props ) }
6275 style = { this . props . styleOverride || BaseChart . legendLabelStyle }
6376 legendLabelComponent = { < MyTooltipLabel /> }
6477 />
6578 )
6679 }
6780}
6881
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+
6994class MyTooltipContent extends React . PureComponent < ChartLegendTooltipContentProps > {
7095 public render ( ) {
7196 return (
7297 < ChartLegendTooltipContent
7398 { ...this . props }
99+ legendComponent = { < MyChartLegend /> }
74100 labelComponent = { < MyTooltipLegendLabel /> }
75101 titleComponent = { < MyTooltipLegendLabel styleOverride = { BaseChart . legendTitleStyle } /> }
76102 />
0 commit comments