Command Palette

Search for a command to run...

Hectal
Phase 17: Storytelling and Scrollytelling
Data Visualization · Exercise 2 of 6 PreviousNext
Intermediate

Flip the label near the edge

labelSide(pointX, textWidth, chartWidth) decides whether a label goes to the right or the left of its point. It always says "right", so labels near the right edge run off the chart.

Return "left" when pointX + 8 + textWidth would be wider than chartWidth - 4. Otherwise return "right".

What Check tests

  1. A point far from the edge gets a label on the right
  2. A point near the right edge gets a label on the left
  3. A label that fits exactly stays on the right

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Console

Nothing printed yet.