Skip to content

Commit b0daa3a

Browse files
ryugarajRaj Jaiswal
andauthored
fix: handle undefined series during re-renders (#139)
Co-authored-by: Raj Jaiswal <[email protected]>
1 parent af2dcf8 commit b0daa3a

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/core/chart-api/chart-extra-tooltip.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ class HighlightCursorCartesian {
186186

187187
public create(target: Rect, point: null | Highcharts.Point, group: readonly Highcharts.Point[], showLine: boolean) {
188188
this.hide();
189+
if (!group[0]?.series) {
190+
return;
191+
}
192+
189193
const chart = group[0]?.series.chart;
190194
if (!chart) {
191195
return;

src/core/components/core-tooltip.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ export function ChartTooltip({
5757
const tooltip = useSelector(api.tooltipStore, (s) => s);
5858
const debouncedTooltip = useDebouncedValue(tooltip, debounce === true ? DEFAULT_DEBOUNCE : debounce || 0);
5959

60-
if (!debouncedTooltip || !debouncedTooltip.visible || debouncedTooltip.group.length === 0) {
60+
if (
61+
!debouncedTooltip ||
62+
!debouncedTooltip.visible ||
63+
debouncedTooltip.group.length === 0 ||
64+
debouncedTooltip.group[0].series === undefined
65+
) {
6166
return null;
6267
}
6368

src/core/utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ export function getLegendsProps(
269269
// There are differences in how the rectangle is computed, but in all cases it is supposed to
270270
// enclose the point's visual representation in the chart, with no extra offsets.
271271
export function getPointRect(point: Highcharts.Point): Rect {
272+
if (!point.series) {
273+
return { x: 0, y: 0, width: 0, height: 0 };
274+
}
275+
272276
switch (point.series.type) {
273277
case "column":
274278
return getColumnPointRect(point);
@@ -283,7 +287,7 @@ export function getPointRect(point: Highcharts.Point): Rect {
283287
// which includes all given points, but also stretched vertically or horizontally (in inverted charts)
284288
// to the entire chart's height or width.
285289
export function getGroupRect(points: readonly Highcharts.Point[]): Rect {
286-
if (points.length === 0) {
290+
if (points.length === 0 || !points[0].series) {
287291
return { x: 0, y: 0, width: 0, height: 0 };
288292
}
289293
const chart = points[0].series.chart;

0 commit comments

Comments
 (0)