-
Notifications
You must be signed in to change notification settings - Fork 0
Strategy Charts #37
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?
Strategy Charts #37
Changes from all commits
102a8d6
cd64c33
132bfb7
056a123
081d3e5
40567f1
ce71fb1
474483f
36c6cfe
7e69ef6
8d7a055
ab5f16d
d3c19b3
b4b4867
1eabcf2
c19d8b2
066131f
32a7f61
c067736
09743f7
5fcfc8d
7e9b0bb
735f248
312ebcc
b385209
19c4d31
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| // בס"ד | ||
| export interface DataSet<T extends string | number> { | ||
| name: string; | ||
| points: Record<T, number>; | ||
| color?: string; //assign color if not defined | ||
| } | ||
|
Comment on lines
+2
to
+6
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consider renaming this file DataSet or something
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. still rename this file |
||
|
|
||
|
|
||
RJ0907 marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,63 @@ | ||||||
| //בס"ד | ||||||
| import { Line } from "react-chartjs-2"; | ||||||
| import { | ||||||
| Chart as ChartJS, | ||||||
| LineElement, | ||||||
| PointElement, | ||||||
| LinearScale, | ||||||
| CategoryScale, | ||||||
| Title, | ||||||
| Tooltip, | ||||||
| Legend, | ||||||
| Filler, | ||||||
| ArcElement, | ||||||
| } from "chart.js"; | ||||||
|
|
||||||
| import type { ChartData, ChartOptions } from "chart.js"; | ||||||
| import type { DataSet } from "./DatasetTemplate"; | ||||||
|
|
||||||
| ChartJS.register( | ||||||
| LineElement, | ||||||
| PointElement, | ||||||
| LinearScale, | ||||||
| CategoryScale, | ||||||
| Title, | ||||||
| Tooltip, | ||||||
| Legend, | ||||||
| Filler, | ||||||
| ArcElement, | ||||||
| ); | ||||||
RJ0907 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
|
||||||
| export interface LineChartProps { | ||||||
| dataSetsProps: DataSet<any>[]; | ||||||
| max?: number; | ||||||
| min?: number; | ||||||
| } | ||||||
| const convertDataToLineChartFormat = ({ | ||||||
| dataSetsProps, | ||||||
| }: LineChartProps): ChartData<"line", number[], string> => { | ||||||
| const defaultColors = ["blue", "red", "violet", "orange"]; | ||||||
|
|
||||||
| const labels = Array.from( | ||||||
| new Set(dataSetsProps.flatMap((ds) => Object.keys(ds.points))), | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| ).sort((a, b) => Number(a) - Number(b)); | ||||||
|
|
||||||
| return { | ||||||
| labels, | ||||||
| datasets: dataSetsProps.map((dataset, index) => ({ | ||||||
| label: dataset.name, | ||||||
| data: labels.map((label) => dataset.points[label] ?? null), | ||||||
| borderColor: dataset.color ?? defaultColors[index % defaultColors.length], | ||||||
| })), | ||||||
| }; | ||||||
| }; | ||||||
|
|
||||||
| export const LineGraph = ({ dataSetsProps, min, max }: LineChartProps) => { | ||||||
| const options: ChartOptions<"line"> = { | ||||||
| scales: { | ||||||
| y: { min, max }, | ||||||
| }, | ||||||
| }; | ||||||
| const data = convertDataToLineChartFormat({ dataSetsProps }); | ||||||
| return <Line data={data} options={options} />; | ||||||
| }; | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| //בס"ד | ||
| import { Pie } from "react-chartjs-2"; | ||
| import { | ||
| Chart as ChartJS, | ||
| LineElement, | ||
| PointElement, | ||
| LinearScale, | ||
| CategoryScale, | ||
| Title, | ||
| Tooltip, | ||
| Legend, | ||
| Filler, | ||
| ArcElement, | ||
| } from "chart.js"; | ||
|
|
||
| import type { ChartData, ChartOptions } from "chart.js"; | ||
| import type { DataSet } from "./DatasetTemplate"; | ||
|
|
||
| ChartJS.register( | ||
| LineElement, | ||
| PointElement, | ||
| LinearScale, | ||
| CategoryScale, | ||
| Title, | ||
| Tooltip, | ||
| Legend, | ||
| Filler, | ||
| ArcElement, | ||
| ); | ||
|
|
||
| const convertDataToPieChartFormat = ({ | ||
| name, | ||
| points, | ||
| color, | ||
| }: DataSet<string | number>): ChartData<"pie", number[], string> => { | ||
| const defaultColor = "red"; | ||
|
|
||
| const labels = Object.keys(points); | ||
| const values = Object.values(points); | ||
|
|
||
| return { | ||
| labels, | ||
| datasets: [ | ||
| { | ||
| label: name, | ||
| data: values, | ||
| backgroundColor: labels.map(() => color ?? defaultColor), | ||
| }, | ||
| ], | ||
| }; | ||
| }; | ||
|
|
||
| export const PieGraph = ({ name, points, color }: DataSet<string | number>) => { | ||
| const data = convertDataToPieChartFormat({ name, points, color }); | ||
| const options: ChartOptions<"pie"> = { | ||
| responsive: true, | ||
| maintainAspectRatio: false, | ||
| }; | ||
| return <Pie data={data} options={options} />; | ||
| }; |
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.
don't really see a reason for this to be named a
template