Documentation Index
Fetch the complete documentation index at: https://mintlify.com/apursley2012/airgead-investment-calculator/llms.txt
Use this file to discover all available pages before exploring further.
js/lib/charts.js contains two exported functions that use the HTML5 Canvas API to draw data visualizations. Both functions are DPI-aware — they scale the canvas for high-resolution displays using devicePixelRatio — and should be called again whenever the window is resized to keep the chart sharp and correctly sized.
Import
Internal setup() function
A private setup(canvas) function handles DPI scaling before every draw call. It reads the canvas element’s CSS layout size via getBoundingClientRect(), multiplies both dimensions by window.devicePixelRatio, and assigns the results to canvas.width and canvas.height. It then calls ctx.setTransform(dpr, 0, 0, dpr, 0, 0) so that all subsequent drawing commands use CSS pixel coordinates rather than physical pixel coordinates. Neither drawGrowthChart nor drawComparisonChart exposes setup() — it is called internally at the start of each draw.
drawGrowthChart(canvas, rows)
Draws the year-by-year growth chart on the Results page. The chart renders two filled area lines side by side so the viewer can compare the trajectory of a balance that includes monthly deposits against one that does not.
The
<canvas> element to draw on. The function is a no-op if this value is falsy.The array of year row objects returned by
calculateCompoundInterest(). Each object must include year, withDeposits, and withoutDeposits. The function is a no-op if the array is empty or falsy.- Legend — displayed at the top of the chart. “With monthly deposits” is labelled in dark green; “Without deposits” is labelled in grey.
- Y-axis — 5 evenly spaced grid lines with abbreviated dollar labels (
$k/$msuffixes for readability). - X-axis — year labels at every fifth year (Y0, Y5, Y10, …).
- Area paths — two filled area paths, one per scenario, drawn beneath their respective lines.
The Results page registers a
resize listener automatically. If you embed the chart in a custom page, add your own resize handler as shown above.drawComparisonChart(canvas, data)
Draws the stacked bar chart on the Compare page. Each bar represents one saved scenario and is split vertically into two segments: the total principal (grey, bottom) and the earned interest (dark green, top). The total balance is printed above each bar, and the scenario name is printed below it.
The
<canvas> element to draw on. The function is a no-op if this value is falsy.An array of scenario objects to plot. The function is a no-op if the array is empty or falsy. Each object must have the following shape:
The scenario label, printed below the bar on the x-axis.
The total final balance for the scenario. Printed above the bar.
The total deposits (starting balance + all monthly deposits). Determines the height of the grey bottom segment.
The interest earned. Determines the height of the dark-green top segment.
- Legend — displayed at the top of the chart. “Interest earned” is labelled in dark green; “Total principal” is labelled in grey.
- Y-axis — 5 evenly spaced grid lines.
- Stacked bars — one bar per scenario, split into principal (grey, bottom) and interest (dark green, top).
- Labels — the formatted total balance is printed above each bar; the scenario name is printed below.