-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handling central text overflow and adding tooltip for donut charts #26192
base: master
Are you sure you want to change the base?
Changes from all commits
7e3a3c2
42d2636
322ca58
62a5b7f
d1d70a7
66c1fa7
2457a45
8ce67c1
60789fd
b9e2c85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "patch", | ||
"comment": "Bug Fix", | ||
"packageName": "@fluentui/react-charting", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,9 @@ export class DonutChartBase extends React.Component<IDonutChartProps, IDonutChar | |
private _currentHoverElement: any; | ||
private _calloutId: string; | ||
private _calloutAnchorPoint: IChartDataPoint | null; | ||
private _tooltip: any; | ||
private _tooltipId: string; | ||
private _rectTooltipId: string; | ||
private _emptyChartId: string | null; | ||
|
||
public static getDerivedStateFromProps( | ||
|
@@ -80,6 +83,8 @@ export class DonutChartBase extends React.Component<IDonutChartProps, IDonutChar | |
this._hoverLeave = this._hoverLeave.bind(this); | ||
this._calloutId = getId('callout'); | ||
this._uniqText = getId('_Pie_'); | ||
this._tooltipId = getId('_Donut_tooltip_'); | ||
this._rectTooltipId = getId('_Rect_tooltip_'); | ||
this._emptyChartId = getId('_DonutChart_empty'); | ||
} | ||
public componentDidMount(): void { | ||
|
@@ -118,11 +123,23 @@ export class DonutChartBase extends React.Component<IDonutChartProps, IDonutChar | |
> | ||
<FocusZone direction={FocusZoneDirection.horizontal} handleTabKey={FocusZoneTabbableElements.all}> | ||
<div> | ||
<div | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use SvgTooltipText control here. |
||
id={this._tooltipId} | ||
style={{ position: 'absolute', display: 'none' }} | ||
className={this._classNames.tooltip!} | ||
/> | ||
<svg | ||
className={this._classNames.chart} | ||
aria-label={data?.chartTitle} | ||
ref={(node: SVGElement | null) => this._setViewBox(node)} | ||
> | ||
<rect | ||
id={this._rectTooltipId} | ||
onMouseMove={this._showTooltip.bind(this, this.props.valueInsideDonut)} | ||
onMouseOut={this._hideTooltip.bind(this)} | ||
className={this._classNames.tooltipContainer!} | ||
ref={(element: SVGElement | null) => (this._tooltip = element)} | ||
/> | ||
<Pie | ||
width={this.state._width!} | ||
height={this.state._height!} | ||
|
@@ -302,7 +319,7 @@ export class DonutChartBase extends React.Component<IDonutChartProps, IDonutChar | |
}); | ||
return legendValue; | ||
} else { | ||
return valueInsideDonut; | ||
return valueInsideDonut !== undefined ? valueInsideDonut : ''; | ||
} | ||
} | ||
|
||
|
@@ -324,6 +341,23 @@ export class DonutChartBase extends React.Component<IDonutChartProps, IDonutChar | |
return this.state.selectedLegend || this.state.activeLegend; | ||
} | ||
|
||
private _showTooltip = (text: string | number, evt: any) => { | ||
if (this._tooltip) { | ||
this._tooltip!.innerHTML = text ? text.toString() : ''; | ||
this._tooltip!.style.display = 'block'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be done using react states and not direct dom interactions There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
this._tooltip!.style.opacity = '0.9'; | ||
this._tooltip!.style.left = evt.pageX + 'px'; | ||
this._tooltip!.style.top = evt.pageY - 28 + 'px'; | ||
} | ||
}; | ||
|
||
private _hideTooltip = (evt: any) => { | ||
if (this._tooltip) { | ||
this._tooltip = document.getElementById(this._tooltipId); | ||
this._tooltip!.style.display = 'none'; | ||
} | ||
}; | ||
|
||
private _isChartEmpty(): boolean { | ||
return !( | ||
this.props.data && | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,7 @@ export class Pie extends React.Component<IPieProps, {}> { | |
{this.props.valueInsideDonut && ( | ||
<text | ||
y={5} | ||
id="Donut_center_text" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use getId? |
||
textAnchor="middle" | ||
dominantBaseline="middle" | ||
className={classNames.insideDonutString} | ||
|
@@ -97,7 +98,11 @@ export class Pie extends React.Component<IPieProps, {}> { | |
theme: this.props.theme!, | ||
}); | ||
|
||
wrapTextInsideDonut(classNames.insideDonutString, this.props.innerRadius! * 2 - TEXT_PADDING); | ||
wrapTextInsideDonut( | ||
classNames.insideDonutString, | ||
this.props.innerRadius! * 2 - TEXT_PADDING, | ||
this.props.valueInsideDonut!.toString(), | ||
); | ||
} | ||
|
||
private _focusCallback = (data: IChartDataPoint, id: string, e: SVGPathElement): void => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change needed?