@@ -403,6 +403,33 @@ function ticksFromTimestamps(values, majorUnit) {
403403 return ticks ;
404404}
405405
406+ function determineLabelFormat ( data , timeOpts ) {
407+ var i , momentDate , hasMillis , hasTime ;
408+
409+ if ( timeOpts . tooltipFormat ) {
410+ return timeOpts . tooltipFormat ;
411+ }
412+
413+ // find the label with the most parts (milliseconds, minutes, etc.)
414+ // format all labels with the same level of detail as the most specific label
415+ for ( i = 0 ; i < data . length ; i ++ ) {
416+ momentDate = momentify ( data [ i ] , timeOpts ) ;
417+ if ( momentDate . millisecond ( ) !== 0 ) {
418+ hasMillis = true ;
419+ break ;
420+ }
421+ if ( momentDate . second ( ) !== 0 || momentDate . minute ( ) !== 0 || momentDate . hour ( ) !== 0 ) {
422+ hasTime = true ;
423+ }
424+ }
425+ if ( hasMillis ) {
426+ return 'MMM D, YYYY h:mm:ss.SSS a' ;
427+ } else if ( hasTime ) {
428+ return 'MMM D, YYYY h:mm:ss a' ;
429+ }
430+ return 'MMM D, YYYY' ;
431+ }
432+
406433module . exports = function ( Chart ) {
407434
408435 var defaultConfig = {
@@ -621,6 +648,7 @@ module.exports = function(Chart) {
621648 me . _majorUnit = determineMajorUnit ( me . _unit ) ;
622649 me . _table = buildLookupTable ( me . _timestamps . data , min , max , options . distribution ) ;
623650 me . _offsets = computeOffsets ( me . _table , ticks , min , max , options ) ;
651+ me . _labelFormat = determineLabelFormat ( me . _timestamps . data , timeOpts ) ;
624652
625653 return ticksFromTimestamps ( ticks , me . _majorUnit ) ;
626654 } ,
@@ -635,11 +663,8 @@ module.exports = function(Chart) {
635663 if ( helpers . isObject ( value ) ) {
636664 label = me . getRightValue ( value ) ;
637665 }
638- if ( timeOpts . tooltipFormat ) {
639- label = momentify ( label , timeOpts ) . format ( timeOpts . tooltipFormat ) ;
640- }
641666
642- return label ;
667+ return momentify ( label , timeOpts ) . format ( me . _labelFormat ) ;
643668 } ,
644669
645670 /**
0 commit comments