Lenses are a core feature of Knarr. They are designed to allow you to filter data in complex ways so you can quickly and easily see relationships and associations without writing any code.
Lenses can be accessed either from the left-side filter pane, or from the full-screen filter panel. To lens a field, click the camera lens icon on the top right of the field box:
Lenses typically work best with fields that have a large number of values that you are looking to filter using other fields. For example, let’s say you were interested in finding all of the people (the Name field) who have won a gold Medal. Simply click on the lens icon, click “association”, choose the “Medal” field, and type in “Gold”, like so:
This is a simple example, and you could have gotten to this result with a simple filter, of course. Where lenses become more powerful is when you start stacking them on top of one another. For example, let’s say you wanted to see everyone who won a gold medal but didn’t win a Silver medal - that one would be tough to filter on, but with lenses, it’s simple:
Note that to find something that is not associated, simply click the “swap” icon next to the eye and you will get a nonassociation.
Finding the top items in any category is simple; just add a “top” lens to the field for which you’d like to find the top values by a metric. In this example, we’re trying to find the top 5 Names by how many medals they’ve won:
You can use the “for each” toggle to find top values across another field. For example, I can count the top 5 Names for each Sex, in the case of this dataset only 2 values exist in the Sex field, so I can see 10 Names appear (top 5 by count of medal across 2 Sexes):
The “eye” icon allows you to hide that piece of the lens, so you can quickly toggle a lense on or off to see how it affects the field you are lensing.
Once you have a lens you like, click the “apply” button to select the values in your lensed field.
Lenses respect previously-made selections as well, so if you have a series of selections made, any lens you create will lens the remaining data. This can get confusing, especially if you’re using “top” and “for each”, so make sure you always understand what you have selected.