Skip to content

Commit

Permalink
Enable Controlled Legend working in Declarative HBC (#33476)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anush2303 authored Dec 16, 2024
1 parent e049b57 commit 7b75871
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Enable Controlled Legends working in declarative HBC",
"packageName": "@fluentui/react-charting",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class HorizontalBarChartWithAxisBase extends React.Component<
color: '',
dataForHoverCard: 0,
isCalloutVisible: false,
isLegendSelected: false,
isLegendSelected: props.legendProps?.selectedLegend !== undefined,
isLegendHovered: false,
refSelected: null,
selectedLegendTitle: props.legendProps?.selectedLegend ?? '',
Expand Down Expand Up @@ -583,6 +583,15 @@ export class HorizontalBarChartWithAxisBase extends React.Component<
const { xBarScale, yBarScale } = this._getScales(containerHeight, containerWidth, false);
const { useSingleColor = false } = this.props;
const bars = this._points.map((point: IHorizontalBarChartWithAxisDataPoint, index: number) => {
let shouldHighlight = true;
if (this.state.isLegendHovered || this.state.isLegendSelected) {
shouldHighlight = this.state.selectedLegendTitle === point.legend;
}
this._classNames = getClassNames(this.props.styles!, {
theme: this.props.theme!,
legendColor: this.state.color,
shouldHighlight,
});
const barHeight: number = Math.max(yBarScale(point.y), 0);
if (barHeight < 1) {
return <React.Fragment key={point.x}> </React.Fragment>;
Expand Down Expand Up @@ -627,6 +636,7 @@ export class HorizontalBarChartWithAxisBase extends React.Component<
<rect
transform={`translate(0,${0.5 * (yBarScale.bandwidth() - this._barHeight)})`}
key={point.x}
className={this._classNames.opacityChangeOnHover}
x={this._isRtl ? xBarScale(point.x) : this.margins.left!}
y={yBarScale(point.y)}
rx={this.props.roundCorners ? 3 : 0}
Expand All @@ -646,7 +656,7 @@ export class HorizontalBarChartWithAxisBase extends React.Component<
onMouseOver={this._onBarHover.bind(this, point, startColor)}
onMouseLeave={this._onBarLeave}
onBlur={this._onBarLeave}
data-is-focusable={true}
data-is-focusable={shouldHighlight}
onFocus={this._onBarFocus.bind(this, point, index, startColor)}
fill={this.props.enableGradient ? `url(#${gradientId})` : startColor}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2128,6 +2128,11 @@ exports[`HorizontalBarChartWithAxis snapShot testing renders showToolTipForYAxis
<rect
aria-label="1000. String One."
aria-labelledby="toolTipcallout0"
className=
{
opacity: ;
}
data-is-focusable={true}
fill="#0078d4"
height={32}
Expand Down Expand Up @@ -2739,6 +2744,11 @@ exports[`HorizontalBarChartWithAxis snapShot testing renders showYAxisLables cor
<rect
aria-label="1000. String One."
aria-labelledby="toolTipcallout0"
className=
{
opacity: ;
}
data-is-focusable={true}
fill="#0078d4"
height={32}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4389,6 +4389,11 @@ exports[`Horizontal bar chart with axis rendering Should render the Horizontal b
<rect
aria-label="1000. String One."
aria-labelledby="toolTipcallout0"
class=
{
opacity: ;
}
data-is-focusable="true"
fill="#0078d4"
height="32"
Expand All @@ -4403,6 +4408,11 @@ exports[`Horizontal bar chart with axis rendering Should render the Horizontal b
<rect
aria-label="5000. String Two."
aria-labelledby="toolTipcallout0"
class=
{
opacity: ;
}
data-is-focusable="true"
fill="#002050"
height="32"
Expand All @@ -4417,6 +4427,11 @@ exports[`Horizontal bar chart with axis rendering Should render the Horizontal b
<rect
aria-label="3000. String Three."
aria-labelledby="toolTipcallout0"
class=
{
opacity: ;
}
data-is-focusable="true"
fill="#00188f"
height="32"
Expand All @@ -4431,6 +4446,11 @@ exports[`Horizontal bar chart with axis rendering Should render the Horizontal b
<rect
aria-label="2000. String Four."
aria-labelledby="toolTipcallout0"
class=
{
opacity: ;
}
data-is-focusable="true"
fill="#0078d4"
height="32"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
],
"layout": {
"title": "PHP Framework Popularity at Work - SitePoint, 2015",
"width": 1151,
"width": 850,
"xaxis": {
"type": "linear",
"range": [-198.2562959184288, 1830.6731869091736],
Expand Down

0 comments on commit 7b75871

Please sign in to comment.