Skip to content

Commit

Permalink
feat(declarative-charts): Support rounded ticks for y-axis (#33730)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anush2303 authored Jan 30, 2025
1 parent 82cc27f commit 669de2d
Show file tree
Hide file tree
Showing 9 changed files with 1,349 additions and 1,201 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Support rounded ticks in declarative charts",
"packageName": "@fluentui/react-charting",
"email": "[email protected]",
"dependentChangeType": "patch"
}
3 changes: 2 additions & 1 deletion packages/charts/react-charting/etc/react-charting.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ export interface ICartesianChartProps {
noOfCharsToTruncate?: number;
parentRef?: HTMLElement | null;
rotateXAxisLables?: boolean;
roundedTicks?: boolean;
secondaryYAxistitle?: string;
secondaryYScaleOptions?: {
yMinValue?: number;
Expand Down Expand Up @@ -1080,7 +1081,7 @@ export interface IModifiedCartesianChartProps extends ICartesianChartProps {
createStringYAxis: (yAxisParams: IYAxisParams, dataPoints: string[], isRtl: boolean, barWidth: number | undefined) => ScaleBand<string>;
// Warning: (ae-forgotten-export) The symbol "IYAxisParams" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "IAxisData" needs to be exported by the entry point index.d.ts
createYAxis: (yAxisParams: IYAxisParams, isRtl: boolean, axisData: IAxisData, isIntegralDataset: boolean, useSecondaryYScale?: boolean, supportNegativeData?: boolean) => ScaleLinear<number, number, never>;
createYAxis: (yAxisParams: IYAxisParams, isRtl: boolean, axisData: IAxisData, isIntegralDataset: boolean, useSecondaryYScale?: boolean, supportNegativeData?: boolean, roundedTicks?: boolean) => ScaleLinear<number, number, never>;
culture?: string;
customizedCallout?: any;
datasetForXAxisDomain?: string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ export class CartesianChartBase
this.isIntegralDataset,
true,
this.props.supportNegativeData!,
this.props.roundedTicks!,
);
}
yScale = this.props.createYAxis(
Expand All @@ -422,6 +423,7 @@ export class CartesianChartBase
this.isIntegralDataset,
false,
this.props.supportNegativeData!,
this.props.roundedTicks!,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,12 @@ export interface ICartesianChartProps {
*/
supportNegativeData?: boolean;

/**
* @default false
* The prop used to decide rounded ticks on y axis
*/
roundedTicks?: boolean;

/**
* Optional callback to access the IChart interface. Use this instead of ref for accessing
* the public methods and properties of the component.
Expand Down Expand Up @@ -665,6 +671,7 @@ export interface IModifiedCartesianChartProps extends ICartesianChartProps {
isIntegralDataset: boolean,
useSecondaryYScale?: boolean,
supportNegativeData?: boolean,
roundedTicks?: boolean,
) => ScaleLinear<number, number, never>;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { DataVizPalette, getColorFromToken, getNextColor } from '../../utilities
import { GaugeChartVariant, IGaugeChartProps, IGaugeChartSegment } from '../GaugeChart/index';
import { IGroupedVerticalBarChartProps } from '../GroupedVerticalBarChart/index';
import { IVerticalBarChartProps } from '../VerticalBarChart/index';
import { findNumericMinMaxOfY } from '../../utilities/utilities';
import { Layout, PlotlySchema, PieData, PlotData, SankeyData } from './PlotlySchema';
import type { Datum, TypedArray } from './PlotlySchema';
import { timeParse } from 'd3-time-format';
Expand Down Expand Up @@ -525,6 +526,7 @@ export const transformPlotlyJsonToScatterChartProps = (
} as ILineChartPoints;
});

const yMinMaxValues = findNumericMinMaxOfY(chartData);
const { chartTitle, xAxisTitle, yAxisTitle } = getTitles(input.layout);

const chartProps: IChartProps = {
Expand All @@ -550,6 +552,9 @@ export const transformPlotlyJsonToScatterChartProps = (
yAxisTitle,
secondaryYAxistitle: secondaryYAxisValues.secondaryYAxistitle,
secondaryYScaleOptions: secondaryYAxisValues.secondaryYScaleOptions,
roundedTicks: true,
yMinValue: yMinMaxValues.startValue,
yMaxValue: yMinMaxValues.endValue,
} as ILineChartProps;
}
};
Expand Down
Loading

0 comments on commit 669de2d

Please sign in to comment.