-
Notifications
You must be signed in to change notification settings - Fork 4
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
base: master
Are you sure you want to change the base?
Conversation
src/analytics/canvas.ts
Outdated
const canvasConfiguration = { | ||
width: 800, | ||
height: 600, | ||
backgroundColour: "white", | ||
} as const; |
There was a problem hiding this comment.
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.
src/analytics/color.ts
Outdated
There was a problem hiding this comment.
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[] { |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
|
||
export function isDarkColor(color: string): boolean { | ||
const luminance = calculateLuminance(color); | ||
return luminance < 0.35; |
There was a problem hiding this comment.
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 = [ |
There was a problem hiding this comment.
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.
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.