From 927002e6b71c03449ff95356ece872fb4b22063c Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 19 Oct 2023 12:07:00 -0400 Subject: [PATCH] Added the steps native examples 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 --- src/schema-validator-data.json => schema-data.json | 0 src/schema-validator-options.json => schema-options.json | 0 src/chart-types.ts | 5 +++-- src/chart.tsx | 8 ++++---- src/schema-validator.ts | 4 ++-- 5 files changed, 9 insertions(+), 8 deletions(-) rename src/schema-validator-data.json => schema-data.json (100%) rename src/schema-validator-options.json => schema-options.json (100%) diff --git a/src/schema-validator-data.json b/schema-data.json similarity index 100% rename from src/schema-validator-data.json rename to schema-data.json diff --git a/src/schema-validator-options.json b/schema-options.json similarity index 100% rename from src/schema-validator-options.json rename to schema-options.json diff --git a/src/chart-types.ts b/src/chart-types.ts index 71b7648..7bcf5c3 100644 --- a/src/chart-types.ts +++ b/src/chart-types.ts @@ -1,17 +1,18 @@ import { ChartType, ChartData, ChartDataset, ChartOptions, DefaultDataPoint } from 'chart.js'; export type GeoChartType = ChartType; +export type GeoDefaultDataPoint = DefaultDataPoint; /** * Extends the ChartData used by Chart.js and represents the whole Data to be displayed in the Chart */ -export interface GeoChartData, TLabel = string> +export interface GeoChartData, TLabel = string> extends ChartData {} /** * Represents a Dataset to be shown in the Chart */ -export type GeoChartDataset> = ChartDataset; +export type GeoChartDataset> = ChartDataset; /** * Indicates an action to be performed by the Chart. diff --git a/src/chart.tsx b/src/chart.tsx index 08b2d65..b556130 100644 --- a/src/chart.tsx +++ b/src/chart.tsx @@ -1,7 +1,7 @@ /* 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'; @@ -9,10 +9,10 @@ import { SchemaValidator, ValidatorResult } from './schema-validator'; /** * Main props for the Chart */ -export interface TypeChartChartProps { +export interface TypeChartChartProps, TLabel = string> { style?: unknown; // Will be casted as CSSProperties later via the imported cgpv react defaultColors?: GeoChartDefaultColors; - data?: GeoChartData; + data?: GeoChartData; options?: GeoChartOptions; action?: GeoChartAction; handleSliderXChanged?: (value: number | number[]) => void; @@ -178,7 +178,7 @@ export function Chart(props: TypeChartChartProps): JSX.Element { if (datasets.length > 1) { return ( - {datasets.map((ds: ChartDataset, idx: number) => { + {datasets.map((ds: ChartDataset, 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; diff --git a/src/schema-validator.ts b/src/schema-validator.ts index aeaae7e..104259e 100644 --- a/src/schema-validator.ts +++ b/src/schema-validator.ts @@ -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.