Charts
Measuring the camera behind Office's 3D pie charts
Office never says how it draws a 3D pie. But its PDFs contain the picture, and a picture of a cylinder gives away the camera that took it.
Love them or hate them, 3D pie charts are everywhere in real documents. The file only stores a few settings: tilt, rotation, perspective, height as a percent. How Office turns those into a picture isn't written anywhere.
When Office exports a 3D chart to PDF, it draws the 3D part as an image, with the labels and ticks as normal vector text on top. So I have pictures of a lot of pies, at every setting real documents use.
A pie is a cylinder
A pie chart in 3D is just a short cylinder cut into slices. And a cylinder seen by a camera has a few points you can find in a picture: the far edge of the top, the centre, the near edge, the bottom edge below it.
From those four points, across many charts, the camera falls out:
- Height: 0.243 × the radius × the height percent.
- Tilt: the stated angle, minus 0.53, minus 0.001 × the perspective squared.
- Distance: 2.08 + 0.756 / tan(perspective / 2) radii from the centre.
- Size: 0.971 × the room available, plus 2.6 pt, and 0.85 of that if labels might go outside.
Nobody chose these numbers on purpose, probably. They're what falls out of Office's real camera code. But with them, the pies land on Office's pies.
The light is fixed too
The shading of 3D shapes in charts isn't real lighting. It's fixed amounts per face:
- front: 100% of the colour
- top: 75%
- side: 63.5%
The same at every angle. The curved wall of a pie slice follows a simple formula of the angle you're looking from. And the cut faces of a slice are lit from the opposite side to the rim.
Flat charts have rules too
The same method worked for ordinary charts: read Office's PDFs, find the pattern. A few I like:
- The axis picks steps of 1, 2 or 5 × a power of ten, the finest that keeps the labels from overlapping.
- The axis starts at zero unless the spread is small compared to the maximum (less than a sixth).
- Percent labels in a pie always add up to exactly 100, rounding the largest remainders up, with later slices winning ties.
- Files saved by Office 2007 read missing settings as "off". Every other version reads them as "on".
That last one explains a whole class of "why does this old chart look different" bugs.