Skip to content

Commit

Permalink
[income statement] use second level breakdown on tooltips
Browse files Browse the repository at this point in the history
  • Loading branch information
ananthakumaran committed Feb 1, 2024
1 parent 29a77e2 commit 4551a85
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/lib/income_statement.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import * as d3 from "d3";
import { formatCurrency, formatCurrencyCrude, tooltip, type IncomeStatement, rem } from "./utils";
import {
formatCurrency,
formatCurrencyCrude,
tooltip,
type IncomeStatement,
rem,
firstNames
} from "./utils";
import COLORS from "./colors";
import _ from "lodash";
import { iconGlyph, iconify } from "./icon";
Expand Down Expand Up @@ -204,8 +211,15 @@ export function renderIncomeStatement(element: Element) {
.attr("fill", (d) => d.color)
.attr("fill-opacity", 0.5)
.attr("data-tippy-content", (d) => {
const secondLevelBreakdown = _.chain(d.breakdown)
.toPairs()
.groupBy((pair) => firstNames(pair[0], 2))
.map((pairs, label) => [label, _.sumBy(pairs, (pair) => pair[1])])
.fromPairs()
.value();

return tooltip(
_.map(d.breakdown, (value, label) => [
_.map(secondLevelBreakdown, (value, label) => [
iconify(label),
[formatCurrency(value * d.multiplier), "has-text-right has-text-weight-bold"]
]),
Expand Down
4 changes: 4 additions & 0 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,10 @@ export function secondName(account: string) {
return account.split(":")[1];
}

export function firstNames(account: string, n: number) {
return _.take(account.split(":"), n).join(":");
}

export function restName(account: string) {
return _.drop(account.split(":")).join(":");
}
Expand Down

0 comments on commit 4551a85

Please sign in to comment.