Photo by Patrick Fore on Unsplash

As a former Sketch user, I’m still figuring out the way of doing things.

Where as before with Sketch, my first move would be to search for a plugin, (I’m starting to think all those plugins made me lazy?) now I have to build most things from the ground up.

Most recently, this meant slaying every designer’s favorite demon — the tasty chart.

I’m not going to debate the utility of donut here. (As a quick aside, I will say they’re a big step up from pie since you can compare length instead of angle.) This post is really a how-to for creating donut charts in Figma the right way.

Dirty donuts

There are already a few tutorials out there for tackling these gnarly little graphs. The method employed in these examples is quick and dirty — perfect if you’re just trying to placehold a chart in your layout.

  1. Start with a rectangle, cut it into a few parallelograms with a common point at the center.
  2. Boolean exclude a circle out of the center of the parallelogram group.
  3. Mask the whole thing with another circle to finish the donut shape.
One fast and filthy donut

Unfortunately, the charts produced with this method are best used as a one-off, not a library component. They are difficult to edit after the fact and do not accurately render the miter angles and relationships in the graph. What happens if I need to add another section to the graph? How do I rejigger the size relationships? Almost immediately, these sort of edits become untenable.

If you’re in a role like our team, where data visualization is actually our core mission, then you’ll need a graph component that is both accurate and flexible. We don’t want to redraw a chart for every configuration our use cases demand.

We need our donut component to support a few essential functions:

  • Adjust the position of segments around the chart.
  • Adjust the arc length of each segment.
  • Easily add/remove segments.

A tastier recipe

To make a truly flexible donut chart, I really had to figure out how to make an editable arc segment.

Figma doesn’t allow you to edit the arc length of a curve (yet). So, I knew the only way to fake this effect would be through rotation.

I worked backwards from the core shape of our graph — a circle. I cut the circle in half so that it could visibly rotate. To get the semicircle to rotate around the center of the graph, I added an empty bounding box rectangle. Finally to simulate the effect of growing arc length from an origin point, I masked one side of the graph. Now, the semicircle seemed to rotate into view.

Impressive, right?

By then subtracting a smaller circle from inside the semicircle, I had something close to the segment effect I needed. Unfortunately, it only worked on one side of the graph. The segment could only ever show a value of 50% or less.

The simple solution was to stop trying to make a whole segment from beginning to end, and instead build it out from the middle.

I duplicated and flipped the first group so that now I had two 180 degree arc segments: one for the start of the graph segment and one for the end. Now, I can rotate each in opposite directions to fill the donut.

One successful donut segment!

From there, it’s pretty trivial to duplicate and adjust the segments to create a full graph.

Fresh donut, with sprinkles

All editing of the graph is done through rotation only. To edit any segment, you rotate the entire segment group (both beginning and end) to position it around the graph. Then, you rotate the start segment and/or end segment to adjust the arc length of the segment.

It can be challenging to describe this design process in words, so if you’d like to play with this graph you can try it here:

Chart Tutorial on Figma

Feel free to use it in your own projects. Any and all improvements are welcome!


Source link


Please enter your comment!
Please enter your name here