From a5cefc0371f22c8cc88f9572203e404aa22cec75 Mon Sep 17 00:00:00 2001 From: petterav Date: Fri, 22 Mar 2024 22:33:29 +0100 Subject: [PATCH] fix: Plugin and deleted unused hook merge --- src/Plugin.tsx | 4 +- .../GrowthChartBuilder/GrowthChartBuilder.tsx | 102 ------------------ src/utils/DataFetching/Sorting/index.ts | 1 - .../Sorting/usePercentilesOrZScores.ts | 6 -- 4 files changed, 2 insertions(+), 111 deletions(-) delete mode 100644 src/components/GrowthChart/GrowthChartBuilder/GrowthChartBuilder.tsx delete mode 100644 src/utils/DataFetching/Sorting/usePercentilesOrZScores.ts diff --git a/src/Plugin.tsx b/src/Plugin.tsx index 95e2ede..00ce989 100644 --- a/src/Plugin.tsx +++ b/src/Plugin.tsx @@ -38,7 +38,7 @@ const PluginInner = (propsFromParent: EnrollmentOverviewProps) => { isWeightInGrams: chartConfig?.settings.weightInGrams || false, }); - const usePercent = chartConfig?.settings.defaultStandard === 'p'; + const isPercentiles = chartConfig?.settings.defaultStandard === 'p'; const [open, setOpen] = useState(true); @@ -75,7 +75,7 @@ const PluginInner = (propsFromParent: EnrollmentOverviewProps) => { diff --git a/src/components/GrowthChart/GrowthChartBuilder/GrowthChartBuilder.tsx b/src/components/GrowthChart/GrowthChartBuilder/GrowthChartBuilder.tsx deleted file mode 100644 index 0f3bb56..0000000 --- a/src/components/GrowthChart/GrowthChartBuilder/GrowthChartBuilder.tsx +++ /dev/null @@ -1,102 +0,0 @@ -import React from 'react'; -import i18n from '@dhis2/d2-i18n'; -import { Line } from 'react-chartjs-2'; -import Chart, { ChartOptions } from 'chart.js/auto'; -import annotationPlugin from 'chartjs-plugin-annotation'; -import AutoSizer from 'react-virtualized-auto-sizer'; -import { ChartDataTypes, CategoryToLabel, MeasurementTypeCodesLabel, - MeasurementTypeCodes, DataSetLabels, CategoryCodes } from '../../../types/chartDataTypes'; -import { GrowthChartAnnotations, AnnotateLineEnd } from '../../../utils/ChartOptions'; -import { useMeasurementPlotting, useChartLines } from '../../../utils/Hooks/ChartDataVisualization'; -import { ChartTooltip } from './ChartTooltip'; - -interface GrowthChartBuilderProps extends ChartDataTypes { - category: keyof typeof CategoryToLabel; - dataset: string; - dateOfBirth: Date; - isPercentiles: boolean; -} - -export const GrowthChartBuilder = ({ - datasetValues, - datasetMetadata, - yAxisValues, - keysDataSet, - measurementData, - category, - dataset, - dateOfBirth, - isPercentiles, -}: GrowthChartBuilderProps) => { - Chart.register(annotationPlugin); - - const { minDataValue, maxDataValue } = yAxisValues; - - const categoryLabel = CategoryToLabel[category]; - - const MeasuremenCode = MeasurementTypeCodes[category]; - const MeasuremenLabel = MeasurementTypeCodesLabel[MeasuremenCode]; - - const adjustIndex = (dataset === DataSetLabels.y_2_5) ? 24 : 0; - const startIndex = (category !== CategoryCodes.wflh_b && category !== CategoryCodes.wflh_g) ? adjustIndex : datasetMetadata.range.start; - - const ChartLinesData = useChartLines(datasetValues, keysDataSet, datasetMetadata, category, dataset, startIndex, isPercentiles); - const MeasurementData = useMeasurementPlotting(measurementData, MeasuremenCode, category, dataset, dateOfBirth, startIndex); - const data: any = { datasets: [...ChartLinesData, ...MeasurementData] }; - const annotations = GrowthChartAnnotations(ChartLinesData, datasetMetadata); - - const options: ChartOptions<'line'> = { - elements: { point: { radius: 0, hoverRadius: 0 } }, - plugins: { - annotation: { annotations }, - legend: { display: false }, - tooltip: ChartTooltip(MeasuremenLabel, categoryLabel), - }, - scales: { - x: { - type: 'linear', - title: { - display: true, - text: i18n.t(datasetMetadata.xAxisLabel), - font: { size: 13 }, - }, - min: datasetMetadata.range.start, - max: datasetMetadata.range.end, - ticks: { stepSize: 1 }, - }, - y: { - title: { - display: true, - text: i18n.t(datasetMetadata.yAxisLabel), - font: { size: 13 }, - }, - position: 'left', - min: minDataValue, - max: maxDataValue, - }, - yRight: { - position: 'right', - min: minDataValue, - max: maxDataValue, - ticks: { padding: isPercentiles ? 36 : 18 }, - }, - }, - animation: { - onComplete: (chartAnimation: any) => AnnotateLineEnd(chartAnimation, isPercentiles, keysDataSet), - onProgress: (chartAnimation: any) => AnnotateLineEnd(chartAnimation, isPercentiles, keysDataSet), - }, - }; - - return ( -
- - {/* eslint-disable-next-line react/no-unused-prop-types */} - {({ height, width }: { height: number, width: number }) => ( -
- -
- )} -
-
- ); -}; diff --git a/src/utils/DataFetching/Sorting/index.ts b/src/utils/DataFetching/Sorting/index.ts index 856095b..6131cdc 100644 --- a/src/utils/DataFetching/Sorting/index.ts +++ b/src/utils/DataFetching/Sorting/index.ts @@ -1,2 +1 @@ export { useChartDataForGender } from './useChartDataForGender'; -export { usePercentilesOrZScores } from './usePercentilesOrZScores'; diff --git a/src/utils/DataFetching/Sorting/usePercentilesOrZScores.ts b/src/utils/DataFetching/Sorting/usePercentilesOrZScores.ts deleted file mode 100644 index d8042bc..0000000 --- a/src/utils/DataFetching/Sorting/usePercentilesOrZScores.ts +++ /dev/null @@ -1,6 +0,0 @@ -export const usePercentilesOrZScores = (category: any, usePercentiles: boolean): any[] | undefined => { - if (category) { - return usePercentiles ? category.percentileDatasetValues : category.zScoreDatasetValues; - } - return undefined; -};