Skip to content

Cohort retention charts + POC of rendering charts on node and send them as attachment #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

FranjoMindek
Copy link
Contributor

@FranjoMindek FranjoMindek commented Apr 18, 2025

Fixes: #33

Adds cohort retention chart which is fully rendered on our server via chart.js.
Chose chart.js as it's most popular one so hopefully for further chart edits people would find it most easy to pick up.

@FranjoMindek FranjoMindek self-assigned this Apr 18, 2025
@FranjoMindek FranjoMindek added the enhancement New feature or request label Apr 18, 2025
Comment on lines 12 to 16
const canvasConfiguration = {
width: 800,
height: 600,
backgroundColour: "white",
} as const;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The resolution is something we can increase if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vibe coded but checked that it's okay.

* - `["10", "6 (60%)", "3 (30%)", "0 (0%)"]`
* - `["0", "N/A", "N/A"]`
*/
function calcCohortRetentionTableRow(cohort: number[]): string[] {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract out as a standalone function

percentage: number;
};

async function createCohortRetentionHeatMap(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently the code to generate the chart is very large.
This is due to the fact that this is the first chart we made via chart.js and all that can be in future extracted out as "utils" and "our base configuration" lives in here. So far we can't be sure what can be shared so it's best to leave it as it is. In future we can create e.g. base scale settings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I extracted 1 plugin out which can be reused.
Also extracted color stuff to color.ts.
Also made it a bit more readable.

@@ -13,7 +13,11 @@ export interface ChartReport {
chart: ImageCharts;
}

export type CohortRetentionReport = TextReport;
export interface LocalChartReport {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already had ChartReport, this one comes form our own server so for development I named it LocalChartReport. Now we can decide for better name since renames will add a lot of "code changes' which aren't really related to logic which I will apply before merge.

My idea would be to use:
ChartReport -> ImageChartsReport
LocalChartReport -> ChartReport

@FranjoMindek FranjoMindek marked this pull request as ready for review April 18, 2025 12:02
@FranjoMindek FranjoMindek marked this pull request as draft April 18, 2025 12:59
@FranjoMindek FranjoMindek marked this pull request as ready for review April 18, 2025 15:43

export function isDarkColor(color: string): boolean {
const luminance = calculateLuminance(color);
return luminance < 0.35;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.35 is something i defined by feeling, I really don't like it at 0.5

@@ -0,0 +1,171 @@
// Palettes source https://mk.bcgsc.ca/brewer/swatches/brewer.txt
export const SEQUENTIAL_BLUE_PALETTE = [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are options with more than 7 colors in palette, but that might be overkill, even 7 might be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a chart that shows cohort retention
1 participant