-
-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
363 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
frontend/src/component/personalDashboard/createChartData.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import type { IFeatureMetricsRaw } from 'interfaces/featureToggle'; | ||
import type { ChartData } from 'chart.js'; | ||
import 'chartjs-adapter-date-fns'; | ||
|
||
export interface IPoint { | ||
x: string; | ||
y: number; | ||
variants: Record<string, number>; | ||
} | ||
|
||
export const createChartData = ( | ||
metrics: IFeatureMetricsRaw[], | ||
): ChartData<'bar', IPoint[], string> => { | ||
const yesSeries = { | ||
label: 'Exposed', | ||
hoverBackgroundColor: '#A39EFF', | ||
backgroundColor: '#A39EFF', | ||
data: createChartPoints(metrics, (m) => m.yes), | ||
}; | ||
|
||
const noSeries = { | ||
label: 'Not exposed', | ||
hoverBackgroundColor: '#D8D6FF', | ||
backgroundColor: '#D8D6FF', | ||
data: createChartPoints(metrics, (m) => m.no), | ||
}; | ||
|
||
return { | ||
datasets: [yesSeries, noSeries], | ||
}; | ||
}; | ||
|
||
const createChartPoints = ( | ||
metrics: IFeatureMetricsRaw[], | ||
y: (m: IFeatureMetricsRaw) => number, | ||
): IPoint[] => { | ||
return metrics.map((metric) => ({ | ||
x: metric.timestamp, | ||
y: y(metric), | ||
variants: metric.variants || {}, | ||
})); | ||
}; |
Oops, something went wrong.