What the diagram shows. Each box is one orbital, and each arrow is one electron; the direction of the arrow shows its spin. Boxes are arranged up an energy axis, so a box higher on the page is an orbital of higher energy. The axis is schematic rather than to scale: the real gap between the 1s and 2s levels is many times larger than any gap above it, and the diagram compresses this so that everything fits on one page.
How the electrons go in. Electrons occupy the lowest-energy orbital available (the Aufbau principle), each orbital holds at most two electrons and these must have opposite spins (the Pauli principle), and where several orbitals share an energy, the electrons spread out one per orbital with parallel spins before any of them pair up (Hund's rule). The order of filling is 1s, 2s, 2p, 3s, 3p, 4s, 3d, 4p.
4s and 3d. Potassium and calcium put their outer electrons into 4s rather than 3d, so while 3d is empty the diagram draws 4s below it. Once 3d holds any electrons, however, it is the 3d level that lies lower, and the diagram moves it below 4s. This matters for ions: the 4s electrons are then the highest in energy, so a transition metal loses them first. Fe²⁺ is 3d⁶, not 3d⁴ 4s². The simulation removes electrons from the highest occupied shell first (4p, then 4s, then 3d) and adds extra electrons to the lowest vacancy.
Chromium and copper. These two do not follow the simple pattern: chromium is 3d⁵ 4s¹ rather than 3d⁴ 4s², and copper is 3d¹⁰ 4s¹ rather than 3d⁹ 4s². The 4s and 3d levels are so close in energy for these atoms that the extra repulsion of pairing two electrons in the compact 4s orbital tips the balance. Their ions follow the usual rule of losing 4s first, which is why Cu⁺ is 3d¹⁰ and Cr³⁺ is 3d³.
Notation. Configurations are written in order of shell number, with 3d before 4s, which is the convention on most UK A-level courses. The shorthand form replaces the filled shells of the previous noble gas with its symbol in square brackets. The simulation stops at krypton, the last element whose configuration needs no more than the 4p subshell.