Last, next month. Blue.

This commit is contained in:
Neil 2023-05-12 22:25:58 -07:00
parent 45c667cdda
commit d46b5b4d4d
3 changed files with 16 additions and 5 deletions

View File

@ -20,6 +20,8 @@ union line64 {
#define TREE_HEAD
#include "../src/tree.h"
union date32 date32_last_month(union date32 d);
union date32 date32_next_month(union date32 d);
#include "text.h"
struct journal { struct day_tree days; struct char_array backing; };
struct journal_iterator { struct day_tree_iterator _; };

View File

@ -17,6 +17,16 @@
#include <sys/stat.h> /* umask (POSIX) */
#include <dirent.h> /* opendir readdir closedir */
union date32 date32_last_month(union date32 d) {
if(d.month <= 1) d.month = 12, d.year--;
else d.month--;
return d;
}
union date32 date32_next_month(union date32 d) {
if(d.month >= 12) d.month = 1, d.year++;
else d.month++;
return d;
}
/* Day tree-map from date to pointer; is backed by a huge array of text. */
void date32_to_string(const union date32 d, char (*const a)[12]) {
sprintf(*a, "%" PRIu32 "-%2.2" PRIu32 "-%2.2" PRIu32,

View File

@ -1377,16 +1377,15 @@ void scan_dream_graph(struct scan *const scan) {
printf("%" PRIu32 "-%.2" PRIu32 ", %zu\n",
accum.date.year, accum.date.month, accum.count);
/* If we skip a month, output zero as dummy. */
union date32 next = { .u32 = accum.date.u32 + 32 };
const union date32 next = date32_next_month(accum.date);
if(next.u32 < now.u32) {
printf("%" PRIu32 "-%.2" PRIu32 ", 0\n",
next.year, next.month);
/* Skip more than a month, place dummy output on both. */
union date32 last = { .u32 = now.u32 - 32 };
const union date32 last = date32_last_month(now);
if(next.u32 < last.u32)
printf("%" PRIu32 "-%.2" PRIu32 ", 0\n",
last.year, last.month);
/* fixme: this will not work because it's not packed. */
}
}
accum.date = now;
@ -1406,8 +1405,8 @@ void scan_dream_graph(struct scan *const scan) {
"set timefmt \"%%Y-%%m\"\n"
"set format x \"%%Y-%%m\"\n"
"set style fill transparent solid 0.3\n"
"set ylabel \"remembered dreams binned by month\"\n"
"\n"
"plot $Data using 1:2 with boxes notitle\n" /*lc rgb "blue"?*/);
"plot $Data using 1:2 with boxes notitle lc rgb \"blue\"\n");
fprintf(stderr, "\n");
}