Skip to content

Commit

Permalink
Added the steps native examples
Browse files Browse the repository at this point in the history
Made chart-validator more generic with schema-validator
Enforcing return types
Moved the schema validators into json files
Better typing
Moved the schema validators to root folder
  • Loading branch information
Alex-NRCan committed Oct 25, 2023
1 parent e603783 commit 927002e
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
File renamed without changes.
File renamed without changes.
5 changes: 3 additions & 2 deletions src/chart-types.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { ChartType, ChartData, ChartDataset, ChartOptions, DefaultDataPoint } from 'chart.js';

export type GeoChartType = ChartType;
export type GeoDefaultDataPoint = DefaultDataPoint<GeoChartType>;

/**
* 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>
export interface GeoChartData<TType extends GeoChartType = GeoChartType, TData = DefaultDataPoint<GeoChartType>, 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>;
export type GeoChartDataset<TType extends GeoChartType = GeoChartType, TData = DefaultDataPoint<GeoChartType>> = ChartDataset<TType, TData>;

/**
* Indicates an action to be performed by the Chart.
Expand Down
8 changes: 4 additions & 4 deletions src/chart.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/* eslint-disable no-console */
// TODO: Remove the disable above
import { Box } from '@mui/material';
import { Chart as ChartJS, ChartDataset, registerables } from 'chart.js';
import { Chart as ChartJS, ChartDataset, DefaultDataPoint, registerables } from 'chart.js';
import { Chart as ChartReact } from 'react-chartjs-2';
import { GeoChartOptions, GeoChartType, GeoChartData, GeoChartAction, GeoChartDefaultColors } from './chart-types';
import { SchemaValidator, ValidatorResult } from './schema-validator';

/**
* Main props for the Chart
*/
export interface TypeChartChartProps<TType extends GeoChartType> {
export interface TypeChartChartProps<TType extends GeoChartType, TData = DefaultDataPoint<GeoChartType>, TLabel = string> {
style?: unknown; // Will be casted as CSSProperties later via the imported cgpv react
defaultColors?: GeoChartDefaultColors;
data?: GeoChartData<TType>;
data?: GeoChartData<TType, TData, TLabel>;
options?: GeoChartOptions;
action?: GeoChartAction;
handleSliderXChanged?: (value: number | number[]) => void;
Expand Down Expand Up @@ -178,7 +178,7 @@ export function Chart(props: TypeChartChartProps<GeoChartType>): JSX.Element {
if (datasets.length > 1) {
return (
<Box>
{datasets.map((ds: ChartDataset, idx: number) => {
{datasets.map((ds: ChartDataset<GeoChartType>, idx: number) => {
// Find a color for the legend based on the dataset info
let { color } = ChartJS.defaults;
if (ds.borderColor) color = ds.borderColor! as string;
Expand Down
4 changes: 2 additions & 2 deletions src/schema-validator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Ajv from 'ajv';
import SCHEMA_DATA from './schema-validator-data.json';
import SCHEMA_OPTIONS from './schema-validator-options.json';
import SCHEMA_DATA from '../schema-data.json';
import SCHEMA_OPTIONS from '../schema-options.json';

/**
* Represents the result of a Chart data or options inputs validations.
Expand Down

0 comments on commit 927002e

Please sign in to comment.