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

Fixes RadarChart axes (#796) #842

Merged
merged 1 commit into from
Jun 27, 2018
Merged

Fixes RadarChart axes (#796) #842

merged 1 commit into from
Jun 27, 2018

Conversation

NoobCIT
Copy link
Contributor

@NoobCIT NoobCIT commented Jun 27, 2018

I ran into the same issue (#796). The RadarChart axes does not show or is displayed incorrectly (ex. wrong number of ticks) depending on what the startingAngle is. Rotating your graph a certain degree can cause these problems, because JavaScript's trigonometric functions (ex. Math.sin & Math.cos) can return numbers with floating point errors (see table below). These floating point numbers can cause calculation errors.

Trig Function Angle JavaScript Value True Value
sin PI 1.2246467991473532e-16 0
cos PI/3 0.5000000000000001 0.5

Shown below is what I used for my RadarChart.

class App extends Component {
  render() {
    const RADAR_PROPS = {
      data: [{
        C: 30,
        VisualBasics: 60,
        Excel: 40,
        Access: 40
      }],
      domains: [
        {name: 'C', domain: [0, 100]},
        {name: 'VisualBasics', domain: [0, 100]},
        {name: 'Excel', domain: [0, 100]},
        {name: 'Access', domain: [0, 100]}
      ],
      height: 300,
      width: 400,
    };
    return (
      <div>
        <RadarChart
          data={RADAR_PROPS.data}
          domains={RADAR_PROPS.domains}
          height={RADAR_PROPS.height}
          width={RADAR_PROPS.height}
          startingAngle={Math.PI/4}
          className='overflow-okay horizontally-centered'
          style={{
              labels: {
                  fontSize: 13
              },
              polygons: {
                  fillOpacity: 0.1,
                  strokeOpacity: 1,
                  strokeWidth: 0.5,
              },
          }}
        />
      </div>
    );
  }
}

For the src/utils/axis-utils.js, I wanted to make sure the axes displayed the correct number of ticks, because there could be cases where maybe more ticks would be generated than what was specified. Let me know what you think. Thanks.

The RadarChart axes does not show or is displayed incorrectly
(ex. wrong number of ticks) depending on what the startingAngle is.
Rotating your graph a certain degree can cause these problems,
because JavaScript's trigonometric functions (ex. Math.sin & Math.cos)
can return numbers with floating point errors, ex. sin(pi) is zero. But
JavaScript may return a floating point number very close to zero which
can cause calculation errors to occur in displaying axes.
@jckr
Copy link
Contributor

jckr commented Jun 27, 2018

thanks @NoobCIT !

@jckr jckr merged commit 7e2b386 into uber:master Jun 27, 2018
@mcnuttandrew
Copy link
Contributor

mcnuttandrew commented Jun 27, 2018

I actually would like to see a follow up to this with some tests, there's some behavior in there that i'm not 100% sure about.

  • I get that you are basically just doing rounding, but could you do it more explicitly?
  • It's not clear that this change in functionality addresses the issue, would you mind writing a test to reproduce the described issue so we don't back slide in future iterations?

@NoobCIT
Copy link
Contributor Author

NoobCIT commented Jun 27, 2018

@mcnuttandrew , yeah I'll look into it.

@NoobCIT NoobCIT deleted the radar-chart-axes branch June 28, 2018 17:39
ayarcohaila pushed a commit to ayarcohaila/react-vis that referenced this pull request Jun 30, 2021
The RadarChart axes does not show or is displayed incorrectly
(ex. wrong number of ticks) depending on what the startingAngle is.
Rotating your graph a certain degree can cause these problems,
because JavaScript's trigonometric functions (ex. Math.sin & Math.cos)
can return numbers with floating point errors, ex. sin(pi) is zero. But
JavaScript may return a floating point number very close to zero which
can cause calculation errors to occur in displaying axes.
ayarcohaila added a commit to ayarcohaila/react-vis that referenced this pull request May 30, 2023
The RadarChart axes does not show or is displayed incorrectly
(ex. wrong number of ticks) depending on what the startingAngle is.
Rotating your graph a certain degree can cause these problems,
because JavaScript's trigonometric functions (ex. Math.sin & Math.cos)
can return numbers with floating point errors, ex. sin(pi) is zero. But
JavaScript may return a floating point number very close to zero which
can cause calculation errors to occur in displaying axes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants