@@ -26,15 +26,14 @@ import {
2626 unique ,
2727} from '@togglecorp/fujs' ;
2828
29- import useChartData from '#hooks/useChartData' ;
3029import useInputState from '#hooks/useInputState' ;
30+ import useTemporalChartData from '#hooks/useTemporalChartData' ;
3131import {
3232 COLOR_HAZARD_CYCLONE ,
3333 COLOR_HAZARD_DROUGHT ,
3434 COLOR_HAZARD_FLOOD ,
3535 COLOR_HAZARD_FOOD_INSECURITY ,
36- defaultChartMargin ,
37- defaultChartPadding ,
36+ DEFAULT_Y_AXIS_WIDTH_WITH_LABEL ,
3837} from '#utils/constants' ;
3938import type { GoApiResponse } from '#utils/restRequest' ;
4039import { useRequest } from '#utils/restRequest' ;
@@ -66,20 +65,6 @@ const validDisastersForChart: Record<number, boolean> = {
6665 [ DISASTER_DROUGHT ] : true ,
6766} ;
6867
69- const X_AXIS_HEIGHT = 32 ;
70- const Y_AXIS_WIDTH = 64 ;
71-
72- const chartOffset = {
73- left : Y_AXIS_WIDTH ,
74- top : 0 ,
75- right : 0 ,
76- bottom : X_AXIS_HEIGHT ,
77- } ;
78-
79- const currentYear = new Date ( ) . getFullYear ( ) ;
80- const firstDayOfYear = new Date ( currentYear , 0 , 1 ) ;
81- const lastDayOfYear = new Date ( currentYear , 11 , 31 ) ;
82-
8368function isValidDisaster (
8469 disaster : PartialDisasterType | null | undefined ,
8570) : disaster is DisasterType {
@@ -193,36 +178,15 @@ function HistoricalDataChart(props: Props) {
193178 } ,
194179 ) . filter ( isDefined ) ;
195180
196- const {
197- dataPoints,
198- xAxisTicks,
199- yAxisTicks,
200- chartSize,
201- } = useChartData (
181+ const chartData = useTemporalChartData (
202182 filteredEvents ,
203183 {
204184 containerRef : chartContainerRef ,
205- chartOffset,
206- chartMargin : defaultChartMargin ,
207- chartPadding : defaultChartPadding ,
208185 keySelector : ( datum ) => datum . id ,
209- xValueSelector : ( datum ) => {
210- const date = new Date ( datum . disaster_start_date ) ;
211- date . setFullYear ( currentYear ) ;
212- return date . getTime ( ) ;
213- } ,
214- type : 'temporal' ,
215- xAxisLabelSelector : ( timestamp ) => (
216- new Date ( timestamp ) . toLocaleString (
217- navigator . language ,
218- { month : 'short' } ,
219- )
220- ) ,
186+ xValueSelector : ( datum ) => datum . disaster_start_date ,
221187 yValueSelector : ( datum ) => datum . num_affected ,
222- xDomain : {
223- min : firstDayOfYear . getTime ( ) ,
224- max : lastDayOfYear . getTime ( ) ,
225- } ,
188+ yearlyChart : true ,
189+ yAxisWidth : DEFAULT_Y_AXIS_WIDTH_WITH_LABEL ,
226190 } ,
227191 ) ;
228192
@@ -250,16 +214,11 @@ function HistoricalDataChart(props: Props) {
250214 >
251215 < svg className = { styles . svg } >
252216 < ChartAxes
253- xAxisPoints = { xAxisTicks }
254- yAxisPoints = { yAxisTicks }
255- chartSize = { chartSize }
256- chartMargin = { defaultChartMargin }
257- xAxisHeight = { X_AXIS_HEIGHT }
258- yAxisWidth = { Y_AXIS_WIDTH }
217+ chartData = { chartData }
259218 yAxisLabel = { strings . peopleExposed }
260219 />
261220 </ svg >
262- { dataPoints ?. map (
221+ { chartData . chartPoints ?. map (
263222 ( point ) => {
264223 const funded = sumSafe (
265224 point . originalData . appeals . map (
0 commit comments