Skip to content

Commit

Permalink
Cleanup and added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-NRCan committed Oct 6, 2023
1 parent 3a5bc8d commit 0627e7f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 31 deletions.
15 changes: 15 additions & 0 deletions src/chart-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,26 @@ import { ChartType, ChartData, ChartDataset, ChartOptions, DefaultDataPoint } fr

export type GeoChartType = ChartType;

/**
* Extends the ChartData used by Chart.js and represents the whole Data to be displayed in the Chart
*/
export interface GeoChartData<
TType extends GeoChartType = GeoChartType,
TData = DefaultDataPoint<TType>,
TLabel = string
> extends ChartData<TType, TData, TLabel> { };

/**
* Represents a Dataset to be shown in the Chart
*/
export type GeoChartDataset<
TType extends GeoChartType = GeoChartType,
TData = DefaultDataPoint<TType>
> = ChartDataset<TType, TData>;

/**
* Extends the ChartOptions used by Chart.js with more 'GeoChart' options
*/
export interface GeoChartOptions extends ChartOptions<GeoChartType> {
geochart: {
chart: GeoChartType;
Expand All @@ -23,6 +32,9 @@ export interface GeoChartOptions extends ChartOptions<GeoChartType> {
};
};

/**
* Options for the Slider component
*/
export type GeoChartOptionsSlider = {
display: boolean;
min: number;
Expand All @@ -31,6 +43,9 @@ export type GeoChartOptionsSlider = {
track: 'normal' | 'inverted' | false;
};

/**
* Options for the Slider Axis component
*/
export type GeoChartOptionsAxis = {
type: string;
};
21 changes: 18 additions & 3 deletions src/chart.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// import { useEffect, useState } from 'react';
import { Box } from '@mui/material';
import { Chart as ChartJS, ChartData, ChartOptions, DefaultDataPoint } from 'chart.js';
import { ChartData, ChartOptions, DefaultDataPoint } from 'chart.js';
import { GeoChartOptions, GeoChartType, GeoChartData} from './chart-types';
import { ChartDoughnut } from './charts/chart-doughnut';
import { ChartBarsVertical } from './charts/chart-bars-vertical';
Expand Down Expand Up @@ -47,6 +46,10 @@ export function Chart(props: TypeChartChartProps<GeoChartType>): JSX.Element {
}
};

/**
* Renders the Chart JSX.Element itself using Line as default
* @returns The Chart JSX.Element itself using Line as default
*/
const renderChart = (): JSX.Element => {
// Depending on the type of chart
switch (options!.geochart.chart) {
Expand Down Expand Up @@ -96,6 +99,10 @@ export function Chart(props: TypeChartChartProps<GeoChartType>): JSX.Element {
}
};

/**
* Renders the X Chart Slider JSX.Element or an empty div
* @returns The X Chart Slider JSX.Element or an empty div
*/
const renderXSlider = () : JSX.Element => {
const { xSlider } = options!.geochart;
if (xSlider?.display) {
Expand All @@ -116,6 +123,10 @@ export function Chart(props: TypeChartChartProps<GeoChartType>): JSX.Element {
return <div />;
}

/**
* Renders the Y Chart Slider JSX.Element or an empty div
* @returns The Y Chart Slider JSX.Element or an empty div
*/
const renderYSlider = (): JSX.Element => {
const { ySlider } = options!.geochart;
if (ySlider?.display) {
Expand All @@ -136,6 +147,10 @@ export function Chart(props: TypeChartChartProps<GeoChartType>): JSX.Element {
return <div />;
};

/**
* Renders the whole Chart container JSX.Element or an empty div
* @returns The whole Chart container JSX.Element or an empty div
*/
const renderChartContainer = (): JSX.Element => {
if (options && options.geochart && options.geochart.chart) {
return (
Expand All @@ -147,7 +162,7 @@ export function Chart(props: TypeChartChartProps<GeoChartType>): JSX.Element {
</div>
);
}
return <div></div>;
return <div />;
}

return renderChartContainer();
Expand Down
7 changes: 0 additions & 7 deletions src/charts/chart-bars-vertical.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,5 @@ export function ChartBarsVertical(props: ChartProps<'bar', DefaultDataPoint<'bar

ChartJS.register(CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend);

// useEffect(() => {
// console.log("ChartBarsVertical useEffect Hey")
// return () => {
// console.log("ChartBarsVertical useEffect Kill")
// };
// }, []);

return <Bar style={style} data={data} options={options} redraw={redraw} />;
}
7 changes: 0 additions & 7 deletions src/charts/chart-doughnut.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,5 @@ export function ChartDoughnut(props: ChartProps<'doughnut', DefaultDataPoint<'do

ChartJS.register(ArcElement, Tooltip, Legend);

// useEffect(() => {
// console.log("ChartDoughnut useEffect Hey")
// return () => {
// console.log("ChartDoughnut useEffect Kill")
// };
// }, []);

return <Doughnut style={style} data={data} options={options} redraw={redraw} />;
}
7 changes: 0 additions & 7 deletions src/charts/chart-line.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,5 @@ export function ChartLine(props: ChartProps<'line', DefaultDataPoint<'line'>>):

ChartJS.register(CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip, Legend);

// useEffect(() => {
// console.log("ChartLine useEffect Hey")
// return () => {
// console.log("ChartLine useEffect Kill")
// };
// }, []);

return <Line style={style} data={data} options={options} redraw={redraw} />;
}
7 changes: 0 additions & 7 deletions src/charts/chart-pie.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,5 @@ export function ChartPie(props: ChartProps<'pie', DefaultDataPoint<'pie'>>): JSX

ChartJS.register(ArcElement, Tooltip, Legend);

// useEffect(() => {
// console.log("ChartPie useEffect Hey")
// return () => {
// console.log("ChartPie useEffect Kill")
// };
// }, []);

return <Pie style={style} data={data} options={options} redraw={redraw} />;
}

0 comments on commit 0627e7f

Please sign in to comment.