PDFPipe

Numbers, tables and totals / Risk matrix grid

A risk matrix that survives being printed in black and white

A likelihood by consequence grid with cells scored and coloured, used in method statements, assessments and permits.

Why this block is harder than it looks

A risk matrix conveys almost all of its meaning through colour, and colour is the least reliable thing in a printed document. Print backgrounds are frequently disabled, and even when they are not, a matrix printed on a monochrome device becomes five shades of grey that are hard to distinguish and impossible to name. The second problem is size: a five-by-five grid with readable labels is wider than most people expect, so it gets shrunk until the axis labels are illegible, which removes the other half of the meaning.

The decisions that make it work

Reasons rather than a description of the code. Each of these is a choice that has a wrong answer, and the wrong answer is usually the default.

  • Put the score in every cell as a number, so the grid is readable with no colour at all. Colour then reinforces the number instead of carrying it.
  • Add a pattern or a border weight per band as well as a fill, so the bands remain distinguishable in greyscale.
  • Set print-color-adjust: exact on the cells. Without it the fills are the first thing a print pipeline drops.
  • Give the axes real labels rather than numbers alone, and rotate the vertical axis label rather than stacking single letters.
  • Size the grid in millimetres with square cells. A matrix whose cells are not square reads as though the two axes carry different weight.
  • Keep the legend beside the grid rather than below it, so the grid and its key are in one glance and one avoid container.

The fragment

Markup and the CSS it needs, and nothing else. It expects a document that already has a page rule and a base stylesheet, so paste it into one rather than opening it on its own.

html
<table class="risk">
  <tr><th></th><th>Minor</th><th>Moderate</th><th>Major</th></tr>
  <tr><th>Likely</th>
      <td class="b3">6</td><td class="b4">9</td><td class="b5">12</td></tr>
  <tr><th>Possible</th>
      <td class="b2">4</td><td class="b3">6</td><td class="b4">9</td></tr>
  <tr><th>Rare</th>
      <td class="b1">2</td><td class="b2">4</td><td class="b3">6</td></tr>
</table>

<style>
  .risk {
    break-inside: avoid;
    border-collapse: collapse;
    font-size: 9pt;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
  .risk th { padding: 3pt 6pt; font-weight: 600; text-align: right; }
  .risk td {
    width: 18mm; height: 18mm;        /* square, in real units */
    text-align: center;
    vertical-align: middle;
    border: 0.5pt solid #fff;
    font-weight: 700;
  }
  /* fill plus a border weight, so the bands survive greyscale */
  .risk .b1 { background: #eceae4; }
  .risk .b2 { background: #ddd8cc; }
  .risk .b3 { background: #c9bfa8; border-width: 1pt; }
  .risk .b4 { background: #d98a6a; border-width: 1.5pt; }
  .risk .b5 { background: #d23a1d; color: #fff; border-width: 2pt; }
</style>

What breaks when it is built the obvious way

Leaving the cells blank and relying on the fill alone. It is the version that looks best on screen and the version that conveys nothing on a photocopy, which is how a method statement is usually read on site.

How to prove it survived pagination

Print the page in black and white and ask somebody to name the highest-scoring cell. If they can, the numbers are doing the work. Then measure a cell on the paper: if it is not square, the sizing is relative to something it should not be.

Where it sits in a finished document

This page is one block. The document it belongs to has a page rule, a base stylesheet, a header and everything else around it, and repeating all of that here would make thirty pages that say the same thing. The hot work permit template is a complete file with this block already in it, so take that and change the fragment rather than assembling one from parts. The property doing most of the work here is covered on its own page, with the support caveats that belong there rather than here.

Frequently asked

Will this fragment work on its own?

Not as a whole document. It has no page rule, no margins and no base type, because those belong to the document rather than to the block, and duplicating them in every fragment would mean thirty copies to keep in step. Paste it into a template that already has them.

Why does it look right in a browser and wrong in the PDF?

Because a browser window is one continuous surface and a document is a stack of fixed rectangles. Nothing in a scrolling view exercises a page boundary, so every break rule in the fragment is inert until the content is paginated. Render the real thing with enough content to cross two or three boundaries, then look.

Do I need a special option on the render request for this?

No. Everything on this page is CSS and markup, which is your side of the boundary. What the render has to give you is a real page size with real margins, and after that the layout is decided by the stylesheet.

Other parts of a document

The blocks that sit next to this one, and one from the next group along so you are not sealed inside a single kind of problem.

Paste the fragment into the playground inside a page rule and see what it does at a real page size. That is the only way any of this gets confirmed.