Skip to content

Commit

Permalink
handle empty journal
Browse files Browse the repository at this point in the history
fixes #154
  • Loading branch information
ananthakumaran committed Jan 21, 2024
1 parent 10eb989 commit f2274d1
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/lib/allocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,13 @@ export function renderAllocationTimeline(
assets,
_.map(assets, () => 0)
);
const start = timeline[0][0].timestamp,
const start = timeline[0]?.[0]?.timestamp,
end = now();

if (!start) {
return [];
}

interface Point {
date: dayjs.Dayjs;
[key: string]: number | dayjs.Dayjs;
Expand Down
16 changes: 13 additions & 3 deletions src/lib/expense/monthly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
type Legend
} from "$lib/utils";
import COLORS, { generateColorScheme, white } from "$lib/colors";
import { get, type Readable, type Writable } from "svelte/store";
import { get, type Readable, type Unsubscriber, type Writable } from "svelte/store";
import { iconify } from "$lib/icon";
import { byExpenseGroup, expenseGroup, pieData } from "$lib/expense";

Expand Down Expand Up @@ -133,7 +133,11 @@ export function renderMonthlyExpensesTimeline(
groupsStore: Writable<string[]>,
monthStore: Writable<string>,
dateRangeStore: Readable<{ from: Dayjs; to: Dayjs }>
) {
): {
z: d3.ScaleOrdinal<string, string, never>;
destroy: Unsubscriber;
legends: Legend[];
} {
const id = "#d3-monthly-expense-timeline";
const timeFormat = "MMM-YYYY";
const MAX_BAR_WIDTH = rem(40);
Expand All @@ -158,7 +162,13 @@ export function renderMonthlyExpensesTimeline(
const [start, end] = d3.extent(_.map(postings, (p) => p.date));

if (!start) {
return { z: z };
return {
z: z,
destroy: () => {
// void
},
legends: []
};
}

const ms = _.groupBy(postings, (p) => p.date.format(timeFormat));
Expand Down
8 changes: 8 additions & 0 deletions src/lib/income.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ export function renderYearlyIncomeTimeline(yearlyCards: IncomeYearlyCard[]): Leg
const start = _.min(_.map(yearlyCards, (c) => c.start_date)),
end = _.max(_.map(yearlyCards, (c) => c.end_date));

if (!start || !end) {
return [];
}

const height = BAR_HEIGHT * (end.year() - start.year());
svg.attr("height", height + margin.top + margin.bottom);

Expand Down Expand Up @@ -321,6 +325,10 @@ export function renderYearlyTimelineOf(
const start = _.min(_.map(yearlyCards, (c) => c.start_date)),
end = _.max(_.map(yearlyCards, (c) => c.end_date));

if (!start || !end) {
return [];
}

const height = BAR_HEIGHT * (end.year() - start.year());
svg.attr("height", height + margin.top + margin.bottom);

Expand Down
8 changes: 8 additions & 0 deletions src/lib/investment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export function renderMonthlyInvestmentTimeline(postings: Posting[]): Legend[] {
end = now().startOf("month");
const ts = _.groupBy(postings, (p) => p.date.format(timeFormat));

if (!start) {
return [];
}

interface Point {
month: string;
[key: string]: number | string | dayjs.Dayjs;
Expand Down Expand Up @@ -218,6 +222,10 @@ export function renderYearlyInvestmentTimeline(yearlyCards: InvestmentYearlyCard
const start = _.min(_.map(yearlyCards, (c) => c.start_date)),
end = _.max(_.map(yearlyCards, (c) => c.end_date));

if (!start || !end) {
return [];
}

const height = BAR_HEIGHT * (end.year() - start.year());
svg.attr("height", height + margin.top + margin.bottom);

Expand Down
2 changes: 1 addition & 1 deletion src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const theme = writable("light");
export const loading = writable(false);

const DELAY = 200;
const DEBOUNCE_DELAY = 150;
const DEBOUNCE_DELAY = 200;

let timeoutId: NodeJS.Timeout;
export const delayedLoading = derived(
Expand Down

0 comments on commit f2274d1

Please sign in to comment.