@@ -366,6 +366,58 @@ export const gitjobsChartTheme = {
366366
367367const MESSAGE_EMPTY_STATS = "No data available yet" ;
368368
369+ /**
370+ * Finds the smallest value in an array of numbers.
371+ * @param {Array<number> } numbers - Array of numbers to search
372+ * @returns {number } The smallest number in the array
373+ */
374+ const getSmallestValue = ( numbers ) => {
375+ if ( ! numbers || numbers . length === 0 ) {
376+ throw new Error ( "Array is empty or undefined" ) ;
377+ }
378+ return Math . min ( ...numbers ) ;
379+ } ;
380+
381+ /**
382+ * Gets the minimum date value from the data array.
383+ * If the minimum date is less than the provided minimum value, returns that date.
384+ * Otherwise, returns the provided minimum value.
385+ * @param {Array } data - Array of data items where each item is an array with a timestamp as the first element
386+ * @param {number } min - Minimum date value to compare
387+ * @returns {number } The minimum date value from the data or the provided minimum value
388+ */
389+ const getMinDateValue = ( data , min ) => {
390+ const dates = data . map ( ( item ) => item [ 0 ] ) ;
391+ const minDate = getSmallestValue ( dates ) ;
392+ return minDate < min ? minDate : min ;
393+ } ;
394+
395+ /**
396+ * Finds the greatest value in an array of numbers.
397+ * @param {Array<number> } numbers - Array of numbers to search
398+ * @returns {number } The greatest number in the array
399+ */
400+ const getGreatestValue = ( numbers ) => {
401+ if ( ! numbers || numbers . length === 0 ) {
402+ throw new Error ( "Array is empty or undefined" ) ;
403+ }
404+ return Math . max ( ...numbers ) ;
405+ } ;
406+
407+ /**
408+ * Gets the maximum date value from the data array.
409+ * If the maximum date is greater than the provided maximum value, returns that date.
410+ * Otherwise, returns the provided maximum value.
411+ * @param {Array } data - Array of data items where each item is an array with a timestamp as the first element
412+ * @param {number } max - Maximum date value to compare
413+ * @returns {number } The maximum date value from the data or the provided maximum value
414+ */
415+ const getMaxDateValue = ( data , max ) => {
416+ const dates = data . map ( ( item ) => item [ 0 ] ) ;
417+ const maxDate = getGreatestValue ( dates ) ;
418+ return maxDate > max ? maxDate : max ;
419+ } ;
420+
369421/**
370422 * Renders a line chart showing job publication trends.
371423 * @param {Array } data - Time series data with timestamps and job counts
@@ -577,8 +629,8 @@ const renderBarDailyChart = (data, max, min) => {
577629 splitLine : {
578630 show : false ,
579631 } ,
580- min : min ,
581- max : max ,
632+ min : getMinDateValue ( data , min ) ,
633+ max : getMaxDateValue ( data , max ) ,
582634 } ,
583635 } ;
584636 option && myChart . setOption ( option ) ;
@@ -628,8 +680,8 @@ const renderBarMonthlyChart = (data, max, min) => {
628680 xAxis : {
629681 ...getBarStatsOptions ( ) . xAxis ,
630682 axisLabel : { interval : 0 , formatter : "{MMM}'{yy}" , hideOverlap : true } ,
631- min : min ,
632- max : max ,
683+ min : getMinDateValue ( data , min ) ,
684+ max : getMaxDateValue ( data , max ) ,
633685 } ,
634686 } ;
635687 option && myChart . setOption ( option ) ;
0 commit comments