Skip to content

Commit 426c539

Browse files
authored
chore: API docs update and minor changes to test utils API (#45)
* chore: API docs update and minor changes to test utils API * remove unneeded module import * resolved pr feedback * update callback names
1 parent ad6a29a commit 426c539

File tree

22 files changed

+391
-235
lines changed

22 files changed

+391
-235
lines changed

pages/01-cartesian-chart/controlled-visibility.page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ function ExampleMixedChart() {
108108
valueFormatter: numberFormatter,
109109
}}
110110
visibleSeries={visibleSeries}
111-
onChangeVisibleSeries={({ detail: { visibleSeries } }) => setSettings({ visibleItems: visibleSeries.join(",") })}
111+
onVisibleSeriesChange={({ detail: { visibleSeries } }) => setSettings({ visibleItems: visibleSeries.join(",") })}
112112
emphasizeBaseline={settings.emphasizeBaseline}
113113
/>
114114
);

pages/02-pie-chart/controlled-visibility.page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function ExamplePieChart() {
7676
`${segmentValue} units, ${((segmentValue / totalValue) * 100).toFixed(0)}%`
7777
}
7878
visibleSegments={visibleSegments}
79-
onChangeVisibleSegments={({ detail: { visibleSegments } }) =>
79+
onVisibleSegmentsChange={({ detail: { visibleSegments } }) =>
8080
setSettings({ visibleItems: visibleSegments.join(",") })
8181
}
8282
/>

pages/04-migration/examples/line-chart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export function ComponentNew({ headerFilter, legendFilter }: { headerFilter?: bo
136136
}
137137
tooltip={{ placement: "middle" }}
138138
visibleSeries={visibleSeries}
139-
onChangeVisibleSeries={({ detail }) => setVisibleSeries(detail.visibleSeries)}
139+
onVisibleSeriesChange={({ detail }) => setVisibleSeries(detail.visibleSeries)}
140140
/>
141141
);
142142
}

pages/04-migration/examples/pie-chart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export function ComponentNew({
9393
) : undefined,
9494
}}
9595
visibleSegments={visibleSegments}
96-
onChangeVisibleSegments={({ detail }) => setVisibleSegments(detail.visibleSegments)}
96+
onVisibleSegmentsChange={({ detail }) => setVisibleSegments(detail.visibleSegments)}
9797
innerAreaTitle="60"
9898
innerAreaDescription="total instances"
9999
/>

