Skip to content

Instantly share code, notes, and snippets.

@victorouse
Created May 4, 2020 02:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorouse/e9396b970869cf94d1c845f59f58d43e to your computer and use it in GitHub Desktop.
Save victorouse/e9396b970869cf94d1c845f59f58d43e to your computer and use it in GitHub Desktop.

Charts

Requirements

  • Render a pie chart
  • Render labels (either inside or outside the pie - inside labels can be problematic with small slices + potentially render SVGs for the labels
  • On hover event handlers
  • Render a gap between the active "slice" and the rest of the pie chart
  • Grow the active slice larger than the existing slices
  • Typescript

Nice to haves

  • Ergonomic API: balance between low level primitives and high level abstractions (make it easy, but don't lose flexibility)
  • Composable API: enable flexibility to compose different chart elements together (pie slices, labels, legends, etc.)
  • Component API: uses components rather than wrapping an options object than spits out a graph to a dom node
  • SVG-backed implementation: canvas graphing libraries more often than not, suck

Disqualified

  • React-vis
  • Nivo
    • onMouseEnter / onMouseLeave properties not exported in Typescript definitions (plouc/nivo#724)
  • ChartJS
    • Honestly, this API is just incredibly cumbersome and it uses canvas as well - the react wrapper for this lib leaves a lot to be desired..

Comparisons / thoughts:

Recharts

Pros

  • API is very simple
  • API is easily composable (all chart elements are children of the parent chart)

Cons

  • Sometimes math is required (radians, angles, calculating radii, label placement)
  • API docs are okay, but could use a lot more context

Victory

Pros

Cons

  • onMouse events are incredibly flexible but can be difficult to reach into to figure out
  • Generally less composable, end up with fat components and only the surface API to configure

VX

Pros

  • Incredibly flexible and composable, mostly helpers around low-level svg primitives - can pretty much make anything with this

Cons

  • Docs are incredibly lacking
  • Maybe too low level to be ergonomic
  • Sometimes math

Screenshots

Recharts

image

Victory

image

VX

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment