Added a disribution line.

This commit is contained in:
2026-02-25 00:00:46 -08:00
parent 0b42611b0d
commit 490b318a34

58
main.c
View File

@@ -2,7 +2,7 @@
// TODOS: //
// [X] Lower the the time text lower below the activity title. //
// [ ] On timeline, hower, display additional activity chunk info. //
// [ ] Display distribution timeline below the activity line. //
// [X] Display distribution timeline below the activity line. //
// [ ] Better file save error handling. //
//////////////////////////////////////////////////////////////////////////
@@ -17,7 +17,7 @@
#include <sys/stat.h>
#include <stdio.h>
#include <time.h>
#include "math.h"
#include <math.h>
#include "sourcecodepro.h"
#include "third_party/raylib/src/raylib.h"
@@ -136,7 +136,6 @@ Color activity_type_color_representation[activity_type_COUNT] = {
typedef struct activity {
activity_type type;
Color color;
U64 began;
U64 ended;
} activity;
@@ -167,7 +166,6 @@ void switch_activity(activity *activities, U32 *current_activity, activity_type
(*current_activity)++;
activities[*current_activity].type = type;
activities[*current_activity].color = activity_type_color_representation[type];
activities[*current_activity].began = time;
activities[*current_activity].ended = time;
}
@@ -238,21 +236,14 @@ FILE *load_activities(char *file_path, activity *activities, U32 *current_activi
continue;
activity_type type = other;
if(strcmp(activity_name, activity_type_string_representation[other]) == 0)
type = other;
else if(strcmp(activity_name, activity_type_string_representation[studying]) == 0)
type = studying;
else if(strcmp(activity_name, activity_type_string_representation[projects]) == 0)
type = projects;
else if(strcmp(activity_name, activity_type_string_representation[gaming]) == 0)
type = gaming;
else if(strcmp(activity_name, activity_type_string_representation[exercise]) == 0)
type = exercise;
else
continue;
for(U32 i = 0; i < activity_type_COUNT; i++) {
if(strcmp(activity_name, activity_type_string_representation[i]) == 0)
type = i;
else
continue;
}
activities[*current_activity].type = type;
activities[*current_activity].color = activity_type_color_representation[type];
activities[*current_activity].began = lower;
activities[*current_activity].ended = upper;
@@ -292,10 +283,12 @@ void save_activities(FILE *f, char *file_path, U32 current_activity, activity *a
int main(int argc, char *argv[])
{
// TODO: Move into global state.
activity activities[256]; // TODO: This should be a dynamic array.
memset(activities, 0, sizeof(activities));
U32 current_activity = 0;
// TODO: Move into global state.
Activity_Stat activities_stats[activity_type_COUNT];
memset(activities_stats, 0, sizeof(activities_stats));
@@ -305,6 +298,7 @@ int main(int argc, char *argv[])
char *dir_path = get_dir();
char *file_path = get_file(dir_path, t);
// TODO: Move into load_activities.
if(!is_directory(dir_path)) {
if(mkdir(dir_path, 0700) == -1) {
fprintf(stderr, "mkdir(%s) failed: %s\n", dir_path, strerror(errno));
@@ -339,7 +333,6 @@ int main(int argc, char *argv[])
// Initialize to default activity at the start.
activities[current_activity].type = other;
activities[current_activity].color = RED;
activities[current_activity].began = now();
activities[current_activity].ended = now();
@@ -373,7 +366,6 @@ int main(int argc, char *argv[])
current_activity = 0;
activities[current_activity].type = old_type;
activities[current_activity].color = activity_type_color_representation[old_type];
activities[current_activity].began = now();
}
@@ -393,31 +385,43 @@ int main(int argc, char *argv[])
activities[current_activity].ended = now_s;
U64 total_seconds = 0;
for(U32 i = 0; i <= current_activity; i++) {
U64 difference = activities[i].ended - activities[i].began;
activities_stats[activities[i].type].total_seconds += difference;
total_seconds += difference;
}
BeginDrawing();
ClearBackground(BLACK);
F32 padding_x = 10.0f;
// F32 padding_y = 10.0f;
DrawRectangle(0, 0, state.window_w, 40, GRAY);
for(U32 i = 0; i <= current_activity; i++) {
F32 start_x = floor((F32)(activities[i].began - lower_bound_s) / (F32)(upper_bound_s - lower_bound_s) * (F32)(state.window_w));
F32 end_x = floor(((F32)(activities[i].ended - lower_bound_s) / (F32)(upper_bound_s - lower_bound_s)) * (F32)(state.window_w));
DrawRectangle(start_x, 0, end_x - start_x, 40, activities[i].color);
DrawRectangle(start_x, 0, end_x - start_x, 40, activity_type_color_representation[activities[i].type]);
}
DrawRectangle(0, 40, state.window_w, 40, GRAY);
F32 last_x = 0.0f;
for(U32 i = 0; i <= activity_type_COUNT; i++) {
F32 ratio = (F32)(activities_stats[i].total_seconds) / (F32)total_seconds;
F32 x = ((F32)(state.window_w) * ratio);
DrawRectangle(last_x, 40, x, 40, activity_type_color_representation[i]);
last_x += x;
}
F32 width = (state.window_w-padding_x*(float)(activity_type_COUNT+1)) / (float)activity_type_COUNT;
for(U32 i = 0; i <= current_activity; i++) {
activities_stats[activities[i].type].total_seconds += activities[i].ended - activities[i].began;
}
for(U32 i = 0; i < activity_type_COUNT; i ++) {
Hours time = break_time(activities_stats[i].total_seconds);
snprintf(activities_stats[i].seconds_str, sizeof(activities_stats[i].seconds_str), "%02llu:%02llu:%02llu", time.hours, time.minutes, time.seconds);
Rectangle rect = { (padding_x*(i+1))+(width*i), 60, width, (state.window_h-70) };
Rectangle rect = { (padding_x*(i+1))+(width*i), 100, width, (state.window_h-110) };
if(activity_button(rect, activity_type_string_representation[i], activities_stats[i].seconds_str, state.font_size, (activities[current_activity].type == i ? WHITE : BLACK), activity_type_color_representation[i])) {
if(activities[current_activity].type != i) {
switch_activity(activities, &current_activity, i, now_s);