pages/common/use-highcharts.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export function useHighcharts({ more = false, xrange = false }: { more?: boolean
1414
const Highcharts = await import("highcharts");
1515

1616
await import("highcharts/modules/accessibility");
17-
await import("highcharts/modules/heatmap"); // Required for point visibility API!
1817

1918
// Required for arearange, areasplinerange, columnrange, gauge, boxplot, errorbar, waterfall, polygon, bubble
2019
if (more) {

src/__tests__/__snapshots__/documenter.test.ts.snap

Lines changed: 105 additions & 75 deletions
Large diffs are not rendered by default.

src/cartesian-chart/__tests__/cartesian-chart-visibility.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ function getVisibilityState() {
2323
};
2424
}
2525

26-
const onChangeVisibleSeries = vi.fn();
26+
const onVisibleSeriesChange = vi.fn();
2727

2828
afterEach(() => {
29-
onChangeVisibleSeries.mockReset();
29+
onVisibleSeriesChange.mockReset();
3030
});
3131

32-
const defaultProps = { highcharts, onChangeVisibleSeries };
32+
const defaultProps = { highcharts, onVisibleSeriesChange };
3333

3434
const lineSeries: CartesianChartProps.SeriesOptions[] = [
3535
{
@@ -74,7 +74,7 @@ describe("CartesianChart: visibility", () => {
7474
hiddenSeries: ["L1"],
7575
});
7676

77-
expect(onChangeVisibleSeries).toHaveBeenCalledWith(
77+
expect(onVisibleSeriesChange).toHaveBeenCalledWith(
7878
expect.objectContaining({
7979
detail: {
8080
visibleSeries: ["L2"],

src/cartesian-chart/__tests__/common.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ export const StatefulChart = forwardRef((props: CartesianChartProps, ref: React.
1919
ref={ref}
2020
{...props}
2121
visibleSeries={visibleSeries}
22-
onChangeVisibleSeries={(event) => {
22+
onVisibleSeriesChange={(event) => {
2323
setVisibleSeries(event.detail.visibleSeries);
24-
props.onChangeVisibleSeries?.(event);
24+
props.onVisibleSeriesChange?.(event);
2525
}}
2626
/>
2727
);
@@ -58,5 +58,5 @@ export const getTooltip = () => getChart().findTooltip()!;
5858
export const getTooltipHeader = () => getChart().findTooltip()!.findHeader()!;
5959
export const getTooltipBody = () => getChart().findTooltip()!.findBody()!;
6060
export const getTooltipFooter = () => getChart().findTooltip()!.findFooter()!;
61-
export const getAllTooltipSeries = () => getChart().findTooltip()!.findSeries();
61+
export const getAllTooltipSeries = () => getChart().findTooltip()!.findPoints();
6262
export const getTooltipSeries = (index: number) => getAllTooltipSeries()[index];

src/cartesian-chart/chart-cartesian-internal.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ export const InternalCartesianChart = forwardRef(
3232
({ tooltip, ...props }: InternalCartesianChartProps, ref: React.Ref<CartesianChartProps.Ref>) => {
3333
const apiRef = useRef<null | CoreChartAPI>(null);
3434

35-
// When visibleSeries and onChangeVisibleSeries are provided - the series visibility can be controlled from the outside.
35+
// When visibleSeries and onVisibleSeriesChange are provided - the series visibility can be controlled from the outside.
3636
// Otherwise - the component handles series visibility using its internal state.
37-
useControllableState(props.visibleSeries, props.onChangeVisibleSeries, undefined, {
37+
useControllableState(props.visibleSeries, props.onVisibleSeriesChange, undefined, {
3838
componentName: "CartesianChart",
3939
propertyName: "visibleSeries",
40-
changeHandlerName: "onChangeVisibleSeries",
40+
changeHandlerName: "onVisibleSeriesChange",
4141
});
4242
const allSeriesIds = props.series.map((s) => getOptionsId(s));
4343
// We keep local visible series state to compute threshold series data, that depends on series visibility.
@@ -46,7 +46,7 @@ export const InternalCartesianChart = forwardRef(
4646
const onVisibleSeriesChange: CoreChartProps["onVisibleItemsChange"] = (items) => {
4747
const visibleSeries = items.filter((i) => i.visible).map((i) => i.id);
4848
if (props.visibleSeries) {
49-
fireNonCancelableEvent(props.onChangeVisibleSeries, { visibleSeries });
49+
fireNonCancelableEvent(props.onVisibleSeriesChange, { visibleSeries });
5050
} else {
5151
setVisibleSeriesLocal(visibleSeries);
5252
}

src/cartesian-chart/interfaces.ts

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import { NonCancelableEventHandler } from "../internal/events";
77
// CartesianChartProps is the type for CartesianChart React component properties. Unlike in Highcharts API,
88
// we pass options directly to the component, instead of grouping them all into a single "options" property.
99
// We do still organize related options in groups, e.g.: "SeriesOptions", "TooltipOptions".
10-
export interface CartesianChartProps extends CoreTypes.BaseChartOptions, CoreTypes.CoreCartesianOptions {
10+
export interface CartesianChartProps
11+
extends CoreTypes.BaseChartOptions,
12+
CoreTypes.CoreCartesianOptions,
13+
CoreTypes.WithCartesianI18nStrings {
1114
/**
1215
* Inverts X and Y axes. Use it to show horizontal columns (bars).
1316
* This property corresponds to [chart.inverted](https://api.highcharts.com/highcharts/chart.inverted).
@@ -21,7 +24,7 @@ export interface CartesianChartProps extends CoreTypes.BaseChartOptions, CoreTyp
2124
stacking?: "normal";
2225

2326
/**
24-
* Chart series options.
27+
* Defines series options of the chart.
2528
* This property corresponds to [series](https://api.highcharts.com/highcharts/series), and extends it
2629
* with two additional series types: "x-threshold", and "y-threshold".
2730
*
@@ -39,31 +42,29 @@ export interface CartesianChartProps extends CoreTypes.BaseChartOptions, CoreTyp
3942
series: readonly CartesianChartProps.SeriesOptions[];
4043

4144
/**
42-
* Chart tooltip options.
43-
*
44-
* Supported options:
45+
* Defines tooltip options of the chart, including:
4546
* * `enabled` - (optional, boolean) - Hides the tooltip.
4647
* * `size` - (optional, "small" | "medium" | "large") - Specifies max tooltip size.
4748
* * `placement` - (optional, "middle" | "outside") - Specifies preferred tooltip placement.
4849
* * `point` - (optional, function) - Customizes tooltip series point rendering.
49-
* * `header` - (optional, function) - Provides a custom tooltip header.
50-
* * `body` - (optional, function) - Provides a custom tooltip content.
51-
* * `footer` - (optional, function) - Adds a tooltip footer.
50+
* * `header` - (optional, function) - Renders a custom tooltip header.
51+
* * `body` - (optional, function) - Renders a custom tooltip body.
52+
* * `footer` - (optional, function) - Renders a custom tooltip footer.
5253
*/
5354
tooltip?: CartesianChartProps.TooltipOptions;
5455

5556
/**
56-
* X-axis options.
57+
* Defines options of the chart's x axis.
5758
* This property corresponds to [xAxis](https://api.highcharts.com/highcharts/xAxis), and extends it
5859
* with a custom value formatter.
5960
*
6061
* Supported options:
6162
* * `title` (optional, string) - Axis title.
62-
* * `type` (optional, 'linear' | 'datetime' | 'category' | 'logarithmic') - Axis type.
63-
* * * linear - Uses continuous proportional values scale.
64-
* * * datetime - Similar to linear, but takes epoch time as values.
65-
* * * category - Uses discrete scale, requires `categories` to be set.
66-
* * * logarithmic - Uses continuous logarithmic values scale.
63+
* * `type` (optional, "linear" | "datetime" | "category" | "logarithmic") - Axis type.
64+
* * * "linear" - Uses continuous proportional values scale.
65+
* * * "datetime" - Similar to linear, but takes epoch time as values.
66+
* * * "category" - Uses discrete scale, requires `categories` to be set.
67+
* * * "logarithmic" - Uses continuous logarithmic values scale.
6768
* * `min` (optional, number) - Axis min value boundary.
6869
* * `max` (optional, number) - Axis max value boundary.
6970
* * `tickInterval` (optional, number) - Distance between axis ticks.
@@ -74,52 +75,49 @@ export interface CartesianChartProps extends CoreTypes.BaseChartOptions, CoreTyp
7475
xAxis?: CartesianChartProps.XAxisOptions;
7576

7677
/**
77-
* Y-axis options.
78+
* Defines options of the chart's y axis.
7879
* This property corresponds to [xAxis](https://api.highcharts.com/highcharts/yAxis), and extends it
7980
* with a custom value formatter.
8081
*
8182
* Supported options:
8283
* * `title` (optional, string) - Axis title.
83-
* * `type` (optional, 'linear' | 'datetime' | 'category' | 'logarithmic') - Axis type.
84-
* * * linear - Uses continuous proportional values scale.
85-
* * * datetime - Similar to linear, but takes epoch time as values.
86-
* * * category - Uses discrete scale, requires `categories` to be set.
87-
* * * logarithmic - Uses continuous logarithmic values scale.
84+
* * `type` (optional, "linear" | "datetime" | "category" | "logarithmic") - Axis type.
85+
* * * "linear" - Uses continuous proportional values scale.
86+
* * * "datetime" - Similar to linear, but takes epoch time as values.
87+
* * * "category" - Uses discrete scale, requires `categories` to be set.
88+
* * * "logarithmic" - Uses continuous logarithmic values scale.
8889
* * `min` (optional, number) - Axis min value boundary.
8990
* * `max` (optional, number) - Axis max value boundary.
9091
* * `tickInterval` (optional, number) - Distance between axis ticks.
9192
* * `categories` (optional, Array<string>) - Predefined list of values, used for categorical axis type.
9293
* * `reversedStacks` (optional, boolean) - Reverts series order in stacked series.
9394
* * `valueFormatter` (optional, function) - Takes axis tick as input and returns a formatted string. This formatter also
94-
* applies to the tooltip series value.
95+
* applies to the tooltip points values.
9596
*/
9697
yAxis?: CartesianChartProps.YAxisOptions;
9798

9899
/**
99-
* Specifies visible series by their IDs. When unset, all series are visible by default, and the visibility state
100-
* is managed internally by the component. When a series does not have an ID, its name is used instead.
101-
* When the property is provided, use `onChangeVisibleSeries` to manage state updates.
100+
* Specifies which series to show using their IDs. By default, all series are visible and managed by the component.
101+
* If a series doesn't have an ID, its name is used. When using this property, manage state updates with `onVisibleSeriesChange`.
102102
*/
103103
visibleSeries?: readonly string[];
104104

105105
/**
106-
* A callback, triggered when series visibility changes as result of user interacting with the legend or filter.
107-
*/
108-
onChangeVisibleSeries?: NonCancelableEventHandler<{ visibleSeries: string[] }>;
109-
110-
/**
111-
* An object that contains all of the localized strings required by the component.
112-
* @i18n
106+
* A callback function, triggered when series visibility changes as a result of user interaction with the legend or filter.
113107
*/
114-
i18nStrings?: CoreTypes.CartesianI18nStrings;
108+
onVisibleSeriesChange?: NonCancelableEventHandler<{ visibleSeries: string[] }>;
115109
}
116110

117111
export namespace CartesianChartProps {
118112
export interface Ref {
119-
// Controls series visibility that works with both controlled and uncontrolled visibility mode.
113+
/**
114+
* Controls series visibility and works with both controlled and uncontrolled visibility modes.
115+
*/
120116
setVisibleSeries(visibleSeries: readonly string[]): void;
121-
// Same as `setVisibleSeries`, but applies to all series and requires no series IDs on input. This is useful when
122-
// implementing clear-filter action in no-match state.
117+
/**
118+
* Functions similarly to `setVisibleSeries`, but applies to all series and doesn't require series IDs as input.
119+
* Use this when implementing clear-filter actions in no-match states.
120+
*/
123121
showAllSeries(): void;
124122
}
125123

0 commit comments

Comments
 (0)