Slicing

For styling only parts of a table novem offers a python inspired array slicing notation

The Novem slicing instruction is modelled on the python array slicing notation, but expanded with a few quality of life enhancements. The goal of slicing is to provide an easy way to subdivide the table for applying styles and formatting. The slicing operations always comes in a pair called a selector with one slice for the rows and one for the columns. Any styles using selectors will only be applied on the union of the slices.

In addition for the primary slicing function, we also allow the user to supply a comma separated list of indices starting at zero (negative indices are also supported).

Syntax

The novem slicing syntax is created to operate on sub section of tables, to do this we need two slices, one for rows and one for columns. These two slicers together is called a selector.

Slicer

The slicing operation consists of one or more integers separated by a colon :. The first number denotes the starting position (counting from zero), the second the ending position and the third the step (how many items to skip). The integer values can be skipped to indicate start of or end of range.

Selector

For a complete selector the slicer is repeated twice, once for rows and once for columns. The instructions are separated with a space so no space can be contained within a slice.

Below are a few examples of selectors along with some explanations.

-- select all rows and all columns
  :     :

-- select first row and all columns
 0      :

-- select last row and all columns
-1      :

-- select first three rows
 0:2    :   -- we use 2 ans that's the third element in a zero index

-- select last three rows
-1:-4   :

-- select a 3x3 matrix in the top left corner of the table
 0:2   0:2        
  :2    :2  -- the zero is implied if omitted

-- select every other row in the table
  ::2   : 

-- select the first and last row
0,-1    :

-- select row 4,5,6
3,4,5   :   -- remember zero index

Try it out

Below is a live example of the slicer grammar, feel free to play around with the example.

  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌
  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌
  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌
  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌
  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌
  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌
  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌
  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌
  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌
  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌
  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌
  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌
  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌
  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌
  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌  ‌   ‌   ‌
Row slicer:
Column slicer:

Examples

Below are a couple of examples showing how the slicer selection can be used to apply different styles to a novem table.

Slicers and steps

This example shows a static color pattern reminiscent of a picnic blanket using three shades of blue and setting the background color.

Here we use four selectors and take particular advantage of the step instructor. First we color alternating rows starting at different offsets. Then we add alternating columns, overwriting the colors.

text
/config/colors/colors
-- Create a "picnic blanket" using 4 shades of blue
 ::2  :     bg sta blue-100 -- color every other row starting at 0
1::2  :     bg sta blue-200 -- color every other row starting at 1
1::2 1::2   bg sta blue-300 -- color every other col starting at row 1 col 1
 ::2 1::2   bg sta blue-200 -- color every other row starting at row 0 col 1 

Index lists

Here we emulate a hierarchical structure in our table by coloring rows in descending shades of gray, a common strategy when wanting to preserve space.

Unlike in the picnic example above, here we use a comma separated list of rows to shade, this is because there is no geomteric pattern to the hierarchy, rather it depends on the data itself.

text
/config/colors/colors
-- Color rows by "hierarchy"
1           : bg sta gray-500 -- world
2,5,8       : bg sta gray-400 -- region 1
3,6,9,12,19 : bg sta gray-300 -- region 2