Tinderbox Forum

Timelines: automatic mapping of timeline labels & band allocations

Background. Say you’re using a Tinderbox timeline view with notes separated onto separate bands. This throws up a number of ongoing management tasks:

  • You want to set notes to a band based on a ‘tag’ (in the general sense) that matches with, or maps to a band label.
  • You want to change the order of the bands or the band label.

Here are a pair of code snippets to help with this. Some assumptions first:

  • You have a note with the unique $Name ‘Config’, where we’ll store the look-up list. If you already have such a note for other purposes, by all means change the code to use that note.
  • References to ‘My-’ attributes, MyList, MyString, etc. simply imply an attribute of that data type. You can use the code as it is, or insert suitably-type attributes of your own.

Why a stamp and not a rule? You can use what you want, but I’d argue a rule is just running code you don’t need always on. If you’re worried about forgetting, use an edict.

Code 1. This is applied to the container holding the timeline view and where the view’s per-band labels are defined:

var vOffset(0);
  $MyList = $MyList + (aLabel + ":" + vOffset);
  vOffset = vOffset + 1;
$MyList("Config") = vList;

Code 2. Only then do you use the second code on the notes in the timeline itself , i.e. not the one stamped above:

$TimelineBand = $MyList("Config").lookup($MyString);

Note, when v9 comes out we will be able to use the new ‘Dictionary’ type attribute for the look-up process making it a bit neater. I’ll update this when v9 comes around.


I’ve updated the above as some users were having problems with the variables not populating properly.

In case the the MyList references are confusing, I’ll explain. In Stamp #1, we build the look-up list in the stamped note’s MyList. After the loop runs, we stored the result in a note called “Config”. At start and end of the stamp we reset the stamped notes MyList attribute to the default value (and empty list). This ensures we don’t keep interim data data for the long term.

† We don’t have to store the look-up list in a separate note. WE could store it in the current note, in which case the last part of code 1 becomes this:


i.e., once the loop is run the look-up is made: done! The last two lines of code above are not needed. But, remember to edit code 2 to use the name of the timeline container to find the look-up list.

1 Like