agateblue / tempo

Your personal diary and mood tracker
GNU Affero General Public License v3.0
106 stars 12 forks source link

Documentation #37

Closed dskrad closed 1 year ago

dskrad commented 2 years ago

I was hoping you could add some documentation (to the readme file?) regarding how to use blueprints to visualize data.

For example, you show a little bit how you can use @ labels to document data points (lab values, weight, etc) , but I cannot figure out how to visualize that data on the graph section.

Thanks.

agateblue commented 2 years ago

Hi @dskrad, thank you for opening the issue. Until this is properly documented, you can find below a custom blueprint I have that includes visualizations:

{
  "id": "agate:travel",
  "label": "Travel",
  "title": "Forms and visualizations for your trips",
  "version": "1",
  "fields": [
    {
      "id": "travel:distance",
      "label": "Distance",
      "unit": "Kilometers",
      "type": "number",
      "min": 0
    },
    {
      "id": "travel:from",
      "label": "Place of departure",
      "type": "text"
    },
    {
      "id": "travel:to",
      "label": "Destination",
      "type": "text"
    },
    {
      "id": "travel:by",
      "label": "Transport",
      "type": "text"
    }
  ],
  "forms": [
    {
      "id": "travel:trip",
      "label": "Trip",
      "fields": [
        {
          "id": "travel:from"
        },
        {
          "id": "travel:to"
        },
        {
          "id": "travel:distance"
        },
        {
          "id": "travel:by"
        }
      ]
    }
  ],
  "visualizations": [
    {
      "label": "Travel distance",
      "help": "In kilometers",
      "query": "SELECT date, sum(CASE WHEN data->`travel:distance` > 0 THEN data->`travel:distance` ELSE 0 END) as Distance FROM ? GROUP BY date ORDER BY date DESC",
      "displayType": "bar",
      "displayOptions": {
        "colors": [
          "green"
        ]
      }
    },
    {
      "label": "Means of transportation",
      "help": "In kilometers",
      "query": "SELECT data->`travel:by`, sum(data->`travel:distance`) as Distance FROM ? GROUP BY data->`travel:by` ORDER BY date DESC",
      "displayType": "pie",
      "displayOptions": {}
    },
    {
      "label": "Travels by distance and destination",
      "help": "In kilometers",
      "query": "SELECT data->`travel:from` as `From`, data->`travel:to` as `To`, sum(data->`travel:distance`) as Distance FROM ? GROUP BY data->`travel:from`, data->`travel:to` ORDER BY Distance DESC",
      "displayType": "table",
      "displayOptions": {}
    }
  ]
}

Hopefully, it can help you getting started.