plouc / nivo

nivo provides a rich set of dataviz components, built on top of the awesome d3 and React libraries
https://nivo.rocks
MIT License
13.11k stars 1.03k forks source link

Line Graph - Cannot read from undefined property (reading 'x') when useMesh is enabled. #2630

Open rob-cleeia opened 1 month ago

rob-cleeia commented 1 month ago

Describe/explain the bug We're using Nivo/Line (responsive) to render some line graphs. The data we use is nondeterministic, so we validate the data before we send it to the graph. Based on the documentation (here: https://nivo.rocks/line/), we use the following type for line graph data:

interface line {
    id:   string | number;
    data: {
        x: number | string | Date
        y: number | string | Date
    }[]
}[]

However, we've recently noticed that if we have the x axis as a number and the y axis as a string, with useMesh enabled, it throws a client side exception.

To Reproduce Render a Nivo/Line Graph with useMesh enabled, with data containing x axis as a number, and y axis as a string. EG:

import React from 'react';
import { ResponsiveLine } from '@nivo/line';

export const LineGraph: React.FC = () => (
  <div style={{ height: '20rem' }}>
    <ResponsiveLine
      data={[
        {
          id: '1',
          label: 'Joe Biden',
          data: [
            {
              x: 1973,
              y: 'Senator',
            },
            {
              x: 2009,
              y: 'Vice President',
            },
            {
              x: 2017,
              y: 'End of Vice Presidency',
            },
            {
              x: 2021,
              y: 'President',
            },
          ],
        },
      ]}
      useMesh
    />
  </div>
);
export default LineGraph;

Steps to reproduce the behaviour:

  1. Load above component.
  2. Hover mouse over Line Graph

Expected behaviour Should not cause a client side error.

Screenshots Chrome: Screenshot 2024-08-08 at 12 00 12 FireFox: Screenshot 2024-08-08 at 12 02 56

Desktop (please complete the following information - Not sure if this at all relevant, but okay):

Additional context