Skip to content

Commit

Permalink
Support single point in area chart (#25842)
Browse files Browse the repository at this point in the history
* Allow single point in area chart

* Add change file

* Fix lint issue

* Add tests for area chart single point
  • Loading branch information
AtishayMsft authored Nov 30, 2022
1 parent c46ff8d commit a5ea64c
Show file tree
Hide file tree
Showing 4 changed files with 386 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Support single point in area chart",
"packageName": "@fluentui/react-charting",
"email": "[email protected]",
"dependentChangeType": "patch"
}
37 changes: 27 additions & 10 deletions packages/react-charting/src/components/AreaChart/AreaChart.base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -576,16 +576,33 @@ export class AreaChartBase extends React.Component<IAreaChartProps, IAreaChartSt
onMouseOver={this._onRectMouseMove}
{...points[index]!.lineOptions}
/>
<path
id={`${index}-graph-${this._uniqueIdForGraph}`}
d={area(singleStackedData)!}
fill={this._colors[index]}
opacity={this._opacity[index]}
fillOpacity={this._getOpacity(points[index]!.legend)}
onMouseMove={this._onRectMouseMove}
onMouseOut={this._onRectMouseOut}
onMouseOver={this._onRectMouseMove}
/>
{singleStackedData.length === 1 ? (
<circle
id={`${index}-graph-${this._uniqueIdForGraph}`}
cx={xScale(singleStackedData[0].xVal)}
cy={yScale(singleStackedData[0].values[1])}
r={6}
stroke={this._colors[index]}
strokeWidth={3}
fill={this._colors[index]}
opacity={this._opacity[index]}
fillOpacity={this._getOpacity(points[index]!.legend)}
onMouseMove={this._onRectMouseMove}
onMouseOut={this._onRectMouseOut}
onMouseOver={this._onRectMouseMove}
/>
) : (
<path
id={`${index}-graph-${this._uniqueIdForGraph}`}
d={area(singleStackedData)!}
fill={this._colors[index]}
opacity={this._opacity[index]}
fillOpacity={this._getOpacity(points[index]!.legend)}
onMouseMove={this._onRectMouseMove}
onMouseOut={this._onRectMouseOut}
onMouseOver={this._onRectMouseMove}
/>
)}
</React.Fragment>,
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ const chartPoints = {
lineChartData: points,
};

const singlePoint = [
{
legend: 'metaData1',
data: [{ x: 20, y: 50 }],
color: 'red',
},
];
const singleChartPoint = {
chartTitle: 'AreaChart',
lineChartData: singlePoint,
};

describe('AreaChart snapShot testing', () => {
it('renders Areachart correctly', () => {
const component = renderer.create(<AreaChart data={chartPoints} />);
Expand Down Expand Up @@ -86,6 +98,12 @@ describe('AreaChart snapShot testing', () => {
const tree = component.toJSON();
expect(tree).toMatchSnapshot();
});

it('renders Areachart with single point correctly', () => {
const component = renderer.create(<AreaChart data={singleChartPoint} />);
const tree = component.toJSON();
expect(tree).toMatchSnapshot();
});
});

describe('AreaChart - basic props', () => {
Expand Down
Loading

0 comments on commit a5ea64c

Please sign in to comment.