Skip to content
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

feat(react-charting): hide overlapping x-axis tick labels #33678

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "feat: hide overlapping x-axis tick labels",
"packageName": "@fluentui/react-charting",
"email": "[email protected]",
"dependentChangeType": "patch"
}
7 changes: 4 additions & 3 deletions packages/charts/react-charting/etc/react-charting.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ export interface ICartesianChartProps {
focusZonePropsForLegendsInHoverCard?: IFocusZoneProps;
height?: number;
hideLegend?: boolean;
hideTickOverlap?: boolean;
hideTooltip?: boolean;
href?: string;
// (undocumented)
Expand All @@ -302,7 +303,7 @@ export interface ICartesianChartProps {
theme?: ITheme;
tickFormat?: string;
tickPadding?: number;
tickValues?: number[] | Date[];
tickValues?: number[] | Date[] | string[];
timeFormatLocale?: TimeLocaleDefinition;
useUTC?: boolean;
width?: number;
Expand Down Expand Up @@ -1089,7 +1090,7 @@ export interface IModifiedCartesianChartProps extends ICartesianChartProps {
getAxisData?: any;
getDomainMargins?: (containerWidth: number) => IMargins;
// Warning: (ae-forgotten-export) The symbol "IDomainNRange" needs to be exported by the entry point index.d.ts
getDomainNRangeValues: (points: ILineChartPoints[] | IVerticalBarChartDataPoint[] | IVerticalStackedBarDataPoint[] | IHorizontalBarChartWithAxisDataPoint[] | IGroupedVerticalBarChartData[] | IHeatMapChartDataPoint[], margins: IMargins, width: number, chartType: ChartTypes, isRTL: boolean, xAxisType: XAxisTypes, barWidth: number, tickValues: Date[] | number[] | undefined, shiftX: number) => IDomainNRange;
getDomainNRangeValues: (points: ILineChartPoints[] | IVerticalBarChartDataPoint[] | IVerticalStackedBarDataPoint[] | IHorizontalBarChartWithAxisDataPoint[] | IGroupedVerticalBarChartData[] | IHeatMapChartDataPoint[], margins: IMargins, width: number, chartType: ChartTypes, isRTL: boolean, xAxisType: XAxisTypes, barWidth: number, tickValues: Date[] | number[] | string[] | undefined, shiftX: number) => IDomainNRange;
getGraphData?: any;
getmargins?: (margins: IMargins) => void;
getMinMaxOfYAxis: (points: ILineChartPoints[] | IHorizontalBarChartWithAxisDataPoint[] | IVerticalBarChartDataPoint[] | IDataPoint[], yAxisType: YAxisType | undefined) => {
Expand All @@ -1107,7 +1108,7 @@ export interface IModifiedCartesianChartProps extends ICartesianChartProps {
stringDatasetForYAxisDomain?: string[];
svgFocusZoneProps?: IFocusZoneProps;
tickParams?: {
tickValues?: number[] | Date[];
tickValues?: number[] | Date[] | string[];
tickFormat?: string;
};
xAxisInnerPadding?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,12 @@ export class CartesianChartBase
xAxisPadding: this.props.xAxisPadding,
xAxisInnerPadding: this.props.xAxisInnerPadding,
xAxisOuterPadding: this.props.xAxisOuterPadding,
containerWidth: this.state.containerWidth,
hideTickOverlap:
this.props.hideTickOverlap &&
!this.props.rotateXAxisLables &&
!this.props.showXAxisLablesTooltip &&
!this.props.wrapXAxisLables,
};

const YAxisParams = {
Expand Down Expand Up @@ -324,7 +330,12 @@ export class CartesianChartBase
let tickValues: (string | number)[];
switch (this.props.xAxisType!) {
case XAxisTypes.NumericAxis:
({ xScale, tickValues } = createNumericXAxis(XAxisParams, this.props.chartType, culture));
({ xScale, tickValues } = createNumericXAxis(
XAxisParams,
this.props.tickParams!,
this.props.chartType,
culture,
));
break;
case XAxisTypes.DateAxis:
({ xScale, tickValues } = createDateXAxis(
Expand All @@ -346,7 +357,12 @@ export class CartesianChartBase
));
break;
default:
({ xScale, tickValues } = createNumericXAxis(XAxisParams, this.props.chartType, culture));
({ xScale, tickValues } = createNumericXAxis(
XAxisParams,
this.props.tickParams!,
this.props.chartType,
culture,
));
}
this._xScale = xScale;
this._tickValues = tickValues;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export interface ICartesianChartProps {
* This is a optional parameter if not specified D3 will decide which values appear on the x-axis for you
* Please look at https://github.com/d3/d3-scale for more information on how D3 decides what data to appear on the axis of chart
*/
tickValues?: number[] | Date[];
tickValues?: number[] | Date[] | string[];

/**
* the format for the data on x-axis. For date object this can be specified to your requirement. Eg: '%m/%d', '%d'
Expand Down Expand Up @@ -452,6 +452,12 @@ export interface ICartesianChartProps {
* the public methods and properties of the component.
*/
componentRef?: IRefObject<IChart>;

/**
* Determines whether overlapping x-axis tick labels should be hidden.
* @default false
*/
hideTickOverlap?: boolean;
}

export interface IYValueHover {
Expand Down Expand Up @@ -551,7 +557,7 @@ export interface IModifiedCartesianChartProps extends ICartesianChartProps {
* Tick params are applicable for date axis only.
*/
tickParams?: {
tickValues?: number[] | Date[];
tickValues?: number[] | Date[] | string[];
tickFormat?: string;
};

Expand Down Expand Up @@ -684,7 +690,7 @@ export interface IModifiedCartesianChartProps extends ICartesianChartProps {
isRTL: boolean,
xAxisType: XAxisTypes,
barWidth: number,
tickValues: Date[] | number[] | undefined,
tickValues: Date[] | number[] | string[] | undefined,
shiftX: number,
) => IDomainNRange;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ export const transformPlotlyJsonToVSBCProps = (
mode: 'plotly',
secondaryYAxistitle: secondaryYAxisValues.secondaryYAxistitle,
secondaryYScaleOptions: secondaryYAxisValues.secondaryYScaleOptions,
hideTickOverlap: true,
};
};

Expand Down Expand Up @@ -358,6 +359,7 @@ export const transformPlotlyJsonToGVBCProps = (
mode: 'plotly',
secondaryYAxistitle: secondaryYAxisValues.secondaryYAxistitle,
secondaryYScaleOptions: secondaryYAxisValues.secondaryYScaleOptions,
hideTickOverlap: true,
};
};

Expand Down Expand Up @@ -449,6 +451,7 @@ export const transformPlotlyJsonToVBCProps = (
xAxisTitle,
yAxisTitle,
mode: 'plotly',
hideTickOverlap: true,
};
};

Expand Down Expand Up @@ -497,6 +500,7 @@ export const transformPlotlyJsonToScatterChartProps = (
secondaryYAxistitle: secondaryYAxisValues.secondaryYAxistitle,
secondaryYScaleOptions: secondaryYAxisValues.secondaryYScaleOptions,
mode,
hideTickOverlap: true,
} as IAreaChartProps;
} else {
return {
Expand All @@ -506,6 +510,7 @@ export const transformPlotlyJsonToScatterChartProps = (
yAxisTitle,
secondaryYAxistitle: secondaryYAxisValues.secondaryYAxistitle,
secondaryYScaleOptions: secondaryYAxisValues.secondaryYScaleOptions,
hideTickOverlap: true,
} as ILineChartProps;
}
};
Expand Down Expand Up @@ -561,6 +566,7 @@ export const transformPlotlyJsonToHorizontalBarWithAxisProps = (
width: input.layout?.width ?? 600,
},
},
hideTickOverlap: true,
};
};

Expand Down Expand Up @@ -618,6 +624,7 @@ export const transformPlotlyJsonToHeatmapProps = (input: PlotlySchema): IHeatMap
xAxisTitle,
yAxisTitle,
sortOrder: 'none',
hideTickOverlap: true,
};
};

Expand Down
Loading
Loading